Update of /cvsroot/java-game-lib/LWJGL/src/native/linux
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13079/src/native/linux
Modified Files:
display.c display.h org_lwjgl_opengl_Display.c
Log Message:
Linux: reset/restore gamma settings on activate/deactivate
Index: display.h
===================================================================
RCS file: /cvsroot/java-game-lib/LWJGL/src/native/linux/display.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- display.h 8 Sep 2004 20:15:55 -0000 1.4
+++ display.h 22 Sep 2004 19:25:16 -0000 1.5
@@ -50,12 +50,11 @@
extern int getScreenModeHeight(void);
extern jobject initDisplay(JNIEnv *env, int screen);
extern void switchDisplayMode(JNIEnv * env, jobject mode, int screen);
-extern void resetDisplayMode(JNIEnv * env, int screen);
+extern void resetDisplayMode(int screen);
extern jobjectArray getAvailableDisplayModes(JNIEnv * env, int screen);
extern int getGammaRampLength(int screen);
extern void setGammaRamp(JNIEnv *env, jobject gamma_ramp_buffer, int screen);
extern extension getCurrentDisplayModeExtension();
-extern void temporaryResetMode(int screen);
extern void temporaryRestoreMode(int screen);
#endif
Index: display.c
===================================================================
RCS file: /cvsroot/java-game-lib/LWJGL/src/native/linux/display.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- display.c 10 Sep 2004 08:13:55 -0000 1.1
+++ display.c 22 Sep 2004 19:25:15 -0000 1.2
@@ -68,9 +68,11 @@
static int current_height;
static int current_freq;
static int saved_gamma_ramp_length = 0;
-static unsigned short *r_ramp;
-static unsigned short *g_ramp;
-static unsigned short *b_ramp;
+static unsigned short *r_ramp = NULL;
+static unsigned short *g_ramp = NULL;
+static unsigned short *b_ramp = NULL;
+static unsigned short *current_ramp = NULL;
+static int current_gamma_ramp_length = 0;
static extension current_extension = NONE;
int getScreenModeWidth(void) {
@@ -341,26 +343,34 @@
return newMode;
}
-void temporaryRestoreMode(int screen) {
- Display *disp = XOpenDisplay(NULL);
- if (disp == NULL) {
- printfDebug("Could not open display");
+static void freeCurrentGamma(void) {
+ if (current_ramp != NULL) {
+ free(current_ramp);
+ current_ramp = NULL;
+ current_gamma_ramp_length = 0;
+ }
+}
+
+static void setCurrentGamma(Display *disp, int screen, JNIEnv *env) {
+ if (current_gamma_ramp_length == 0)
return;
+ if (XF86VidModeSetGammaRamp(disp, screen, current_gamma_ramp_length, current_ramp, current_ramp, current_ramp) == False) {
+ if (env != NULL)
+ throwException(env, "Could not set gamma ramp.");
+ else
+ printfDebug("Could not set gamma ramp\n");
}
- if (!setMode(disp, screen, current_width, current_height, current_freq))
- printfDebug("Could not restore mode\n");
- XCloseDisplay(disp);
- // Don't propagate error to caller
}
-void temporaryResetMode(int screen) {
+void temporaryRestoreMode(int screen) {
Display *disp = XOpenDisplay(NULL);
if (disp == NULL) {
printfDebug("Could not open display");
return;
}
- if (!setMode(disp, screen, saved_width, saved_height, saved_freq))
- printfDebug("Could not reset mode\n");
+ if (!setMode(disp, screen, current_width, current_height, current_freq))
+ printfDebug("Could not restore mode\n");
+ setCurrentGamma(disp, screen, NULL);
XCloseDisplay(disp);
// Don't propagate error to caller
}
@@ -391,9 +401,8 @@
XCloseDisplay(disp);
}
-void resetDisplayMode(JNIEnv *env, int screen) {
+void resetDisplayMode(int screen) {
Display *disp = XOpenDisplay(NULL);
-// Display *disp = incDisplay(env);
if (disp == NULL)
return;
if (!setMode(disp, screen, saved_width, saved_height, saved_freq)) {
@@ -401,7 +410,6 @@
}
if (saved_gamma_ramp_length > 0) {
XF86VidModeSetGammaRamp(disp, screen, saved_gamma_ramp_length, r_ramp, g_ramp, b_ramp);
- freeSavedGammaRamps();
}
// decDisplay();
XCloseDisplay(disp);
@@ -443,21 +451,19 @@
throwException(env, "Could not open display");
return;
}
- int gamma_ramp_length = getGammaRampLengthOfDisplay(disp, screen);
- if (gamma_ramp_length == 0) {
+ freeCurrentGamma();
+ current_gamma_ramp_length = getGammaRampLengthOfDisplay(disp, screen);
+ if (current_gamma_ramp_length == 0) {
throwException(env, "Gamma ramp not supported");
return;
}
const float *gamma_ramp = (const float *)(*env)->GetDirectBufferAddress(env, gamma_ramp_buffer);
- unsigned short *ramp;
- ramp = (unsigned short *)malloc(sizeof(unsigned short)*gamma_ramp_length);
+ current_ramp = (unsigned short *)malloc(sizeof(unsigned short)*current_gamma_ramp_length);
int i;
- for (i = 0; i < gamma_ramp_length; i++) {
+ for (i = 0; i < current_gamma_ramp_length; i++) {
float scaled_gamma = gamma_ramp[i]*0xffff;
- ramp[i] = (unsigned short)round(scaled_gamma);
- }
- if (XF86VidModeSetGammaRamp(disp, screen, gamma_ramp_length, ramp, ramp, ramp) == False) {
- throwException(env, "Could not set gamma ramp.");
+ current_ramp[i] = (unsigned short)round(scaled_gamma);
}
+ setCurrentGamma(disp, screen, env);
XCloseDisplay(disp);
}
Index: org_lwjgl_opengl_Display.c
===================================================================
RCS file: /cvsroot/java-game-lib/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- org_lwjgl_opengl_Display.c 22 Sep 2004 09:28:09 -0000 1.4
+++ org_lwjgl_opengl_Display.c 22 Sep 2004 19:25:16 -0000 1.5
@@ -207,7 +207,7 @@
updateInputGrab();
if (current_window_mode == FULLSCREEN_NETWM) {
XIconifyWindow(getDisplay(), getCurrentWindow(), getCurrentScreen());
- temporaryResetMode(getCurrentScreen());
+ resetDisplayMode(getCurrentScreen());
}
return true;
}
@@ -664,7 +664,7 @@
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_resetDisplayMode(JNIEnv *env, jclass clazz) {
- resetDisplayMode(env, getCurrentScreen());
+ resetDisplayMode(getCurrentScreen());
}
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Display_getGammaRampLength(JNIEnv *env, jclass clazz) {
|