Skip to content

Commit ade3227

Browse files
author
Johan Vos
committed
8254569: Remove hard dependency on Dispman in Monocle fb rendering
Reviewed-by: kcr, jpereda
1 parent 08d8a98 commit ade3227

File tree

7 files changed

+347
-4
lines changed

7 files changed

+347
-4
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public class AcceleratedScreen {
3333
private static long glesLibraryHandle;
3434
private static long eglLibraryHandle;
3535
private static boolean initialized = false;
36-
private long eglSurface;
37-
private long eglContext;
38-
private long eglDisplay;
39-
private long nativeWindow;
36+
long eglSurface;
37+
long eglContext;
38+
long eglDisplay;
39+
long nativeWindow;
4040
protected static final LinuxSystem ls = LinuxSystem.getLinuxSystem();
4141
private EGL egl;
4242
long eglConfigs[] = {0};
@@ -55,6 +55,14 @@ protected long platformGetNativeWindow() {
5555
return 0L;
5656
}
5757

58+
/**
59+
* Create and initialize an AcceleratedScreen. Subclasses should override
60+
* this constructor in case the {@link #AcceleratedScreen(int[]) AcceleratedScreen(int[])}
61+
* constructor is not sufficient.
62+
*/
63+
AcceleratedScreen() {
64+
}
65+
5866
/**
5967
* Perform basic egl intialization - open the display, create the drawing
6068
* surface, and create a GL context to that drawing surface.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright (c) 2020, 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+
package com.sun.glass.ui.monocle;
26+
27+
/**
28+
* The <code>EGLAcceleratedScreen</code> manages the link to the hardware-accelerated
29+
* component, using EGL. This class is not directly using EGL commands,
30+
* as the order and meaning of parameters might vary between implementations.
31+
* Also, implementation-specific logic may be applied before, in between, or
32+
* after the EGL commands.
33+
*/
34+
public class EGLAcceleratedScreen extends AcceleratedScreen {
35+
36+
private long eglWindowHandle = -1;
37+
38+
/**
39+
* Create a new <code>EGLAcceleratedScreen</code> with a set of attributes.
40+
* This will create an <code>EGL Context</code> that can be used by the
41+
* Prism component.
42+
* @param attributes an array of attributes that will be used by the underlying
43+
* implementation to get the best matching configuration.
44+
*/
45+
EGLAcceleratedScreen(int[] attributes) throws GLException {
46+
eglWindowHandle = platformGetNativeWindow();
47+
eglDisplay = nGetEglDisplayHandle();
48+
nEglInitialize(eglDisplay);
49+
nEglBindApi(EGL.EGL_OPENGL_ES_API);
50+
long eglConfig = nEglChooseConfig(eglDisplay, attributes);
51+
if (eglConfig == -1) {
52+
throw new IllegalArgumentException("Could not create an EGLChooseConfig");
53+
}
54+
eglSurface = nEglCreateWindowSurface(eglDisplay, eglConfig, eglWindowHandle);
55+
eglContext = nEglCreateContext(eglDisplay, eglConfig);
56+
}
57+
58+
@Override
59+
protected long platformGetNativeWindow() {
60+
String displayID = System.getProperty("egl.displayid", "/dev/dri/card1" );
61+
return nPlatformGetNativeWindow(displayID);
62+
}
63+
64+
@Override
65+
public void enableRendering(boolean flag) {
66+
if (flag) {
67+
nEglMakeCurrent(eglDisplay, eglSurface, eglSurface,
68+
eglContext);
69+
} else {
70+
nEglMakeCurrent(eglDisplay, 0, 0, eglContext);
71+
}
72+
}
73+
74+
@Override
75+
public boolean swapBuffers() {
76+
boolean result = false;
77+
synchronized (NativeScreen.framebufferSwapLock) {
78+
result = nEglSwapBuffers(eglDisplay, eglSurface);
79+
}
80+
return result;
81+
}
82+
83+
private native long nPlatformGetNativeWindow(String displayID);
84+
private native long nGetEglDisplayHandle();
85+
private native boolean nEglInitialize(long handle);
86+
private native boolean nEglBindApi(int v);
87+
private native long nEglChooseConfig(long eglDisplay, int[] attribs);
88+
private native boolean nEglMakeCurrent(long eglDisplay, long eglDrawSurface, long eglReadSurface, long eglContext);
89+
private native long nEglCreateWindowSurface(long eglDisplay, long eglConfig, long nativeWindow);
90+
private native long nEglCreateContext(long eglDisplay, long eglConfig);
91+
private native boolean nEglSwapBuffers(long eglDisplay, long eglSurface);
92+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2020, 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+
package com.sun.glass.ui.monocle;
26+
27+
public class EGLPlatform extends LinuxPlatform {
28+
29+
/**
30+
* Create an <code>EGLPlatform</code>. If a library with specific native code is needed for this platform,
31+
* it will be downloaded now. The system property <code>monocle.egl.lib</code> can be used to define the
32+
* name of the library that should be loaded.
33+
*/
34+
public EGLPlatform() {
35+
String lib = System.getProperty("monocle.egl.lib");
36+
if (lib != null) {
37+
long handle = LinuxSystem.getLinuxSystem().dlopen(lib, LinuxSystem.RTLD_LAZY | LinuxSystem.RTLD_GLOBAL);
38+
if (handle == 0) {
39+
throw new UnsatisfiedLinkError("EGLPlatform failed to load the requested library " + lib);
40+
}
41+
}
42+
}
43+
44+
@Override
45+
public synchronized AcceleratedScreen getAcceleratedScreen(int[] attributes) throws GLException {
46+
if (accScreen == null) {
47+
accScreen = new EGLAcceleratedScreen(attributes);
48+
}
49+
return accScreen;
50+
51+
}
52+
53+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2020, 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+
package com.sun.glass.ui.monocle;
26+
27+
public class EGLPlatformFactory extends NativePlatformFactory {
28+
29+
@Override
30+
protected boolean matches() {
31+
return true;
32+
}
33+
34+
@Override
35+
protected int getMajorVersion() {
36+
return 1;
37+
}
38+
39+
@Override
40+
protected int getMinorVersion() {
41+
return 0;
42+
}
43+
44+
@Override
45+
protected NativePlatform createNativePlatform() {
46+
return new EGLPlatform();
47+
}
48+
49+
50+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3+
*
4+
* This code is free software; you can redistribute it and/or modify it
5+
* under the terms of the GNU General Public License version 2 only, as
6+
* published by the Free Software Foundation. Oracle designates this
7+
* particular file as subject to the "Classpath" exception as provided
8+
* by Oracle in the LICENSE file that accompanied this code.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*/
24+
#include "com_sun_glass_ui_monocle_EGLAcceleratedScreen.h"
25+
#include "Monocle.h"
26+
#include "egl_ext.h"
27+
28+
JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_monocle_EGLAcceleratedScreen_nPlatformGetNativeWindow
29+
(JNIEnv *env, jobject obj, jstring cardId) {
30+
const char *ccid = (*env)->GetStringUTFChars(env, cardId, NULL);
31+
long answer = getNativeWindowHandle(ccid);
32+
(*env)->ReleaseStringUTFChars(env, cardId, ccid);
33+
return (jlong)answer;
34+
}
35+
36+
JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_monocle_EGLAcceleratedScreen_nGetEglDisplayHandle
37+
(JNIEnv *env, jobject obj) {
38+
long answer = getEglDisplayHandle();
39+
return (jlong)answer;
40+
}
41+
42+
JNIEXPORT jboolean JNICALL Java_com_sun_glass_ui_monocle_EGLAcceleratedScreen_nEglInitialize
43+
(JNIEnv *env, jclass clazz, jlong eglDisplay) {
44+
jboolean answer = doEglInitialize(asPtr(eglDisplay));
45+
return answer;
46+
}
47+
48+
JNIEXPORT jboolean JNICALL Java_com_sun_glass_ui_monocle_EGLAcceleratedScreen_nEglBindApi
49+
(JNIEnv *env, jclass clazz, jint api) {
50+
jboolean answer = doEglBindApi((int)api);
51+
return answer;
52+
}
53+
54+
JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_monocle_EGLAcceleratedScreen_nEglChooseConfig
55+
(JNIEnv *env, jclass clazz, jlong eglDisplay, jintArray attribs) {
56+
jint *attrArray = (*env)->GetIntArrayElements(env, attribs, JNI_FALSE);
57+
if (attrArray == 0) {
58+
fprintf(stderr, "Fatal error getting int* from int[]\n");
59+
return -1;
60+
}
61+
jlong answer = doEglChooseConfig(eglDisplay, attrArray);
62+
(*env)->ReleaseIntArrayElements(env, attribs, attrArray, JNI_ABORT);
63+
return answer;
64+
}
65+
66+
JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_monocle_EGLAcceleratedScreen_nEglCreateWindowSurface
67+
(JNIEnv *env, jclass clazz, jlong eglDisplay, jlong config, jlong nativeWindow) {
68+
jlong answer = doEglCreateWindowSurface(eglDisplay, config, nativeWindow);
69+
return answer;
70+
}
71+
72+
JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_monocle_EGLAcceleratedScreen_nEglCreateContext
73+
(JNIEnv *UNUSED(env), jclass UNUSED(clazz), jlong eglDisplay, jlong config) {
74+
jlong answer = doEglCreateContext(eglDisplay, config);
75+
return answer;
76+
}
77+
78+
JNIEXPORT jboolean JNICALL Java_com_sun_glass_ui_monocle_EGLAcceleratedScreen_nEglMakeCurrent
79+
(JNIEnv *UNUSED(env), jclass UNUSED(clazz), jlong eglDisplay, jlong drawSurface,
80+
jlong readSurface, jlong eglContext) {
81+
jlong answer = doEglMakeCurrent(eglDisplay, drawSurface, readSurface, eglContext);
82+
return answer;
83+
}
84+
85+
JNIEXPORT jboolean JNICALL Java_com_sun_glass_ui_monocle_EGLAcceleratedScreen_nEglSwapBuffers
86+
(JNIEnv *UNUSED(env), jclass UNUSED(clazz), jlong eglDisplay, jlong eglSurface) {
87+
jlong answer = doEglSwapBuffers(eglDisplay, eglSurface);
88+
return answer;
89+
}
90+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2011, 2020, 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+
#ifndef __EGL_EXT__
26+
#define __EGL_EXT__
27+
#include <jni.h>
28+
extern jlong getNativeWindowHandle(const char *v);
29+
extern jlong getEglDisplayHandle();
30+
extern jboolean doEglInitialize(void* handle);
31+
extern jboolean doEglBindApi(int api);
32+
extern jlong doEglChooseConfig (jlong eglDisplay, int* attribs);
33+
34+
extern jlong doEglCreateWindowSurface(jlong eglDisplay, jlong config,
35+
jlong nativeWindow);
36+
37+
extern jlong doEglCreateContext(jlong eglDisplay, jlong config);
38+
39+
extern jboolean doEglMakeCurrent(jlong eglDisplay, jlong drawSurface,
40+
jlong readSurface, jlong eglContext);
41+
42+
extern jboolean doEglSwapBuffers(jlong eglDisplay, jlong eglSurface);
43+
#endif // EGL_EXT

modules/javafx.graphics/src/main/native-prism-es2/monocle/MonocleGLFactory.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
#include "../PrismES2Defs.h"
3636

3737
#include "com_sun_prism_es2_MonocleGLContext.h"
38+
#ifndef ANDROID
39+
#define __USE_GNU
40+
#include <dlfcn.h>
41+
#endif
3842

3943
extern void *get_dlsym(void *handle, const char *symbol, int warn);
4044

@@ -108,6 +112,9 @@ JNIEXPORT jlong JNICALL Java_com_sun_prism_es2_MonocleGLFactory_nPopulateNativeC
108112

109113
// from the eglWrapper.c
110114
void *handle = asPtr(libraryHandle);
115+
if (libraryHandle == 0) {
116+
handle = RTLD_DEFAULT;
117+
}
111118

112119
/* set function pointers */
113120
ctxInfo->glActiveTexture = (PFNGLACTIVETEXTUREPROC)

0 commit comments

Comments
 (0)