diff options
author | Sven Gothel <[email protected]> | 2009-05-30 11:39:21 +0000 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2009-05-30 11:39:21 +0000 |
commit | 522e3b3ed592d80881938cc3176d5fba5289a79f (patch) | |
tree | 2e8b83b9dd52c40cd6dd4e8af55fdbfcc1a319dd /src/jogl/classes | |
parent | 762d53cd7f94d0e558b706284de42e144c3dbcfa (diff) |
Fix Deadlock in X11AWTNativeWindowFactory (adding missing notifyAll() ; Stricten unlock(), throw an exception if not locked to make cheap coding more visible ; Removed double lock of surface and JAWT ; Adding missing try/finally block for some locks
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1921 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/jogl/classes')
3 files changed, 82 insertions, 64 deletions
diff --git a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsOnscreenWGLDrawable.java b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsOnscreenWGLDrawable.java index 32e786a2b..a5ccec377 100644 --- a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsOnscreenWGLDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsOnscreenWGLDrawable.java @@ -72,36 +72,38 @@ public class WindowsOnscreenWGLDrawable extends WindowsWGLDrawable { public void swapBuffers() throws GLException { boolean didLock = false; - if (getNativeWindow().getSurfaceHandle() == 0) { - if (lockSurface() == NativeWindow.LOCK_SURFACE_NOT_READY) { - return; - } - didLock = true; - } + try { + if (getNativeWindow().getSurfaceHandle() == 0) { + if (lockSurface() == NativeWindow.LOCK_SURFACE_NOT_READY) { + return; + } + didLock = true; + } - long startTime = 0; - if (PROFILING) { - startTime = System.currentTimeMillis(); - } + long startTime = 0; + if (PROFILING) { + startTime = System.currentTimeMillis(); + } - if (!WGL.SwapBuffers(getNativeWindow().getSurfaceHandle()) && (WGL.GetLastError() != 0)) { - throw new GLException("Error swapping buffers"); - } - - if (PROFILING) { - long endTime = System.currentTimeMillis(); - profilingSwapBuffersTime += (endTime - startTime); - int ticks = PROFILING_TICKS; - if (++profilingSwapBuffersTicks == ticks) { - System.err.println("SwapBuffers calls: " + profilingSwapBuffersTime + " ms / " + ticks + " calls (" + - ((float) profilingSwapBuffersTime / (float) ticks) + " ms/call)"); - profilingSwapBuffersTime = 0; - profilingSwapBuffersTicks = 0; - } - } + if (!WGL.SwapBuffers(getNativeWindow().getSurfaceHandle()) && (WGL.GetLastError() != 0)) { + throw new GLException("Error swapping buffers"); + } - if (didLock) { - unlockSurface(); + if (PROFILING) { + long endTime = System.currentTimeMillis(); + profilingSwapBuffersTime += (endTime - startTime); + int ticks = PROFILING_TICKS; + if (++profilingSwapBuffersTicks == ticks) { + System.err.println("SwapBuffers calls: " + profilingSwapBuffersTime + " ms / " + ticks + " calls (" + + ((float) profilingSwapBuffersTime / (float) ticks) + " ms/call)"); + profilingSwapBuffersTime = 0; + profilingSwapBuffersTicks = 0; + } + } + } finally { + if (didLock) { + unlockSurface(); + } } } diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawableFactory.java index bb284d60f..661fa9fcb 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawableFactory.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawableFactory.java @@ -212,13 +212,17 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { int[] size = new int[1]; lockToolkit(); - long display = X11Util.getDisplayConnection(); - boolean res = X11Lib.XF86VidModeGetGammaRampSize(display, - X11Lib.DefaultScreen(display), - size, 0); - unlockToolkit(); - if (!res) - return 0; + try { + long display = X11Util.getDisplayConnection(); + boolean res = X11Lib.XF86VidModeGetGammaRampSize(display, + X11Lib.DefaultScreen(display), + size, 0); + if (!res) { + return 0; + } + } finally { + unlockToolkit(); + } gotGammaRampLength = true; gammaRampLength = size[0]; return gammaRampLength; @@ -232,15 +236,18 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { } lockToolkit(); - long display = X11Util.getDisplayConnection(); - boolean res = X11Lib.XF86VidModeSetGammaRamp(display, - X11Lib.DefaultScreen(display), - rampData.length, - rampData, 0, - rampData, 0, - rampData, 0); - unlockToolkit(); - return res; + try { + long display = X11Util.getDisplayConnection(); + boolean res = X11Lib.XF86VidModeSetGammaRamp(display, + X11Lib.DefaultScreen(display), + rampData.length, + rampData, 0, + rampData, 0, + rampData, 0); + return res; + } finally { + unlockToolkit(); + } } protected Buffer getGammaRamp() { @@ -256,16 +263,20 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { rampData.limit(3 * size); ShortBuffer blueRampData = rampData.slice(); lockToolkit(); - long display = X11Util.getDisplayConnection(); - boolean res = X11Lib.XF86VidModeGetGammaRamp(display, - X11Lib.DefaultScreen(display), - size, - redRampData, - greenRampData, - blueRampData); - unlockToolkit(); - if (!res) - return null; + try { + long display = X11Util.getDisplayConnection(); + boolean res = X11Lib.XF86VidModeGetGammaRamp(display, + X11Lib.DefaultScreen(display), + size, + redRampData, + greenRampData, + blueRampData); + if (!res) { + return null; + } + } finally { + unlockToolkit(); + } return rampData; } @@ -288,13 +299,16 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { rampData.limit(3 * size); ShortBuffer blueRampData = rampData.slice(); lockToolkit(); - long display = X11Util.getDisplayConnection(); - X11Lib.XF86VidModeSetGammaRamp(display, - X11Lib.DefaultScreen(display), - size, - redRampData, - greenRampData, - blueRampData); - unlockToolkit(); + try { + long display = X11Util.getDisplayConnection(); + X11Lib.XF86VidModeSetGammaRamp(display, + X11Lib.DefaultScreen(display), + size, + redRampData, + greenRampData, + blueRampData); + } finally { + unlockToolkit(); + } } } diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXDrawable.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXDrawable.java index 6a42a53c4..b8f6cc7ef 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXDrawable.java @@ -62,19 +62,21 @@ public class X11OnscreenGLXDrawable extends X11GLXDrawable { } public void swapBuffers() throws GLException { - getFactoryImpl().lockToolkit(); + boolean didLock = false; try { if (component.getSurfaceHandle() == 0) { if (lockSurface() == NativeWindow.LOCK_SURFACE_NOT_READY) { return; } + didLock=true; } GLX.glXSwapBuffers(component.getDisplayHandle(), component.getSurfaceHandle()); } finally { - unlockSurface(); - getFactoryImpl().unlockToolkit(); + if(didLock) { + unlockSurface(); + } } } } |