From ebe980ad6ac40148bc84913d1ba1f7adf6200490 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 6 Jun 2014 12:51:45 +0200 Subject: Bug 741 HiDPI: Add new NativeSurfaceHolder interface to GLDrawable and NativeWindow; [AWT|SWT]NewtEventFactory use NativeSurfaceHolder as source, fixes pixel unit conversion - Add new NativeSurfaceHolder interface to GLDrawable and NativeWindow, allowing NativeSurface access (pixel unit conversion) A NativeSurfaceHolder is e.g.: - NativeWindow (is-a) - NEWT [GL]Window - GLDrawable (has-a) - [AWT|SWT]GLCanvas - [AWT|SWT]NewtEventFactory use NativeSurfaceHolder as source, fixes pixel unit conversion --- .../classes/javax/media/opengl/GLDrawable.java | 9 +- .../com/jogamp/nativewindow/awt/JAWTWindow.java | 3 + .../media/nativewindow/NativeSurfaceHolder.java | 41 +++++++++ .../javax/media/nativewindow/NativeWindow.java | 11 ++- .../classes/jogamp/nativewindow/WrappedWindow.java | 4 + .../classes/com/jogamp/newt/awt/NewtCanvasAWT.java | 26 +++--- .../com/jogamp/newt/event/awt/AWTAdapter.java | 68 ++++++++++++--- .../com/jogamp/newt/event/awt/AWTKeyAdapter.java | 10 ++- .../com/jogamp/newt/event/awt/AWTMouseAdapter.java | 22 ++--- .../jogamp/newt/event/awt/AWTWindowAdapter.java | 23 ++--- .../classes/com/jogamp/newt/swt/NewtCanvasSWT.java | 3 + src/newt/classes/jogamp/newt/WindowImpl.java | 3 + .../jogamp/newt/awt/event/AWTNewtEventFactory.java | 46 +++++----- .../jogamp/newt/swt/event/SWTNewtEventFactory.java | 99 +++++++++++++--------- .../glels/TestGLContextDrawableSwitch02AWT.java | 7 +- .../jogl/awt/TestBug816OSXCALayerPos01AWT.java | 5 +- .../jogl/awt/TestBug816OSXCALayerPos02AWT.java | 4 +- .../awt/TestBug816OSXCALayerPos03aB729AWT.java | 4 +- .../awt/TestBug816OSXCALayerPos03bB849AWT.java | 4 +- .../awt/TestBug816OSXCALayerPos03cB849AWT.java | 4 +- .../jogl/awt/TestBug816OSXCALayerPos04aAWT.java | 46 +++++----- .../jogl/awt/TestBug816OSXCALayerPos04bAWT.java | 46 +++++----- .../jogl/awt/TestGLJPanelTextureStateAWT.java | 88 +++++++++---------- .../opengl/test/junit/jogl/demos/es1/GearsES1.java | 4 +- .../opengl/test/junit/jogl/demos/es2/GearsES2.java | 4 +- .../jogl/demos/es2/TextureSequenceCubeES2.java | 2 +- .../junit/jogl/demos/es2/awt/TestGearsES2AWT.java | 7 +- .../demos/es2/awt/TestGearsES2GLJPanelAWT.java | 7 +- .../opengl/test/junit/jogl/demos/gl2/Gears.java | 4 +- .../junit/jogl/demos/gl2/awt/TestGearsAWT.java | 27 +++--- .../demos/gl2/awt/TestGearsAWTAnalyzeBug455.java | 30 ++++--- .../jogl/demos/gl2/awt/TestGearsGLJPanelAWT.java | 31 +++---- .../jogl/tile/TestRandomTiledRendering3GL2AWT.java | 52 ++++++------ .../junit/jogl/tile/TestTiledPrintingGearsAWT.java | 58 ++++++------- .../jogl/tile/TestTiledPrintingGearsNewtAWT.java | 56 ++++++------ .../jogl/tile/TestTiledPrintingGearsSwingAWT.java | 9 +- .../jogl/tile/TestTiledPrintingGearsSwingAWT2.java | 7 +- .../util/texture/TestPNGTextureFromFileAWT.java | 71 ++++++++-------- .../util/texture/TestTextureSequence01AWT.java | 13 +-- .../event/TestNewtEventModifiersAWTCanvas.java | 16 ++-- 40 files changed, 561 insertions(+), 413 deletions(-) create mode 100644 src/nativewindow/classes/javax/media/nativewindow/NativeSurfaceHolder.java diff --git a/src/jogl/classes/javax/media/opengl/GLDrawable.java b/src/jogl/classes/javax/media/opengl/GLDrawable.java index e93d1c3ad..57883c8ac 100644 --- a/src/jogl/classes/javax/media/opengl/GLDrawable.java +++ b/src/jogl/classes/javax/media/opengl/GLDrawable.java @@ -42,6 +42,7 @@ package javax.media.opengl; import javax.media.nativewindow.AbstractGraphicsConfiguration; import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.NativeSurfaceHolder; /** An abstraction for an OpenGL rendering target. A GLDrawable's @@ -50,7 +51,7 @@ import javax.media.nativewindow.NativeSurface; create an OpenGL context, but all implementations of {@link GLAutoDrawable} do so upon creation. */ -public interface GLDrawable { +public interface GLDrawable extends NativeSurfaceHolder { /** * Creates a new context for drawing to this drawable that will * optionally share buffer objects, textures and other server-side OpenGL @@ -190,11 +191,15 @@ public interface GLDrawable { public GLProfile getGLProfile(); /** - * Returns the underlying native surface which surface handle + * {@inheritDoc} + *

+ * Returns the underlying {@link NativeSurface} which {@link NativeSurface#getSurfaceHandle() native handle} * represents this OpenGL drawable's native resource. + *

* * @see #getHandle() */ + @Override public NativeSurface getNativeSurface(); /** diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java index ea6ec893e..690d77901 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java @@ -633,6 +633,9 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, return getHeight() * getPixelScale(); } + @Override + public final NativeSurface getNativeSurface() { return this; } + // // NativeWindow // diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeSurfaceHolder.java b/src/nativewindow/classes/javax/media/nativewindow/NativeSurfaceHolder.java new file mode 100644 index 000000000..b459ab74a --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeSurfaceHolder.java @@ -0,0 +1,41 @@ +/** + * Copyright 2014 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 javax.media.nativewindow; + +/** + * Accessor interface for implementing classes with ownership of a {@link NativeSurface} + * via an is-a or has-a relation. + */ +public interface NativeSurfaceHolder { + /** + * Returns the associated {@link NativeSurface} of this {@link NativeSurfaceHolder}. + */ + public NativeSurface getNativeSurface(); +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java index 5e5f99aac..7f71bc33b 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java @@ -68,7 +68,16 @@ import javax.media.nativewindow.util.Point; * which can create NativeWindow objects for its components. *

*/ -public interface NativeWindow extends NativeSurface { +public interface NativeWindow extends NativeSurface, NativeSurfaceHolder { + + /** + * {@inheritDoc} + *

+ * Returns this instance, which is-a {@link NativeSurface}. + *

+ */ + @Override + public NativeSurface getNativeSurface(); /** * Destroys this window incl. releasing all related resources. diff --git a/src/nativewindow/classes/jogamp/nativewindow/WrappedWindow.java b/src/nativewindow/classes/jogamp/nativewindow/WrappedWindow.java index b93cbe7f5..403ec83c0 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/WrappedWindow.java +++ b/src/nativewindow/classes/jogamp/nativewindow/WrappedWindow.java @@ -2,6 +2,7 @@ package jogamp.nativewindow; import javax.media.nativewindow.AbstractGraphicsConfiguration; import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.NativeSurface; import javax.media.nativewindow.NativeWindow; import javax.media.nativewindow.ProxySurface; import javax.media.nativewindow.UpstreamSurfaceHook; @@ -65,6 +66,9 @@ public class WrappedWindow extends WrappedSurface implements NativeWindow { destroyNotify(); } + @Override + public final NativeSurface getNativeSurface() { return this; } + @Override public NativeWindow getParent() { return null; diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java index f6b2bab1f..37e9f9813 100644 --- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java +++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java @@ -104,7 +104,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto private boolean newtChildAttached = false; private boolean isOnscreen = true; private WindowClosingMode newtChildCloseOp; - private final AWTParentWindowAdapter awtAdapter; + private final AWTParentWindowAdapter awtWinAdapter; private final AWTAdapter awtMouseAdapter; private final AWTAdapter awtKeyAdapter; @@ -140,8 +140,8 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto super(); awtMouseAdapter = new AWTMouseAdapter().addTo(this); awtKeyAdapter = new AWTKeyAdapter().addTo(this); - awtAdapter = (AWTParentWindowAdapter) new AWTParentWindowAdapter().addTo(this); - awtAdapter.removeWindowClosingFrom(this); // we utilize AWTWindowClosingProtocol triggered destruction! + awtWinAdapter = (AWTParentWindowAdapter) new AWTParentWindowAdapter().addTo(this); + awtWinAdapter.removeWindowClosingFrom(this); // we utilize AWTWindowClosingProtocol triggered destruction! } /** @@ -151,8 +151,8 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto super(gc); awtMouseAdapter = new AWTMouseAdapter().addTo(this); awtKeyAdapter = new AWTKeyAdapter().addTo(this); - awtAdapter = (AWTParentWindowAdapter) new AWTParentWindowAdapter().addTo(this); - awtAdapter.removeWindowClosingFrom(this); // we utilize AWTWindowClosingProtocol triggered destruction! + awtWinAdapter = (AWTParentWindowAdapter) new AWTParentWindowAdapter().addTo(this); + awtWinAdapter.removeWindowClosingFrom(this); // we utilize AWTWindowClosingProtocol triggered destruction! } /** @@ -162,8 +162,8 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto super(); awtMouseAdapter = new AWTMouseAdapter().addTo(this); awtKeyAdapter = new AWTKeyAdapter().addTo(this); - awtAdapter = (AWTParentWindowAdapter) new AWTParentWindowAdapter().addTo(this); - awtAdapter.removeWindowClosingFrom(this); // we utilize AWTWindowClosingProtocol triggered destruction! + awtWinAdapter = (AWTParentWindowAdapter) new AWTParentWindowAdapter().addTo(this); + awtWinAdapter.removeWindowClosingFrom(this); // we utilize AWTWindowClosingProtocol triggered destruction! setNEWTChild(child); } @@ -174,8 +174,8 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto super(gc); awtMouseAdapter = new AWTMouseAdapter().addTo(this); awtKeyAdapter = new AWTKeyAdapter().addTo(this); - awtAdapter = (AWTParentWindowAdapter) new AWTParentWindowAdapter().addTo(this); - awtAdapter.removeWindowClosingFrom(this); // we utilize AWTWindowClosingProtocol triggered destruction! + awtWinAdapter = (AWTParentWindowAdapter) new AWTParentWindowAdapter().addTo(this); + awtWinAdapter.removeWindowClosingFrom(this); // we utilize AWTWindowClosingProtocol triggered destruction! setNEWTChild(child); } @@ -779,11 +779,9 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto } private final void configureNewtChild(boolean attach) { - awtAdapter.clear(); + awtWinAdapter.clear(); + awtKeyAdapter.clear(); awtMouseAdapter.clear(); - awtKeyAdapter.setConsumeAWTEvent(false); - awtMouseAdapter.clear(); - awtKeyAdapter.setConsumeAWTEvent(false); if(null != keyboardFocusManager) { keyboardFocusManager.removePropertyChangeListener("focusOwner", focusPropertyChangeListener); @@ -797,7 +795,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto throw new InternalError("XXX"); } isOnscreen = jawtWindow.getGraphicsConfiguration().getChosenCapabilities().isOnscreen(); - awtAdapter.setDownstream(jawtWindow, newtChild); + awtWinAdapter.setDownstream(jawtWindow, newtChild); newtChild.addWindowListener(clearAWTMenusOnNewtFocus); newtChild.setFocusAction(focusAction); // enable AWT focus traversal newtChildCloseOp = newtChild.setDefaultCloseOperation(WindowClosingMode.DO_NOTHING_ON_CLOSE); diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java index cf533eb9e..9b1348288 100644 --- a/src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java +++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTAdapter.java @@ -28,6 +28,8 @@ package com.jogamp.newt.event.awt; +import javax.media.nativewindow.NativeSurfaceHolder; + import jogamp.newt.Debug; /** @@ -117,37 +119,44 @@ public abstract class AWTAdapter implements java.util.EventListener com.jogamp.newt.event.NEWTEventListener newtListener; com.jogamp.newt.Window newtWindow; + NativeSurfaceHolder nsHolder; boolean consumeAWTEvent; protected boolean isSetup; /** - * Simply wrap aroung a NEWT EventListener, exposed as an AWT EventListener.
+ * Create a proxy adapter, wrapping around an NEWT EventListener, exposed as an AWT EventListener,
+ * where the given {@link NativeSurfaceHolder} impersonates the event's source. * The NEWT EventListener will be called when an event happens.
*/ - protected AWTAdapter(com.jogamp.newt.event.NEWTEventListener newtListener) { + protected AWTAdapter(com.jogamp.newt.event.NEWTEventListener newtListener, NativeSurfaceHolder nsProxy) { if(null==newtListener) { - throw new RuntimeException("Argument newtListener is null"); + throw new IllegalArgumentException("Argument newtListener is null"); + } + if(null==nsProxy) { + throw new IllegalArgumentException("Argument nwProxy is null"); } this.newtListener = newtListener; this.newtWindow = null; + this.nsHolder = nsProxy; this.consumeAWTEvent = false; this.isSetup = true; } /** - * Wrap aroung a NEWT EventListener, exposed as an AWT EventListener,
- * where the given NEWT Window impersonates as the event's source. + * Create a proxy adapter, wrapping around an NEWT EventListener, exposed as an AWT EventListener,
+ * where the given {@link com.jogamp.newt.Window NEWT Window}, a {@link NativeSurfaceHolder}, impersonates the event's source. * The NEWT EventListener will be called when an event happens.
*/ protected AWTAdapter(com.jogamp.newt.event.NEWTEventListener newtListener, com.jogamp.newt.Window newtProxy) { if(null==newtListener) { - throw new RuntimeException("Argument newtListener is null"); + throw new IllegalArgumentException("Argument newtListener is null"); } if(null==newtProxy) { - throw new RuntimeException("Argument newtProxy is null"); + throw new IllegalArgumentException("Argument newtProxy is null"); } this.newtListener = newtListener; this.newtWindow = newtProxy; + this.nsHolder = newtProxy; this.consumeAWTEvent = false; this.isSetup = true; } @@ -156,8 +165,9 @@ public abstract class AWTAdapter implements java.util.EventListener * Create a pipeline adapter, AWT EventListener.
* Once attached to an AWT component, it sends the converted AWT events to the NEWT downstream window.
* This is only supported with EDT enabled! + * @throws IllegalStateException if EDT is not enabled */ - protected AWTAdapter(com.jogamp.newt.Window downstream) { + protected AWTAdapter(com.jogamp.newt.Window downstream) throws IllegalStateException { this(); setDownstream(downstream); } @@ -171,26 +181,34 @@ public abstract class AWTAdapter implements java.util.EventListener * Setup a pipeline adapter, AWT EventListener.
* Once attached to an AWT component, it sends the converted AWT events to the NEWT downstream window.
* This is only supported with EDT enabled! + * @throws IllegalStateException if EDT is not enabled */ - public synchronized AWTAdapter setDownstream(com.jogamp.newt.Window downstream) { + public synchronized AWTAdapter setDownstream(com.jogamp.newt.Window downstream) throws IllegalStateException { if(null==downstream) { throw new RuntimeException("Argument downstream is null"); } this.newtListener = null; this.newtWindow = downstream; - this.consumeAWTEvent = false; + this.nsHolder = downstream; if( null == newtWindow.getScreen().getDisplay().getEDTUtil() ) { - throw new RuntimeException("EDT not enabled"); + throw new IllegalStateException("EDT not enabled"); } this.isSetup = true; return this; } - /** Removes all references, downstream and NEWT-EventListener. */ + /** + * Removes all references, downstream and NEWT-EventListener. + *

+ * Also sets the internal setup flag and {@link #setConsumeAWTEvent(boolean)} to false. + *

+ */ public synchronized AWTAdapter clear() { this.newtListener = null; this.newtWindow = null; + this.nsHolder = null; this.isSetup = false; + this.consumeAWTEvent = false; return this; } @@ -198,10 +216,36 @@ public abstract class AWTAdapter implements java.util.EventListener this.consumeAWTEvent = v; } + /** + * Returns the {@link NativeSurfaceHolder} acting {@link #AWTAdapter(com.jogamp.newt.Window) as downstream}, + * {@link #AWTAdapter(com.jogamp.newt.event.NEWTEventListener, com.jogamp.newt.Window) NEWT window proxy} + * or as an {@link #AWTAdapter(com.jogamp.newt.event.NEWTEventListener, NativeSurfaceHolder) NativeSurfaceHolder proxy}. + *

+ * Returned value is never null. + *

+ */ + public final synchronized NativeSurfaceHolder getNativeSurfaceHolder() { + return nsHolder; + } + + /** + * Returns the {@link com.jogamp.newt.Window NEWT Window} acting {@link #AWTAdapter(com.jogamp.newt.Window) as downstream} + * or as a {@link #AWTAdapter(com.jogamp.newt.event.NEWTEventListener, com.jogamp.newt.Window) NEWT window proxy}. + *

+ * Returned value maybe null if instance is used to be a + * {@link #AWTAdapter(com.jogamp.newt.event.NEWTEventListener, NativeSurfaceHolder) NativeSurfaceHolder proxy}. + *

+ */ public final synchronized com.jogamp.newt.Window getNewtWindow() { return newtWindow; } + /** + * Returns the {@link com.jogamp.newt.event.NEWTEventListener NEWT event-listener} if instance + * is used as an {@link #AWTAdapter(com.jogamp.newt.event.NEWTEventListener, NativeSurfaceHolder) NativeSurfaceHolder proxy} + * or {@link #AWTAdapter(com.jogamp.newt.event.NEWTEventListener, com.jogamp.newt.Window) NEWT window proxy}, + * otherwise method returns null. + */ public final synchronized com.jogamp.newt.event.NEWTEventListener getNewtEventListener() { return newtListener; } diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java index ddbeb6e42..5ea36bac8 100644 --- a/src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java +++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTKeyAdapter.java @@ -28,6 +28,8 @@ package com.jogamp.newt.event.awt; +import javax.media.nativewindow.NativeSurfaceHolder; + import jogamp.newt.awt.event.AWTNewtEventFactory; /** @@ -37,8 +39,8 @@ import jogamp.newt.awt.event.AWTNewtEventFactory; */ public class AWTKeyAdapter extends AWTAdapter implements java.awt.event.KeyListener { - public AWTKeyAdapter(com.jogamp.newt.event.KeyListener newtListener) { - super(newtListener); + public AWTKeyAdapter(com.jogamp.newt.event.KeyListener newtListener, NativeSurfaceHolder nsProxy) { + super(newtListener, nsProxy); } public AWTKeyAdapter(com.jogamp.newt.event.KeyListener newtListener, com.jogamp.newt.Window newtProxy) { @@ -68,7 +70,7 @@ public class AWTKeyAdapter extends AWTAdapter implements java.awt.event.KeyListe @Override public synchronized void keyPressed(java.awt.event.KeyEvent e) { if( !isSetup ) { return; } - final com.jogamp.newt.event.KeyEvent event = AWTNewtEventFactory.createKeyEvent(com.jogamp.newt.event.KeyEvent.EVENT_KEY_PRESSED, e, newtWindow); + final com.jogamp.newt.event.KeyEvent event = AWTNewtEventFactory.createKeyEvent(com.jogamp.newt.event.KeyEvent.EVENT_KEY_PRESSED, e, nsHolder); if( consumeAWTEvent ) { e.consume(); } @@ -80,7 +82,7 @@ public class AWTKeyAdapter extends AWTAdapter implements java.awt.event.KeyListe @Override public synchronized void keyReleased(java.awt.event.KeyEvent e) { if( !isSetup ) { return; } - final com.jogamp.newt.event.KeyEvent event = AWTNewtEventFactory.createKeyEvent(com.jogamp.newt.event.KeyEvent.EVENT_KEY_RELEASED, e, newtWindow); + final com.jogamp.newt.event.KeyEvent event = AWTNewtEventFactory.createKeyEvent(com.jogamp.newt.event.KeyEvent.EVENT_KEY_RELEASED, e, nsHolder); if( consumeAWTEvent ) { e.consume(); } diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.java index d0f73ef33..53fe70bf7 100644 --- a/src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.java +++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTMouseAdapter.java @@ -28,14 +28,16 @@ package com.jogamp.newt.event.awt; +import javax.media.nativewindow.NativeSurfaceHolder; + import jogamp.newt.awt.event.AWTNewtEventFactory; public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.MouseWheelListener { - public AWTMouseAdapter(com.jogamp.newt.event.MouseListener newtListener) { - super(newtListener); + public AWTMouseAdapter(com.jogamp.newt.event.MouseListener newtListener, NativeSurfaceHolder nsProxy) { + super(newtListener, nsProxy); } public AWTMouseAdapter(com.jogamp.newt.event.MouseListener newtListener, com.jogamp.newt.Window newtProxy) { @@ -69,7 +71,7 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL @Override public synchronized void mouseClicked(java.awt.event.MouseEvent e) { if( !isSetup ) { return; } - com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); + com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, nsHolder); if( consumeAWTEvent ) { e.consume(); } @@ -81,7 +83,7 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL @Override public synchronized void mouseEntered(java.awt.event.MouseEvent e) { if( !isSetup ) { return; } - com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); + com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, nsHolder); if( consumeAWTEvent ) { e.consume(); } @@ -93,7 +95,7 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL @Override public synchronized void mouseExited(java.awt.event.MouseEvent e) { if( !isSetup ) { return; } - com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); + com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, nsHolder); if( consumeAWTEvent ) { e.consume(); } @@ -105,7 +107,7 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL @Override public synchronized void mousePressed(java.awt.event.MouseEvent e) { if( !isSetup ) { return; } - com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); + com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, nsHolder); if( consumeAWTEvent ) { e.consume(); } @@ -117,7 +119,7 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL @Override public synchronized void mouseReleased(java.awt.event.MouseEvent e) { if( !isSetup ) { return; } - com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); + com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, nsHolder); if( consumeAWTEvent ) { e.consume(); } @@ -129,7 +131,7 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL @Override public synchronized void mouseDragged(java.awt.event.MouseEvent e) { if( !isSetup ) { return; } - com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); + com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, nsHolder); if( consumeAWTEvent ) { e.consume(); } @@ -141,7 +143,7 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL @Override public synchronized void mouseMoved(java.awt.event.MouseEvent e) { if( !isSetup ) { return; } - com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); + com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, nsHolder); if( consumeAWTEvent ) { e.consume(); } @@ -153,7 +155,7 @@ public class AWTMouseAdapter extends AWTAdapter implements java.awt.event.MouseL @Override public synchronized void mouseWheelMoved(java.awt.event.MouseWheelEvent e) { if( !isSetup ) { return; } - com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, newtWindow); + com.jogamp.newt.event.MouseEvent event = AWTNewtEventFactory.createMouseEvent(e, nsHolder); if( consumeAWTEvent ) { e.consume(); } diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java index 43a28b3b3..698fe86f4 100644 --- a/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java +++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java @@ -30,6 +30,8 @@ package com.jogamp.newt.event.awt; import java.awt.Dimension; +import javax.media.nativewindow.NativeSurfaceHolder; + import jogamp.newt.awt.event.AWTNewtEventFactory; public class AWTWindowAdapter @@ -38,8 +40,8 @@ public class AWTWindowAdapter { WindowClosingListener windowClosingListener; - public AWTWindowAdapter(com.jogamp.newt.event.WindowListener newtListener) { - super(newtListener); + public AWTWindowAdapter(com.jogamp.newt.event.WindowListener newtListener, NativeSurfaceHolder nsProxy) { + super(newtListener, nsProxy); } public AWTWindowAdapter(com.jogamp.newt.event.WindowListener newtListener, com.jogamp.newt.Window newtProxy) { @@ -49,6 +51,7 @@ public class AWTWindowAdapter public AWTWindowAdapter(com.jogamp.newt.Window downstream) { super(downstream); } + public AWTWindowAdapter() { super(); } @@ -100,7 +103,7 @@ public class AWTWindowAdapter @Override public synchronized void focusGained(java.awt.event.FocusEvent e) { if( !isSetup ) { return; } - com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); + com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, nsHolder); if(DEBUG_IMPLEMENTATION) { System.err.println("AWT: focusGained: "+e+" -> "+event); } @@ -112,7 +115,7 @@ public class AWTWindowAdapter @Override public synchronized void focusLost(java.awt.event.FocusEvent e) { if( !isSetup ) { return; } - com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); + com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, nsHolder); if(DEBUG_IMPLEMENTATION) { System.err.println("AWT: focusLost: "+e+" -> "+event); } @@ -124,7 +127,7 @@ public class AWTWindowAdapter @Override public synchronized void componentResized(java.awt.event.ComponentEvent e) { if( !isSetup ) { return; } - com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); + com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, nsHolder); if(DEBUG_IMPLEMENTATION) { final java.awt.Component c = e.getComponent(); final java.awt.Dimension sz = c.getSize(); @@ -148,7 +151,7 @@ public class AWTWindowAdapter @Override public synchronized void componentMoved(java.awt.event.ComponentEvent e) { if( !isSetup ) { return; } - com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); + com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, nsHolder); if(DEBUG_IMPLEMENTATION) { System.err.println("AWT: componentMoved: "+e+" -> "+event); } @@ -198,7 +201,7 @@ public class AWTWindowAdapter @Override public synchronized void windowActivated(java.awt.event.WindowEvent e) { if( !isSetup ) { return; } - com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); + com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, nsHolder); if( EventProcRes.DISPATCH == processEvent(false, event) ) { ((com.jogamp.newt.event.WindowListener)newtListener).windowGainedFocus(event); } @@ -213,7 +216,7 @@ public class AWTWindowAdapter @Override public synchronized void windowDeactivated(java.awt.event.WindowEvent e) { if( !isSetup ) { return; } - com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); + com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, nsHolder); if( EventProcRes.DISPATCH == processEvent(false, event) ) { ((com.jogamp.newt.event.WindowListener)newtListener).windowLostFocus(event); } @@ -233,7 +236,7 @@ public class AWTWindowAdapter public void windowClosing(java.awt.event.WindowEvent e) { synchronized( AWTWindowAdapter.this ) { if( !isSetup ) { return; } - com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); + com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, nsHolder); if( EventProcRes.DISPATCH == processEvent(true, event) ) { ((com.jogamp.newt.event.WindowListener)newtListener).windowDestroyNotify(event); } @@ -243,7 +246,7 @@ public class AWTWindowAdapter public void windowClosed(java.awt.event.WindowEvent e) { synchronized( AWTWindowAdapter.this ) { if( !isSetup ) { return; } - com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); + com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, nsHolder); if( EventProcRes.DISPATCH == processEvent(true, event) ) { ((com.jogamp.newt.event.WindowListener)newtListener).windowDestroyed(event); } diff --git a/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java b/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java index 93ecc8bb2..674d467f9 100644 --- a/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java +++ b/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java @@ -547,6 +547,9 @@ public class NewtCanvasSWT extends Canvas implements WindowClosingProtocol { return clientArea.height; } + @Override + public final NativeSurface getNativeSurface() { return this; } + @Override public AbstractGraphicsConfiguration getGraphicsConfiguration() { return config; diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index 2411f6595..5288bfcc5 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -853,6 +853,9 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer // public final void destroy() - see below + @Override + public final NativeSurface getNativeSurface() { return this; } + @Override public final NativeWindow getParent() { return parentWindow; diff --git a/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java b/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java index 709143b82..b04fd98f4 100644 --- a/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java +++ b/src/newt/classes/jogamp/newt/awt/event/AWTNewtEventFactory.java @@ -28,6 +28,9 @@ package jogamp.newt.awt.event; +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.NativeSurfaceHolder; + import com.jogamp.newt.event.MouseEvent; /** @@ -590,31 +593,31 @@ public class AWTNewtEventFactory { return defAwtKeyCode; } - public static final com.jogamp.newt.event.WindowEvent createWindowEvent(java.awt.event.WindowEvent event, com.jogamp.newt.Window newtSource) { + public static final com.jogamp.newt.event.WindowEvent createWindowEvent(final java.awt.event.WindowEvent event, final NativeSurfaceHolder sourceHolder) { final short newtType = eventTypeAWT2NEWT(event.getID()); if( (short)0 != newtType ) { - return new com.jogamp.newt.event.WindowEvent(newtType, ((null==newtSource)?(Object)event.getComponent():(Object)newtSource), System.currentTimeMillis()); + return new com.jogamp.newt.event.WindowEvent(newtType, sourceHolder, System.currentTimeMillis()); } return null; // no mapping .. } - public static final com.jogamp.newt.event.WindowEvent createWindowEvent(java.awt.event.ComponentEvent event, com.jogamp.newt.Window newtSource) { + public static final com.jogamp.newt.event.WindowEvent createWindowEvent(final java.awt.event.ComponentEvent event, final NativeSurfaceHolder sourceHolder) { final short newtType = eventTypeAWT2NEWT(event.getID()); if( (short)0 != newtType ) { - return new com.jogamp.newt.event.WindowEvent(newtType, (null==newtSource)?(Object)event.getComponent():(Object)newtSource, System.currentTimeMillis()); + return new com.jogamp.newt.event.WindowEvent(newtType, sourceHolder, System.currentTimeMillis()); } return null; // no mapping .. } - public static final com.jogamp.newt.event.WindowEvent createWindowEvent(java.awt.event.FocusEvent event, com.jogamp.newt.Window newtSource) { + public static final com.jogamp.newt.event.WindowEvent createWindowEvent(final java.awt.event.FocusEvent event, final NativeSurfaceHolder sourceHolder) { final short newtType = eventTypeAWT2NEWT(event.getID()); if( (short)0 != newtType ) { - return new com.jogamp.newt.event.WindowEvent(newtType, (null==newtSource)?(Object)event.getComponent():(Object)newtSource, System.currentTimeMillis()); + return new com.jogamp.newt.event.WindowEvent(newtType, sourceHolder, System.currentTimeMillis()); } return null; // no mapping .. } - public static final com.jogamp.newt.event.MouseEvent createMouseEvent(java.awt.event.MouseEvent event, com.jogamp.newt.Window newtSource) { + public static final com.jogamp.newt.event.MouseEvent createMouseEvent(final java.awt.event.MouseEvent event, final NativeSurfaceHolder sourceHolder) { final short newtType = eventTypeAWT2NEWT(event.getID()); if( (short)0 != newtType ) { float rotation = 0; @@ -626,35 +629,40 @@ public class AWTNewtEventFactory { final short newtButton = awtButton2Newt(event.getButton()); int mods = awtModifiers2Newt(event.getModifiers(), event.getModifiersEx()); mods |= com.jogamp.newt.event.InputEvent.getButtonMask(newtButton); // always include NEWT BUTTON_MASK + final NativeSurface source = sourceHolder.getNativeSurface(); final int[] pixelPos; - if(null!=newtSource) { - if(newtSource.isPointerConfined()) { - mods |= com.jogamp.newt.event.InputEvent.CONFINED_MASK; - } - if(!newtSource.isPointerVisible()) { - mods |= com.jogamp.newt.event.InputEvent.INVISIBLE_MASK; + if( null != source ) { + if( source instanceof com.jogamp.newt.Window ) { + final com.jogamp.newt.Window newtSource = (com.jogamp.newt.Window) source; + if(newtSource.isPointerConfined()) { + mods |= com.jogamp.newt.event.InputEvent.CONFINED_MASK; + } + if(!newtSource.isPointerVisible()) { + mods |= com.jogamp.newt.event.InputEvent.INVISIBLE_MASK; + } } - pixelPos = newtSource.convertToPixelUnits(new int[] { event.getX(), event.getY() }); + pixelPos = source.convertToPixelUnits(new int[] { event.getX(), event.getY() }); } else { pixelPos = new int[] { event.getX(), event.getY() }; } + return new com.jogamp.newt.event.MouseEvent( - newtType, (null==newtSource)?(Object)event.getComponent():(Object)newtSource, event.getWhen(), + newtType, sourceHolder, event.getWhen(), mods, pixelPos[0], pixelPos[1], (short)event.getClickCount(), newtButton, MouseEvent.getRotationXYZ(rotation, mods), 1f); } return null; // no mapping .. } - public static final com.jogamp.newt.event.KeyEvent createKeyEvent(java.awt.event.KeyEvent event, com.jogamp.newt.Window newtSource) { - return createKeyEvent(eventTypeAWT2NEWT(event.getID()), event, newtSource); + public static final com.jogamp.newt.event.KeyEvent createKeyEvent(final java.awt.event.KeyEvent event, final NativeSurfaceHolder sourceHolder) { + return createKeyEvent(eventTypeAWT2NEWT(event.getID()), event, sourceHolder); } - public static final com.jogamp.newt.event.KeyEvent createKeyEvent(short newtType, java.awt.event.KeyEvent event, com.jogamp.newt.Window newtSource) { + public static final com.jogamp.newt.event.KeyEvent createKeyEvent(final short newtType, final java.awt.event.KeyEvent event, final NativeSurfaceHolder sourceHolder) { if( (short)0 != newtType ) { final short newtKeyCode = awtKeyCode2NewtKeyCode( event.getKeyCode() ); return com.jogamp.newt.event.KeyEvent.create( - newtType, (null==newtSource)?(Object)event.getComponent():(Object)newtSource, event.getWhen(), + newtType, sourceHolder, event.getWhen(), awtModifiers2Newt(event.getModifiers(), event.getModifiersEx()), newtKeyCode, newtKeyCode, event.getKeyChar()); } diff --git a/src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java b/src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java index b5c45c1aa..386149b22 100644 --- a/src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java +++ b/src/newt/classes/jogamp/newt/swt/event/SWTNewtEventFactory.java @@ -28,6 +28,9 @@ package jogamp.newt.swt.event; +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.NativeSurfaceHolder; + import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; @@ -134,7 +137,7 @@ public class SWTNewtEventFactory { } public static int newtKeyCode2SWTKeyCode(final short newtKeyCode) { - final int defSWTKeyCode = 0xFFFF & (int)newtKeyCode; + final int defSWTKeyCode = 0xFFFF & newtKeyCode; switch (newtKeyCode) { case com.jogamp.newt.event.KeyEvent.VK_HOME : return SWT.HOME; case com.jogamp.newt.event.KeyEvent.VK_END : return SWT.END; @@ -199,15 +202,15 @@ public class SWTNewtEventFactory { } - public static final com.jogamp.newt.event.InputEvent createInputEvent(org.eclipse.swt.widgets.Event event, Object source) { - com.jogamp.newt.event.InputEvent res = createMouseEvent(event, source); + public static final com.jogamp.newt.event.InputEvent createInputEvent(org.eclipse.swt.widgets.Event event, NativeSurfaceHolder sourceHolder) { + com.jogamp.newt.event.InputEvent res = createMouseEvent(event, sourceHolder); if(null == res) { - res = createKeyEvent(event, source); + res = createKeyEvent(event, sourceHolder); } return res; } - public static final com.jogamp.newt.event.MouseEvent createMouseEvent(org.eclipse.swt.widgets.Event event, Object source) { + public static final com.jogamp.newt.event.MouseEvent createMouseEvent(org.eclipse.swt.widgets.Event event, NativeSurfaceHolder sourceHolder) { switch(event.type) { case SWT.MouseDown: case SWT.MouseUp: @@ -230,24 +233,31 @@ public class SWTNewtEventFactory { int mods = swtModifiers2Newt(event.stateMask, true); - if( source instanceof com.jogamp.newt.Window) { - final com.jogamp.newt.Window newtSource = (com.jogamp.newt.Window)source; - if(newtSource.isPointerConfined()) { - mods |= InputEvent.CONFINED_MASK; - } - if(!newtSource.isPointerVisible()) { - mods |= InputEvent.INVISIBLE_MASK; + final NativeSurface source = sourceHolder.getNativeSurface(); + final int[] pixelPos; + if( null != source ) { + if( source instanceof com.jogamp.newt.Window) { + final com.jogamp.newt.Window newtSource = (com.jogamp.newt.Window)source; + if(newtSource.isPointerConfined()) { + mods |= InputEvent.CONFINED_MASK; + } + if(!newtSource.isPointerVisible()) { + mods |= InputEvent.INVISIBLE_MASK; + } } + pixelPos = source.convertToPixelUnits(new int[] { event.x, event.y }); + } else { + pixelPos = new int[] { event.x, event.y }; } return new com.jogamp.newt.event.MouseEvent( - type, (null==source)?(Object)event.data:source, (0xFFFFFFFFL & (long)event.time), - mods, event.x, event.y, (short)event.count, (short)event.button, MouseEvent.getRotationXYZ(rotation, mods), 1f); + type, sourceHolder, (0xFFFFFFFFL & event.time), + mods, pixelPos[0], pixelPos[1], (short)event.count, (short)event.button, MouseEvent.getRotationXYZ(rotation, mods), 1f); } return null; // no mapping .. } - public static final com.jogamp.newt.event.KeyEvent createKeyEvent(org.eclipse.swt.widgets.Event event, Object source) { + public static final com.jogamp.newt.event.KeyEvent createKeyEvent(org.eclipse.swt.widgets.Event event, NativeSurfaceHolder sourceHolder) { switch(event.type) { case SWT.KeyDown: case SWT.KeyUp: @@ -259,7 +269,7 @@ public class SWTNewtEventFactory { if( (short)0 != type ) { final short newtKeyCode = swtKeyCode2NewtKeyCode( event.keyCode ); return com.jogamp.newt.event.KeyEvent.create( - type, (null==source)?(Object)event.data:source, (0xFFFFFFFFL & (long)event.time), + type, sourceHolder, (0xFFFFFFFFL & event.time), swtModifiers2Newt(event.stateMask, false), newtKeyCode, newtKeyCode, event.character); } @@ -280,8 +290,8 @@ public class SWTNewtEventFactory { dragButtonDown = 0; } - public final boolean dispatchMouseEvent(org.eclipse.swt.widgets.Event event, Object source, com.jogamp.newt.event.MouseListener l) { - com.jogamp.newt.event.MouseEvent res = createMouseEvent(event, source); + public final boolean dispatchMouseEvent(org.eclipse.swt.widgets.Event event, NativeSurfaceHolder sourceHolder, com.jogamp.newt.event.MouseListener l) { + com.jogamp.newt.event.MouseEvent res = createMouseEvent(event, sourceHolder); if(null != res) { if(null != l) { switch(event.type) { @@ -331,8 +341,8 @@ public class SWTNewtEventFactory { return false; } - public final boolean dispatchKeyEvent(org.eclipse.swt.widgets.Event event, Object source, com.jogamp.newt.event.KeyListener l) { - com.jogamp.newt.event.KeyEvent res = createKeyEvent(event, source); + public final boolean dispatchKeyEvent(org.eclipse.swt.widgets.Event event, NativeSurfaceHolder sourceHolder, com.jogamp.newt.event.KeyListener l) { + com.jogamp.newt.event.KeyEvent res = createKeyEvent(event, sourceHolder); if(null != res) { if(null != l) { switch(event.type) { @@ -349,27 +359,38 @@ public class SWTNewtEventFactory { return false; } - public final void attachDispatchListener(final org.eclipse.swt.widgets.Control ctrl, final Object source, + public final void attachDispatchListener(final org.eclipse.swt.widgets.Control ctrl, final NativeSurfaceHolder sourceHolder, final com.jogamp.newt.event.MouseListener ml, final com.jogamp.newt.event.KeyListener kl) { - final Listener listener = new Listener () { - @Override - public void handleEvent (Event event) { - if( dispatchMouseEvent( event, source, ml ) ) { - return; - } - if( dispatchKeyEvent( event, source, kl ) ) { - return; - } - } }; - ctrl.addListener(SWT.MouseDown, listener); - ctrl.addListener(SWT.MouseUp, listener); - ctrl.addListener(SWT.MouseMove, listener); - ctrl.addListener(SWT.MouseEnter, listener); - ctrl.addListener(SWT.MouseExit, listener); - ctrl.addListener(SWT.MouseVerticalWheel, listener); - ctrl.addListener(SWT.KeyDown, listener); - ctrl.addListener(SWT.KeyUp, listener); + if(null==ctrl) { + throw new IllegalArgumentException("Argument ctrl is null"); + } + if(null==sourceHolder) { + throw new IllegalArgumentException("Argument source is null"); + } + + if( null != ml ) { + final Listener listener = new Listener () { + @Override + public void handleEvent (Event event) { + dispatchMouseEvent( event, sourceHolder, ml ); + } }; + ctrl.addListener(SWT.MouseDown, listener); + ctrl.addListener(SWT.MouseUp, listener); + ctrl.addListener(SWT.MouseMove, listener); + ctrl.addListener(SWT.MouseEnter, listener); + ctrl.addListener(SWT.MouseExit, listener); + ctrl.addListener(SWT.MouseVerticalWheel, listener); + } + if( null != kl ) { + final Listener listener = new Listener () { + @Override + public void handleEvent (Event event) { + dispatchKeyEvent( event, sourceHolder, kl ); + } }; + ctrl.addListener(SWT.KeyDown, listener); + ctrl.addListener(SWT.KeyUp, listener); + } } } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestGLContextDrawableSwitch02AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestGLContextDrawableSwitch02AWT.java index 316199d07..c612f1204 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestGLContextDrawableSwitch02AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/glels/TestGLContextDrawableSwitch02AWT.java @@ -45,7 +45,6 @@ import javax.media.opengl.awt.GLCanvas; import com.jogamp.opengl.util.Animator; import com.jogamp.opengl.util.GLDrawableUtil; - import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; import com.jogamp.opengl.test.junit.util.QuitAdapter; import com.jogamp.opengl.test.junit.util.UITestCase; @@ -116,14 +115,14 @@ public class TestGLContextDrawableSwitch02AWT extends UITestCase { final GLCapabilities capsOffscreen = (GLCapabilities) capsOnscreen.clone(); capsOffscreen.setOnscreen(false); - final QuitAdapter quitAdapter = new QuitAdapter(); - final Frame frame = new Frame("Gears AWT Test"); Assert.assertNotNull(frame); - new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter)).addTo(frame); GLAutoDrawable glCanvas = createGLAutoDrawable(frame, capsOnscreen, width, height); + final QuitAdapter quitAdapter = new QuitAdapter(); + new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glCanvas).addTo(frame); + final SnapshotGLEventListener snapshotGLEventListener = new SnapshotGLEventListener(); GearsES2 gears = new GearsES2(1); glCanvas.addGLEventListener(gears); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos01AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos01AWT.java index 443908ff8..28e00dfe2 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos01AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos01AWT.java @@ -236,9 +236,8 @@ public class TestBug816OSXCALayerPos01AWT extends UITestCase { if( twoCanvas ) { animator.add(glCanvas2); } - QuitAdapter quitAdapter = new QuitAdapter(); - - new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter)).addTo(frame); + final QuitAdapter quitAdapter = new QuitAdapter(); + new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glCanvas1).addTo(frame); javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos02AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos02AWT.java index df24fc6e0..5f1b43a61 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos02AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos02AWT.java @@ -80,9 +80,9 @@ public class TestBug816OSXCALayerPos02AWT extends UITestCase { final Animator animator = new Animator(); animator.add(glCanvas1); - QuitAdapter quitAdapter = new QuitAdapter(); - new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter)).addTo(frame); + final QuitAdapter quitAdapter = new QuitAdapter(); + new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glCanvas1).addTo(frame); // Build a GUI where the canvas 3D is located at top right of the frame // and can be resized with split panes dividers diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03aB729AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03aB729AWT.java index 29dc9a190..f37cdf332 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03aB729AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03aB729AWT.java @@ -87,9 +87,9 @@ public class TestBug816OSXCALayerPos03aB729AWT extends UITestCase { final Animator animator = new Animator(); animator.add(glCanvas1); - QuitAdapter quitAdapter = new QuitAdapter(); - new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter)).addTo(frame); + final QuitAdapter quitAdapter = new QuitAdapter(); + new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glCanvas1).addTo(frame); // Create a check box that hides / shows canvas final Checkbox checkbox = new Checkbox("Visible canvas", true); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03bB849AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03bB849AWT.java index 3e60c8b47..acdd40764 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03bB849AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03bB849AWT.java @@ -93,9 +93,9 @@ public class TestBug816OSXCALayerPos03bB849AWT extends UITestCase { final Animator animator = new Animator(); animator.add(glCanvas1); - QuitAdapter quitAdapter = new QuitAdapter(); - new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter)).addTo(frame); + final QuitAdapter quitAdapter = new QuitAdapter(); + new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glCanvas1).addTo(frame); // Create a check box that hides / shows canvas final Checkbox checkbox = new Checkbox("Visible canvas", true); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03cB849AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03cB849AWT.java index 24f9de961..52480b89b 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03cB849AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos03cB849AWT.java @@ -95,9 +95,9 @@ public class TestBug816OSXCALayerPos03cB849AWT extends UITestCase { final Animator animator = new Animator(); animator.add(glCanvas1); - QuitAdapter quitAdapter = new QuitAdapter(); - new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter)).addTo(frame); + final QuitAdapter quitAdapter = new QuitAdapter(); + new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glCanvas1).addTo(frame); // Create a check box that hides / shows canvas final JCheckBox checkbox = new JCheckBox("Visible canvas", true); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos04aAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos04aAWT.java index b558b1680..246c5cdb5 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos04aAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug816OSXCALayerPos04aAWT.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.awt; import java.awt.BorderLayout; @@ -59,55 +59,55 @@ import com.jogamp.opengl.util.Animator; */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestBug816OSXCALayerPos04aAWT extends UITestCase { - static long duration = 1600; // ms + static long duration = 1600; // ms static int width=640, height=480; - + @Test public void test() throws InterruptedException, InvocationTargetException { final GLCapabilities caps = new GLCapabilities(getGLP()); - + final Frame frame = new Frame("TestBug816OSXCALayerPos04aAWT"); Assert.assertNotNull(frame); final GLCanvas glCanvas1 = new GLCanvas(caps); Assert.assertNotNull(glCanvas1); glCanvas1.addGLEventListener(new GearsES2(1)); - + final Animator animator = new Animator(); animator.add(glCanvas1); - QuitAdapter quitAdapter = new QuitAdapter(); - - new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter)).addTo(frame); + + final QuitAdapter quitAdapter = new QuitAdapter(); + new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glCanvas1).addTo(frame); // Display the canvas 3D in a dialog child of a frame frame.setSize(400, 400); - + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { frame.setLocation(100, 100); frame.setSize(width, height); frame.setVisible(true); - }}); + }}); Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true)); - + final Dialog dialog = new Dialog(frame, "Bug 816 AWT Top-Level Dialog"); dialog.setLayout(new BorderLayout()); dialog.add(glCanvas1, BorderLayout.CENTER); - + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { dialog.setLocation(200, 200); dialog.setSize(width/2, height/2); dialog.setVisible(true); - }}); + }}); Assert.assertEquals(true, AWTRobotUtil.waitForVisible(dialog, true)); - Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas1, true)); - + Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glCanvas1, true)); + animator.start(); Assert.assertTrue(animator.isStarted()); Assert.assertTrue(animator.isAnimating()); animator.setUpdateFPSFrames(60, System.err); - + final long t0 = System.currentTimeMillis(); long t1 = t0; while(!quitAdapter.shouldQuit() && t1 - t0 < duration) { @@ -117,7 +117,7 @@ public class TestBug816OSXCALayerPos04aAWT extends UITestCase { Assert.assertNotNull(frame); Assert.assertNotNull(glCanvas1); - + Assert.assertNotNull(animator); animator.stop(); Assert.assertFalse(animator.isAnimating()); @@ -138,7 +138,7 @@ public class TestBug816OSXCALayerPos04aAWT extends UITestCase { static GLProfile getGLP() { return GLProfile.getMaxProgrammableCore(true); } - + public static void main(String args[]) { for(int i=0; i * {@link RandomTileRenderer} is being kicked off from the main thread. *

*

* {@link RandomTileRenderer} setup and finishing is performed - * within the pre- and post {@link GLEventListener} + * within the pre- and post {@link GLEventListener} * set via {@link TileRendererBase#setGLEventListener(GLEventListener, GLEventListener)} - * on the animation thread. + * on the animation thread. *

*

* At tile rendering finish, the viewport and * and the original {@link GLEventListener}'s PMV matrix as well. - * The latter is done by calling it's {@link GLEventListener#reshape(GLAutoDrawable, int, int, int, int) reshape} method. + * The latter is done by calling it's {@link GLEventListener#reshape(GLAutoDrawable, int, int, int, int) reshape} method. *

*/ @FixMethodOrder(MethodSorters.NAME_ASCENDING) @@ -82,7 +82,7 @@ public class TestRandomTiledRendering3GL2AWT extends UITestCase { static long duration = 3500; // ms static int width = 512; static int height = 512; - + @Test public void test01_aa0() throws IOException, InterruptedException, InvocationTargetException { doTest(0); @@ -92,7 +92,7 @@ public class TestRandomTiledRendering3GL2AWT extends UITestCase { doTest(8); } - void doTest(int msaaCount) throws IOException, InterruptedException, InvocationTargetException { + void doTest(int msaaCount) throws IOException, InterruptedException, InvocationTargetException { final GLCapabilities caps = new GLCapabilities(null); if( msaaCount > 0 ) { caps.setSampleBuffers(true); @@ -113,11 +113,9 @@ public class TestRandomTiledRendering3GL2AWT extends UITestCase { final Gears gears = new Gears(); glad.addGLEventListener( gears ); - final Animator animator = new Animator(glad); final QuitAdapter quitAdapter = new QuitAdapter(); - - new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter)).addTo(glad); - new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter)).addTo(frame); + new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter), glad).addTo(glad); + new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glad).addTo(frame); // Fix the image size for now final int maxTileSize = 64; @@ -134,7 +132,7 @@ public class TestRandomTiledRendering3GL2AWT extends UITestCase { final GLEventListener preTileGLEL = new GLEventListener() { final int w = maxTileSize, h = maxTileSize; int dx = 0, dy = 0; - + @Override public void init(GLAutoDrawable drawable) { final GL gl = drawable.getGL(); @@ -183,15 +181,15 @@ public class TestRandomTiledRendering3GL2AWT extends UITestCase { caps.getGLProfile(), 0 /* internalFormat */, imageWidth, imageHeight, - 0, + 0, imageBuffer.pixelAttributes, - false, false, + false, false, flipVertically[0], imageBuffer.buffer, null /* Flusher */); try { final String filename = getSnapshotFilename(0, "-tile", glad.getChosenGLCapabilities(), imageWidth, imageHeight, false, TextureIO.PNG, null); - final File file = new File(filename); + final File file = new File(filename); TextureIO.write(textureData, file); } catch (IOException e) { e.printStackTrace(); @@ -206,19 +204,21 @@ public class TestRandomTiledRendering3GL2AWT extends UITestCase { public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {} }; renderer.setGLEventListener(preTileGLEL, postTileGLEL); - + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { frame.pack(); frame.setVisible(true); }}); - animator.setUpdateFPSFrames(60, System.err); + + final Animator animator = new Animator(glad); + animator.setUpdateFPSFrames(60, System.err); animator.start(); boolean signalTileRenderer = true; - - while(!quitAdapter.shouldQuit() && animator.isAnimating() && - ( rendererActive[0] || animator.getTotalFPSDuration() 90 ) { signalTileRenderer = false; @@ -244,9 +244,9 @@ public class TestRandomTiledRendering3GL2AWT extends UITestCase { public void run() { frame.remove(glad); frame.dispose(); - }}); + }}); } - + public static void main(String args[]) { for(int i=0; i