diff options
Diffstat (limited to 'src/newt')
-rw-r--r-- | src/newt/classes/com/jogamp/newt/opengl/GLWindow.java | 8 | ||||
-rw-r--r-- | src/newt/classes/com/jogamp/newt/util/MainThread.java | 86 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/DefaultEDTUtil.java | 14 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/WindowImpl.java | 78 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/awt/AWTCanvas.java | 63 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/awt/AWTDisplay.java | 20 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/awt/AWTEDTUtil.java | 108 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/awt/AWTScreen.java | 16 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/awt/AWTWindow.java | 188 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/windows/WindowsWindow.java | 14 |
10 files changed, 344 insertions, 251 deletions
diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java index f3fab7bce..fee188768 100644 --- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java +++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java @@ -76,14 +76,14 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { ((WindowImpl)this.window).setHandleDestroyNotify(false); window.addWindowListener(new WindowAdapter() { public void windowRepaint(WindowUpdateEvent e) { - if( !GLWindow.this.window.isSurfaceLockedByOtherThread() && !GLWindow.this.helper.isExternalAnimatorAnimating() ) { + if( !GLWindow.this.window.isWindowLockedByOtherThread() && !GLWindow.this.helper.isExternalAnimatorAnimating() ) { display(); } } public void windowResized(WindowEvent e) { sendReshape = true; - if( !GLWindow.this.window.isSurfaceLockedByOtherThread() && !GLWindow.this.helper.isExternalAnimatorAnimating() ) { + if( !GLWindow.this.window.isWindowLockedByOtherThread() && !GLWindow.this.helper.isExternalAnimatorAnimating() ) { display(); } } @@ -99,8 +99,8 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { if(isPaused) { ctrl.resume(); } - } else if (GLWindow.this.window.isSurfaceLockedByOtherThread()) { - // Surface is locked by another thread + } else if (GLWindow.this.window.isWindowLockedByOtherThread()) { + // Window is locked by another thread // Flag that destroy should be performed on the next // attempt to display. sendDestroy = true; diff --git a/src/newt/classes/com/jogamp/newt/util/MainThread.java b/src/newt/classes/com/jogamp/newt/util/MainThread.java index 607645052..9f66fefe6 100644 --- a/src/newt/classes/com/jogamp/newt/util/MainThread.java +++ b/src/newt/classes/com/jogamp/newt/util/MainThread.java @@ -37,16 +37,25 @@ package com.jogamp.newt.util; -import java.util.*; import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; -import java.security.*; - -import javax.media.nativewindow.*; - -import com.jogamp.common.util.*; -import com.jogamp.newt.*; -import jogamp.newt.*; +import java.security.AccessControlContext; +import java.security.AccessController; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Timer; +import java.util.TimerTask; + +import javax.media.nativewindow.NativeWindowFactory; + +import com.jogamp.common.util.ReflectionUtil; +import com.jogamp.common.util.RunnableTask; +import com.jogamp.newt.Display; +import jogamp.newt.Debug; +import jogamp.newt.NEWTJNILibLoader; +import jogamp.newt.awt.AWTEDTUtil; /** * NEWT Utility class MainThread<P> @@ -103,16 +112,11 @@ public class MainThread implements EDTUtil { private static Map/*<Display, Runnable>*/ pumpMessageDisplayMap = new HashMap(); private static boolean useMainThread = false; - private static Class cAWTEventQueue=null; - private static Method mAWTInvokeAndWait=null; - private static Method mAWTInvokeLater=null; - private static Method mAWTIsDispatchThread=null; static class MainAction extends Thread { private String mainClassName; private String[] mainClassArgs; - private Class mainClass; private Method mainClassMain; public MainAction(String mainClassName, String[] mainClassArgs) { @@ -237,33 +241,28 @@ public class MainThread implements EDTUtil { } } - private void initAWTReflection() { - if(null == cAWTEventQueue) { - ClassLoader cl = MainThread.class.getClassLoader(); - cAWTEventQueue = ReflectionUtil.getClass("java.awt.EventQueue", true, cl); - mAWTInvokeAndWait = ReflectionUtil.getMethod(cAWTEventQueue, "invokeAndWait", new Class[] { java.lang.Runnable.class }, cl); - mAWTInvokeLater = ReflectionUtil.getMethod(cAWTEventQueue, "invokeLater", new Class[] { java.lang.Runnable.class }, cl); - mAWTIsDispatchThread = ReflectionUtil.getMethod(cAWTEventQueue, "isDispatchThread", new Class[] { }, cl); + final public void reset() { + if(NativeWindowFactory.isAWTAvailable()) { + AWTEDTUtil.getSingleton().reset(); } - } - - public void reset() { // nop } - public void start() { + final public void start() { + if(NativeWindowFactory.isAWTAvailable()) { + AWTEDTUtil.getSingleton().start(); + } // nop } - public boolean isCurrentThreadEDT() { + final public boolean isCurrentThreadEDT() { if(NativeWindowFactory.isAWTAvailable()) { - initAWTReflection(); - return ((Boolean) ReflectionUtil.callMethod(null, mAWTIsDispatchThread, null) ).booleanValue(); + return AWTEDTUtil.getSingleton().isCurrentThreadEDT(); } return isRunning() && mainThread == Thread.currentThread() ; } - public boolean isRunning() { + final public boolean isRunning() { if( useMainThread ) { synchronized(taskWorkerLock) { return isRunning; @@ -284,11 +283,11 @@ public class MainThread implements EDTUtil { } } - public void invokeStop(Runnable r) { + final public void invokeStop(Runnable r) { invokeImpl(true, r, true); } - public void invoke(boolean wait, Runnable r) { + final public void invoke(boolean wait, Runnable r) { invokeImpl(wait, r, false); } @@ -298,22 +297,7 @@ public class MainThread implements EDTUtil { } if(NativeWindowFactory.isAWTAvailable()) { - initAWTReflection(); - - // handover to AWT MainThread .. - try { - if ( ((Boolean) ReflectionUtil.callMethod(null, mAWTIsDispatchThread, null) ).booleanValue() ) { - r.run(); - return; - } - if(wait) { - ReflectionUtil.callMethod(null, mAWTInvokeAndWait, new Object[] { r }); - } else { - ReflectionUtil.callMethod(null, mAWTInvokeLater, new Object[] { r }); - } - } catch (Exception e) { - throw new NativeWindowException(e); - } + AWTEDTUtil.getSingleton().invokeImpl(wait, r, stop); return; } @@ -355,10 +339,16 @@ public class MainThread implements EDTUtil { } } - public void waitUntilIdle() { + final public void waitUntilIdle() { + if(NativeWindowFactory.isAWTAvailable()) { + AWTEDTUtil.getSingleton().waitUntilIdle(); + } } - public void waitUntilStopped() { + final public void waitUntilStopped() { + if(NativeWindowFactory.isAWTAvailable()) { + AWTEDTUtil.getSingleton().waitUntilStopped(); + } } private void waitUntilRunning() { diff --git a/src/newt/classes/jogamp/newt/DefaultEDTUtil.java b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java index 925828175..016906581 100644 --- a/src/newt/classes/jogamp/newt/DefaultEDTUtil.java +++ b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java @@ -37,10 +37,10 @@ package jogamp.newt; +import java.util.ArrayList; +import javax.media.nativewindow.NativeWindowException; import com.jogamp.common.util.RunnableTask; import com.jogamp.newt.util.EDTUtil; -import java.util.*; -import javax.media.nativewindow.NativeWindowException; public class DefaultEDTUtil implements EDTUtil { public static final boolean DEBUG = Debug.debug("EDT"); @@ -191,7 +191,7 @@ public class DefaultEDTUtil implements EDTUtil { } } - public void waitUntilIdle() { + final public void waitUntilIdle() { if(edt.isRunning() && edt != Thread.currentThread()) { synchronized(edt.tasks) { while(edt.isRunning() && edt.tasks.size()>0) { @@ -206,7 +206,7 @@ public class DefaultEDTUtil implements EDTUtil { } } - public void waitUntilStopped() { + final public void waitUntilStopped() { if(edt.isRunning() && edt != Thread.currentThread() ) { synchronized(edtLock) { if(edt.isRunning() && edt != Thread.currentThread() ) { @@ -231,11 +231,11 @@ public class DefaultEDTUtil implements EDTUtil { super(tg, name); } - public final boolean isRunning() { + final public boolean isRunning() { return isRunning; } - public void start() throws IllegalThreadStateException { + final public void start() throws IllegalThreadStateException { isRunning = true; super.start(); } @@ -244,7 +244,7 @@ public class DefaultEDTUtil implements EDTUtil { * Utilizing locking only on tasks and its execution, * not for event dispatching. */ - public void run() { + final public void run() { if(DEBUG) { System.err.println(getName()+": EDT run() START "+ getName()); } diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index 79679b7b3..815fd705e 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -73,7 +73,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer { public static final boolean DEBUG_TEST_REPARENT_INCOMPATIBLE = Debug.isPropertyDefined("newt.test.Window.reparent.incompatible", true); - private RecursiveLock windowLock = new RecursiveLock(); + private RecursiveLock windowLock = new RecursiveLock(); // Window instance wide lock + private RecursiveLock surfaceLock = new RecursiveLock(); // Surface only lock private long windowHandle; private ScreenImpl screen; private boolean screenReferenceAdded = false; @@ -463,52 +464,73 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer // public final int lockSurface() { - int res = LOCK_SURFACE_NOT_READY; windowLock.lock(); + surfaceLock.lock(); + int res = surfaceLock.getRecursionCount() == 0 ? LOCK_SURFACE_NOT_READY : LOCK_SUCCESS; - if(isNativeValid()) { - AbstractGraphicsDevice adevice = screen.getDisplay().getGraphicsDevice(); - adevice.lock(); + if ( LOCK_SURFACE_NOT_READY == res ) { try { - res = lockSurfaceImpl(); + if( isNativeValid() ) { + final AbstractGraphicsDevice adevice = config.getScreen().getDevice(); + adevice.lock(); + try { + res = lockSurfaceImpl(); + } finally { + if (LOCK_SURFACE_NOT_READY >= res) { + adevice.unlock(); + } + } + } } finally { - if( LOCK_SURFACE_NOT_READY == res ) { - adevice.unlock(); + if (LOCK_SURFACE_NOT_READY >= res) { + surfaceLock.unlock(); + windowLock.unlock(); } } } - if( LOCK_SURFACE_NOT_READY == res ) { - windowLock.unlock(); - } - return res; } public final void unlockSurface() { - // may throw RuntimeException if not locked + surfaceLock.validateLocked(); windowLock.validateLocked(); - AbstractGraphicsDevice adevice = screen.getDisplay().getGraphicsDevice(); - try { - unlockSurfaceImpl(); - } finally { - adevice.unlock(); + if (surfaceLock.getRecursionCount() == 0) { + final AbstractGraphicsDevice adevice = config.getScreen().getDevice(); + try { + unlockSurfaceImpl(); + } finally { + adevice.unlock(); + } } + surfaceLock.unlock(); windowLock.unlock(); } - public final boolean isSurfaceLockedByOtherThread() { + public final boolean isWindowLockedByOtherThread() { return windowLock.isLockedByOtherThread(); } - public final boolean isSurfaceLocked() { + public final boolean isWindowLocked() { return windowLock.isLocked(); } - public final Thread getSurfaceLockOwner() { + public final Thread getWindowLockOwner() { return windowLock.getOwner(); } + public final boolean isSurfaceLockedByOtherThread() { + return surfaceLock.isLockedByOtherThread(); + } + + public final boolean isSurfaceLocked() { + return surfaceLock.isLocked(); + } + + public final Thread getSurfaceLockOwner() { + return surfaceLock.getOwner(); + } + public long getSurfaceHandle() { return windowHandle; // default: return window handle } @@ -1367,7 +1389,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer "\n, ParentWindow "+parentWindow+ "\n, ParentWindowHandle "+toHexString(parentWindowHandle)+ "\n, WindowHandle "+toHexString(getWindowHandle())+ - "\n, SurfaceHandle "+toHexString(getSurfaceHandle())+ " (lockedExt "+isSurfaceLockedByOtherThread()+")"+ + "\n, SurfaceHandle "+toHexString(getSurfaceHandle())+ " (lockedExt window "+isWindowLockedByOtherThread()+", surface "+isSurfaceLockedByOtherThread()+")"+ "\n, Pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+ "\n, Visible "+isVisible()+ "\n, Undecorated "+undecorated+ @@ -1645,8 +1667,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer switch(e.getEventType()) { // special repaint treatment case WindowEvent.EVENT_WINDOW_REPAINT: - // queue repaint event in case surface is locked, ie in operation - if( isSurfaceLocked() ) { + // queue repaint event in case window is locked, ie in operation + if( isWindowLocked() ) { // make sure only one repaint event is queued if(!repaintQueued) { repaintQueued=true; @@ -1664,8 +1686,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer // common treatment case WindowEvent.EVENT_WINDOW_RESIZED: - // queue event in case surface is locked, ie in operation - if( isSurfaceLocked() ) { + // queue event in case window is locked, ie in operation + if( isWindowLocked() ) { if(DEBUG_IMPLEMENTATION) { System.err.println("Window.consumeEvent: queued "+e); // Exception ee = new Exception("Window.windowRepaint: "+e); @@ -2160,10 +2182,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } } - protected int getWindowLockRecursionCount() { - return windowLock.getRecursionCount(); - } - // // Reflection helper .. // diff --git a/src/newt/classes/jogamp/newt/awt/AWTCanvas.java b/src/newt/classes/jogamp/newt/awt/AWTCanvas.java index 5606ceb01..01e813449 100644 --- a/src/newt/classes/jogamp/newt/awt/AWTCanvas.java +++ b/src/newt/classes/jogamp/newt/awt/AWTCanvas.java @@ -33,18 +33,24 @@ package jogamp.newt.awt; -import com.jogamp.newt.Window; - import java.awt.Canvas; import java.awt.GraphicsDevice; import java.awt.GraphicsConfiguration; - -import javax.media.nativewindow.*; -import javax.media.nativewindow.awt.*; import java.lang.reflect.Method; import java.security.AccessController; import java.security.PrivilegedAction; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.AbstractGraphicsScreen; +import javax.media.nativewindow.CapabilitiesChooser; +import javax.media.nativewindow.CapabilitiesImmutable; +import javax.media.nativewindow.GraphicsConfigurationFactory; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.awt.AWTGraphicsConfiguration; +import javax.media.nativewindow.awt.AWTGraphicsDevice; +import javax.media.nativewindow.awt.AWTGraphicsScreen; +import com.jogamp.newt.Window; + public class AWTCanvas extends Canvas { private GraphicsDevice device; private GraphicsConfiguration chosen; @@ -76,29 +82,37 @@ public class AWTCanvas extends Canvas { } public void addNotify() { - super.addNotify(); - - disableBackgroundErase(); - GraphicsConfiguration gc = super.getGraphicsConfiguration(); - if(null!=gc) { - device = gc.getDevice(); - } - - /* - * Save the chosen capabilities for use in getGraphicsConfiguration(). + /** + * 'super.addNotify()' determines the GraphicsConfiguration, + * while calling this class's overriden 'getGraphicsConfiguration()' method + * after which it creates the native peer. + * Hence we have to set the 'awtConfig' before since it's GraphicsConfiguration + * is being used in getGraphicsConfiguration(). + * This code order also allows recreation, ie re-adding the GLCanvas. */ awtConfig = chooseGraphicsConfiguration(capabilities, capabilities, chooser, device); if(Window.DEBUG_IMPLEMENTATION) { Exception e = new Exception("Info: Created Config: "+awtConfig); e.printStackTrace(); } - if(null!=awtConfig) { - // update .. - chosen = awtConfig.getGraphicsConfiguration(); - } if(null==awtConfig) { - throw new NativeWindowException("Error: AWTGraphicsConfiguration is null"); + throw new NativeWindowException("Error: NULL AWTGraphicsConfiguration"); + } + chosen = awtConfig.getGraphicsConfiguration(); + + // before native peer is valid: X11 + disableBackgroundErase(); + + // issues getGraphicsConfiguration() and creates the native peer + super.addNotify(); + + // after native peer is valid: Windows + disableBackgroundErase(); + + GraphicsConfiguration gc = super.getGraphicsConfiguration(); + if(null!=gc) { + device = gc.getDevice(); } } @@ -276,13 +290,22 @@ public class AWTCanvas extends Canvas { } catch (Exception e) { } disableBackgroundEraseInitialized = true; + if(Window.DEBUG_IMPLEMENTATION) { + System.err.println("AWTCanvas: TK disableBackgroundErase method found: "+ + (null!=disableBackgroundEraseMethod)); + } } if (disableBackgroundEraseMethod != null) { + Throwable t=null; try { disableBackgroundEraseMethod.invoke(getToolkit(), new Object[] { this }); } catch (Exception e) { // FIXME: workaround for 6504460 (incorrect backport of 6333613 in 5.0u10) // throw new GLException(e); + t = e; + } + if(Window.DEBUG_IMPLEMENTATION) { + System.err.println("AWTCanvas: TK disableBackgroundErase error: "+t); } } } diff --git a/src/newt/classes/jogamp/newt/awt/AWTDisplay.java b/src/newt/classes/jogamp/newt/awt/AWTDisplay.java index f8a756f60..4c864c111 100644 --- a/src/newt/classes/jogamp/newt/awt/AWTDisplay.java +++ b/src/newt/classes/jogamp/newt/awt/AWTDisplay.java @@ -33,13 +33,10 @@ package jogamp.newt.awt; -import java.awt.event.*; -import com.jogamp.newt.Display; -import com.jogamp.newt.Window; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.awt.AWTGraphicsDevice; +import com.jogamp.newt.NewtFactory; import jogamp.newt.DisplayImpl; -import javax.media.nativewindow.*; -import javax.media.nativewindow.awt.*; -import java.util.*; public class AWTDisplay extends DisplayImpl { public AWTDisplay() { @@ -55,9 +52,16 @@ public class AWTDisplay extends DisplayImpl { protected void closeNativeImpl() { } - protected boolean shallRunOnEDT() { - return false; + @Override + protected void createEDTUtil() { + if(NewtFactory.useEDT()) { + edtUtil = AWTEDTUtil.getSingleton(); + if(DEBUG) { + System.err.println("AWTDisplay.createNative("+getFQName()+") Create EDTUtil: "+edtUtil.getClass().getName()); + } + } } + protected void dispatchMessagesNative() { /* nop */ } } diff --git a/src/newt/classes/jogamp/newt/awt/AWTEDTUtil.java b/src/newt/classes/jogamp/newt/awt/AWTEDTUtil.java new file mode 100644 index 000000000..914a73f4d --- /dev/null +++ b/src/newt/classes/jogamp/newt/awt/AWTEDTUtil.java @@ -0,0 +1,108 @@ +/** + * Copyright 2010 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 jogamp.newt.awt; + +import java.awt.EventQueue; +import javax.media.nativewindow.NativeWindowException; +import com.jogamp.newt.util.EDTUtil; +import jogamp.newt.Debug; + +public class AWTEDTUtil implements EDTUtil { + public static final boolean DEBUG = Debug.debug("EDT"); + + private static AWTEDTUtil singletonMainThread = new AWTEDTUtil(); // one singleton MainThread + + public static final AWTEDTUtil getSingleton() { + return singletonMainThread; + } + + AWTEDTUtil() { + // package private access .. + } + + final public void reset() { + // nop + } + + final public void start() { + // nop + } + + final public boolean isCurrentThreadEDT() { + return EventQueue.isDispatchThread(); + } + + final public boolean isRunning() { + return true; // AWT is always running + } + + final public void invokeStop(Runnable r) { + invokeImpl(true, r, true); + } + + final public void invoke(boolean wait, Runnable r) { + invokeImpl(wait, r, false); + } + + /** + * Public access to provide simple dispatching from other EDTUtil implementations + * @param wait true if invokeLater + * @param r the Runnable action + * @param stop true if EDT shall stop (ignored with AWT) + */ + final public void invokeImpl(boolean wait, Runnable r, boolean stop) { + if(r == null) { + return; + } + + // handover to AWT MainThread .. + try { + if ( isCurrentThreadEDT() ) { + r.run(); + return; + } + if(wait) { + EventQueue.invokeAndWait(r); + } else { + EventQueue.invokeLater(r); + } + } catch (Exception e) { + throw new NativeWindowException(e); + } + } + + final public void waitUntilIdle() { + } + + final public void waitUntilStopped() { + } + +} + + diff --git a/src/newt/classes/jogamp/newt/awt/AWTScreen.java b/src/newt/classes/jogamp/newt/awt/AWTScreen.java index 83d7be57c..d05933321 100644 --- a/src/newt/classes/jogamp/newt/awt/AWTScreen.java +++ b/src/newt/classes/jogamp/newt/awt/AWTScreen.java @@ -33,11 +33,11 @@ package jogamp.newt.awt; -import com.jogamp.newt.*; -import jogamp.newt.ScreenImpl; import java.awt.DisplayMode; -import javax.media.nativewindow.*; -import javax.media.nativewindow.awt.*; + +import jogamp.newt.ScreenImpl; +import javax.media.nativewindow.awt.AWTGraphicsDevice; +import javax.media.nativewindow.awt.AWTGraphicsScreen; public class AWTScreen extends ScreenImpl { public AWTScreen() { @@ -46,10 +46,10 @@ public class AWTScreen extends ScreenImpl { protected void createNativeImpl() { aScreen = new AWTGraphicsScreen((AWTGraphicsDevice)display.getGraphicsDevice()); - DisplayMode mode = ((AWTGraphicsDevice)getDisplay().getGraphicsDevice()).getGraphicsDevice().getDisplayMode(); - int w = mode.getWidth(); - int h = mode.getHeight(); - setScreenSize(w, h); + final DisplayMode mode = ((AWTGraphicsDevice)getDisplay().getGraphicsDevice()).getGraphicsDevice().getDisplayMode(); + if(null != mode) { + setScreenSize(mode.getWidth(), mode.getHeight()); + } } protected void setAWTGraphicsScreen(AWTGraphicsScreen s) { diff --git a/src/newt/classes/jogamp/newt/awt/AWTWindow.java b/src/newt/classes/jogamp/newt/awt/AWTWindow.java index 908b6f2cb..0a6a557f7 100644 --- a/src/newt/classes/jogamp/newt/awt/AWTWindow.java +++ b/src/newt/classes/jogamp/newt/awt/AWTWindow.java @@ -34,19 +34,19 @@ package jogamp.newt.awt; -import com.jogamp.newt.event.awt.*; -import com.jogamp.newt.util.EDTUtil; - import java.awt.BorderLayout; import java.awt.Container; import java.awt.DisplayMode; -import java.awt.EventQueue; import java.awt.Frame; -import jogamp.newt.WindowImpl; import java.awt.Insets; -import javax.media.nativewindow.*; -import javax.media.nativewindow.awt.*; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.awt.AWTGraphicsDevice; +import javax.media.nativewindow.awt.AWTGraphicsScreen; import javax.media.nativewindow.util.Point; +import jogamp.newt.WindowImpl; +import com.jogamp.newt.event.awt.AWTKeyAdapter; +import com.jogamp.newt.event.awt.AWTMouseAdapter; +import com.jogamp.newt.event.awt.AWTWindowAdapter; /** An implementation of the Newt Window class built using the AWT. This is provided for convenience of porting to platforms @@ -77,89 +77,67 @@ public class AWTWindow extends WindowImpl { private AWTCanvas canvas; protected void requestFocusImpl(boolean reparented) { - runOnEDT(true, new Runnable() { - public void run() { - container.requestFocus(); - } - }); + container.requestFocus(); } protected void setTitleImpl(final String title) { - runOnEDT(true, new Runnable() { - public void run() { - if (frame != null) { - frame.setTitle(title); - } - } - }); + if (frame != null) { + frame.setTitle(title); + } } protected void createNativeImpl() { - if(0!=getParentWindowHandle()) { throw new RuntimeException("Window parenting not supported in AWT, use AWTWindow(Frame) cstr for wrapping instead"); } - final AWTWindow awtWindow = this; + if(null==container) { + frame = new Frame(); + container = frame; + owningFrame=true; + } else { + owningFrame=false; + width = container.getWidth(); + height = container.getHeight(); + x = container.getX(); + y = container.getY(); + } + if(null!=frame) { + frame.setTitle(getTitle()); + } + container.setLayout(new BorderLayout()); + canvas = new AWTCanvas(capsRequested, AWTWindow.this.capabilitiesChooser); - runOnEDT(true, new Runnable() { - public void run() { - if(null==container) { - frame = new Frame(); - container = frame; - owningFrame=true; - } else { - owningFrame=false; - width = container.getWidth(); - height = container.getHeight(); - x = container.getX(); - y = container.getY(); - } - if(null!=frame) { - frame.setTitle(getTitle()); - } - container.setLayout(new BorderLayout()); - canvas = new AWTCanvas(capsRequested, AWTWindow.this.capabilitiesChooser); + addWindowListener(new LocalWindowListener()); - addWindowListener(new LocalWindowListener()); + new AWTMouseAdapter(this).addTo(canvas); // fwd all AWT Mouse events to here + new AWTKeyAdapter(this).addTo(canvas); // fwd all AWT Key events to here - new AWTMouseAdapter(awtWindow).addTo(canvas); // fwd all AWT Mouse events to here - new AWTKeyAdapter(awtWindow).addTo(canvas); // fwd all AWT Key events to here + // canvas.addComponentListener(listener); + container.add(canvas, BorderLayout.CENTER); + container.setSize(width, height); + container.setLocation(x, y); + new AWTWindowAdapter(this).addTo(container); // fwd all AWT Window events to here - // canvas.addComponentListener(listener); - container.add(canvas, BorderLayout.CENTER); - container.setSize(width, height); - container.setLocation(x, y); - new AWTWindowAdapter(awtWindow).addTo(container); // fwd all AWT Window events to here + if(null!=frame) { + frame.setUndecorated(undecorated||fullscreen); + } - if(null!=frame) { - frame.setUndecorated(undecorated||fullscreen); - } - } - }); setWindowHandle(1); // just a marker .. } protected void closeNativeImpl() { setWindowHandle(0); // just a marker .. if(null!=container) { - runOnEDT(true, new Runnable() { - public void run() { - container.setVisible(false); - container.remove(canvas); - container.setEnabled(false); - canvas.setEnabled(false); - } - }); + container.setVisible(false); + container.remove(canvas); + container.setEnabled(false); + canvas.setEnabled(false); } if(owningFrame && null!=frame) { - runOnEDT(true, new Runnable() { - public void run() { - frame.dispose(); - owningFrame=false; - frame = null; - } - }); + frame.dispose(); + owningFrame=false; + frame = null; } } @@ -176,11 +154,7 @@ public class AWTWindow extends WindowImpl { } protected void setVisibleImpl(final boolean visible, int x, int y, int width, int height) { - runOnEDT(true, new Runnable() { - public void run() { - container.setVisible(visible); - } - }); + container.setVisible(visible); reconfigureWindowImpl(x, y, width, height, false, 0, 0); config = canvas.getAWTGraphicsConfiguration(); @@ -206,42 +180,33 @@ public class AWTWindow extends WindowImpl { public javax.media.nativewindow.util.Insets getInsets() { final int insets[] = new int[] { 0, 0, 0, 0 }; - runOnEDT(true, new Runnable() { - public void run() { - Insets contInsets = container.getInsets(); - insets[0] = contInsets.top; - insets[1] = contInsets.left; - insets[2] = contInsets.bottom; - insets[3] = contInsets.right; - } - }); + Insets contInsets = container.getInsets(); + insets[0] = contInsets.top; + insets[1] = contInsets.left; + insets[2] = contInsets.bottom; + insets[3] = contInsets.right; return new javax.media.nativewindow.util.Insets(insets[0],insets[1],insets[2],insets[3]); } protected boolean reconfigureWindowImpl(final int x, final int y, final int width, final int height, final boolean parentChange, final int fullScreenChange, final int decorationChange) { - /** An AWT event on setSize() would bring us in a deadlock situation, hence invokeLater() */ - runOnEDT(false, new Runnable() { - public void run() { - if(decorationChange!=0 && null!=frame) { - if(!container.isDisplayable()) { - frame.setUndecorated(isUndecorated()); - } else { - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - System.err.println("AWTWindow can't undecorate already created frame"); - } - } - } - int _x=(x>=0)?x:AWTWindow.this.x; - int _y=(x>=0)?y:AWTWindow.this.y; - int _w=(width>0)?width:AWTWindow.this.width; - int _h=(height>0)?height:AWTWindow.this.height; - - container.setLocation(_x, _y); - Insets insets = container.getInsets(); - container.setSize(_w + insets.left + insets.right, - _h + insets.top + insets.bottom); + if(decorationChange!=0 && null!=frame) { + if(!container.isDisplayable()) { + frame.setUndecorated(isUndecorated()); + } else { + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("AWTWindow can't undecorate already created frame"); } - }); + } + } + int _x=(x>=0)?x:AWTWindow.this.x; + int _y=(x>=0)?y:AWTWindow.this.y; + int _w=(width>0)?width:AWTWindow.this.width; + int _h=(height>0)?height:AWTWindow.this.height; + + container.setLocation(_x, _y); + Insets insets = container.getInsets(); + container.setSize(_w + insets.left + insets.right, + _h + insets.top + insets.bottom); return true; } @@ -255,23 +220,6 @@ public class AWTWindow extends WindowImpl { return canvas; } - private void runOnEDT(boolean wait, Runnable r) { - EDTUtil edtUtil = getScreen().getDisplay().getEDTUtil(); - if ( ( null != edtUtil && edtUtil.isCurrentThreadEDT() ) || EventQueue.isDispatchThread() ) { - r.run(); - } else { - try { - if(wait) { - EventQueue.invokeAndWait(r); - } else { - EventQueue.invokeLater(r); - } - } catch (Exception e) { - throw new NativeWindowException(e); - } - } - } - class LocalWindowListener extends com.jogamp.newt.event.WindowAdapter { public void windowMoved(com.jogamp.newt.event.WindowEvent e) { if(null!=container) { diff --git a/src/newt/classes/jogamp/newt/windows/WindowsWindow.java b/src/newt/classes/jogamp/newt/windows/WindowsWindow.java index d820be529..05d169c5e 100644 --- a/src/newt/classes/jogamp/newt/windows/WindowsWindow.java +++ b/src/newt/classes/jogamp/newt/windows/WindowsWindow.java @@ -56,18 +56,20 @@ public class WindowsWindow extends WindowImpl { } protected int lockSurfaceImpl() { - if( 0 != getWindowHandle() && 0 == hdc ) { - hdc = GDI.GetDC(getWindowHandle()); - hmon = MonitorFromWindow0(getWindowHandle()); + if (0 != hdc) { + throw new InternalError("surface not released"); } + hdc = GDI.GetDC(getWindowHandle()); + hmon = MonitorFromWindow0(getWindowHandle()); return ( 0 != hdc ) ? LOCK_SUCCESS : LOCK_SURFACE_NOT_READY; } protected void unlockSurfaceImpl() { - if ( 0 != hdc && 0 != getWindowHandle() && getWindowLockRecursionCount() == 0) { - GDI.ReleaseDC(getWindowHandle(), hdc); - hdc=0; + if (0 == hdc) { + throw new InternalError("surface not acquired"); } + GDI.ReleaseDC(getWindowHandle(), hdc); + hdc=0; } public final long getSurfaceHandle() { |