Linux: Moved another Display instance to java

This commit is contained in:
Elias Naur 2006-10-23 14:22:27 +00:00
parent 1a83741b89
commit 5dba786574
4 changed files with 17 additions and 65 deletions

View File

@ -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());

View File

@ -47,7 +47,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#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) {

View File

@ -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 <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
#ifndef _DISPLAY_H
#define _DISPLAY_H
#include <jni.h>
#include "common_tools.h"
extern bool switchDisplayMode(JNIEnv * env, int screen, jint extension, jobject mode);
#endif

View File

@ -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"