summaryrefslogtreecommitdiffstats
path: root/src/newt/classes/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/newt/classes/com')
-rwxr-xr-xsrc/newt/classes/com/jogamp/newt/Display.java74
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java2
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/intel/gdl/Display.java4
-rwxr-xr-xsrc/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java2
-rw-r--r--src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Display.java6
-rwxr-xr-xsrc/newt/classes/com/jogamp/newt/impl/opengl/kd/KDDisplay.java7
-rwxr-xr-xsrc/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java2
-rwxr-xr-xsrc/newt/classes/com/jogamp/newt/impl/x11/X11Display.java19
8 files changed, 65 insertions, 51 deletions
diff --git a/src/newt/classes/com/jogamp/newt/Display.java b/src/newt/classes/com/jogamp/newt/Display.java
index 6705db970..674a45ded 100755
--- a/src/newt/classes/com/jogamp/newt/Display.java
+++ b/src/newt/classes/com/jogamp/newt/Display.java
@@ -127,17 +127,18 @@ public abstract class Display {
/** Make sure to reuse a Display with the same name */
protected static Display create(String type, String name, final long handle) {
try {
- if(null==name && 0!=handle) {
- name="wrapping-0x"+Long.toHexString(handle); // may change within implementation ..
- }
+ Class displayClass = getDisplayClass(type);
+ Display tmpDisplay = (Display) displayClass.newInstance();
+ name = tmpDisplay.validateDisplayName(name, handle);
+
if(DEBUG) {
dumpDisplayMap("Display.create("+getFQName(type, name)+") BEGIN");
}
Display display = getCurrentDisplay(type, name);
if(null==display) {
- Class displayClass = getDisplayClass(type);
- display = (Display) displayClass.newInstance();
- display.name=name;
+ display = tmpDisplay;
+ tmpDisplay = null;
+ display.name = name;
display.type=type;
display.refCount=1;
@@ -155,11 +156,11 @@ public abstract class Display {
display.edt = display.edtUtil.start();
display.edtUtil.invokeAndWait(new Runnable() {
public void run() {
- f_dpy.createNative(handle);
+ f_dpy.createNative();
}
} );
} else {
- display.createNative(handle);
+ display.createNative();
}
if(null==display.aDevice) {
throw new RuntimeException("Display.createNative() failed to instanciate an AbstractGraphicsDevice");
@@ -169,6 +170,7 @@ public abstract class Display {
System.err.println("Display.create("+getFQName(type, name)+") NEW: "+display+" "+Thread.currentThread());
}
} else {
+ tmpDisplay = null;
synchronized(display) {
display.refCount++;
if(DEBUG) {
@@ -224,7 +226,7 @@ public abstract class Display {
}
}
- protected abstract void createNative(long handle);
+ protected abstract void createNative();
protected abstract void closeNative();
public final String getType() {
@@ -241,6 +243,13 @@ public abstract class Display {
static final String nilString = "nil" ;
+ protected String validateDisplayName(String name, long handle) {
+ if(null==name && 0!=handle) {
+ name="wrapping-0x"+Long.toHexString(handle);
+ }
+ return ( null == name ) ? nilString : name ;
+ }
+
public static final String getFQName(String type, String name) {
if(null==type) type=nilString;
if(null==name) name=nilString;
@@ -276,32 +285,49 @@ public abstract class Display {
private LinkedList/*<NEWTEvent>*/ events = new LinkedList();
protected void dispatchMessages() {
- NEWTEvent e;
- do {
+ if(!events.isEmpty()) {
synchronized(events) {
- if (!events.isEmpty()) {
- e = (NEWTEvent) events.removeFirst();
- } else {
- e = null;
- }
- }
- if (e != null) {
- Object source = e.getSource();
- if(source instanceof Window) {
- ((Window)source).sendEvent(e);
- } else {
- throw new RuntimeException("Event source not a NEWT Window: "+source.getClass().getName()+", "+source);
+ while (!events.isEmpty()) {
+ NEWTEvent e = (NEWTEvent) events.removeFirst();
+ Object source = e.getSource();
+ if(source instanceof Window) {
+ ((Window)source).sendEvent(e);
+ } else {
+ throw new RuntimeException("Event source not a NEWT Window: "+source.getClass().getName()+", "+source);
+ }
}
+ events.notifyAll();
}
- } while (e != null);
+ }
dispatchMessagesNative();
}
public void enqueueEvent(NEWTEvent e) {
+ enqueueEvent(false, e);
+ }
+
+ public void enqueueEvent(boolean wait, NEWTEvent e) {
synchronized(events) {
+ if(DEBUG) {
+ System.out.println("Display.enqueueEvent: START - wait "+wait+", "+e);
+ }
events.addLast(e);
}
+ if(wait && !events.isEmpty()) {
+ synchronized(events) {
+ while(!events.isEmpty()) {
+ try {
+ events.wait();
+ } catch (InterruptedException ie) {
+ ie.printStackTrace();
+ }
+ }
+ }
+ }
+ if(DEBUG) {
+ System.out.println("Display.enqueueEvent: END - wait "+wait+", "+e);
+ }
}
diff --git a/src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java b/src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java
index b0b518c59..f54e66f07 100644
--- a/src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java
+++ b/src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java
@@ -44,7 +44,7 @@ public class AWTDisplay extends Display {
public AWTDisplay() {
}
- protected void createNative(long handle) {
+ protected void createNative() {
aDevice = (AWTGraphicsDevice) AWTGraphicsDevice.createDevice(null); // default
}
diff --git a/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Display.java b/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Display.java
index ac27da9ef..d19aaf796 100644
--- a/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Display.java
+++ b/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Display.java
@@ -58,10 +58,10 @@ public class Display extends com.jogamp.newt.Display {
public Display() {
}
- protected void createNative(long handle) {
+ protected void createNative() {
synchronized(Display.class) {
if(0==initCounter) {
- displayHandle = (0 == handle) ? CreateDisplay() : handle;
+ displayHandle = CreateDisplay();
if(0==displayHandle) {
throw new NativeWindowException("Couldn't initialize GDL Display");
}
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 6e1119a9d..0c4362a9e 100755
--- a/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java
+++ b/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java
@@ -70,7 +70,7 @@ public class MacDisplay extends Display {
MainThread.invoke(false, dispatchAction);
}
- protected void createNative(long handle) {
+ protected void createNative() {
aDevice = new MacOSXGraphicsDevice();
}
diff --git a/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Display.java b/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Display.java
index c08499359..c2d323e56 100644
--- a/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Display.java
+++ b/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Display.java
@@ -56,10 +56,8 @@ public class Display extends com.jogamp.newt.Display {
public Display() {
}
- protected void createNative(long handle) {
- if( 0 == handle ) {
- handle = CreateDisplay(Screen.fixedWidth, Screen.fixedHeight);
- }
+ protected void createNative() {
+ long handle = CreateDisplay(Screen.fixedWidth, Screen.fixedHeight);
if (handle == EGL.EGL_NO_DISPLAY) {
throw new NativeWindowException("BC EGL CreateDisplay failed");
}
diff --git a/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDDisplay.java b/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDDisplay.java
index bb5f1cc7a..2ab30773f 100755
--- a/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDDisplay.java
+++ b/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDDisplay.java
@@ -57,12 +57,9 @@ public class KDDisplay extends Display {
public KDDisplay() {
}
- protected void createNative(long handle) {
+ protected void createNative() {
// FIXME: map name to EGL_*_DISPLAY
- // FIXME: what do to with external handle ?
- if(0==handle) {
- handle = EGL.eglGetDisplay(EGL.EGL_DEFAULT_DISPLAY);
- }
+ long handle = EGL.eglGetDisplay(EGL.EGL_DEFAULT_DISPLAY);
if (handle == EGL.EGL_NO_DISPLAY) {
throw new NativeWindowException("eglGetDisplay failed");
}
diff --git a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java
index f75c11cfb..ef033d1c8 100755
--- a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java
+++ b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java
@@ -60,7 +60,7 @@ public class WindowsDisplay extends Display {
public WindowsDisplay() {
}
- protected void createNative(long handle) {
+ protected void createNative() {
aDevice = new WindowsGraphicsDevice();
}
diff --git a/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java b/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java
index 3b0868620..54fe0542b 100755
--- a/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java
+++ b/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java
@@ -60,19 +60,12 @@ public class X11Display extends Display {
public X11Display() {
}
- protected void createNative(long handle) {
- if(0 != handle) {
- // Can't use that Display handle directly,
- // but we open up a new connection to the same Display by it's name
- String newName = X11Util.getNameOfDisplay(handle);
- if(DEBUG) {
- System.out.println("Changing Display Name (provided handle): "+name+" -> 0x"+
- Long.toHexString(handle)+" : "+newName);
- }
- handle = 0;
- name = newName;
- }
- handle= X11Util.createThreadLocalDisplay(name);
+ protected String validateDisplayName(String name, long handle) {
+ return X11Util.validateDisplayName(name, handle);
+ }
+
+ protected void createNative() {
+ long handle= X11Util.createThreadLocalDisplay(name);
if( 0 == handle ) {
throw new RuntimeException("Error creating display: "+name);
}