49 import sun.java2d.Disposer; |
49 import sun.java2d.Disposer; |
50 import sun.java2d.DisposerRecord; |
50 import sun.java2d.DisposerRecord; |
51 import sun.java2d.Surface; |
51 import sun.java2d.Surface; |
52 import sun.java2d.SurfaceData; |
52 import sun.java2d.SurfaceData; |
53 import sun.java2d.opengl.OGLContext.OGLContextCaps; |
53 import sun.java2d.opengl.OGLContext.OGLContextCaps; |
54 import sun.java2d.metal.MetalLayer; |
|
55 import sun.java2d.pipe.hw.AccelSurface; |
54 import sun.java2d.pipe.hw.AccelSurface; |
56 import sun.java2d.pipe.hw.AccelTypedVolatileImage; |
55 import sun.java2d.pipe.hw.AccelTypedVolatileImage; |
57 import sun.java2d.pipe.hw.ContextCapabilities; |
56 import sun.java2d.pipe.hw.ContextCapabilities; |
58 import sun.lwawt.LWComponentPeer; |
57 import sun.lwawt.LWComponentPeer; |
|
58 import sun.lwawt.macosx.CFRetainedResource; |
59 import sun.lwawt.macosx.CPlatformView; |
59 import sun.lwawt.macosx.CPlatformView; |
60 |
60 |
61 import static sun.java2d.opengl.OGLContext.OGLContextCaps.CAPS_DOUBLEBUFFERED; |
61 import static sun.java2d.opengl.OGLContext.OGLContextCaps.CAPS_DOUBLEBUFFERED; |
62 import static sun.java2d.opengl.OGLContext.OGLContextCaps.CAPS_EXT_FBOBJECT; |
62 import static sun.java2d.opengl.OGLContext.OGLContextCaps.CAPS_EXT_FBOBJECT; |
63 import static sun.java2d.opengl.OGLSurfaceData.FBOBJECT; |
63 import static sun.java2d.opengl.OGLSurfaceData.FBOBJECT; |
64 import static sun.java2d.opengl.OGLSurfaceData.TEXTURE; |
64 import static sun.java2d.opengl.OGLSurfaceData.TEXTURE; |
65 |
65 |
66 public final class CGLGraphicsConfig extends CGraphicsConfig |
66 public final class CGLGraphicsConfig extends CGraphicsConfig |
67 implements OGLGraphicsConfig |
67 implements OGLGraphicsConfig |
68 { |
68 { |
69 //private static final int kOpenGLSwapInterval = |
69 //private static final int kOpenGLSwapInterval = |
70 // RuntimeOptions.getCurrentOptions().OpenGLSwapInterval; |
70 // RuntimeOptions.getCurrentOptions().OpenGLSwapInterval; |
71 private static final int kOpenGLSwapInterval = 0; // TODO |
71 private static final int kOpenGLSwapInterval = 0; // TODO |
72 private static boolean cglAvailable; |
72 private static boolean cglAvailable; |
109 context = new OGLContext(OGLRenderQueue.getInstance(), this); |
109 context = new OGLContext(OGLRenderQueue.getInstance(), this); |
110 |
110 |
111 // add a record to the Disposer so that we destroy the native |
111 // add a record to the Disposer so that we destroy the native |
112 // CGLGraphicsConfigInfo data when this object goes away |
112 // CGLGraphicsConfigInfo data when this object goes away |
113 Disposer.addRecord(disposerReferent, |
113 Disposer.addRecord(disposerReferent, |
114 new CGLGCDisposerRecord(pConfigInfo)); |
114 new CGLGCDisposerRecord(pConfigInfo)); |
115 } |
115 } |
116 |
116 |
117 @Override |
117 @Override |
118 public Object getProxyKey() { |
118 public Object getProxyKey() { |
119 return this; |
119 return this; |
120 } |
120 } |
121 |
121 |
122 @Override |
122 @Override |
123 public SurfaceData createManagedSurface(int w, int h, int transparency) { |
123 public SurfaceData createManagedSurface(int w, int h, int transparency) { |
124 return CGLSurfaceData.createData(this, w, h, |
124 return CGLSurfaceData.createData(this, w, h, |
125 getColorModel(transparency), |
125 getColorModel(transparency), |
126 null, |
126 null, |
127 OGLSurfaceData.TEXTURE); |
127 OGLSurfaceData.TEXTURE); |
128 } |
128 } |
129 |
129 |
130 public static CGLGraphicsConfig getConfig(CGraphicsDevice device, |
130 public static CGLGraphicsConfig getConfig(CGraphicsDevice device, |
131 int displayID, int pixfmt) |
131 int displayID, int pixfmt) |
132 { |
132 { |
193 |
193 |
194 @Override |
194 @Override |
195 public BufferedImage createCompatibleImage(int width, int height) { |
195 public BufferedImage createCompatibleImage(int width, int height) { |
196 ColorModel model = new DirectColorModel(24, 0xff0000, 0xff00, 0xff); |
196 ColorModel model = new DirectColorModel(24, 0xff0000, 0xff00, 0xff); |
197 WritableRaster |
197 WritableRaster |
198 raster = model.createCompatibleWritableRaster(width, height); |
198 raster = model.createCompatibleWritableRaster(width, height); |
199 return new BufferedImage(model, raster, model.isAlphaPremultiplied(), |
199 return new BufferedImage(model, raster, model.isAlphaPremultiplied(), |
200 null); |
200 null); |
201 } |
201 } |
202 |
202 |
203 @Override |
203 @Override |
204 public ColorModel getColorModel(int transparency) { |
204 public ColorModel getColorModel(int transparency) { |
205 switch (transparency) { |
205 switch (transparency) { |
206 case Transparency.OPAQUE: |
206 case Transparency.OPAQUE: |
207 // REMIND: once the ColorModel spec is changed, this should be |
207 // REMIND: once the ColorModel spec is changed, this should be |
208 // an opaque premultiplied DCM... |
208 // an opaque premultiplied DCM... |
209 return new DirectColorModel(24, 0xff0000, 0xff00, 0xff); |
209 return new DirectColorModel(24, 0xff0000, 0xff00, 0xff); |
210 case Transparency.BITMASK: |
210 case Transparency.BITMASK: |
211 return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000); |
211 return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000); |
212 case Transparency.TRANSLUCENT: |
212 case Transparency.TRANSLUCENT: |
213 ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); |
213 ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); |
214 return new DirectColorModel(cs, 32, |
214 return new DirectColorModel(cs, 32, |
215 0xff0000, 0xff00, 0xff, 0xff000000, |
215 0xff0000, 0xff00, 0xff, 0xff000000, |
216 true, DataBuffer.TYPE_INT); |
216 true, DataBuffer.TYPE_INT); |
217 default: |
217 default: |
218 return null; |
218 return null; |
219 } |
219 } |
220 } |
220 } |
221 |
221 |
222 public boolean isDoubleBuffered() { |
222 public boolean isDoubleBuffered() { |
223 return isCapPresent(CAPS_DOUBLEBUFFERED); |
223 return isCapPresent(CAPS_DOUBLEBUFFERED); |
263 public SurfaceData createSurfaceData(CPlatformView pView) { |
263 public SurfaceData createSurfaceData(CPlatformView pView) { |
264 return CGLSurfaceData.createData(pView); |
264 return CGLSurfaceData.createData(pView); |
265 } |
265 } |
266 |
266 |
267 @Override |
267 @Override |
268 public SurfaceData createSurfaceData(CGLLayer layer) { |
268 public SurfaceData createSurfaceData(CFRetainedResource layer) { |
269 return CGLSurfaceData.createData(layer); |
269 return CGLSurfaceData.createData((CGLLayer) layer); |
270 } |
|
271 |
|
272 @Override |
|
273 public SurfaceData createSurfaceData(MetalLayer layer) { |
|
274 return null; |
|
275 } |
270 } |
276 |
271 |
277 @Override |
272 @Override |
278 public Image createAcceleratedImage(Component target, |
273 public Image createAcceleratedImage(Component target, |
279 int width, int height) |
274 int width, int height) |
280 { |
275 { |
281 ColorModel model = getColorModel(Transparency.OPAQUE); |
276 ColorModel model = getColorModel(Transparency.OPAQUE); |
282 WritableRaster wr = model.createCompatibleWritableRaster(width, height); |
277 WritableRaster wr = model.createCompatibleWritableRaster(width, height); |
283 return new OffScreenImage(target, model, wr, |
278 return new OffScreenImage(target, model, wr, |
284 model.isAlphaPremultiplied()); |
279 model.isAlphaPremultiplied()); |
285 } |
280 } |
286 |
281 |
287 @Override |
282 @Override |
288 public void assertOperationSupported(final int numBuffers, |
283 public void assertOperationSupported(final int numBuffers, |
289 final BufferCapabilities caps) |
284 final BufferCapabilities caps) |
310 // It is possible for the component to have size 0x0, adjust it to |
305 // It is possible for the component to have size 0x0, adjust it to |
311 // be at least 1x1 to avoid IAE |
306 // be at least 1x1 to avoid IAE |
312 final int w = Math.max(1, r.width); |
307 final int w = Math.max(1, r.width); |
313 final int h = Math.max(1, r.height); |
308 final int h = Math.max(1, r.height); |
314 final int transparency = peer.isTranslucent() ? Transparency.TRANSLUCENT |
309 final int transparency = peer.isTranslucent() ? Transparency.TRANSLUCENT |
315 : Transparency.OPAQUE; |
310 : Transparency.OPAQUE; |
316 return new SunVolatileImage(this, w, h, transparency, null); |
311 return new SunVolatileImage(this, w, h, transparency, null); |
317 } |
312 } |
318 |
313 |
319 @Override |
314 @Override |
320 public void destroyBackBuffer(final Image backBuffer) { |
315 public void destroyBackBuffer(final Image backBuffer) { |
336 if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) { |
331 if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) { |
337 final Graphics2D bg = (Graphics2D) backBuffer.getGraphics(); |
332 final Graphics2D bg = (Graphics2D) backBuffer.getGraphics(); |
338 try { |
333 try { |
339 bg.setBackground(peer.getBackground()); |
334 bg.setBackground(peer.getBackground()); |
340 bg.clearRect(0, 0, backBuffer.getWidth(null), |
335 bg.clearRect(0, 0, backBuffer.getWidth(null), |
341 backBuffer.getHeight(null)); |
336 backBuffer.getHeight(null)); |
342 } finally { |
337 } finally { |
343 bg.dispose(); |
338 bg.dispose(); |
344 } |
339 } |
345 } |
340 } |
346 } |
341 } |
347 |
342 |
348 private static class CGLBufferCaps extends BufferCapabilities { |
343 private static class CGLBufferCaps extends BufferCapabilities { |
349 public CGLBufferCaps(boolean dblBuf) { |
344 public CGLBufferCaps(boolean dblBuf) { |
350 super(imageCaps, imageCaps, |
345 super(imageCaps, imageCaps, |
351 dblBuf ? FlipContents.UNDEFINED : null); |
346 dblBuf ? FlipContents.UNDEFINED : null); |
352 } |
347 } |
353 } |
348 } |
354 |
349 |
355 @Override |
350 @Override |
356 public BufferCapabilities getBufferCapabilities() { |
351 public BufferCapabilities getBufferCapabilities() { |
382 || transparency == Transparency.BITMASK |
377 || transparency == Transparency.BITMASK |
383 || type == FBOBJECT && !isCapPresent(CAPS_EXT_FBOBJECT)) { |
378 || type == FBOBJECT && !isCapPresent(CAPS_EXT_FBOBJECT)) { |
384 return null; |
379 return null; |
385 } |
380 } |
386 SunVolatileImage vi = new AccelTypedVolatileImage(this, width, height, |
381 SunVolatileImage vi = new AccelTypedVolatileImage(this, width, height, |
387 transparency, type); |
382 transparency, type); |
388 Surface sd = vi.getDestSurface(); |
383 Surface sd = vi.getDestSurface(); |
389 if (!(sd instanceof AccelSurface) || |
384 if (!(sd instanceof AccelSurface) || |
390 ((AccelSurface)sd).getType() != type) |
385 ((AccelSurface)sd).getType() != type) |
391 { |
386 { |
392 vi.flush(); |
387 vi.flush(); |
393 vi = null; |
388 vi = null; |
394 } |
389 } |
395 |
390 |