From: <eli...@us...> - 2006-10-23 13:58:58
|
Revision: 2591 http://svn.sourceforge.net/java-game-lib/?rev=2591&view=rev Author: elias_naur Date: 2006-10-23 06:58:33 -0700 (Mon, 23 Oct 2006) Log Message: ----------- Linux: Moved Display pointer from native to java Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/Sys.java trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxCanvasImplementation.java trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplayPeerInfo.java trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxPbufferPeerInfo.java trunk/LWJGL/src/native/linux/display.c trunk/LWJGL/src/native/linux/org_lwjgl_input_Cursor.c trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c trunk/LWJGL/src/native/linux/org_lwjgl_opengl_LinuxCanvasImplementation.c trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Pbuffer.c Modified: trunk/LWJGL/src/java/org/lwjgl/Sys.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/Sys.java 2006-10-23 10:24:03 UTC (rev 2590) +++ trunk/LWJGL/src/java/org/lwjgl/Sys.java 2006-10-23 13:58:33 UTC (rev 2591) @@ -57,7 +57,7 @@ private static final String VERSION = "1.0beta3"; /** Current version of the JNI library */ - static final int JNI_VERSION = 4; + static final int JNI_VERSION = 5; /** The implementation instance to delegate platform specific behavior to */ private final static SysImplementation implementation; Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxCanvasImplementation.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxCanvasImplementation.java 2006-10-23 10:24:03 UTC (rev 2590) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxCanvasImplementation.java 2006-10-23 13:58:33 UTC (rev 2591) @@ -107,7 +107,7 @@ GLContext.loadOpenGLLibrary(); try { LinuxDisplay.incDisplay(); - return nFindVisualIDFromFormat(screen, pixel_format); + return nFindVisualIDFromFormat(LinuxDisplay.getDisplay(), screen, pixel_format); } finally { LinuxDisplay.decDisplay(); } @@ -118,5 +118,5 @@ LinuxDisplay.unlockAWT(); } } - private static native int nFindVisualIDFromFormat(int screen, PixelFormat pixel_format) throws LWJGLException; + private static native int nFindVisualIDFromFormat(long display, int screen, PixelFormat pixel_format) throws LWJGLException; } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2006-10-23 10:24:03 UTC (rev 2590) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2006-10-23 13:58:33 UTC (rev 2591) @@ -75,6 +75,9 @@ */ private static Thread current_awt_lock_owner; private static int awt_lock_count; + + /** Current X11 Display pointer */ + private static long display; private static int display_connection_usage_count = 0; @@ -111,7 +114,7 @@ incDisplay(); try { if (isXF86VidModeSupported()) - return nGetCurrentGammaRamp(); + return nGetCurrentGammaRamp(getDisplay()); else return null; } finally { @@ -121,7 +124,7 @@ unlockAWT(); } } - private static native ByteBuffer nGetCurrentGammaRamp() throws LWJGLException; + private static native ByteBuffer nGetCurrentGammaRamp(long display) throws LWJGLException; private static int getBestDisplayModeExtension() { int result; @@ -145,7 +148,7 @@ try { incDisplay(); try { - return nIsXrandrSupported(); + return nIsXrandrSupported(getDisplay()); } finally { decDisplay(); } @@ -156,14 +159,14 @@ unlockAWT(); } } - private static native boolean nIsXrandrSupported() throws LWJGLException; + private static native boolean nIsXrandrSupported(long display) throws LWJGLException; private static boolean isXF86VidModeSupported() { lockAWT(); try { incDisplay(); try { - return nIsXF86VidModeSupported(); + return nIsXF86VidModeSupported(getDisplay()); } finally { decDisplay(); } @@ -174,7 +177,7 @@ unlockAWT(); } } - private static native boolean nIsXF86VidModeSupported() throws LWJGLException; + private static native boolean nIsXF86VidModeSupported(long display) throws LWJGLException; private static boolean isNetWMFullscreenSupported() throws LWJGLException { if (Display.getPrivilegedBoolean("LWJGL_DISABLE_NETWM")) @@ -183,7 +186,7 @@ try { incDisplay(); try { - return nIsNetWMFullscreenSupported(); + return nIsNetWMFullscreenSupported(getDisplay()); } finally { decDisplay(); } @@ -194,7 +197,7 @@ unlockAWT(); } } - private static native boolean nIsNetWMFullscreenSupported() throws LWJGLException; + private static native boolean nIsNetWMFullscreenSupported(long display) throws LWJGLException; /* Since Xlib is not guaranteed to be thread safe, we need a way to synchronize LWJGL * Xlib calls with AWT Xlib calls. Fortunately, JAWT implements Lock()/Unlock() to @@ -245,7 +248,7 @@ static void incDisplay() throws LWJGLException { if (display_connection_usage_count == 0) { GLContext.loadOpenGLLibrary(); - openDisplay(); + display = openDisplay(); } display_connection_usage_count++; } @@ -255,13 +258,14 @@ if (display_connection_usage_count < 0) throw new InternalError("display_connection_usage_count < 0: " + display_connection_usage_count); if (display_connection_usage_count == 0) { - closeDisplay(); + closeDisplay(getDisplay()); + display = 0; GLContext.unloadOpenGLLibrary(); } } - private static native void openDisplay() throws LWJGLException; - private static native void closeDisplay(); + private static native long openDisplay() throws LWJGLException; + private static native void closeDisplay(long display); private int getWindowMode(boolean fullscreen) throws LWJGLException { if (fullscreen) { @@ -276,7 +280,10 @@ return WINDOWED; } - private static native long getDisplay(); + static long getDisplay() { + return display; + } + private static native int getScreen(); private static native long getWindow(); @@ -367,7 +374,7 @@ ByteBuffer handle = peer_info.lockAndGetHandle(); try { current_window_mode = getWindowMode(fullscreen); - nCreateWindow(handle, mode, current_window_mode, x, y); + nCreateWindow(getDisplay(), handle, mode, current_window_mode, x, y); blank_cursor = createBlankCursor(); current_cursor = null; focused = true; @@ -391,7 +398,7 @@ unlockAWT(); } } - private static native void nCreateWindow(ByteBuffer peer_info_handle, DisplayMode mode, int window_mode, int x, int y) throws LWJGLException; + private static native void nCreateWindow(long display, ByteBuffer peer_info_handle, DisplayMode mode, int window_mode, int x, int y) throws LWJGLException; private void updateInputGrab() { updatePointerGrab(); @@ -406,17 +413,17 @@ } catch (LWJGLException e) { LWJGLUtil.log("Failed to reset cursor: " + e.getMessage()); } - nDestroyCursor(blank_cursor); + nDestroyCursor(getDisplay(), blank_cursor); blank_cursor = null; ungrabKeyboard(); - nDestroyWindow(); + nDestroyWindow(getDisplay()); nSetRepeatMode(getDisplay(), AutoRepeatModeDefault); decDisplay(); } finally { unlockAWT(); } } - private static native void nDestroyWindow(); + private static native void nDestroyWindow(long display); public void switchDisplayMode(DisplayMode mode) throws LWJGLException { lockAWT(); @@ -530,7 +537,7 @@ try { incDisplay(); try { - return nGetCurrentXRandrMode(); + return nGetCurrentXRandrMode(getDisplay()); } finally { decDisplay(); } @@ -540,17 +547,17 @@ } /** Assumes extension == XRANDR */ - private static native DisplayMode nGetCurrentXRandrMode() throws LWJGLException; + private static native DisplayMode nGetCurrentXRandrMode(long display) throws LWJGLException; public void setTitle(String title) { lockAWT(); try { - nSetTitle(title); + nSetTitle(getDisplay(), title); } finally { unlockAWT(); } } - private static native void nSetTitle(String title); + private static native void nSetTitle(long display, String title); public boolean isCloseRequested() { boolean result = close_requested; @@ -580,7 +587,7 @@ public void update() { lockAWT(); try { - nUpdate(); + nUpdate(getDisplay()); checkInput(); } catch (LWJGLException e) { LWJGLUtil.log("Caught exception while processing messages: " + e); @@ -588,24 +595,24 @@ unlockAWT(); } } - private native void nUpdate() throws LWJGLException; + private native void nUpdate(long display) throws LWJGLException; public void reshape(int x, int y, int width, int height) { lockAWT(); try { - nReshape(x, y, width, height); + nReshape(getDisplay(), x, y, width, height); } finally { unlockAWT(); } } - private static native void nReshape(int x, int y, int width, int height); + private static native void nReshape(long display, int x, int y, int width, int height); public DisplayMode[] getAvailableDisplayModes() throws LWJGLException { lockAWT(); try { incDisplay(); try { - DisplayMode[] modes = nGetAvailableDisplayModes(current_displaymode_extension); + DisplayMode[] modes = nGetAvailableDisplayModes(getDisplay(), current_displaymode_extension); return modes; } finally { decDisplay(); @@ -614,7 +621,7 @@ unlockAWT(); } } - private static native DisplayMode[] nGetAvailableDisplayModes(int extension) throws LWJGLException; + private static native DisplayMode[] nGetAvailableDisplayModes(long display, int extension) throws LWJGLException; /* Mouse */ public boolean hasWheel() { @@ -734,7 +741,7 @@ try { incDisplay(); try { - return nGetNativeCursorCapabilities(); + return nGetNativeCursorCapabilities(getDisplay()); } finally { decDisplay(); } @@ -744,7 +751,7 @@ unlockAWT(); } } - private static native int nGetNativeCursorCapabilities() throws LWJGLException; + private static native int nGetNativeCursorCapabilities(long display) throws LWJGLException; public void setNativeCursor(Object handle) throws LWJGLException { current_cursor = (ByteBuffer)handle; @@ -761,7 +768,7 @@ try { incDisplay(); try { - return nGetMinCursorSize(); + return nGetMinCursorSize(getDisplay()); } finally { decDisplay(); } @@ -772,14 +779,14 @@ unlockAWT(); } } - private static native int nGetMinCursorSize(); + private static native int nGetMinCursorSize(long display); public int getMaxCursorSize() { lockAWT(); try { incDisplay(); try { - return nGetMaxCursorSize(); + return nGetMaxCursorSize(getDisplay()); } finally { decDisplay(); } @@ -790,7 +797,7 @@ unlockAWT(); } } - private static native int nGetMaxCursorSize(); + private static native int nGetMaxCursorSize(long display); /* Keyboard */ public void createKeyboard() throws LWJGLException { @@ -836,7 +843,7 @@ return Keyboard.STATE_UNKNOWN; } */ - private static native ByteBuffer nCreateCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, int images_offset, IntBuffer delays, int delays_offset) throws LWJGLException; + private static native ByteBuffer nCreateCursor(long display, int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, int images_offset, IntBuffer delays, int delays_offset) throws LWJGLException; private static ByteBuffer createBlankCursor() { return nCreateBlankCursor(getDisplay(), getWindow()); @@ -848,7 +855,7 @@ try { incDisplay(); try { - return nCreateCursor(width, height, xHotspot, yHotspot, numImages, images, images.position(), delays, delays != null ? delays.position() : -1); + return nCreateCursor(getDisplay(), width, height, xHotspot, yHotspot, numImages, images, images.position(), delays, delays != null ? delays.position() : -1); } catch (LWJGLException e) { decDisplay(); throw e; @@ -861,20 +868,20 @@ public void destroyCursor(Object cursorHandle) { lockAWT(); try { - nDestroyCursor(cursorHandle); + nDestroyCursor(getDisplay(), cursorHandle); decDisplay(); } finally { unlockAWT(); } } - private static native void nDestroyCursor(Object cursorHandle); + private static native void nDestroyCursor(long display, Object cursorHandle); public int getPbufferCapabilities() { lockAWT(); try { incDisplay(); try { - return nGetPbufferCapabilities(); + return nGetPbufferCapabilities(getDisplay()); } finally { decDisplay(); } @@ -885,7 +892,7 @@ unlockAWT(); } } - private static native int nGetPbufferCapabilities(); + private static native int nGetPbufferCapabilities(long display); public boolean isBufferLost(PeerInfo handle) { return false; @@ -954,7 +961,7 @@ int size = icons[i].limit() / 4; int dimension = (int)Math.sqrt(size); ByteBuffer icon = convertIcon(icons[i], dimension, dimension); - nSetWindowIcon(icon, icon.capacity(), dimension, dimension); + nSetWindowIcon(getDisplay(), icon, icon.capacity(), dimension, dimension); return 1; } return 0; @@ -969,7 +976,7 @@ } } - private static native void nSetWindowIcon(ByteBuffer icon, int icons_size, int width, int height); + private static native void nSetWindowIcon(long display, ByteBuffer icon, int icons_size, int width, int height); /* Callbacks from nUpdate() */ private void handleButtonEvent(long millis, int type, int button, int state) { Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplayPeerInfo.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplayPeerInfo.java 2006-10-23 10:24:03 UTC (rev 2590) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplayPeerInfo.java 2006-10-23 13:58:33 UTC (rev 2591) @@ -49,7 +49,7 @@ try { LinuxDisplay.incDisplay(); try { - initDefaultPeerInfo(getHandle(), pixel_format); + initDefaultPeerInfo(LinuxDisplay.getDisplay(), getHandle(), pixel_format); } catch (LWJGLException e) { LinuxDisplay.decDisplay(); throw e; @@ -62,7 +62,7 @@ LinuxDisplay.unlockAWT(); } } - private static native void initDefaultPeerInfo(ByteBuffer peer_info_handle, PixelFormat pixel_format) throws LWJGLException; + private static native void initDefaultPeerInfo(long display, ByteBuffer peer_info_handle, PixelFormat pixel_format) throws LWJGLException; protected void doLockAndInitHandle() throws LWJGLException { LinuxDisplay.lockAWT(); Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxPbufferPeerInfo.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxPbufferPeerInfo.java 2006-10-23 10:24:03 UTC (rev 2590) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxPbufferPeerInfo.java 2006-10-23 13:58:33 UTC (rev 2591) @@ -49,7 +49,7 @@ try { LinuxDisplay.incDisplay(); try { - nInitHandle(getHandle(), width, height, pixel_format); + nInitHandle(LinuxDisplay.getDisplay(), getHandle(), width, height, pixel_format); } catch (LWJGLException e) { LinuxDisplay.decDisplay(); throw e; @@ -62,7 +62,7 @@ LinuxDisplay.unlockAWT(); } } - private static native void nInitHandle(ByteBuffer handle, int width, int height, PixelFormat pixel_format) throws LWJGLException; + private static native void nInitHandle(long display, ByteBuffer handle, int width, int height, PixelFormat pixel_format) throws LWJGLException; public void destroy() { LinuxDisplay.lockAWT(); Modified: trunk/LWJGL/src/native/linux/display.c =================================================================== --- trunk/LWJGL/src/native/linux/display.c 2006-10-23 10:24:03 UTC (rev 2590) +++ trunk/LWJGL/src/native/linux/display.c 2006-10-23 13:58:33 UTC (rev 2591) @@ -108,13 +108,15 @@ return major_ver >= 2; } -JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nIsXrandrSupported(JNIEnv *env, jclass unused) { - jboolean result = isXrandrSupported(env, getDisplay()) ? JNI_TRUE : JNI_FALSE; +JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nIsXrandrSupported(JNIEnv *env, jclass unused, jlong display) { + Display *disp = (Display *)(intptr_t)display; + jboolean result = isXrandrSupported(env, disp) ? JNI_TRUE : JNI_FALSE; return result; } -JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nIsXF86VidModeSupported(JNIEnv *env, jclass unused) { - jboolean result = isXF86VidModeSupported(env, getDisplay()) ? JNI_TRUE : JNI_FALSE; +JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nIsXF86VidModeSupported(JNIEnv *env, jclass unused, jlong display) { + Display *disp = (Display *)(intptr_t)display; + jboolean result = isXF86VidModeSupported(env, disp) ? JNI_TRUE : JNI_FALSE; return result; } @@ -287,15 +289,16 @@ return native_ramp; } -JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetCurrentGammaRamp(JNIEnv *env, jclass unused) { - int ramp_size = getGammaRampLengthOfDisplay(env, getDisplay(), getCurrentScreen()); +JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetCurrentGammaRamp(JNIEnv *env, jclass unused, jlong display) { + Display *disp = (Display *)(intptr_t)display; + int ramp_size = getGammaRampLengthOfDisplay(env, disp, getCurrentScreen()); jobject ramp_buffer = newJavaManagedByteBuffer(env, sizeof(unsigned short)*3*ramp_size); if (ramp_buffer == NULL) { throwException(env, "Could not allocate gamma ramp buffer"); return NULL; } unsigned short *ramp = (unsigned short *)(*env)->GetDirectBufferAddress(env, ramp_buffer); - if (!XF86VidModeGetGammaRamp(getDisplay(), getCurrentScreen(), ramp_size, ramp, + if (!XF86VidModeGetGammaRamp(disp, getCurrentScreen(), ramp_size, ramp, ramp + ramp_size, ramp + ramp_size*2)) { throwException(env, "Could not get the current gamma ramp"); return NULL; @@ -400,12 +403,14 @@ return displayMode; } -JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetCurrentXRandrMode(JNIEnv *env, jclass unused) { - return getCurrentXRandrMode(env, getDisplay(), getCurrentScreen()); +JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetCurrentXRandrMode(JNIEnv *env, jclass unused, jlong display) { + Display *disp = (Display *)(intptr_t)display; + return getCurrentXRandrMode(env, disp, getCurrentScreen()); } -JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetAvailableDisplayModes(JNIEnv *env, jclass clazz, jint extension) { - return getAvailableDisplayModes(env, getDisplay(), getCurrentScreen(), extension); +JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetAvailableDisplayModes(JNIEnv *env, jclass clazz, jlong display, jint extension) { + Display *disp = (Display *)(intptr_t)display; + return getAvailableDisplayModes(env, disp, getCurrentScreen(), extension); } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nSwitchDisplayMode(JNIEnv *env, jclass clazz, jint screen, jint extension, jobject mode) { Modified: trunk/LWJGL/src/native/linux/org_lwjgl_input_Cursor.c =================================================================== --- trunk/LWJGL/src/native/linux/org_lwjgl_input_Cursor.c 2006-10-23 10:24:03 UTC (rev 2590) +++ trunk/LWJGL/src/native/linux/org_lwjgl_input_Cursor.c 2006-10-23 13:58:33 UTC (rev 2591) @@ -48,10 +48,11 @@ #include "common_tools.h" JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetNativeCursorCapabilities - (JNIEnv *env, jclass clazz) { + (JNIEnv *env, jclass clazz, jlong display) { + Display *disp = (Display *)(intptr_t)display; int caps = 0; - XcursorBool argb_supported = XcursorSupportsARGB(getDisplay()); - XcursorBool anim_supported = XcursorSupportsAnim(getDisplay()); + XcursorBool argb_supported = XcursorSupportsARGB(disp); + XcursorBool anim_supported = XcursorSupportsAnim(disp); if (argb_supported) caps |= org_lwjgl_input_Cursor_CURSOR_8_BIT_ALPHA | org_lwjgl_input_Cursor_CURSOR_ONE_BIT_TRANSPARENCY; if (anim_supported) @@ -60,26 +61,29 @@ } JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetMinCursorSize - (JNIEnv *env, jclass clazz) + (JNIEnv *env, jclass clazz, jlong display) { + Display *disp = (Display *)(intptr_t)display; unsigned int width_return = 0; unsigned int height_return = 0; - XQueryBestCursor(getDisplay(), getCurrentWindow(), 1, 1, &width_return, &height_return); + XQueryBestCursor(disp, getCurrentWindow(), 1, 1, &width_return, &height_return); return width_return > height_return ? width_return : height_return; } JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetMaxCursorSize - (JNIEnv *env, jclass clazz) + (JNIEnv *env, jclass clazz, jlong display) { + Display *disp = (Display *)(intptr_t)display; unsigned int width_return = 0; unsigned int height_return = 0; - XQueryBestCursor(getDisplay(), getCurrentWindow(), 0xffffffff, 0xffffffff, &width_return, &height_return); + XQueryBestCursor(disp, getCurrentWindow(), 0xffffffff, 0xffffffff, &width_return, &height_return); return width_return > height_return ? height_return : width_return; } JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nCreateCursor - (JNIEnv *env, jclass clazz, jint width, jint height, jint x_hotspot, jint y_hotspot, jint num_images, jobject image_buffer, jint images_offset, jobject delay_buffer, jint delays_offset) + (JNIEnv *env, jclass clazz, jlong display, jint width, jint height, jint x_hotspot, jint y_hotspot, jint num_images, jobject image_buffer, jint images_offset, jobject delay_buffer, jint delays_offset) { + Display *disp = (Display *)(intptr_t)display; jobject handle_buffer = newJavaManagedByteBuffer(env, sizeof(Cursor)); if (handle_buffer == NULL) { throwException(env, "Could not allocate handle buffer"); @@ -107,14 +111,15 @@ cursor_images->images[i] = cursor_image; } Cursor *cursor = (Cursor *)(*env)->GetDirectBufferAddress(env, handle_buffer); - *cursor = XcursorImagesLoadCursor(getDisplay(), cursor_images); + *cursor = XcursorImagesLoadCursor(disp, cursor_images); XcursorImagesDestroy(cursor_images); return handle_buffer; } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nDestroyCursor - (JNIEnv *env, jclass clazz, jobject cursor_handle_buffer) + (JNIEnv *env, jclass clazz, jlong display, jobject cursor_handle_buffer) { + Display *disp = (Display *)(intptr_t)display; Cursor *cursor = (Cursor *)(*env)->GetDirectBufferAddress(env, cursor_handle_buffer); - XFreeCursor(getDisplay(), *cursor); + XFreeCursor(disp, *cursor); } Modified: trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c =================================================================== --- trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c 2006-10-23 10:24:03 UTC (rev 2590) +++ trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c 2006-10-23 13:58:33 UTC (rev 2591) @@ -80,7 +80,6 @@ static Visual *current_visual; static int current_screen; -static Display *display_connection = NULL; static bool async_x_error; static char error_message[ERR_MSG_SIZE]; static Atom warp_atom; @@ -112,35 +111,27 @@ return 0; } -Display *getDisplay(void) { - return display_connection; -} - -static void openDisplay(JNIEnv *env) { +static jlong openDisplay(JNIEnv *env) { async_x_error = false; XSetErrorHandler(errorHandler); - display_connection = XOpenDisplay(NULL); + Display *display_connection = XOpenDisplay(NULL); if (display_connection == NULL) { throwException(env, "Could not open X display connection"); - return; + return (intptr_t)NULL; } - current_screen = XDefaultScreen(getDisplay()); + current_screen = XDefaultScreen(display_connection); warp_atom = XInternAtom(display_connection, "_LWJGL_WARP", False); + return (intptr_t)display_connection; } Atom getWarpAtom(void) { return warp_atom; } -static void closeDisplay(void) { - XCloseDisplay(display_connection); - display_connection = NULL; -} - -static void waitMapped(Window win) { +static void waitMapped(Display *disp, Window win) { XEvent event; do { - XMaskEvent(getDisplay(), StructureNotifyMask, &event); + XMaskEvent(disp, StructureNotifyMask, &event); } while ((event.type != MapNotify) || (event.xmap.event != win)); } @@ -155,19 +146,19 @@ XCloseDisplay(disp); } -static void setDecorations(int dec) { - Atom motif_hints_atom = XInternAtom(getDisplay(), "_MOTIF_WM_HINTS", False); +static void setDecorations(Display *disp, int dec) { + Atom motif_hints_atom = XInternAtom(disp, "_MOTIF_WM_HINTS", False); MotifWmHints motif_hints; motif_hints.flags = MWM_HINTS_DECORATIONS; motif_hints.decorations = dec; - XChangeProperty (getDisplay(), getCurrentWindow(), motif_hints_atom, motif_hints_atom, 32, PropModeReplace, (unsigned char *)&motif_hints, sizeof(MotifWmHints)/sizeof(long)); + XChangeProperty(disp, getCurrentWindow(), motif_hints_atom, motif_hints_atom, 32, PropModeReplace, (unsigned char *)&motif_hints, sizeof(MotifWmHints)/sizeof(long)); } static bool isLegacyFullscreen(jint window_mode) { return window_mode == org_lwjgl_opengl_LinuxDisplay_FULLSCREEN_LEGACY; } -static void handleMessages(JNIEnv *env, jobject disp_obj) { +static void handleMessages(JNIEnv *env, Display *disp, jobject disp_obj) { XEvent event; jclass disp_class = (*env)->GetObjectClass(env, disp_obj); if (disp_class == NULL) @@ -196,8 +187,8 @@ jmethodID handleCloseEvent_method = (*env)->GetMethodID(env, disp_class, "handleCloseEvent", "()V"); if (handleCloseEvent_method == NULL) return; - while (!(*env)->ExceptionOccurred(env) && XPending(getDisplay()) > 0) { - XNextEvent(getDisplay(), &event); + while (!(*env)->ExceptionOccurred(env) && XPending(disp) > 0) { + XNextEvent(disp, &event); if (XFilterEvent(&event, None) == True) continue; // Ignore events from old windows @@ -234,16 +225,17 @@ } } -static void setWindowTitle(const char *title) { - XStoreName(getDisplay(), current_win, title); +static void setWindowTitle(Display *disp, const char *title) { + XStoreName(disp, current_win, title); } -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_openDisplay(JNIEnv *env, jclass clazz) { - openDisplay(env); +JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_LinuxDisplay_openDisplay(JNIEnv *env, jclass clazz) { + return openDisplay(env); } -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_closeDisplay(JNIEnv *env, jclass clazz) { - closeDisplay(); +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_closeDisplay(JNIEnv *env, jclass clazz, jlong display) { + Display *disp = (Display *)(intptr_t)display; + XCloseDisplay(disp); } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplayPeerInfo_initDrawable(JNIEnv *env, jclass clazz, jobject peer_info_handle) { @@ -254,46 +246,48 @@ peer_info->drawable = getCurrentWindow(); } -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplayPeerInfo_initDefaultPeerInfo(JNIEnv *env, jclass clazz, jobject peer_info_handle, jobject pixel_format) { - initPeerInfo(env, peer_info_handle, getDisplay(), getCurrentScreen(), pixel_format, true, GLX_WINDOW_BIT, true, false); +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplayPeerInfo_initDefaultPeerInfo(JNIEnv *env, jclass clazz, jlong display, jobject peer_info_handle, jobject pixel_format) { + Display *disp = (Display *)(intptr_t)display; + initPeerInfo(env, peer_info_handle, disp, getCurrentScreen(), pixel_format, true, GLX_WINDOW_BIT, true, false); } -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nSetTitle(JNIEnv * env, jclass clazz, jstring title_obj) { +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nSetTitle(JNIEnv * env, jclass clazz, jlong display, jstring title_obj) { + Display *disp = (Display *)(intptr_t)display; char * title = GetStringNativeChars(env, title_obj); - setWindowTitle(title); + setWindowTitle(disp, title); free(title); } -static void freeIconPixmap() { +static void freeIconPixmap(Display *disp) { if (current_icon_pixmap != 0) { - XFreePixmap(getDisplay(), current_icon_pixmap); + XFreePixmap(disp, current_icon_pixmap); current_icon_pixmap = 0; } } -static void destroyWindow(JNIEnv *env) { +static void destroyWindow(JNIEnv *env, Display *disp) { if (glx_window != None) { - lwjgl_glXDestroyWindow(getDisplay(), glx_window); + lwjgl_glXDestroyWindow(disp, glx_window); glx_window = None; } - XDestroyWindow(getDisplay(), current_win); - XFreeColormap(getDisplay(), cmap); - freeIconPixmap(); + XDestroyWindow(disp, current_win); + XFreeColormap(disp, cmap); + freeIconPixmap(disp); } -static bool isNetWMFullscreenSupported(JNIEnv *env) { +static bool isNetWMFullscreenSupported(JNIEnv *env, Display *disp) { unsigned long nitems; Atom actual_type; int actual_format; unsigned long bytes_after; Atom *supported_list; - Atom netwm_supported_atom = XInternAtom(getDisplay(), "_NET_SUPPORTED", False); - int result = XGetWindowProperty(getDisplay(), RootWindow(getDisplay(), getCurrentScreen()), netwm_supported_atom, 0, 10000, False, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes_after, (void *)&supported_list); + Atom netwm_supported_atom = XInternAtom(disp, "_NET_SUPPORTED", False); + int result = XGetWindowProperty(disp, RootWindow(disp, getCurrentScreen()), netwm_supported_atom, 0, 10000, False, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes_after, (void *)&supported_list); if (result != Success) { throwException(env, "Unable to query _NET_SUPPORTED window property"); return false; } - Atom fullscreen_atom = XInternAtom(getDisplay(), "_NET_WM_STATE_FULLSCREEN", False); + Atom fullscreen_atom = XInternAtom(disp, "_NET_WM_STATE_FULLSCREEN", False); bool supported = false; unsigned long i; for (i = 0; i < nitems; i++) { @@ -306,26 +300,28 @@ return supported; } -JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nIsNetWMFullscreenSupported(JNIEnv *env, jclass unused) { - return isNetWMFullscreenSupported(env) ? JNI_TRUE : JNI_FALSE; +JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nIsNetWMFullscreenSupported(JNIEnv *env, jclass unused, jlong display) { + Display *disp = (Display *)(intptr_t)display; + return isNetWMFullscreenSupported(env, disp) ? JNI_TRUE : JNI_FALSE; } -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nReshape(JNIEnv *env, jclass clazz, jint x, jint y, jint width, jint height) { - XMoveWindow(getDisplay(), getCurrentWindow(), x, y); +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nReshape(JNIEnv *env, jclass clazz, jlong display, jint x, jint y, jint width, jint height) { + Display *disp = (Display *)(intptr_t)display; + XMoveWindow(disp, getCurrentWindow(), x, y); } -static bool createWindow(JNIEnv* env, jint window_mode, X11PeerInfo *peer_info, int x, int y, int width, int height) { +static bool createWindow(JNIEnv* env, Display *disp, jint window_mode, X11PeerInfo *peer_info, int x, int y, int width, int height) { bool undecorated = getBooleanProperty(env, "org.lwjgl.opengl.Window.undecorated"); Window root_win; Window win; XSetWindowAttributes attribs; int attribmask; - root_win = RootWindow(getDisplay(), getCurrentScreen()); + root_win = RootWindow(disp, getCurrentScreen()); XVisualInfo *vis_info = getVisualInfoFromPeerInfo(env, peer_info); if (vis_info == NULL) return false; - cmap = XCreateColormap(getDisplay(), root_win, vis_info->visual, AllocNone); + cmap = XCreateColormap(disp, root_win, vis_info->visual, AllocNone); attribs.colormap = cmap; attribs.event_mask = ExposureMask | /*FocusChangeMask | */VisibilityChangeMask | StructureNotifyMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask; attribs.background_pixel = 0xFF000000; @@ -335,21 +331,21 @@ attribmask |= CWOverrideRedirect; attribs.override_redirect = True; } - win = XCreateWindow(getDisplay(), root_win, x, y, width, height, 0, vis_info->depth, InputOutput, vis_info->visual, attribmask, &attribs); + win = XCreateWindow(disp, root_win, x, y, width, height, 0, vis_info->depth, InputOutput, vis_info->visual, attribmask, &attribs); current_depth = vis_info->depth; current_visual = vis_info->visual; XFree(vis_info); - if (!checkXError(env, getDisplay())) { - XFreeColormap(getDisplay(), cmap); + if (!checkXError(env, disp)) { + XFreeColormap(disp, cmap); return false; } printfDebugJava(env, "Created window"); current_win = win; if (window_mode != org_lwjgl_opengl_LinuxDisplay_WINDOWED || undecorated) { // Use Motif decoration hint property and hope the window manager respects them - setDecorations(0); + setDecorations(disp, 0); } XSizeHints * size_hints = XAllocSizeHints(); size_hints->flags = PMinSize | PMaxSize; @@ -357,20 +353,20 @@ size_hints->max_width = width; size_hints->min_height = height; size_hints->max_height = height; - XSetWMNormalHints(getDisplay(), win, size_hints); + XSetWMNormalHints(disp, win, size_hints); XFree(size_hints); - delete_atom = XInternAtom(getDisplay(), "WM_DELETE_WINDOW", False); - XSetWMProtocols(getDisplay(), win, &delete_atom, 1); + delete_atom = XInternAtom(disp, "WM_DELETE_WINDOW", False); + XSetWMProtocols(disp, win, &delete_atom, 1); if (window_mode == org_lwjgl_opengl_LinuxDisplay_FULLSCREEN_NETWM) { - Atom fullscreen_atom = XInternAtom(getDisplay(), "_NET_WM_STATE_FULLSCREEN", False); - XChangeProperty(getDisplay(), getCurrentWindow(), XInternAtom(getDisplay(), "_NET_WM_STATE", False), - XInternAtom(getDisplay(), "ATOM", False), 32, PropModeReplace, (const unsigned char*)&fullscreen_atom, 1); + Atom fullscreen_atom = XInternAtom(disp, "_NET_WM_STATE_FULLSCREEN", False); + XChangeProperty(disp, getCurrentWindow(), XInternAtom(disp, "_NET_WM_STATE", False), + XInternAtom(disp, "ATOM", False), 32, PropModeReplace, (const unsigned char*)&fullscreen_atom, 1); } - XMapRaised(getDisplay(), win); - waitMapped(win); - XClearWindow(getDisplay(), win); - if (!checkXError(env, getDisplay())) { - destroyWindow(env); + XMapRaised(disp, win); + waitMapped(disp, win); + XClearWindow(disp, win); + if (!checkXError(env, disp)) { + destroyWindow(env, disp); return false; } return true; @@ -380,12 +376,13 @@ return current_win; } -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nUpdate - (JNIEnv *env, jobject disp_obj) { - handleMessages(env, disp_obj); +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nUpdate(JNIEnv *env, jobject disp_obj, jlong display) { + Display *disp = (Display *)(intptr_t)display; + handleMessages(env, disp, disp_obj); } -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nCreateWindow(JNIEnv *env, jclass clazz, jobject peer_info_handle, jobject mode, jint window_mode, jint x, jint y) { +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nCreateWindow(JNIEnv *env, jclass clazz, jlong display, jobject peer_info_handle, jobject mode, jint window_mode, jint x, jint y) { + Display *disp = (Display *)(intptr_t)display; X11PeerInfo *peer_info = (*env)->GetDirectBufferAddress(env, peer_info_handle); GLXFBConfig *fb_config = NULL; if (peer_info->glx13) { @@ -398,22 +395,23 @@ jfieldID fid_height = (*env)->GetFieldID(env, cls_displayMode, "height", "I"); int width = (*env)->GetIntField(env, mode, fid_width); int height = (*env)->GetIntField(env, mode, fid_height); - bool window_created = createWindow(env, window_mode, peer_info, x, y, width, height); + bool window_created = createWindow(env, disp, window_mode, peer_info, x, y, width, height); if (!window_created) { return; } if (peer_info->glx13) { - glx_window = lwjgl_glXCreateWindow(getDisplay(), *fb_config, getCurrentWindow(), NULL); + glx_window = lwjgl_glXCreateWindow(disp, *fb_config, getCurrentWindow(), NULL); XFree(fb_config); } - if (!checkXError(env, getDisplay())) { - lwjgl_glXDestroyWindow(getDisplay(), glx_window); - destroyWindow(env); + if (!checkXError(env, disp)) { + lwjgl_glXDestroyWindow(disp, glx_window); + destroyWindow(env, disp); } } -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nDestroyWindow(JNIEnv *env, jclass clazz) { - destroyWindow(env); +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nDestroyWindow(JNIEnv *env, jclass clazz, jlong display) { + Display *disp = (Display *)(intptr_t)display; + destroyWindow(env, disp); } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nLockAWT(JNIEnv *env, jclass clazz) { @@ -436,10 +434,10 @@ jawt.Unlock(env); } -static void setIcon(JNIEnv *env, char *data, int icon_size, int width,int height) { +static void setIcon(JNIEnv *env, Display *disp, char *data, int icon_size, int width,int height) { XWMHints* win_hints; - freeIconPixmap(); - current_icon_pixmap = XCreatePixmap(getDisplay(), getCurrentWindow(), width, height, current_depth); + freeIconPixmap(disp); + current_icon_pixmap = XCreatePixmap(disp, getCurrentWindow(), width, height, current_depth); /* We need to copy the image data since XDestroyImage will also free its data buffer, which can't be allowed * since the data buffer is managed by the jvm (it's the storage for the direct ByteBuffer) */ @@ -450,17 +448,17 @@ return; } memcpy(icon_copy, data, icon_size); - XImage *image = XCreateImage(getDisplay(), current_visual, current_depth, ZPixmap, 0, icon_copy, width, height, 32, 0); + XImage *image = XCreateImage(disp, current_visual, current_depth, ZPixmap, 0, icon_copy, width, height, 32, 0); if (image == NULL) { - freeIconPixmap(); + freeIconPixmap(disp); free(icon_copy); throwException(env, "XCreateImage failed"); return; } - GC gc = XCreateGC(getDisplay(), current_icon_pixmap, 0, NULL); - XPutImage(getDisplay(), current_icon_pixmap, gc, image, 0, 0, 0, 0, width, height); - XFreeGC(getDisplay(), gc); + GC gc = XCreateGC(disp, current_icon_pixmap, 0, NULL); + XPutImage(disp, current_icon_pixmap, gc, image, 0, 0, 0, 0, width, height); + XFreeGC(disp, gc); XDestroyImage(image); // We won't free icon_copy because it is freed by XDestroyImage @@ -473,23 +471,20 @@ win_hints->flags = IconPixmapHint; win_hints->icon_pixmap = current_icon_pixmap; - XSetWMHints(getDisplay(), getCurrentWindow(), win_hints); + XSetWMHints(disp, getCurrentWindow(), win_hints); XFree(win_hints); - XFlush(getDisplay()); + XFlush(disp); } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nSetWindowIcon - (JNIEnv *env, jclass clazz, jobject iconBuffer, jint icon_size, jint width, jint height) + (JNIEnv *env, jclass clazz, jlong display, jobject iconBuffer, jint icon_size, jint width, jint height) { + Display *disp = (Display *)(intptr_t)display; char *imgData = (char *)(*env)->GetDirectBufferAddress(env, iconBuffer); - setIcon(env, imgData, icon_size, width, height); + setIcon(env, disp, imgData, icon_size, width, height); } -JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_LinuxDisplay_getDisplay(JNIEnv *env, jclass unused) { - return (intptr_t)getDisplay(); -} - JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_LinuxDisplay_getWindow(JNIEnv *env, jclass unused) { return getCurrentWindow(); } Modified: trunk/LWJGL/src/native/linux/org_lwjgl_opengl_LinuxCanvasImplementation.c =================================================================== --- trunk/LWJGL/src/native/linux/org_lwjgl_opengl_LinuxCanvasImplementation.c 2006-10-23 10:24:03 UTC (rev 2590) +++ trunk/LWJGL/src/native/linux/org_lwjgl_opengl_LinuxCanvasImplementation.c 2006-10-23 13:58:33 UTC (rev 2591) @@ -47,13 +47,14 @@ #include "Window.h" JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxCanvasImplementation_nFindVisualIDFromFormat - (JNIEnv *env, jclass clazz, jint screen, jobject pixel_format) { + (JNIEnv *env, jclass clazz, jlong display, jint screen, jobject pixel_format) { + Display *disp = (Display *)(intptr_t)display; GLXExtensions extension_flags; - if (!extgl_InitGLX(getDisplay(), screen, &extension_flags)) { + if (!extgl_InitGLX(disp, screen, &extension_flags)) { throwException(env, "Could not initialize GLX"); return -1; } - XVisualInfo *vis_info = chooseVisualGLX(env, getDisplay(), screen, pixel_format, true, true); + XVisualInfo *vis_info = chooseVisualGLX(env, disp, screen, pixel_format, true, true); if (vis_info == NULL) { throwException(env, "Could not choose a VisualInfo"); return -1; Modified: trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Pbuffer.c =================================================================== --- trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Pbuffer.c 2006-10-23 10:24:03 UTC (rev 2590) +++ trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Pbuffer.c 2006-10-23 13:58:33 UTC (rev 2591) @@ -48,23 +48,25 @@ #include "common_tools.h" JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetPbufferCapabilities - (JNIEnv *env, jclass clazz) + (JNIEnv *env, jclass clazz, jlong display) { + Display *disp = (Display *)(intptr_t)display; GLXExtensions extension_flags; - if (!extgl_InitGLX(getDisplay(), getCurrentScreen(), &extension_flags)) + if (!extgl_InitGLX(disp, getCurrentScreen(), &extension_flags)) return 0; // Only support the GLX 1.3 Pbuffers and ignore the GLX_SGIX_pbuffer extension return extension_flags.GLX13 ? org_lwjgl_opengl_Pbuffer_PBUFFER_SUPPORTED : 0; } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxPbufferPeerInfo_nInitHandle - (JNIEnv *env, jclass clazz, jobject peer_info_handle, jint width, jint height, jobject pixel_format) { + (JNIEnv *env, jclass clazz, jlong display, jobject peer_info_handle, jint width, jint height, jobject pixel_format) { + Display *disp = (Display *)(intptr_t)display; GLXExtensions extension_flags; - if (!extgl_InitGLX(getDisplay(), getCurrentScreen(), &extension_flags) || !extension_flags.GLX13) { + if (!extgl_InitGLX(disp, getCurrentScreen(), &extension_flags) || !extension_flags.GLX13) { throwException(env, "No Pbuffer support"); return; } - bool result = initPeerInfo(env, peer_info_handle, getDisplay(), getCurrentScreen(), pixel_format, false, GLX_PBUFFER_BIT, false, true); + bool result = initPeerInfo(env, peer_info_handle, disp, getCurrentScreen(), pixel_format, false, GLX_PBUFFER_BIT, false, true); if (!result) return; const int buffer_attribs[] = {GLX_PBUFFER_WIDTH, width, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |