From 46542168d64b37f544f61802693f15b59b224e4e Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 9 Nov 2011 07:42:20 +0100 Subject: OS X Layered View: Part5 NEWT/AWT Interaction ; Fix NSOpenGLLayer pos ; Cleanup Better JAWT* name for offscreen layer surface: - MacOSXCGLDrawableFactory, JAWTUtil, JAWTWindow, MacOSXJAWTWindow - FIXME: Need to get rid of the cached JAWT instance, in case we like to have dual usage of offscreenLayerSurface and onscreen. This would be done implicit by using NEWT .. hence low prio. AWTGraphicsConfiguration: - Fix create(): Use capsRequested for AWT aligned caps if capsChosen is null. (was capsChosen .. which is null) - Add updateGraphicsConfiguration() which allows to update the AWTGraphicsConfiguration. NewtFactoryAWT: - Add updateGraphicsConfiguration() .. entrypoint for AWTGraphicsConfiguration.updateGraphicsConfiguration() NSOpenGLLayer Impl: - For 'some reason' the layer's position is initially negative, fix it @ 1st 'draw' - Re-add CVDisplayLink OpenGL setting .. for what it's worth .. I don't know JAWTWindow: - Remove test setting: Only enable offscreenLayerSurface for applets if avail. (New unit test enables it seperatly) NewtCanvasAWT: - If NEWT child is offscreen, attach AWTMouseAdapter and AWTKeyAdapter to route these AWT input events to NEWT. - Don't loose-focus if NEWT child is offscreen. - Impl. NativeSurfaceHolder, NativeWindowHolder - NativeWindow is created at construction and it's GraphicsConfiguration updated at addNotify(..). - At addNotify/reparent: try harder to determine proper NEWT child size: - use preferred size if set - use minimum size if set - subtract insets from container size OffscreenWindow/WindowImpl: - Allow setSize() .. currently NOP for offscreen. - WindowImpl: Commented out recreate case for offscreen-setSize .. TEST: com.jogamp.opengl.test.junit.newt.parenting.TestParentingOffscreenLayer01AWT Passed tests: - GLCanvas - NewtCanvasAWT/OffscreenWindow --- src/newt/classes/jogamp/newt/OffscreenWindow.java | 7 ---- src/newt/classes/jogamp/newt/WindowImpl.java | 49 ++++++++++++++++------ .../jogamp/newt/awt/event/NewtFactoryAWT.java | 16 ++++++- 3 files changed, 52 insertions(+), 20 deletions(-) (limited to 'src/newt/classes/jogamp') diff --git a/src/newt/classes/jogamp/newt/OffscreenWindow.java b/src/newt/classes/jogamp/newt/OffscreenWindow.java index a7a930691..d6402c6bb 100644 --- a/src/newt/classes/jogamp/newt/OffscreenWindow.java +++ b/src/newt/classes/jogamp/newt/OffscreenWindow.java @@ -85,13 +85,6 @@ public class OffscreenWindow extends WindowImpl implements SurfaceChangeable { protected void requestFocusImpl(boolean reparented) { } - @Override - public void setSize(int width, int height) { - if(!isNativeValid()) { - super.setSize(width, height); - } - } - @Override public void setPosition(int x, int y) { // nop diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index 919c32f13..823868f2b 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -308,6 +308,30 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer return isNativeValid() ; } + private void recreate(boolean skipCreate) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("Window.recreate() START ("+getThreadName()+", "+this+")"); + } + if(!isNativeValid()) { + throw new InternalError("XXX"); + } + ScreenImpl retainedScreen = screen; + retainedScreen.addReference(); // +1 - retain over destroy + destroy(); + setScreen(retainedScreen); + retainedScreen.removeReference(); // -1 - release + if(!skipCreate) { + setVisible(true); // native creation + } + } + + private void setScreen(ScreenImpl newScreen) { // never null ! + removeScreenReference(); + screen = newScreen; + screen.addReference(); + screenReferenceAdded = false; + } + private void removeScreenReference() { if(screenReferenceAdded) { // be nice, probably already called recursive via @@ -821,6 +845,11 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } public void setSize(int width, int height) { + /** FIXME: freezes due to many resize events by eg AWT + if( isNativeValid() && !getGraphicsConfiguration().getChosenCapabilities().isOnscreen() ) { + recreate(true); // skip create, create is done here .. + } + */ runOnEDTIfAvail(true, new SetSizeActionImpl(width, height)); } @@ -927,7 +956,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer private ReparentActionImpl(NativeWindow newParentWindow, boolean forceDestroyCreate) { this.newParentWindow = newParentWindow; - this.forceDestroyCreate = forceDestroyCreate; + this.forceDestroyCreate = forceDestroyCreate | DEBUG_TEST_REPARENT_INCOMPATIBLE; this.reparentAction = -1; // ensure it's set } @@ -935,13 +964,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer return reparentAction; } - private void setScreen(ScreenImpl newScreen) { // never null ! - WindowImpl.this.removeScreenReference(); - screen = newScreen; - screen.addReference(); - screenReferenceAdded = false; - } - public final void run() { boolean animatorPaused = false; if(null!=lifecycleHook) { @@ -973,7 +995,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer long newParentWindowHandle = 0 ; if(DEBUG_IMPLEMENTATION) { - System.err.println("Window.reparent: START ("+getThreadName()+") windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle)+", visible "+wasVisible+", old parentWindow: "+Display.hashCodeNullSafe(parentWindow)+", new parentWindow: "+Display.hashCodeNullSafe(newParentWindow)+", forceDestroyCreate "+forceDestroyCreate+", DEBUG_TEST_REPARENT_INCOMPATIBLE "+DEBUG_TEST_REPARENT_INCOMPATIBLE+" "+x+"/"+y+" "+width+"x"+height); + System.err.println("Window.reparent: START ("+getThreadName()+") valid "+isNativeValid()+", windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle)+", visible "+wasVisible+", old parentWindow: "+Display.hashCodeNullSafe(parentWindow)+", new parentWindow: "+Display.hashCodeNullSafe(newParentWindow)+", forceDestroyCreate "+forceDestroyCreate+", "+x+"/"+y+" "+width+"x"+height); } if(null!=lifecycleHook) { @@ -1024,8 +1046,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } else { reparentAction = ACTION_NATIVE_CREATION_PENDING; } - } else if ( DEBUG_TEST_REPARENT_INCOMPATIBLE || forceDestroyCreate || - !NewtFactory.isScreenCompatible(newParentWindow, getScreen()) ) { + } else if ( forceDestroyCreate || !NewtFactory.isScreenCompatible(newParentWindow, getScreen()) ) { // Destroy this window, may create a new compatible Screen/Display, // and mark it for creation. destroy(); @@ -1056,7 +1077,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer if( 0 == parentWindowHandle ) { // Already Top Window reparentAction = ACTION_UNCHANGED; - } else if( !isNativeValid() || DEBUG_TEST_REPARENT_INCOMPATIBLE || forceDestroyCreate ) { + } else if( !isNativeValid() || forceDestroyCreate ) { // Destroy this window and mark it for [pending] creation. destroy(); if( 0 "+awtNative); } return awtNative; } + + public static void updateGraphicsConfiguration(NativeWindow nw, java.awt.Component awtComp) { + if(! ( nw instanceof JAWTWindow ) ) { + throw new NativeWindowException("Not an AWT NativeWindow: "+nw); + } + final AWTGraphicsConfiguration awtConfig = (AWTGraphicsConfiguration) nw.getGraphicsConfiguration(); + awtConfig.updateGraphicsConfiguration(awtComp); + if(DEBUG_IMPLEMENTATION) { + System.err.println("NewtFactoryAWT.updateGraphicsConfiguration: "+awtComp+" -> "+nw); + } + } + } -- cgit v1.2.3