diff options
author | Sven Gothel <[email protected]> | 2010-11-14 21:20:57 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2010-11-14 21:20:57 +0100 |
commit | 250ca5671f24bc2ef3e9c5aad2bf7b11db2ffbfb (patch) | |
tree | 30da0bd80830b0a85f80d5b879c72ecf16eae496 /src/jogl/classes | |
parent | deeb2ee63d3765336325c095a22f494e2f6bfe5b (diff) |
JOGL X11/WGL: Proper usage of the shared resources in implementation
Diffstat (limited to 'src/jogl/classes')
4 files changed, 103 insertions, 74 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java index 6ebd3938a..c7e0a0417 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java @@ -146,7 +146,7 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { } } - protected void shutdownInstance() {} + protected final void shutdownInstance() {} protected GLDrawableImpl createOnscreenDrawableImpl(NativeSurface target) { if (target == null) { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java index f41b68d31..7981e7ba2 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java @@ -121,7 +121,7 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl { return null; } - protected void shutdownInstance() {} + protected final void shutdownInstance() {} protected GLDrawableImpl createOnscreenDrawableImpl(NativeSurface target) { if (target == null) { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java index f8405961f..850cf5542 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java @@ -131,7 +131,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { } } - protected final GLContext getOrCreateSharedContextImpl(AbstractGraphicsDevice device) { + private final SharedResource getOrCreateShared(AbstractGraphicsDevice device) { String connection = device.getConnection(); SharedResource sr; synchronized(sharedMap) { @@ -160,13 +160,18 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { NativeWindowFactory.getDefaultToolkitLock().unlock(); // OK } } + return sr; + } + + protected final GLContext getOrCreateSharedContextImpl(AbstractGraphicsDevice device) { + SharedResource sr = getOrCreateShared(device); if(null!=sr) { return sr.context; } return null; } - protected void shutdownInstance() { + protected final void shutdownInstance() { if (DEBUG) { Exception e = new Exception("Debug"); e.printStackTrace(); @@ -195,41 +200,35 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { sharedMap.clear(); } - protected GLDrawableImpl createOnscreenDrawableImpl(NativeSurface target) { + protected final GLDrawableImpl createOnscreenDrawableImpl(NativeSurface target) { if (target == null) { throw new IllegalArgumentException("Null target"); } return new WindowsOnscreenWGLDrawable(this, target); } - protected GLDrawableImpl createOffscreenDrawableImpl(NativeSurface target) { + protected final GLDrawableImpl createOffscreenDrawableImpl(NativeSurface target) { if (target == null) { throw new IllegalArgumentException("Null target"); } return new WindowsOffscreenWGLDrawable(this, target); } - public boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { - SharedResource sr; - synchronized(sharedMap) { - sr = (SharedResource) sharedMap.get(device.getConnection()); - } + public final boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { + SharedResource sr = getOrCreateShared((null!=device)?device:defaultDevice); if(null!=sr) { return sr.canCreateGLPbuffer; } return false; } - protected GLDrawableImpl createGLPbufferDrawableImpl(final NativeSurface target) { + protected final GLDrawableImpl createGLPbufferDrawableImpl(final NativeSurface target) { if (target == null) { throw new IllegalArgumentException("Null target"); } final AbstractGraphicsDevice device = target.getGraphicsConfiguration().getNativeGraphicsConfiguration().getScreen().getDevice(); - final SharedResource sr; - synchronized(sharedMap) { - sr = (SharedResource) sharedMap.get(device.getConnection()); - } + final SharedResource sr = getOrCreateShared(device); if(null==sr) { return null; } @@ -261,7 +260,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { return (GLDrawableImpl) returnList.get(0); } - protected NativeSurface createOffscreenSurfaceImpl(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) { + protected final NativeSurface createOffscreenSurfaceImpl(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) { AbstractGraphicsScreen screen = DefaultGraphicsScreen.createDefault(); ProxySurface ns = new ProxySurface(WindowsWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic( capabilities, chooser, screen) ); @@ -269,15 +268,15 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { return ns; } - protected GLContext createExternalGLContextImpl() { + protected final GLContext createExternalGLContextImpl() { return WindowsExternalWGLContext.create(this, null); } - public boolean canCreateExternalGLDrawable(AbstractGraphicsDevice device) { + public final boolean canCreateExternalGLDrawable(AbstractGraphicsDevice device) { return true; } - protected GLDrawable createExternalGLDrawableImpl() { + protected final GLDrawable createExternalGLDrawableImpl() { return WindowsExternalWGLDrawable.create(this, null); } @@ -295,11 +294,11 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { return detail; } - public boolean canCreateContextOnJava2DSurface(AbstractGraphicsDevice device) { + public final boolean canCreateContextOnJava2DSurface(AbstractGraphicsDevice device) { return false; } - public GLContext createContextOnJava2DSurface(Object graphics, GLContext shareWith) + public final GLContext createContextOnJava2DSurface(Object graphics, GLContext shareWith) throws GLException { throw new GLException("Unimplemented on this platform"); } @@ -310,11 +309,11 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { private static final int GAMMA_RAMP_LENGTH = 256; - protected int getGammaRampLength() { + protected final int getGammaRampLength() { return GAMMA_RAMP_LENGTH; } - protected boolean setGammaRamp(float[] ramp) { + protected final boolean setGammaRamp(float[] ramp) { short[] rampData = new short[3 * GAMMA_RAMP_LENGTH]; for (int i = 0; i < GAMMA_RAMP_LENGTH; i++) { short scaledValue = (short) (ramp[i] * 65535); @@ -329,7 +328,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { return res; } - protected Buffer getGammaRamp() { + protected final Buffer getGammaRamp() { ShortBuffer rampData = ShortBuffer.wrap(new short[3 * GAMMA_RAMP_LENGTH]); long screenDC = GDI.GetDC(0); boolean res = GDI.GetDeviceGammaRamp(screenDC, rampData); @@ -340,7 +339,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { return rampData; } - protected void resetGammaRamp(Buffer originalGammaRamp) { + protected final void resetGammaRamp(Buffer originalGammaRamp) { if (originalGammaRamp == null) { // getGammaRamp failed earlier return; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java index 7efbc6ed7..ddfae1f4c 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java @@ -296,7 +296,6 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { } } HashMap/*<connection, SharedResource>*/ sharedMap = new HashMap(); - SharedResource defaultShare; X11GraphicsDevice defaultDevice; public final AbstractGraphicsDevice getDefaultDevice() { @@ -322,7 +321,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { } } - protected final GLContext getOrCreateSharedContextImpl(AbstractGraphicsDevice device) { + protected final SharedResource getOrCreateShared(AbstractGraphicsDevice device) { String connection = device.getConnection(); boolean deviceTried = getDeviceTried(connection); SharedResource sr; @@ -331,12 +330,12 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { } if (DEBUG) { - System.err.println("getOrCreateSharedContext() "+connection+": has shared "+(null!=sr)+", already tried "+deviceTried); + System.err.println("getOrCreateShared() "+connection+": has shared "+(null!=sr)+", already tried "+deviceTried); } if(null==sr && !deviceTried) { if (DEBUG) { - System.err.println("getOrCreateSharedContext() "+connection+": trying"); + System.err.println("getOrCreateShared() "+connection+": trying"); } addDeviceTried(connection); sharedResourcesRunner.initializeAndWait(connection); @@ -344,70 +343,74 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { sr = (SharedResource) sharedMap.get(connection); } if(DEBUG) { - Throwable t = new Throwable("getOrCreateSharedContextImpl() "+connection+": done"); + Throwable t = new Throwable("getOrCreateSharedl() "+connection+": done"); t.printStackTrace(); } } + return sr; + } + + protected final GLContext getOrCreateSharedContextImpl(AbstractGraphicsDevice device) { + SharedResource sr = getOrCreateShared(device); if(null!=sr) { return sr.context; } return null; } - protected final String getVendorName(AbstractGraphicsDevice device) { - SharedResource sr; - synchronized(sharedMap) { - sr = (SharedResource) sharedMap.get(device.getConnection()); + protected final long getOrCreateSharedDpy(AbstractGraphicsDevice device) { + SharedResource sr = getOrCreateShared(device); + if(null!=sr) { + return sr.device.getHandle(); } + return 0; + } + + protected final String getVendorName(AbstractGraphicsDevice device) { + SharedResource sr = getOrCreateShared(device); if(null!=sr) { return sr.vendorName; } - return null; + return GLXUtil.getVendorName(device.getHandle()); } protected final boolean isVendorATI(AbstractGraphicsDevice device) { - SharedResource sr; - synchronized(sharedMap) { - sr = (SharedResource) sharedMap.get(device.getConnection()); - } + SharedResource sr = getOrCreateShared(device); if(null!=sr) { return sr.isVendorATI; } - return false; + return GLXUtil.isVendorATI(device.getHandle()); } protected final boolean isVendorNVIDIA(AbstractGraphicsDevice device) { - SharedResource sr; - synchronized(sharedMap) { - sr = (SharedResource) sharedMap.get(device.getConnection()); - } + SharedResource sr = getOrCreateShared(device); if(null!=sr) { return sr.isVendorNVIDIA; } - return false; + return GLXUtil.isVendorNVIDIA(device.getHandle()); } - protected void shutdownInstance() { + protected final void shutdownInstance() { sharedResourcesRunner.releaseAndWait(); X11Util.shutdown( true, DEBUG ); } - protected GLDrawableImpl createOnscreenDrawableImpl(NativeSurface target) { + protected final GLDrawableImpl createOnscreenDrawableImpl(NativeSurface target) { if (target == null) { throw new IllegalArgumentException("Null target"); } return new X11OnscreenGLXDrawable(this, target); } - protected GLDrawableImpl createOffscreenDrawableImpl(NativeSurface target) { + protected final GLDrawableImpl createOffscreenDrawableImpl(NativeSurface target) { if (target == null) { throw new IllegalArgumentException("Null target"); } return new X11OffscreenGLXDrawable(this, target); } - public boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { + public final boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { return glxVersionGreaterEqualThan(device, 1, 3); } @@ -416,7 +419,10 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { protected final boolean glxVersionGreaterEqualThan(AbstractGraphicsDevice device, int majorReq, int minorReq) { if (!glxVersionsQueried) { if(null == device) { - device = (X11GraphicsDevice) defaultShare.screen.getDevice(); + SharedResource sr = getOrCreateShared(defaultDevice); + if(null!=sr) { + device = sr.device; + } } if(null == device) { throw new GLException("FIXME: No AbstractGraphicsDevice (passed or shared-device"); @@ -443,7 +449,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return ( glxVersionMajor > majorReq ) || ( glxVersionMajor == majorReq && glxVersionMinor >= minorReq ) ; } - protected GLDrawableImpl createGLPbufferDrawableImpl(final NativeSurface target) { + protected final GLDrawableImpl createGLPbufferDrawableImpl(final NativeSurface target) { if (target == null) { throw new IllegalArgumentException("Null target"); } @@ -459,11 +465,8 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { * The dummy context shall also use the same Display, * since switching Display in this regard is another ATI bug. */ - SharedResource sr; - synchronized(sharedMap) { - sr = (SharedResource) sharedMap.get(device.getConnection()); - } - if( sr.isVendorATI && null == GLContext.getCurrent() ) { + SharedResource sr = getOrCreateShared(device); + if( null!=sr && sr.isVendorATI && null == GLContext.getCurrent() ) { synchronized(sr.context) { sr.context.makeCurrent(); try { @@ -479,32 +482,41 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { } - protected NativeSurface createOffscreenSurfaceImpl(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) { + protected final NativeSurface createOffscreenSurfaceImpl(GLCapabilities capabilities, GLCapabilitiesChooser chooser, int width, int height) { + X11GraphicsScreen screen = null; + SharedResource sr = getOrCreateShared(defaultDevice); + if(null!=sr) { + screen = sr.screen; + } + if(null==screen) { + return null; + } + ProxySurface ns = new ProxySurface( - X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capabilities, chooser, defaultShare.screen)); + X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capabilities, chooser, screen) ); if(ns != null) { ns.setSize(width, height); } return ns; } - protected GLContext createExternalGLContextImpl() { + protected final GLContext createExternalGLContextImpl() { return X11ExternalGLXContext.create(this, null); } - public boolean canCreateExternalGLDrawable(AbstractGraphicsDevice device) { + public final boolean canCreateExternalGLDrawable(AbstractGraphicsDevice device) { return canCreateGLPbuffer(device); } - protected GLDrawable createExternalGLDrawableImpl() { + protected final GLDrawable createExternalGLDrawableImpl() { return X11ExternalGLXDrawable.create(this, null); } - public boolean canCreateContextOnJava2DSurface(AbstractGraphicsDevice device) { + public final boolean canCreateContextOnJava2DSurface(AbstractGraphicsDevice device) { return false; } - public GLContext createContextOnJava2DSurface(Object graphics, GLContext shareWith) + public final GLContext createContextOnJava2DSurface(Object graphics, GLContext shareWith) throws GLException { throw new GLException("Unimplemented on this platform"); } @@ -515,12 +527,15 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { private boolean gotGammaRampLength; private int gammaRampLength; - protected synchronized int getGammaRampLength() { + protected final synchronized int getGammaRampLength() { if (gotGammaRampLength) { return gammaRampLength; } - long display = defaultShare.screen.getDevice().getHandle(); + long display = getOrCreateSharedDpy(defaultDevice); + if(0 == display) { + return 0; + } int[] size = new int[1]; boolean res = X11Util.XF86VidModeGetGammaRampSize(display, @@ -534,14 +549,18 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return gammaRampLength; } - protected boolean setGammaRamp(float[] ramp) { + protected final boolean setGammaRamp(float[] ramp) { + long display = getOrCreateSharedDpy(defaultDevice); + if(0 == display) { + return false; + } + int len = ramp.length; short[] rampData = new short[len]; for (int i = 0; i < len; i++) { rampData[i] = (short) (ramp[i] * 65535); } - long display = defaultShare.screen.getDevice().getHandle(); boolean res = X11Util.XF86VidModeSetGammaRamp(display, X11Util.DefaultScreen(display), rampData.length, @@ -551,7 +570,12 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return res; } - protected Buffer getGammaRamp() { + protected final Buffer getGammaRamp() { + long display = getOrCreateSharedDpy(defaultDevice); + if(0 == display) { + return null; + } + int size = getGammaRampLength(); ShortBuffer rampData = ShortBuffer.wrap(new short[3 * size]); rampData.position(0); @@ -563,7 +587,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { rampData.position(2 * size); rampData.limit(3 * size); ShortBuffer blueRampData = rampData.slice(); - long display = defaultShare.screen.getDevice().getHandle(); + boolean res = X11Util.XF86VidModeGetGammaRamp(display, X11Util.DefaultScreen(display), size, @@ -576,9 +600,15 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return rampData; } - protected void resetGammaRamp(Buffer originalGammaRamp) { - if (originalGammaRamp == null) - return; // getGammaRamp failed originally + protected final void resetGammaRamp(Buffer originalGammaRamp) { + if (originalGammaRamp == null) { + return; // getGammaRamp failed originally + } + long display = getOrCreateSharedDpy(defaultDevice); + if(0 == display) { + return; + } + ShortBuffer rampData = (ShortBuffer) originalGammaRamp; int capacity = rampData.capacity(); if ((capacity % 3) != 0) { @@ -594,7 +624,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { rampData.position(2 * size); rampData.limit(3 * size); ShortBuffer blueRampData = rampData.slice(); - long display = defaultShare.screen.getDevice().getHandle(); + X11Util.XF86VidModeSetGammaRamp(display, X11Util.DefaultScreen(display), size, |