diff options
author | Sven Gothel <[email protected]> | 2011-11-11 07:35:43 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-11-11 07:35:43 +0100 |
commit | 7e81956daf1d5c81f6344e7f5509ae08947f8434 (patch) | |
tree | ac118f8062c9da59604cf69a7a2f5a4e9f84f091 | |
parent | f0962124acf99a608f5e5e2f5f59fcb10f604403 (diff) |
OS X Layered View: Part7 Allow NEWT onscreen MacWindow to be used incl reparenting
Test: enable NEWT 'onscreen' case
8 files changed, 102 insertions, 33 deletions
diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface-pbuffer.m b/src/jogl/native/macosx/MacOSXWindowSystemInterface-pbuffer.m index f261e95b2..47f679fac 100644 --- a/src/jogl/native/macosx/MacOSXWindowSystemInterface-pbuffer.m +++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface-pbuffer.m @@ -406,13 +406,20 @@ void waitUntilNSOpenGLLayerIsReady(NSOpenGLLayer* layer, long to_ms) { timespec_now(&to_abs); timespec_addms(&to_abs, to_ms); wr = pthread_cond_timedwait(&l->renderSignal, &l->renderLock, &to_abs); + #ifdef DBG_SYNC + struct timespec t1, td; + timespec_now(&t1); + timespec_subtract(&td, &t1, &to_abs); + long td_ms = timespec_milliseconds(&td); + fprintf(stderr, "%ld ms", td_ms); + #endif } else { pthread_cond_wait (&l->renderSignal, &l->renderLock); } ready = !l->shallDraw; } } while (NO == ready && 0 == wr) ; - SYNC_PRINT("%d}", ready); + SYNC_PRINT("-%d}", ready); pthread_mutex_unlock(&l->renderLock); } diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface.h b/src/jogl/native/macosx/MacOSXWindowSystemInterface.h index 763930e37..3625cfbde 100644 --- a/src/jogl/native/macosx/MacOSXWindowSystemInterface.h +++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface.h @@ -3,7 +3,7 @@ #import <OpenGL/CGLTypes.h> #import <jni.h> -#define VERBOSE_ON 1 +// #define VERBOSE_ON 1 #ifdef VERBOSE_ON // #define DBG_PRINT(...) NSLog(@ ## __VA_ARGS__) diff --git a/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java b/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java index 7c07e616b..5cb7d5aca 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java +++ b/src/nativewindow/classes/jogamp/nativewindow/NativeWindowFactoryImpl.java @@ -32,11 +32,16 @@ package jogamp.nativewindow; -import com.jogamp.common.os.Platform; -import com.jogamp.common.util.*; -import java.lang.reflect.*; +import java.lang.reflect.Constructor; + +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.NativeWindow; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.nativewindow.ToolkitLock; -import javax.media.nativewindow.*; +import com.jogamp.common.os.Platform; +import com.jogamp.common.util.ReflectionUtil; public class NativeWindowFactoryImpl extends NativeWindowFactory { private static final ToolkitLock nullToolkitLock = new NullToolkitLock(); @@ -44,7 +49,7 @@ public class NativeWindowFactoryImpl extends NativeWindowFactory { public static ToolkitLock getNullToolkitLock() { return nullToolkitLock; } - + // This subclass of NativeWindowFactory handles the case of // NativeWindows being passed in protected NativeWindow getNativeWindowImpl(Object winObj, AbstractGraphicsConfiguration config) throws IllegalArgumentException { @@ -66,7 +71,7 @@ public class NativeWindowFactoryImpl extends NativeWindowFactory { "javax.media.nativewindow.NativeWindow or "+AWTComponentClassName); } - private Constructor nativeWindowConstructor = null; + private Constructor<?> nativeWindowConstructor = null; private NativeWindow getAWTNativeWindow(Object winObj, AbstractGraphicsConfiguration config) { if (nativeWindowConstructor == null) { diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java index 364b2054d..c19569606 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java @@ -129,6 +129,7 @@ public class MacOSXJAWTWindow extends JAWTWindow implements SurfaceChangeable { if(DEBUG) { System.err.println("MacOSXJAWTWindow.setSurfaceHandle(): 0x"+Long.toHexString(surfaceHandle)); } + sscSet &= 0 != surfaceHandle; // reset ssc flag if NULL surfaceHandle, ie. back to JAWT this.surfaceHandle = surfaceHandle; } diff --git a/src/nativewindow/native/macosx/OSXmisc.m b/src/nativewindow/native/macosx/OSXmisc.m index de0d278fd..45ff1bd4c 100644 --- a/src/nativewindow/native/macosx/OSXmisc.m +++ b/src/nativewindow/native/macosx/OSXmisc.m @@ -39,7 +39,7 @@ #include <jawt_md.h> #import <JavaNativeFoundation.h> -#define VERBOSE 1 +// #define VERBOSE 1 // #ifdef VERBOSE // #define DBG_PRINT(...) NSLog(@ ## __VA_ARGS__) @@ -294,10 +294,11 @@ JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_RemoveCASublayer0 CALayer* rootLayer = (CALayer*) ((intptr_t) rootCALayer); CALayer* subLayer = (CALayer*) ((intptr_t) subCALayer); + (void)rootLayer; // no warnings + DBG_PRINT("CALayer::RemoveCASublayer0.0: %p . %p (refcnt %d)\n", rootLayer, subLayer, (int)[subLayer retainCount]); [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ [subLayer removeFromSuperlayer]; - // [[rootLayer sublayers] makeObjectsPerformSelector:@selector(removeFromSuperlayer)]; }]; DBG_PRINT("CALayer::RemoveCASublayer0.X: %p . %p (refcnt %d)\n", rootLayer, subLayer, (int)[subLayer retainCount]); JNF_COCOA_EXIT(env); diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index e8d6997c2..3865cd6c8 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -921,6 +921,22 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer runOnEDTIfAvail(true, destroyAction); } + /** + * @param cWin child window, must not be null + * @param pWin parent window, may be null + * @return true if at least one of both window's configurations is offscreen + */ + protected static boolean isOffscreenInstance(NativeWindow cWin, NativeWindow pWin) { + boolean ofs = false; + if( null != cWin.getGraphicsConfiguration() ) { + ofs = !cWin.getGraphicsConfiguration().getChosenCapabilities().isOnscreen(); + } + if( null != pWin && null != pWin.getGraphicsConfiguration() ) { + ofs |= !pWin.getGraphicsConfiguration().getChosenCapabilities().isOnscreen(); + } + return ofs; + } + private class ReparentActionImpl implements Runnable, ReparentAction { NativeWindow newParentWindow; boolean forceDestroyCreate; @@ -962,6 +978,11 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer windowLock.lock(); try { + if(isNativeValid()) { + // force recreation if offscreen, since it may become onscreen + forceDestroyCreate |= isOffscreenInstance(WindowImpl.this, newParentWindow); + } + wasVisible = isVisible(); Window newParentWindowNEWT = null; @@ -1217,11 +1238,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } public int reparentWindow(NativeWindow newParent, boolean forceDestroyCreate) { - if(isNativeValid()) { - // force recreation if offscreen, since it may become onscreen - forceDestroyCreate |= !getGraphicsConfiguration().getChosenCapabilities().isOnscreen(); - } - ReparentActionImpl reparentAction = new ReparentActionImpl(newParent, forceDestroyCreate); + final ReparentActionImpl reparentAction = new ReparentActionImpl(newParent, forceDestroyCreate); runOnEDTIfAvail(true, reparentAction); return reparentAction.getStrategy(); } diff --git a/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java b/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java index d57910957..292a9c255 100644 --- a/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java +++ b/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java @@ -37,6 +37,7 @@ package jogamp.newt.driver.macosx; import javax.media.nativewindow.GraphicsConfigurationFactory; import javax.media.nativewindow.NativeWindow; import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.SurfaceChangeable; import javax.media.nativewindow.util.Insets; import javax.media.nativewindow.util.InsetsImmutable; import javax.media.nativewindow.util.Point; @@ -46,7 +47,7 @@ import jogamp.newt.WindowImpl; import com.jogamp.newt.event.KeyEvent; -public class MacWindow extends WindowImpl { +public class MacWindow extends WindowImpl implements SurfaceChangeable { // Window styles private static final int NSBorderlessWindowMask = 0; @@ -135,6 +136,7 @@ public class MacWindow extends WindowImpl { private static final int NSModeSwitchFunctionKey = 0xF747; private volatile long surfaceHandle; + private long sscSurfaceHandle; static { MacDisplay.initSingleton(); @@ -185,9 +187,28 @@ public class MacWindow extends WindowImpl { @Override public final long getSurfaceHandle() { - return surfaceHandle; + return 0 != sscSurfaceHandle ? sscSurfaceHandle : surfaceHandle; } + public void setSurfaceHandle(long surfaceHandle) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("MacWindow.setSurfaceHandle(): 0x"+Long.toHexString(surfaceHandle)); + } + sscSurfaceHandle = surfaceHandle; + if (isNativeValid()) { + if (0 != sscSurfaceHandle) { + orderOut0( 0!=getParentWindowHandle() ? getParentWindowHandle() : getWindowHandle() ); + } /** this is done by recreation! + else if (isVisible()){ + orderFront0( 0!=getParentWindowHandle() ? getParentWindowHandle() : getWindowHandle() ); + } */ + } + } + + public void surfaceSizeChanged(int width, int height) { + sizeChanged(false, width, height, false); + } + @Override protected void setTitleImpl(final String title) { setTitle0(getWindowHandle(), title); @@ -199,28 +220,32 @@ public class MacWindow extends WindowImpl { protected boolean reconfigureWindowImpl(int x, int y, int width, int height, int flags) { final PointImmutable pS = position2TopLevel(new Point(x, y)); + final boolean offscreenInstance = 0 != sscSurfaceHandle || isOffscreenInstance(this, this.getParent()); if(DEBUG_IMPLEMENTATION) { - System.err.println("MacWindow reconfig: "+x+"/"+y+" -> "+pS+" - "+width+"x"+height+", "+ - getReconfigureFlagsAsString(null, flags)); + System.err.println("MacWindow reconfig: "+x+"/"+y+" -> "+pS+" - "+width+"x"+height+ + ", offscreenInstance "+offscreenInstance+ + ", "+getReconfigureFlagsAsString(null, flags)); } if( getWindowHandle() == 0 ) { if( 0 != ( FLAG_IS_VISIBLE & flags) ) { - createWindow(false, pS, width, height, 0 != ( FLAG_IS_FULLSCREEN & flags)); + createWindow(offscreenInstance, false, pS, width, height, 0 != ( FLAG_IS_FULLSCREEN & flags)); // no native event .. visibleChanged(true, true); } /* else { ?? } */ } else { if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) && 0 == ( FLAG_IS_VISIBLE & flags) ) { - orderOut0(getWindowHandle()); + if ( !offscreenInstance ) { + orderOut0(getWindowHandle()); + } // no native event .. visibleChanged(true, false); - } + } if( 0 != ( FLAG_CHANGE_DECORATION & flags) || 0 != ( FLAG_CHANGE_PARENTING & flags) || 0 != ( FLAG_CHANGE_FULLSCREEN & flags) ) { - createWindow(true, pS, width, height, 0 != ( FLAG_IS_FULLSCREEN & flags)); + createWindow(offscreenInstance, true, pS, width, height, 0 != ( FLAG_IS_FULLSCREEN & flags)); if(isVisible()) { flags |= FLAG_CHANGE_VISIBILITY; } } if(x>=0 && y>=0) { @@ -234,11 +259,15 @@ public class MacWindow extends WindowImpl { sizeChanged(true, width, height, false); // incl. validation (incl. repositioning) } if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) && 0 != ( FLAG_IS_VISIBLE & flags) ) { - orderFront0(getWindowHandle()); + if( !offscreenInstance ) { + orderFront0(getWindowHandle()); + } // no native event .. visibleChanged(true, true); } - setAlwaysOnTop0(getWindowHandle(), 0 != ( FLAG_IS_ALWAYSONTOP & flags)); + if( !offscreenInstance ) { + setAlwaysOnTop0(getWindowHandle(), 0 != ( FLAG_IS_ALWAYSONTOP & flags)); + } } return true; } @@ -385,7 +414,7 @@ public class MacWindow extends WindowImpl { return keyChar; } - private void createWindow(final boolean recreate, + private void createWindow(final boolean offscreenInstance, final boolean recreate, final PointImmutable pS, final int width, final int height, final boolean fullscreen) { @@ -408,20 +437,24 @@ public class MacWindow extends WindowImpl { } setWindowHandle(createWindow0(getParentWindowHandle(), pS.getX(), pS.getY(), width, height, - config.getChosenCapabilities().isBackgroundOpaque(), + (config.getChosenCapabilities().isBackgroundOpaque() && !offscreenInstance), fullscreen, - (isUndecorated() ? - NSBorderlessWindowMask : - NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask), + ((isUndecorated() || offscreenInstance) ? + NSBorderlessWindowMask : + NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask), NSBackingStoreBuffered, getScreen().getIndex(), surfaceHandle)); if (getWindowHandle() == 0) { throw new NativeWindowException("Could create native window "+Thread.currentThread().getName()+" "+this); } surfaceHandle = contentView0(getWindowHandle()); - setTitle0(getWindowHandle(), getTitle()); - // need to revalidate real position - positionChanged(true, getLocationOnScreenImpl(0, 0)); // incl. validation + if( offscreenInstance ) { + orderOut0(0!=getParentWindowHandle() ? getParentWindowHandle() : getWindowHandle()); + } else { + setTitle0(getWindowHandle(), getTitle()); + // need to revalidate real position + positionChanged(true, getLocationOnScreenImpl(0, 0)); // incl. validation + } } catch (Exception ie) { ie.printStackTrace(); } diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingOffscreenLayer01AWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingOffscreenLayer01AWT.java index 018b52f16..378d43049 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingOffscreenLayer01AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingOffscreenLayer01AWT.java @@ -132,6 +132,11 @@ public class TestParentingOffscreenLayer01AWT extends UITestCase { testOffscreenLayerPath1_Impl(true); } + @Test + public void testOffscreenLayerPath1_NewtOnscreen() throws InterruptedException, InvocationTargetException { + testOffscreenLayerPath1_Impl(false); + } + private void testOffscreenLayerPath1_Impl(boolean newtOffscreenClass) throws InterruptedException, InvocationTargetException { if( newtOffscreenClass && !JAWTUtil.isCachedJAWTUsingOffscreenLayer() ) { System.err.println("JAWT OffscreenLayer n/a on this platform."); |