diff options
Diffstat (limited to 'src')
15 files changed, 507 insertions, 116 deletions
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java index 4ab81e5ff..8e845e847 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java @@ -422,7 +422,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl System.err.println("NS create pixelFormat: "+toHexString(pixelFormat)); System.err.println("NS create drawable native-handle: "+toHexString(drawable.getHandle())); System.err.println("NS create drawable NSView-handle: "+toHexString(drawable.getNSViewHandle())); - Thread.dumpStack(); + // Thread.dumpStack(); } try { int[] viewNotReady = new int[1]; diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java index 95401db83..e08461527 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java @@ -266,7 +266,7 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl { if( nwThis instanceof MacOSXJAWTWindow) { // direct surface host, eg. via AWT GLCanvas final MacOSXJAWTWindow r = (MacOSXJAWTWindow) nwThis; - return r.isLayeredSurface() ? r : null; + return r.isOffscreenLayerSurface() ? r : null; } else { // parent surface host, eg. via native parenting w/ NewtCanvasAWT NativeWindow nwParent = nwThis.getParent(); @@ -276,7 +276,7 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl { } if(null != nwParent && nwParent instanceof MacOSXJAWTWindow) { final MacOSXJAWTWindow r = (MacOSXJAWTWindow) nwParent; - return r.isLayeredSurface() ? r : null; + return r.isOffscreenLayerSurface() ? r : null; } } } diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java index c29a5f9b5..5c4c3907c 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java @@ -51,14 +51,10 @@ import javax.media.opengl.GLDrawableFactory; import javax.media.opengl.GLException; import javax.media.opengl.GLProfile; -import jogamp.opengl.Debug; - import com.jogamp.common.nio.PointerBuffer; import com.jogamp.opengl.util.GLBuffers; -public class MacOSXPbufferCGLDrawable extends MacOSXCGLDrawable { - private static final boolean DEBUG = Debug.debug("MacOSXPbufferCGLDrawable"); - +public class MacOSXPbufferCGLDrawable extends MacOSXCGLDrawable { // Abstract interface for implementation of this drawable (either // NSOpenGL-based or CGL-based) interface GLBackendImpl { @@ -171,9 +167,10 @@ public class MacOSXPbufferCGLDrawable extends MacOSXCGLDrawable { pBuffer = impl.create(pBufferTexTarget, internalFormat, getWidth(), getHeight()); if(DEBUG) { System.err.println("MacOSXPbufferCGLDrawable tex: target "+toHexString(pBufferTexTarget)+ - ", size "+toHexString(pBufferTexWidth)+"x"+toHexString(pBufferTexHeight)+ + ", size "+pBufferTexWidth+"x"+pBufferTexHeight+ ", internal-fmt "+toHexString(internalFormat)); System.err.println("MacOSXPbufferCGLDrawable pBuffer: "+toHexString(pBuffer)); + // Thread.dumpStack(); } if (pBuffer == 0) { throw new GLException("pbuffer creation error: CGL.createPBuffer() failed"); diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface-pbuffer.m b/src/jogl/native/macosx/MacOSXWindowSystemInterface-pbuffer.m index 6e6e1e2c2..ef6d11419 100644 --- a/src/jogl/native/macosx/MacOSXWindowSystemInterface-pbuffer.m +++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface-pbuffer.m @@ -122,14 +122,13 @@ static CVReturn renderMyNSOpenGLLayer(CVDisplayLinkRef displayLink, displayLink = NULL; } } - /** if(NULL != displayLink) { cvres = CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink, [_ctx CGLContextObj], [_fmt CGLPixelFormatObj]); if(kCVReturnSuccess != cvres) { DBG_PRINT("MyNSOpenGLLayer::init %p, CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext failed: %d\n", self, cvres); displayLink = NULL; } - } */ + } if(NULL != displayLink) { cvres = CVDisplayLinkSetOutputCallback(displayLink, renderMyNSOpenGLLayer, self); if(kCVReturnSuccess != cvres) { @@ -150,8 +149,12 @@ static CVReturn renderMyNSOpenGLLayer(CVDisplayLinkRef displayLink, textureID = 0; swapInterval = -1; shallDraw = NO; - DBG_PRINT("MyNSOpenGLLayer::init %p, ctx %p, pfmt %p, pbuffer %p, opaque %d, pbuffer %dx%d -> tex %dx%d\n", - self, _ctx, _fmt, pbuffer, opaque, [pbuffer pixelsWide], [pbuffer pixelsHigh], texWidth, texHeight); + + CGRect lRect = [self frame]; + + DBG_PRINT("MyNSOpenGLLayer::init %p, ctx %p, pfmt %p, pbuffer %p, opaque %d, pbuffer %dx%d -> tex %dx%d, frame: %lf/%lf %lfx%lf\n", + self, _ctx, _fmt, pbuffer, opaque, [pbuffer pixelsWide], [pbuffer pixelsHigh], texWidth, texHeight, + lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.height); return self; } @@ -193,6 +196,7 @@ static CVReturn renderMyNSOpenGLLayer(CVDisplayLinkRef displayLink, forLayerTime:(CFTimeInterval)timeInterval displayTime:(const CVTimeStamp *)timeStamp { [context makeCurrentContext]; + // FIXME ?? [context update]; /** * v-sync doesn't works w/ NSOpenGLLayer's context .. well :( @@ -220,6 +224,17 @@ static CVReturn renderMyNSOpenGLLayer(CVDisplayLinkRef displayLink, glGenTextures(1, &textureID); DBG_PRINT("MyNSOpenGLLayer::drawInOpenGLContext %p, ctx %p, pfmt %p tex %dx%d -> %fx%f 0x%X: creating texID 0x%X\n", self, context, pixelFormat, texWidth, texHeight, tWidth, tHeight, textureTarget, textureID); + + CGRect lRect = [self frame]; + DBG_PRINT("MyNSOpenGLLayer::drawInOpenGLContext %p frame0: %lf/%lf %lfx%lf\n", + self, lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.height); + if(lRect.origin.x<0 || lRect.origin.y<0) { + lRect.origin.x = 0; + lRect.origin.y = 0; + [self setFrame: lRect]; + DBG_PRINT("MyNSOpenGLLayer::drawInOpenGLContext %p frame*: %lf/%lf %lfx%lf\n", + self, lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.height); + } } glBindTexture(textureTarget, textureID); diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java index d83a92a5b..38ad2d795 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java +++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java @@ -41,6 +41,7 @@ package javax.media.nativewindow.awt; import javax.media.nativewindow.*; + import java.awt.Component; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; @@ -98,12 +99,42 @@ public class AWTGraphicsConfiguration extends DefaultGraphicsConfiguration imple if(null==capsChosen) { GraphicsConfiguration gc = awtGraphicsDevice.getDefaultConfiguration(); - capsChosen = setupCapabilitiesRGBABits(capsChosen, gc); + capsChosen = setupCapabilitiesRGBABits(capsRequested, gc); } return new AWTGraphicsConfiguration(awtScreen, capsChosen, capsRequested, awtGfxConfig); } - @Override + public void updateGraphicsConfiguration(Component awtComp) + { + AWTGraphicsScreen awtScreen = null; + AWTGraphicsDevice awtDevice = null; + GraphicsDevice awtGraphicsDevice = null; + GraphicsConfiguration awtGfxConfig = awtComp.getGraphicsConfiguration(); + if(null!=awtGfxConfig) { + awtGraphicsDevice = awtGfxConfig.getDevice(); + if(null!=awtGraphicsDevice) { + // Create Device/Screen + awtDevice = new AWTGraphicsDevice(awtGraphicsDevice, AbstractGraphicsDevice.DEFAULT_UNIT); + awtScreen = new AWTGraphicsScreen(awtDevice); + } + } + if(null==awtScreen) { + throw new NativeWindowException("native peer n/a: "+awtComp); + } + config = awtGfxConfig; + setScreen(awtScreen); + + CapabilitiesImmutable caps = ( null != getChosenCapabilities() ) ? getChosenCapabilities() : getRequestedCapabilities(); + GraphicsConfiguration gc = awtGraphicsDevice.getDefaultConfiguration(); + setChosenCapabilities(setupCapabilitiesRGBABits(caps, gc)); + } + + // open access to superclass method + public void setChosenCapabilities(CapabilitiesImmutable capsChosen) { + super.setChosenCapabilities(capsChosen); + } + + @Override public Object clone() { return super.clone(); } diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java index a88ca678e..4435c4f8f 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTUtil.java @@ -77,20 +77,36 @@ public class JAWTUtil { boolean ok; } - public static boolean setJAWTVersionFlags(boolean useOffScreenLayerIfAvailable) { + /** + * Returns true if this platform's JAWT implementation supports + * or uses offscreen layer. + */ + public static boolean isOffscreenLayerSupported() { + return Platform.OS_TYPE == Platform.OSType.MACOS && + Platform.OS_VERSION_NUMBER.compareTo(JAWT.JAWT_MacOSXCALayerMinVersion) >= 0; + } + + /** + * + * FIXME: Need to get rid of the cached JAWT instance, + * in case we like to have dual usage of offscreenLayeredSurface and onscreen. + * This would be done implicit by using NEWT .. hence low prio. + * + * @param useOffscreenLayerIfAvailable + * @return + */ + public static boolean setCachedJAWTVersionFlags(boolean useOffscreenLayerIfAvailable) { if(JAWT.isJAWTInstantiated()) { return false; } // already instantiated - if(useOffScreenLayerIfAvailable && - Platform.OS_TYPE == Platform.OSType.MACOS && - Platform.OS_VERSION_NUMBER.compareTo(JAWT.JAWT_MacOSXCALayerMinVersion) >= 0) { + if(useOffscreenLayerIfAvailable && isOffscreenLayerSupported()) { JAWT.setJAWTVersionFlags(JAWTFactory.JAWT_VERSION_1_4 | JAWT.JAWT_MACOSX_USE_CALAYER); return true; } JAWT.setJAWTVersionFlags(JAWTFactory.JAWT_VERSION_1_4); - return !useOffScreenLayerIfAvailable; // n/a + return !useOffscreenLayerIfAvailable; // n/a } - public static boolean isJAWTVersionUsingOffscreenLayer() { + public static boolean isCachedJAWTUsingOffscreenLayer() { return 0 != ( JAWT.getJAWT().getVersionCached() & JAWT.JAWT_MACOSX_USE_CALAYER ); } diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java index 3f10fa983..151099f26 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java @@ -98,10 +98,7 @@ public abstract class JAWTWindow implements NativeWindow { windowObject = windowObject.getParent(); } if(isApplet) { - JAWTUtil.setJAWTVersionFlags(true); // useOffScreenLayerIfAvailable := true - } else { - // test - JAWTUtil.setJAWTVersionFlags(true); // useOffScreenLayerIfAvailable := true + JAWTUtil.setCachedJAWTVersionFlags(true); // useOffScreenLayerIfAvailable := true } validateNative(); } diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java index b75bb3f4d..5ac42e21b 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java @@ -64,7 +64,7 @@ import jogamp.nativewindow.macosx.OSXUtil; public class MacOSXJAWTWindow extends JAWTWindow implements SurfaceChangeable { public MacOSXJAWTWindow(Object comp, AbstractGraphicsConfiguration config) { super(comp, config); - isOffscreenLayeredSurface = JAWTUtil.isJAWTVersionUsingOffscreenLayer(); + isOffscreenLayerSurface = JAWTUtil.isCachedJAWTUsingOffscreenLayer(); dumpInfo(); } @@ -73,22 +73,22 @@ public class MacOSXJAWTWindow extends JAWTWindow implements SurfaceChangeable { protected void invalidateNative() { surfaceHandle=0; - if(isOffscreenLayeredSurface && 0 == drawable) { + if(isOffscreenLayerSurface && 0 == drawable) { OSXUtil.DestroyNSWindow(drawable); drawable = 0; } } - public final boolean isLayeredSurface() { - return isOffscreenLayeredSurface; + public final boolean isOffscreenLayerSurface() { + return isOffscreenLayerSurface; } public long getSurfaceHandle() { - return isOffscreenLayeredSurface ? surfaceHandle : super.getSurfaceHandle() ; + return isOffscreenLayerSurface ? surfaceHandle : super.getSurfaceHandle() ; } public void setSurfaceHandle(long surfaceHandle) { - if( !isLayeredSurface() ) { + if( !isOffscreenLayerSurface() ) { throw new java.lang.UnsupportedOperationException("Not using CALAYER"); } if(DEBUG) { @@ -109,8 +109,8 @@ public class MacOSXJAWTWindow extends JAWTWindow implements SurfaceChangeable { return getSurfaceLayers().getLayer(); } */ - public void attachSurfaceLayer(long layerHandle) { - if( !isLayeredSurface() ) { + public void attachSurfaceLayer(final long layerHandle) { + if( !isOffscreenLayerSurface() ) { throw new NativeWindowException("Not using CALAYER"); } int lockRes = lockSurface(); @@ -121,7 +121,7 @@ public class MacOSXJAWTWindow extends JAWTWindow implements SurfaceChangeable { if(DEBUG) { System.err.println("MacOSXJAWTWindow.attachSurfaceLayer(): 0x"+Long.toHexString(layerHandle)); } - OSXUtil.AttachJAWTSurfaceLayer0(dsi, layerHandle); + OSXUtil.AttachJAWTSurfaceLayer(dsi, layerHandle); } finally { unlockSurface(); } @@ -179,7 +179,7 @@ public class MacOSXJAWTWindow extends JAWTWindow implements SurfaceChangeable { dumpInfo(); } firstLock = false; - if( !isOffscreenLayeredSurface ) { + if( !isOffscreenLayerSurface ) { macosxdsi = (JAWT_MacOSXDrawingSurfaceInfo) dsi.platformInfo(); if (macosxdsi == null) { unlockSurfaceImpl(); @@ -258,7 +258,7 @@ public class MacOSXJAWTWindow extends JAWTWindow implements SurfaceChangeable { // System.err.println(this); System.err.println("JAWT version: 0x"+Integer.toHexString(JAWT.getJAWT().getVersionCached())+ ", CA_LAYER: "+ (0!=(JAWT.getJAWT().getVersionCached() & JAWT.JAWT_MACOSX_USE_CALAYER))+ - ", isLayeredSurface "+isLayeredSurface()); + ", isLayeredSurface "+isOffscreenLayerSurface()); if(null != dsi) { JAWT_Rectangle r = dsi.getBounds(); System.err.println("dsi bounds: "+r.getX()+"/"+r.getY()+" "+r.getWidth()+"x"+r.getHeight()); @@ -286,7 +286,7 @@ public class MacOSXJAWTWindow extends JAWTWindow implements SurfaceChangeable { private JAWT_MacOSXDrawingSurfaceInfo macosxdsi; // private JAWT_SurfaceLayers macosxsl; - final boolean isOffscreenLayeredSurface; + final boolean isOffscreenLayerSurface; long surfaceHandle = 0; // Workaround for instance of 4796548 diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java index 79ac24686..a07001def 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java @@ -51,7 +51,7 @@ public class OSXUtil { DestroyNSWindow0(nsWindow); } - public static boolean AttachJAWTSurfaceLayer0(JAWT_DrawingSurfaceInfo dsi, long caLayer) { + public static boolean AttachJAWTSurfaceLayer(JAWT_DrawingSurfaceInfo dsi, long caLayer) { return AttachJAWTSurfaceLayer0(dsi.getBuffer(), caLayer); } diff --git a/src/newt/classes/com/jogamp/newt/NewtFactory.java b/src/newt/classes/com/jogamp/newt/NewtFactory.java index d3be098c0..f38876128 100644 --- a/src/newt/classes/com/jogamp/newt/NewtFactory.java +++ b/src/newt/classes/com/jogamp/newt/NewtFactory.java @@ -34,14 +34,19 @@ package com.jogamp.newt; -import javax.media.nativewindow.*; - -import com.jogamp.common.os.Platform; +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.CapabilitiesImmutable; +import javax.media.nativewindow.NativeWindow; +import javax.media.nativewindow.NativeWindowFactory; +import jogamp.newt.Debug; import jogamp.newt.DisplayImpl; import jogamp.newt.ScreenImpl; import jogamp.newt.WindowImpl; -import jogamp.newt.Debug; + +import com.jogamp.common.os.Platform; public class NewtFactory { public static final boolean DEBUG_IMPLEMENTATION = Debug.debug("Window"); @@ -141,35 +146,34 @@ public class NewtFactory { * * @param parentWindowObject either a NativeWindow instance */ - public static Window createWindow(NativeWindow nParentWindow, CapabilitiesImmutable caps) { + public static Window createWindow(NativeWindow parentWindow, CapabilitiesImmutable caps) { final String type = NativeWindowFactory.getNativeWindowType(true); - Screen screen = null; - Window parentWindow = null; + Window newtParentWindow = null; - if ( nParentWindow instanceof Window ) { + if ( parentWindow instanceof Window ) { // use parent NEWT Windows Display/Screen - parentWindow = (Window) nParentWindow ; - screen = parentWindow.getScreen(); + newtParentWindow = (Window) parentWindow ; + screen = newtParentWindow.getScreen(); } else { // create a Display/Screen compatible to the NativeWindow - AbstractGraphicsConfiguration nParentConfig = nParentWindow.getGraphicsConfiguration(); - if(null!=nParentConfig) { - AbstractGraphicsScreen nParentScreen = nParentConfig.getScreen(); - AbstractGraphicsDevice nParentDevice = nParentScreen.getDevice(); - Display display = NewtFactory.createDisplay(type, nParentDevice.getHandle(), true); - screen = NewtFactory.createScreen(display, nParentScreen.getIndex()); + AbstractGraphicsConfiguration parentConfig = parentWindow.getGraphicsConfiguration(); + if(null!=parentConfig) { + AbstractGraphicsScreen parentScreen = parentConfig.getScreen(); + AbstractGraphicsDevice parentDevice = parentScreen.getDevice(); + Display display = NewtFactory.createDisplay(type, parentDevice.getHandle(), true); + screen = NewtFactory.createScreen(display, parentScreen.getIndex()); } else { Display display = NewtFactory.createDisplay(type, null, true); // local display screen = NewtFactory.createScreen(display, 0); // screen 0 } } - final Window win = createWindowImpl(nParentWindow, screen, caps); + final Window win = createWindowImpl(parentWindow, screen, caps); - win.setSize(nParentWindow.getWidth(), nParentWindow.getHeight()); - if ( null != parentWindow ) { - parentWindow.addChild(win); - win.setVisible(parentWindow.isVisible()); + win.setSize(parentWindow.getWidth(), parentWindow.getHeight()); + if ( null != newtParentWindow ) { + newtParentWindow.addChild(win); + win.setVisible(newtParentWindow.isVisible()); } return win; } diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java index 31d42d21b..4aaffb61f 100644 --- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java +++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java @@ -29,42 +29,52 @@ package com.jogamp.newt.awt; -import com.jogamp.newt.Display; -import java.lang.reflect.*; -import java.security.*; - import java.awt.Canvas; import java.awt.EventQueue; import java.awt.Graphics; import java.awt.GraphicsConfiguration; import java.awt.KeyboardFocusManager; - +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; + +import javax.media.nativewindow.Capabilities; +import javax.media.nativewindow.CapabilitiesImmutable; +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.NativeSurfaceHolder; import javax.media.nativewindow.NativeWindow; import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.NativeWindowHolder; import javax.media.nativewindow.WindowClosingProtocol; import javax.media.nativewindow.awt.AWTWindowClosingProtocol; -import jogamp.nativewindow.awt.AWTMisc; +import javax.swing.MenuSelectionManager; -import com.jogamp.newt.event.awt.AWTAdapter; -import com.jogamp.newt.event.WindowEvent; -import com.jogamp.newt.Window; -import com.jogamp.newt.event.WindowAdapter; -import com.jogamp.newt.event.WindowListener; +import jogamp.nativewindow.awt.AWTMisc; import jogamp.newt.Debug; import jogamp.newt.awt.event.AWTParentWindowAdapter; import jogamp.newt.awt.event.NewtFactoryAWT; -import javax.swing.MenuSelectionManager; +import com.jogamp.newt.Display; +import com.jogamp.newt.Window; +import com.jogamp.newt.event.WindowAdapter; +import com.jogamp.newt.event.WindowEvent; +import com.jogamp.newt.event.WindowListener; +import com.jogamp.newt.event.awt.AWTAdapter; +import com.jogamp.newt.event.awt.AWTKeyAdapter; +import com.jogamp.newt.event.awt.AWTMouseAdapter; @SuppressWarnings("serial") -public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProtocol { +public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProtocol, NativeSurfaceHolder, NativeWindowHolder { public static final boolean DEBUG = Debug.debug("Window"); NativeWindow nativeWindow = null; Window newtChild = null; + boolean isNewtChildOnscreen = true; int newtChildCloseOp; AWTAdapter awtAdapter = null; - + AWTAdapter awtMouseAdapter = null; + AWTAdapter awtKeyAdapter = null; + private AWTWindowClosingProtocol awtWindowClosingProtocol = new AWTWindowClosingProtocol(this, new Runnable() { public void run() { @@ -77,6 +87,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto */ public NewtCanvasAWT() { super(); + createNativeWindow(new Capabilities()); } /** @@ -84,6 +95,23 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto */ public NewtCanvasAWT(GraphicsConfiguration gc) { super(gc); + createNativeWindow(new Capabilities()); + } + + /** + * Instantiates a NewtCanvas without a NEWT child.<br> + */ + public NewtCanvasAWT(CapabilitiesImmutable caps) { + super(); + createNativeWindow(caps); + } + + /** + * Instantiates a NewtCanvas without a NEWT child.<br> + */ + public NewtCanvasAWT(GraphicsConfiguration gc, CapabilitiesImmutable caps) { + super(gc); + createNativeWindow(caps); } /** @@ -91,6 +119,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto */ public NewtCanvasAWT(Window child) { super(); + createNativeWindow(child.getRequestedCapabilities()); setNEWTChild(child); } @@ -99,9 +128,14 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto */ public NewtCanvasAWT(GraphicsConfiguration gc, Window child) { super(gc); + createNativeWindow(child.getRequestedCapabilities()); setNEWTChild(child); } + private final void createNativeWindow(CapabilitiesImmutable caps) { + nativeWindow = NewtFactoryAWT.getNativeWindow(this, caps); + } + class FocusAction implements Window.FocusRunnable { public boolean run() { if ( EventQueue.isDispatchThread() ) { @@ -128,7 +162,9 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto System.err.println("FocusActionImpl.run() "+Display.getThreadName()); } NewtCanvasAWT.this.requestFocusAWTParent(); - KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner(); + if(isNewtChildOnscreen) { + KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner(); + } } } FocusActionImpl focusActionImpl = new FocusActionImpl(); @@ -142,13 +178,13 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto } }; - /** sets a new NEWT child, provoking reparenting on the NEWT level. */ - /*package */ NewtCanvasAWT setNEWTChild(Window child) { + /** sets a new NEWT child, provoking reparenting. */ + private NewtCanvasAWT setNEWTChild(Window child) { if(newtChild!=child) { newtChild = child; - if(null!=nativeWindow) { - java.awt.Container cont = AWTMisc.getContainer(this); + if(isDisplayable()) { // reparent right away, addNotify has been called already + final java.awt.Container cont = AWTMisc.getContainer(this); reparentWindow( (null!=child) ? true : false, cont ); } } @@ -163,6 +199,9 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto /** @return this AWT Canvas NativeWindow representation, may be null in case {@link #removeNotify()} has been called, * or {@link #addNotify()} hasn't been called yet.*/ public NativeWindow getNativeWindow() { return nativeWindow; } + + /** See {@link #getNativeWindow()} */ + public NativeSurface getNativeSurface() { return nativeWindow; } public int getDefaultCloseOperation() { return awtWindowClosingProtocol.getDefaultCloseOperation(); @@ -172,11 +211,31 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto return awtWindowClosingProtocol.setDefaultCloseOperation(op); } + private final void configureNewtChildInputEventHandler() { + if(null==awtMouseAdapter && null != newtChild.getGraphicsConfiguration()) { + isNewtChildOnscreen = newtChild.getGraphicsConfiguration().getChosenCapabilities().isOnscreen(); + if(!isNewtChildOnscreen) { + // offscreen childs require AWT event fwd for key/mouse + awtMouseAdapter = new AWTMouseAdapter(newtChild).addTo(this); + awtKeyAdapter = new AWTKeyAdapter(newtChild).addTo(this); + } + } + } + /* package */ void configureNewtChild(boolean attach) { if(null!=awtAdapter) { awtAdapter.removeFrom(this); awtAdapter=null; } + if(null!=awtMouseAdapter) { + awtMouseAdapter.removeFrom(this); + awtMouseAdapter = null; + } + if(null!=awtKeyAdapter) { + awtKeyAdapter.removeFrom(this); + awtKeyAdapter = null; + } + if( null != newtChild ) { if(attach) { awtAdapter = new AWTParentWindowAdapter(newtChild).addTo(this); @@ -232,21 +291,34 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto newtChild.setFocusAction(null); // no AWT focus traversal .. if(add) { - nativeWindow = NewtFactoryAWT.getNativeWindow(this, newtChild.getRequestedCapabilities()); - if(null!=nativeWindow) { - if(DEBUG) { - System.err.println("NewtCanvasAWT.reparentWindow: "+newtChild); - } - final int w = cont.getWidth(); - final int h = cont.getHeight(); - setSize(w, h); - newtChild.setSize(w, h); - newtChild.reparentWindow(nativeWindow); - newtChild.setVisible(true); - configureNewtChild(true); - newtChild.sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout to listener - newtChild.windowRepaint(0, 0, w, h); + NewtFactoryAWT.updateGraphicsConfiguration(nativeWindow, this); + if(DEBUG) { + System.err.println("NewtCanvasAWT.reparentWindow: "+newtChild); + } + final int w; + final int h; + if(isPreferredSizeSet()) { + java.awt.Dimension d = getPreferredSize(); + w = d.width; + h = d.height; + } else { + final java.awt.Dimension min; + if(this.isMinimumSizeSet()) { + min = getMinimumSize(); + } else { + min = new java.awt.Dimension(0, 0); + } + java.awt.Insets ins = cont.getInsets(); + w = Math.max(min.width, cont.getWidth() - ins.left - ins.right); + h = Math.max(min.height, cont.getHeight() - ins.top - ins.bottom); } + setSize(w, h); + newtChild.setSize(w, h); + newtChild.reparentWindow(nativeWindow); + newtChild.setVisible(true); + configureNewtChild(true); + newtChild.sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout to listener + newtChild.windowRepaint(0, 0, w, h); } else { configureNewtChild(false); nativeWindow = null; @@ -273,7 +345,8 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto System.err.println("NewtCanvasAWT.destroy(): "+newtChild+", from "+cont); } configureNewtChild(false); - nativeWindow = null; + nativeWindow.destroy(); + nativeWindow=null; newtChild.setVisible(false); newtChild.reparentWindow(null); newtChild.destroy(); @@ -288,6 +361,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto public void paint(Graphics g) { awtWindowClosingProtocol.addClosingListenerOneShot(); if(null!=newtChild) { + configureNewtChildInputEventHandler(); newtChild.windowRepaint(0, 0, getWidth(), getHeight()); } } @@ -295,18 +369,21 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto public void update(Graphics g) { awtWindowClosingProtocol.addClosingListenerOneShot(); if(null!=newtChild) { + configureNewtChildInputEventHandler(); newtChild.windowRepaint(0, 0, getWidth(), getHeight()); } } - final void requestFocusAWTParent() { + private final void requestFocusAWTParent() { super.requestFocusInWindow(); } - final void requestFocusNEWTChild() { + private final void requestFocusNEWTChild() { if(null!=newtChild) { newtChild.setFocusAction(null); - KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner(); + if(isNewtChildOnscreen) { + KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner(); + } newtChild.requestFocus(); newtChild.setFocusAction(focusAction); } 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); + } + } + } 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 new file mode 100644 index 000000000..018b52f16 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingOffscreenLayer01AWT.java @@ -0,0 +1,222 @@ +/** + * Copyright 2011 JogAmp Community. All rights reserved. + * + * 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 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * 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.newt.parenting; + +import java.awt.BorderLayout; +import java.awt.Button; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Frame; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; + +import javax.media.opengl.GLAnimatorControl; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.awt.GLCanvas; + +import jogamp.nativewindow.jawt.JAWTUtil; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.jogamp.newt.Window; +import com.jogamp.newt.awt.NewtCanvasAWT; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.Animator; + +public class TestParentingOffscreenLayer01AWT extends UITestCase { + static Dimension frameSize; + static Dimension preferredGLSize; + static Dimension minGLSize; + static long durationPerTest = 800; + + @BeforeClass + public static void initClass() { + // force offscreen layer JAWT, if available + JAWTUtil.setCachedJAWTVersionFlags(true); // useOffScreenLayerIfAvailable := true + frameSize = new Dimension(500,300); + preferredGLSize = new Dimension(400,200); + minGLSize = new Dimension(200,100); + } + + private void setupFrameAndShow(final Frame f, java.awt.Component comp) throws InterruptedException, InvocationTargetException { + + Container c = new Container(); + c.setLayout(new BorderLayout()); + c.add(new Button("north"), BorderLayout.NORTH); + c.add(new Button("south"), BorderLayout.SOUTH); + c.add(new Button("east"), BorderLayout.EAST); + c.add(new Button("west"), BorderLayout.WEST); + c.add(comp, BorderLayout.CENTER); + + f.setLayout(new BorderLayout()); + f.add(new Button("NORTH"), BorderLayout.NORTH); + f.add(new Button("SOUTH"), BorderLayout.SOUTH); + f.add(new Button("EAST"), BorderLayout.EAST); + f.add(new Button("WEST"), BorderLayout.WEST); + f.add(c, BorderLayout.CENTER); + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + // f.pack(); + f.validate(); + f.setVisible(true); + }}); + } + private void end(GLAnimatorControl actrl, final Frame f, Window w) throws InterruptedException, InvocationTargetException { + actrl.stop(); + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + f.dispose(); + } } ); + if(null != w) { + w.destroy(); + } + } + + @Test + public void testOffscreenLayerPath0_GLCanvas() throws InterruptedException, InvocationTargetException { + final Frame frame1 = new Frame("AWT Parent Frame"); + + GLCapabilities glCaps = new GLCapabilities(null); + final GLCanvas glc = new GLCanvas(glCaps); + glc.setPreferredSize(preferredGLSize); + glc.setMinimumSize(minGLSize); + + GLEventListener demo1 = new GearsES2(1); + glc.addGLEventListener(demo1); + + frame1.setSize(frameSize); + setupFrameAndShow(frame1, glc); + + GLAnimatorControl animator1 = new Animator(glc); + animator1.start(); + + Thread.sleep(durationPerTest); + end(animator1, frame1, null); + } + + @Test + public void testOffscreenLayerPath1_NewtOffscreen() throws InterruptedException, InvocationTargetException { + testOffscreenLayerPath1_Impl(true); + } + + private void testOffscreenLayerPath1_Impl(boolean newtOffscreenClass) throws InterruptedException, InvocationTargetException { + if( newtOffscreenClass && !JAWTUtil.isCachedJAWTUsingOffscreenLayer() ) { + System.err.println("JAWT OffscreenLayer n/a on this platform."); + return; + } + final Frame frame1 = new Frame("AWT Parent Frame"); + + GLCapabilities glCaps = new GLCapabilities(null); + if(newtOffscreenClass) { + glCaps.setOnscreen(false); + glCaps.setPBuffer(true); + } + + GLWindow glWindow1 = GLWindow.create(glCaps); + + final NewtCanvasAWT newtCanvasAWT1 = new NewtCanvasAWT(glWindow1); + newtCanvasAWT1.setPreferredSize(preferredGLSize); + newtCanvasAWT1.setMinimumSize(minGLSize); + + GLEventListener demo1 = new GearsES2(1); + setDemoFields(demo1, glWindow1, false); + glWindow1.addGLEventListener(demo1); + glWindow1.addKeyListener(new NewtAWTReparentingKeyAdapter(frame1, newtCanvasAWT1, glWindow1)); + + frame1.setSize(frameSize); + setupFrameAndShow(frame1, newtCanvasAWT1); + Assert.assertTrue(glWindow1.isNativeValid()); + Assert.assertEquals(newtCanvasAWT1.getNativeWindow(),glWindow1.getParent()); + + GLAnimatorControl animator1 = new Animator(glWindow1); + animator1.start(); + + Thread.sleep(durationPerTest); + end(animator1, frame1, glWindow1); + } + + // @Test + public void testOffscreenLayerPath2_NewtOffscreen() throws InterruptedException, InvocationTargetException { + testOffscreenLayerPath2_Impl(true); + } + + private void testOffscreenLayerPath2_Impl(boolean newtOffscreenClass) throws InterruptedException, InvocationTargetException { + } + + public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { + Assert.assertNotNull(demo); + Assert.assertNotNull(glWindow); + Window window = glWindow.getWindow(); + if(debug) { + MiscUtils.setFieldIfExists(demo, "glDebug", true); + MiscUtils.setFieldIfExists(demo, "glTrace", true); + } + if(!MiscUtils.setFieldIfExists(demo, "window", window)) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = atoi(args[++i]); + } + } + String tstname = TestParentingOffscreenLayer01AWT.class.getName(); + /* + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); */ + org.junit.runner.JUnitCore.main(tstname); + } + +} |