author | jdv |
Fri, 21 Jun 2019 12:08:37 +0530 | |
branch | metal-prototype-branch |
changeset 57416 | e153174dba06 |
parent 57196 | a95707a39ff5 |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
53673
e04d39094915
8214076: Cleanup the code related to GraphicsEnvironment/Device/Configuration
serb
parents:
52537
diff
changeset
|
2 |
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. |
12047 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package sun.java2d.opengl; |
|
27 |
||
28 |
import java.awt.AWTException; |
|
29 |
import java.awt.BufferCapabilities; |
|
30 |
import java.awt.Component; |
|
31 |
import java.awt.Graphics; |
|
32 |
import java.awt.Graphics2D; |
|
33 |
import java.awt.Image; |
|
34 |
import java.awt.ImageCapabilities; |
|
13550
648dd6fa0dee
7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents:
12047
diff
changeset
|
35 |
import java.awt.Rectangle; |
12047 | 36 |
import java.awt.Transparency; |
37 |
import java.awt.color.ColorSpace; |
|
38 |
import java.awt.image.BufferedImage; |
|
39 |
import java.awt.image.ColorModel; |
|
40 |
import java.awt.image.DataBuffer; |
|
41 |
import java.awt.image.DirectColorModel; |
|
42 |
import java.awt.image.VolatileImage; |
|
43 |
import java.awt.image.WritableRaster; |
|
44 |
||
45 |
import sun.awt.CGraphicsConfig; |
|
46 |
import sun.awt.CGraphicsDevice; |
|
47 |
import sun.awt.image.OffScreenImage; |
|
48 |
import sun.awt.image.SunVolatileImage; |
|
49 |
import sun.java2d.Disposer; |
|
50 |
import sun.java2d.DisposerRecord; |
|
51 |
import sun.java2d.Surface; |
|
52 |
import sun.java2d.SurfaceData; |
|
53 |
import sun.java2d.opengl.OGLContext.OGLContextCaps; |
|
54 |
import sun.java2d.pipe.hw.AccelSurface; |
|
55 |
import sun.java2d.pipe.hw.AccelTypedVolatileImage; |
|
56 |
import sun.java2d.pipe.hw.ContextCapabilities; |
|
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
57 |
import sun.lwawt.LWComponentPeer; |
57416
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
58 |
import sun.lwawt.macosx.CFRetainedResource; |
12047 | 59 |
import sun.lwawt.macosx.CPlatformView; |
60 |
||
52537
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
52248
diff
changeset
|
61 |
import static sun.java2d.opengl.OGLContext.OGLContextCaps.CAPS_DOUBLEBUFFERED; |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
52248
diff
changeset
|
62 |
import static sun.java2d.opengl.OGLContext.OGLContextCaps.CAPS_EXT_FBOBJECT; |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
52248
diff
changeset
|
63 |
import static sun.java2d.opengl.OGLSurfaceData.FBOBJECT; |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
52248
diff
changeset
|
64 |
import static sun.java2d.opengl.OGLSurfaceData.TEXTURE; |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
52248
diff
changeset
|
65 |
|
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
66 |
public final class CGLGraphicsConfig extends CGraphicsConfig |
57416
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
67 |
implements OGLGraphicsConfig |
12047 | 68 |
{ |
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
69 |
//private static final int kOpenGLSwapInterval = |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
70 |
// RuntimeOptions.getCurrentOptions().OpenGLSwapInterval; |
12047 | 71 |
private static final int kOpenGLSwapInterval = 0; // TODO |
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
72 |
private static boolean cglAvailable; |
12047 | 73 |
private static ImageCapabilities imageCaps = new CGLImageCaps(); |
74 |
||
75 |
private int pixfmt; |
|
76 |
private BufferCapabilities bufferCaps; |
|
77 |
private long pConfigInfo; |
|
78 |
private ContextCapabilities oglCaps; |
|
79 |
private OGLContext context; |
|
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
80 |
private final Object disposerReferent = new Object(); |
23325
4c3942938b0d
8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents:
16840
diff
changeset
|
81 |
private final int maxTextureSize; |
4c3942938b0d
8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents:
16840
diff
changeset
|
82 |
|
12047 | 83 |
private static native boolean initCGL(); |
15988 | 84 |
private static native long getCGLConfigInfo(int displayID, int visualnum, |
12047 | 85 |
int swapInterval); |
86 |
private static native int getOGLCapabilities(long configInfo); |
|
87 |
||
23325
4c3942938b0d
8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents:
16840
diff
changeset
|
88 |
/** |
4c3942938b0d
8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents:
16840
diff
changeset
|
89 |
* Returns GL_MAX_TEXTURE_SIZE from the shared opengl context. Must be |
4c3942938b0d
8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents:
16840
diff
changeset
|
90 |
* called under OGLRQ lock, because this method change current context. |
4c3942938b0d
8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents:
16840
diff
changeset
|
91 |
* |
4c3942938b0d
8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents:
16840
diff
changeset
|
92 |
* @return GL_MAX_TEXTURE_SIZE |
4c3942938b0d
8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents:
16840
diff
changeset
|
93 |
*/ |
4c3942938b0d
8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents:
16840
diff
changeset
|
94 |
private static native int nativeGetMaxTextureSize(); |
4c3942938b0d
8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents:
16840
diff
changeset
|
95 |
|
12047 | 96 |
static { |
97 |
cglAvailable = initCGL(); |
|
98 |
} |
|
99 |
||
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
100 |
private CGLGraphicsConfig(CGraphicsDevice device, int pixfmt, |
23325
4c3942938b0d
8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents:
16840
diff
changeset
|
101 |
long configInfo, int maxTextureSize, |
4c3942938b0d
8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents:
16840
diff
changeset
|
102 |
ContextCapabilities oglCaps) { |
12047 | 103 |
super(device); |
104 |
||
105 |
this.pixfmt = pixfmt; |
|
106 |
this.pConfigInfo = configInfo; |
|
107 |
this.oglCaps = oglCaps; |
|
23325
4c3942938b0d
8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents:
16840
diff
changeset
|
108 |
this.maxTextureSize = maxTextureSize; |
12047 | 109 |
context = new OGLContext(OGLRenderQueue.getInstance(), this); |
110 |
||
111 |
// add a record to the Disposer so that we destroy the native |
|
112 |
// CGLGraphicsConfigInfo data when this object goes away |
|
113 |
Disposer.addRecord(disposerReferent, |
|
57416
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
114 |
new CGLGCDisposerRecord(pConfigInfo)); |
12047 | 115 |
} |
116 |
||
117 |
@Override |
|
118 |
public Object getProxyKey() { |
|
119 |
return this; |
|
120 |
} |
|
121 |
||
122 |
@Override |
|
123 |
public SurfaceData createManagedSurface(int w, int h, int transparency) { |
|
124 |
return CGLSurfaceData.createData(this, w, h, |
|
57416
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
125 |
getColorModel(transparency), |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
126 |
null, |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
127 |
OGLSurfaceData.TEXTURE); |
12047 | 128 |
} |
129 |
||
130 |
public static CGLGraphicsConfig getConfig(CGraphicsDevice device, |
|
52537
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
52248
diff
changeset
|
131 |
int displayID, int pixfmt) |
12047 | 132 |
{ |
133 |
if (!cglAvailable) { |
|
134 |
return null; |
|
135 |
} |
|
136 |
||
137 |
long cfginfo = 0; |
|
23325
4c3942938b0d
8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents:
16840
diff
changeset
|
138 |
int textureSize = 0; |
52248
2e330da7cbf4
8211300: Convert C-style array declarations in JDK client code
tvaleev
parents:
47216
diff
changeset
|
139 |
final String[] ids = new String[1]; |
12047 | 140 |
OGLRenderQueue rq = OGLRenderQueue.getInstance(); |
141 |
rq.lock(); |
|
142 |
try { |
|
143 |
// getCGLConfigInfo() creates and destroys temporary |
|
144 |
// surfaces/contexts, so we should first invalidate the current |
|
145 |
// Java-level context and flush the queue... |
|
146 |
OGLContext.invalidateCurrentContext(); |
|
52537
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
52248
diff
changeset
|
147 |
cfginfo = getCGLConfigInfo(displayID, pixfmt, kOpenGLSwapInterval); |
15988 | 148 |
if (cfginfo != 0L) { |
23325
4c3942938b0d
8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents:
16840
diff
changeset
|
149 |
textureSize = nativeGetMaxTextureSize(); |
4c3942938b0d
8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents:
16840
diff
changeset
|
150 |
// 7160609: GL still fails to create a square texture of this |
4c3942938b0d
8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents:
16840
diff
changeset
|
151 |
// size. Half should be safe enough. |
4c3942938b0d
8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents:
16840
diff
changeset
|
152 |
// Explicitly not support a texture more than 2^14, see 8010999. |
4c3942938b0d
8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents:
16840
diff
changeset
|
153 |
textureSize = textureSize <= 16384 ? textureSize / 2 : 8192; |
15988 | 154 |
OGLContext.setScratchSurface(cfginfo); |
23325
4c3942938b0d
8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents:
16840
diff
changeset
|
155 |
rq.flushAndInvokeNow(() -> { |
4c3942938b0d
8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents:
16840
diff
changeset
|
156 |
ids[0] = OGLContext.getOGLIdString(); |
15988 | 157 |
}); |
158 |
} |
|
12047 | 159 |
} finally { |
160 |
rq.unlock(); |
|
161 |
} |
|
162 |
if (cfginfo == 0) { |
|
163 |
return null; |
|
164 |
} |
|
165 |
||
166 |
int oglCaps = getOGLCapabilities(cfginfo); |
|
167 |
ContextCapabilities caps = new OGLContextCaps(oglCaps, ids[0]); |
|
23325
4c3942938b0d
8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents:
16840
diff
changeset
|
168 |
return new CGLGraphicsConfig(device, pixfmt, cfginfo, textureSize, caps); |
12047 | 169 |
} |
170 |
||
171 |
public static boolean isCGLAvailable() { |
|
172 |
return cglAvailable; |
|
173 |
} |
|
174 |
||
175 |
/** |
|
176 |
* Returns true if the provided capability bit is present for this config. |
|
177 |
* See OGLContext.java for a list of supported capabilities. |
|
178 |
*/ |
|
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
179 |
@Override |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
180 |
public boolean isCapPresent(int cap) { |
12047 | 181 |
return ((oglCaps.getCaps() & cap) != 0); |
182 |
} |
|
183 |
||
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
184 |
@Override |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
185 |
public long getNativeConfigInfo() { |
12047 | 186 |
return pConfigInfo; |
187 |
} |
|
188 |
||
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
189 |
@Override |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
190 |
public OGLContext getContext() { |
12047 | 191 |
return context; |
192 |
} |
|
193 |
||
194 |
@Override |
|
195 |
public BufferedImage createCompatibleImage(int width, int height) { |
|
196 |
ColorModel model = new DirectColorModel(24, 0xff0000, 0xff00, 0xff); |
|
197 |
WritableRaster |
|
57416
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
198 |
raster = model.createCompatibleWritableRaster(width, height); |
12047 | 199 |
return new BufferedImage(model, raster, model.isAlphaPremultiplied(), |
57416
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
200 |
null); |
12047 | 201 |
} |
202 |
||
203 |
@Override |
|
204 |
public ColorModel getColorModel(int transparency) { |
|
205 |
switch (transparency) { |
|
57416
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
206 |
case Transparency.OPAQUE: |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
207 |
// REMIND: once the ColorModel spec is changed, this should be |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
208 |
// an opaque premultiplied DCM... |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
209 |
return new DirectColorModel(24, 0xff0000, 0xff00, 0xff); |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
210 |
case Transparency.BITMASK: |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
211 |
return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000); |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
212 |
case Transparency.TRANSLUCENT: |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
213 |
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
214 |
return new DirectColorModel(cs, 32, |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
215 |
0xff0000, 0xff00, 0xff, 0xff000000, |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
216 |
true, DataBuffer.TYPE_INT); |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
217 |
default: |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
218 |
return null; |
12047 | 219 |
} |
220 |
} |
|
221 |
||
222 |
public boolean isDoubleBuffered() { |
|
223 |
return isCapPresent(CAPS_DOUBLEBUFFERED); |
|
224 |
} |
|
225 |
||
226 |
private static class CGLGCDisposerRecord implements DisposerRecord { |
|
227 |
private long pCfgInfo; |
|
228 |
public CGLGCDisposerRecord(long pCfgInfo) { |
|
229 |
this.pCfgInfo = pCfgInfo; |
|
230 |
} |
|
231 |
public void dispose() { |
|
232 |
if (pCfgInfo != 0) { |
|
233 |
OGLRenderQueue.disposeGraphicsConfig(pCfgInfo); |
|
234 |
pCfgInfo = 0; |
|
235 |
} |
|
236 |
} |
|
237 |
} |
|
238 |
||
239 |
// TODO: CGraphicsConfig doesn't implement displayChanged() yet |
|
240 |
//@Override |
|
241 |
public synchronized void displayChanged() { |
|
242 |
//super.displayChanged(); |
|
243 |
||
244 |
// the context could hold a reference to a CGLSurfaceData, which in |
|
245 |
// turn has a reference back to this CGLGraphicsConfig, so in order |
|
246 |
// for this instance to be disposed we need to break the connection |
|
247 |
OGLRenderQueue rq = OGLRenderQueue.getInstance(); |
|
248 |
rq.lock(); |
|
249 |
try { |
|
250 |
OGLContext.invalidateCurrentContext(); |
|
251 |
} finally { |
|
252 |
rq.unlock(); |
|
253 |
} |
|
254 |
} |
|
255 |
||
256 |
@Override |
|
257 |
public String toString() { |
|
52537
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
52248
diff
changeset
|
258 |
String display = getDevice().getIDstring(); |
814c49afb1a7
8211992: GraphicsConfiguration.getDevice().getDisplayMode() causes JVM crash on Mac
serb
parents:
52248
diff
changeset
|
259 |
return ("CGLGraphicsConfig[" + display + ", pixfmt=" + pixfmt + "]"); |
12047 | 260 |
} |
261 |
||
262 |
@Override |
|
263 |
public SurfaceData createSurfaceData(CPlatformView pView) { |
|
264 |
return CGLSurfaceData.createData(pView); |
|
265 |
} |
|
266 |
||
267 |
@Override |
|
57416
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
268 |
public SurfaceData createSurfaceData(CFRetainedResource layer) { |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
269 |
return CGLSurfaceData.createData((CGLLayer) layer); |
57196
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
53673
diff
changeset
|
270 |
} |
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
53673
diff
changeset
|
271 |
|
a95707a39ff5
Description : Metal Rendering Pipeline - initial implementation of line and quad rendering
aghaisas
parents:
53673
diff
changeset
|
272 |
@Override |
12047 | 273 |
public Image createAcceleratedImage(Component target, |
274 |
int width, int height) |
|
275 |
{ |
|
276 |
ColorModel model = getColorModel(Transparency.OPAQUE); |
|
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
277 |
WritableRaster wr = model.createCompatibleWritableRaster(width, height); |
12047 | 278 |
return new OffScreenImage(target, model, wr, |
57416
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
279 |
model.isAlphaPremultiplied()); |
12047 | 280 |
} |
281 |
||
282 |
@Override |
|
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
283 |
public void assertOperationSupported(final int numBuffers, |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
284 |
final BufferCapabilities caps) |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
285 |
throws AWTException { |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
286 |
// Assume this method is never called with numBuffers != 2, as 0 is |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
287 |
// unsupported, and 1 corresponds to a SingleBufferStrategy which |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
288 |
// doesn't depend on the peer. Screen is considered as a separate |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
289 |
// "buffer". |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
290 |
if (numBuffers != 2) { |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
291 |
throw new AWTException("Only double buffering is supported"); |
12047 | 292 |
} |
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
293 |
final BufferCapabilities configCaps = getBufferCapabilities(); |
12047 | 294 |
if (!configCaps.isPageFlipping()) { |
295 |
throw new AWTException("Page flipping is not supported"); |
|
296 |
} |
|
297 |
if (caps.getFlipContents() == BufferCapabilities.FlipContents.PRIOR) { |
|
298 |
throw new AWTException("FlipContents.PRIOR is not supported"); |
|
299 |
} |
|
300 |
} |
|
301 |
||
302 |
@Override |
|
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
303 |
public Image createBackBuffer(final LWComponentPeer<?, ?> peer) { |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
304 |
final Rectangle r = peer.getBounds(); |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
305 |
// It is possible for the component to have size 0x0, adjust it to |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
306 |
// be at least 1x1 to avoid IAE |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
307 |
final int w = Math.max(1, r.width); |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
308 |
final int h = Math.max(1, r.height); |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
309 |
final int transparency = peer.isTranslucent() ? Transparency.TRANSLUCENT |
57416
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
310 |
: Transparency.OPAQUE; |
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
311 |
return new SunVolatileImage(this, w, h, transparency, null); |
12047 | 312 |
} |
313 |
||
314 |
@Override |
|
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
315 |
public void destroyBackBuffer(final Image backBuffer) { |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
316 |
if (backBuffer != null) { |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
317 |
backBuffer.flush(); |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
318 |
} |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
319 |
} |
12047 | 320 |
|
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
321 |
@Override |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
322 |
public void flip(final LWComponentPeer<?, ?> peer, final Image backBuffer, |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
323 |
final int x1, final int y1, final int x2, final int y2, |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
324 |
final BufferCapabilities.FlipContents flipAction) { |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
325 |
final Graphics g = peer.getGraphics(); |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
326 |
try { |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
327 |
g.drawImage(backBuffer, x1, y1, x2, y2, x1, y1, x2, y2, null); |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
328 |
} finally { |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
329 |
g.dispose(); |
12047 | 330 |
} |
331 |
if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) { |
|
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
332 |
final Graphics2D bg = (Graphics2D) backBuffer.getGraphics(); |
12047 | 333 |
try { |
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
334 |
bg.setBackground(peer.getBackground()); |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
335 |
bg.clearRect(0, 0, backBuffer.getWidth(null), |
57416
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
336 |
backBuffer.getHeight(null)); |
12047 | 337 |
} finally { |
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
338 |
bg.dispose(); |
12047 | 339 |
} |
340 |
} |
|
341 |
} |
|
342 |
||
343 |
private static class CGLBufferCaps extends BufferCapabilities { |
|
344 |
public CGLBufferCaps(boolean dblBuf) { |
|
345 |
super(imageCaps, imageCaps, |
|
57416
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
346 |
dblBuf ? FlipContents.UNDEFINED : null); |
12047 | 347 |
} |
348 |
} |
|
349 |
||
350 |
@Override |
|
351 |
public BufferCapabilities getBufferCapabilities() { |
|
352 |
if (bufferCaps == null) { |
|
353 |
bufferCaps = new CGLBufferCaps(isDoubleBuffered()); |
|
354 |
} |
|
355 |
return bufferCaps; |
|
356 |
} |
|
357 |
||
358 |
private static class CGLImageCaps extends ImageCapabilities { |
|
359 |
private CGLImageCaps() { |
|
360 |
super(true); |
|
361 |
} |
|
362 |
public boolean isTrueVolatile() { |
|
363 |
return true; |
|
364 |
} |
|
365 |
} |
|
366 |
||
367 |
@Override |
|
368 |
public ImageCapabilities getImageCapabilities() { |
|
369 |
return imageCaps; |
|
370 |
} |
|
371 |
||
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
372 |
@Override |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
373 |
public VolatileImage createCompatibleVolatileImage(int width, int height, |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
374 |
int transparency, |
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
375 |
int type) { |
31661
a5cb86f2253b
7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
25859
diff
changeset
|
376 |
if ((type != FBOBJECT && type != TEXTURE) |
a5cb86f2253b
7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
25859
diff
changeset
|
377 |
|| transparency == Transparency.BITMASK |
a5cb86f2253b
7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
25859
diff
changeset
|
378 |
|| type == FBOBJECT && !isCapPresent(CAPS_EXT_FBOBJECT)) { |
12047 | 379 |
return null; |
380 |
} |
|
381 |
SunVolatileImage vi = new AccelTypedVolatileImage(this, width, height, |
|
57416
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
382 |
transparency, type); |
12047 | 383 |
Surface sd = vi.getDestSurface(); |
384 |
if (!(sd instanceof AccelSurface) || |
|
57416
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
385 |
((AccelSurface)sd).getType() != type) |
12047 | 386 |
{ |
387 |
vi.flush(); |
|
388 |
vi = null; |
|
389 |
} |
|
390 |
||
391 |
return vi; |
|
392 |
} |
|
393 |
||
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
394 |
@Override |
12047 | 395 |
public ContextCapabilities getContextCapabilities() { |
396 |
return oglCaps; |
|
397 |
} |
|
398 |
||
14647
bacc2d4f4b27
7124552: [macosx] NullPointerException in getBufferStrategy()
serb
parents:
13550
diff
changeset
|
399 |
@Override |
13550
648dd6fa0dee
7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents:
12047
diff
changeset
|
400 |
public int getMaxTextureWidth() { |
23325
4c3942938b0d
8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents:
16840
diff
changeset
|
401 |
return Math.max(maxTextureSize / getDevice().getScaleFactor(), |
57416
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
402 |
getBounds().width); |
13550
648dd6fa0dee
7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents:
12047
diff
changeset
|
403 |
} |
648dd6fa0dee
7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents:
12047
diff
changeset
|
404 |
|
648dd6fa0dee
7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents:
12047
diff
changeset
|
405 |
@Override |
648dd6fa0dee
7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents:
12047
diff
changeset
|
406 |
public int getMaxTextureHeight() { |
23325
4c3942938b0d
8027778: [macosx] Full screen not working properly on 7u45 and jdk8
serb
parents:
16840
diff
changeset
|
407 |
return Math.max(maxTextureSize / getDevice().getScaleFactor(), |
57416
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
57196
diff
changeset
|
408 |
getBounds().height); |
13550
648dd6fa0dee
7160609: [macosx] JDK crash in libjvm.dylib ( C [GeForceGLDriver+0x675a] gldAttachDrawable+0x941)
anthony
parents:
12047
diff
changeset
|
409 |
} |
12047 | 410 |
} |