diff options
Diffstat (limited to 'src/nativewindow/native')
-rw-r--r-- | src/nativewindow/native/JAWT_DrawingSurfaceInfo.c | 65 | ||||
-rw-r--r-- | src/nativewindow/native/x11/XineramaHelper.c | 121 | ||||
-rw-r--r-- | src/nativewindow/native/x11/Xmisc.c | 504 | ||||
-rw-r--r-- | src/nativewindow/native/x11/extutil.h | 222 |
4 files changed, 912 insertions, 0 deletions
diff --git a/src/nativewindow/native/JAWT_DrawingSurfaceInfo.c b/src/nativewindow/native/JAWT_DrawingSurfaceInfo.c new file mode 100644 index 000000000..a0422fa8e --- /dev/null +++ b/src/nativewindow/native/JAWT_DrawingSurfaceInfo.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +#include <jawt_md.h> + +#ifdef WIN32 + #define PLATFORM_DSI_SIZE sizeof(JAWT_Win32DrawingSurfaceInfo) +#elif defined(linux) || defined(__sun) || defined(__FreeBSD__) || defined(_HPUX) + #define PLATFORM_DSI_SIZE sizeof(JAWT_X11DrawingSurfaceInfo) +#elif defined(macosx) + #define PLATFORM_DSI_SIZE sizeof(JAWT_MacOSXDrawingSurfaceInfo) +#else + ERROR: port JAWT_DrawingSurfaceInfo.c to your platform +#endif + +JNIEXPORT jobject JNICALL +Java_com_jogamp_nativewindow_impl_jawt_JAWT_1DrawingSurfaceInfo_platformInfo0(JNIEnv* env, jobject unused, jobject jthis0) { + JAWT_DrawingSurfaceInfo* dsi; + dsi = (*env)->GetDirectBufferAddress(env, jthis0); + if (dsi == NULL) { + (*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/RuntimeException"), + "Argument \"jthis0\" was not a direct buffer"); + return NULL; + } + if (dsi->platformInfo == NULL) { + return NULL; + } + return (*env)->NewDirectByteBuffer(env, dsi->platformInfo, PLATFORM_DSI_SIZE); +} diff --git a/src/nativewindow/native/x11/XineramaHelper.c b/src/nativewindow/native/x11/XineramaHelper.c new file mode 100644 index 000000000..899bbba55 --- /dev/null +++ b/src/nativewindow/native/x11/XineramaHelper.c @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 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: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +/* This file contains a helper routine to be called by Java code to + determine whether the Xinerama extension is in use and therefore to + treat the multiple AWT screens as one large screen. */ + +#include <inttypes.h> +#include <X11/Xlib.h> + +#ifdef __sun + +typedef Status XineramaGetInfoFunc(Display* display, int screen_number, + XRectangle* framebuffer_rects, unsigned char* framebuffer_hints, + int* num_framebuffers); +typedef Status XineramaGetCenterHintFunc(Display* display, int screen_number, + int* x, int* y); + +XineramaGetCenterHintFunc* XineramaSolarisCenterFunc = NULL; +#include <dlfcn.h> + +#else + +#include <X11/extensions/Xinerama.h> + +#endif + +Bool XineramaEnabled(Display* display) { +#ifdef __sun + +#define MAXFRAMEBUFFERS 16 + char* XinExtName = "XINERAMA"; + int32_t major_opcode, first_event, first_error; + Bool gotXinExt = False; + void* libHandle = 0; + unsigned char fbhints[MAXFRAMEBUFFERS]; + XRectangle fbrects[MAXFRAMEBUFFERS]; + int locNumScr = 0; + Bool usingXinerama = False; + + char* XineramaLibName= "libXext.so"; + char* XineramaGetInfoName = "XineramaGetInfo"; + char* XineramaGetCenterHintName = "XineramaGetCenterHint"; + XineramaGetInfoFunc* XineramaSolarisFunc = NULL; + + gotXinExt = XQueryExtension(display, XinExtName, &major_opcode, + &first_event, &first_error); + + if (gotXinExt) { + /* load library, load and run XineramaGetInfo */ + libHandle = dlopen(XineramaLibName, RTLD_LAZY | RTLD_GLOBAL); + if (libHandle != 0) { + XineramaSolarisFunc = (XineramaGetInfoFunc*)dlsym(libHandle, XineramaGetInfoName); + XineramaSolarisCenterFunc = + (XineramaGetCenterHintFunc*)dlsym(libHandle, + XineramaGetCenterHintName); + if (XineramaSolarisFunc != NULL) { + if ((*XineramaSolarisFunc)(display, 0, &fbrects[0], + &fbhints[0], &locNumScr) != 0) { + + usingXinerama = True; + } + } + dlclose(libHandle); + } + } + return usingXinerama; + +#else + + char* XinExtName = "XINERAMA"; + int32_t major_opcode, first_event, first_error; + Bool gotXinExt = False; + int32_t locNumScr = 0; + + XineramaScreenInfo *xinInfo; + + gotXinExt = XQueryExtension(display, XinExtName, &major_opcode, + &first_event, &first_error); + + if (gotXinExt) { + xinInfo = XineramaQueryScreens(display, &locNumScr); + if (xinInfo != NULL) { + return True; + } + } + return False; + +#endif +} + diff --git a/src/nativewindow/native/x11/Xmisc.c b/src/nativewindow/native/x11/Xmisc.c new file mode 100644 index 000000000..831d94636 --- /dev/null +++ b/src/nativewindow/native/x11/Xmisc.c @@ -0,0 +1,504 @@ +/** + * 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. + */ + + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <stdarg.h> +#include <unistd.h> +#include <errno.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> +/* Linux headers don't work properly */ +#define __USE_GNU +#include <dlfcn.h> +#undef __USE_GNU + +/* Current versions of Solaris don't expose the XF86 extensions, + although with the recent transition to Xorg this will probably + happen in an upcoming release */ +#if !defined(__sun) && !defined(_HPUX) +#include <X11/extensions/xf86vmode.h> +#else +/* Need to provide stubs for these */ +Bool XF86VidModeGetGammaRampSize( + Display *display, + int screen, + int* size) +{ + return False; +} + +Bool XF86VidModeGetGammaRamp( + Display *display, + int screen, + int size, + unsigned short *red_array, + unsigned short *green_array, + unsigned short *blue_array) { + return False; +} +Bool XF86VidModeSetGammaRamp( + Display *display, + int screen, + int size, + unsigned short *red_array, + unsigned short *green_array, + unsigned short *blue_array) { + return False; +} +#endif /* defined(__sun) || defined(_HPUX) */ + +/* HP-UX doesn't define RTLD_DEFAULT. */ +#if defined(_HPUX) && !defined(RTLD_DEFAULT) +#define RTLD_DEFAULT NULL +#endif + +#include "com_jogamp_nativewindow_impl_x11_X11Lib.h" + +// #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 */ +extern Bool XineramaEnabled(Display* display); + +static void _FatalError(JNIEnv *env, const char* msg, ...) +{ + char buffer[512]; + va_list ap; + + va_start(ap, msg); + vsnprintf(buffer, sizeof(buffer), msg, ap); + va_end(ap); + + fprintf(stderr, "%s\n", buffer); + (*env)->FatalError(env, buffer); +} + +static const char * const ClazzNameBuffers = "com/jogamp/common/nio/Buffers"; +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 jclass clazzBuffers = NULL; +static jmethodID cstrBuffers = NULL; +static jclass clazzByteBuffer = NULL; +static jclass clazzRuntimeException=NULL; + +static void _initClazzAccess(JNIEnv *env) { + jclass c; + + if(NULL!=clazzRuntimeException) return ; + + c = (*env)->FindClass(env, ClazzNameRuntimeException); + if(NULL==c) { + _FatalError(env, "Nativewindow 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); + } + + c = (*env)->FindClass(env, ClazzNameBuffers); + if(NULL==c) { + _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); + } + c = (*env)->FindClass(env, ClazzNameByteBuffer); + if(NULL==c) { + _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); + } + + 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", + ClazzNameBuffers, ClazzNameBuffersStaticCstrName, ClazzNameBuffersStaticCstrSignature); + } +} + +static void _throwNewRuntimeException(Display * unlockDisplay, JNIEnv *env, const char* msg, ...) +{ + char buffer[512]; + va_list ap; + + if(NULL!=unlockDisplay) { + XUnlockDisplay(unlockDisplay); + } + + va_start(ap, msg); + vsnprintf(buffer, sizeof(buffer), msg, ap); + va_end(ap); + + (*env)->ThrowNew(env, clazzRuntimeException, buffer); +} + +static JNIEnv * x11ErrorHandlerJNIEnv = NULL; +static XErrorHandler origErrorHandler = NULL ; +static int errorHandlerBlocked = 0 ; + +static int x11ErrorHandler(Display *dpy, XErrorEvent *e) +{ + _throwNewRuntimeException(NULL, x11ErrorHandlerJNIEnv, "Info: Nativewindow X11 Error: Display %p, Code 0x%X, errno %s", + dpy, e->error_code, strerror(errno)); + +#if 0 + if(NULL!=origErrorHandler) { + origErrorHandler(dpy, e); + } +#endif + + return 0; +} + +static void x11ErrorHandlerEnable(Display *dpy, int onoff, JNIEnv * env) { + if(errorHandlerBlocked) return; + + if(onoff) { + if(NULL==origErrorHandler) { + x11ErrorHandlerJNIEnv = env; + if(NULL!=dpy) { + XSync(dpy, False); + } + origErrorHandler = XSetErrorHandler(x11ErrorHandler); + } + } else { + if(NULL!=origErrorHandler) { + if(NULL!=dpy) { + XSync(dpy, False); + } + XSetErrorHandler(origErrorHandler); + origErrorHandler = NULL; + } + } +} + +static void x11ErrorHandlerEnableBlocking(int onoff, JNIEnv * env) { + errorHandlerBlocked = 0 ; + x11ErrorHandlerEnable(NULL, onoff, env); + errorHandlerBlocked = onoff ; +} + + +static XIOErrorHandler origIOErrorHandler = NULL; + +static int x11IOErrorHandler(Display *dpy) +{ + fprintf(stderr, "Nativewindow X11 IOError: Display %p (%s): %s\n", dpy, XDisplayName(NULL), strerror(errno)); + // _FatalError(x11ErrorHandlerJNIEnv, "Nativewindow X11 IOError: Display %p (%s): %s", dpy, XDisplayName(NULL), strerror(errno)); + if(NULL!=origIOErrorHandler) { + origIOErrorHandler(dpy); + } + return 0; +} + +static void x11IOErrorHandlerEnable(int onoff, JNIEnv * env) { + if(onoff) { + if(NULL==origIOErrorHandler) { + x11ErrorHandlerJNIEnv = env; + origIOErrorHandler = XSetIOErrorHandler(x11IOErrorHandler); + } + } else { + XSetIOErrorHandler(origIOErrorHandler); + origIOErrorHandler = NULL; + } +} + +static int _initialized=0; + +JNIEXPORT void JNICALL +Java_com_jogamp_nativewindow_impl_x11_X11Util_initialize0(JNIEnv *env, jclass _unused, jboolean firstUIActionOnProcess) { + if(0==_initialized) { + if( JNI_TRUE == firstUIActionOnProcess ) { + if( 0 == XInitThreads() ) { + fprintf(stderr, "Warning: XInitThreads() failed\n"); + } else { + fprintf(stderr, "Info: XInitThreads() called for concurrent Thread support\n"); + } + } else { + fprintf(stderr, "Info: XInitThreads() _not_ called for concurrent Thread support\n"); + } + + _initClazzAccess(env); + x11IOErrorHandlerEnable(1, env); + _initialized=1; + } +} + +JNIEXPORT void JNICALL +Java_com_jogamp_nativewindow_impl_x11_X11Util_setX11ErrorHandler0(JNIEnv *env, jclass _unused, jboolean onoff) { + x11ErrorHandlerEnableBlocking(( JNI_TRUE == onoff ) ? 1 : 0, env); +} + +/* Java->C glue code: + * Java package: com.jogamp.nativewindow.impl.x11.X11Lib + * Java method: XVisualInfo XGetVisualInfo(long arg0, long arg1, XVisualInfo arg2, java.nio.IntBuffer arg3) + * C function: XVisualInfo * XGetVisualInfo(Display * , long, XVisualInfo * , int * ); + */ +JNIEXPORT jobject JNICALL +Java_com_jogamp_nativewindow_impl_x11_X11Lib_XGetVisualInfo1__JJLjava_nio_ByteBuffer_2Ljava_lang_Object_2I(JNIEnv *env, jclass _unused, jlong arg0, jlong arg1, jobject arg2, jobject arg3, jint arg3_byte_offset) { + XVisualInfo * _ptr2 = NULL; + int * _ptr3 = NULL; + XVisualInfo * _res; + int count; + jobject jbyteSource; + jobject jbyteCopy; + if(0==arg0) { + _FatalError(env, "invalid display connection.."); + } + if (arg2 != NULL) { + _ptr2 = (XVisualInfo *) (((char*) (*env)->GetDirectBufferAddress(env, arg2)) + 0); + } + if (arg3 != NULL) { + _ptr3 = (int *) (((char*) (*env)->GetPrimitiveArrayCritical(env, arg3, NULL)) + arg3_byte_offset); + } + x11ErrorHandlerEnable((Display *) (intptr_t) arg0, 1, env); + _res = XGetVisualInfo((Display *) (intptr_t) arg0, (long) arg1, (XVisualInfo *) _ptr2, (int *) _ptr3); + x11ErrorHandlerEnable((Display *) (intptr_t) arg0, 0, env); + count = _ptr3[0]; + if (arg3 != NULL) { + (*env)->ReleasePrimitiveArrayCritical(env, arg3, _ptr3, 0); + } + if (_res == NULL) return NULL; + + jbyteSource = (*env)->NewDirectByteBuffer(env, _res, count * sizeof(XVisualInfo)); + jbyteCopy = (*env)->CallStaticObjectMethod(env, clazzBuffers, cstrBuffers, jbyteSource); + + XFree(_res); + + return jbyteCopy; +} + +JNIEXPORT jlong JNICALL +Java_com_jogamp_nativewindow_impl_x11_X11Lib_DefaultVisualID(JNIEnv *env, jclass _unused, jlong display, jint screen) { + jlong r; + if(0==display) { + _FatalError(env, "invalid display connection.."); + } + x11ErrorHandlerEnable((Display *) (intptr_t) display, 1, env); + r = (jlong) XVisualIDFromVisual( DefaultVisual( (Display*) (intptr_t) display, screen ) ); + x11ErrorHandlerEnable((Display *) (intptr_t) display, 0, env); + return r; +} + +/* Java->C glue code: + * Java package: com.jogamp.nativewindow.impl.x11.X11Lib + * Java method: void XLockDisplay(long display) + * C function: void XLockDisplay(Display * display); + */ +JNIEXPORT void JNICALL +Java_com_jogamp_nativewindow_impl_x11_X11Lib_XLockDisplay__J(JNIEnv *env, jclass _unused, jlong display) { + if(0==display) { + _FatalError(env, "invalid display connection.."); + } + XLockDisplay((Display *) (intptr_t) display); +} + +/* Java->C glue code: + * Java package: com.jogamp.nativewindow.impl.x11.X11Lib + * Java method: void XUnlockDisplay(long display) + * C function: void XUnlockDisplay(Display * display); + */ +JNIEXPORT void JNICALL +Java_com_jogamp_nativewindow_impl_x11_X11Lib_XUnlockDisplay__J(JNIEnv *env, jclass _unused, jlong display) { + if(0==display) { + _FatalError(env, "invalid display connection.."); + } + XUnlockDisplay((Display *) (intptr_t) display); +} + +/* Java->C glue code: + * Java package: com.jogamp.nativewindow.impl.x11.X11Lib + * Java method: int XCloseDisplay(long display) + * C function: int XCloseDisplay(Display * display); + */ +JNIEXPORT jint JNICALL +Java_com_jogamp_nativewindow_impl_x11_X11Lib_XCloseDisplay__J(JNIEnv *env, jclass _unused, jlong display) { + int _res; + if(0==display) { + _FatalError(env, "invalid display connection.."); + } + x11ErrorHandlerEnable((Display *) (intptr_t) display, 1, env); + _res = XCloseDisplay((Display *) (intptr_t) display); + x11ErrorHandlerEnable(NULL, 0, env); + return _res; +} + +/* + * Class: com_jogamp_nativewindow_impl_x11_X11Lib + * Method: CreateDummyWindow + * 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) +{ + Display * dpy = (Display *)(intptr_t)display; + int scrn_idx = (int)screen_index; + Window windowParent = 0; + Window window = 0; + + XVisualInfo visualTemplate; + XVisualInfo *pVisualQuery = NULL; + Visual *visual = NULL; + int depth; + + XSetWindowAttributes xswa; + unsigned long attrMask; + int n; + + Screen* scrn; + + if(NULL==dpy) { + _FatalError(env, "invalid display connection.."); + return 0; + } + + if(visualID<0) { + _throwNewRuntimeException(NULL, env, "invalid VisualID .."); + return 0; + } + + x11ErrorHandlerEnable(dpy, 1, env); + + scrn = ScreenOfDisplay(dpy, scrn_idx); + + // try given VisualID on screen + memset(&visualTemplate, 0, sizeof(XVisualInfo)); + visualTemplate.screen = scrn_idx; + visualTemplate.visualid = (VisualID)visualID; + pVisualQuery = XGetVisualInfo(dpy, VisualIDMask|VisualScreenMask, &visualTemplate,&n); + if(pVisualQuery!=NULL) { + visual = pVisualQuery->visual; + depth = pVisualQuery->depth; + visualID = (jlong)pVisualQuery->visualid; + XFree(pVisualQuery); + pVisualQuery=NULL; + } + DBG_PRINT( "X11: [CreateWindow] trying given (dpy %p, screen %d, visualID: %d, parent %p) found: %p\n", dpy, scrn_idx, (int)visualID, windowParent, visual); + + if (visual==NULL) + { + x11ErrorHandlerEnable(dpy, 0, env); + _throwNewRuntimeException(dpy, env, "could not query Visual by given VisualID, bail out!"); + return 0; + } + + if(pVisualQuery!=NULL) { + XFree(pVisualQuery); + pVisualQuery=NULL; + } + + if(0==windowParent) { + windowParent = XRootWindowOfScreen(scrn); + } + + attrMask = ( CWBackingStore | CWBackingPlanes | CWBackingPixel | CWBackPixel | + CWBorderPixel | CWColormap | CWOverrideRedirect ) ; + + memset(&xswa, 0, sizeof(xswa)); + xswa.override_redirect = False; // use the window manager, always + xswa.border_pixel = 0; + xswa.background_pixel = 0; + xswa.backing_store=NotUseful; /* NotUseful, WhenMapped, Always */ + xswa.backing_planes=0; /* planes to be preserved if possible */ + xswa.backing_pixel=0; /* value to use in restoring planes */ + xswa.event_mask = 0 ; /* no events */ + + xswa.colormap = XCreateColormap(dpy, + XRootWindow(dpy, scrn_idx), + visual, + AllocNone); + + window = XCreateWindow(dpy, + windowParent, + 0, 0, + 64, 64, + 0, // border width + depth, + InputOutput, + visual, + attrMask, + &xswa); + + XSync(dpy, False); + + XSelectInput(dpy, window, 0); // no events + XSync(dpy, False); + + x11ErrorHandlerEnable(dpy, 0, env); + + DBG_PRINT( "X11: [CreateWindow] created window %p on display %p\n", window, dpy); + + return (jlong) window; +} + + +/* + * Class: com_jogamp_nativewindow_impl_x11_X11Lib + * Method: DestroyDummyWindow + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_DestroyDummyWindow + (JNIEnv *env, jobject obj, jlong display, jlong window) +{ + Display * dpy = (Display *)(intptr_t)display; + Window w = (Window) window; + + if(NULL==dpy) { + _throwNewRuntimeException(NULL, env, "invalid display connection.."); + return; + } + + x11ErrorHandlerEnable(dpy, 1, env); + XUnmapWindow(dpy, w); + XSync(dpy, False); + XDestroyWindow(dpy, w); + x11ErrorHandlerEnable(dpy, 0, env); +} + diff --git a/src/nativewindow/native/x11/extutil.h b/src/nativewindow/native/x11/extutil.h new file mode 100644 index 000000000..f0d3b59c3 --- /dev/null +++ b/src/nativewindow/native/x11/extutil.h @@ -0,0 +1,222 @@ +/* + * $Xorg: extutil.h,v 1.3 2000/08/18 04:05:45 coskrey Exp $ + * +Copyright 1989, 1998 The Open Group + +All Rights Reserved. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + * + * Author: Jim Fulton, MIT The Open Group + * + * Xlib Extension-Writing Utilities + * + * This package contains utilities for writing the client API for various + * protocol extensions. THESE INTERFACES ARE NOT PART OF THE X STANDARD AND + * ARE SUBJECT TO CHANGE! + */ +/* $XFree86: xc/include/extensions/extutil.h,v 1.5 2001/01/17 17:53:20 dawes Exp $ */ + +#ifdef __linux__ + +#ifndef _EXTUTIL_H_ +#define _EXTUTIL_H_ + +/* + * We need to keep a list of open displays since the Xlib display list isn't + * public. We also have to per-display info in a separate block since it isn't + * stored directly in the Display structure. + */ +typedef struct _XExtDisplayInfo { + struct _XExtDisplayInfo *next; /* keep a linked list */ + Display *display; /* which display this is */ + XExtCodes *codes; /* the extension protocol codes */ + XPointer data; /* extra data for extension to use */ +} XExtDisplayInfo; + +typedef struct _XExtensionInfo { + XExtDisplayInfo *head; /* start of list */ + XExtDisplayInfo *cur; /* most recently used */ + int ndisplays; /* number of displays */ +} XExtensionInfo; + +typedef struct _XExtensionHooks { + int (*create_gc)( +#if NeedNestedPrototypes + Display* /* display */, + GC /* gc */, + XExtCodes* /* codes */ +#endif +); + int (*copy_gc)( +#if NeedNestedPrototypes + Display* /* display */, + GC /* gc */, + XExtCodes* /* codes */ +#endif +); + int (*flush_gc)( +#if NeedNestedPrototypes + Display* /* display */, + GC /* gc */, + XExtCodes* /* codes */ +#endif +); + int (*free_gc)( +#if NeedNestedPrototypes + Display* /* display */, + GC /* gc */, + XExtCodes* /* codes */ +#endif +); + int (*create_font)( +#if NeedNestedPrototypes + Display* /* display */, + XFontStruct* /* fs */, + XExtCodes* /* codes */ +#endif +); + int (*free_font)( +#if NeedNestedPrototypes + Display* /* display */, + XFontStruct* /* fs */, + XExtCodes* /* codes */ +#endif +); + int (*close_display)( +#if NeedNestedPrototypes + Display* /* display */, + XExtCodes* /* codes */ +#endif +); + Bool (*wire_to_event)( +#if NeedNestedPrototypes + Display* /* display */, + XEvent* /* re */, + xEvent* /* event */ +#endif +); + Status (*event_to_wire)( +#if NeedNestedPrototypes + Display* /* display */, + XEvent* /* re */, + xEvent* /* event */ +#endif +); + int (*error)( +#if NeedNestedPrototypes + Display* /* display */, + xError* /* err */, + XExtCodes* /* codes */, + int* /* ret_code */ +#endif +); + char *(*error_string)( +#if NeedNestedPrototypes + Display* /* display */, + int /* code */, + XExtCodes* /* codes */, + char* /* buffer */, + int /* nbytes */ +#endif +); +} XExtensionHooks; + +extern XExtensionInfo *XextCreateExtension( +#if NeedFunctionPrototypes + void +#endif +); +extern void XextDestroyExtension( +#if NeedFunctionPrototypes + XExtensionInfo* /* info */ +#endif +); +extern XExtDisplayInfo *XextAddDisplay( +#if NeedFunctionPrototypes + XExtensionInfo* /* extinfo */, + Display* /* dpy */, + char* /* ext_name */, + XExtensionHooks* /* hooks */, + int /* nevents */, + XPointer /* data */ +#endif +); +extern int XextRemoveDisplay( +#if NeedFunctionPrototypes + XExtensionInfo* /* extinfo */, + Display* /* dpy */ +#endif +); +extern XExtDisplayInfo *XextFindDisplay( +#if NeedFunctionPrototypes + XExtensionInfo* /* extinfo */, + Display* /* dpy */ +#endif +); + +#define XextHasExtension(i) ((i) && ((i)->codes)) +#define XextCheckExtension(dpy,i,name,val) \ + if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return val; } +#define XextSimpleCheckExtension(dpy,i,name) \ + if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return; } + + +/* + * helper macros to generate code that is common to all extensions; caller + * should prefix it with static if extension source is in one file; this + * could be a utility function, but have to stack 6 unused arguments for + * something that is called many, many times would be bad. + */ +#define XEXT_GENERATE_FIND_DISPLAY(proc,extinfo,extname,hooks,nev,data) \ +XExtDisplayInfo *proc (Display *dpy) \ +{ \ + XExtDisplayInfo *dpyinfo; \ + if (!extinfo) { if (!(extinfo = XextCreateExtension())) return NULL; } \ + if (!(dpyinfo = XextFindDisplay (extinfo, dpy))) \ + dpyinfo = XextAddDisplay (extinfo,dpy,extname,hooks,nev,data); \ + return dpyinfo; \ +} + +#define XEXT_FIND_DISPLAY_PROTO(proc) \ + XExtDisplayInfo *proc(Display *dpy) + +#define XEXT_GENERATE_CLOSE_DISPLAY(proc,extinfo) \ +int proc (Display *dpy, XExtCodes *codes) \ +{ \ + return XextRemoveDisplay (extinfo, dpy); \ +} + +#define XEXT_CLOSE_DISPLAY_PROTO(proc) \ + int proc(Display *dpy, XExtCodes *codes) + +#define XEXT_GENERATE_ERROR_STRING(proc,extname,nerr,errl) \ +char *proc (Display *dpy, int code, XExtCodes *codes, char *buf, int n) \ +{ \ + code -= codes->first_error; \ + if (code >= 0 && code < nerr) { \ + char tmp[256]; \ + sprintf (tmp, "%s.%d", extname, code); \ + XGetErrorDatabaseText (dpy, "XProtoError", tmp, errl[code], buf, n); \ + return buf; \ + } \ + return (char *)0; \ +} + +#define XEXT_ERROR_STRING_PROTO(proc) \ + char *proc(Display *dpy, int code, XExtCodes *codes, char *buf, int n) +#endif + +#endif /* __linux__ */ |