37 import java.awt.image.ColorModel;
38 import java.awt.image.DataBuffer;
39 import java.awt.image.DirectColorModel;
40 import java.awt.image.VolatileImage;
41 import sun.awt.Win32GraphicsConfig;
42 import sun.awt.Win32GraphicsDevice;
43 import sun.awt.image.SunVolatileImage;
44 import sun.awt.image.SurfaceManager;
45 import sun.awt.windows.WComponentPeer;
46 import sun.java2d.Disposer;
47 import sun.java2d.DisposerRecord;
48 import sun.java2d.SunGraphics2D;
49 import sun.java2d.Surface;
50 import sun.java2d.SurfaceData;
51 import sun.java2d.pipe.hw.AccelSurface;
52 import sun.java2d.pipe.hw.AccelTypedVolatileImage;
53 import sun.java2d.pipe.hw.ContextCapabilities;
54 import static sun.java2d.opengl.OGLContext.OGLContextCaps.*;
55 import static sun.java2d.opengl.WGLSurfaceData.*;
56 import sun.java2d.opengl.OGLContext.OGLContextCaps;
57 import sun.java2d.pipe.hw.AccelDeviceEventListener;
58 import sun.java2d.pipe.hw.AccelDeviceEventNotifier;
59 import sun.java2d.windows.GDIWindowSurfaceData;
60
61 public class WGLGraphicsConfig
62 extends Win32GraphicsConfig
63 implements OGLGraphicsConfig
64 {
65 protected static boolean wglAvailable;
66 private static ImageCapabilities imageCaps = new WGLImageCaps();
67
68 private BufferCapabilities bufferCaps;
69 private long pConfigInfo;
70 private ContextCapabilities oglCaps;
71 private OGLContext context;
72 private Object disposerReferent = new Object();
73
74 public static native int getDefaultPixFmt(int screennum);
75 private static native boolean initWGL();
76 private static native long getWGLConfigInfo(int screennum, int visualnum);
77 private static native int getOGLCapabilities(long configInfo);
78
79 static {
80 wglAvailable = initWGL();
81 }
82
83 @SuppressWarnings("deprecation")
84 protected WGLGraphicsConfig(Win32GraphicsDevice device, int visualnum,
85 long configInfo, ContextCapabilities oglCaps)
86 {
87 super(device, visualnum);
88 this.pConfigInfo = configInfo;
89 this.oglCaps = oglCaps;
90 context = new OGLContext(OGLRenderQueue.getInstance(), this);
91
92 // add a record to the Disposer so that we destroy the native
93 // WGLGraphicsConfigInfo data when this object goes away
94 Disposer.addRecord(disposerReferent,
95 new WGLGCDisposerRecord(pConfigInfo,
96 device.getScreen()));
97 }
98
99 public Object getProxyKey() {
100 return this;
101 }
102
103 public SurfaceData createManagedSurface(int w, int h, int transparency) {
104 return WGLSurfaceData.createData(this, w, h,
105 getColorModel(transparency),
106 null,
107 OGLSurfaceData.TEXTURE);
108 }
109
110 public static WGLGraphicsConfig getConfig(Win32GraphicsDevice device,
111 int pixfmt)
112 {
113 if (!wglAvailable) {
114 return null;
115 }
116
181 return ((oglCaps.getCaps() & cap) != 0);
182 }
183
184 @Override
185 public final long getNativeConfigInfo() {
186 return pConfigInfo;
187 }
188
189 /**
190 * {@inheritDoc}
191 *
192 * @see sun.java2d.pipe.hw.BufferedContextProvider#getContext
193 */
194 @Override
195 public final OGLContext getContext() {
196 return context;
197 }
198
199 private static class WGLGCDisposerRecord implements DisposerRecord {
200 private long pCfgInfo;
201 private int screen;
202 public WGLGCDisposerRecord(long pCfgInfo, int screen) {
203 this.pCfgInfo = pCfgInfo;
204 }
205 public void dispose() {
206 OGLRenderQueue rq = OGLRenderQueue.getInstance();
207 rq.lock();
208 try {
209 rq.flushAndInvokeNow(new Runnable() {
210 public void run() {
211 AccelDeviceEventNotifier.
212 eventOccured(screen,
213 AccelDeviceEventNotifier.DEVICE_RESET);
214 AccelDeviceEventNotifier.
215 eventOccured(screen,
216 AccelDeviceEventNotifier.DEVICE_DISPOSED);
217 }
218 });
219 } finally {
220 rq.unlock();
221 }
222 if (pCfgInfo != 0) {
223 OGLRenderQueue.disposeGraphicsConfig(pCfgInfo);
224 pCfgInfo = 0;
225 }
226 }
227 }
228
229 @Override
230 public synchronized void displayChanged() {
231 super.displayChanged();
232 // the context could hold a reference to a WGLSurfaceData, which in
233 // turn has a reference back to this WGLGraphicsConfig, so in order
234 // for this instance to be disposed we need to break the connection
235 OGLRenderQueue rq = OGLRenderQueue.getInstance();
236 rq.lock();
237 try {
238 OGLContext.invalidateCurrentContext();
239 } finally {
240 rq.unlock();
241 }
437 transparency, type);
438 Surface sd = vi.getDestSurface();
439 if (!(sd instanceof AccelSurface) ||
440 ((AccelSurface)sd).getType() != type)
441 {
442 vi.flush();
443 vi = null;
444 }
445
446 return vi;
447 }
448
449 /**
450 * {@inheritDoc}
451 *
452 * @see sun.java2d.pipe.hw.AccelGraphicsConfig#getContextCapabilities
453 */
454 @Override
455 public ContextCapabilities getContextCapabilities() {
456 return oglCaps;
457 }
458
459 @Override
460 public void addDeviceEventListener(AccelDeviceEventListener l) {
461 AccelDeviceEventNotifier.addListener(l, screen.getScreen());
462 }
463
464 @Override
465 public void removeDeviceEventListener(AccelDeviceEventListener l) {
466 AccelDeviceEventNotifier.removeListener(l);
467 }
468 }
|
37 import java.awt.image.ColorModel;
38 import java.awt.image.DataBuffer;
39 import java.awt.image.DirectColorModel;
40 import java.awt.image.VolatileImage;
41 import sun.awt.Win32GraphicsConfig;
42 import sun.awt.Win32GraphicsDevice;
43 import sun.awt.image.SunVolatileImage;
44 import sun.awt.image.SurfaceManager;
45 import sun.awt.windows.WComponentPeer;
46 import sun.java2d.Disposer;
47 import sun.java2d.DisposerRecord;
48 import sun.java2d.SunGraphics2D;
49 import sun.java2d.Surface;
50 import sun.java2d.SurfaceData;
51 import sun.java2d.pipe.hw.AccelSurface;
52 import sun.java2d.pipe.hw.AccelTypedVolatileImage;
53 import sun.java2d.pipe.hw.ContextCapabilities;
54 import static sun.java2d.opengl.OGLContext.OGLContextCaps.*;
55 import static sun.java2d.opengl.WGLSurfaceData.*;
56 import sun.java2d.opengl.OGLContext.OGLContextCaps;
57 import sun.java2d.windows.GDIWindowSurfaceData;
58
59 public class WGLGraphicsConfig
60 extends Win32GraphicsConfig
61 implements OGLGraphicsConfig
62 {
63 protected static boolean wglAvailable;
64 private static ImageCapabilities imageCaps = new WGLImageCaps();
65
66 private BufferCapabilities bufferCaps;
67 private long pConfigInfo;
68 private ContextCapabilities oglCaps;
69 private OGLContext context;
70 private Object disposerReferent = new Object();
71
72 public static native int getDefaultPixFmt(int screennum);
73 private static native boolean initWGL();
74 private static native long getWGLConfigInfo(int screennum, int visualnum);
75 private static native int getOGLCapabilities(long configInfo);
76
77 static {
78 wglAvailable = initWGL();
79 }
80
81 @SuppressWarnings("deprecation")
82 protected WGLGraphicsConfig(Win32GraphicsDevice device, int visualnum,
83 long configInfo, ContextCapabilities oglCaps)
84 {
85 super(device, visualnum);
86 this.pConfigInfo = configInfo;
87 this.oglCaps = oglCaps;
88 context = new OGLContext(OGLRenderQueue.getInstance(), this);
89
90 // add a record to the Disposer so that we destroy the native
91 // WGLGraphicsConfigInfo data when this object goes away
92 Disposer.addRecord(disposerReferent,
93 new WGLGCDisposerRecord(pConfigInfo));
94 }
95
96 public Object getProxyKey() {
97 return this;
98 }
99
100 public SurfaceData createManagedSurface(int w, int h, int transparency) {
101 return WGLSurfaceData.createData(this, w, h,
102 getColorModel(transparency),
103 null,
104 OGLSurfaceData.TEXTURE);
105 }
106
107 public static WGLGraphicsConfig getConfig(Win32GraphicsDevice device,
108 int pixfmt)
109 {
110 if (!wglAvailable) {
111 return null;
112 }
113
178 return ((oglCaps.getCaps() & cap) != 0);
179 }
180
181 @Override
182 public final long getNativeConfigInfo() {
183 return pConfigInfo;
184 }
185
186 /**
187 * {@inheritDoc}
188 *
189 * @see sun.java2d.pipe.hw.BufferedContextProvider#getContext
190 */
191 @Override
192 public final OGLContext getContext() {
193 return context;
194 }
195
196 private static class WGLGCDisposerRecord implements DisposerRecord {
197 private long pCfgInfo;
198 public WGLGCDisposerRecord(long pCfgInfo) {
199 this.pCfgInfo = pCfgInfo;
200 }
201 public void dispose() {
202 if (pCfgInfo != 0) {
203 OGLRenderQueue.disposeGraphicsConfig(pCfgInfo);
204 pCfgInfo = 0;
205 }
206 }
207 }
208
209 @Override
210 public synchronized void displayChanged() {
211 super.displayChanged();
212 // the context could hold a reference to a WGLSurfaceData, which in
213 // turn has a reference back to this WGLGraphicsConfig, so in order
214 // for this instance to be disposed we need to break the connection
215 OGLRenderQueue rq = OGLRenderQueue.getInstance();
216 rq.lock();
217 try {
218 OGLContext.invalidateCurrentContext();
219 } finally {
220 rq.unlock();
221 }
417 transparency, type);
418 Surface sd = vi.getDestSurface();
419 if (!(sd instanceof AccelSurface) ||
420 ((AccelSurface)sd).getType() != type)
421 {
422 vi.flush();
423 vi = null;
424 }
425
426 return vi;
427 }
428
429 /**
430 * {@inheritDoc}
431 *
432 * @see sun.java2d.pipe.hw.AccelGraphicsConfig#getContextCapabilities
433 */
434 @Override
435 public ContextCapabilities getContextCapabilities() {
436 return oglCaps;
437 }
438 }
|