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.Color;
31 import java.awt.Component;
32 import java.awt.Graphics;
33 import java.awt.Graphics2D;
34 import java.awt.Image;
35 import java.awt.ImageCapabilities;
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.awt.image.SurfaceManager;
50 import sun.java2d.Disposer;
51 import sun.java2d.DisposerRecord;
52 import sun.java2d.SunGraphics2D;
53 import sun.java2d.Surface;
54 import sun.java2d.SurfaceData;
55 import sun.java2d.opengl.OGLContext.OGLContextCaps;
56 import sun.java2d.pipe.hw.AccelSurface;
57 import sun.java2d.pipe.hw.AccelTypedVolatileImage;
58 import sun.java2d.pipe.hw.ContextCapabilities;
59 import static sun.java2d.opengl.OGLSurfaceData.*;
60 import static sun.java2d.opengl.OGLContext.OGLContextCaps.*;
61 import sun.java2d.opengl.CGLSurfaceData.CGLVSyncOffScreenSurfaceData;
62 import sun.java2d.pipe.hw.AccelDeviceEventListener;
63 import sun.java2d.pipe.hw.AccelDeviceEventNotifier;
64
65 import sun.lwawt.macosx.CPlatformView;
66
67 public class CGLGraphicsConfig extends CGraphicsConfig
68 implements OGLGraphicsConfig
69 {
70 //private static final int kOpenGLSwapInterval = RuntimeOptions.getCurrentOptions().OpenGLSwapInterval;
71 private static final int kOpenGLSwapInterval = 0; // TODO
72 protected static boolean cglAvailable;
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;
80 private Object disposerReferent = new Object();
81
82 public static native int getDefaultPixFmt(int screennum);
83 private static native boolean initCGL();
84 private static native long getCGLConfigInfo(int screennum, int visualnum,
85 int swapInterval);
86 private static native int getOGLCapabilities(long configInfo);
87
88 static {
225 pCfgInfo = 0;
226 }
227 }
228 }
229
230 // TODO: CGraphicsConfig doesn't implement displayChanged() yet
231 //@Override
232 public synchronized void displayChanged() {
233 //super.displayChanged();
234
235 // the context could hold a reference to a CGLSurfaceData, which in
236 // turn has a reference back to this CGLGraphicsConfig, so in order
237 // for this instance to be disposed we need to break the connection
238 OGLRenderQueue rq = OGLRenderQueue.getInstance();
239 rq.lock();
240 try {
241 OGLContext.invalidateCurrentContext();
242 } finally {
243 rq.unlock();
244 }
245 }
246
247 @Override
248 public String toString() {
249 int screen = getDevice().getCoreGraphicsScreen();
250 return ("CGLGraphicsConfig[dev="+screen+",pixfmt="+pixfmt+"]");
251 }
252
253
254 /**
255 * The following methods are invoked from ComponentModel.java rather
256 * than having the Mac OS X-dependent implementations hardcoded in that
257 * class. This way the appropriate actions are taken based on the peer's
258 * GraphicsConfig, whether it is a CGraphicsConfig or a
259 * CGLGraphicsConfig.
260 */
261
262 /**
263 * Creates a new SurfaceData that will be associated with the given
264 * LWWindowPeer.
460
461 return vi;
462 }
463
464 /**
465 * {@inheritDoc}
466 *
467 * @see sun.java2d.pipe.hw.AccelGraphicsConfig#getContextCapabilities
468 */
469 public ContextCapabilities getContextCapabilities() {
470 return oglCaps;
471 }
472
473 public void addDeviceEventListener(AccelDeviceEventListener l) {
474 int screen = getDevice().getCoreGraphicsScreen();
475 AccelDeviceEventNotifier.addListener(l, screen);
476 }
477
478 public void removeDeviceEventListener(AccelDeviceEventListener l) {
479 AccelDeviceEventNotifier.removeListener(l);
480 }
481 }
|
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.Color;
31 import java.awt.Component;
32 import java.awt.Graphics;
33 import java.awt.Graphics2D;
34 import java.awt.GraphicsConfiguration;
35 import java.awt.GraphicsDevice;
36 import java.awt.GraphicsEnvironment;
37 import java.awt.Image;
38 import java.awt.ImageCapabilities;
39 import java.awt.Rectangle;
40 import java.awt.Transparency;
41 import java.awt.color.ColorSpace;
42 import java.awt.image.BufferedImage;
43 import java.awt.image.ColorModel;
44 import java.awt.image.DataBuffer;
45 import java.awt.image.DirectColorModel;
46 import java.awt.image.VolatileImage;
47 import java.awt.image.WritableRaster;
48
49 import sun.awt.CGraphicsConfig;
50 import sun.awt.CGraphicsDevice;
51 import sun.awt.TextureSizeConstraining;
52 import sun.awt.image.OffScreenImage;
53 import sun.awt.image.SunVolatileImage;
54 import sun.awt.image.SurfaceManager;
55 import sun.java2d.Disposer;
56 import sun.java2d.DisposerRecord;
57 import sun.java2d.SunGraphics2D;
58 import sun.java2d.Surface;
59 import sun.java2d.SurfaceData;
60 import sun.java2d.opengl.OGLContext.OGLContextCaps;
61 import sun.java2d.pipe.hw.AccelSurface;
62 import sun.java2d.pipe.hw.AccelTypedVolatileImage;
63 import sun.java2d.pipe.hw.ContextCapabilities;
64 import static sun.java2d.opengl.OGLSurfaceData.*;
65 import static sun.java2d.opengl.OGLContext.OGLContextCaps.*;
66 import sun.java2d.opengl.CGLSurfaceData.CGLVSyncOffScreenSurfaceData;
67 import sun.java2d.pipe.hw.AccelDeviceEventListener;
68 import sun.java2d.pipe.hw.AccelDeviceEventNotifier;
69
70 import sun.lwawt.macosx.CPlatformView;
71
72 public class CGLGraphicsConfig extends CGraphicsConfig
73 implements OGLGraphicsConfig, TextureSizeConstraining
74 {
75 //private static final int kOpenGLSwapInterval = RuntimeOptions.getCurrentOptions().OpenGLSwapInterval;
76 private static final int kOpenGLSwapInterval = 0; // TODO
77 protected static boolean cglAvailable;
78 private static ImageCapabilities imageCaps = new CGLImageCaps();
79
80 private int pixfmt;
81 private BufferCapabilities bufferCaps;
82 private long pConfigInfo;
83 private ContextCapabilities oglCaps;
84 private OGLContext context;
85 private Object disposerReferent = new Object();
86
87 public static native int getDefaultPixFmt(int screennum);
88 private static native boolean initCGL();
89 private static native long getCGLConfigInfo(int screennum, int visualnum,
90 int swapInterval);
91 private static native int getOGLCapabilities(long configInfo);
92
93 static {
230 pCfgInfo = 0;
231 }
232 }
233 }
234
235 // TODO: CGraphicsConfig doesn't implement displayChanged() yet
236 //@Override
237 public synchronized void displayChanged() {
238 //super.displayChanged();
239
240 // the context could hold a reference to a CGLSurfaceData, which in
241 // turn has a reference back to this CGLGraphicsConfig, so in order
242 // for this instance to be disposed we need to break the connection
243 OGLRenderQueue rq = OGLRenderQueue.getInstance();
244 rq.lock();
245 try {
246 OGLContext.invalidateCurrentContext();
247 } finally {
248 rq.unlock();
249 }
250
251 updateTotalDisplayBounds();
252 }
253
254 @Override
255 public String toString() {
256 int screen = getDevice().getCoreGraphicsScreen();
257 return ("CGLGraphicsConfig[dev="+screen+",pixfmt="+pixfmt+"]");
258 }
259
260
261 /**
262 * The following methods are invoked from ComponentModel.java rather
263 * than having the Mac OS X-dependent implementations hardcoded in that
264 * class. This way the appropriate actions are taken based on the peer's
265 * GraphicsConfig, whether it is a CGraphicsConfig or a
266 * CGLGraphicsConfig.
267 */
268
269 /**
270 * Creates a new SurfaceData that will be associated with the given
271 * LWWindowPeer.
467
468 return vi;
469 }
470
471 /**
472 * {@inheritDoc}
473 *
474 * @see sun.java2d.pipe.hw.AccelGraphicsConfig#getContextCapabilities
475 */
476 public ContextCapabilities getContextCapabilities() {
477 return oglCaps;
478 }
479
480 public void addDeviceEventListener(AccelDeviceEventListener l) {
481 int screen = getDevice().getCoreGraphicsScreen();
482 AccelDeviceEventNotifier.addListener(l, screen);
483 }
484
485 public void removeDeviceEventListener(AccelDeviceEventListener l) {
486 AccelDeviceEventNotifier.removeListener(l);
487 }
488
489 private static final Rectangle totalDisplayBounds = new Rectangle();
490
491 private static void updateTotalDisplayBounds() {
492 synchronized (totalDisplayBounds) {
493 Rectangle virtualBounds = new Rectangle();
494 for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
495 for (GraphicsConfiguration gc : gd.getConfigurations()) {
496 virtualBounds = virtualBounds.union(gc.getBounds());
497 }
498 }
499 totalDisplayBounds.setBounds(virtualBounds);
500 }
501 }
502
503 // 7160609: GL still fails to create a square texture of this size,
504 // so we use this value to cap the total display bounds.
505 native private static int getMaxTextureSize();
506
507 @Override
508 public int getMaxTextureWidth() {
509 int width;
510
511 synchronized (totalDisplayBounds) {
512 if (totalDisplayBounds.width == 0) {
513 updateTotalDisplayBounds();
514 }
515 width = totalDisplayBounds.width;
516 }
517
518 return Math.min(width, getMaxTextureSize());
519 }
520
521 @Override
522 public int getMaxTextureHeight() {
523 int height;
524
525 synchronized (totalDisplayBounds) {
526 if (totalDisplayBounds.height == 0) {
527 updateTotalDisplayBounds();
528 }
529 height = totalDisplayBounds.height;
530 }
531
532 return Math.min(height, getMaxTextureSize());
533 }
534 }
|