Skip to content

Commit

Permalink
Prefer EGL over GLX
Browse files Browse the repository at this point in the history
  • Loading branch information
tsayao committed May 1, 2024
1 parent bc1ebd3 commit 86b07b6
Show file tree
Hide file tree
Showing 31 changed files with 1,794 additions and 308 deletions.
18 changes: 13 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -2367,7 +2367,12 @@ project(":graphics") {
addNative(project, "font")
addNative(project, "iio")
if (IS_INCLUDE_ES2) {
addNative(project, "prismES2")
if (IS_LINUX) {
addNative(project, "prismES2GLX")
addNative(project, "prismES2EGL")
} else {
addNative(project, "prismES2")
}
}

if (IS_COMPILE_PANGO) {
Expand Down Expand Up @@ -5116,8 +5121,7 @@ compileTargets { t ->
if (!targetProperties.includeGTK) { //usually IS_LINUX
exclude (
"com/sun/glass/ui/gtk",
"com/sun/prism/es2/EGL*",
"com/sun/prism/es2/X11GL*"
"com/sun/prism/es2/Linux*",
)
}

Expand Down Expand Up @@ -5254,7 +5258,11 @@ compileTargets { t ->
from("${graphicsProject.buildDir}/libs/jsl-decora/${t.name}/${library(targetProperties.decora.lib)}")
def libs = ['font', 'prism', 'prismSW', 'glass', 'iio']
if (IS_INCLUDE_ES2) {
libs += ['prismES2'];
if (IS_LINUX) {
libs += ['prismES2GLX', 'prismES2EGL'];
} else {
libs += ['prismES2'];
}
}
if (IS_COMPILE_PANGO) {
libs += ['fontFreetype', 'fontPango'];
Expand Down
8 changes: 4 additions & 4 deletions buildSrc/armv6hf.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -140,12 +140,12 @@ def iioCFlags = [extraCFlags,
].flatten()
def iioLFlags = [extraLFlags].flatten()

def es2EglfbCFlags = [extraCFlags, "-DIS_EGLFB", "-DLINUX", "-D_GNU_SOURCE"].flatten()
def es2EglfbCFlags = [extraCFlags, "-DIS_MONOCLE_EGLFB", "-DLINUX", "-D_GNU_SOURCE"].flatten()
def es2EglfbLFlags = [extraLFlags].flatten()
def es2MonocleCFlags = [extraCFlags, "-DIS_EGLFB", "-DLINUX"].flatten()
def es2MonocleCFlags = [extraCFlags, "-DIS_MONOCLE_EGLFB", "-DLINUX"].flatten()
def es2MonocleLFlags = [extraLFlags].flatten()

def es2X11CFlags = [extraCFlags, "-DUSE_XSHM", "-DDEBUG", "-DIS_EGLX11", "-DLINUX"].flatten()
def es2X11CFlags = [extraCFlags, "-DUSE_XSHM", "-DDEBUG", "-DIS_MONOCLE_EGLX11", "-DLINUX"].flatten()
def es2X11LFlags = [extraLFlags, "-lX11", "-lXext", "-lXdmcp", "-lXau"].flatten()

def mediaCFlags = [extraCFlags,
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/ios.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -74,7 +74,7 @@ IOS.jfxrtJarExcludes = [
"com/sun/glass/ui/gtk",

"com/sun/glass/ui/lens",
"com/sun/prism/es2/gl/x11",
"com/sun/prism/es2/gl/linux",

"com/sun/glass/ui/swt", // SWT glass

Expand Down
30 changes: 21 additions & 9 deletions buildSrc/linux.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -246,17 +246,29 @@ LINUX.iio.linker = IS_STATIC_BUILD ? "ld" : linker
LINUX.iio.linkFlags = [linkFlags].flatten()
LINUX.iio.lib = "javafx_iio"

LINUX.prismES2 = [:]
LINUX.prismES2.nativeSource = [
LINUX.prismES2GLX = [:]
LINUX.prismES2GLX.nativeSource = [
file("${project("graphics").projectDir}/src/main/native-prism-es2"),
file("${project("graphics").projectDir}/src/main/native-prism-es2/GL"),
file("${project("graphics").projectDir}/src/main/native-prism-es2/linux/glx")
]
LINUX.prismES2GLX.compiler = compiler
LINUX.prismES2GLX.ccFlags = ["-DLINUX", "-DIS_LINUX_GLX", cFlags].flatten()
LINUX.prismES2GLX.linker = linker
LINUX.prismES2GLX.linkFlags = IS_STATIC_BUILD ? linkFlags : [linkFlags, "-lX11", "-lXxf86vm", "-lGL"].flatten()
LINUX.prismES2GLX.lib = "prism_es2_glx"

LINUX.prismES2EGL = [:]
LINUX.prismES2EGL.nativeSource = [
file("${project("graphics").projectDir}/src/main/native-prism-es2"),
file("${project("graphics").projectDir}/src/main/native-prism-es2/GL"),
file("${project("graphics").projectDir}/src/main/native-prism-es2/x11")
file("${project("graphics").projectDir}/src/main/native-prism-es2/linux/egl")
]
LINUX.prismES2.compiler = compiler
LINUX.prismES2.ccFlags = ["-DLINUX", cFlags].flatten()
LINUX.prismES2.linker = linker
LINUX.prismES2.linkFlags =IS_STATIC_BUILD ? linkFlags : [linkFlags, "-lX11", "-lXxf86vm", "-lGL", "-lEGL"].flatten()
LINUX.prismES2.lib = "prism_es2"
LINUX.prismES2EGL.compiler = compiler
LINUX.prismES2EGL.ccFlags = ["-DLINUX", "-DIS_LINUX_EGL", cFlags].flatten()
LINUX.prismES2EGL.linker = linker
LINUX.prismES2EGL.linkFlags = IS_STATIC_BUILD ? linkFlags : [linkFlags, "-lX11", "-lGL", "-lEGL"].flatten()
LINUX.prismES2EGL.lib = "prism_es2_egl_x11"

def closedDir = file("$projectDir/../rt-closed")
LINUX.font = [:]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -47,25 +47,9 @@ public class ES2Pipeline extends GraphicsPipeline {
private static boolean es2Enabled;
private static boolean isEglfb = false;


static {
@SuppressWarnings("removal")
var dummy = AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
String libName = "prism_es2";

String eglType = PlatformUtil.getEmbeddedType();
if ("monocle".equals(eglType)) {
isEglfb = true;
libName = "prism_es2_monocle";
}
if (PrismSettings.verbose) {
System.out.println("Loading ES2 native library ... " + libName);
}
NativeLibLoader.loadLibrary(libName);
if (PrismSettings.verbose) {
System.out.println("\tsucceeded.");
}
return null;
});
loadNativeLib();

// Initialize the prism-es2 pipe and a handler of it
glFactory = GLFactory.getFactory();
Expand Down Expand Up @@ -103,6 +87,22 @@ public class ES2Pipeline extends GraphicsPipeline {
private static final ES2Pipeline theInstance;
private static ES2ResourceFactory factories[];

private static void loadNativeLib() {
if (PlatformUtil.isLinux()) {
//Linux will have to decide between EGL and GLX
return;
}
String libName = "prism_es2";

String eglType = PlatformUtil.getEmbeddedType();
if ("monocle".equals(eglType)) {
isEglfb = true;
libName = "prism_es2_monocle";
}

GLFactory.loadNativeLib(libName);
}

public static ES2Pipeline getInstance() {
return theInstance;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -25,10 +25,12 @@

package com.sun.prism.es2;

import com.sun.glass.utils.NativeLibLoader;
import com.sun.prism.impl.PrismSettings;
import com.sun.javafx.PlatformUtil;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Arrays;
import java.util.HashMap;

abstract class GLFactory {
Expand Down Expand Up @@ -60,54 +62,81 @@ abstract class GLFactory {
* Instantiate singleton factories if available, the OS native ones.
*/
static {

final String factoryClassName;
final FactoryLoader loader;
if (PlatformUtil.isUnix()) {
if ("monocle".equals(PlatformUtil.getEmbeddedType()))
factoryClassName = "com.sun.prism.es2.MonocleGLFactory";
else
factoryClassName = "com.sun.prism.es2.X11GLFactory";
if ("monocle".equals(PlatformUtil.getEmbeddedType())) {
loader = new FactoryLoader("com.sun.prism.es2.MonocleGLFactory");
} else {
if (System.getProperty("prism.es2.forceGLX", "false").equals("true")) {
loader = new FactoryLoader("com.sun.prism.es2.LinuxGLXFactory");
} else {
loader = new FactoryLoader("com.sun.prism.es2.LinuxEGLFactory",
"com.sun.prism.es2.LinuxGLXFactory");
}
}
} else if (PlatformUtil.isWindows()) {
factoryClassName = "com.sun.prism.es2.WinGLFactory";
loader = new FactoryLoader("com.sun.prism.es2.WinGLFactory");
} else if (PlatformUtil.isMac()) {
factoryClassName = "com.sun.prism.es2.MacGLFactory";
loader = new FactoryLoader("com.sun.prism.es2.MacGLFactory");
} else if (PlatformUtil.isIOS()) {
factoryClassName = "com.sun.prism.es2.IOSGLFactory";
loader = new FactoryLoader("com.sun.prism.es2.IOSGLFactory");
} else if (PlatformUtil.isAndroid()) {
factoryClassName = "com.sun.prism.es2.MonocleGLFactory";
loader = new FactoryLoader("com.sun.prism.es2.MonocleGLFactory");
} else {
factoryClassName = null;
loader = null;
System.err.println("GLFactory.static - No Platform Factory for: " + System.getProperty("os.name"));
}

if (PrismSettings.verbose) {
System.out.println("GLFactory using " + factoryClassName);
System.out.println("GLFactory using " + loader);
}

@SuppressWarnings("removal")
GLFactory tmp = factoryClassName == null ? null :
AccessController.doPrivileged(new FactoryLoader(factoryClassName));
GLFactory tmp = loader == null ? null : AccessController.doPrivileged(loader);
platformFactory = tmp;
}

private static class FactoryLoader implements PrivilegedAction<GLFactory> {
private final String factoryClassName;
FactoryLoader(String factoryClassName) {
this.factoryClassName = factoryClassName;
private final String[] factoryClassNames;
FactoryLoader(String... factoryClassNames) {
this.factoryClassNames = factoryClassNames;
}

@Override
public GLFactory run() {
GLFactory factory = null;
try {
factory = (GLFactory) Class.forName(factoryClassName).getDeclaredConstructor().newInstance();
} catch (Throwable t) {
System.err.println("GLFactory.static - Platform: "
+ System.getProperty("os.name")
+ " - not available: "
+ factoryClassName);
t.printStackTrace();
for (String factoryClassName : factoryClassNames) {
try {
return (GLFactory) Class.forName(factoryClassName).getDeclaredConstructor().newInstance();
} catch (Throwable t) {
System.err.println("GLFactory.static - Platform: "
+ System.getProperty("os.name")
+ " - not available: "
+ factoryClassName);
t.printStackTrace();
}
}
return factory;

return null;
}

@Override
public String toString() {
return "{" + Arrays.toString(factoryClassNames) + "}";
}
}

static void loadNativeLib(String libName) {
@SuppressWarnings("removal")
var dummy = AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
if (PrismSettings.verbose) {
System.out.println("Loading ES2 native library ... " + libName);
}
NativeLibLoader.loadLibrary(libName);
if (PrismSettings.verbose) {
System.out.println("\tsucceeded.");
}
return null;
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -40,6 +40,10 @@ class IOSGLFactory extends GLFactory {
private GLGPUInfo rejectList[] = {
};

public IOSGLFactory() {
loadNativeLib("prism_es2");
}

@Override
GLGPUInfo[] getPreQualificationFilter() {
return preQualificationFilter;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package com.sun.prism.es2;

class LinuxEGLContext extends LinuxGLContext {
public LinuxEGLContext(long nativeCtxInfo) {
super(nativeCtxInfo);
}

public LinuxEGLContext(GLDrawable drawable, GLPixelFormat pixelFormat, boolean vSyncRequest) {
super(drawable, pixelFormat, vSyncRequest);
}
}
Loading

0 comments on commit 86b07b6

Please sign in to comment.