diff options
Diffstat (limited to 'src/newt/classes/jogamp')
-rw-r--r-- | src/newt/classes/jogamp/newt/OffscreenWindow.java | 7 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/WindowImpl.java | 49 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/awt/event/NewtFactoryAWT.java | 16 |
3 files changed, 52 insertions, 20 deletions
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 @@ -86,13 +86,6 @@ public class OffscreenWindow extends WindowImpl implements SurfaceChangeable { } @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<width*height ) { @@ -1219,6 +1240,10 @@ 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); runOnEDTIfAvail(true, reparentAction); return reparentAction.getStrategy(); diff --git a/src/newt/classes/jogamp/newt/awt/event/NewtFactoryAWT.java b/src/newt/classes/jogamp/newt/awt/event/NewtFactoryAWT.java index aa98d3a37..1d11887fb 100644 --- a/src/newt/classes/jogamp/newt/awt/event/NewtFactoryAWT.java +++ b/src/newt/classes/jogamp/newt/awt/event/NewtFactoryAWT.java @@ -34,6 +34,8 @@ import javax.media.nativewindow.*; import javax.media.nativewindow.awt.*; import com.jogamp.newt.NewtFactory; + +import jogamp.nativewindow.jawt.JAWTWindow; import jogamp.newt.Debug; public class NewtFactoryAWT extends NewtFactory { @@ -62,12 +64,24 @@ public class NewtFactoryAWT extends NewtFactory { } public static NativeWindow getNativeWindow(java.awt.Component awtComp, CapabilitiesImmutable capsRequested) { - DefaultGraphicsConfiguration config = AWTGraphicsConfiguration.create(awtComp, capsRequested, capsRequested); + AWTGraphicsConfiguration config = AWTGraphicsConfiguration.create(awtComp, null, capsRequested); NativeWindow awtNative = NativeWindowFactory.getNativeWindow(awtComp, config); // a JAWTWindow if(DEBUG_IMPLEMENTATION) { System.err.println("NewtFactoryAWT.getNativeWindow: "+awtComp+" -> "+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); + } + } + } |