From d94115b3d72ec556371e6d09c2967345662fc781 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 2 Jun 2010 04:13:43 +0200 Subject: NEWT: Simplified Locking - Using Display.getEDTUtil() and Display.runCreateAndDestroyOnEDT() to determine the NEWT EDT behavior, which may be specialized by the implementation. - AWTWrapper and Newt/AWT Parenting deadlock fix. - Misc fixes in test cases --- make/build.xml | 4 ++-- make/scripts/java-run-all.sh | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'make') diff --git a/make/build.xml b/make/build.xml index 9a1cf81ce..4b6c2cabe 100644 --- a/make/build.xml +++ b/make/build.xml @@ -63,7 +63,7 @@ - + @@ -155,7 +155,7 @@ - Main build target. --> - + diff --git a/make/scripts/java-run-all.sh b/make/scripts/java-run-all.sh index 0e5be242a..5f6cff28a 100755 --- a/make/scripts/java-run-all.sh +++ b/make/scripts/java-run-all.sh @@ -38,6 +38,7 @@ uname -a | grep -i Darwin && MOSX=1 # D_ARGS="-Dnewt.debug=all -Dnativewindow.debug=all" # D_ARGS="-Dnewt.debug=all" # D_ARGS="-Dnewt.debug.Window" +# D_ARGS="-Dnewt.debug.Display" # D_ARGS="-Djogl.debug=all" rm -f java-run.log -- cgit v1.2.3 From ede9386de45b63f46c206aaed27ddeafe8fe96fa Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 2 Jun 2010 04:16:28 +0200 Subject: NEWT/MacOSX: First Changes towards general NEWT/AWT solution (incomplete). - Excluding MacOSX build from CDC build - If MainThread is not running, use AWT's EDT thread - Execute most MacWindow tasks directly. --- make/build-newt.xml | 2 +- .../com/jogamp/newt/impl/macosx/MacDisplay.java | 17 +- .../com/jogamp/newt/impl/macosx/MacWindow.java | 245 +++++++++------------ 3 files changed, 116 insertions(+), 148 deletions(-) (limited to 'make') diff --git a/make/build-newt.xml b/make/build-newt.xml index 2cb848588..0d9ee2118 100644 --- a/make/build-newt.xml +++ b/make/build-newt.xml @@ -122,7 +122,7 @@ - + diff --git a/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java b/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java index 0c4362a9e..9b9dca2e4 100755 --- a/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java +++ b/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java @@ -67,7 +67,16 @@ public class MacDisplay extends Display { private DispatchAction dispatchAction = new DispatchAction(); protected void dispatchMessagesNative() { - MainThread.invoke(false, dispatchAction); + if (false && MainThread.isRunning()) { + MainThread.invoke(false, dispatchAction); + } else { + try { + java.awt.EventQueue.invokeLater(dispatchAction); + // java.awt.EventQueue.invokeAndWait(dispatchAction); + } catch (Exception ie) { + ie.printStackTrace(); + } + } } protected void createNative() { @@ -76,6 +85,12 @@ public class MacDisplay extends Display { protected void closeNative() { } + /*public boolean runCreateAndDestroyOnEDT() { + return false; + } + public EDTUtil getEDTUtil() { + return null; + }*/ private static native boolean initNSApplication0(); protected native void dispatchMessages0(); } diff --git a/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java b/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java index 20a181096..c45a30bc7 100755 --- a/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java +++ b/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java @@ -36,7 +36,6 @@ package com.jogamp.newt.impl.macosx; import javax.media.nativewindow.*; import com.jogamp.nativewindow.impl.RecursiveToolkitLock; -import com.jogamp.newt.util.MainThread; import com.jogamp.newt.*; import com.jogamp.newt.event.*; import com.jogamp.newt.impl.*; @@ -149,30 +148,23 @@ public class MacWindow extends Window { } } - class CloseAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if(DEBUG_IMPLEMENTATION) { System.out.println("MacWindow.CloseAction "+Thread.currentThread().getName()); } - if (windowHandle != 0) { - close0(windowHandle); - } - } catch (Throwable t) { - if(DEBUG_IMPLEMENTATION) { - Exception e = new Exception("closeNative failed - "+Thread.currentThread().getName(), t); - e.printStackTrace(); - } - } finally { - windowHandle = 0; - nsViewLock.unlock(); + protected void closeNative() { + nsViewLock.lock(); + try { + if(DEBUG_IMPLEMENTATION) { System.out.println("MacWindow.CloseAction "+Thread.currentThread().getName()); } + if (windowHandle != 0) { + close0(windowHandle); } + } catch (Throwable t) { + if(DEBUG_IMPLEMENTATION) { + Exception e = new Exception("closeNative failed - "+Thread.currentThread().getName(), t); + e.printStackTrace(); + } + } finally { + windowHandle = 0; + nsViewLock.unlock(); } } - private CloseAction closeAction = new CloseAction(); - - protected void closeNative() { - MainThread.invoke(true, closeAction); - } public long getWindowHandle() { nsViewLock.lock(); @@ -192,25 +184,12 @@ public class MacWindow extends Window { } } - class EnsureWindowCreatedAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - createWindow(false, getX(), getY(), getWidth(), getHeight(), isFullscreen()); - } finally { - nsViewLock.unlock(); - } - } - } - private EnsureWindowCreatedAction ensureWindowCreatedAction = - new EnsureWindowCreatedAction(); - public Insets getInsets() { // in order to properly calculate insets we need the window to be // created - MainThread.invoke(true, ensureWindowCreatedAction); nsViewLock.lock(); try { + createWindow(false, getX(), getY(), getWidth(), getHeight(), isFullscreen()); return (Insets) insets.clone(); } finally { nsViewLock.unlock(); @@ -235,120 +214,84 @@ public class MacWindow extends Window { } protected void setVisibleImpl(final boolean visible) { - MainThread.invoke(true, new Runnable() { - public void run() { - nsViewLock.lock(); - try { - if (visible) { - createWindow(false, getX(), getY(), getWidth(), getHeight(), isFullscreen()); - if (windowHandle != 0) { - makeKeyAndOrderFront0(windowHandle); - } - } else { - if (windowHandle != 0) { - orderOut0(windowHandle); - } - } - } finally { - nsViewLock.unlock(); + nsViewLock.lock(); + try { + if (visible) { + createWindow(false, getX(), getY(), getWidth(), getHeight(), isFullscreen()); + if (windowHandle != 0) { + makeKeyAndOrderFront0(windowHandle); } - } - }); - } - - class TitleAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { + } else { if (windowHandle != 0) { - setTitle0(windowHandle, title); + orderOut0(windowHandle); } - } finally { - nsViewLock.unlock(); } + } finally { + nsViewLock.unlock(); } } - private TitleAction titleAction = new TitleAction(); public void setTitle(String title) { super.setTitle(title); - MainThread.invoke(true, titleAction); - } - - class FocusAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if (windowHandle != 0) { - makeKey0(windowHandle); - } - } finally { - nsViewLock.unlock(); + nsViewLock.lock(); + try { + if (windowHandle != 0) { + setTitle0(windowHandle, title); } + } finally { + nsViewLock.unlock(); } } - private FocusAction focusAction = new FocusAction(); public void requestFocus() { super.requestFocus(); - MainThread.invoke(true, focusAction); - } - - class SizeAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if (windowHandle != 0) { - setContentSize0(windowHandle, width, height); - } - } finally { - nsViewLock.unlock(); + nsViewLock.lock(); + try { + if (windowHandle != 0) { + makeKey0(windowHandle); } + } finally { + nsViewLock.unlock(); } } - private SizeAction sizeAction = new SizeAction(); - + protected void setSizeImpl(int width, int height) { // this width/height will be set by sizeChanged, called by OSX - MainThread.invoke(true, sizeAction); - } - - class PositionAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if (windowHandle != 0) { - setFrameTopLeftPoint0(parentWindowHandle, windowHandle, x, y); - } - } finally { - nsViewLock.unlock(); + nsViewLock.lock(); + try { + if (windowHandle != 0) { + setContentSize0(windowHandle, width, height); } + } finally { + nsViewLock.unlock(); } } - private PositionAction positionAction = new PositionAction(); - + protected void setPositionImpl(int x, int y) { // this x/y will be set by positionChanged, called by OSX - MainThread.invoke(true, positionAction); + nsViewLock.lock(); + try { + if (windowHandle != 0) { + setFrameTopLeftPoint0(parentWindowHandle, windowHandle, x, y); + } + } finally { + nsViewLock.unlock(); + } } protected boolean setFullscreenImpl(final boolean fullscreen, final int x, final int y, final int w, final int h) { - MainThread.invoke(true, new Runnable() { - public void run() { - nsViewLock.lock(); - try { - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - System.err.println("MacWindow fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); - } - createWindow(true, x, y, w, h, fullscreen); - if (windowHandle != 0) { - makeKeyAndOrderFront0(windowHandle); - } - } finally { - nsViewLock.unlock(); - } + nsViewLock.lock(); + try { + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("MacWindow fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); } - }); + createWindow(true, x, y, w, h, fullscreen); + if (windowHandle != 0) { + makeKeyAndOrderFront0(windowHandle); + } + } finally { + nsViewLock.unlock(); + } return fullscreen; } @@ -500,35 +443,45 @@ public class MacWindow extends Window { super.sendKeyEvent(eventType, modifiers, key, keyChar); } - private void createWindow(boolean recreate, int x, int y, int width, int height, boolean fullscreen) { + private void createWindow(final boolean recreate, final int x, final int y, final int width, final int height, final boolean fullscreen) { + if(0!=windowHandle && !recreate) { return; } - if(0!=windowHandle) { - // save the view .. close the window - surfaceHandle = changeContentView0(parentWindowHandle, windowHandle, 0); - if(recreate && 0==surfaceHandle) { - throw new NativeWindowException("Internal Error - recreate, window but no view"); - } - close0(windowHandle); - windowHandle=0; - } else { - surfaceHandle = 0; - } - windowHandle = createWindow0(parentWindowHandle, - x, y, width, height, fullscreen, - (isUndecorated(fullscreen) ? - NSBorderlessWindowMask : - NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask), - NSBackingStoreBuffered, - getScreen().getIndex(), surfaceHandle); - if (windowHandle == 0) { - throw new NativeWindowException("Could create native window "+Thread.currentThread().getName()+" "+this); + + try { + java.awt.EventQueue.invokeAndWait(new Runnable() { + public void run() { + if(0!=windowHandle) { + // save the view .. close the window + surfaceHandle = changeContentView0(parentWindowHandle, windowHandle, 0); + if(recreate && 0==surfaceHandle) { + throw new NativeWindowException("Internal Error - recreate, window but no view"); + } + close0(windowHandle); + windowHandle=0; + } else { + surfaceHandle = 0; + } + windowHandle = createWindow0(parentWindowHandle, + x, y, width, height, fullscreen, + (isUndecorated(fullscreen) ? + NSBorderlessWindowMask : + NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask), + NSBackingStoreBuffered, + getScreen().getIndex(), surfaceHandle); + if (windowHandle == 0) { + throw new NativeWindowException("Could create native window "+Thread.currentThread().getName()+" "+this); + } + surfaceHandle = contentView0(windowHandle); + setTitle0(windowHandle, getTitle()); + // don't make the window visible on window creation + // makeKeyAndOrderFront0(windowHandle); + } } ); + } catch (Exception ie) { + ie.printStackTrace(); } - surfaceHandle = contentView0(windowHandle); - setTitle0(windowHandle, getTitle()); - // don't make the window visible on window creation -// makeKeyAndOrderFront0(windowHandle); + sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS); -- cgit v1.2.3