Implement Cursor.destroy and release memory used by native cursors

This commit is contained in:
kappaOne 2013-02-03 17:47:09 +00:00
parent bf13ed9cc3
commit c328463776
3 changed files with 24 additions and 14 deletions

View File

@ -441,9 +441,9 @@ final class MacOSXDisplay implements DisplayImplementation {
mouse.setCursorPosition(x, y);
}
}
else {
//else {
//MacOSXMouseEventQueue.nWarpCursor(x, y);
}
//}
}
public void setNativeCursor(Object handle) throws LWJGLException {
@ -520,7 +520,14 @@ final class MacOSXDisplay implements DisplayImplementation {
}
public void destroyCursor(Object cursor_handle) {
long handle = getCursorHandle(cursor_handle);
// reset current cursor if same
if (currentNativeCursor == handle) {
currentNativeCursor = 0;
}
MacOSXNativeMouse.destroyCursor(handle);
}
private static long getCursorHandle(Object cursor_handle) {

View File

@ -91,7 +91,7 @@ final class MacOSXNativeMouse extends EventQueue {
private static native long nCreateCursor(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 void nDestroyCursor(long cursor_handle) throws LWJGLException;
private static native void nDestroyCursor(long cursor_handle);
private static native void nSetCursor(long cursor_handle) throws LWJGLException;
@ -107,12 +107,8 @@ final class MacOSXNativeMouse extends EventQueue {
}
}
public static void destroyCursor(long cursor_handle) throws LWJGLException {
try {
nDestroyCursor(cursor_handle);
} catch (LWJGLException e) {
throw e;
}
public static void destroyCursor(long cursor_handle) {
nDestroyCursor(cursor_handle);
}
public static void setCursor(long cursor_handle) throws LWJGLException {

View File

@ -101,9 +101,11 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nUnregisterMouseL
}
JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nCreateCursor(JNIEnv *env, jobject _this, 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) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
jlong *bytes = (jint *)(*env)->GetDirectBufferAddress(env, image_buffer) + images_offset;
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc]
NSBitmapImageRep *bitmap = [[[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:(jlong *)&bytes
pixelsWide:width pixelsHigh:height
bitsPerSample:8
@ -113,20 +115,25 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nCreateCursor(JN
colorSpaceName:NSDeviceRGBColorSpace
bitmapFormat:NSAlphaNonpremultipliedBitmapFormat
bytesPerRow:width*4
bitsPerPixel:32];
bitsPerPixel:32] autorelease];
NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];
NSImage *image = [[[NSImage alloc] initWithSize:NSMakeSize(width, height)] autorelease];
[image addRepresentation:bitmap];
NSCursor *cursor = [[NSCursor alloc] initWithImage:image hotSpot:NSMakePoint(x_hotspot, y_hotspot)];
[pool release];
return (jlong)cursor;
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nDestroyCursor(JNIEnv *env, jobject _this, jlong handle) {
// TODO
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nDestroyCursor(JNIEnv *env, jobject _this, jlong cursor_pointer) {
if (cursor_pointer != 0) {
NSCursor *cursor = (NSCursor *)cursor_pointer;
[cursor release];
}
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nSetCursor(JNIEnv *env, jobject _this, jlong cursor_pointer) {