author | jdv |
Fri, 21 Jun 2019 12:08:37 +0530 | |
branch | metal-prototype-branch |
changeset 57416 | e153174dba06 |
permissions | -rw-r--r-- |
57416
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
1 |
/* |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
4 |
* |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
10 |
* |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
15 |
* accompanied this code). |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
16 |
* |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
20 |
* |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
23 |
* questions. |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
24 |
*/ |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
25 |
|
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
26 |
package sun.java2d.metal; |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
27 |
|
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
28 |
import sun.java2d.SurfaceData; |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
29 |
import sun.java2d.SurfaceDataProxy; |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
30 |
import sun.java2d.loops.CompositeType; |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
31 |
|
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
32 |
import java.awt.*; |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
33 |
|
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
34 |
/** |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
35 |
* The proxy class contains the logic for when to replace a |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
36 |
* SurfaceData with a cached OGL Texture and the code to create |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
37 |
* the accelerated surfaces. |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
38 |
*/ |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
39 |
public class MTLSurfaceDataProxy extends SurfaceDataProxy { |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
40 |
public static SurfaceDataProxy createProxy(SurfaceData srcData, |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
41 |
MTLGraphicsConfig dstConfig) |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
42 |
{ |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
43 |
if (srcData instanceof MTLSurfaceData) { |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
44 |
// srcData must be a VolatileImage which either matches |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
45 |
// our pixel format or not - either way we do not cache it... |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
46 |
return UNCACHED; |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
47 |
} |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
48 |
|
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
49 |
return new MTLSurfaceDataProxy(dstConfig, srcData.getTransparency()); |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
50 |
} |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
51 |
|
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
52 |
MTLGraphicsConfig oglgc; |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
53 |
int transparency; |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
54 |
|
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
55 |
public MTLSurfaceDataProxy(MTLGraphicsConfig oglgc, int transparency) { |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
56 |
this.oglgc = oglgc; |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
57 |
this.transparency = transparency; |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
58 |
} |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
59 |
|
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
60 |
@Override |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
61 |
public SurfaceData validateSurfaceData(SurfaceData srcData, |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
62 |
SurfaceData cachedData, |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
63 |
int w, int h) |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
64 |
{ |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
65 |
if (cachedData == null) { |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
66 |
try { |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
67 |
cachedData = oglgc.createManagedSurface(w, h, transparency); |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
68 |
} catch (OutOfMemoryError er) { |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
69 |
return null; |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
70 |
} |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
71 |
} |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
72 |
return cachedData; |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
73 |
} |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
74 |
|
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
75 |
@Override |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
76 |
public boolean isSupportedOperation(SurfaceData srcData, |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
77 |
int txtype, |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
78 |
CompositeType comp, |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
79 |
Color bgColor) |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
80 |
{ |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
81 |
return comp.isDerivedFrom(CompositeType.AnyAlpha) && |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
82 |
(bgColor == null || transparency == Transparency.OPAQUE); |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
83 |
} |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
diff
changeset
|
84 |
} |