Skip to content

Commit fe81b9c

Browse files
author
Johan Vos
committed
8268120: Allow hardware cursor to be used on Monocle-EGL platforms
Reviewed-by: jpereda, kcr
1 parent ee03238 commit fe81b9c

File tree

4 files changed

+150
-1
lines changed

4 files changed

+150
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
package com.sun.glass.ui.monocle;
27+
28+
import com.sun.glass.ui.Size;
29+
30+
class EGLCursor extends NativeCursor {
31+
32+
private static final int CURSOR_WIDTH = 16;
33+
private static final int CURSOR_HEIGHT = 16;
34+
35+
36+
private native void _initEGLCursor(int cursorWidth, int cursorHeight);
37+
private native void _setVisible(boolean visible);
38+
private native void _setLocation(int x, int y);
39+
private native void _setImage(byte[] cursorImage);
40+
41+
EGLCursor() {
42+
_initEGLCursor(CURSOR_WIDTH, CURSOR_HEIGHT);
43+
}
44+
45+
@Override
46+
Size getBestSize() {
47+
return new Size(CURSOR_WIDTH, CURSOR_HEIGHT);
48+
}
49+
50+
@Override
51+
void setVisibility(boolean visibility) {
52+
isVisible = visibility;
53+
_setVisible(visibility);
54+
}
55+
56+
private void updateImage(boolean always) {
57+
System.out.println("EGLCursor.updateImage: not implemented");
58+
}
59+
60+
@Override
61+
void setImage(byte[] cursorImage) {
62+
_setImage(cursorImage);
63+
}
64+
65+
@Override
66+
void setLocation(int x, int y) {
67+
_setLocation(x, y);
68+
}
69+
70+
@Override
71+
void setHotSpot(int hotspotX, int hotspotY) {
72+
}
73+
74+
@Override
75+
void shutdown() {
76+
}
77+
}

modules/javafx.graphics/src/main/java/com/sun/glass/ui/monocle/EGLPlatform.java

+10
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ public EGLPlatform() {
4646
}
4747
}
4848

49+
@Override
50+
protected NativeCursor createCursor() {
51+
// By default, hardware cursor will be used
52+
// Fallback to software cursor will be used in case monocle.egl.swcursor is set to true
53+
boolean swcursor = Boolean.getBoolean("monocle.egl.swcursor");
54+
final NativeCursor c = useCursor ? (swcursor ? new SoftwareCursor() : new EGLCursor()) : new NullCursor();
55+
return logSelectedCursor(c);
56+
}
57+
58+
4959
@Override
5060
protected NativeScreen createScreen() {
5161
return new EGLScreen(0);

modules/javafx.graphics/src/main/native-glass/monocle/egl/eglBridge.c

+29
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* questions.
2323
*/
2424
#include "com_sun_glass_ui_monocle_EGLAcceleratedScreen.h"
25+
#include "com_sun_glass_ui_monocle_EGLCursor.h"
2526
#include "com_sun_glass_ui_monocle_EGLPlatform.h"
2627
#include "com_sun_glass_ui_monocle_EGLScreen.h"
2728
#include "Monocle.h"
@@ -139,3 +140,31 @@ JNIEXPORT jint JNICALL Java_com_sun_glass_ui_monocle_EGLPlatform_nGetNumberOfScr
139140
(JNIEnv *UNUSED(env), jobject UNUSED(obj)) {
140141
return doGetNumberOfScreens();
141142
}
143+
144+
JNIEXPORT void JNICALL Java_com_sun_glass_ui_monocle_EGLCursor__1initEGLCursor
145+
(JNIEnv *env, jobject obj, jint width, jint height) {
146+
doInitCursor(width, height);
147+
}
148+
149+
JNIEXPORT void JNICALL Java_com_sun_glass_ui_monocle_EGLCursor__1setVisible
150+
(JNIEnv *env, jobject obj, jboolean val) {
151+
doSetCursorVisibility(val);
152+
}
153+
154+
JNIEXPORT void JNICALL Java_com_sun_glass_ui_monocle_EGLCursor__1setLocation
155+
(JNIEnv *env, jobject obj, jint x, jint y) {
156+
doSetLocation(x, y);
157+
}
158+
159+
JNIEXPORT void JNICALL Java_com_sun_glass_ui_monocle_EGLCursor__1setImage
160+
(JNIEnv *env, jobject obj, jbyteArray jarr) {
161+
int length = (*env)->GetArrayLength(env, jarr);
162+
jbyte *attrArray = (*env)->GetByteArrayElements(env, jarr, JNI_FALSE);
163+
if (attrArray == 0) {
164+
fprintf(stderr, "Fatal error getting jbyte* from jbyteArray\n");
165+
return;
166+
}
167+
doSetCursorImage(attrArray, length);
168+
(*env)->ReleaseByteArrayElements(env, jarr, attrArray, JNI_ABORT);
169+
170+
}

modules/javafx.graphics/src/main/native-glass/monocle/egl/egl_ext.h

+34-1
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,44 @@
2525
#ifndef __EGL_EXT__
2626
#define __EGL_EXT__
2727
#include <jni.h>
28+
29+
// This header file declares functions that need to be provided by low-level
30+
// drivers or libraries.
31+
32+
// get a handle to the native window (without specifying what window is)
2833
extern jlong getNativeWindowHandle(const char *v);
34+
35+
// get a handle to the EGL display
2936
extern jlong getEglDisplayHandle();
37+
38+
// initialize the EGL system with the specified handle
3039
extern jboolean doEglInitialize(void* handle);
40+
41+
// bind a specific API to the EGL system
3142
extern jboolean doEglBindApi(int api);
43+
44+
// instruct the system to choose an EGL configuration matching the provided attributes
3245
extern jlong doEglChooseConfig (jlong eglDisplay, int* attribs);
3346

47+
// create an EGL Surface for the given display, configuration and window
3448
extern jlong doEglCreateWindowSurface(jlong eglDisplay, jlong config,
3549
jlong nativeWindow);
3650

51+
// create an EGL Context for the given display and configuration
3752
extern jlong doEglCreateContext(jlong eglDisplay, jlong config);
3853

54+
// enable the specified EGL system
3955
extern jboolean doEglMakeCurrent(jlong eglDisplay, jlong drawSurface,
4056
jlong readSurface, jlong eglContext);
4157

58+
// swap buffers (and render frontbuffer)
4259
extern jboolean doEglSwapBuffers(jlong eglDisplay, jlong eglSurface);
4360

61+
// get the number of native screens in the current configuration
62+
extern jint doGetNumberOfScreens();
63+
64+
// get specific information about each screen
65+
// the idx parameter specifies which screen needs to be queried
4466
extern jlong doGetHandle(jint idx);
4567
extern jint doGetDepth(jint idx);
4668
extern jint doGetWidth(jint idx);
@@ -50,6 +72,17 @@ extern jint doGetOffsetY(jint idx);
5072
extern jint doGetDpi(jint idx);
5173
extern jint doGetNativeFormat(jint idx);
5274
extern jfloat doGetScale(jint idx);
53-
extern jint doGetNumberOfScreens();
75+
76+
// initialize a hardware cursor with specified dimensions
77+
extern void doInitCursor(jint width, jint height);
78+
79+
// show/hide the hardware cursor
80+
extern void doSetCursorVisibility(jboolean val);
81+
82+
// point the hardware cursor to the provided location
83+
extern void doSetLocation(jint x, jint y);
84+
85+
// use the specified image as cursor image
86+
extern void doSetCursorImage(jbyte* img, int length);
5487

5588
#endif // EGL_EXT

0 commit comments

Comments
 (0)