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