aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-02-22 07:40:23 +0100
committerSven Gothel <[email protected]>2011-02-22 07:40:23 +0100
commitbb3d3743b4800d006457c767a00436b9308da75d (patch)
treefd687329fbcb7a53eab9aa1d9735f9eac7c6d22e
parentbff7e97c2f22673bb0457765696fb867d3e4f69d (diff)
NativeWindow ProxySurface Abstraction and lock/unlock Surface cleanup
- ProxySurface -> abstract javax.media.nativewindow.ProxySurface, implemented by jogamp.nativewindow.WrappedSurface, just wrapping surface handle jogamp.nativewindow.windows.GDISurface, using HWND and get/release HDC on lock/unlock - Unifying NativeSurface's lockSurface/unlockSurface implementations - NEWT's WindowImpl - NativeWindow's ProxySurface, WrappedWindow, GDIWindow and JAWTWindow - wingdi/GDI: Add 'WindowFromDC' and 'GetClientRect' to GDI
-rw-r--r--make/stub_includes/win32/windows.h3
-rw-r--r--make/stub_includes/win32/wingdi.h2
-rw-r--r--src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java4
-rw-r--r--src/jogl/classes/jogamp/opengl/egl/EGLExternalContext.java4
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java4
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXExternalCGLContext.java8
-rw-r--r--src/jogl/classes/jogamp/opengl/windows/wgl/WindowsDummyWGLDrawable.java102
-rw-r--r--src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLDrawable.java4
-rw-r--r--src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java13
-rw-r--r--src/jogl/classes/jogamp/opengl/x11/glx/X11DummyGLXDrawable.java4
-rw-r--r--src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXContext.java8
-rw-r--r--src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXDrawable.java4
-rw-r--r--src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java4
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/ProxySurface.java155
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/ProxySurface.java171
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java70
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java29
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/windows/GDISurface.java87
-rw-r--r--src/newt/classes/jogamp/newt/WindowImpl.java39
-rw-r--r--src/newt/classes/jogamp/newt/windows/WindowsWindow.java14
20 files changed, 404 insertions, 325 deletions
diff --git a/make/stub_includes/win32/windows.h b/make/stub_includes/win32/windows.h
index ddee94c06..c30f99ebd 100644
--- a/make/stub_includes/win32/windows.h
+++ b/make/stub_includes/win32/windows.h
@@ -52,3 +52,6 @@ typedef struct tagRECT {
LONG bottom;
} RECT;
+typedef RECT* PRECT;
+typedef RECT* LPRECT;
+
diff --git a/make/stub_includes/win32/wingdi.h b/make/stub_includes/win32/wingdi.h
index b169621f5..23ac428ca 100644
--- a/make/stub_includes/win32/wingdi.h
+++ b/make/stub_includes/win32/wingdi.h
@@ -191,6 +191,8 @@ WINGDIAPI HGDIOBJ WINAPI SelectObject(HDC, HGDIOBJ);
WINUSERAPI BOOL WINAPI ShowWindow(HWND hWnd, int nCmdShow);
WINUSERAPI HDC WINAPI GetDC(HWND);
WINUSERAPI int WINAPI ReleaseDC(HWND hWnd, HDC hDC);
+WINUSERAPI HWND WINAPI WindowFromDC(HDC hDC); // avail in >= Win2k
+WINUSERAPI BOOL WINAPI GetClientRect(HWND hwnd, LPRECT lpRect);
WINUSERAPI BOOL WINAPI DestroyWindow(HWND hWnd);
WINUSERAPI DWORD WINAPI GetObjectType(HGDIOBJ h);
diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java
index b6f5dabd3..f81e5a70e 100644
--- a/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java
+++ b/src/jogl/classes/jogamp/opengl/egl/EGLDrawableFactory.java
@@ -43,7 +43,7 @@ import javax.media.opengl.*;
import com.jogamp.common.JogampRuntimeException;
import com.jogamp.common.util.*;
import jogamp.opengl.*;
-import jogamp.nativewindow.ProxySurface;
+import jogamp.nativewindow.WrappedSurface;
import java.util.HashMap;
import java.util.List;
@@ -220,7 +220,7 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl {
}
protected NativeSurface createOffscreenSurfaceImpl(AbstractGraphicsDevice device, GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser, int width, int height) {
- ProxySurface ns = new ProxySurface(EGLGraphicsConfigurationFactory.createOffscreenGraphicsConfiguration(device, capsChosen, capsRequested, chooser));
+ WrappedSurface ns = new WrappedSurface(EGLGraphicsConfigurationFactory.createOffscreenGraphicsConfiguration(device, capsChosen, capsRequested, chooser));
ns.setSize(width, height);
return ns;
}
diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLExternalContext.java b/src/jogl/classes/jogamp/opengl/egl/EGLExternalContext.java
index 78c23f710..dd06dc148 100644
--- a/src/jogl/classes/jogamp/opengl/egl/EGLExternalContext.java
+++ b/src/jogl/classes/jogamp/opengl/egl/EGLExternalContext.java
@@ -40,7 +40,6 @@ import jogamp.opengl.*;
import javax.media.nativewindow.*;
public class EGLExternalContext extends EGLContext {
- private boolean firstMakeCurrent = true;
private GLContext lastContext;
public EGLExternalContext(AbstractGraphicsScreen screen) {
@@ -68,9 +67,6 @@ public class EGLExternalContext extends EGLContext {
}
protected void makeCurrentImpl(boolean newCreated) throws GLException {
- if (firstMakeCurrent) {
- firstMakeCurrent = false;
- }
}
protected void releaseImpl() throws GLException {
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java
index 19f3ce640..8e27c217b 100644
--- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java
+++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java
@@ -51,7 +51,7 @@ import javax.media.opengl.*;
import com.jogamp.common.JogampRuntimeException;
import com.jogamp.common.util.*;
import jogamp.opengl.*;
-import jogamp.nativewindow.ProxySurface;
+import jogamp.nativewindow.WrappedSurface;
public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl {
private static final DesktopGLDynamicLookupHelper macOSXCGLDynamicLookupHelper;
@@ -167,7 +167,7 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl {
protected NativeSurface createOffscreenSurfaceImpl(AbstractGraphicsDevice device,GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser, int width, int height) {
AbstractGraphicsScreen screen = DefaultGraphicsScreen.createDefault(NativeWindowFactory.TYPE_MACOSX);
- ProxySurface ns = new ProxySurface(MacOSXCGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capsChosen, capsRequested, chooser, screen, true));
+ WrappedSurface ns = new WrappedSurface(MacOSXCGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capsChosen, capsRequested, chooser, screen, true));
ns.setSize(width, height);
return ns;
}
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXExternalCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXExternalCGLContext.java
index e0ee8ea73..af055913d 100644
--- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXExternalCGLContext.java
+++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXExternalCGLContext.java
@@ -44,10 +44,9 @@ import javax.media.opengl.*;
import jogamp.opengl.*;
import javax.media.nativewindow.*;
-import jogamp.nativewindow.ProxySurface;
+import jogamp.nativewindow.WrappedSurface;
public class MacOSXExternalCGLContext extends MacOSXCGLContext {
- private boolean firstMakeCurrent = true;
private GLContext lastContext;
private MacOSXExternalCGLContext(Drawable drawable, boolean isNSContext, long handle) {
@@ -100,7 +99,7 @@ public class MacOSXExternalCGLContext extends MacOSXCGLContext {
AbstractGraphicsScreen aScreen = DefaultGraphicsScreen.createDefault(NativeWindowFactory.TYPE_MACOSX);
MacOSXCGLGraphicsConfiguration cfg = new MacOSXCGLGraphicsConfiguration(aScreen, caps, caps, pixelFormat);
- ProxySurface ns = new ProxySurface(cfg);
+ WrappedSurface ns = new WrappedSurface(cfg);
ns.setSurfaceHandle(currentDrawable);
return new MacOSXExternalCGLContext(new Drawable(factory, ns), isNSContext, contextHandle);
}
@@ -127,9 +126,6 @@ public class MacOSXExternalCGLContext extends MacOSXCGLContext {
}
protected void makeCurrentImpl(boolean newCreated) throws GLException {
- if (firstMakeCurrent) {
- firstMakeCurrent = false;
- }
}
protected void releaseImpl() throws GLException {
diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsDummyWGLDrawable.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsDummyWGLDrawable.java
index 27d7b342e..3d0cce725 100644
--- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsDummyWGLDrawable.java
+++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsDummyWGLDrawable.java
@@ -45,29 +45,21 @@ import javax.media.opengl.GLDrawableFactory;
import javax.media.opengl.GLProfile;
import javax.media.nativewindow.AbstractGraphicsScreen;
-import jogamp.nativewindow.ProxySurface;
import jogamp.nativewindow.windows.GDI;
-import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.nativewindow.NativeSurface;
import javax.media.opengl.GLCapabilities;
-import javax.media.opengl.GLCapabilitiesImmutable;
import javax.media.opengl.GLException;
+import jogamp.nativewindow.windows.GDISurface;
public class WindowsDummyWGLDrawable extends WindowsWGLDrawable {
- private static final int f_dim = 64;
- private long hwnd, hdc;
+ private long hwnd;
+ private boolean handleHwndLifecycle;
- protected WindowsDummyWGLDrawable(GLDrawableFactory factory, GLCapabilitiesImmutable caps, AbstractGraphicsScreen absScreen) {
- super(factory, new ProxySurface(WindowsWGLGraphicsConfigurationFactory.createDefaultGraphicsConfiguration(caps, absScreen)), true);
- hwnd = GDI.CreateDummyWindow(0, 0, f_dim, f_dim);
- if(0 == hwnd) {
- throw new GLException("Error hwnd 0, werr: "+GDI.GetLastError());
- }
- // manual debug only - GDI.ShowWindow(hwnd, GDI.SW_SHOW);
- ProxySurface ns = (ProxySurface) getNativeSurface();
- ns.setSize(f_dim, f_dim);
+ private WindowsDummyWGLDrawable(GLDrawableFactory factory, GDISurface ns, boolean handleHwndLifecycle) {
+ super(factory, ns, true);
+ this.handleHwndLifecycle = handleHwndLifecycle;
- if(NativeSurface.LOCK_SURFACE_NOT_READY >= lockSurface()) {
+ if(NativeSurface.LOCK_SURFACE_NOT_READY >= ns.lockSurface()) {
throw new GLException("WindowsDummyWGLDrawable: surface not ready (lockSurface)");
}
try {
@@ -84,70 +76,16 @@ public class WindowsDummyWGLDrawable extends WindowsWGLDrawable {
}
}
- public static WindowsDummyWGLDrawable create(GLDrawableFactory factory, GLProfile glp, AbstractGraphicsScreen absScreen) {
- GLCapabilities caps = new GLCapabilities(glp);
- caps.setDepthBits(16);
- caps.setDoubleBuffered(true);
- caps.setOnscreen (true);
- 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();
- }
+ public static WindowsDummyWGLDrawable create(GLDrawableFactory factory, GLProfile glp, AbstractGraphicsScreen absScreen,
+ long windowHandle, int width, int height, boolean handleWindowLifecycle) {
+ if(0 == windowHandle) {
+ throw new GLException("Error windowHandle 0, werr: "+GDI.GetLastError());
}
- 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) {
- }
-
- public int getWidth() {
- return 1;
- }
-
- public int getHeight() {
- return 1;
+ GLCapabilities caps = new GLCapabilities(glp);
+ WindowsWGLGraphicsConfiguration cfg = WindowsWGLGraphicsConfigurationFactory.createDefaultGraphicsConfiguration(caps, absScreen);
+ GDISurface ns = new GDISurface(cfg, windowHandle);
+ ns.setSize(width, height);
+ return new WindowsDummyWGLDrawable(factory, ns, handleWindowLifecycle);
}
public GLContext createContext(GLContext shareWith) {
@@ -156,13 +94,7 @@ public class WindowsDummyWGLDrawable extends WindowsWGLDrawable {
}
protected void destroyImpl() {
- if (hdc != 0) {
- GDI.ReleaseDC(hwnd, hdc);
- hdc = 0;
- ProxySurface ns = (ProxySurface) getNativeSurface();
- ns.setSurfaceHandle(hdc);
- }
- if (hwnd != 0) {
+ if (handleHwndLifecycle && hwnd != 0) {
GDI.ShowWindow(hwnd, GDI.SW_HIDE);
GDI.DestroyDummyWindow(hwnd);
hwnd = 0;
diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLDrawable.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLDrawable.java
index 742a42709..7666ae350 100644
--- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLDrawable.java
+++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsExternalWGLDrawable.java
@@ -49,7 +49,7 @@ import javax.media.opengl.GLDrawableFactory;
import javax.media.opengl.GLException;
import javax.media.opengl.GLProfile;
-import jogamp.nativewindow.ProxySurface;
+import jogamp.nativewindow.WrappedSurface;
import jogamp.nativewindow.windows.GDI;
public class WindowsExternalWGLDrawable extends WindowsWGLDrawable {
@@ -70,7 +70,7 @@ public class WindowsExternalWGLDrawable extends WindowsWGLDrawable {
AbstractGraphicsScreen aScreen = DefaultGraphicsScreen.createDefault(NativeWindowFactory.TYPE_WINDOWS);
WindowsWGLGraphicsConfiguration cfg = WindowsWGLGraphicsConfiguration.createFromCurrent(factory, hdc, pfdID, glp, aScreen, true);
- return new WindowsExternalWGLDrawable(factory, new ProxySurface(cfg, hdc));
+ return new WindowsExternalWGLDrawable(factory, new WrappedSurface(cfg, hdc));
}
diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java
index 2c078dd98..5afbb9218 100644
--- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java
+++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java
@@ -51,6 +51,7 @@ import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.nativewindow.AbstractGraphicsScreen;
import javax.media.nativewindow.DefaultGraphicsScreen;
import javax.media.nativewindow.NativeSurface;
+import javax.media.nativewindow.ProxySurface;
import javax.media.nativewindow.NativeWindowFactory;
import javax.media.nativewindow.windows.WindowsGraphicsDevice;
import javax.media.nativewindow.AbstractGraphicsConfiguration;
@@ -64,11 +65,11 @@ import javax.media.opengl.GLProfile;
import com.jogamp.common.JogampRuntimeException;
import com.jogamp.common.nio.PointerBuffer;
import com.jogamp.common.util.ReflectionUtil;
-import jogamp.nativewindow.ProxySurface;
+import jogamp.nativewindow.WrappedSurface;
import jogamp.nativewindow.windows.GDI;
+import jogamp.nativewindow.windows.GDISurface;
import jogamp.nativewindow.windows.RegisteredClassFactory;
import jogamp.opengl.DesktopGLDynamicLookupHelper;
-import jogamp.opengl.GLContextImpl;
import jogamp.opengl.GLDrawableFactoryImpl;
import jogamp.opengl.GLDrawableImpl;
import jogamp.opengl.GLDynamicLookupHelper;
@@ -228,7 +229,9 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl {
if (null == glp) {
throw new GLException("Couldn't get default GLProfile for device: "+sharedDevice);
}
- WindowsDummyWGLDrawable sharedDrawable = WindowsDummyWGLDrawable.create(WindowsWGLDrawableFactory.this, glp, absScreen);
+ final int f_dim = 64;
+ long hwnd = GDI.CreateDummyWindow(0, 0, f_dim, f_dim);
+ WindowsDummyWGLDrawable sharedDrawable = WindowsDummyWGLDrawable.create(WindowsWGLDrawableFactory.this, glp, absScreen, hwnd, f_dim, f_dim, true);
if (null == sharedDrawable) {
throw new GLException("Couldn't create shared drawable for screen: "+absScreen+", "+glp);
}
@@ -434,9 +437,9 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl {
return false;
}
- protected final NativeSurface createOffscreenSurfaceImpl(AbstractGraphicsDevice device,GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser, int width, int height) {
+ protected final NativeSurface createOffscreenSurfaceImpl(AbstractGraphicsDevice device, GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser, int width, int height) {
AbstractGraphicsScreen screen = DefaultGraphicsScreen.createDefault(NativeWindowFactory.TYPE_WINDOWS);
- ProxySurface ns = new ProxySurface(WindowsWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(
+ WrappedSurface ns = new WrappedSurface(WindowsWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(
capsChosen, capsRequested, chooser, screen) );
ns.setSize(width, height);
return ns;
diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11DummyGLXDrawable.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11DummyGLXDrawable.java
index 202bba9e7..68bdb4ab8 100644
--- a/src/jogl/classes/jogamp/opengl/x11/glx/X11DummyGLXDrawable.java
+++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11DummyGLXDrawable.java
@@ -45,11 +45,11 @@ public class X11DummyGLXDrawable extends X11OnscreenGLXDrawable {
*/
public X11DummyGLXDrawable(X11GraphicsScreen screen, GLDrawableFactory factory, GLCapabilitiesImmutable caps) {
super(factory,
- new ProxySurface(X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(
+ new WrappedSurface(X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(
caps, caps, null, screen)));
this.realized = true;
- ProxySurface ns = (ProxySurface) getNativeSurface();
+ WrappedSurface ns = (WrappedSurface) getNativeSurface();
X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)ns.getGraphicsConfiguration().getNativeGraphicsConfiguration();
X11GraphicsDevice device = (X11GraphicsDevice) screen.getDevice();
diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXContext.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXContext.java
index 769d5f1da..c488fe5cf 100644
--- a/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXContext.java
+++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXContext.java
@@ -44,10 +44,9 @@ import javax.media.nativewindow.*;
import javax.media.nativewindow.x11.*;
import javax.media.opengl.*;
import jogamp.opengl.*;
-import jogamp.nativewindow.ProxySurface;
+import jogamp.nativewindow.WrappedSurface;
public class X11ExternalGLXContext extends X11GLXContext {
- private boolean firstMakeCurrent = true;
private GLContext lastContext;
private X11ExternalGLXContext(Drawable drawable, long ctx) {
@@ -78,7 +77,7 @@ public class X11ExternalGLXContext extends X11GLXContext {
GLX.glXQueryContext(display, ctx, GLX.GLX_FBCONFIG_ID, val, 0);
X11GLXGraphicsConfiguration cfg = X11GLXGraphicsConfiguration.create(glp, x11Screen, val[0]);
- ProxySurface ns = new ProxySurface(cfg);
+ WrappedSurface ns = new WrappedSurface(cfg);
ns.setSurfaceHandle(drawable);
return new X11ExternalGLXContext(new Drawable(factory, ns), ctx);
}
@@ -105,9 +104,6 @@ public class X11ExternalGLXContext extends X11GLXContext {
}
protected void makeCurrentImpl(boolean newCreated) throws GLException {
- if (firstMakeCurrent) {
- firstMakeCurrent = false;
- }
}
protected void releaseImpl() throws GLException {
diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXDrawable.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXDrawable.java
index 014992b88..eb286cdf0 100644
--- a/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXDrawable.java
+++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11ExternalGLXDrawable.java
@@ -42,7 +42,7 @@ package jogamp.opengl.x11.glx;
import javax.media.nativewindow.*;
import javax.media.nativewindow.x11.*;
import javax.media.opengl.*;
-import jogamp.nativewindow.ProxySurface;
+import jogamp.nativewindow.WrappedSurface;
public class X11ExternalGLXDrawable extends X11GLXDrawable {
@@ -83,7 +83,7 @@ public class X11ExternalGLXDrawable extends X11GLXDrawable {
System.err.println("X11ExternalGLXDrawable: WARNING: forcing GLX_RGBA_TYPE for newly created contexts (current 0x"+Integer.toHexString(val[0])+")");
}
}
- ProxySurface ns = new ProxySurface(cfg);
+ WrappedSurface ns = new WrappedSurface(cfg);
ns.setSurfaceHandle(drawable);
ns.setSize(w, h);
return new X11ExternalGLXDrawable(factory, ns);
diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java
index 44ade1513..755c078b9 100644
--- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java
+++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java
@@ -49,7 +49,7 @@ import javax.media.opengl.*;
import jogamp.opengl.*;
import com.jogamp.common.JogampRuntimeException;
import com.jogamp.common.util.*;
-import jogamp.nativewindow.ProxySurface;
+import jogamp.nativewindow.WrappedSurface;
import jogamp.nativewindow.x11.*;
public class X11GLXDrawableFactory extends GLDrawableFactoryImpl {
@@ -399,7 +399,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl {
return null;
}
- ProxySurface ns = new ProxySurface(
+ WrappedSurface ns = new WrappedSurface(
X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capsChosen, capsRequested, chooser, screen) );
if(ns != null) {
ns.setSize(width, height);
diff --git a/src/nativewindow/classes/javax/media/nativewindow/ProxySurface.java b/src/nativewindow/classes/javax/media/nativewindow/ProxySurface.java
new file mode 100644
index 000000000..386ba32f4
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/ProxySurface.java
@@ -0,0 +1,155 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package javax.media.nativewindow;
+
+import com.jogamp.common.util.locks.RecursiveLock;
+
+public abstract class ProxySurface implements NativeSurface {
+ protected RecursiveLock recurLock = new RecursiveLock();
+ protected AbstractGraphicsConfiguration config;
+ protected long displayHandle;
+ protected int height;
+ protected int scrnIndex;
+ protected int width;
+
+ public ProxySurface(AbstractGraphicsConfiguration cfg) {
+ invalidate();
+ config = cfg;
+ displayHandle=cfg.getScreen().getDevice().getHandle();
+ }
+
+ public final void invalidate() {
+ recurLock.lock();
+ try {
+ displayHandle = 0;
+ invalidateImpl();
+ } finally {
+ recurLock.unlock();
+ }
+ }
+ protected abstract void invalidateImpl();
+
+ public final long getDisplayHandle() {
+ return displayHandle;
+ }
+
+ public final AbstractGraphicsConfiguration getGraphicsConfiguration() {
+ return config;
+ }
+
+ public final int getScreenIndex() {
+ return config.getScreen().getIndex();
+ }
+
+ public abstract long getSurfaceHandle();
+
+ public final int getWidth() {
+ return width;
+ }
+
+ public final int getHeight() {
+ return height;
+ }
+
+ public void setSize(int width, int height) {
+ this.width = width;
+ this.height = height;
+ }
+
+ public boolean surfaceSwap() {
+ return false;
+ }
+
+ public void surfaceUpdated(Object updater, NativeSurface ns, long when) {
+ }
+
+ public int lockSurface() throws NativeWindowException {
+ recurLock.lock();
+ int res = recurLock.getRecursionCount() == 0 ? LOCK_SURFACE_NOT_READY : LOCK_SUCCESS;
+
+ if ( LOCK_SURFACE_NOT_READY == res ) {
+ try {
+ final AbstractGraphicsDevice adevice = config.getScreen().getDevice();
+ adevice.lock();
+ try {
+ res = lockSurfaceImpl();
+ } finally {
+ if (LOCK_SURFACE_NOT_READY >= res) {
+ adevice.unlock();
+ }
+ }
+ } finally {
+ if (LOCK_SURFACE_NOT_READY >= res) {
+ recurLock.unlock();
+ }
+ }
+ }
+ return res;
+ }
+
+ public final void unlockSurface() {
+ recurLock.validateLocked();
+
+ if (recurLock.getRecursionCount() == 0) {
+ final AbstractGraphicsDevice adevice = config.getScreen().getDevice();
+ try {
+ unlockSurfaceImpl();
+ } finally {
+ adevice.unlock();
+ }
+ }
+ recurLock.unlock();
+ }
+
+ protected abstract int lockSurfaceImpl();
+
+ protected abstract void unlockSurfaceImpl() ;
+
+ public final void validateSurfaceLocked() {
+ recurLock.validateLocked();
+ }
+
+ public final boolean isSurfaceLocked() {
+ return recurLock.isLocked();
+ }
+
+ public final boolean isSurfaceLockedByOtherThread() {
+ return recurLock.isLockedByOtherThread();
+ }
+
+ public final Thread getSurfaceLockOwner() {
+ return recurLock.getOwner();
+ }
+
+ public final int getSurfaceRecursionCount() {
+ return recurLock.getRecursionCount();
+ }
+
+ public abstract String toString();
+}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/ProxySurface.java b/src/nativewindow/classes/jogamp/nativewindow/ProxySurface.java
deleted file mode 100644
index 6dfbb2a91..000000000
--- a/src/nativewindow/classes/jogamp/nativewindow/ProxySurface.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
- * Copyright (c) 2010 JogAmp Community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed or intended for use
- * in the design, construction, operation or maintenance of any nuclear
- * facility.
- */
-
-package jogamp.nativewindow;
-
-import javax.media.nativewindow.AbstractGraphicsConfiguration;
-import javax.media.nativewindow.NativeSurface;
-import javax.media.nativewindow.NativeWindow;
-import javax.media.nativewindow.NativeWindowException;
-import javax.media.nativewindow.SurfaceChangeable;
-
-import com.jogamp.common.util.locks.RecursiveLock;
-
-public class ProxySurface implements NativeSurface, SurfaceChangeable {
- private RecursiveLock recurLock = new RecursiveLock();
- protected AbstractGraphicsConfiguration config;
- protected long displayHandle;
- protected long surfaceHandle;
- protected int scrnIndex;
- protected int width, height;
-
- public ProxySurface(AbstractGraphicsConfiguration cfg) {
- this(cfg, 0);
- }
-
- public ProxySurface(AbstractGraphicsConfiguration cfg, long handle) {
- invalidate();
- config = cfg;
- displayHandle=cfg.getScreen().getDevice().getHandle();
- surfaceHandle=handle;
- scrnIndex=cfg.getScreen().getIndex();
- }
-
- protected void init(Object windowObject) throws NativeWindowException {
- }
-
- protected void initNative() throws NativeWindowException {
- }
-
- public NativeWindow getParent() {
- return null;
- }
-
- public void destroy() {
- invalidate();
- }
-
- public synchronized void invalidate() {
- displayHandle=0;
- scrnIndex=-1;
- surfaceHandle=0;
- }
-
- public final int lockSurface() throws NativeWindowException {
- recurLock.lock();
-
- if(recurLock.getRecursionCount() == 0) {
- config.getScreen().getDevice().lock();
- }
- return LOCK_SUCCESS;
- }
-
- public final void unlockSurface() {
- recurLock.validateLocked();
-
- if(recurLock.getRecursionCount()==0) {
- config.getScreen().getDevice().unlock();
- }
- recurLock.unlock();
- }
-
- public final void validateSurfaceLocked() {
- recurLock.validateLocked();
- }
-
- public final int getSurfaceRecursionCount() {
- return recurLock.getRecursionCount();
- }
-
- public final boolean isSurfaceLockedByOtherThread() {
- return recurLock.isLockedByOtherThread();
- }
-
- public final boolean isSurfaceLocked() {
- return recurLock.isLocked();
- }
-
- public final Thread getSurfaceLockOwner() {
- return recurLock.getOwner();
- }
-
- public boolean surfaceSwap() {
- return false;
- }
-
- public long getSurfaceHandle() {
- return surfaceHandle;
- }
-
- public int getWidth() {
- return width;
- }
-
- public int getHeight() {
- return height;
- }
-
- public AbstractGraphicsConfiguration getGraphicsConfiguration() {
- return config;
- }
-
- public void surfaceUpdated(Object updater, NativeSurface ns, long when) { }
-
- public long getDisplayHandle() {
- return displayHandle;
- }
- public int getScreenIndex() {
- return scrnIndex;
- }
-
- public void setSurfaceHandle(long surfaceHandle) {
- this.surfaceHandle=surfaceHandle;
- }
-
- public void setSize(int width, int height) {
- this.width=width;
- this.height=height;
- }
-
- public String toString() {
- return "ProxySurface[config "+config+
- ", displayHandle 0x"+Long.toHexString(getDisplayHandle())+
- ", surfaceHandle 0x"+Long.toHexString(getSurfaceHandle())+
- ", size "+getWidth()+"x"+getHeight()+"]";
- }
-
-}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java b/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java
new file mode 100644
index 000000000..4c2b1c875
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java
@@ -0,0 +1,70 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package jogamp.nativewindow;
+
+import javax.media.nativewindow.AbstractGraphicsConfiguration;
+import javax.media.nativewindow.ProxySurface;
+import javax.media.nativewindow.SurfaceChangeable;
+
+
+public class WrappedSurface extends ProxySurface implements SurfaceChangeable {
+ protected long surfaceHandle;
+
+ public WrappedSurface(AbstractGraphicsConfiguration cfg) {
+ this(cfg, 0);
+ }
+
+ public WrappedSurface(AbstractGraphicsConfiguration cfg, long handle) {
+ super(cfg);
+ surfaceHandle=handle;
+ }
+
+ protected final void invalidateImpl() {
+ surfaceHandle = 0;
+ }
+
+ public long getSurfaceHandle() {
+ return surfaceHandle;
+ }
+
+ public void setSurfaceHandle(long surfaceHandle) {
+ this.surfaceHandle=surfaceHandle;
+ }
+
+ protected int lockSurfaceImpl() {
+ return LOCK_SUCCESS;
+ }
+
+ protected void unlockSurfaceImpl() {
+ }
+
+ public String toString() {
+ return "WrappedSurface[config " + config + ", displayHandle 0x" + Long.toHexString(getDisplayHandle()) + ", surfaceHandle 0x" + Long.toHexString(getSurfaceHandle()) + ", size " + getWidth() + "x" + getHeight() + "]";
+ }
+}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java
index 944c08604..0f7f1ee62 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java
@@ -42,6 +42,7 @@ import com.jogamp.common.util.locks.RecursiveLock;
import java.awt.Component;
import java.awt.Window;
import javax.media.nativewindow.AbstractGraphicsConfiguration;
+import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.nativewindow.NativeSurface;
import javax.media.nativewindow.NativeWindow;
import javax.media.nativewindow.NativeWindowException;
@@ -111,25 +112,26 @@ public abstract class JAWTWindow implements NativeWindow {
protected abstract int lockSurfaceImpl() throws NativeWindowException;
public final int lockSurface() throws NativeWindowException {
- int res = LOCK_SURFACE_NOT_READY;
-
recurLock.lock();
+ int res = recurLock.getRecursionCount() == 0 ? LOCK_SURFACE_NOT_READY : LOCK_SUCCESS;
- if(recurLock.getRecursionCount() == 0) {
- config.getScreen().getDevice().lock();
+ if ( LOCK_SURFACE_NOT_READY == res ) {
try {
- res = lockSurfaceImpl();
+ final AbstractGraphicsDevice adevice = config.getScreen().getDevice();
+ adevice.lock();
+ try {
+ res = lockSurfaceImpl();
+ } finally {
+ if (LOCK_SURFACE_NOT_READY >= res) {
+ adevice.unlock();
+ }
+ }
} finally {
- // Unlock in case surface couldn't be locked
- if(LOCK_SURFACE_NOT_READY >= res ) {
- config.getScreen().getDevice().unlock();
+ if (LOCK_SURFACE_NOT_READY >= res) {
recurLock.unlock();
}
}
- } else {
- res = LOCK_SUCCESS;
}
-
return res;
}
@@ -138,11 +140,12 @@ public abstract class JAWTWindow implements NativeWindow {
public final void unlockSurface() {
recurLock.validateLocked();
- if(recurLock.getRecursionCount()==0) {
+ if (recurLock.getRecursionCount() == 0) {
+ final AbstractGraphicsDevice adevice = config.getScreen().getDevice();
try {
unlockSurfaceImpl();
} finally {
- config.getScreen().getDevice().unlock();
+ adevice.unlock();
}
}
recurLock.unlock();
diff --git a/src/nativewindow/classes/jogamp/nativewindow/windows/GDISurface.java b/src/nativewindow/classes/jogamp/nativewindow/windows/GDISurface.java
new file mode 100644
index 000000000..68cf8af45
--- /dev/null
+++ b/src/nativewindow/classes/jogamp/nativewindow/windows/GDISurface.java
@@ -0,0 +1,87 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package jogamp.nativewindow.windows;
+
+import javax.media.nativewindow.AbstractGraphicsConfiguration;
+import javax.media.nativewindow.NativeWindowException;
+
+import javax.media.nativewindow.ProxySurface;
+
+/**
+ * GDI Surface implementation which wraps an existing window handle
+ * allowing the use of HDC via lockSurface()/unlockSurface() protocol.
+ * The latter will get and release the HDC.
+ * The size via getWidth()/getHeight() is invalid.
+ */
+public class GDISurface extends ProxySurface {
+ protected long windowHandle;
+ protected long surfaceHandle;
+
+ public GDISurface(AbstractGraphicsConfiguration cfg, long windowHandle) {
+ super(cfg);
+ if(0 == windowHandle) {
+ throw new NativeWindowException("Error hwnd 0, werr: "+GDI.GetLastError());
+ }
+ this.windowHandle=windowHandle;
+ }
+
+ protected final void invalidateImpl() {
+ windowHandle=0;
+ surfaceHandle=0;
+ }
+
+ protected int lockSurfaceImpl() {
+ if (0 != surfaceHandle) {
+ throw new InternalError("surface not released");
+ }
+ surfaceHandle = GDI.GetDC(windowHandle);
+ return (0 != surfaceHandle) ? LOCK_SUCCESS : LOCK_SURFACE_NOT_READY;
+ }
+
+ protected void unlockSurfaceImpl() {
+ if (0 == surfaceHandle) {
+ throw new InternalError("surface not acquired");
+ }
+ GDI.ReleaseDC(windowHandle, surfaceHandle);
+ surfaceHandle=0;
+ }
+
+ public long getSurfaceHandle() {
+ return surfaceHandle;
+ }
+
+ public String toString() {
+ return "GDISurface[config "+config+
+ ", displayHandle 0x"+Long.toHexString(getDisplayHandle())+
+ ", windowHandle 0x"+Long.toHexString(windowHandle)+
+ ", surfaceHandle 0x"+Long.toHexString(getSurfaceHandle())+
+ ", size "+getWidth()+"x"+getHeight()+"]";
+ }
+
+}
diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java
index 79679b7b3..b0991b748 100644
--- a/src/newt/classes/jogamp/newt/WindowImpl.java
+++ b/src/newt/classes/jogamp/newt/WindowImpl.java
@@ -463,36 +463,41 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
//
public final int lockSurface() {
- int res = LOCK_SURFACE_NOT_READY;
windowLock.lock();
+ int res = windowLock.getRecursionCount() == 0 ? LOCK_SURFACE_NOT_READY : LOCK_SUCCESS;
- if(isNativeValid()) {
- AbstractGraphicsDevice adevice = screen.getDisplay().getGraphicsDevice();
- adevice.lock();
+ if ( LOCK_SURFACE_NOT_READY == res ) {
try {
- res = lockSurfaceImpl();
+ if( isNativeValid() ) {
+ final AbstractGraphicsDevice adevice = config.getScreen().getDevice();
+ adevice.lock();
+ try {
+ res = lockSurfaceImpl();
+ } finally {
+ if (LOCK_SURFACE_NOT_READY >= res) {
+ adevice.unlock();
+ }
+ }
+ }
} finally {
- if( LOCK_SURFACE_NOT_READY == res ) {
- adevice.unlock();
+ if (LOCK_SURFACE_NOT_READY >= res) {
+ windowLock.unlock();
}
}
}
- if( LOCK_SURFACE_NOT_READY == res ) {
- windowLock.unlock();
- }
-
return res;
}
public final void unlockSurface() {
- // may throw RuntimeException if not locked
windowLock.validateLocked();
- AbstractGraphicsDevice adevice = screen.getDisplay().getGraphicsDevice();
- try {
- unlockSurfaceImpl();
- } finally {
- adevice.unlock();
+ if (windowLock.getRecursionCount() == 0) {
+ final AbstractGraphicsDevice adevice = config.getScreen().getDevice();
+ try {
+ unlockSurfaceImpl();
+ } finally {
+ adevice.unlock();
+ }
}
windowLock.unlock();
}
diff --git a/src/newt/classes/jogamp/newt/windows/WindowsWindow.java b/src/newt/classes/jogamp/newt/windows/WindowsWindow.java
index d820be529..05d169c5e 100644
--- a/src/newt/classes/jogamp/newt/windows/WindowsWindow.java
+++ b/src/newt/classes/jogamp/newt/windows/WindowsWindow.java
@@ -56,18 +56,20 @@ public class WindowsWindow extends WindowImpl {
}
protected int lockSurfaceImpl() {
- if( 0 != getWindowHandle() && 0 == hdc ) {
- hdc = GDI.GetDC(getWindowHandle());
- hmon = MonitorFromWindow0(getWindowHandle());
+ if (0 != hdc) {
+ throw new InternalError("surface not released");
}
+ hdc = GDI.GetDC(getWindowHandle());
+ hmon = MonitorFromWindow0(getWindowHandle());
return ( 0 != hdc ) ? LOCK_SUCCESS : LOCK_SURFACE_NOT_READY;
}
protected void unlockSurfaceImpl() {
- if ( 0 != hdc && 0 != getWindowHandle() && getWindowLockRecursionCount() == 0) {
- GDI.ReleaseDC(getWindowHandle(), hdc);
- hdc=0;
+ if (0 == hdc) {
+ throw new InternalError("surface not acquired");
}
+ GDI.ReleaseDC(getWindowHandle(), hdc);
+ hdc=0;
}
public final long getSurfaceHandle() {