aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2010-12-12 07:51:06 +0100
committerSven Gothel <[email protected]>2010-12-12 07:51:06 +0100
commit48f6568ebffdd557651460fb5f3f7f4abbca2440 (patch)
tree2cbd9cc815ab54fcd61fccae17e7d75ca6cc6d51 /src/jogl/classes/com/jogamp/opengl
parentf3512c700b2b3161eb773e77d0d41567acb710be (diff)
Windows RegisterClass: Use new RegisteredClassFactory (window class), Misc.
This solves the issue when an applet is started/stop and started again, or another applet runs in the same JVM. Also soves the issue for multiple JVMs. RegisteredClassFactory can be instanced to manage one shared window class, currently in use for GDI's dummy window and NEWT. A class base name and a window proc handle must be passed in the factory cstr. Before registering, the class is tested if already exists, eg another applet in the same JVM. If registration fails, the class name will iterate until successful or MAX_INT reached, eg if multiple JVMs are running. Added NativeWindow Common Native Code.
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java84
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java19
2 files changed, 72 insertions, 31 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java
index 920000bf1..9a93f6b33 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java
@@ -65,32 +65,21 @@ public class WindowsDummyWGLDrawable extends WindowsWGLDrawable {
}
ProxySurface ns = (ProxySurface) getNativeSurface();
ns.setSize(f_dim, f_dim);
-
- WindowsWGLGraphicsConfiguration config = (WindowsWGLGraphicsConfiguration)ns.getGraphicsConfiguration().getNativeGraphicsConfiguration();
- AbstractGraphicsDevice adevice = config.getScreen().getDevice();
- adevice.lock();
+
+ if(NativeSurface.LOCK_SURFACE_NOT_READY >= lockSurface()) {
+ throw new GLException("WindowsDummyWGLDrawable: surface not ready (lockSurface)");
+ }
try {
- if(NativeSurface.LOCK_SURFACE_NOT_READY >= ns.lockSurface()) {
- throw new GLException("WindowsDummyWGLDrawable: surface not ready (lockSurface)");
- }
- try {
- hdc = GDI.GetDC(hwnd);
- if(0 == hdc) {
- throw new GLException("Error hdc 0, werr: "+GDI.GetLastError());
- }
- ns.setSurfaceHandle(hdc);
- config.updateGraphicsConfiguration(factory, ns, null);
- if (DEBUG) {
- System.err.println("!!! WindowsDummyWGLDrawable: hdc "+toHexString(hdc)+", "+config);
- }
- } catch (Throwable t) {
- destroyImpl();
- throw new GLException(t);
- } finally {
- ns.unlockSurface();
+ WindowsWGLGraphicsConfiguration config = (WindowsWGLGraphicsConfiguration)ns.getGraphicsConfiguration().getNativeGraphicsConfiguration();
+ config.updateGraphicsConfiguration(factory, ns, null);
+ if (DEBUG) {
+ System.err.println("!!! WindowsDummyWGLDrawable: "+config);
}
+ } catch (Throwable t) {
+ destroyImpl();
+ throw new GLException(t);
} finally {
- adevice.unlock();
+ unlockSurface();
}
}
@@ -103,6 +92,53 @@ public class WindowsDummyWGLDrawable extends WindowsWGLDrawable {
return new WindowsDummyWGLDrawable(factory, caps, absScreen);
}
+ public int lockSurface() throws GLException {
+ int res = NativeSurface.LOCK_SURFACE_NOT_READY;
+ ProxySurface ns = (ProxySurface) getNativeSurface();
+ AbstractGraphicsDevice adevice = ns.getGraphicsConfiguration().getNativeGraphicsConfiguration().getScreen().getDevice();
+ adevice.lock();
+ try {
+ res = ns.lockSurface();
+ if(NativeSurface.LOCK_SUCCESS == res) {
+ if(0 == hdc) {
+ hdc = GDI.GetDC(hwnd);
+ ns.setSurfaceHandle(hdc);
+ if(0 == hdc) {
+ res = NativeSurface.LOCK_SURFACE_NOT_READY;
+ ns.unlockSurface();
+ throw new GLException("Error hdc 0, werr: "+GDI.GetLastError());
+ // finally will unlock adevice
+ }
+ }
+ } else {
+ Throwable t = new Throwable("Error lock failed - res "+res+", hwnd "+toHexString(hwnd)+", hdc "+toHexString(hdc));
+ t.printStackTrace();
+ }
+ } finally {
+ if( NativeSurface.LOCK_SURFACE_NOT_READY == res ) {
+ adevice.unlock();
+ }
+ }
+ return res;
+ }
+
+ public void unlockSurface() {
+ ProxySurface ns = (ProxySurface) getNativeSurface();
+ ns.validateSurfaceLocked();
+ AbstractGraphicsDevice adevice = ns.getGraphicsConfiguration().getNativeGraphicsConfiguration().getScreen().getDevice();
+
+ try {
+ if ( 0 != hdc && 0 != hwnd && ns.getSurfaceRecursionCount() == 0) {
+ GDI.ReleaseDC(hwnd, hdc);
+ hdc=0;
+ ns.setSurfaceHandle(hdc);
+ }
+ surface.unlockSurface();
+ } finally {
+ adevice.unlock();
+ }
+ }
+
public void setSize(int width, int height) {
}
@@ -128,7 +164,7 @@ public class WindowsDummyWGLDrawable extends WindowsWGLDrawable {
}
if (hwnd != 0) {
GDI.ShowWindow(hwnd, GDI.SW_HIDE);
- GDI.DestroyWindow(hwnd);
+ GDI.DestroyDummyWindow(hwnd);
hwnd = 0;
}
}
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 4d687a00c..eb6db0a50 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
@@ -45,8 +45,6 @@ import java.nio.ShortBuffer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import javax.media.nativewindow.AbstractGraphicsDevice;
@@ -72,6 +70,7 @@ import com.jogamp.opengl.impl.GLDrawableImpl;
import com.jogamp.opengl.impl.GLDynamicLookupHelper;
import com.jogamp.opengl.impl.SharedResourceRunner;
import javax.media.nativewindow.AbstractGraphicsConfiguration;
+import javax.media.nativewindow.windows.RegisteredClassFactory;
import javax.media.opengl.GLCapabilitiesImmutable;
public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl {
@@ -195,11 +194,16 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl {
throw new GLException("Couldn't create shared context for drawable: "+sharedDrawable);
}
sharedContext.setSynchronized(true);
+ boolean canCreateGLPbuffer;
+ boolean readDrawableAvailable;
sharedContext.makeCurrent();
- boolean canCreateGLPbuffer = sharedContext.getGL().isExtensionAvailable(GL_ARB_pbuffer);
- boolean readDrawableAvailable = sharedContext.isExtensionAvailable(WGL_ARB_make_current_read) &&
- sharedContext.isFunctionAvailable(wglMakeContextCurrent);
- sharedContext.release();
+ try {
+ canCreateGLPbuffer = sharedContext.getGL().isExtensionAvailable(GL_ARB_pbuffer);
+ readDrawableAvailable = sharedContext.isExtensionAvailable(WGL_ARB_make_current_read) &&
+ sharedContext.isFunctionAvailable(wglMakeContextCurrent);
+ } finally {
+ sharedContext.release();
+ }
if (DEBUG) {
System.err.println("!!! SharedDevice: " + sharedDevice);
System.err.println("!!! SharedScreen: " + absScreen);
@@ -231,7 +235,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl {
}
if (null != sr.drawable) {
- // may cause JVM SIGSEGV: sharedDrawable.destroy();
+ sr.drawable.destroy();
sr.drawable = null;
}
@@ -287,6 +291,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl {
protected final void shutdownInstance() {
sharedResourceRunner.releaseAndWait();
+ RegisteredClassFactory.shutdownSharedClasses();
}
protected final GLDrawableImpl createOnscreenDrawableImpl(NativeSurface target) {