Linux: Removed current_* mode cache from display.c

This commit is contained in:
Elias Naur 2005-11-22 11:23:37 +00:00
parent f548d581ce
commit 7469d59dbf
4 changed files with 33 additions and 46 deletions

View File

@ -85,6 +85,7 @@ final class LinuxDisplay implements DisplayImplementation {
/** Saved mode to restore with */
private static DisplayMode saved_mode;
private static DisplayMode current_mode;
private static ByteBuffer getCurrentGammaRamp() throws LWJGLException {
lockAWT();
@ -249,7 +250,8 @@ final class LinuxDisplay implements DisplayImplementation {
public void switchDisplayMode(DisplayMode mode) throws LWJGLException {
lockAWT();
try {
nSwitchDisplayMode(current_displaymode_extension, mode);
current_mode = mode;
nSwitchDisplayMode(current_displaymode_extension, current_mode);
} finally {
unlockAWT();
}
@ -329,6 +331,7 @@ final class LinuxDisplay implements DisplayImplementation {
if (modes == null || modes.length == 0)
throw new LWJGLException("No modes available");
saved_mode = modes[0];
current_mode = saved_mode;
saved_gamma = getCurrentGammaRamp();
current_gamma = saved_gamma;
return saved_mode;
@ -386,13 +389,13 @@ final class LinuxDisplay implements DisplayImplementation {
public void update() {
lockAWT();
try {
nUpdate(current_displaymode_extension, current_window_mode, saved_gamma, current_gamma, saved_mode);
nUpdate(current_displaymode_extension, current_window_mode, saved_gamma, current_gamma, saved_mode, current_mode);
} catch (LWJGLException e) {
LWJGLUtil.log("Caught exception while processing messages: " + e);
}
unlockAWT();
}
private static native void nUpdate(int extension, int current_window_mode, ByteBuffer saved_gamma, ByteBuffer current_gamma, DisplayMode saved_mode) throws LWJGLException;
private static native void nUpdate(int extension, int current_window_mode, ByteBuffer saved_gamma, ByteBuffer current_gamma, DisplayMode saved_mode, DisplayMode current_mode) throws LWJGLException;
public void reshape(int x, int y, int width, int height) {
lockAWT();

View File

@ -64,10 +64,6 @@ typedef struct {
} mode_data;
} mode_info;
static int current_width;
static int current_height;
static int current_freq;
static bool getXF86VidModeVersion(JNIEnv *env, Display *disp, int *major, int *minor) {
int event_base, error_base;
@ -226,7 +222,7 @@ static bool setXrandrMode(Display *disp, int screen, mode_info *mode) {
return false;
}
static bool setMode(JNIEnv *env, Display *disp, int screen, jint extension, int width, int height, int freq, bool temporary) {
static bool setMode(JNIEnv *env, Display *disp, int screen, jint extension, int width, int height, int freq) {
int num_modes, i;
mode_info *avail_modes = getDisplayModes(disp, screen, extension, &num_modes);
if (avail_modes == NULL) {
@ -255,11 +251,6 @@ static bool setMode(JNIEnv *env, Display *disp, int screen, jint extension, int
continue;
}
result = true;
if (!temporary) {
current_width = width;
current_height = height;
current_freq = freq;
}
break;
}
}
@ -323,7 +314,7 @@ static void setGamma(JNIEnv *env, Display *disp, int screen, jobject ramp_buffer
}
}
static void setGammaRamp(JNIEnv *env, jobject gamma_ramp_buffer, int screen) {
static void setGammaRamp(JNIEnv *env, int screen, jobject gamma_ramp_buffer) {
Display * disp = XOpenDisplay(NULL);
if (disp == NULL) {
throwException(env, "Could not open display");
@ -333,20 +324,7 @@ static void setGammaRamp(JNIEnv *env, jobject gamma_ramp_buffer, int screen) {
XCloseDisplay(disp);
}
void temporaryRestoreMode(JNIEnv *env, int screen, jint extension, jobject saved_gamma_ramp) {
Display *disp = XOpenDisplay(NULL);
if (disp == NULL) {
printfDebugJava(env, "Could not open display");
return;
}
if (!setMode(env, disp, screen, extension, current_width, current_height, current_freq, false))
printfDebugJava(env, "Could not restore mode");
XCloseDisplay(disp);
// Don't propagate error to caller
setGammaRamp(env, saved_gamma_ramp, screen);
}
static bool switchDisplayMode(JNIEnv * env, int screen, jint extension, jobject mode, bool temporary) {
static bool switchDisplayMode(JNIEnv * env, int screen, jint extension, jobject mode) {
if (mode == NULL) {
throwException(env, "mode must be non-null");
return false;
@ -363,7 +341,7 @@ static bool switchDisplayMode(JNIEnv * env, int screen, jint extension, jobject
throwException(env, "Could not open display");
return false;
}
if (!setMode(env, disp, screen, extension, width, height, freq, temporary)) {
if (!setMode(env, disp, screen, extension, width, height, freq)) {
XCloseDisplay(disp);
throwException(env, "Could not switch mode.");
return false;
@ -372,10 +350,16 @@ static bool switchDisplayMode(JNIEnv * env, int screen, jint extension, jobject
return true;
}
void resetDisplayMode(JNIEnv *env, int screen, jint extension, jobject gamma_ramp, jobject saved_mode, bool temporary) {
if (!switchDisplayMode(env, screen, extension, saved_mode, temporary))
void temporaryRestoreMode(JNIEnv *env, int screen, jint extension, jobject current_gamma_ramp, jobject current_mode) {
switchDisplayMode(env, screen, extension, current_mode);
// Don't propagate error to caller
setGammaRamp(env, screen, current_gamma_ramp);
}
void resetDisplayMode(JNIEnv *env, int screen, jint extension, jobject saved_gamma_ramp, jobject saved_mode) {
if (!switchDisplayMode(env, screen, extension, saved_mode))
return;
setGammaRamp(env, gamma_ramp, screen);
setGammaRamp(env, screen, saved_gamma_ramp);
}
static jobjectArray getAvailableDisplayModes(JNIEnv * env, Display *disp, int screen, jint extension) {
@ -406,11 +390,11 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetAvailableD
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nSwitchDisplayMode(JNIEnv *env, jclass clazz, jint extension, jobject mode) {
switchDisplayMode(env, getCurrentScreen(), extension, mode, false);
switchDisplayMode(env, getCurrentScreen(), extension, mode);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nResetDisplayMode(JNIEnv *env, jclass clazz, jint extension, jobject gamma_ramp, jobject saved_mode) {
resetDisplayMode(env, getCurrentScreen(), extension, gamma_ramp, saved_mode, false);
resetDisplayMode(env, getCurrentScreen(), extension, gamma_ramp, saved_mode);
}
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetGammaRampLength(JNIEnv *env, jclass clazz) {
@ -418,6 +402,6 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetGammaRampLength(JN
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nSetGammaRamp(JNIEnv *env, jclass clazz, jobject gamma_buffer) {
setGammaRamp(env, gamma_buffer, getCurrentScreen());
setGammaRamp(env, getCurrentScreen(), gamma_buffer);
}

View File

@ -45,7 +45,7 @@
#include <jni.h>
#include "common_tools.h"
extern void resetDisplayMode(JNIEnv *env, int screen, jint extension, jobject gamma_ramp, jobject saved_mode, bool temporary);
extern void temporaryRestoreMode(JNIEnv *env, int screen, jint extension, jobject gamma_ramp);
extern void resetDisplayMode(JNIEnv *env, int screen, jint extension, jobject gamma_ramp, jobject saved_mode);
extern void temporaryRestoreMode(JNIEnv *env, int screen, jint extension, jobject gamma_ramp, jobject saved_mode);
#endif

View File

@ -190,19 +190,19 @@ static bool releaseInput(JNIEnv *env, jint extension, jint window_mode, jobject
updateInputGrab(window_mode);
if (window_mode == org_lwjgl_opengl_LinuxDisplay_FULLSCREEN_NETWM) {
XIconifyWindow(getDisplay(), getCurrentWindow(), getCurrentScreen());
resetDisplayMode(env, getCurrentScreen(), extension, gamma_ramp, saved_mode, true);
resetDisplayMode(env, getCurrentScreen(), extension, gamma_ramp, saved_mode);
}
return true;
}
static void acquireInput(JNIEnv *env, jint extension, jint window_mode, jobject gamma_ramp) {
static void acquireInput(JNIEnv *env, jint extension, jint window_mode, jobject gamma_ramp, jobject mode) {
if (isLegacyFullscreen(window_mode) || !input_released)
return;
input_released = false;
setRepeatMode(env, AutoRepeatModeOff);
updateInputGrab(window_mode);
if (window_mode == org_lwjgl_opengl_LinuxDisplay_FULLSCREEN_NETWM) {
temporaryRestoreMode(env, getCurrentScreen(), extension, gamma_ramp);
temporaryRestoreMode(env, getCurrentScreen(), extension, gamma_ramp, mode);
}
}
@ -229,12 +229,12 @@ void setGrab(jint window_mode, bool new_grab) {
}
}
static void checkInput(JNIEnv *env, jint extension, jint window_mode, jobject saved_gamma, jobject current_gamma, jobject saved_mode) {
static void checkInput(JNIEnv *env, jint extension, jint window_mode, jobject saved_gamma, jobject current_gamma, jobject saved_mode, jobject current_mode) {
Window win;
int revert_mode;
XGetInputFocus(getDisplay(), &win, &revert_mode);
if (win == current_win) {
acquireInput(env, extension, window_mode, current_gamma);
acquireInput(env, extension, window_mode, current_gamma, current_mode);
focused = true;
} else {
releaseInput(env, extension, window_mode, saved_gamma, saved_mode);
@ -242,7 +242,7 @@ static void checkInput(JNIEnv *env, jint extension, jint window_mode, jobject sa
}
}
void handleMessages(JNIEnv *env, jint extension, jint window_mode, jobject saved_gamma, jobject current_gamma, jobject saved_mode) {
void handleMessages(JNIEnv *env, jint extension, jint window_mode, jobject saved_gamma, jobject current_gamma, jobject saved_mode, jobject current_mode) {
XEvent event;
/* Window win;
int revert_mode;*/
@ -293,7 +293,7 @@ void handleMessages(JNIEnv *env, jint extension, jint window_mode, jobject saved
break;
}
}
checkInput(env, extension, window_mode, saved_gamma, current_gamma, saved_mode);
checkInput(env, extension, window_mode, saved_gamma, current_gamma, saved_mode, current_mode);
}
static void setWindowTitle(const char *title) {
@ -446,9 +446,9 @@ Window getCurrentWindow(void) {
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nUpdate
(JNIEnv *env, jclass clazz, jint extension, jint window_mode, jobject saved_gamma, jobject current_gamma, jobject saved_mode)
(JNIEnv *env, jclass clazz, jint extension, jint window_mode, jobject saved_gamma, jobject current_gamma, jobject saved_mode, jobject current_mode)
{
handleMessages(env, extension, window_mode, saved_gamma, current_gamma, saved_mode);
handleMessages(env, extension, window_mode, saved_gamma, current_gamma, saved_mode, current_mode);
}
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) {