From 5dba7865742ce139b94ab287208021a3afaefd70 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 23 Oct 2006 14:22:27 +0000 Subject: [PATCH] Linux: Moved another Display instance to java --- src/java/org/lwjgl/opengl/LinuxDisplay.java | 17 +++++-- src/native/linux/display.c | 14 ++---- src/native/linux/display.h | 50 --------------------- src/native/linux/org_lwjgl_opengl_Display.c | 1 - 4 files changed, 17 insertions(+), 65 deletions(-) delete mode 100644 src/native/linux/display.h diff --git a/src/java/org/lwjgl/opengl/LinuxDisplay.java b/src/java/org/lwjgl/opengl/LinuxDisplay.java index d28d7e2b..c3670ec9 100644 --- a/src/java/org/lwjgl/opengl/LinuxDisplay.java +++ b/src/java/org/lwjgl/opengl/LinuxDisplay.java @@ -430,13 +430,22 @@ final class LinuxDisplay implements DisplayImplementation { public void switchDisplayMode(DisplayMode mode) throws LWJGLException { lockAWT(); try { - nSwitchDisplayMode(getScreen(), current_displaymode_extension, mode); + switchDisplayModeOnTmpDisplay(mode); current_mode = mode; } finally { unlockAWT(); } } - private static native void nSwitchDisplayMode(int screen, int extension, DisplayMode mode) throws LWJGLException; + + private void switchDisplayModeOnTmpDisplay(DisplayMode mode) throws LWJGLException { + long tmp_display = openDisplay(); + try { + nSwitchDisplayMode(tmp_display, getScreen(), current_displaymode_extension, mode); + } finally { + closeDisplay(tmp_display); + } + } + private static native void nSwitchDisplayMode(long display, int screen, int extension, DisplayMode mode) throws LWJGLException; public void resetDisplayMode() { lockAWT(); @@ -704,7 +713,7 @@ final class LinuxDisplay implements DisplayImplementation { if (current_window_mode == FULLSCREEN_NETWM) { nIconifyWindow(getDisplay(), getWindow(), getScreen()); try { - nSwitchDisplayMode(getScreen(), current_displaymode_extension, saved_mode); + switchDisplayModeOnTmpDisplay(saved_mode); setGammaRampOnTmpDisplay(saved_gamma); } catch (LWJGLException e) { LWJGLUtil.log("Failed to restore saved mode: " + e.getMessage()); @@ -721,7 +730,7 @@ final class LinuxDisplay implements DisplayImplementation { updateInputGrab(); if (current_window_mode == FULLSCREEN_NETWM) { try { - nSwitchDisplayMode(getScreen(), current_displaymode_extension, current_mode); + switchDisplayModeOnTmpDisplay(current_mode); setGammaRampOnTmpDisplay(current_gamma); } catch (LWJGLException e) { LWJGLUtil.log("Failed to restore mode: " + e.getMessage()); diff --git a/src/native/linux/display.c b/src/native/linux/display.c index a5a66722..6488f007 100644 --- a/src/native/linux/display.c +++ b/src/native/linux/display.c @@ -47,7 +47,6 @@ #include #include #include -#include "display.h" #include "common_tools.h" #include "Window.h" #include "org_lwjgl_opengl_LinuxDisplay.h" @@ -319,7 +318,7 @@ static void setGamma(JNIEnv *env, Display *disp, int screen, jobject ramp_buffer } } -bool switchDisplayMode(JNIEnv * env, int screen, jint extension, jobject mode) { +static bool switchDisplayMode(JNIEnv * env, Display *disp, int screen, jint extension, jobject mode) { if (mode == NULL) { throwException(env, "mode must be non-null"); return false; @@ -331,17 +330,11 @@ bool switchDisplayMode(JNIEnv * env, int screen, jint extension, jobject mode) { int width = (*env)->GetIntField(env, mode, fid_width); int height = (*env)->GetIntField(env, mode, fid_height); int freq = (*env)->GetIntField(env, mode, fid_freq); - Display *disp = XOpenDisplay(NULL); - if (disp == NULL) { - throwException(env, "Could not open display"); - return false; - } if (!setMode(env, disp, screen, extension, width, height, freq)) { XCloseDisplay(disp); throwException(env, "Could not switch mode."); return false; } - XCloseDisplay(disp); return true; } @@ -403,8 +396,9 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetAvailableD 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) { - switchDisplayMode(env, screen, extension, mode); +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nSwitchDisplayMode(JNIEnv *env, jclass clazz, jlong display, jint screen, jint extension, jobject mode) { + Display *disp = (Display *)(intptr_t)display; + switchDisplayMode(env, disp, screen, extension, mode); } JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetGammaRampLength(JNIEnv *env, jclass clazz, jlong display_ptr, jint screen) { diff --git a/src/native/linux/display.h b/src/native/linux/display.h deleted file mode 100644 index 329b18f2..00000000 --- a/src/native/linux/display.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2002-2004 LWJGL Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * 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. - * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "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 THE COPYRIGHT OWNER 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. - */ - -/** - * $Id$ - * - * Linux specific library for display handling. - * - * @author elias_naur - * @version $Revision$ - */ - -#ifndef _DISPLAY_H -#define _DISPLAY_H - -#include -#include "common_tools.h" - -extern bool switchDisplayMode(JNIEnv * env, int screen, jint extension, jobject mode); - -#endif diff --git a/src/native/linux/org_lwjgl_opengl_Display.c b/src/native/linux/org_lwjgl_opengl_Display.c index 152fada3..f866c4cf 100644 --- a/src/native/linux/org_lwjgl_opengl_Display.c +++ b/src/native/linux/org_lwjgl_opengl_Display.c @@ -53,7 +53,6 @@ #include "extgl_glx.h" #include "Window.h" #include "context.h" -#include "display.h" #include "org_lwjgl_opengl_LinuxDisplay.h" #include "org_lwjgl_opengl_LinuxDisplayPeerInfo.h"