Linux: moved Cursor handle allocation to native side

This commit is contained in:
Elias Naur 2005-02-21 15:56:53 +00:00
parent c8fc535c7c
commit 8bb10a1372
2 changed files with 10 additions and 11 deletions

View File

@ -48,7 +48,6 @@ import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
final class LinuxDisplay implements DisplayImplementation {
private static final int CURSOR_HANDLE_SIZE = 8;
// private static final int PBUFFER_HANDLE_SIZE = 24;
private static final int NUM_BUTTONS = 3;
@ -359,16 +358,14 @@ final class LinuxDisplay implements DisplayImplementation {
return Keyboard.STATE_UNKNOWN;
}
private static native void nCreateCursor(ByteBuffer handle, int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, int images_offset, IntBuffer delays, int delays_offset) throws LWJGLException;
private static native ByteBuffer nCreateCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, int images_offset, IntBuffer delays, int delays_offset) throws LWJGLException;
public Object createCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException {
lockAWT();
try {
incDisplay();
try {
ByteBuffer handle = BufferUtils.createByteBuffer(CURSOR_HANDLE_SIZE);
nCreateCursor(handle, width, height, xHotspot, yHotspot, numImages, images, images.position(), delays, delays != null ? delays.position() : -1);
return handle;
return nCreateCursor(width, height, xHotspot, yHotspot, numImages, images, images.position(), delays, delays != null ? delays.position() : -1);
} catch (LWJGLException e) {
decDisplay();
throw e;

View File

@ -77,12 +77,13 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetMaxCursorSize
return width_return > height_return ? height_return : width_return;
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nCreateCursor
(JNIEnv *env, jclass clazz, jobject handle_buffer, jint width, jint height, jint x_hotspot, jint y_hotspot, jint num_images, jobject image_buffer, jint images_offset, jobject delay_buffer, jint delays_offset)
JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nCreateCursor
(JNIEnv *env, jclass clazz, jint width, jint height, jint x_hotspot, jint y_hotspot, jint num_images, jobject image_buffer, jint images_offset, jobject delay_buffer, jint delays_offset)
{
if ((*env)->GetDirectBufferCapacity(env, handle_buffer) < sizeof(Cursor)) {
throwException(env, "Handle buffer not large enough");
return;
jobject handle_buffer = newJavaManagedByteBuffer(env, sizeof(Cursor));
if (handle_buffer == NULL) {
throwException(env, "Could not allocate handle buffer");
return NULL;
}
const int *delays = NULL;
if (delay_buffer != NULL)
@ -92,7 +93,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nCreateCursor
XcursorImages *cursor_images = XcursorImagesCreate(num_images);
if (cursor_images == NULL) {
throwException(env, "Could not allocate cursor.");
return;
return NULL;
}
cursor_images->nimage = num_images;
int i;
@ -108,6 +109,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nCreateCursor
Cursor *cursor = (Cursor *)(*env)->GetDirectBufferAddress(env, handle_buffer);
*cursor = XcursorImagesLoadCursor(getDisplay(), cursor_images);
XcursorImagesDestroy(cursor_images);
return handle_buffer;
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nDestroyCursor