aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-06-12 08:20:38 +0200
committerSven Gothel <[email protected]>2014-06-12 08:20:38 +0200
commit5626740d14554acf7a17a73ec12b0893445832d0 (patch)
treef2d68b4df87f0ecc1946d72e3d84f0b3587d2798 /src
parent94de08a2b0661d072324677c729fc8d1b3d0ef0f (diff)
Fix Bug 1019 - Remedy of Bug 691 causes 'access/modify after free' and crashes the app
The 'magic' MyNSOpenGLContext::dealloc (MacOSXWindowSystemInterface-calayer.m) of force destroying the underlying CGLContextObj of it's associated NSOpenGLContext as introduced as a remedy of Bug 691 is plain wrong. It was added in commit f6e6fab2a7ddfb5c9b614cb072c27ff697629161 to mitigate the experience behavior of delayed GL context destruction when creating/destroying them multiple times as exposed in unit test TestGLCanvasAddRemove01SwingAWT. While this 'hack' worked for some reason on some OSX versions, it caused a 'access/modify after free' issue exposed under some circumstances and crashes the application. The actual culprit of the delayed GL context destruction is different. The offthread CALayer detachment and hence final destruction issued on the main-thread is _not_ issued immediately due to some referencing holding by NSApp. Issuing an empty event on the NSApp (thread) will wake up the thread and release claimed resources. This has been found while realizing that the GL context are released if the mouse is being moved (duh!). This issue is also known when triggering stop on the NSApp (NEWT MainThread), same remedy has been implemented here for a long time.
Diffstat (limited to 'src')
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java4
-rw-r--r--src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m29
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java2
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java116
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java40
-rw-r--r--src/nativewindow/native/macosx/OSXmisc.m40
-rw-r--r--src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java164
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove01GLCanvasSwingAWT.java80
8 files changed, 252 insertions, 223 deletions
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java
index 485fbd0a0..19a334b75 100644
--- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java
+++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java
@@ -866,7 +866,7 @@ public class MacOSXCGLContext extends GLContextImpl
if(DEBUG) {
System.err.println("MaxOSXCGLContext.NSOpenGLImpl.associateDrawable(true): "+attachGLLayerCmd);
}
- OSXUtil.RunOnMainThread(false, attachGLLayerCmd);
+ OSXUtil.RunOnMainThread(false, false /* kickNSApp */, attachGLLayerCmd);
} else { // -> null == backingLayerHost
lastWidth = drawable.getSurfaceWidth();
lastHeight = drawable.getSurfaceHeight();
@@ -893,7 +893,7 @@ public class MacOSXCGLContext extends GLContextImpl
if(DEBUG) {
System.err.println("MaxOSXCGLContext.NSOpenGLImpl.associateDrawable(false): "+dCmd);
}
- OSXUtil.RunOnMainThread(false, dCmd);
+ OSXUtil.RunOnMainThread(false, true /* kickNSApp */, dCmd);
if( null != gl3ShaderProgram ) {
gl3ShaderProgram.destroy(MacOSXCGLContext.this.gl.getGL3());
gl3ShaderProgram = null;
diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m b/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m
index 652b0545e..d83ddbc22 100644
--- a/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m
+++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m
@@ -112,39 +112,14 @@ extern GLboolean glIsVertexArray (GLuint array);
#endif
-#ifdef VERBOSE_ON
- #define CGLRETAINCOUNT(c) (NULL!=c?(int)CGLGetContextRetainCount(c):-1)
-#else
- #define CGLRETAINCOUNT(c)
-#endif
-
- (void)dealloc
{
- /**
- * The explicit CGLContext destruction below
- * ensures that it is not left behind.
- * Tests show that w/o these gymnastics, the CGLContext is not freed immediately after calling dealloc.
- * The retain, release and dealloc ensures [super dealloc] won't message 'invalid context'.
- */
- CGLContextObj cglCtx = [self CGLContextObj];
-
- DBG_PRINT("MyNSOpenGLContext::dealloc.0 %p (refcnt %d) - CGL-Ctx %p\n", self, (int)[self retainCount], cglCtx, CGLRETAINCOUNT(cglCtx));
+ DBG_PRINT("MyNSOpenGLContext::dealloc.0 %p (refcnt %d)\n", self, (int)[self retainCount]);
// NSLog(@"MyNSOpenGLContext::dealloc: %@",[NSThread callStackSymbols]);
[self clearDrawable];
- DBG_PRINT("MyNSOpenGLContext::dealloc.1 %d\n", CGLRETAINCOUNT(cglCtx));
- if( NULL != cglCtx ) {
- CGLRetainContext( cglCtx );
- DBG_PRINT("MyNSOpenGLContext::dealloc.2 %d\n", CGLRETAINCOUNT(cglCtx));
- }
+
[super dealloc];
- DBG_PRINT("MyNSOpenGLContext::dealloc.3 %d\n", CGLRETAINCOUNT(cglCtx));
- if( NULL != cglCtx ) {
- CGLReleaseContext( cglCtx );
- DBG_PRINT("MyNSOpenGLContext::dealloc.4 %d\n", CGLRETAINCOUNT(cglCtx));
- CGLDestroyContext( cglCtx );
- DBG_PRINT("MyNSOpenGLContext::dealloc.5 %d\n", CGLRETAINCOUNT(cglCtx));
- }
DBG_PRINT("MyNSOpenGLContext::dealloc.X\n");
}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java b/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java
index 36bf646d5..02cec5bbf 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java
@@ -480,7 +480,7 @@ public class SWTAccessor {
public static void invoke(boolean wait, Runnable runnable) {
if( isOSX ) {
// Use SWT main thread! Only reliable config w/ -XStartOnMainThread !?
- OSXUtil.RunOnMainThread(wait, runnable);
+ OSXUtil.RunOnMainThread(wait, false, runnable);
} else {
runnable.run();
}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
index 3728bfb59..e64525fbe 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
@@ -96,7 +96,7 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface {
if(0 != windowHandle) {
OSXUtil.DestroyNSWindow(windowHandle);
}
- OSXUtil.RunOnMainThread(false, new Runnable() {
+ OSXUtil.RunOnMainThread(false, true /* kickNSApp */, new Runnable() {
@Override
public void run() {
if( 0 != rootSurfaceLayer ) {
@@ -121,7 +121,7 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface {
updatePixelScale();
if( hadPixelScaleX != getPixelScaleX() && 0 != getAttachedSurfaceLayer() ) {
- OSXUtil.RunOnMainThread(false, new Runnable() {
+ OSXUtil.RunOnMainThread(false, false, new Runnable() {
@Override
public void run() {
final long osl = getAttachedSurfaceLayer();
@@ -136,37 +136,37 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface {
@Override
protected void attachSurfaceLayerImpl(final long layerHandle) {
- OSXUtil.RunOnMainThread(false, new Runnable() {
- @Override
- public void run() {
- // AWT position is top-left w/ insets, where CALayer position is bottom/left from root CALayer w/o insets.
- // Determine p0: components location on screen w/o insets.
- // CALayer position will be determined in native code.
- // See detailed description in {@link JAWTUtil#JAWT_OSX_CALAYER_QUIRK_LAYOUT}
- final Point p0 = new Point();
- final Component outterComp = getLocationOnScreenNonBlocking(p0, component);
- final java.awt.Insets outterInsets = AWTMisc.getInsets(outterComp, true);
- final Point p1 = (Point)p0.cloneMutable();
- p1.translate(-outterComp.getX(), -outterComp.getY());
- if( null != outterInsets ) {
- p1.translate(-outterInsets.left, -outterInsets.top);
- }
-
- if( DEBUG_CALAYER_POS_CRITICAL ) {
- final java.awt.Point pA0 = component.getLocationOnScreen();
- final Point pA1 = new Point(pA0.x, pA0.y);
- pA1.translate(-outterComp.getX(), -outterComp.getY());
+ OSXUtil.RunOnMainThread(false, false /* kickNSApp */, new Runnable() {
+ @Override
+ public void run() {
+ // AWT position is top-left w/ insets, where CALayer position is bottom/left from root CALayer w/o insets.
+ // Determine p0: components location on screen w/o insets.
+ // CALayer position will be determined in native code.
+ // See detailed description in {@link JAWTUtil#JAWT_OSX_CALAYER_QUIRK_LAYOUT}
+ final Point p0 = new Point();
+ final Component outterComp = getLocationOnScreenNonBlocking(p0, component);
+ final java.awt.Insets outterInsets = AWTMisc.getInsets(outterComp, true);
+ final Point p1 = (Point)p0.cloneMutable();
+ p1.translate(-outterComp.getX(), -outterComp.getY());
if( null != outterInsets ) {
- pA1.translate(-outterInsets.left, -outterInsets.top);
+ p1.translate(-outterInsets.left, -outterInsets.top);
}
- System.err.println("JAWTWindow.attachSurfaceLayerImpl: "+toHexString(layerHandle) + ", [ins "+outterInsets+"], pA "+pA0+" -> "+pA1+
- ", p0 "+p0+" -> "+p1+", bounds "+bounds);
- } else if( DEBUG ) {
- System.err.println("JAWTWindow.attachSurfaceLayerImpl: "+toHexString(layerHandle) + ", [ins "+outterInsets+"], p0 "+p0+" -> "+p1+", bounds "+bounds);
- }
- // HiDPI: uniform pixel scale
- OSXUtil.AddCASublayer(rootSurfaceLayer, layerHandle, p1.getX(), p1.getY(), getWidth(), getHeight(), getPixelScaleX(), JAWTUtil.getOSXCALayerQuirks());
- } } );
+
+ if( DEBUG_CALAYER_POS_CRITICAL ) {
+ final java.awt.Point pA0 = component.getLocationOnScreen();
+ final Point pA1 = new Point(pA0.x, pA0.y);
+ pA1.translate(-outterComp.getX(), -outterComp.getY());
+ if( null != outterInsets ) {
+ pA1.translate(-outterInsets.left, -outterInsets.top);
+ }
+ System.err.println("JAWTWindow.attachSurfaceLayerImpl: "+toHexString(layerHandle) + ", [ins "+outterInsets+"], pA "+pA0+" -> "+pA1+
+ ", p0 "+p0+" -> "+p1+", bounds "+bounds);
+ } else if( DEBUG ) {
+ System.err.println("JAWTWindow.attachSurfaceLayerImpl: "+toHexString(layerHandle) + ", [ins "+outterInsets+"], p0 "+p0+" -> "+p1+", bounds "+bounds);
+ }
+ // HiDPI: uniform pixel scale
+ OSXUtil.AddCASublayer(rootSurfaceLayer, layerHandle, p1.getX(), p1.getY(), getWidth(), getHeight(), getPixelScaleX(), JAWTUtil.getOSXCALayerQuirks());
+ } } );
}
@Override
@@ -204,12 +204,12 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface {
@Override
protected void detachSurfaceLayerImpl(final long layerHandle, final Runnable detachNotify) {
- OSXUtil.RunOnMainThread(false, new Runnable() {
- @Override
- public void run() {
- detachNotify.run();
- OSXUtil.RemoveCASublayer(rootSurfaceLayer, layerHandle);
- } } );
+ OSXUtil.RunOnMainThread(false, true /* kickNSApp */, new Runnable() {
+ @Override
+ public void run() {
+ detachNotify.run();
+ OSXUtil.RemoveCASublayer(rootSurfaceLayer, layerHandle);
+ } });
}
@Override
@@ -326,30 +326,30 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface {
}
if(null == errMsg) {
jawtSurfaceLayersHandle = GetJAWTSurfaceLayersHandle0(dsi.getBuffer());
- OSXUtil.RunOnMainThread(false, new Runnable() {
- @Override
- public void run() {
- String errMsg = null;
- if(0 == rootSurfaceLayer && 0 != jawtSurfaceLayersHandle) {
- rootSurfaceLayer = OSXUtil.CreateCALayer(bounds.getWidth(), bounds.getHeight(), getPixelScaleX()); // HiDPI: uniform pixel scale
- if(0 == rootSurfaceLayer) {
- errMsg = "Could not create root CALayer";
- } else {
- try {
- SetJAWTRootSurfaceLayer0(jawtSurfaceLayersHandle, rootSurfaceLayer);
- } catch(Exception e) {
- errMsg = "Could not set JAWT rootSurfaceLayerHandle "+toHexString(rootSurfaceLayer)+", cause: "+e.getMessage();
+ OSXUtil.RunOnMainThread(false, false, new Runnable() {
+ @Override
+ public void run() {
+ String errMsg = null;
+ if(0 == rootSurfaceLayer && 0 != jawtSurfaceLayersHandle) {
+ rootSurfaceLayer = OSXUtil.CreateCALayer(bounds.getWidth(), bounds.getHeight(), getPixelScaleX()); // HiDPI: uniform pixel scale
+ if(0 == rootSurfaceLayer) {
+ errMsg = "Could not create root CALayer";
+ } else {
+ try {
+ SetJAWTRootSurfaceLayer0(jawtSurfaceLayersHandle, rootSurfaceLayer);
+ } catch(Exception e) {
+ errMsg = "Could not set JAWT rootSurfaceLayerHandle "+toHexString(rootSurfaceLayer)+", cause: "+e.getMessage();
+ }
}
- }
- if(null != errMsg) {
- if(0 != rootSurfaceLayer) {
- OSXUtil.DestroyCALayer(rootSurfaceLayer);
- rootSurfaceLayer = 0;
+ if(null != errMsg) {
+ if(0 != rootSurfaceLayer) {
+ OSXUtil.DestroyCALayer(rootSurfaceLayer);
+ rootSurfaceLayer = 0;
+ }
+ throw new NativeWindowException(errMsg+": "+MacOSXJAWTWindow.this);
}
- throw new NativeWindowException(errMsg+": "+MacOSXJAWTWindow.this);
}
- }
- } } );
+ } } );
}
if(null != errMsg) {
if(0 != windowHandle) {
diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
index a91698f62..22ac9c355 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
@@ -251,9 +251,10 @@ public class OSXUtil implements ToolkitProperties {
* </p>
*
* @param waitUntilDone
+ * @param kickNSApp if <code>true</code> issues {@link #KickNSApp()}
* @param runnable
*/
- public static void RunOnMainThread(boolean waitUntilDone, Runnable runnable) {
+ public static void RunOnMainThread(final boolean waitUntilDone, final boolean kickNSApp, final Runnable runnable) {
if( IsMainThread0() ) {
runnable.run(); // don't leave the JVM
} else {
@@ -263,7 +264,7 @@ public class OSXUtil implements ToolkitProperties {
final Object sync = new Object();
final RunnableTask rt = new RunnableTask( runnable, waitUntilDone ? sync : null, true, waitUntilDone ? null : System.err );
synchronized(sync) {
- RunOnMainThread0(rt);
+ RunOnMainThread0(kickNSApp, rt);
if( waitUntilDone ) {
try {
sync.wait();
@@ -288,14 +289,33 @@ public class OSXUtil implements ToolkitProperties {
* @param delay delay to run the runnable in milliseconds
*/
public static void RunLater(boolean onMain, Runnable runnable, int delay) {
- RunLater0(onMain, new RunnableTask( runnable, null, true, System.err ), delay);
+ RunLater0(onMain, false /* kickNSApp */, new RunnableTask( runnable, null, true, System.err ), delay);
+ }
+
+ /**
+ * Wakes up NSApp thread by sending an empty NSEvent ..
+ * <p>
+ * This is deemed important <i>sometimes</i> where resources shall get freed ASAP, e.g. GL context etc.
+ * </p>
+ * <p>
+ * The following scenarios requiring this <i>wake-up</i> are currently known:
+ * <ul>
+ * <li>Destruction of an OpenGL context</li>
+ * <li>Destruction of Windows .. ?</li>
+ * <li>Stopping the NSApp</li>
+ * </ul>
+ * </p>
+ * FIXME: Complete list of scenarios and reason it.
+ */
+ public static void KickNSApp() {
+ KickNSApp0();
}
private static Runnable _nop = new Runnable() { @Override public void run() {}; };
- /** Issues a {@link #RunOnMainThread(boolean, Runnable)} w/ an <i>NOP</i> runnable, while waiting until done. */
+ /** Issues a {@link #RunOnMainThread(boolean, boolean, Runnable)} w/ an <i>NOP</i> runnable, while waiting until done and issuing {@link #KickNSApp()}. */
public static void WaitUntilFinish() {
- RunOnMainThread(true, _nop);
+ RunOnMainThread(true, true /* kickNSApp */, _nop);
}
/**
@@ -305,9 +325,10 @@ public class OSXUtil implements ToolkitProperties {
* </p>
*
* @param waitUntilDone
+ * @param kickNSApp if <code>true</code> issues {@link #KickNSApp()}
* @param func
*/
- public static <R,A> R RunOnMainThread(boolean waitUntilDone, Function<R,A> func, A... args) {
+ public static <R,A> R RunOnMainThread(final boolean waitUntilDone, final boolean kickNSApp, final Function<R,A> func, final A... args) {
if( IsMainThread0() ) {
return func.eval(args); // don't leave the JVM
} else {
@@ -318,7 +339,7 @@ public class OSXUtil implements ToolkitProperties {
final FunctionTask<R,A> rt = new FunctionTask<R,A>( func, waitUntilDone ? sync : null, true, waitUntilDone ? null : System.err );
synchronized(sync) {
rt.setArgs(args);
- RunOnMainThread0(rt);
+ RunOnMainThread0(kickNSApp, rt);
if( waitUntilDone ) {
try {
sync.wait();
@@ -384,8 +405,9 @@ public class OSXUtil implements ToolkitProperties {
private static native void SetCALayerPixelScale0(long rootCALayer, long subCALayer, float contentsScale);
private static native void RemoveCASublayer0(long rootCALayer, long subCALayer);
private static native void DestroyCALayer0(long caLayer);
- private static native void RunOnMainThread0(Runnable runnable);
- private static native void RunLater0(boolean onMain, Runnable runnable, int delay);
+ private static native void RunOnMainThread0(boolean kickNSApp, Runnable runnable);
+ private static native void RunLater0(boolean onMain, boolean kickNSApp, Runnable runnable, int delay);
+ private static native void KickNSApp0();
private static native boolean IsMainThread0();
private static native int GetScreenRefreshRate0(int scrn_idx);
}
diff --git a/src/nativewindow/native/macosx/OSXmisc.m b/src/nativewindow/native/macosx/OSXmisc.m
index fa3bf026a..bf01f19d8 100644
--- a/src/nativewindow/native/macosx/OSXmisc.m
+++ b/src/nativewindow/native/macosx/OSXmisc.m
@@ -1006,29 +1006,61 @@ static void RunOnThread (JNIEnv *env, jobject runnable, BOOL onMain, jint delayI
DBG_PRINT2( "RunOnThread.X\n");
}
-/*
+static void OSXUtil_KickNSApp() {
+ NSEvent* event = [NSEvent otherEventWithType: NSApplicationDefined
+ location: NSMakePoint(0,0)
+ modifierFlags: 0
+ timestamp: 0.0
+ windowNumber: 0
+ context: nil
+ subtype: 0
+ data1: 0
+ data2: 0];
+ [NSApp postEvent: event atStart: true];
+}
+
+/**
* Class: Java_jogamp_nativewindow_macosx_OSXUtil
* Method: RunOnMainThread0
* Signature: (ZLjava/lang/Runnable;)V
*/
JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_RunOnMainThread0
- (JNIEnv *env, jclass unused, jobject runnable)
+ (JNIEnv *env, jclass unused, jboolean kickNSApp, jobject runnable)
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
RunOnThread (env, runnable, YES, 0);
+ if( kickNSApp ) {
+ OSXUtil_KickNSApp();
+ }
[pool release];
}
/*
* Class: Java_jogamp_nativewindow_macosx_OSXUtil
* Method: RunLater0
- * Signature: (ZLjava/lang/Runnable;I)V
+ * Signature: (ZZLjava/lang/Runnable;I)V
*/
JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_RunLater0
- (JNIEnv *env, jclass unused, jboolean onMain, jobject runnable, jint delay)
+ (JNIEnv *env, jclass unused, jboolean onMain, jboolean kickNSApp, jobject runnable, jint delay)
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
RunOnThread (env, runnable, onMain ? YES : NO, delay);
+ if( kickNSApp ) {
+ OSXUtil_KickNSApp();
+ }
+ [pool release];
+}
+
+/**
+ * Class: Java_jogamp_nativewindow_macosx_OSXUtil
+ * Method: KickNSApp0
+ * Signature: (V)V
+ */
+JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_KickNSApp0
+ (JNIEnv *env, jclass unused)
+{
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ OSXUtil_KickNSApp();
[pool release];
}
diff --git a/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java
index b44c2a3cc..fe7411f29 100644
--- a/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java
+++ b/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java
@@ -159,7 +159,7 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
}
} else {
// set pixelScale in native code, will issue an update PixelScale
- OSXUtil.RunOnMainThread(true, new Runnable() {
+ OSXUtil.RunOnMainThread(true, false, new Runnable() {
@Override
public void run() {
setPixelScale0(getWindowHandle(), surfaceHandle, reqPixelScale[0]); // HiDPI: uniformPixelScale
@@ -204,11 +204,11 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
sscSurfaceHandle = 0;
isOffscreenInstance = false;
if (0 != handle) {
- OSXUtil.RunOnMainThread(false, new Runnable() {
+ OSXUtil.RunOnMainThread(false, true /* kickNSApp */, new Runnable() {
@Override
public void run() {
close0( handle );
- } } );
+ } });
}
} catch (Throwable t) {
if(DEBUG_IMPLEMENTATION) {
@@ -262,11 +262,11 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
sscSurfaceHandle = surfaceHandle;
if (isNativeValid()) {
if (0 != sscSurfaceHandle) {
- OSXUtil.RunOnMainThread(false, new Runnable() {
- @Override
- public void run() {
- orderOut0( 0 != getParentWindowHandle() ? getParentWindowHandle() : getWindowHandle() );
- } } );
+ OSXUtil.RunOnMainThread(false, false, new Runnable() {
+ @Override
+ public void run() {
+ orderOut0( 0 != getParentWindowHandle() ? getParentWindowHandle() : getWindowHandle() );
+ } } );
} /** this is done by recreation!
else if (isVisible()){
OSXUtil.RunOnMainThread(false, new Runnable() {
@@ -279,11 +279,11 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
@Override
protected void setTitleImpl(final String title) {
- OSXUtil.RunOnMainThread(false, new Runnable() {
- @Override
- public void run() {
- setTitle0(getWindowHandle(), title);
- } } );
+ OSXUtil.RunOnMainThread(false, false, new Runnable() {
+ @Override
+ public void run() {
+ setTitle0(getWindowHandle(), title);
+ } } );
}
@Override
@@ -294,15 +294,15 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
System.err.println("MacWindow: requestFocusImpl(), isOffscreenInstance "+_isOffscreenInstance+", isFullscreen "+_isFullscreen);
}
if(!_isOffscreenInstance) {
- OSXUtil.RunOnMainThread(false, new Runnable() {
- @Override
- public void run() {
- requestFocus0(getWindowHandle(), force);
- if(_isFullscreen) {
- // 'NewtMacWindow::windowDidBecomeKey()' is not always called in fullscreen-mode!
- focusChanged(false, true);
- }
- } } );
+ OSXUtil.RunOnMainThread(false, false, new Runnable() {
+ @Override
+ public void run() {
+ requestFocus0(getWindowHandle(), force);
+ if(_isFullscreen) {
+ // 'NewtMacWindow::windowDidBecomeKey()' is not always called in fullscreen-mode!
+ focusChanged(false, true);
+ }
+ } } );
} else {
focusChanged(false, true);
}
@@ -314,11 +314,11 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
System.err.println("MacWindow: clearFocus(), isOffscreenInstance "+isOffscreenInstance);
}
if(!isOffscreenInstance) {
- OSXUtil.RunOnMainThread(false, new Runnable() {
- @Override
- public void run() {
- resignFocus0(getWindowHandle());
- } } );
+ OSXUtil.RunOnMainThread(false, false, new Runnable() {
+ @Override
+ public void run() {
+ resignFocus0(getWindowHandle());
+ } } );
} else {
focusChanged(false, false);
}
@@ -337,11 +337,11 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
if(DEBUG_IMPLEMENTATION) {
System.err.println("MacWindow: updatePosition() parent["+useParent+" "+pX+"/"+pY+"] "+x+"/"+y+" -> "+x+"/"+y+" rel-client-pos, "+p0S+" screen-client-pos");
}
- OSXUtil.RunOnMainThread(false, new Runnable() {
- @Override
- public void run() {
- setWindowClientTopLeftPoint0(handle, p0S.getX(), p0S.getY(), isVisible());
- } } );
+ OSXUtil.RunOnMainThread(false, false, new Runnable() {
+ @Override
+ public void run() {
+ setWindowClientTopLeftPoint0(handle, p0S.getX(), p0S.getY(), isVisible());
+ } } );
// no native event (fullscreen, some reparenting)
positionChanged(true, x, y);
}
@@ -359,11 +359,11 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
if(DEBUG_IMPLEMENTATION) {
System.err.println("MacWindow: sizeChanged() parent["+useParent+" "+x+"/"+y+"] "+getX()+"/"+getY()+" "+newWidth+"x"+newHeight+" -> "+p0S+" screen-client-pos");
}
- OSXUtil.RunOnMainThread(false, new Runnable() {
- @Override
- public void run() {
- setWindowClientTopLeftPoint0(getWindowHandle(), p0S.getX(), p0S.getY(), isVisible());
- } } );
+ OSXUtil.RunOnMainThread(false, false, new Runnable() {
+ @Override
+ public void run() {
+ setWindowClientTopLeftPoint0(getWindowHandle(), p0S.getX(), p0S.getY(), isVisible());
+ } } );
}
}
super.sizeChanged(defer, newWidth, newHeight, force);
@@ -407,12 +407,12 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) && !setVisible ) {
if ( !isOffscreenInstance ) {
- OSXUtil.RunOnMainThread(false, new Runnable() {
- @Override
- public void run() {
- orderOut0(getWindowHandle());
- visibleChanged(true, false);
- } } );
+ OSXUtil.RunOnMainThread(false, false, new Runnable() {
+ @Override
+ public void run() {
+ orderOut0(getWindowHandle());
+ visibleChanged(true, false);
+ } } );
} else {
visibleChanged(true, false);
}
@@ -438,11 +438,11 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
} else {
if( width>0 && height>0 ) {
if( !isOffscreenInstance ) {
- OSXUtil.RunOnMainThread(false, new Runnable() {
- @Override
- public void run() {
- setWindowClientTopLeftPointAndSize0(getWindowHandle(), pClientLevelOnSreen.getX(), pClientLevelOnSreen.getY(), width, height, setVisible);
- } } );
+ OSXUtil.RunOnMainThread(false, false, new Runnable() {
+ @Override
+ public void run() {
+ setWindowClientTopLeftPointAndSize0(getWindowHandle(), pClientLevelOnSreen.getX(), pClientLevelOnSreen.getY(), width, height, setVisible);
+ } } );
} // else offscreen size is realized via recreation
// no native event (fullscreen, some reparenting)
positionChanged(true, x, y);
@@ -450,12 +450,12 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
}
if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) && setVisible ) {
if( !isOffscreenInstance ) {
- OSXUtil.RunOnMainThread(false, new Runnable() {
- @Override
- public void run() {
- orderFront0(getWindowHandle());
- visibleChanged(true, true);
- } } );
+ OSXUtil.RunOnMainThread(false, false, new Runnable() {
+ @Override
+ public void run() {
+ orderFront0(getWindowHandle());
+ visibleChanged(true, true);
+ } } );
} else {
visibleChanged(true, true);
}
@@ -523,22 +523,22 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
protected void setPointerIconImpl(final PointerIconImpl pi) {
if( !isOffscreenInstance ) {
final long piHandle = null != pi ? pi.validatedHandle() : 0;
- OSXUtil.RunOnMainThread(true, new Runnable() { // waitUntildone due to PointerIconImpl's Lifecycle !
- @Override
- public void run() {
- setPointerIcon0(getWindowHandle(), piHandle);
- } } );
+ OSXUtil.RunOnMainThread(true, false, new Runnable() { // waitUntildone due to PointerIconImpl's Lifecycle !
+ @Override
+ public void run() {
+ setPointerIcon0(getWindowHandle(), piHandle);
+ } } );
}
}
@Override
protected boolean setPointerVisibleImpl(final boolean pointerVisible) {
if( !isOffscreenInstance ) {
- OSXUtil.RunOnMainThread(false, new Runnable() {
- @Override
- public void run() {
- setPointerVisible0(getWindowHandle(), hasFocus(), pointerVisible);
- } } );
+ OSXUtil.RunOnMainThread(false, false, new Runnable() {
+ @Override
+ public void run() {
+ setPointerVisible0(getWindowHandle(), hasFocus(), pointerVisible);
+ } } );
return true;
}
return false;
@@ -643,12 +643,12 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
if( 0 == surfaceHandle ) {
throw new NativeWindowException("Internal Error - create w/ window, but no Newt NSView");
}
- OSXUtil.RunOnMainThread(false, new Runnable() {
- @Override
- public void run() {
- changeContentView0(parentWinHandle, preWinHandle, 0);
- close0( preWinHandle );
- } } );
+ OSXUtil.RunOnMainThread(false, false /* kickNSApp */, new Runnable() {
+ @Override
+ public void run() {
+ changeContentView0(parentWinHandle, preWinHandle, 0);
+ close0( preWinHandle );
+ } });
} else {
if( 0 != surfaceHandle ) {
throw new NativeWindowException("Internal Error - create w/o window, but has Newt NSView");
@@ -670,18 +670,18 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl
final boolean isOpaque = getGraphicsConfiguration().getChosenCapabilities().isBackgroundOpaque() && !offscreenInstance;
// Blocking initialization on main-thread!
- OSXUtil.RunOnMainThread(true, new Runnable() {
- @Override
- public void run() {
- initWindow0( parentWinHandle, newWin, pS.getX(), pS.getY(), width, height, reqPixelScale[0] /* HiDPI uniformPixelScale */,
- isOpaque, visible && !offscreenInstance, surfaceHandle);
- if( offscreenInstance ) {
- orderOut0(0!=parentWinHandle ? parentWinHandle : newWin);
- } else {
- setTitle0(newWin, getTitle());
- setAlwaysOnTop0(getWindowHandle(), alwaysOnTop);
- }
- } } );
+ OSXUtil.RunOnMainThread(true, false /* kickNSApp */, new Runnable() {
+ @Override
+ public void run() {
+ initWindow0( parentWinHandle, newWin, pS.getX(), pS.getY(), width, height, reqPixelScale[0] /* HiDPI uniformPixelScale */,
+ isOpaque, visible && !offscreenInstance, surfaceHandle);
+ if( offscreenInstance ) {
+ orderOut0(0!=parentWinHandle ? parentWinHandle : newWin);
+ } else {
+ setTitle0(newWin, getTitle());
+ setAlwaysOnTop0(getWindowHandle(), alwaysOnTop);
+ }
+ } });
} catch (Exception ie) {
ie.printStackTrace();
}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove01GLCanvasSwingAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove01GLCanvasSwingAWT.java
index 3e54bcd60..8dfd93e47 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove01GLCanvasSwingAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestAddRemove01GLCanvasSwingAWT.java
@@ -3,14 +3,14 @@
*
* 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
@@ -20,12 +20,12 @@
* 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 com.jogamp.opengl.test.junit.jogl.acore;
import java.awt.AWTException;
@@ -88,9 +88,9 @@ public class TestAddRemove01GLCanvasSwingAWT extends UITestCase {
@AfterClass
public static void releaseClass() {
}
-
- protected JPanel create(final JFrame[] top, final int width, final int height, final int num)
- throws InterruptedException, InvocationTargetException
+
+ protected JPanel create(final JFrame[] top, final int width, final int height, final int num)
+ throws InterruptedException, InvocationTargetException
{
final JPanel[] jPanel = new JPanel[] { null };
SwingUtilities.invokeAndWait(new Runnable() {
@@ -103,30 +103,30 @@ public class TestAddRemove01GLCanvasSwingAWT extends UITestCase {
jFrame1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // equivalent to Frame, use windowClosing event!
jFrame1.getContentPane().add(jPanel[0]);
jFrame1.setSize(width, height);
-
+
top[0] = jFrame1;
} } );
- return jPanel[0];
+ return jPanel[0];
}
- protected void add(final Container cont, final Component comp)
- throws InterruptedException, InvocationTargetException
+ protected void add(final Container cont, final Component comp)
+ throws InterruptedException, InvocationTargetException
{
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
- cont.add(comp, BorderLayout.CENTER);
+ cont.add(comp, BorderLayout.CENTER);
} } );
}
-
- protected void dispose(final GLCanvas glc)
- throws InterruptedException, InvocationTargetException
+
+ protected void dispose(final GLCanvas glc)
+ throws InterruptedException, InvocationTargetException
{
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
- glc.destroy();
+ glc.destroy();
} } );
}
-
+
protected void setVisible(final JFrame jFrame, final boolean visible) throws InterruptedException, InvocationTargetException {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
@@ -135,25 +135,25 @@ public class TestAddRemove01GLCanvasSwingAWT extends UITestCase {
jFrame.validate();
}
jFrame.setVisible(visible);
- } } ) ;
+ } } ) ;
}
-
+
protected void dispose(final JFrame jFrame) throws InterruptedException, InvocationTargetException {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
jFrame.dispose();
- } } ) ;
+ } } ) ;
}
-
+
protected void runTestGL(boolean onscreen, GLCapabilities caps, int addRemoveOpCount)
throws AWTException, InterruptedException, InvocationTargetException
{
-
if(waitForKey) {
UITestCase.waitForKey("Start");
- }
+ }
for(int i=0; i<addRemoveOpCount; i++) {
- System.err.println("Loop # "+i+" / "+addRemoveCount);
+ int ti = 0;
+ System.err.println("Loop."+(ti++)+" "+(i+1)+"/"+addRemoveOpCount);
final GLCanvas glc = new GLCanvas(caps);
Assert.assertNotNull(glc);
if( !onscreen ) {
@@ -166,23 +166,23 @@ public class TestAddRemove01GLCanvasSwingAWT extends UITestCase {
final GearsES2 gears = new GearsES2(1);
gears.setVerbose(false);
glc.addGLEventListener(gears);
-
+
final JFrame[] top = new JFrame[] { null };
final Container glcCont = create(top, width, height, i);
add(glcCont, glc);
-
+
setVisible(top[0], true);
-
+
final long t0 = System.currentTimeMillis();
do {
glc.display();
Thread.sleep(10);
} while ( ( System.currentTimeMillis() - t0 ) < durationPerTest ) ;
-
- System.err.println("GLCanvas isOffscreenLayerSurfaceEnabled: "+glc.isOffscreenLayerSurfaceEnabled()+": "+glc.getChosenGLCapabilities());
-
+
+ System.err.println("Loop."+(ti++)+" "+(i+1)+"/"+addRemoveOpCount+": GLCanvas isOffscreenLayerSurfaceEnabled: "+glc.isOffscreenLayerSurfaceEnabled()+": "+glc.getChosenGLCapabilities());
+
dispose(top[0]);
-
+
if( 0 < pauseEach && 0 == i % pauseEach ) {
System.err.println("******* P A U S E - Start ********");
// OSXUtil.WaitUntilFinish();
@@ -192,7 +192,7 @@ public class TestAddRemove01GLCanvasSwingAWT extends UITestCase {
}
if(waitForKeyPost) {
UITestCase.waitForKey("End");
- }
+ }
}
@Test
@@ -226,7 +226,7 @@ public class TestAddRemove01GLCanvasSwingAWT extends UITestCase {
}
runTestGL(false, caps, addRemoveCount);
}
-
+
@Test
public void test03OffscreenPBuffer()
throws AWTException, InterruptedException, InvocationTargetException
@@ -244,7 +244,7 @@ public class TestAddRemove01GLCanvasSwingAWT extends UITestCase {
caps.setOnscreen(true); // simulate normal behavior ..
runTestGL(false, caps, addRemoveCount);
}
-
+
public static void main(String args[]) throws IOException {
for(int i=0; i<args.length; i++) {
if(args[i].equals("-time")) {
@@ -277,16 +277,16 @@ public class TestAddRemove01GLCanvasSwingAWT extends UITestCase {
}
System.err.println("waitForKey "+waitForKey);
System.err.println("waitForKeyPost "+waitForKeyPost);
-
+
System.err.println("addRemoveCount "+addRemoveCount);
System.err.println("pauseEach "+pauseEach);
- System.err.println("pauseDuration "+pauseDuration);
-
+ System.err.println("pauseDuration "+pauseDuration);
+
System.err.println("noOnscreenTest "+noOnscreenTest);
System.err.println("noOffscreenTest "+noOffscreenTest);
System.err.println("offscreenPBufferOnly "+offscreenPBufferOnly);
System.err.println("offscreenFBOOnly "+offscreenFBOOnly);
-
- org.junit.runner.JUnitCore.main(TestAddRemove01GLCanvasSwingAWT.class.getName());
+
+ org.junit.runner.JUnitCore.main(TestAddRemove01GLCanvasSwingAWT.class.getName());
}
}