Added java debug to all of linux native code

This commit is contained in:
Elias Naur 2004-12-11 20:18:18 +00:00
parent 7e4fc4c3b9
commit d1fb731587
3 changed files with 32 additions and 33 deletions

View File

@ -59,10 +59,10 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTimerResolution
return 1000000; return 1000000;
} }
static long queryTime(void) { static long queryTime(JNIEnv *env) {
struct timeval tv; struct timeval tv;
if (gettimeofday(&tv, NULL) == -1) { if (gettimeofday(&tv, NULL) == -1) {
printfDebug("Could not read current time\n"); printfDebugJava(env, "Could not read current time");
} }
long result = tv.tv_sec * 1000000l + tv.tv_usec; long result = tv.tv_sec * 1000000l + tv.tv_usec;
@ -81,7 +81,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setDebug(JNIEnv *env, jclass clazz, jb
JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_ngetTime JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_ngetTime
(JNIEnv * env, jclass clazz) (JNIEnv * env, jclass clazz)
{ {
hires_timer = queryTime(); hires_timer = queryTime(env);
return (jlong) hires_timer; return (jlong) hires_timer;
} }
@ -101,7 +101,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setProcessPriority
// Reset scheduler to normal // Reset scheduler to normal
sched_pri.sched_priority = 0; sched_pri.sched_priority = 0;
if (sched_setscheduler(0, SCHED_OTHER, &sched_pri) != 0) { if (sched_setscheduler(0, SCHED_OTHER, &sched_pri) != 0) {
printfDebug("Could not set realtime priority\n"); printfDebugJava(env, "Could not set realtime priority");
return; return;
} }
} }
@ -111,12 +111,12 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setProcessPriority
min_pri = sched_get_priority_min(SCHED_FIFO); min_pri = sched_get_priority_min(SCHED_FIFO);
max_pri = sched_get_priority_max(SCHED_FIFO); max_pri = sched_get_priority_max(SCHED_FIFO);
if (min_pri == -1 || max_pri == -1) { if (min_pri == -1 || max_pri == -1) {
printfDebug("Failed to set realtime priority\n"); printfDebugJava(env, "Failed to set realtime priority");
return; return;
} }
sched_pri.sched_priority = (max_pri + min_pri)/2; sched_pri.sched_priority = (max_pri + min_pri)/2;
if (sched_setscheduler(0, SCHED_FIFO, &sched_pri) != 0) { if (sched_setscheduler(0, SCHED_FIFO, &sched_pri) != 0) {
printfDebug("Could not set realtime priority\n"); printfDebugJava(env, "Could not set realtime priority");
return; return;
} }
return; return;
@ -134,7 +134,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_setProcessPriority
} }
if (setpriority(PRIO_PROCESS, 0, linux_priority) == -1) { if (setpriority(PRIO_PROCESS, 0, linux_priority) == -1) {
printfDebug("Failed to set priority.\n"); printfDebugJava(env, "Failed to set priority.");
} }
} }
@ -143,7 +143,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nAlert(JNIEnv * env, jclass clazz, jst
char * eMessageText = GetStringNativeChars(env, message); char * eMessageText = GetStringNativeChars(env, message);
char * cTitleBarText = GetStringNativeChars(env, title); char * cTitleBarText = GetStringNativeChars(env, title);
printfDebug("*** Alert ***%s\n%s\n", cTitleBarText, eMessageText); printfDebugJava(env, "*** Alert ***%s\n%s\n", cTitleBarText, eMessageText);
free(eMessageText); free(eMessageText);
free(cTitleBarText); free(cTitleBarText);

View File

@ -110,10 +110,10 @@ static void resetCursor(int x, int y) {
last_y = y; last_y = y;
} }
static bool blankCursor(void) { static bool blankCursor(JNIEnv *env) {
unsigned int best_width, best_height; unsigned int best_width, best_height;
if (XQueryBestCursor(getDisplay(), getCurrentWindow(), 1, 1, &best_width, &best_height) == 0) { if (XQueryBestCursor(getDisplay(), getCurrentWindow(), 1, 1, &best_width, &best_height) == 0) {
printfDebug("Could not query best cursor size\n"); throwException(env, "Could not query best cursor size");
return false; return false;
} }
Pixmap mask = XCreatePixmap(getDisplay(), getCurrentWindow(), best_width, best_height, 1); Pixmap mask = XCreatePixmap(getDisplay(), getCurrentWindow(), best_width, best_height, 1);
@ -259,9 +259,8 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_createMouse
reset(); reset();
for (i = 0; i < NUM_BUTTONS; i++) for (i = 0; i < NUM_BUTTONS; i++)
buttons[i] = 0; buttons[i] = 0;
if (!blankCursor()) { if (!blankCursor(env)) {
decDisplay(); decDisplay();
throwException(env, "Could not create blank cursor");
return; return;
} }
current_cursor = None; current_cursor = None;
@ -367,7 +366,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_pollMouse(JNIEnv * env
int buttons_length = (*env)->GetDirectBufferCapacity(env, button_buffer_obj); int buttons_length = (*env)->GetDirectBufferCapacity(env, button_buffer_obj);
handleMessages(env); handleMessages(env);
if (coords_length < 3) { if (coords_length < 3) {
printfDebug("ERROR: Not enough space in coords array: %d < 3\n", coords_length); printfDebugJava(env, "ERROR: Not enough space in coords array: %d < 3", coords_length);
return; return;
} }
if (isGrabbed()) { if (isGrabbed()) {

View File

@ -115,7 +115,7 @@ bool checkXError(JNIEnv *env) {
if (env != NULL) if (env != NULL)
throwException(env, error_message); throwException(env, error_message);
else else
printfDebug(error_message); printfDebugJava(env, error_message);
return false; return false;
} else } else
return true; return true;
@ -145,7 +145,7 @@ Display *incDisplay(JNIEnv *env) {
if (env != NULL) if (env != NULL)
throwException(env, "Could not open X display connection"); throwException(env, "Could not open X display connection");
else else
printfDebug("Could not open X display connection\n"); printfDebugJava(env, "Could not open X display connection");
return NULL; return NULL;
} }
warp_atom = XInternAtom(display_connection, "_LWJGL_WARP", False); warp_atom = XInternAtom(display_connection, "_LWJGL_WARP", False);
@ -179,12 +179,12 @@ static void updateInputGrab(void) {
updateKeyboardGrab(); updateKeyboardGrab();
} }
static void setRepeatMode(int mode) { static void setRepeatMode(JNIEnv *env, int mode) {
XKeyboardControl repeat_mode; XKeyboardControl repeat_mode;
repeat_mode.auto_repeat_mode = mode; repeat_mode.auto_repeat_mode = mode;
Display *disp = XOpenDisplay(NULL); Display *disp = XOpenDisplay(NULL);
if (disp == NULL) { if (disp == NULL) {
printfDebug("Could not open display to set repeat mode\n"); printfDebugJava(env, "Could not open display to set repeat mode");
return; return;
} }
XChangeKeyboardControl(disp, KBAutoRepeatMode, &repeat_mode); XChangeKeyboardControl(disp, KBAutoRepeatMode, &repeat_mode);
@ -203,7 +203,7 @@ static bool releaseInput(JNIEnv *env) {
if (isLegacyFullscreen() || input_released) if (isLegacyFullscreen() || input_released)
return false; return false;
input_released = true; input_released = true;
setRepeatMode(AutoRepeatModeDefault); setRepeatMode(env, AutoRepeatModeDefault);
updateInputGrab(); updateInputGrab();
if (current_window_mode == FULLSCREEN_NETWM) { if (current_window_mode == FULLSCREEN_NETWM) {
XIconifyWindow(getDisplay(), getCurrentWindow(), getCurrentScreen()); XIconifyWindow(getDisplay(), getCurrentWindow(), getCurrentScreen());
@ -216,7 +216,7 @@ static void acquireInput(JNIEnv *env) {
if (isLegacyFullscreen() || !input_released) if (isLegacyFullscreen() || !input_released)
return; return;
input_released = false; input_released = false;
setRepeatMode(AutoRepeatModeOff); setRepeatMode(env, AutoRepeatModeOff);
updateInputGrab(); updateInputGrab();
if (current_window_mode == FULLSCREEN_NETWM) { if (current_window_mode == FULLSCREEN_NETWM) {
temporaryRestoreMode(env, getCurrentScreen()); temporaryRestoreMode(env, getCurrentScreen());
@ -323,15 +323,15 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_setTitle(JNIEnv * env,
free(title); free(title);
} }
static void destroyWindow(void) { static void destroyWindow(JNIEnv *env) {
if (USEGLX13) if (USEGLX13)
glXDestroyWindow(getDisplay(), glx_window); glXDestroyWindow(getDisplay(), glx_window);
XDestroyWindow(getDisplay(), current_win); XDestroyWindow(getDisplay(), current_win);
XFreeColormap(getDisplay(), cmap); XFreeColormap(getDisplay(), cmap);
setRepeatMode(AutoRepeatModeDefault); setRepeatMode(env, AutoRepeatModeDefault);
} }
static bool isNetWMFullscreenSupported() { static bool isNetWMFullscreenSupported(JNIEnv *env) {
unsigned long nitems; unsigned long nitems;
Atom actual_type; Atom actual_type;
int actual_format; int actual_format;
@ -340,7 +340,7 @@ static bool isNetWMFullscreenSupported() {
Atom netwm_supported_atom = XInternAtom(getDisplay(), "_NET_SUPPORTED", False); Atom netwm_supported_atom = XInternAtom(getDisplay(), "_NET_SUPPORTED", False);
int result = XGetWindowProperty(getDisplay(), RootWindow(getDisplay(), getCurrentScreen()), netwm_supported_atom, 0, 10000, False, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes_after, (void *)&supported_list); int result = XGetWindowProperty(getDisplay(), RootWindow(getDisplay(), getCurrentScreen()), netwm_supported_atom, 0, 10000, False, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes_after, (void *)&supported_list);
if (result != Success) { if (result != Success) {
printfDebug("Unable to query _NET_SUPPORTED window property\n"); printfDebugJava(env, "Unable to query _NET_SUPPORTED window property");
return false; return false;
} }
Atom fullscreen_atom = XInternAtom(getDisplay(), "_NET_WM_STATE_FULLSCREEN", False); Atom fullscreen_atom = XInternAtom(getDisplay(), "_NET_WM_STATE_FULLSCREEN", False);
@ -392,7 +392,7 @@ static bool createWindow(JNIEnv* env, int x, int y, int width, int height) {
XFreeColormap(getDisplay(), cmap); XFreeColormap(getDisplay(), cmap);
return false; return false;
} }
printfDebug("Created window\n"); printfDebugJava(env, "Created window");
current_win = win; current_win = win;
if (current_window_mode != WINDOWED || undecorated) { if (current_window_mode != WINDOWED || undecorated) {
// Use Motif decoration hint property and hope the window manager respects them // Use Motif decoration hint property and hope the window manager respects them
@ -416,9 +416,9 @@ static bool createWindow(JNIEnv* env, int x, int y, int width, int height) {
XMapRaised(getDisplay(), win); XMapRaised(getDisplay(), win);
waitMapped(win); waitMapped(win);
XClearWindow(getDisplay(), win); XClearWindow(getDisplay(), win);
setRepeatMode(AutoRepeatModeOff); setRepeatMode(env, AutoRepeatModeOff);
if (!checkXError(env)) { if (!checkXError(env)) {
destroyWindow(); destroyWindow(env);
return false; return false;
} }
return true; return true;
@ -575,7 +575,7 @@ static XVisualInfo *chooseVisualGLX(JNIEnv *env, jobject pixel_format) {
return glXChooseVisual(getDisplay(), getCurrentScreen(), attrib_list.attribs); return glXChooseVisual(getDisplay(), getCurrentScreen(), attrib_list.attribs);
} }
static void dumpVisualInfo(XVisualInfo *vis_info) { static void dumpVisualInfo(JNIEnv *env, XVisualInfo *vis_info) {
int alpha, depth, stencil, r, g, b; int alpha, depth, stencil, r, g, b;
int sample_buffers = 0; int sample_buffers = 0;
int samples = 0; int samples = 0;
@ -589,7 +589,7 @@ static void dumpVisualInfo(XVisualInfo *vis_info) {
glXGetConfig(getDisplay(), vis_info, GLX_SAMPLE_BUFFERS_ARB, &sample_buffers); glXGetConfig(getDisplay(), vis_info, GLX_SAMPLE_BUFFERS_ARB, &sample_buffers);
glXGetConfig(getDisplay(), vis_info, GLX_SAMPLES_ARB, &samples); glXGetConfig(getDisplay(), vis_info, GLX_SAMPLES_ARB, &samples);
} }
printfDebug("Pixel format info: r = %d, g = %d, b = %d, a = %d, depth = %d, stencil = %d, sample buffers = %d, samples = %d\n", r, g, b, alpha, depth, stencil, sample_buffers, samples); printfDebugJava(env, "Pixel format info: r = %d, g = %d, b = %d, a = %d, depth = %d, stencil = %d, sample buffers = %d, samples = %d", r, g, b, alpha, depth, stencil, sample_buffers, samples);
} }
static void destroyContext(void) { static void destroyContext(void) {
@ -645,7 +645,7 @@ static bool initWindowGLX(JNIEnv *env, jobject pixel_format) {
return false; return false;
} }
if (isDebugEnabled()) if (isDebugEnabled())
dumpVisualInfo(vis_info); dumpVisualInfo(env, vis_info);
context = glXCreateContext(getDisplay(), vis_info, NULL, True); context = glXCreateContext(getDisplay(), vis_info, NULL, True);
if (context == NULL) { if (context == NULL) {
XFree(vis_info); XFree(vis_info);
@ -726,7 +726,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_destroyContext(JNIEnv
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_createWindow(JNIEnv *env, jobject this, jobject mode, jboolean fullscreen, int x, int y) { JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_createWindow(JNIEnv *env, jobject this, jobject mode, jboolean fullscreen, int x, int y) {
bool current_fullscreen = fullscreen == JNI_TRUE; bool current_fullscreen = fullscreen == JNI_TRUE;
if (current_fullscreen) { if (current_fullscreen) {
if (getCurrentDisplayModeExtension() == XRANDR && isNetWMFullscreenSupported()) if (getCurrentDisplayModeExtension() == XRANDR && isNetWMFullscreenSupported(env))
current_window_mode = FULLSCREEN_NETWM; current_window_mode = FULLSCREEN_NETWM;
else else
current_window_mode = FULLSCREEN_LEGACY; current_window_mode = FULLSCREEN_LEGACY;
@ -742,17 +742,17 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_createWindow(JNIEnv *e
return; return;
} }
if (isDebugEnabled()) if (isDebugEnabled())
dumpVisualInfo(vis_info); dumpVisualInfo(env, vis_info);
if (USEGLX13) if (USEGLX13)
glx_window = glXCreateWindow(getDisplay(), configs[0], getCurrentWindow(), NULL); glx_window = glXCreateWindow(getDisplay(), configs[0], getCurrentWindow(), NULL);
if (!makeCurrent() || !checkXError(env)) { if (!makeCurrent() || !checkXError(env)) {
glXDestroyWindow(getDisplay(), glx_window); glXDestroyWindow(getDisplay(), glx_window);
destroyWindow(); destroyWindow(env);
} }
} }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_destroyWindow(JNIEnv *env, jobject this) { JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_destroyWindow(JNIEnv *env, jobject this) {
destroyWindow(); destroyWindow(env);
} }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_swapBuffers(JNIEnv * env, jobject this) JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_swapBuffers(JNIEnv * env, jobject this)