diff --git a/src/java/org/lwjgl/input/Cursor.java b/src/java/org/lwjgl/input/Cursor.java index 67b1e7ea..16cf524d 100644 --- a/src/java/org/lwjgl/input/Cursor.java +++ b/src/java/org/lwjgl/input/Cursor.java @@ -32,10 +32,10 @@ package org.lwjgl.input; import java.nio.ByteBuffer; -import java.nio.ByteOrder; import java.nio.IntBuffer; import org.lwjgl.LWJGLException; +import org.lwjgl.BufferUtils; import org.lwjgl.Sys; /** @@ -49,8 +49,9 @@ import org.lwjgl.Sys; */ public class Cursor { + private final static int HANDLE_SIZE = 8; /** First element to display */ - private CursorElement[] cursors = null; + private final CursorElement[] cursors; /** Index into list of cursors */ private int index = 0; @@ -88,15 +89,15 @@ public class Cursor { yHotspot = height - 1 - yHotspot; // create cursor (or cursors if multiple images supplied) - createCursors(width, height, xHotspot, yHotspot, numImages, images, delays); + cursors = createCursors(width, height, xHotspot, yHotspot, numImages, images, delays); } /** * Creates the actual cursor, using a platform specific class */ - private void createCursors(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException { + private static CursorElement[] createCursors(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException { // create copy and flip images to match ogl - IntBuffer images_copy = ByteBuffer.allocateDirect(images.remaining()*4).order(ByteOrder.nativeOrder()).asIntBuffer(); + IntBuffer images_copy = BufferUtils.createIntBuffer(images.remaining()); flipImages(width, height, numImages, images, images_copy); // Win32 doesn't (afaik) allow for animation based cursors, except when they're @@ -107,25 +108,30 @@ public class Cursor { // might want to split it into a X/Win/Mac cursor if it gets too cluttered String osName = System.getProperty("os.name", ""); + CursorElement[] cursors; if (osName.startsWith("Win")) { // create our cursor elements cursors = new CursorElement[numImages]; for(int i=0; iGetDirectBufferCapacity(handle_buffer) < sizeof(Cursor)) { + throwException(env, "Handle buffer not large enough"); + return; + } Display *disp = incDisplay(env); if (disp == NULL) - return 0; + return; const int *delays = NULL; if (delay_buffer != NULL) delays = (const int *)env->GetDirectBufferAddress(delay_buffer) + delays_offset; @@ -74,20 +73,16 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_input_Cursor_nCreateCursor cursor_image->delay = delays[i]; cursor_images->images[i] = cursor_image; } - Cursor cursor = XcursorImagesLoadCursor(disp, cursor_images); + Cursor *cursor = (Cursor *)env->GetDirectBufferAddress(handle_buffer); + *cursor = XcursorImagesLoadCursor(disp, cursor_images); XcursorImagesDestroy(cursor_images); - return (jlong)cursor; } -/* - * Class: org_lwjgl_input_Cursor - * Method: nDestroyCursor - * Signature: (I)V - */ JNIEXPORT void JNICALL Java_org_lwjgl_input_Cursor_nDestroyCursor - (JNIEnv *env, jclass clazz, jlong cursor_handle) + (JNIEnv *env, jclass clazz, jobject cursor_handle_buffer) { - Cursor cursor = (Cursor)cursor_handle; - XFreeCursor(getDisplay(), cursor); + Cursor *cursor = (Cursor *)env->GetDirectBufferAddress(cursor_handle_buffer); +// Cursor cursor = (Cursor)cursor_handle; + XFreeCursor(getDisplay(), *cursor); decDisplay(); } diff --git a/src/native/linux/org_lwjgl_input_Mouse.cpp b/src/native/linux/org_lwjgl_input_Mouse.cpp index 2fc927c5..e512ef94 100644 --- a/src/native/linux/org_lwjgl_input_Mouse.cpp +++ b/src/native/linux/org_lwjgl_input_Mouse.cpp @@ -202,10 +202,11 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nGetNativeCursorCaps return caps; } -JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nSetNativeCursor (JNIEnv *env, jclass clazz, jlong cursor_handle) { - if (cursor_handle != 0) { - Cursor cursor = (Cursor)cursor_handle; - current_cursor = cursor; +JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nSetNativeCursor(JNIEnv *env, jclass clazz, jobject cursor_handle) { + if (cursor_handle != NULL) { + Cursor *cursor = (Cursor *)env->GetDirectBufferAddress(cursor_handle); +// Cursor cursor = (Cursor)cursor_handle; + current_cursor = *cursor; } else current_cursor = None; updateCursor(); diff --git a/src/native/linux/org_lwjgl_opengl_Pbuffer.cpp b/src/native/linux/org_lwjgl_opengl_Pbuffer.cpp index 5a56c735..ac53c362 100644 --- a/src/native/linux/org_lwjgl_opengl_Pbuffer.cpp +++ b/src/native/linux/org_lwjgl_opengl_Pbuffer.cpp @@ -52,7 +52,7 @@ typedef struct _PbufferInfo { } PbufferInfo; JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Pbuffer_nIsBufferLost - (JNIEnv *env, jclass clazz, jint handle) + (JNIEnv *env, jclass clazz, jobject handle_buffer) { // The buffer is never lost, because of the GLX_PRESERVED_CONTENTS flag return JNI_FALSE; @@ -71,7 +71,7 @@ static void destroyPbuffer(PbufferInfo *buffer_info) { glXDestroyPbuffer(getDisplay(), buffer); if (!buffer_info->use_display_context) glXDestroyContext(getDisplay(), context); - free(buffer_info); +// free(buffer_info); decDisplay(); } @@ -147,17 +147,17 @@ static bool createPbufferUsingDisplayContext(JNIEnv *env, PbufferInfo *buffer_in return true; } -JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Pbuffer_nCreate(JNIEnv *env, jclass clazz, jboolean use_display_context, jint width, jint height, jobject pixel_format, jobject pixelFormatCaps, jobject pBufferAttribs) +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nCreate(JNIEnv *env, jclass clazz, jobject handle_buffer, jboolean use_display_context, jint width, jint height, jobject pixel_format, jobject pixelFormatCaps, jobject pBufferAttribs) { Display *disp = incDisplay(env); if (disp == NULL) { - return -1; + return; } int current_screen = XDefaultScreen(disp); if (!extgl_InitGLX(env, disp, current_screen)) { decDisplay(); throwException(env, "Could not init GLX"); - return -1; + return; } const int buffer_attribs[] = {GLX_PBUFFER_WIDTH, width, @@ -166,7 +166,12 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Pbuffer_nCreate(JNIEnv *env, jclass GLX_LARGEST_PBUFFER, False, None, None}; - PbufferInfo *buffer_info = (PbufferInfo *)malloc(sizeof(PbufferInfo)); + if (env->GetDirectBufferCapacity(handle_buffer) < sizeof(PbufferInfo)) { + throwException(env, "Handle buffer not large enough"); + return; + } + PbufferInfo *buffer_info = (PbufferInfo *)env->GetDirectBufferAddress(handle_buffer); +// PbufferInfo *buffer_info = (PbufferInfo *)malloc(sizeof(PbufferInfo)); buffer_info->use_display_context = use_display_context; bool result; if (use_display_context) { @@ -175,18 +180,18 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Pbuffer_nCreate(JNIEnv *env, jclass result = createPbufferUsingUniqueContext(env, buffer_info, pixel_format, width, height, buffer_attribs); } if (!result) - return -1; + return; if (!checkXError(env)) { destroyPbuffer(buffer_info); - return -1; + return; } - return (jint)buffer_info; } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nMakeCurrent - (JNIEnv *env, jclass clazz, jint handle) + (JNIEnv *env, jclass clazz, jobject handle_buffer) { - PbufferInfo *buffer_info = (PbufferInfo *)handle; + PbufferInfo *buffer_info = (PbufferInfo *)env->GetDirectBufferAddress(handle_buffer); + //PbufferInfo *buffer_info = (PbufferInfo *)handle; GLXPbuffer buffer = buffer_info->buffer; GLXContext context = buffer_info->context; if (glXMakeContextCurrent(getDisplay(), buffer, buffer, context) == False) { @@ -200,26 +205,27 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nMakeCurrent * Signature: (I)V */ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nDestroy - (JNIEnv *env, jclass clazz, jint handle) + (JNIEnv *env, jclass clazz, jobject handle_buffer) { - PbufferInfo *buffer_info = (PbufferInfo *)handle; + PbufferInfo *buffer_info = (PbufferInfo *)env->GetDirectBufferAddress(handle_buffer); + //PbufferInfo *buffer_info = (PbufferInfo *)handle; destroyPbuffer(buffer_info); } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nSetAttrib - (JNIEnv *env, jclass clazz, jint handle, jint attrib, jint value) + (JNIEnv *env, jclass clazz, jobject handle_buffer, jint attrib, jint value) { throwException(env, "The render-to-texture extension is not supported."); } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nBindTexImage - (JNIEnv *env, jclass clazz, jint handle, jint buffer) + (JNIEnv *env, jclass clazz, jobject handle_buffer, jint buffer) { throwException(env, "The render-to-texture extension is not supported."); } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nReleaseTexImage - (JNIEnv *env, jclass clazz, jint handle, jint buffer) + (JNIEnv *env, jclass clazz, jobject handle_buffer, jint buffer) { throwException(env, "The render-to-texture extension is not supported."); }