From 61bfceaaed1745899f7de8351341b28895c3c104 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 21 Nov 2005 16:50:11 +0000 Subject: [PATCH] Linux: Moved a display connection to java --- src/java/org/lwjgl/opengl/LinuxDisplay.java | 9 +++++++-- src/native/linux/display.c | 9 +-------- src/native/linux/display.h | 2 +- src/native/linux/org_lwjgl_opengl_Display.c | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/java/org/lwjgl/opengl/LinuxDisplay.java b/src/java/org/lwjgl/opengl/LinuxDisplay.java index e8967086..a91bd3f2 100644 --- a/src/java/org/lwjgl/opengl/LinuxDisplay.java +++ b/src/java/org/lwjgl/opengl/LinuxDisplay.java @@ -392,8 +392,13 @@ final class LinuxDisplay implements DisplayImplementation { public DisplayMode[] getAvailableDisplayModes() throws LWJGLException { lockAWT(); try { - DisplayMode[] modes = nGetAvailableDisplayModes(current_displaymode_extension); - return modes; + incDisplay(); + try { + DisplayMode[] modes = nGetAvailableDisplayModes(current_displaymode_extension); + return modes; + } finally { + decDisplay(); + } } finally { unlockAWT(); } diff --git a/src/native/linux/display.c b/src/native/linux/display.c index a1c35fef..848a1659 100644 --- a/src/native/linux/display.c +++ b/src/native/linux/display.c @@ -413,15 +413,9 @@ void resetDisplayMode(JNIEnv *env, int screen, jint extension, jobject gamma_ram XCloseDisplay(disp); } -jobjectArray getAvailableDisplayModes(JNIEnv * env, int screen, jint extension) { +jobjectArray getAvailableDisplayModes(JNIEnv * env, Display *disp, int screen, jint extension) { int num_modes, i; mode_info *avail_modes; - Display *disp = XOpenDisplay(NULL); - if (disp == NULL) { - throwException(env, "Could not open display"); - return NULL; - } - int bpp = XDefaultDepth(disp, screen); avail_modes = getDisplayModes(disp, screen, extension, &num_modes); if (avail_modes == NULL) { @@ -439,7 +433,6 @@ jobjectArray getAvailableDisplayModes(JNIEnv * env, int screen, jint extension) (*env)->SetObjectArrayElement(env, ret, i, displayMode); } free(avail_modes); - XCloseDisplay(disp); return ret; } diff --git a/src/native/linux/display.h b/src/native/linux/display.h index 65c139f8..a6947be9 100644 --- a/src/native/linux/display.h +++ b/src/native/linux/display.h @@ -50,7 +50,7 @@ extern int getScreenModeHeight(void); extern jobject initDisplay(JNIEnv *env, int screen, jint extension); extern void switchDisplayMode(JNIEnv * env, jobject mode, int screen, jint extension); extern void resetDisplayMode(JNIEnv *env, int screen, jint extension, jobject gamma_ramp, bool temporary); -extern jobjectArray getAvailableDisplayModes(JNIEnv * env, int screen, jint extension); +extern jobjectArray getAvailableDisplayModes(JNIEnv * env, Display *disp, int screen, jint extension); extern int getGammaRampLengthOfDisplay(JNIEnv *env, Display *disp, int screen); extern void setGammaRamp(JNIEnv *env, jobject gamma_ramp_buffer, int screen); extern void temporaryRestoreMode(JNIEnv *env, int screen, jint extension, jobject gamma_ramp); diff --git a/src/native/linux/org_lwjgl_opengl_Display.c b/src/native/linux/org_lwjgl_opengl_Display.c index 18875077..254e7995 100644 --- a/src/native/linux/org_lwjgl_opengl_Display.c +++ b/src/native/linux/org_lwjgl_opengl_Display.c @@ -460,7 +460,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nUpdate } JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetAvailableDisplayModes(JNIEnv *env, jclass clazz, jint extension) { - return getAvailableDisplayModes(env, getCurrentScreen(), extension); + return getAvailableDisplayModes(env, getDisplay(), getCurrentScreen(), extension); } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nSwitchDisplayMode(JNIEnv *env, jclass clazz, jint extension, jobject mode) {