From 9969889de2cde06e724b25b6da1e29354e303915 Mon Sep 17 00:00:00 2001
From: Sven Gothel
- *
- * The surface handle, see {@link #lockSurface()},
- *
+ * Lock the surface of this native window.
+ *
+ * The surface handle shall be valid after a successfull call,
+ * ie return a value other than {@link #LOCK_SURFACE_UNLOCKED} and {@link #LOCK_SURFACE_NOT_READY},
+ * which is
+ *
- * shall be valid after a successfull call,
- * ie return a value other than {@link #LOCK_SURFACE_NOT_READY}.
+ * boolean ok = lockSurface() > LOCK_SURFACE_NOT_READY;
+ *
+ *
+ * The caller may need to take care of the result {@link #LOCK_SURFACE_CHANGED}, + * where the surface handle is valid but has changed. + *
+ ** This call is blocking until the surface has been locked - * or a timeout is reached. The latter will throw a runtime exception.
- * - * This call allows recursion from the same thread.
- * + * or a timeout is reached. The latter will throw a runtime exception. + *
+ *+ * This call allows recursion from the same thread. + *
+ ** The implementation may want to aquire the * application level {@link com.jogamp.common.util.locks.RecursiveLock} - * first before proceeding with a native surface lock.
- * + * first before proceeding with a native surface lock. + *
+ ** The implementation shall also invoke {@link AbstractGraphicsDevice#lock()} - * for the initial lock (recursive count zero).
+ * for the initial lock (recursive count zero). + *
* * @return {@link #LOCK_SUCCESS}, {@link #LOCK_SURFACE_CHANGED} or {@link #LOCK_SURFACE_NOT_READY}. * diff --git a/src/nativewindow/classes/javax/media/nativewindow/ProxySurface.java b/src/nativewindow/classes/javax/media/nativewindow/ProxySurface.java index 9100beac2..6a36bb130 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/ProxySurface.java +++ b/src/nativewindow/classes/javax/media/nativewindow/ProxySurface.java @@ -28,15 +28,20 @@ package javax.media.nativewindow; + +import jogamp.nativewindow.Debug; import jogamp.nativewindow.SurfaceUpdatedHelper; import com.jogamp.common.util.locks.LockFactory; import com.jogamp.common.util.locks.RecursiveLock; public abstract class ProxySurface implements NativeSurface { + public static final boolean DEBUG = Debug.debug("ProxySurface"); + private SurfaceUpdatedHelper surfaceUpdatedHelper = new SurfaceUpdatedHelper(); private AbstractGraphicsConfiguration config; // control access due to delegation protected RecursiveLock surfaceLock = LockFactory.createRecursiveLock(); + private long surfaceHandle_old; protected long displayHandle; protected int height; protected int scrnIndex; @@ -46,6 +51,7 @@ public abstract class ProxySurface implements NativeSurface { invalidate(); config = cfg; displayHandle=cfg.getNativeGraphicsConfiguration().getScreen().getDevice().getHandle(); + surfaceHandle_old = 0; } void invalidate() { @@ -115,6 +121,13 @@ public abstract class ProxySurface implements NativeSurface { adevice.lock(); try { res = lockSurfaceImpl(); + if(LOCK_SUCCESS == res && surfaceHandle_old != getSurfaceHandle()) { + res = LOCK_SURFACE_CHANGED; + if(DEBUG) { + System.err.println("ProxySurface: surface change 0x"+Long.toHexString(surfaceHandle_old)+" -> 0x"+Long.toHexString(getSurfaceHandle())); + // Thread.dumpStack(); + } + } } finally { if (LOCK_SURFACE_NOT_READY >= res) { adevice.unlock(); @@ -131,6 +144,7 @@ public abstract class ProxySurface implements NativeSurface { public final void unlockSurface() { surfaceLock.validateLocked(); + surfaceHandle_old = getSurfaceHandle(); if (surfaceLock.getHoldCount() == 1) { final AbstractGraphicsDevice adevice = getGraphicsConfiguration().getScreen().getDevice(); -- cgit v1.2.3