diff options
author | Sven Gothel <[email protected]> | 2010-11-17 10:39:56 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2010-11-17 10:39:56 +0100 |
commit | 984d1ef68ce7e353e9192fe3a4c3ec4ad7a2929c (patch) | |
tree | 59367df59c23445265cdf92af4080dec5267b2c4 | |
parent | dd0038a68a9aa99646549644c3338266546b05f8 (diff) |
Moving NEWT X11Window GetRelativeLocation() native implementation to NativeWindow X11.
-rw-r--r-- | make/config/nativewindow/x11-CustomJavaCode.java | 5 | ||||
-rw-r--r-- | make/config/nativewindow/x11-lib.cfg | 2 | ||||
-rw-r--r-- | src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java | 10 | ||||
-rw-r--r-- | src/nativewindow/native/x11/Xmisc.c | 76 | ||||
-rw-r--r-- | src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java | 3 | ||||
-rw-r--r-- | src/newt/native/X11Window.c | 58 |
6 files changed, 80 insertions, 74 deletions
diff --git a/make/config/nativewindow/x11-CustomJavaCode.java b/make/config/nativewindow/x11-CustomJavaCode.java index 5afa86737..0570901d5 100644 --- a/make/config/nativewindow/x11-CustomJavaCode.java +++ b/make/config/nativewindow/x11-CustomJavaCode.java @@ -29,6 +29,11 @@ public static native long CreateDummyWindow(long display, int screen_index, long visualID); public static native void DestroyDummyWindow(long display, long window); + public static Point GetRelativeLocation(long display, int screen_index, long src_win, long dest_win, int src_x, int src_y) { + return (Point) GetRelativeLocation0(display, screen_index, src_win, dest_win, src_x, src_y); + } + private static native Object GetRelativeLocation0(long display, int screen_index, long src_win, long dest_win, int src_x, int src_y); + public static native int XCloseDisplay(long display); public static native void XUnlockDisplay(long display); public static native void XLockDisplay(long display); diff --git a/make/config/nativewindow/x11-lib.cfg b/make/config/nativewindow/x11-lib.cfg index e554259b8..fb481ac51 100644 --- a/make/config/nativewindow/x11-lib.cfg +++ b/make/config/nativewindow/x11-lib.cfg @@ -12,6 +12,7 @@ NativeOutputDir gensrc/native/X11 # Imports needed by all glue code Import java.nio.* Import java.util.* +Import javax.media.nativewindow.util.Point # XID needs to be treated as a long for 32/64 bit compatibility Opaque long XID @@ -21,7 +22,6 @@ Opaque boolean Bool Opaque long GLXFBConfig IncludeAs CustomJavaCode X11Lib x11-CustomJavaCode.java -# Now resides in x11/Xmisc.c: IncludeAs CustomCCode x11-CustomCCode.c ArgumentIsString XOpenDisplay 0 ReturnsString XDisplayString diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java index f7f4828ca..bd76908a1 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java @@ -44,6 +44,7 @@ import java.nio.ShortBuffer; import java.security.AccessController; import java.util.ArrayList; import java.util.List; +import javax.media.nativewindow.util.Point; /** * Contains a thread safe X11 utility to retrieve display connections. @@ -517,6 +518,15 @@ public class X11Util { } } + public static Point GetRelativeLocation(long display, int screen_index, long src_win, long dest_win, int src_x, int src_y) { + lockDefaultToolkit(display); + try { + return X11Lib.GetRelativeLocation(display, screen_index, src_win, dest_win, src_x, src_y); + } finally { + unlockDefaultToolkit(display); + } + } + public static XVisualInfo[] XGetVisualInfo(long display, long arg1, XVisualInfo arg2, int[] arg3, int arg3_offset) { lockDefaultToolkit(display); try { diff --git a/src/nativewindow/native/x11/Xmisc.c b/src/nativewindow/native/x11/Xmisc.c index 0e91ae831..91292fd37 100644 --- a/src/nativewindow/native/x11/Xmisc.c +++ b/src/nativewindow/native/x11/Xmisc.c @@ -85,14 +85,9 @@ Bool XF86VidModeSetGammaRamp( // #define VERBOSE_ON 1 #ifdef VERBOSE_ON - // Workaround for ancient compiler on Solaris/SPARC #define DBG_PRINT(args...) fprintf(stderr, args); - #else - - // Workaround for ancient compiler on Solaris/SPARC #define DBG_PRINT(args...) - #endif /* Need to pull this in as we don't have a stub header for it */ @@ -116,10 +111,15 @@ static const char * const ClazzNameBuffersStaticCstrName = "copyByteBuffer"; static const char * const ClazzNameBuffersStaticCstrSignature = "(Ljava/nio/ByteBuffer;)Ljava/nio/ByteBuffer;"; static const char * const ClazzNameByteBuffer = "java/nio/ByteBuffer"; static const char * const ClazzNameRuntimeException = "java/lang/RuntimeException"; +static const char * const ClazzNamePoint = "javax/media/nativewindow/util/Point"; +static const char * const ClazzAnyCstrName = "<init>"; +static const char * const ClazzNamePointCstrSignature = "(II)V"; static jclass clazzBuffers = NULL; static jmethodID cstrBuffers = NULL; static jclass clazzByteBuffer = NULL; static jclass clazzRuntimeException=NULL; +static jclass pointClz = NULL; +static jmethodID pointCstr = NULL; static void _initClazzAccess(JNIEnv *env) { jclass c; @@ -128,39 +128,54 @@ static void _initClazzAccess(JNIEnv *env) { c = (*env)->FindClass(env, ClazzNameRuntimeException); if(NULL==c) { - _FatalError(env, "Nativewindow X11Lib: can't find %s", ClazzNameRuntimeException); + _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNameRuntimeException); } clazzRuntimeException = (jclass)(*env)->NewGlobalRef(env, c); (*env)->DeleteLocalRef(env, c); if(NULL==clazzRuntimeException) { - _FatalError(env, "FatalError: NEWT X11Window: can't use %s", ClazzNameRuntimeException); + _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNameRuntimeException); } c = (*env)->FindClass(env, ClazzNameBuffers); if(NULL==c) { - _FatalError(env, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNameBuffers); + _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNameBuffers); } clazzBuffers = (jclass)(*env)->NewGlobalRef(env, c); (*env)->DeleteLocalRef(env, c); if(NULL==clazzBuffers) { - _FatalError(env, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNameBuffers); + _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNameBuffers); } c = (*env)->FindClass(env, ClazzNameByteBuffer); if(NULL==c) { - _FatalError(env, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNameByteBuffer); + _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNameByteBuffer); } clazzByteBuffer = (jclass)(*env)->NewGlobalRef(env, c); (*env)->DeleteLocalRef(env, c); if(NULL==c) { - _FatalError(env, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNameByteBuffer); + _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNameByteBuffer); } cstrBuffers = (*env)->GetStaticMethodID(env, clazzBuffers, ClazzNameBuffersStaticCstrName, ClazzNameBuffersStaticCstrSignature); if(NULL==cstrBuffers) { - _FatalError(env, "FatalError: Java_com_jogamp_nativewindow_impl_x11_X11Lib:: can't create %s.%s %s", + _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't create %s.%s %s", ClazzNameBuffers, ClazzNameBuffersStaticCstrName, ClazzNameBuffersStaticCstrSignature); } + + c = (*env)->FindClass(env, ClazzNamePoint); + if(NULL==c) { + _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNamePoint); + } + pointClz = (jclass)(*env)->NewGlobalRef(env, c); + (*env)->DeleteLocalRef(env, c); + if(NULL==pointClz) { + _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNamePoint); + } + pointCstr = (*env)->GetMethodID(env, pointClz, ClazzAnyCstrName, ClazzNamePointCstrSignature); + if(NULL==pointCstr) { + _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't fetch %s.%s %s", + ClazzNamePoint, ClazzAnyCstrName, ClazzNamePointCstrSignature); + } } static void _throwNewRuntimeException(Display * unlockDisplay, JNIEnv *env, const char* msg, ...) @@ -386,7 +401,7 @@ Java_com_jogamp_nativewindow_impl_x11_X11Lib_XCloseDisplay__J(JNIEnv *env, jclas * Signature: (JIJ)J */ JNIEXPORT jlong JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_CreateDummyWindow - (JNIEnv *env, jobject obj, jlong display, jint screen_index, jlong visualID) + (JNIEnv *env, jclass unused, jlong display, jint screen_index, jlong visualID) { Display * dpy = (Display *)(intptr_t)display; int scrn_idx = (int)screen_index; @@ -495,7 +510,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_CreateDummy * Signature: (JJ)V */ JNIEXPORT void JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_DestroyDummyWindow - (JNIEnv *env, jobject obj, jlong display, jlong window) + (JNIEnv *env, jclass unused, jlong display, jlong window) { Display * dpy = (Display *)(intptr_t)display; Window w = (Window) window; @@ -512,3 +527,36 @@ JNIEXPORT void JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_DestroyDummy x11ErrorHandlerEnable(dpy, 0, env); } +/* + * Class: com_jogamp_nativewindow_impl_x11_X11Lib + * Method: GetRelativeLocation + * Signature: (JIJJII)Ljavax/media/nativewindow/util/Point; + */ +JNIEXPORT jobject JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_GetRelativeLocation0 + (JNIEnv *env, jclass unused, jlong jdisplay, jint screen_index, jlong jsrc_win, jlong jdest_win, jint src_x, jint src_y) +{ + Display * dpy = (Display *) (intptr_t) jdisplay; + Screen * scrn = ScreenOfDisplay(dpy, (int)screen_index); + Window root = XRootWindowOfScreen(scrn); + Window src_win = (Window)jsrc_win; + Window dest_win = (Window)jdest_win; + int dest_x=-1; + int dest_y=-1; + Window child; + Bool res; + + if( 0 == jdest_win ) { dest_win = root; } + if( 0 == jsrc_win ) { src_win = root; } + + x11ErrorHandlerEnable(dpy, 1, env); + + res = XTranslateCoordinates(dpy, src_win, dest_win, src_x, src_y, &dest_x, &dest_y, &child); + + x11ErrorHandlerEnable(dpy, 0, env); + + DBG_PRINT( "X11: GetRelativeLocation0: %p %d/%d -> %p %d/%d - ok: %d\n", + (void*)src_win, src_x, src_y, (void*)dest_win, dest_x, dest_y, (int)res); + + return (*env)->NewObject(env, pointClz, pointCstr, (jint)dest_x, (jint)dest_y); +} + diff --git a/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java b/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java index 06c7dfa99..91143923d 100644 --- a/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java +++ b/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java @@ -33,6 +33,7 @@ package com.jogamp.newt.impl.x11; +import com.jogamp.nativewindow.impl.x11.X11Util; import com.jogamp.newt.impl.WindowImpl; import javax.media.nativewindow.*; import javax.media.nativewindow.x11.*; @@ -114,7 +115,7 @@ public class X11Window extends WindowImpl { } protected Point getLocationOnScreenImpl(int x, int y) { - return (Point) getRelativeLocation0( getDisplayHandle(), getScreenIndex(), getWindowHandle(), 0 /*root win*/, x, y); + return X11Util.GetRelativeLocation( getDisplayHandle(), getScreenIndex(), getWindowHandle(), 0 /*root win*/, x, y); } //---------------------------------------------------------------------- diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c index becfa7596..7a19cf202 100644 --- a/src/newt/native/X11Window.c +++ b/src/newt/native/X11Window.c @@ -140,15 +140,8 @@ static jint X11KeySym2NewtVKey(KeySym keySym) { static const char * const ClazzNameNewtWindow = "com/jogamp/newt/Window"; -static const char * const ClazzNamePoint = "javax/media/nativewindow/util/Point"; -static const char * const ClazzAnyCstrName = "<init>"; -static const char * const ClazzNamePointCstrSignature = "(II)V"; - static jclass newtWindowClz=NULL; -static jclass pointClz = NULL; -static jmethodID pointCstr = NULL; - static jmethodID sizeChangedID = NULL; static jmethodID positionChangedID = NULL; static jmethodID focusChangedID = NULL; @@ -233,22 +226,6 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_impl_x11_X11Display_initIDs0 } } - if(NULL==pointClz) { - c = (*env)->FindClass(env, ClazzNamePoint); - if(NULL==c) { - NewtCommon_FatalError(env, "NEWT X11Windows: can't find %s", ClazzNamePoint); - } - pointClz = (jclass)(*env)->NewGlobalRef(env, c); - (*env)->DeleteLocalRef(env, c); - if(NULL==pointClz) { - NewtCommon_FatalError(env, "NEWT X11Windows: can't use %s", ClazzNamePoint); - } - pointCstr = (*env)->GetMethodID(env, pointClz, ClazzAnyCstrName, ClazzNamePointCstrSignature); - if(NULL==pointCstr) { - NewtCommon_FatalError(env, "NEWT X11Windows: can't fetch %s.%s %s", - ClazzNamePoint, ClazzAnyCstrName, ClazzNamePointCstrSignature); - } - } return JNI_TRUE; } @@ -1596,38 +1573,3 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_setTitle0 #endif } - - -/* - * Class: com_jogamp_newt_impl_x11_X11Window - * Method: getRelativeLocation0 - * Signature: (JIJJII)Ljavax/media/nativewindow/util/Point; - */ -JNIEXPORT jobject JNICALL Java_com_jogamp_newt_impl_x11_X11Window_getRelativeLocation0 - (JNIEnv *env, jobject obj, jlong jdisplay, jint screen_index, jlong jsrc_win, jlong jdest_win, jint src_x, jint src_y) -{ - Display * dpy = (Display *) (intptr_t) jdisplay; - Screen * scrn = ScreenOfDisplay(dpy, (int)screen_index); - Window root = XRootWindowOfScreen(scrn); - Window src_win = (Window)jsrc_win; - Window dest_win = (Window)jdest_win; - int dest_x=-1; - int dest_y=-1; - Window child; - Bool res; - - if( 0 == jdest_win ) { dest_win = root; } - if( 0 == jsrc_win ) { src_win = root; } - - displayDispatchErrorHandlerEnable(1, env); - - res = XTranslateCoordinates(dpy, src_win, dest_win, src_x, src_y, &dest_x, &dest_y, &child); - - displayDispatchErrorHandlerEnable(0, env); - - DBG_PRINT( "X11: getRelativeLocation0: %p %d/%d -> %p %d/%d - ok: %d\n", - (void*)src_win, src_x, src_y, (void*)dest_win, dest_x, dest_y, (int)res); - - return (*env)->NewObject(env, pointClz, pointCstr, (jint)dest_x, (jint)dest_y); -} - |