From 381858b82c5197193ba2f490a8282149536a54f7 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 29 Nov 2019 07:32:52 +0100 Subject: Bug 1156: DRM/GBM: Add full PointerIcon (Cursor) Support DRM allows 64x64 pixel cursor images, using GBM_FORMAT_ARGB888 only. Notable: GBM_FORMAT_ARGB888 == PixelFormat.BGRA8888 Having fixed mouse and keyboard input with previous commit, the demo com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT shows via key press - i -> pointer visible/invisible - c -> pointer icon change --- src/newt/native/drm_gbm.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) (limited to 'src/newt/native/drm_gbm.c') diff --git a/src/newt/native/drm_gbm.c b/src/newt/native/drm_gbm.c index 93b02dbe7..fd1879d88 100644 --- a/src/newt/native/drm_gbm.c +++ b/src/newt/native/drm_gbm.c @@ -49,6 +49,111 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_egl_gbm_DisplayDriver_DispatchMes { } +JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_egl_gbm_DisplayDriver_CreatePointerIcon0 + (JNIEnv *env, jclass clazz, jlong jgbmDevice, jobject jpixels, jint pixels_byte_offset, jboolean pixels_is_direct, + jint width, jint height, jint hotX, jint hotY) +{ + const uint32_t *pixels = NULL; + struct gbm_device * gbmDevice = (struct gbm_device *) (intptr_t) jgbmDevice; + struct gbm_bo *bo = NULL; + uint32_t bo_handle; + uint32_t buf[64 * 64]; + int i, j; + + ERR_PRINT("cursor.cstr %dx%d %d/%d\n", width, height, hotX, hotY); + + if ( NULL == jpixels ) { + ERR_PRINT("CreateCursor: null icon pixels\n"); + return 0; + } + if( 0 >= width || width > 64 || 0 >= height || height > 64 ) { + ERR_PRINT("CreateCursor: icon must be of size [1..64] x [1..64]\n"); + return 0; + } + { + const char * c1 = (const char *) ( JNI_TRUE == pixels_is_direct ? + (*env)->GetDirectBufferAddress(env, jpixels) : + (*env)->GetPrimitiveArrayCritical(env, jpixels, NULL) ); + pixels = (uint32_t *) ( c1 + pixels_byte_offset ); + } + + bo = gbm_bo_create(gbmDevice, 64, 64, + GBM_FORMAT_ARGB8888, + // GBM_FORMAT_BGRA8888, + GBM_BO_USE_CURSOR_64X64 | GBM_BO_USE_WRITE); + if( NULL == bo ) { + ERR_PRINT("cursor.cstr gbm_bo_create failed\n"); + return 0; + } + + // align user data width x height -> 64 x 64 + memset(buf, 0, sizeof(buf)); // cleanup + for(int i=0; i