Linux: let exceptions from display.c propagate to LinuxDisplay.java
This commit is contained in:
parent
b6dd18fc7d
commit
e2ee957f0b
|
@ -260,11 +260,13 @@ final class LinuxDisplay implements DisplayImplementation {
|
||||||
lockAWT();
|
lockAWT();
|
||||||
try {
|
try {
|
||||||
nResetDisplayMode(current_displaymode_extension, saved_gamma, saved_mode);
|
nResetDisplayMode(current_displaymode_extension, saved_gamma, saved_mode);
|
||||||
|
} catch (LWJGLException e) {
|
||||||
|
LWJGLUtil.log("Caught exception while resetting mode: " + e);
|
||||||
} finally {
|
} finally {
|
||||||
unlockAWT();
|
unlockAWT();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static native void nResetDisplayMode(int extension, ByteBuffer gamma_ramp, DisplayMode saved_mode);
|
private static native void nResetDisplayMode(int extension, ByteBuffer gamma_ramp, DisplayMode saved_mode) throws LWJGLException;
|
||||||
|
|
||||||
public int getGammaRampLength() {
|
public int getGammaRampLength() {
|
||||||
lockAWT();
|
lockAWT();
|
||||||
|
@ -383,10 +385,14 @@ final class LinuxDisplay implements DisplayImplementation {
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
lockAWT();
|
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);
|
||||||
|
} catch (LWJGLException e) {
|
||||||
|
LWJGLUtil.log("Caught exception while processing messages: " + e);
|
||||||
|
}
|
||||||
unlockAWT();
|
unlockAWT();
|
||||||
}
|
}
|
||||||
private static native void nUpdate(int extension, int current_window_mode, ByteBuffer saved_gamma, ByteBuffer current_gamma, DisplayMode saved_mode);
|
private static native void nUpdate(int extension, int current_window_mode, ByteBuffer saved_gamma, ByteBuffer current_gamma, DisplayMode saved_mode) throws LWJGLException;
|
||||||
|
|
||||||
public void reshape(int x, int y, int width, int height) {
|
public void reshape(int x, int y, int width, int height) {
|
||||||
lockAWT();
|
lockAWT();
|
||||||
|
|
|
@ -319,30 +319,24 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetCurrentGammaRam
|
||||||
return ramp_buffer;
|
return ramp_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setGamma(JNIEnv *env, Display *disp, int screen, jobject ramp_buffer, bool throw_on_error) {
|
static void setGamma(JNIEnv *env, Display *disp, int screen, jobject ramp_buffer) {
|
||||||
unsigned short *ramp_ptr = (unsigned short *)(*env)->GetDirectBufferAddress(env, ramp_buffer);
|
unsigned short *ramp_ptr = (unsigned short *)(*env)->GetDirectBufferAddress(env, ramp_buffer);
|
||||||
jlong capacity = (*env)->GetDirectBufferCapacity(env, ramp_buffer);
|
jlong capacity = (*env)->GetDirectBufferCapacity(env, ramp_buffer);
|
||||||
int size = capacity/(sizeof(unsigned short)*3);
|
int size = capacity/(sizeof(unsigned short)*3);
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
return;
|
return;
|
||||||
if (XF86VidModeSetGammaRamp(disp, screen, size, ramp_ptr, ramp_ptr + size, ramp_ptr + size*2) == False) {
|
if (XF86VidModeSetGammaRamp(disp, screen, size, ramp_ptr, ramp_ptr + size, ramp_ptr + size*2) == False) {
|
||||||
if (throw_on_error)
|
|
||||||
throwException(env, "Could not set gamma ramp.");
|
throwException(env, "Could not set gamma ramp.");
|
||||||
else
|
|
||||||
printfDebugJava(env, "Could not set gamma ramp.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setGammaRamp(JNIEnv *env, jobject gamma_ramp_buffer, int screen, bool throw_on_error) {
|
static void setGammaRamp(JNIEnv *env, jobject gamma_ramp_buffer, int screen) {
|
||||||
Display * disp = XOpenDisplay(NULL);
|
Display * disp = XOpenDisplay(NULL);
|
||||||
if (disp == NULL) {
|
if (disp == NULL) {
|
||||||
if (throw_on_error)
|
|
||||||
throwException(env, "Could not open display");
|
throwException(env, "Could not open display");
|
||||||
else
|
|
||||||
printfDebugJava(env, "Could not open display");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setGamma(env, disp, screen, gamma_ramp_buffer, throw_on_error);
|
setGamma(env, disp, screen, gamma_ramp_buffer);
|
||||||
XCloseDisplay(disp);
|
XCloseDisplay(disp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,15 +350,12 @@ void temporaryRestoreMode(JNIEnv *env, int screen, jint extension, jobject saved
|
||||||
printfDebugJava(env, "Could not restore mode");
|
printfDebugJava(env, "Could not restore mode");
|
||||||
XCloseDisplay(disp);
|
XCloseDisplay(disp);
|
||||||
// Don't propagate error to caller
|
// Don't propagate error to caller
|
||||||
setGammaRamp(env, saved_gamma_ramp, screen, false);
|
setGammaRamp(env, saved_gamma_ramp, screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool switchDisplayMode(JNIEnv * env, int screen, jint extension, jobject mode, bool temporary, bool throw_on_error) {
|
static bool switchDisplayMode(JNIEnv * env, int screen, jint extension, jobject mode, bool temporary) {
|
||||||
if (mode == NULL) {
|
if (mode == NULL) {
|
||||||
if (throw_on_error)
|
|
||||||
throwException(env, "mode must be non-null");
|
throwException(env, "mode must be non-null");
|
||||||
else
|
|
||||||
printfDebugJava(env, "Ignored null mode");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
jclass cls_displayMode = (*env)->GetObjectClass(env, mode);
|
jclass cls_displayMode = (*env)->GetObjectClass(env, mode);
|
||||||
|
@ -376,18 +367,12 @@ static bool switchDisplayMode(JNIEnv * env, int screen, jint extension, jobject
|
||||||
int freq = (*env)->GetIntField(env, mode, fid_freq);
|
int freq = (*env)->GetIntField(env, mode, fid_freq);
|
||||||
Display *disp = XOpenDisplay(NULL);
|
Display *disp = XOpenDisplay(NULL);
|
||||||
if (disp == NULL) {
|
if (disp == NULL) {
|
||||||
if (throw_on_error)
|
|
||||||
throwException(env, "Could not open display");
|
throwException(env, "Could not open display");
|
||||||
else
|
|
||||||
printfDebugJava(env, "Could not open display");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!setMode(env, disp, screen, extension, width, height, freq, temporary)) {
|
if (!setMode(env, disp, screen, extension, width, height, freq, temporary)) {
|
||||||
XCloseDisplay(disp);
|
XCloseDisplay(disp);
|
||||||
if (throw_on_error)
|
|
||||||
throwException(env, "Could not switch mode.");
|
throwException(env, "Could not switch mode.");
|
||||||
else
|
|
||||||
printfDebugJava(env, "Could not switch mode");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
XCloseDisplay(disp);
|
XCloseDisplay(disp);
|
||||||
|
@ -395,9 +380,9 @@ static bool switchDisplayMode(JNIEnv * env, int screen, jint extension, jobject
|
||||||
}
|
}
|
||||||
|
|
||||||
void resetDisplayMode(JNIEnv *env, int screen, jint extension, jobject gamma_ramp, jobject saved_mode, bool temporary) {
|
void resetDisplayMode(JNIEnv *env, int screen, jint extension, jobject gamma_ramp, jobject saved_mode, bool temporary) {
|
||||||
if (!switchDisplayMode(env, screen, extension, saved_mode, temporary, false))
|
if (!switchDisplayMode(env, screen, extension, saved_mode, temporary))
|
||||||
return;
|
return;
|
||||||
setGammaRamp(env, gamma_ramp, screen, false);
|
setGammaRamp(env, gamma_ramp, screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static jobjectArray getAvailableDisplayModes(JNIEnv * env, Display *disp, int screen, jint extension) {
|
static jobjectArray getAvailableDisplayModes(JNIEnv * env, Display *disp, int screen, jint extension) {
|
||||||
|
@ -428,7 +413,7 @@ 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) {
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nSwitchDisplayMode(JNIEnv *env, jclass clazz, jint extension, jobject mode) {
|
||||||
switchDisplayMode(env, getCurrentScreen(), extension, mode, false, true);
|
switchDisplayMode(env, getCurrentScreen(), extension, mode, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nResetDisplayMode(JNIEnv *env, jclass clazz, jint extension, jobject gamma_ramp, jobject saved_mode) {
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nResetDisplayMode(JNIEnv *env, jclass clazz, jint extension, jobject gamma_ramp, jobject saved_mode) {
|
||||||
|
@ -440,6 +425,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) {
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nSetGammaRamp(JNIEnv *env, jclass clazz, jobject gamma_buffer) {
|
||||||
setGammaRamp(env, gamma_buffer, getCurrentScreen(), true);
|
setGammaRamp(env, gamma_buffer, getCurrentScreen());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue