Added java debug output to linux display.c
This commit is contained in:
parent
5ee6565bb5
commit
7e4fc4c3b9
|
@ -80,7 +80,7 @@ void printfDebugJava(JNIEnv *env, const char *format, ...) {
|
|||
buffer[BUFFER_SIZE - 1] = '\0';
|
||||
jstring str = (*env)->NewStringUTF(env, buffer);
|
||||
jclass org_lwjgl_Sys_class = (*env)->FindClass(env, "org/lwjgl/Sys");
|
||||
jmethodID log_method = (*env)->GetMethodID(env, org_lwjgl_Sys_class, "log", "(Ljava/lang/String;)V");
|
||||
jmethodID log_method = (*env)->GetStaticMethodID(env, org_lwjgl_Sys_class, "log", "(Ljava/lang/String;)V");
|
||||
(*env)->CallStaticVoidMethod(env, org_lwjgl_Sys_class, log_method, str);
|
||||
}
|
||||
va_end(ap);
|
||||
|
|
|
@ -53,8 +53,7 @@
|
|||
/*
|
||||
* release input (keyboard, mouse)
|
||||
*/
|
||||
extern bool releaseInput(void);
|
||||
extern void handleMessages(void);
|
||||
extern void handleMessages(JNIEnv *env);
|
||||
|
||||
extern bool checkXError(JNIEnv *env);
|
||||
extern Atom getWarpAtom(void);
|
||||
|
|
|
@ -87,54 +87,54 @@ extension getCurrentDisplayModeExtension(void) {
|
|||
return current_extension;
|
||||
}
|
||||
|
||||
static bool getXF86VidModeVersion(Display *disp, int *major, int *minor) {
|
||||
static bool getXF86VidModeVersion(JNIEnv *env, Display *disp, int *major, int *minor) {
|
||||
int event_base, error_base;
|
||||
|
||||
if (!XF86VidModeQueryExtension(disp, &event_base, &error_base)) {
|
||||
printfDebug("XF86VidMode extension not available\n");
|
||||
printfDebugJava(env, "XF86VidMode extension not available");
|
||||
return false;
|
||||
}
|
||||
if (!XF86VidModeQueryVersion(disp, major, minor)) {
|
||||
printfDebug("Could not query XF86VidMode version\n");
|
||||
printfDebugJava(env, "Could not query XF86VidMode version");
|
||||
return false;
|
||||
}
|
||||
printfDebug("XF86VidMode extension version %i.%i\n", *major, *minor);
|
||||
printfDebugJava(env, "XF86VidMode extension version %i.%i", *major, *minor);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool getXrandrVersion(Display *disp, int *major, int *minor) {
|
||||
static bool getXrandrVersion(JNIEnv *env, Display *disp, int *major, int *minor) {
|
||||
int event_base, error_base;
|
||||
|
||||
if (!XRRQueryExtension(disp, &event_base, &error_base)) {
|
||||
printfDebug("Xrandr extension not available\n");
|
||||
printfDebugJava(env, "Xrandr extension not available");
|
||||
return false;
|
||||
}
|
||||
if (!XRRQueryVersion(disp, major, minor)) {
|
||||
printfDebug("Could not query Xrandr version\n");
|
||||
printfDebugJava(env, "Could not query Xrandr version");
|
||||
return false;
|
||||
}
|
||||
printfDebug("Xrandr extension version %i.%i\n", *major, *minor);
|
||||
printfDebugJava(env, "Xrandr extension version %i.%i", *major, *minor);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool isXrandrSupported(Display *disp) {
|
||||
static bool isXrandrSupported(JNIEnv *env, Display *disp) {
|
||||
int major, minor;
|
||||
if (!getXrandrVersion(disp, &major, &minor))
|
||||
if (!getXrandrVersion(env, disp, &major, &minor))
|
||||
return false;
|
||||
return major >= 1;
|
||||
}
|
||||
|
||||
static bool isXF86VidModeSupported(Display *disp) {
|
||||
static bool isXF86VidModeSupported(JNIEnv *env, Display *disp) {
|
||||
int minor_ver, major_ver;
|
||||
if (!getXF86VidModeVersion(disp, &major_ver, &minor_ver))
|
||||
if (!getXF86VidModeVersion(env, disp, &major_ver, &minor_ver))
|
||||
return false;
|
||||
return major_ver >= 2;
|
||||
}
|
||||
|
||||
static extension getBestDisplayModeExtension(Display *disp) {
|
||||
if (isXrandrSupported(disp))
|
||||
static extension getBestDisplayModeExtension(JNIEnv *env, Display *disp) {
|
||||
if (isXrandrSupported(env, disp))
|
||||
return XRANDR;
|
||||
else if (isXF86VidModeSupported(disp))
|
||||
else if (isXF86VidModeSupported(env, disp))
|
||||
return XF86VIDMODE;
|
||||
else
|
||||
return NONE;
|
||||
|
@ -225,29 +225,29 @@ static bool setXrandrMode(Display *disp, int screen, mode_info *mode) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool setMode(Display *disp, int screen, int width, int height, int freq, bool temporary) {
|
||||
static bool setMode(JNIEnv *env, Display *disp, int screen, int width, int height, int freq, bool temporary) {
|
||||
if (current_extension == NONE)
|
||||
return false;
|
||||
int num_modes, i;
|
||||
mode_info *avail_modes = getDisplayModes(disp, screen, &num_modes);
|
||||
if (avail_modes == NULL) {
|
||||
printfDebug("Could not get display modes\n");
|
||||
printfDebugJava(env, "Could not get display modes");
|
||||
return false;
|
||||
}
|
||||
bool result = false;
|
||||
for ( i = 0; i < num_modes; ++i ) {
|
||||
printfDebug("Mode %d: %dx%d @%d\n", i, avail_modes[i].width, avail_modes[i].height, avail_modes[i].freq);
|
||||
printfDebugJava(env, "Mode %d: %dx%d @%d", i, avail_modes[i].width, avail_modes[i].height, avail_modes[i].freq);
|
||||
if (avail_modes[i].width == width && avail_modes[i].height == height && avail_modes[i].freq == freq) {
|
||||
switch (current_extension) {
|
||||
case XF86VIDMODE:
|
||||
if (!setXF86VidModeMode(disp, screen, &avail_modes[i])) {
|
||||
printfDebug("Could not switch mode\n");
|
||||
printfDebugJava(env, "Could not switch mode");
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case XRANDR:
|
||||
if (!setXrandrMode(disp, screen, &avail_modes[i])) {
|
||||
printfDebug("Could not switch mode\n");
|
||||
printfDebugJava(env, "Could not switch mode");
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
@ -279,26 +279,26 @@ static void freeSavedGammaRamps() {
|
|||
saved_gamma_ramp_length = 0;
|
||||
}
|
||||
|
||||
static int getGammaRampLengthOfDisplay(Display *disp, int screen) {
|
||||
static int getGammaRampLengthOfDisplay(JNIEnv *env, Display *disp, int screen) {
|
||||
int ramp_size;
|
||||
if (!isXF86VidModeSupported(disp)) {
|
||||
printfDebug("XF86VidMode extension version >= 2 not found\n");
|
||||
if (!isXF86VidModeSupported(env, disp)) {
|
||||
printfDebugJava(env, "XF86VidMode extension version >= 2 not found");
|
||||
return 0;
|
||||
}
|
||||
if (XF86VidModeGetGammaRampSize(disp, screen, &ramp_size) == False) {
|
||||
printfDebug("XF86VidModeGetGammaRampSize call failed\n");
|
||||
printfDebugJava(env, "XF86VidModeGetGammaRampSize call failed");
|
||||
return 0;
|
||||
}
|
||||
return ramp_size;
|
||||
}
|
||||
|
||||
int getGammaRampLength(int screen) {
|
||||
int getGammaRampLength(JNIEnv *env, int screen) {
|
||||
Display *disp = XOpenDisplay(NULL);
|
||||
if (disp == NULL) {
|
||||
printfDebug("Could not open display");
|
||||
printfDebugJava(env, "Could not open display");
|
||||
return 0;
|
||||
}
|
||||
int length = getGammaRampLengthOfDisplay(disp, screen);
|
||||
int length = getGammaRampLengthOfDisplay(env, disp, screen);
|
||||
XCloseDisplay(disp);
|
||||
return length;
|
||||
}
|
||||
|
@ -312,7 +312,7 @@ jobject initDisplay(JNIEnv *env, int screen) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
current_extension = getBestDisplayModeExtension(disp);
|
||||
current_extension = getBestDisplayModeExtension(env, disp);
|
||||
if (current_extension == NONE) {
|
||||
throwException(env, "No display mode extension is available");
|
||||
XCloseDisplay(disp);
|
||||
|
@ -328,7 +328,7 @@ jobject initDisplay(JNIEnv *env, int screen) {
|
|||
saved_height = current_height = avail_modes[0].height;
|
||||
saved_freq = current_freq = avail_modes[0].freq;
|
||||
int bpp = XDefaultDepth(disp, screen);
|
||||
printfDebug("Original display dimensions: width %d, height %d freq %d\n", saved_width, saved_height, saved_freq);
|
||||
printfDebugJava(env, "Original display dimensions: width %d, height %d freq %d", saved_width, saved_height, saved_freq);
|
||||
jclass jclass_DisplayMode = (*env)->FindClass(env, "org/lwjgl/opengl/DisplayMode");
|
||||
jmethodID ctor = (*env)->GetMethodID(env, jclass_DisplayMode, "<init>", "(IIII)V");
|
||||
jobject newMode = (*env)->NewObject(env, jclass_DisplayMode, ctor, saved_width, saved_height, bpp, saved_freq);
|
||||
|
@ -336,7 +336,7 @@ jobject initDisplay(JNIEnv *env, int screen) {
|
|||
free(avail_modes);
|
||||
|
||||
/* Fetch the current gamma ramp */
|
||||
saved_gamma_ramp_length = getGammaRampLengthOfDisplay(disp, screen);
|
||||
saved_gamma_ramp_length = getGammaRampLengthOfDisplay(env, disp, screen);
|
||||
if (saved_gamma_ramp_length > 0) {
|
||||
r_ramp = (unsigned short *)malloc(sizeof(unsigned short)*saved_gamma_ramp_length);
|
||||
g_ramp = (unsigned short *)malloc(sizeof(unsigned short)*saved_gamma_ramp_length);
|
||||
|
@ -363,18 +363,18 @@ static void setCurrentGamma(Display *disp, int screen, JNIEnv *env) {
|
|||
if (env != NULL)
|
||||
throwException(env, "Could not set gamma ramp.");
|
||||
else
|
||||
printfDebug("Could not set gamma ramp\n");
|
||||
printfDebugJava(env, "Could not set gamma ramp");
|
||||
}
|
||||
}
|
||||
|
||||
void temporaryRestoreMode(int screen) {
|
||||
void temporaryRestoreMode(JNIEnv *env, int screen) {
|
||||
Display *disp = XOpenDisplay(NULL);
|
||||
if (disp == NULL) {
|
||||
printfDebug("Could not open display");
|
||||
printfDebugJava(env, "Could not open display");
|
||||
return;
|
||||
}
|
||||
if (!setMode(disp, screen, current_width, current_height, current_freq, false))
|
||||
printfDebug("Could not restore mode\n");
|
||||
if (!setMode(env, disp, screen, current_width, current_height, current_freq, false))
|
||||
printfDebugJava(env, "Could not restore mode");
|
||||
setCurrentGamma(disp, screen, NULL);
|
||||
XCloseDisplay(disp);
|
||||
// Don't propagate error to caller
|
||||
|
@ -397,17 +397,17 @@ void switchDisplayMode(JNIEnv * env, jobject mode, int screen) {
|
|||
throwException(env, "Could not open display");
|
||||
return;
|
||||
}
|
||||
if (!setMode(disp, screen, width, height, freq, false))
|
||||
if (!setMode(env, disp, screen, width, height, freq, false))
|
||||
throwException(env, "Could not switch mode.");
|
||||
XCloseDisplay(disp);
|
||||
}
|
||||
|
||||
void resetDisplayMode(int screen, bool temporary) {
|
||||
void resetDisplayMode(JNIEnv *env, int screen, bool temporary) {
|
||||
Display *disp = XOpenDisplay(NULL);
|
||||
if (disp == NULL)
|
||||
return;
|
||||
if (!setMode(disp, screen, saved_width, saved_height, saved_freq, temporary)) {
|
||||
printfDebug("Failed to reset mode");
|
||||
if (!setMode(env, disp, screen, saved_width, saved_height, saved_freq, temporary)) {
|
||||
printfDebugJava(env, "Failed to reset mode");
|
||||
}
|
||||
if (saved_gamma_ramp_length > 0) {
|
||||
XF86VidModeSetGammaRamp(disp, screen, saved_gamma_ramp_length, r_ramp, g_ramp, b_ramp);
|
||||
|
@ -428,7 +428,7 @@ jobjectArray getAvailableDisplayModes(JNIEnv * env, int screen) {
|
|||
int bpp = XDefaultDepth(disp, screen);
|
||||
avail_modes = getDisplayModes(disp, screen, &num_modes);
|
||||
if (avail_modes == NULL) {
|
||||
printfDebug("Could not get display modes\n");
|
||||
printfDebugJava(env, "Could not get display modes");
|
||||
XCloseDisplay(disp);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -453,7 +453,7 @@ void setGammaRamp(JNIEnv *env, jobject gamma_ramp_buffer, int screen) {
|
|||
return;
|
||||
}
|
||||
freeCurrentGamma();
|
||||
current_gamma_ramp_length = getGammaRampLengthOfDisplay(disp, screen);
|
||||
current_gamma_ramp_length = getGammaRampLengthOfDisplay(env, disp, screen);
|
||||
if (current_gamma_ramp_length == 0) {
|
||||
throwException(env, "Gamma ramp not supported");
|
||||
return;
|
||||
|
|
|
@ -51,11 +51,11 @@ extern int getScreenModeWidth(void);
|
|||
extern int getScreenModeHeight(void);
|
||||
extern jobject initDisplay(JNIEnv *env, int screen);
|
||||
extern void switchDisplayMode(JNIEnv * env, jobject mode, int screen);
|
||||
extern void resetDisplayMode(int screen, bool temporary);
|
||||
extern void resetDisplayMode(JNIEnv *env, int screen, bool temporary);
|
||||
extern jobjectArray getAvailableDisplayModes(JNIEnv * env, int screen);
|
||||
extern int getGammaRampLength(int screen);
|
||||
extern int getGammaRampLength(JNIEnv *env, int screen);
|
||||
extern void setGammaRamp(JNIEnv *env, jobject gamma_ramp_buffer, int screen);
|
||||
extern extension getCurrentDisplayModeExtension();
|
||||
extern void temporaryRestoreMode(int screen);
|
||||
extern void temporaryRestoreMode(JNIEnv *env, int screen);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -285,12 +285,12 @@ void handleKeyEvent(XKeyEvent *event) {
|
|||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_pollKeyboard(JNIEnv * env, jobject this, jobject buffer) {
|
||||
unsigned char *new_keyboard_buffer = (unsigned char *)(*env)->GetDirectBufferAddress(env, buffer);
|
||||
handleMessages();
|
||||
handleMessages(env);
|
||||
memcpy(new_keyboard_buffer, key_buf, KEYBOARD_SIZE*sizeof(unsigned char));
|
||||
}
|
||||
|
||||
JNIEXPORT int JNICALL Java_org_lwjgl_opengl_LinuxDisplay_readKeyboard(JNIEnv * env, jobject this, jobject buffer, jint buffer_position) {
|
||||
handleMessages();
|
||||
handleMessages(env);
|
||||
jint* buffer_ptr = (jint *)(*env)->GetDirectBufferAddress(env, buffer);
|
||||
int buffer_size = ((*env)->GetDirectBufferCapacity(env, buffer))/sizeof(jint) - buffer_position;
|
||||
return copyEvents(&event_queue, buffer_ptr + buffer_position, buffer_size);
|
||||
|
|
|
@ -365,7 +365,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_pollMouse(JNIEnv * env
|
|||
int coords_length = (*env)->GetDirectBufferCapacity(env, coord_buffer_obj);
|
||||
unsigned char *buttons_buffer = (unsigned char *)(*env)->GetDirectBufferAddress(env, button_buffer_obj);
|
||||
int buttons_length = (*env)->GetDirectBufferCapacity(env, button_buffer_obj);
|
||||
handleMessages();
|
||||
handleMessages(env);
|
||||
if (coords_length < 3) {
|
||||
printfDebug("ERROR: Not enough space in coords array: %d < 3\n", coords_length);
|
||||
return;
|
||||
|
@ -394,7 +394,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_enableMouseBuffer(JNIE
|
|||
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_readMouse(JNIEnv *env, jobject this, jobject buffer, jint buffer_position) {
|
||||
jint* buffer_ptr = (jint *)(*env)->GetDirectBufferAddress(env, buffer);
|
||||
int buffer_size = ((*env)->GetDirectBufferCapacity(env, buffer))/sizeof(jint) - buffer_position;
|
||||
handleMessages();
|
||||
handleMessages(env);
|
||||
return copyEvents(&event_queue, buffer_ptr + buffer_position, buffer_size);
|
||||
}
|
||||
|
||||
|
|
|
@ -199,7 +199,7 @@ static void setDecorations(int dec) {
|
|||
XChangeProperty (getDisplay(), getCurrentWindow(), motif_hints_atom, motif_hints_atom, 32, PropModeReplace, (unsigned char *)&motif_hints, sizeof(MotifWmHints)/sizeof(long));
|
||||
}
|
||||
|
||||
bool releaseInput(void) {
|
||||
static bool releaseInput(JNIEnv *env) {
|
||||
if (isLegacyFullscreen() || input_released)
|
||||
return false;
|
||||
input_released = true;
|
||||
|
@ -207,19 +207,19 @@ bool releaseInput(void) {
|
|||
updateInputGrab();
|
||||
if (current_window_mode == FULLSCREEN_NETWM) {
|
||||
XIconifyWindow(getDisplay(), getCurrentWindow(), getCurrentScreen());
|
||||
resetDisplayMode(getCurrentScreen(), true);
|
||||
resetDisplayMode(env, getCurrentScreen(), true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void acquireInput(void) {
|
||||
static void acquireInput(JNIEnv *env) {
|
||||
if (isLegacyFullscreen() || !input_released)
|
||||
return;
|
||||
input_released = false;
|
||||
setRepeatMode(AutoRepeatModeOff);
|
||||
updateInputGrab();
|
||||
if (current_window_mode == FULLSCREEN_NETWM) {
|
||||
temporaryRestoreMode(getCurrentScreen());
|
||||
temporaryRestoreMode(env, getCurrentScreen());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -246,20 +246,20 @@ void setGrab(bool new_grab) {
|
|||
}
|
||||
}
|
||||
|
||||
static void checkInput(void) {
|
||||
static void checkInput(JNIEnv *env) {
|
||||
Window win;
|
||||
int revert_mode;
|
||||
XGetInputFocus(getDisplay(), &win, &revert_mode);
|
||||
if (win == current_win) {
|
||||
acquireInput();
|
||||
acquireInput(env);
|
||||
focused = true;
|
||||
} else {
|
||||
releaseInput();
|
||||
releaseInput(env);
|
||||
focused = false;
|
||||
}
|
||||
}
|
||||
|
||||
void handleMessages(void) {
|
||||
void handleMessages(JNIEnv *env) {
|
||||
XEvent event;
|
||||
/* Window win;
|
||||
int revert_mode;*/
|
||||
|
@ -310,7 +310,7 @@ void handleMessages(void) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
checkInput();
|
||||
checkInput(env);
|
||||
}
|
||||
|
||||
static void setWindowTitle(const char *title) {
|
||||
|
@ -439,7 +439,7 @@ int getWindowHeight(void) {
|
|||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_update
|
||||
(JNIEnv *env, jobject this)
|
||||
{
|
||||
handleMessages();
|
||||
handleMessages(env);
|
||||
}
|
||||
|
||||
static bool makeCurrent(void) {
|
||||
|
@ -676,11 +676,11 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_switchDisplayMode(JNIE
|
|||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_resetDisplayMode(JNIEnv *env, jobject this) {
|
||||
resetDisplayMode(getCurrentScreen(), false);
|
||||
resetDisplayMode(env, getCurrentScreen(), false);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_getGammaRampLength(JNIEnv *env, jobject this) {
|
||||
return (jint)getGammaRampLength(getCurrentScreen());
|
||||
return (jint)getGammaRampLength(env, getCurrentScreen());
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_setGammaRamp(JNIEnv *env, jobject this, jobject gamma_buffer) {
|
||||
|
|
Loading…
Reference in New Issue