diff options
Diffstat (limited to 'src/newt')
-rwxr-xr-x | src/newt/classes/com/sun/javafx/newt/NewtFactory.java | 2 | ||||
-rwxr-xr-x | src/newt/classes/com/sun/javafx/newt/x11/X11Display.java | 22 | ||||
-rwxr-xr-x | src/newt/native/X11Window.c | 52 |
3 files changed, 30 insertions, 46 deletions
diff --git a/src/newt/classes/com/sun/javafx/newt/NewtFactory.java b/src/newt/classes/com/sun/javafx/newt/NewtFactory.java index c9b230355..5eae559aa 100755 --- a/src/newt/classes/com/sun/javafx/newt/NewtFactory.java +++ b/src/newt/classes/com/sun/javafx/newt/NewtFactory.java @@ -36,11 +36,13 @@ package com.sun.javafx.newt; import javax.media.nativewindow.*; import java.util.ArrayList; import java.util.Iterator; +import com.sun.nativewindow.impl.jvm.JVMUtil; public abstract class NewtFactory { // Work-around for initialization order problems on Mac OS X // between native Newt and (apparently) Fmod static { + JVMUtil.initSingleton(); Window.init(NativeWindowFactory.getNativeWindowType(true)); } diff --git a/src/newt/classes/com/sun/javafx/newt/x11/X11Display.java b/src/newt/classes/com/sun/javafx/newt/x11/X11Display.java index 99c0f599c..050b9b24d 100755 --- a/src/newt/classes/com/sun/javafx/newt/x11/X11Display.java +++ b/src/newt/classes/com/sun/javafx/newt/x11/X11Display.java @@ -33,10 +33,11 @@ package com.sun.javafx.newt.x11; -import com.sun.javafx.newt.*; -import com.sun.javafx.newt.impl.*; import javax.media.nativewindow.*; import javax.media.nativewindow.x11.*; +import com.sun.javafx.newt.*; +import com.sun.javafx.newt.impl.*; +import com.sun.nativewindow.impl.x11.X11Util; public class X11Display extends Display { static { @@ -65,15 +66,23 @@ public class X11Display extends Display { } protected void createNative() { - long handle= CreateDisplay(name); + long handle= X11Util.getThreadLocalDisplay(name); if (handle == 0 ) { throw new RuntimeException("Error creating display: "+name); } + try { + CompleteDisplay(handle); + } catch(RuntimeException e) { + X11Util.closeThreadLocalDisplay(name); + throw e; + } aDevice = new X11GraphicsDevice(handle); } protected void closeNative() { - DestroyDisplay(getHandle()); + if(0==X11Util.closeThreadLocalDisplay(name)) { + throw new NativeWindowException(this+" was not mapped"); + } } protected void dispatchMessages() { @@ -88,12 +97,11 @@ public class X11Display extends Display { // private static native boolean initIDs(); - private native long CreateDisplay(String name); - private native void DestroyDisplay(long handle); + private native void CompleteDisplay(long handle); private native void DispatchMessages(long display, long javaObjectAtom, long windowDeleteAtom); - private void displayCreated(long javaObjectAtom, long windowDeleteAtom) { + private void displayCompleted(long javaObjectAtom, long windowDeleteAtom) { this.javaObjectAtom=javaObjectAtom; this.windowDeleteAtom=windowDeleteAtom; } diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c index c239dd780..8651a8cea 100755 --- a/src/newt/native/X11Window.c +++ b/src/newt/native/X11Window.c @@ -156,7 +156,7 @@ static jmethodID windowCreatedID = NULL; static jmethodID sendMouseEventID = NULL; static jmethodID sendKeyEventID = NULL; -static jmethodID displayCreatedID = NULL; +static jmethodID displayCompletedID = NULL; static void _throwNewRuntimeException(JNIEnv *env, const char* msg, ...) { @@ -184,8 +184,8 @@ JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_x11_X11Display_initIDs { jclass c; - displayCreatedID = (*env)->GetMethodID(env, clazz, "displayCreated", "(JJ)V"); - if (displayCreatedID == NULL) { + displayCompletedID = (*env)->GetMethodID(env, clazz, "displayCompleted", "(JJ)V"); + if (displayCompletedID == NULL) { return JNI_FALSE; } @@ -223,60 +223,34 @@ JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_x11_X11Display_initIDs /* * Class: com_sun_javafx_newt_x11_X11Display - * Method: CreateDisplay - * Signature: (Ljava/lang/String;)J + * Method: CompleteDisplay + * Signature: (J)V */ -JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_x11_X11Display_CreateDisplay - (JNIEnv *env, jobject obj, jstring displayName) +JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Display_CompleteDisplay + (JNIEnv *env, jobject obj, jlong display) { - Display * dpy = NULL; - const char * _displayName = NULL; + Display * dpy = (Display *)(intptr_t)display; jlong javaObjectAtom; jlong windowDeleteAtom; - if(displayName!=0) { - _displayName = (*env)->GetStringUTFChars(env, displayName, 0); - } - DBG_PRINT1("open display connection for %s ..\n", ((NULL==_displayName)?"NULL":_displayName)); - dpy = XOpenDisplay(_displayName); if(dpy==NULL) { - _throwNewRuntimeException(env, "couldn't open display connection for %s\n", ((NULL==_displayName)?"NULL":_displayName)); - } - if(_displayName!=0) { - (*env)->ReleaseStringChars(env, displayName, (const jchar *)_displayName); + _throwNewRuntimeException(env, "given display connection is NULL\n"); } javaObjectAtom = (jlong) XInternAtom(dpy, "JOGL_JAVA_OBJECT", False); if(None==javaObjectAtom) { - XCloseDisplay(dpy); _throwNewRuntimeException(env, "could not create Atom JOGL_JAVA_OBJECT, bail out!\n"); - return 0; + return; } windowDeleteAtom = (jlong) XInternAtom(dpy, "WM_DELETE_WINDOW", False); if(None==windowDeleteAtom) { - XCloseDisplay(dpy); _throwNewRuntimeException(env, "could not create Atom WM_DELETE_WINDOW, bail out!\n"); - return 0; + return; } - DBG_PRINT1("X11Display_CreateDisplay dpy %p\n", dpy); - - (*env)->CallVoidMethod(env, obj, displayCreatedID, javaObjectAtom, windowDeleteAtom); + DBG_PRINT1("X11Display_completeDisplay dpy %p\n", dpy); - return (jlong) (intptr_t) dpy; -} - -/* - * Class: com_sun_javafx_newt_x11_X11Display - * Method: DestroyDisplay - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_x11_X11Display_DestroyDisplay - (JNIEnv *env, jobject obj, jlong display) -{ - Display * dpy = (Display *)(intptr_t)display; - DBG_PRINT1("X11Display_DestroyDisplay dpy %p\n", dpy); - XCloseDisplay(dpy); + (*env)->CallVoidMethod(env, obj, displayCompletedID, javaObjectAtom, windowDeleteAtom); } static int putPtrIn32Long(unsigned long * dst, uintptr_t src) { |