diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml
index 9178b389f7..cab819f1e5 100644
--- a/.idea/codeStyleSettings.xml
+++ b/.idea/codeStyleSettings.xml
@@ -8,6 +8,7 @@
+
diff --git a/buildSrc/armv6sf.gradle b/buildSrc/armv6sf.gradle
index dac6cd405e..aa0f99f08c 100644
--- a/buildSrc/armv6sf.gradle
+++ b/buildSrc/armv6sf.gradle
@@ -162,6 +162,8 @@ def es2LFlags = [extraLFlags, eglLFlags].flatten()
def es2EglfbCFlags = [extraCFlags, eglCFlags, "-DIS_EGLFB", "-DLINUX"].flatten()
def es2EglfbLFlags = [extraLFlags, eglLFlags].flatten()
+def es2MonocleCFlags = [extraCFlags, eglCFlags, "-DIS_EGLFB", "-DLINUX"].flatten()
+def es2MonocleFlags = [extraLFlags, eglLFlags].flatten()
def es2X11CFlags = [extraCFlags, eglCFlags, x11CFlags, "-DDEBUG", "-DIS_EGLX11", "-DLINUX"].flatten()
def es2X11LFlags = [extraLFlags, x11LFlags, eglLFlags, "-lXdmcp", "-lXau"].flatten()
@@ -350,6 +352,7 @@ ARMV6SF.glass.javahInclude = [
"com/sun/glass/events/**",
"com/sun/glass/ui/*",
"com/sun/glass/ui/lens/*",
+ "com/sun/glass/ui/monocle/*",
"com/sun/glass/ui/monocle/linux/*",
"com/sun/glass/ui/monocle/util/*",
"com/sun/glass/ui/monocle/x11/*",
@@ -369,6 +372,7 @@ ARMV6SF.glass.lensport.lib = "lens_porting"
ARMV6SF.glass.monocle = [:]
ARMV6SF.glass.monocle.nativeSource = [
+ file("modules/graphics/src/main/native-glass/monocle"),
file("modules/graphics/src/main/native-glass/monocle/linux"),
file("modules/graphics/src/main/native-glass/monocle/util") ]
ARMV6SF.glass.monocle.compiler = compiler
@@ -492,7 +496,7 @@ ARMV6SF.iio.linkFlags = iioLFlags
ARMV6SF.iio.lib = "javafx_iio"
ARMV6SF.prismES2 = [:]
-ARMV6SF.prismES2.variants = ["eglfb"]
+ARMV6SF.prismES2.variants = ["eglfb", "monocle"]
ARMV6SF.prismES2.javahInclude = ["com/sun/prism/es2/**/*"]
ARMV6SF.prismES2.eglfb = [:]
@@ -507,6 +511,18 @@ ARMV6SF.prismES2.eglfb.linker = linker
ARMV6SF.prismES2.eglfb.linkFlags = es2EglfbLFlags
ARMV6SF.prismES2.eglfb.lib = "prism_es2_eglfb"
+ARMV6SF.prismES2.monocle= [:]
+ARMV6SF.prismES2.monocle.nativeSource = [
+ file("modules/graphics/src/main/native-prism-es2"),
+ file("modules/graphics/src/main/native-prism-es2/GL"),
+ file("modules/graphics/src/main/native-prism-es2/monocle")
+]
+ARMV6SF.prismES2.monocle.compiler = compiler
+ARMV6SF.prismES2.monocle.ccFlags = [ es2EglfbCFlags, "-I", ARMV6SF.glass.lensport.nativeSource ].flatten()
+ARMV6SF.prismES2.monocle.linker = linker
+ARMV6SF.prismES2.monocle.linkFlags = es2EglfbLFlags
+ARMV6SF.prismES2.monocle.lib = "prism_es2_monocle"
+
ARMV6SF.prismES2.eglx11 = [:]
ARMV6SF.prismES2.eglx11.nativeSource = [
file("modules/graphics/src/main/native-prism-es2"),
diff --git a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/NativeScreen.java b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/NativeScreen.java
index aa493beeeb..26fa8708b2 100644
--- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/NativeScreen.java
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/NativeScreen.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013,2014 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
@@ -37,7 +37,7 @@ public interface NativeScreen {
public int getDPI();
public long getNativeHandle();
public void shutdown();
-
+ public long platformGetNativeDisplay();
public void uploadPixels(Buffer b,
int x, int y, int width, int height, float alpha);
diff --git a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/headless/HeadlessScreen.java b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/headless/HeadlessScreen.java
index 053e4e47a5..b48d576bf4 100644
--- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/headless/HeadlessScreen.java
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/headless/HeadlessScreen.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2014 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
@@ -131,4 +131,8 @@ public IntBuffer getScreenCapture() {
return fb.getBuffer().asIntBuffer();
}
+ @Override
+ public long platformGetNativeDisplay() {
+ return 0L;
+ }
}
diff --git a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/linux/FBDevScreen.java b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/linux/FBDevScreen.java
index eddbd1b627..16f0e15f9c 100644
--- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/linux/FBDevScreen.java
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/linux/FBDevScreen.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2014, 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
@@ -50,6 +50,10 @@ public class FBDevScreen implements NativeScreen {
private Framebuffer fb;
private LinuxFrameBuffer linuxFB;
+ private static long glesLibraryHandle;
+ private static long eglLibraryHandle;
+ private static boolean initialized = false;
+
public FBDevScreen() {
try {
linuxFB = new LinuxFrameBuffer("/dev/fb0");
@@ -210,4 +214,20 @@ public synchronized IntBuffer getScreenCapture() {
return getFramebuffer().getBuffer().asIntBuffer();
}
+ protected boolean initPlatformLibraries() {
+ if (!initialized) {
+ LinuxSystem ls = LinuxSystem.getLinuxSystem();
+ glesLibraryHandle = ls.dlopen("libGLESv2.so",
+ LinuxSystem.RTLD_LAZY | LinuxSystem.RTLD_GLOBAL);
+ eglLibraryHandle = ls.dlopen("libEGL.so",
+ LinuxSystem.RTLD_LAZY | LinuxSystem.RTLD_GLOBAL);
+ initialized = true;
+ }
+ return true;
+ }
+
+ public long platformGetNativeDisplay() {
+ return 0L;
+ }
+
}
diff --git a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/linux/LinuxSystem.java b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/linux/LinuxSystem.java
index 788c24e910..779ed89555 100644
--- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/linux/LinuxSystem.java
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/linux/LinuxSystem.java
@@ -30,6 +30,7 @@
import java.nio.ByteBuffer;
import java.security.Permission;
+import com.sun.glass.utils.NativeLibLoader;
public class LinuxSystem {
private static Permission permission = new RuntimePermission("loadLibrary.*");
@@ -148,6 +149,8 @@ public FbVarScreenInfo() {
public native String strerror(int errnum);
// dlfcn.h
+ public static final int RTLD_LAZY = 0x00001;
+ public static final int RTLD_GLOBAL = 0x00100;
public native long dlopen(String filename, int flag);
public native String dlerror();
public native long dlsym(long handle, String symbol);
diff --git a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/omap/OMAPScreen.java b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/omap/OMAPScreen.java
index e78619ce00..7eb293bc47 100644
--- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/omap/OMAPScreen.java
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/omap/OMAPScreen.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 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
@@ -27,9 +27,14 @@
import com.sun.glass.ui.monocle.linux.FBDevScreen;
import com.sun.glass.ui.monocle.linux.SysFS;
+import com.sun.glass.ui.monocle.linux.LinuxSystem;
import java.io.IOException;
public class OMAPScreen extends FBDevScreen {
+ public long platformGetNativeDisplay() {
+ initPlatformLibraries();
+ return 0L;
+ }
}
diff --git a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/x11/X11Screen.java b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/x11/X11Screen.java
index 1f842b99a3..e610fcd814 100644
--- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/x11/X11Screen.java
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/x11/X11Screen.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2014, 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
@@ -174,4 +174,9 @@ public void swapBuffers() {
public IntBuffer getScreenCapture() {
return null;
}
+
+ @Override
+ public long platformGetNativeDisplay() {
+ return 0L;
+ }
}
diff --git a/modules/graphics/src/main/java/com/sun/prism/es2/ES2Pipeline.java b/modules/graphics/src/main/java/com/sun/prism/es2/ES2Pipeline.java
index ecfef3d59e..f830b909d7 100644
--- a/modules/graphics/src/main/java/com/sun/prism/es2/ES2Pipeline.java
+++ b/modules/graphics/src/main/java/com/sun/prism/es2/ES2Pipeline.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2014, 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
@@ -56,6 +56,10 @@ public Void run() {
isEglfb = true;
libName = "prism_es2_eglfb";
}
+ else if ("monocle".equals(eglType)) {
+ isEglfb = true;
+ libName = "prism_es2_monocle";
+ }
else if ("eglx11".equals(eglType))
libName = "prism_es2_eglx11";
diff --git a/modules/graphics/src/main/java/com/sun/prism/es2/GLFactory.java b/modules/graphics/src/main/java/com/sun/prism/es2/GLFactory.java
index e259cae4e2..eb4f805b83 100644
--- a/modules/graphics/src/main/java/com/sun/prism/es2/GLFactory.java
+++ b/modules/graphics/src/main/java/com/sun/prism/es2/GLFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2014, 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
@@ -67,6 +67,8 @@ abstract class GLFactory {
factoryClassName = "com.sun.prism.es2.EGLX11GLFactory";
else if ("eglfb".equals(PlatformUtil.getEmbeddedType()))
factoryClassName = "com.sun.prism.es2.EGLFBGLFactory";
+ else if ("monocle".equals(PlatformUtil.getEmbeddedType()))
+ factoryClassName = "com.sun.prism.es2.MonocleGLFactory";
else
factoryClassName = "com.sun.prism.es2.X11GLFactory";
} else if (PlatformUtil.isWindows()) {
diff --git a/modules/graphics/src/main/java/com/sun/prism/es2/MonocleGLContext.java b/modules/graphics/src/main/java/com/sun/prism/es2/MonocleGLContext.java
new file mode 100644
index 0000000000..bcc119e7cb
--- /dev/null
+++ b/modules/graphics/src/main/java/com/sun/prism/es2/MonocleGLContext.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2014, 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 MonocleGLContext extends GLContext {
+
+ private static native long nInitialize(long nativeDInfo, long nativePFInfo,
+ boolean vSyncRequest);
+ private static native long nGetNativeHandle(long nativeCtxInfo);
+ private static native void nMakeCurrent(long nativeCtxInfo, long nativeDInfo);
+
+ MonocleGLContext(long nativeCtxInfo) {
+ this.nativeCtxInfo = nativeCtxInfo;
+ }
+
+ MonocleGLContext(GLDrawable drawable, GLPixelFormat pixelFormat,
+ boolean vSyncRequest) {
+
+ // holds the list of attributes to be translated for native call
+ int attrArr[] = new int[GLPixelFormat.Attributes.NUM_ITEMS];
+
+ GLPixelFormat.Attributes attrs = pixelFormat.getAttributes();
+
+ attrArr[GLPixelFormat.Attributes.RED_SIZE] = attrs.getRedSize();
+ attrArr[GLPixelFormat.Attributes.GREEN_SIZE] = attrs.getGreenSize();
+ attrArr[GLPixelFormat.Attributes.BLUE_SIZE] = attrs.getBlueSize();
+ attrArr[GLPixelFormat.Attributes.ALPHA_SIZE] = attrs.getAlphaSize();
+ attrArr[GLPixelFormat.Attributes.DEPTH_SIZE] = attrs.getDepthSize();
+ attrArr[GLPixelFormat.Attributes.DOUBLEBUFFER] = attrs.isDoubleBuffer() ? 1 : 0;
+ attrArr[GLPixelFormat.Attributes.ONSCREEN] = attrs.isOnScreen() ? 1 : 0;
+
+ // return the context info object created on the default screen
+ nativeCtxInfo = nInitialize(drawable.getNativeDrawableInfo(),
+ pixelFormat.getNativePFInfo(), vSyncRequest);
+ }
+
+ @Override
+ long getNativeHandle() {
+ return nGetNativeHandle(nativeCtxInfo);
+ }
+
+ @Override
+ void makeCurrent(GLDrawable drawable) {
+ nMakeCurrent(nativeCtxInfo, drawable.getNativeDrawableInfo());
+ }
+}
diff --git a/modules/graphics/src/main/java/com/sun/prism/es2/MonocleGLDrawable.java b/modules/graphics/src/main/java/com/sun/prism/es2/MonocleGLDrawable.java
new file mode 100644
index 0000000000..ec1557b057
--- /dev/null
+++ b/modules/graphics/src/main/java/com/sun/prism/es2/MonocleGLDrawable.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2014, 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;
+
+import com.sun.prism.paint.Color;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+
+class MonocleGLDrawable extends GLDrawable {
+
+ private static final boolean transparentFramebuffer =
+ AccessController.doPrivileged(new PrivilegedAction() {
+ @Override
+ public Boolean run() {
+ return Boolean.getBoolean("com.sun.javafx.transparentFramebuffer");
+ }
+ });
+
+ private static native long nCreateDrawable(long nativeWindow, long nativeCtxInfo);
+ private static native long nGetDummyDrawable(long nativeCtxInfo);
+ private static native boolean nSwapBuffers(long nativeDInfo);
+ boolean isDummy = false;
+
+ MonocleGLDrawable(GLPixelFormat pixelFormat) {
+
+ super(0L, pixelFormat);
+ long nDInfo = nGetDummyDrawable(pixelFormat.getNativePFInfo());
+ setNativeDrawableInfo(nDInfo);
+ isDummy = true;
+ }
+
+ MonocleGLDrawable(long nativeWindow, GLPixelFormat pixelFormat) {
+ super(nativeWindow, pixelFormat);
+ long nDInfo = nCreateDrawable(nativeWindow, pixelFormat.getNativePFInfo());
+ setNativeDrawableInfo(nDInfo);
+ }
+
+ @Override
+ boolean swapBuffers(GLContext glCtx) {
+ boolean retval = nSwapBuffers(getNativeDrawableInfo());
+ // TODO: This looks hacky. Need to find a better approach.
+ // For Monocle, we are painting in Z-order from the back,
+ // possibly (likely) with an app that does not cover the
+ // full screen. We need to start each paint with an empty canvas.
+ // The assumption here was that we would do that by clearing the buffer.
+ glCtx.clearBuffers(
+ transparentFramebuffer ? Color.TRANSPARENT : Color.BLACK,
+ true, true, true);
+ return retval;
+ }
+}
diff --git a/modules/graphics/src/main/java/com/sun/prism/es2/MonocleGLFactory.java b/modules/graphics/src/main/java/com/sun/prism/es2/MonocleGLFactory.java
new file mode 100644
index 0000000000..df92e95b73
--- /dev/null
+++ b/modules/graphics/src/main/java/com/sun/prism/es2/MonocleGLFactory.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2014, 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;
+
+import com.sun.glass.ui.monocle.NativePlatformFactory;
+import com.sun.prism.es2.GLPixelFormat.Attributes;
+import java.util.HashMap;
+import com.sun.glass.ui.monocle.EGL;
+import com.sun.glass.ui.monocle.NativeScreen;
+
+
+class MonocleGLFactory extends GLFactory {
+
+ private static native long nInitialize(int[] attrArr);
+ private static native int nGetAdapterOrdinal(long nativeScreen);
+ private static native int nGetAdapterCount();
+ private static native int nGetDefaultScreen(long nativeCtxInfo);
+ private static native long nGetDisplay(long nativeCtxInfo);
+ private static native long nGetVisualID(long nativeCtxInfo);
+ private static native boolean nGetIsGL2(long nativeCtxInfo);
+
+ // Entries must be in lowercase and null string is a wild card
+ // For Linux Beta release we will limit es2 pipe qualification check to NVidia GPUs only
+ private GLGPUInfo preQualificationFilter[] = null;
+ private GLGPUInfo blackList[] = null;
+
+ @Override
+ GLGPUInfo[] getPreQualificationFilter() {
+ return preQualificationFilter;
+ }
+
+ @Override
+ GLGPUInfo[] getBlackList() {
+ return blackList;
+ }
+
+ @Override
+ GLContext createGLContext(long nativeCtxInfo) {
+ return new MonocleGLContext(nativeCtxInfo);
+ }
+
+ @Override
+ GLContext createGLContext(GLDrawable drawable, GLPixelFormat pixelFormat,
+ GLContext shareCtx, boolean vSyncRequest) {
+ // No need to pass down shareCtx as we don't use shared ctx on Monocle
+ return new MonocleGLContext(drawable, pixelFormat, vSyncRequest);
+ }
+
+ @Override
+ GLDrawable createDummyGLDrawable(GLPixelFormat pixelFormat) {
+ return new MonocleGLDrawable(pixelFormat);
+ }
+
+ @Override
+ GLDrawable createGLDrawable(long nativeWindow, GLPixelFormat pixelFormat) {
+ return new MonocleGLDrawable(nativeWindow, pixelFormat);
+ }
+
+ @Override
+ GLPixelFormat createGLPixelFormat(long nativeScreen, Attributes attributes) {
+ return new MonocleGLPixelFormat(nativeScreen, attributes);
+ }
+
+ @Override
+ boolean initialize(Class psClass, Attributes attrs) {
+
+ // holds the list of attributes to be translated for native call
+ int attrArr[] = new int[GLPixelFormat.Attributes.NUM_ITEMS];
+
+ attrArr[GLPixelFormat.Attributes.RED_SIZE] = attrs.getRedSize();
+ attrArr[GLPixelFormat.Attributes.GREEN_SIZE] = attrs.getGreenSize();
+ attrArr[GLPixelFormat.Attributes.BLUE_SIZE] = attrs.getBlueSize();
+ attrArr[GLPixelFormat.Attributes.ALPHA_SIZE] = attrs.getAlphaSize();
+ attrArr[GLPixelFormat.Attributes.DEPTH_SIZE] = attrs.getDepthSize();
+ attrArr[GLPixelFormat.Attributes.DOUBLEBUFFER] = attrs.isDoubleBuffer() ? 1 : 0;
+ attrArr[GLPixelFormat.Attributes.ONSCREEN] = attrs.isOnScreen() ? 1 : 0;
+
+ // return the context info object create on the default screen
+ nativeCtxInfo = nInitialize(attrArr);
+
+ EGL.eglGetDisplay(NativePlatformFactory.getNativePlatform().
+ getScreen().platformGetNativeDisplay());
+
+ if (nativeCtxInfo == 0) {
+ // current pipe doesn't support this pixelFormat request
+ return false;
+ } else {
+ gl2 = nGetIsGL2(nativeCtxInfo);
+ return true;
+ }
+ }
+
+ @Override
+ int getAdapterCount() {
+ return nGetAdapterCount();
+ }
+
+ @Override
+ int getAdapterOrdinal(long nativeScreen) {
+ return nGetAdapterOrdinal(nativeScreen);
+ }
+
+ @Override
+ void updateDeviceDetails(HashMap deviceDetails) {
+ }
+}
diff --git a/modules/graphics/src/main/java/com/sun/prism/es2/MonocleGLPixelFormat.java b/modules/graphics/src/main/java/com/sun/prism/es2/MonocleGLPixelFormat.java
new file mode 100644
index 0000000000..82e097c7db
--- /dev/null
+++ b/modules/graphics/src/main/java/com/sun/prism/es2/MonocleGLPixelFormat.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2014, 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;
+
+import com.sun.glass.ui.monocle.EGL;
+import com.sun.glass.ui.monocle.NativeScreen;
+import com.sun.glass.ui.monocle.NativePlatformFactory;
+
+class MonocleGLPixelFormat extends GLPixelFormat {
+
+ private static native long nCreatePixelFormat(long nativeScreen, int[] attrArr);
+ MonocleGLPixelFormat(long nativeScreen, Attributes attrs) {
+ super(nativeScreen, attrs);
+
+ // holds the list of attributes to be translated for native call
+ int attrArr[] = new int[GLPixelFormat.Attributes.NUM_ITEMS];
+
+ //System.err.println("Attributes = " + attrs);
+
+ attrArr[GLPixelFormat.Attributes.RED_SIZE] = attrs.getRedSize();
+ attrArr[GLPixelFormat.Attributes.GREEN_SIZE] = attrs.getGreenSize();
+ attrArr[GLPixelFormat.Attributes.BLUE_SIZE] = attrs.getBlueSize();
+ attrArr[GLPixelFormat.Attributes.ALPHA_SIZE] = attrs.getAlphaSize();
+ attrArr[GLPixelFormat.Attributes.DEPTH_SIZE] = attrs.getDepthSize();
+ attrArr[GLPixelFormat.Attributes.DOUBLEBUFFER] = attrs.isDoubleBuffer() ? 1 : 0;
+ attrArr[GLPixelFormat.Attributes.ONSCREEN] = attrs.isOnScreen() ? 1 : 0;
+
+ //long nativeDisplay = NativeScreen.getNativeDisplay();
+ long nativeDisplay = NativePlatformFactory.getNativePlatform().
+ getScreen().platformGetNativeDisplay();
+
+ long nativePF = nCreatePixelFormat(nativeScreen, attrArr);
+ setNativePFInfo(nativePF);
+
+ }
+}
diff --git a/modules/graphics/src/main/native-glass/monocle/EGL.c b/modules/graphics/src/main/native-glass/monocle/EGL.c
new file mode 100644
index 0000000000..450f0a24f8
--- /dev/null
+++ b/modules/graphics/src/main/native-glass/monocle/EGL.c
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2014, 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.
+ */
+
+#include
+
+#include "com_sun_glass_ui_monocle_EGL.h"
+#include "Monocle.h"
+
+JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_monocle_EGL_eglGetDisplay
+ (JNIEnv *env, jclass class, jlong display) {
+ EGLDisplay dpy = eglGetDisplay(display);
+ return asJLong(dpy);
+}
+
diff --git a/modules/graphics/src/main/native-prism-es2/monocle/MonocleGLContext.c b/modules/graphics/src/main/native-prism-es2/monocle/MonocleGLContext.c
new file mode 100644
index 0000000000..c63f2ebd5a
--- /dev/null
+++ b/modules/graphics/src/main/native-prism-es2/monocle/MonocleGLContext.c
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2014, 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.
+ */
+
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include "eglUtils.h"
+
+#include "../PrismES2Defs.h"
+#include "com_sun_prism_es2_EGLFBGLContext.h"
+
+/*
+ * Class: com_sun_prism_es2_EGLFBGLContext
+ * Method: nInitialize
+ * Signature: (JJZ)J
+ */
+JNIEXPORT jlong JNICALL Java_com_sun_prism_es2_EGLFBGLContext_nInitialize
+(JNIEnv *env, jclass jeglfbcontext, jlong nativeDInfo, jlong nativePFInfo, jboolean SyncRequest) {
+ DrawableInfo *dInfo = (DrawableInfo *) jlong_to_ptr(nativeDInfo);
+ PixelFormatInfo *pfInfo = (PixelFormatInfo *) jlong_to_ptr(nativePFInfo);
+
+ if ((dInfo == NULL) || (pfInfo == NULL)) {
+ fprintf(stderr, "EGLFBGLContext_nInitialize: null dInfo pfInfo\n");
+ return 0;
+ }
+ EGLConfig fbConfig = pfInfo->fbConfig;
+
+ ContextInfo *ctxInfo = eglContextFromConfig(dInfo->egldisplay, fbConfig);
+ return ptr_to_jlong(ctxInfo);
+}
+
+/*
+ * Class: com_sun_prism_es2_EGLFBGLContext
+ * Method: nGetNativeHandle
+ * Signature: (J)J
+ */
+JNIEXPORT jlong JNICALL Java_com_sun_prism_es2_EGLFBGLContext_nGetNativeHandle
+(JNIEnv *env, jclass jeglfbcontext, jlong nativeCtxInfo) {
+ ContextInfo *ctxInfo = (ContextInfo *) jlong_to_ptr(nativeCtxInfo);
+ if (ctxInfo == NULL) {
+ fprintf(stderr, " nGetNativeHandle, ContextInfo is null\n");
+ return 0;
+ }
+ return ptr_to_jlong(ctxInfo->context);
+}
+
+/*
+ * Class: com_sun_prism_es2_EGLFBGLContext
+ * Method: nMakeCurrent
+ * Signature: (JJ)V
+ */
+JNIEXPORT void JNICALL Java_com_sun_prism_es2_EGLFBGLContext_nMakeCurrent
+(JNIEnv *env, jclass jeglfbcontext, jlong nativeCtxInfo, jlong nativeDInfo) {
+
+ DrawableInfo *dInfo = (DrawableInfo *) jlong_to_ptr(nativeDInfo);
+ if (dInfo == NULL) {
+ fprintf(stderr, "nMakeCurrent: dIfno is null!!!\n");
+ return;
+ }
+
+ ContextInfo *ctxInfo = (ContextInfo *) jlong_to_ptr(nativeCtxInfo);
+ if (ctxInfo == NULL) {
+ fprintf(stderr, "nMakeCurrent: ctxInfo is null!!!\n");
+ return;
+ }
+ int interval;
+ jboolean vSyncNeeded;
+
+ if (!eglMakeCurrent(dInfo->egldisplay, dInfo->eglsurface,
+ dInfo->eglsurface, ctxInfo->context)) {
+ fprintf(stderr, "Failed in eglMakeCurrent for %p %p %d\n",
+ dInfo->eglsurface, ctxInfo->context, eglGetError());
+ }
+ vSyncNeeded = ctxInfo->vSyncRequested && dInfo->onScreen;
+ if (vSyncNeeded == ctxInfo->state.vSyncEnabled) {
+ return;
+ }
+
+ return;
+
+}
+
diff --git a/modules/graphics/src/main/native-prism-es2/monocle/MonocleGLDrawable.c b/modules/graphics/src/main/native-prism-es2/monocle/MonocleGLDrawable.c
new file mode 100644
index 0000000000..e6b8b25f05
--- /dev/null
+++ b/modules/graphics/src/main/native-prism-es2/monocle/MonocleGLDrawable.c
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2014, 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.
+ */
+
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include "eglUtils.h"
+
+#include "com_sun_prism_es2_EGLFBGLContext.h"
+
+extern void initializeDrawableInfo(DrawableInfo *dInfo);
+extern void deleteDrawableInfo(DrawableInfo *dInfo);
+
+/*
+ * Class: com_sun_prism_es2_EGLFBGLDrawable
+ * Method: nCreateDrawable
+ * Signature: (JJ)J
+ */
+JNIEXPORT jlong JNICALL Java_com_sun_prism_es2_EGLFBGLDrawable_nCreateDrawable
+(JNIEnv *env, jclass jeglfbDrawable, jlong nativeWindow, jlong nativePFInfo) {
+ DrawableInfo *dInfo = NULL;
+ PixelFormatInfo *pfInfo = (PixelFormatInfo *) jlong_to_ptr(nativePFInfo);
+ if (pfInfo == NULL) {
+ fprintf(stderr, "nCreateDrawable: PixelFormatInfo null\n");
+ return 0;
+ }
+ /* allocate the structure */
+ dInfo = (DrawableInfo *) malloc(sizeof(DrawableInfo));
+ if (dInfo == NULL) {
+ fprintf(stderr, "nCreateDrawable: Failed in malloc\n");
+ return 0;
+ }
+
+ /* initialize the structure */
+ initializeDrawableInfo(dInfo);
+ dInfo->egldisplay = eglGetDisplay(getNativeDisplayType());
+ dInfo->eglsurface = getSharedWindowSurface(dInfo->egldisplay,
+ pfInfo->fbConfig,
+ jlong_to_ptr(nativeWindow));
+ dInfo->onScreen = JNI_TRUE;
+
+ return ptr_to_jlong(dInfo);
+}
+
+/*
+ * Class: com_sun_prism_es2_EGLFBGLDrawable
+ * Method: nGetDummyDrawable
+ * Signature: (J)J
+ */
+JNIEXPORT jlong JNICALL Java_com_sun_prism_es2_EGLFBGLDrawable_nGetDummyDrawable
+(JNIEnv *env, jclass jeglfbDrawable, jlong nativePFInfo) {
+ DrawableInfo *dInfo = NULL;
+ PixelFormatInfo *pfInfo = (PixelFormatInfo *) jlong_to_ptr(nativePFInfo);
+ if (pfInfo == NULL) {
+ fprintf(stderr, " GetDummyDrawable, PixelFormatInfo is null\n");
+ return 0;
+ }
+
+ /* allocate the structure */
+ dInfo = (DrawableInfo *) malloc(sizeof(DrawableInfo));
+ if (dInfo == NULL) {
+ fprintf(stderr, "nGetDummyDrawable: Failed in malloc\n");
+ return 0;
+ }
+
+ /* initialize the structure */
+ initializeDrawableInfo(dInfo);
+ dInfo->egldisplay =
+ eglGetDisplay(getNativeDisplayType());
+ dInfo->onScreen = JNI_FALSE;
+ dInfo->eglsurface = getDummyWindowSurface(pfInfo->display,
+ pfInfo->fbConfig);
+
+ return ptr_to_jlong(dInfo);
+}
+
+/*
+ * Class: com_sun_prism_es2_EGLFBGLDrawable
+ * Method: nSwapBuffers
+ * Signature: (J)Z
+ */
+JNIEXPORT jboolean JNICALL Java_com_sun_prism_es2_EGLFBGLDrawable_nSwapBuffers
+(JNIEnv *env, jclass jeglfbDrawable, jlong nativeDInfo) {
+ int value;
+
+ DrawableInfo *dInfo = (DrawableInfo *) jlong_to_ptr(nativeDInfo);
+ if (dInfo == NULL) {
+ return JNI_FALSE;
+ }
+ if (!eglSwapBuffers(dInfo->egldisplay, dInfo->eglsurface)) {
+ fprintf(stderr, "eglSwapBuffers failed; eglGetError %d\n", eglGetError());
+ }
+ return JNI_TRUE;
+}
+
diff --git a/modules/graphics/src/main/native-prism-es2/monocle/MonocleGLFactory.c b/modules/graphics/src/main/native-prism-es2/monocle/MonocleGLFactory.c
new file mode 100644
index 0000000000..2441fc762b
--- /dev/null
+++ b/modules/graphics/src/main/native-prism-es2/monocle/MonocleGLFactory.c
@@ -0,0 +1,182 @@
+/*
+ * Copyright (c) 2014, 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.
+ */
+
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include "eglUtils.h"
+
+#include "../PrismES2Defs.h"
+
+#include "com_sun_prism_es2_EGLFBGLContext.h"
+
+/*
+ * Class: com_sun_prism_es2_EGLFBGLFactory
+ * Method: nInitialize
+ * Signature: ([I)J
+ */
+JNIEXPORT jlong JNICALL Java_com_sun_prism_es2_MonocleGLFactory_nInitialize
+(JNIEnv *env, jclass jeglfbGLFactory, jintArray attrArr) {
+ int eglAttrs[MAX_GLX_ATTRS_LENGTH]; /* value, attr pair plus a None */
+ jint *attrs;
+
+ if (attrArr == NULL) {
+ return 0;
+ }
+ return 0;
+/*
+ attrs = (*env)->GetIntArrayElements(env, attrArr, NULL);
+ setEGLAttrs(attrs, eglAttrs);
+ (*env)->ReleaseIntArrayElements(env, attrArr, attrs, JNI_ABORT);
+
+ EGLint surfaceType;
+ EGLConfig config = 0;
+ EGLint numconfigs = 0;
+ EGLint configId = 0;
+
+ EGLDisplay egldisplay = eglGetDisplay(getNativeDisplayType());
+ if (EGL_NO_DISPLAY == egldisplay) {
+ fprintf(stderr, "eglGetDisplay returned EGL_NO_DISPLAY");
+ // cleanup
+ return 0;
+ }
+ EGLint egl_major, egl_minor;
+ if (!eglInitialize(egldisplay, &egl_major, &egl_minor)) {
+ fprintf(stderr, "eglInitialize failed!");
+ // cleanup
+ return 0;
+ }
+
+ if (!eglBindAPI(EGL_OPENGL_ES_API)) {
+ fprintf(stderr, "eglBindAPI failed!");
+ return 0;
+ }
+
+#ifdef DEBUG
+ // This is the client side
+ const char *eglVendor = eglQueryString(egldisplay, EGL_VENDOR);
+ const char *eglVersion = eglQueryString(egldisplay, EGL_VERSION);
+ printf("EGL_VENDOR is %s\n", eglVendor);
+ printf("EGL_VERSION version is %s\n", eglVersion);
+ printf("Requested EGL attributes:\n");
+ printConfigAttrs(eglAttrs);
+#endif
+
+ if (!eglChooseConfig(egldisplay, eglAttrs, &config, 1, &numconfigs)) {
+ fprintf(stderr, "Failed to get a FBconfig with requested attrs\n");
+ //cleanup
+ return 0;
+ }
+
+#ifdef DEBUG
+ printf("eglChooseConfig return %d configs\n", numconfigs);
+#endif
+
+ if (!eglGetConfigAttrib(egldisplay, config, EGL_CONFIG_ID, &configId)) {
+ fprintf(stderr, "eglGetConfigAttrib failed!");
+ return 0;
+ }
+
+#ifdef DEBUG
+ printf("EGL: Using config #%d\n", configId);
+ printConfig(egldisplay, config);
+#endif
+
+ ContextInfo *ctxInfo = eglContextFromConfig(egldisplay, config);
+ if (!ctxInfo) {
+ fprintf(stderr, "Failed to create EGLContext");
+ return 0; // cleanup
+ }
+ // Information required by GLass at startup
+ ctxInfo->display = getNativeDisplayType();
+ ctxInfo->gl2 = JNI_FALSE;
+ eglDestroyContext(ctxInfo->egldisplay, ctxInfo->context);
+ return ptr_to_jlong(ctxInfo);
+ */
+}
+
+/*
+ * Class: com_sun_prism_es2_EGLFBGLFactory
+ * Method: nGetAdapterOrdinal
+ * Signature: (J)I
+ */
+JNIEXPORT jint JNICALL Java_com_sun_prism_es2_EGLFBGLFactory_nGetAdapterOrdinal
+(JNIEnv *env, jclass jeglfbGLFactory, jlong nativeScreen) {
+ return 0;
+}
+
+/*
+ * Class: com_sun_prism_es2_EGLFBGLFactory
+ * Method: nGetAdapterCount
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_com_sun_prism_es2_EGLFBGLFactory_nGetAdapterCount
+(JNIEnv *env, jclass jeglfbGLFactory) {
+ return 1;
+}
+
+/*
+ * Class: com_sun_prism_es2_EGLFBGLFactory
+ * Method: nGetDefaultScreen
+ * Signature: (J)I
+ */
+JNIEXPORT jint JNICALL Java_com_sun_prism_es2_EGLFBGLFactory_nGetDefaultScreen
+(JNIEnv *env, jclass jeglfbGLFactory, jlong nativeCtxInfo) {
+ return 0;
+}
+
+/*
+ * Class: com_sun_prism_es2_EGLFBGLFactory
+ * Method: nGetDisplay
+ * Signature: (J)J
+ */
+JNIEXPORT jlong JNICALL Java_com_sun_prism_es2_EGLFBGLFactory_nGetDisplay
+(JNIEnv *env, jclass jeglfbGLFactory, jlong nativeCtxInfo) {
+ return 0;
+}
+
+/*
+ * Class: com_sun_prism_es2_EGLFBGLFactory
+ * Method: nGetVisualID
+ * Signature: (J)J
+ */
+JNIEXPORT jlong JNICALL Java_com_sun_prism_es2_EGLFBGLFactory_nGetVisualID
+(JNIEnv *env, jclass jeglfbGLFactory, jlong nativeCtxInfo) {
+ return 0;
+}
+
+/*
+ * Class: com_sun_prism_es2_EGLFBGLFactory
+ * Method: nGetIsGL2
+ * Signature: (J)Z
+ */
+JNIEXPORT jboolean JNICALL Java_com_sun_prism_es2_EGLFBGLFactory_nGetIsGL2
+(JNIEnv *env, jclass class, jlong nativeCtxInfo) {
+ return ((ContextInfo *)jlong_to_ptr(nativeCtxInfo))->gl2;
+}
diff --git a/modules/graphics/src/main/native-prism-es2/monocle/MonoclePixelFormat.c b/modules/graphics/src/main/native-prism-es2/monocle/MonoclePixelFormat.c
new file mode 100644
index 0000000000..0b92afdb40
--- /dev/null
+++ b/modules/graphics/src/main/native-prism-es2/monocle/MonoclePixelFormat.c
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2014, 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.
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include "../PrismES2Defs.h"
+
+#include
+
+#include "eglUtils.h"
+
+#include "com_sun_prism_es2_EGLFBGLPixelFormat.h"
+
+/*
+ * Class: com_sun_prism_es2_EGLFBGLPixelFormat
+ * Method: nCreatePixelFormat
+ * Signature: (J[I)J
+ */
+JNIEXPORT jlong JNICALL Java_com_sun_prism_es2_EGLFBGLPixelFormat_nCreatePixelFormat
+(JNIEnv *env, jclass jeglfbPixelFormat, jlong nativeScreen, jintArray attrArr) {
+ int eglAttrs[MAX_GLX_ATTRS_LENGTH]; /* value, attr pair plus a None */
+ jint *attrs;
+ PixelFormatInfo *pfInfo = NULL;
+
+ EGLConfig config;
+ int numFBConfigs;
+
+ if (attrArr == NULL) {
+ return 0;
+ }
+ attrs = (*env)->GetIntArrayElements(env, attrArr, NULL);
+ setEGLAttrs(attrs, eglAttrs);
+ (*env)->ReleaseIntArrayElements(env, attrArr, attrs, JNI_ABORT);
+
+ EGLDisplay egldisplay = eglGetDisplay(getNativeDisplayType());
+ if (EGL_NO_DISPLAY == egldisplay) {
+ fprintf(stderr, "eglGetDisplay returned EGL_NO_DISPLAY");
+ return 0;
+ }
+
+ if (!eglInitialize(egldisplay, NULL, NULL)) {
+ fprintf(stderr, "eglInitialize failed!");
+ return 0;
+ }
+
+#ifdef DEBUG
+ printf("Requested EGL attributes:\n");
+ printConfigAttrs(eglAttrs);
+#endif
+
+ if (!eglChooseConfig(egldisplay, eglAttrs, &config, 1, &numFBConfigs)) {
+ fprintf(stderr, "PixelFormat - Failed to get a FBconfig with requested attrs\n");
+ //cleanup
+ return 0;
+ }
+#ifdef DEBUG
+ printf("EGL: Using config\n");
+ printConfig(egldisplay, config);
+#endif
+
+ /* allocate the structure */
+ pfInfo = (PixelFormatInfo *) malloc(sizeof(PixelFormatInfo));
+ if (pfInfo == NULL) {
+ fprintf(stderr, "nCreatePixelFormat: Failed in malloc\n");
+ return 0;
+ }
+
+ /* initialize the structure */
+ initializePixelFormatInfo(pfInfo);
+ pfInfo->fbConfig = config;
+
+ return ptr_to_jlong(pfInfo);
+}
+
diff --git a/modules/graphics/src/main/native-prism-es2/monocle/eglUtils.c b/modules/graphics/src/main/native-prism-es2/monocle/eglUtils.c
new file mode 100644
index 0000000000..9f624bd076
--- /dev/null
+++ b/modules/graphics/src/main/native-prism-es2/monocle/eglUtils.c
@@ -0,0 +1,588 @@
+/*
+ * Copyright (c) 2014, 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.
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "../PrismES2Defs.h"
+
+#include "eglUtils.h"
+
+#include "eglfb/wrapped_egl.h"
+
+#ifdef EGL_X11_FB_CONTAINER
+#include "X11/Xlib.h"
+#endif
+
+#define WARN_MISSING_SYMBOLS 0
+
+void *get_dlsym(void *handle, const char *symbol, int warn) {
+ void *ret = dlsym(handle, symbol);
+ if (!ret && warn) {
+ fprintf(stderr, "ERROR: could not find symbol for %s\n", symbol);
+ }
+ return ret;
+}
+
+#define GET_DLSYM(handle,symbol) get_dlsym(handle,symbol, WARN_MISSING_SYMBOLS);
+
+EGLSurface sharedWindowSurface = NULL;
+#ifdef ANDROID_NDK
+EGLNativeWindowType currentNativeWindow = NULL;
+#endif
+#ifdef EGL_X11_FB_CONTAINER
+EGLSurface dummySurface = NULL;
+#endif
+
+EGLSurface getDummyWindowSurface(EGLDisplay dpy, EGLConfig cfg) {
+#ifdef EGL_X11_FB_CONTAINER
+ if (dummySurface == NULL) {
+ Display *display;
+ Window window;
+
+ display = XOpenDisplay(0);
+ if (display == NULL) {
+ fprintf(stderr, "XOpenDisplay failed\n");
+ return 0;
+ }
+ window = XCreateWindow(display,
+ RootWindow(display, DefaultScreen(display)),
+ 0, 0, 1, 1, 0,
+ CopyFromParent, InputOutput, CopyFromParent, 0,
+ (XSetWindowAttributes *) 0);
+ XSync(display, False);
+ dummySurface = eglCreateWindowSurface(dpy, cfg, window, NULL);
+ XSync(display, False);
+ }
+ return dummySurface;
+#else
+ return getSharedWindowSurface(dpy, cfg, NULL);
+#endif
+}
+
+EGLSurface getSharedWindowSurface(EGLDisplay dpy,
+ EGLConfig cfg,
+ void *nativeWindow) {
+ if (sharedWindowSurface == NULL) {
+ EGLNativeWindowType window = 0;
+#if EGL_X11_FB_CONTAINER
+ window = (EGLNativeWindowType)nativeWindow;
+#else
+ if (nativeWindow == NULL) {
+ window = getNativeWindowType();
+ }
+#endif
+ sharedWindowSurface = eglCreateWindowSurface(dpy, cfg, window, NULL);
+ if (sharedWindowSurface == EGL_NO_SURFACE) {
+ fprintf(stderr, "eglCreateWindowSurface failed! eglGetError %d\n", eglGetError());
+ return 0;
+ }
+#ifdef ANDROID_NDK
+ currentNativeWindow = window;
+#endif
+ return sharedWindowSurface;
+ }
+#ifdef ANDROID_NDK
+ EGLNativeWindowType wnd = getNativeWindowType();
+ if (currentNativeWindow != wnd) {
+ sharedWindowSurface = eglCreateWindowSurface(dpy, cfg, wnd, NULL);
+ if (sharedWindowSurface == EGL_NO_SURFACE) {
+ fprintf(stderr, "Recreating eglSurface: eglCreateWindowSurface failed! eglGetError %d\n", eglGetError());
+ return 0;
+ }
+ currentNativeWindow = wnd;
+ }
+#endif
+ return sharedWindowSurface;
+}
+
+void setEGLAttrs(jint *attrs, int *eglAttrs) {
+ int index = 0;
+
+ eglAttrs[index++] = EGL_SURFACE_TYPE;
+ if (attrs[ONSCREEN] != 0) {
+ eglAttrs[index++] = (EGL_WINDOW_BIT);
+ } else {
+ eglAttrs[index++] = EGL_PBUFFER_BIT;
+ }
+
+ // NOTE: EGL_TRANSPARENT_TYPE ?
+
+ if (attrs[RED_SIZE] == 5 && attrs[GREEN_SIZE] == 6
+ && attrs[BLUE_SIZE] == 5 && attrs[ALPHA_SIZE] == 0) {
+ // Optimization for Raspberry Pi model B. Even though the result
+ // of setting EGL_BUFFER_SIZE to 16 should be the same as setting
+ // component sizes separately, we get less per-frame overhead if we
+ // only set EGL_BUFFER_SIZE.
+ eglAttrs[index++] = EGL_BUFFER_SIZE;
+ eglAttrs[index++] = 16;
+ } else {
+ eglAttrs[index++] = EGL_RED_SIZE;
+ eglAttrs[index++] = attrs[RED_SIZE];
+ eglAttrs[index++] = EGL_GREEN_SIZE;
+ eglAttrs[index++] = attrs[GREEN_SIZE];
+ eglAttrs[index++] = EGL_BLUE_SIZE;
+ eglAttrs[index++] = attrs[BLUE_SIZE];
+ eglAttrs[index++] = EGL_ALPHA_SIZE;
+ eglAttrs[index++] = attrs[ALPHA_SIZE];
+ }
+
+ eglAttrs[index++] = EGL_DEPTH_SIZE;
+ eglAttrs[index++] = attrs[DEPTH_SIZE];
+ eglAttrs[index++] = EGL_RENDERABLE_TYPE;
+ eglAttrs[index++] = EGL_OPENGL_ES2_BIT;
+ eglAttrs[index] = EGL_NONE;
+}
+
+ContextInfo *eglContextFromConfig(EGLDisplay *dpy, EGLConfig config) {
+
+ EGLSurface surface = getDummyWindowSurface(dpy, config);
+
+ EGLint contextAttrs[] = {
+ EGL_CONTEXT_CLIENT_VERSION, 2,
+ EGL_NONE
+ };
+
+ EGLContext context = eglCreateContext(dpy, config, NULL, contextAttrs);
+ if (context == EGL_NO_CONTEXT) {
+ fprintf(stderr, "eglCreateContext() failed - %d\n", eglGetError());
+ return 0;
+ }
+
+ if (!eglMakeCurrent(dpy, surface, surface, context)) {
+ fprintf(stderr, "eglMakeCurrent failed - %d\n", eglGetError());
+ return 0;
+ }
+ ContextInfo *ctxInfo = NULL;
+
+ /* Note: We are only storing the string information of a driver.
+ Assuming a system with a single or homogeneous GPUs. For the case
+ of heterogeneous GPUs system the string information will need to move to
+ GLContext class. */
+ /* allocate the structure */
+ ctxInfo = (ContextInfo *) malloc(sizeof(ContextInfo));
+ if (ctxInfo == NULL) {
+ fprintf(stderr, "nInitialize: Failed in malloc\n");
+ return 0;
+ }
+ /* initialize the structure */
+ initializeCtxInfo(ctxInfo);
+
+ const char *glVersion = (char *)glGetString(GL_VERSION);
+ const char *glVendor = (char *)glGetString(GL_VENDOR);
+ const char *glRenderer = (char *)glGetString(GL_RENDERER);
+ // Make a copy, at least one platform does not preserve the string beyond the call.
+ char *glExtensions = strdup((char *)glGetString(GL_EXTENSIONS));
+ char *eglExtensions = strdup((char *)eglQueryString(dpy, EGL_EXTENSIONS));
+
+ /* find out the version, major and minor version number */
+ char *tmpVersionStr = strdup(glVersion);
+ int versionNumbers[2];
+ extractVersionInfo(tmpVersionStr, versionNumbers);
+ free(tmpVersionStr);
+
+ ctxInfo->versionStr = strdup(glVersion);
+ ctxInfo->vendorStr = strdup(glVendor);
+ ctxInfo->rendererStr = strdup(glRenderer);
+ ctxInfo->glExtensionStr = strdup(glExtensions);
+ ctxInfo->glxExtensionStr = strdup(eglExtensions);
+ ctxInfo->versionNumbers[0] = versionNumbers[0];
+ ctxInfo->versionNumbers[1] = versionNumbers[1];
+
+ ctxInfo->display = getNativeDisplayType();
+ ctxInfo->context = context;
+ ctxInfo->egldisplay = dpy;
+
+ // cleanup
+ free(glExtensions);
+ free(eglExtensions);
+
+ // from the wrapped_egl.c
+ void *handle = getLibGLEShandle();
+
+ /* set function pointers */
+ ctxInfo->glActiveTexture = (PFNGLACTIVETEXTUREPROC)
+ GET_DLSYM(handle, "glActiveTexture");
+ ctxInfo->glAttachShader = (PFNGLATTACHSHADERPROC)
+ GET_DLSYM(handle, "glAttachShader");
+ ctxInfo->glBindAttribLocation = (PFNGLBINDATTRIBLOCATIONPROC)
+ GET_DLSYM(handle, "glBindAttribLocation");
+ ctxInfo->glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)
+ GET_DLSYM(handle, "glBindFramebuffer");
+ ctxInfo->glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC)
+ GET_DLSYM(handle, "glBindRenderbuffer");
+ ctxInfo->glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)
+ GET_DLSYM(handle, "glCheckFramebufferStatus");
+ ctxInfo->glCreateProgram = (PFNGLCREATEPROGRAMPROC)
+ GET_DLSYM(handle, "glCreateProgram");
+ ctxInfo->glCreateShader = (PFNGLCREATESHADERPROC)
+ GET_DLSYM(handle, "glCreateShader");
+ ctxInfo->glCompileShader = (PFNGLCOMPILESHADERPROC)
+ GET_DLSYM(handle, "glCompileShader");
+ ctxInfo->glDeleteBuffers = (PFNGLDELETEBUFFERSPROC)
+ GET_DLSYM(handle, "glDeleteBuffers");
+ ctxInfo->glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)
+ GET_DLSYM(handle, "glDeleteFramebuffers");
+ ctxInfo->glDeleteProgram = (PFNGLDELETEPROGRAMPROC)
+ GET_DLSYM(handle, "glDeleteProgram");
+ ctxInfo->glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC)
+ GET_DLSYM(handle, "glDeleteRenderbuffers");
+ ctxInfo->glDeleteShader = (PFNGLDELETESHADERPROC)
+ GET_DLSYM(handle, "glDeleteShader");
+ ctxInfo->glDetachShader = (PFNGLDETACHSHADERPROC)
+ GET_DLSYM(handle, "glDetachShader");
+ ctxInfo->glDisableVertexAttribArray = (PFNGLDISABLEVERTEXATTRIBARRAYPROC)
+ GET_DLSYM(handle, "glDisableVertexAttribArray");
+ ctxInfo->glEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC)
+ GET_DLSYM(handle, "glEnableVertexAttribArray");
+ ctxInfo->glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC)
+ GET_DLSYM(handle, "glFramebufferRenderbuffer");
+ ctxInfo->glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)
+ GET_DLSYM(handle, "glFramebufferTexture2D");
+ ctxInfo->glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)
+ GET_DLSYM(handle, "glGenFramebuffers");
+ ctxInfo->glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC)
+ GET_DLSYM(handle, "glGenRenderbuffers");
+ ctxInfo->glGetProgramiv = (PFNGLGETPROGRAMIVPROC)
+ GET_DLSYM(handle, "glGetProgramiv");
+ ctxInfo->glGetShaderiv = (PFNGLGETSHADERIVPROC)
+ GET_DLSYM(handle, "glGetShaderiv");
+ ctxInfo->glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC)
+ GET_DLSYM(handle, "glGetUniformLocation");
+ ctxInfo->glLinkProgram = (PFNGLLINKPROGRAMPROC)
+ GET_DLSYM(handle, "glLinkProgram");
+ ctxInfo->glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC)
+ GET_DLSYM(handle, "glRenderbufferStorage");
+ ctxInfo->glShaderSource = (PFNGLSHADERSOURCEPROC)
+ GET_DLSYM(handle, "glShaderSource");
+ ctxInfo->glUniform1f = (PFNGLUNIFORM1FPROC)
+ GET_DLSYM(handle, "glUniform1f");
+ ctxInfo->glUniform2f = (PFNGLUNIFORM2FPROC)
+ GET_DLSYM(handle, "glUniform2f");
+ ctxInfo->glUniform3f = (PFNGLUNIFORM3FPROC)
+ GET_DLSYM(handle, "glUniform3f");
+ ctxInfo->glUniform4f = (PFNGLUNIFORM4FPROC)
+ GET_DLSYM(handle, "glUniform4f");
+ ctxInfo->glUniform4fv = (PFNGLUNIFORM4FVPROC)
+ GET_DLSYM(handle, "glUniform4fv");
+ ctxInfo->glUniform1i = (PFNGLUNIFORM1IPROC)
+ GET_DLSYM(handle, "glUniform1i");
+ ctxInfo->glUniform2i = (PFNGLUNIFORM2IPROC)
+ GET_DLSYM(handle, "glUniform2i");
+ ctxInfo->glUniform3i = (PFNGLUNIFORM3IPROC)
+ GET_DLSYM(handle, "glUniform3i");
+ ctxInfo->glUniform4i = (PFNGLUNIFORM4IPROC)
+ GET_DLSYM(handle, "glUniform4i");
+ ctxInfo->glUniform4iv = (PFNGLUNIFORM4IVPROC)
+ GET_DLSYM(handle, "glUniform4iv");
+ ctxInfo->glUniformMatrix4fv = (PFNGLUNIFORMMATRIX4FVPROC)
+ GET_DLSYM(handle, "glUniformMatrix4fv");
+ ctxInfo->glUseProgram = (PFNGLUSEPROGRAMPROC)
+ GET_DLSYM(handle, "glUseProgram");
+ ctxInfo->glValidateProgram = (PFNGLVALIDATEPROGRAMPROC)
+ GET_DLSYM(handle, "glValidateProgram");
+ ctxInfo->glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC)
+ GET_DLSYM(handle, "glVertexAttribPointer");
+ ctxInfo->glGenBuffers = (PFNGLGENBUFFERSPROC)
+ GET_DLSYM(handle, "glGenBuffers");
+ ctxInfo->glBindBuffer = (PFNGLBINDBUFFERPROC)
+ GET_DLSYM(handle, "glBindBuffer");
+ ctxInfo->glBufferData = (PFNGLBUFFERDATAPROC)
+ GET_DLSYM(handle, "glBufferData");
+ ctxInfo->glBufferSubData = (PFNGLBUFFERSUBDATAPROC)
+ GET_DLSYM(handle, "glBufferSubData");
+ ctxInfo->glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC)
+ GET_DLSYM(handle, "glGetShaderInfoLog");
+ ctxInfo->glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC)
+ GET_DLSYM(handle, "glGetProgramInfoLog");
+ ctxInfo->glTexImage2DMultisample = (PFNGLTEXIMAGE2DMULTISAMPLEPROC)
+ GET_DLSYM(handle, "glTexImage2DMultisample");
+ ctxInfo->glRenderbufferStorageMultisample = (PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC)
+ GET_DLSYM(handle, "glRenderbufferStorageMultisample");
+ ctxInfo->glBlitFramebuffer = (PFNGLBLITFRAMEBUFFERPROC)
+ GET_DLSYM(handle, "glBlitFramebuffer");
+
+ initState(ctxInfo);
+ /* Releasing native resources */
+ eglMakeCurrent(ctxInfo->egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ //eglDestroySurface(ctxInfo->egldisplay, surface);
+ return ctxInfo;
+}
+
+
+
+//#ifdef DEBUG
+
+const char *eglErrorMsg(int err) {
+ const char *ret;
+ if (err == EGL_SUCCESS) {
+ ret = "The last function succeeded without error.";
+ } else if (err == EGL_NOT_INITIALIZED) {
+ ret = "EGL is not initialized, or could not be initialized, for the specified EGL display connection.";
+ } else if (err == EGL_BAD_ACCESS) {
+ ret = "EGL cannot access a requested resource (for example a context is bound in another thread).";
+ } else if (err == EGL_BAD_ALLOC) {
+ ret = "EGL failed to allocate resources for the requested operation.";
+ } else if (err == EGL_BAD_ATTRIBUTE) {
+ ret = "An unrecognized attribute or attribute value was passed in the attribute list.";
+ } else if (err == EGL_BAD_CONTEXT) {
+ ret = "An EGLContext argument does not name a valid EGL rendering context.";
+ } else if (err == EGL_BAD_CONFIG) {
+ ret = "An EGLConfig argument does not name a valid EGL frame buffer configuration.";
+ } else if (err == EGL_BAD_CURRENT_SURFACE) {
+ ret = "The current surface of the calling thread is a window, pixel buffer or pixmap that is no longer valid.";
+ } else if (err == EGL_BAD_DISPLAY) {
+ ret = "An EGLDisplay argument does not name a valid EGL display connection.";
+ } else if (err == EGL_BAD_SURFACE) {
+ ret = "An EGLSurface argument does not name a valid surface (window, pixel buffer or pixmap) configured for GL rendering.";
+ } else if (err == EGL_BAD_MATCH) {
+ ret = "Arguments are inconsistent (for example, a valid context requires buffers not supplied by a valid surface).";
+ } else if (err == EGL_BAD_PARAMETER) {
+ ret = "One or more argument values are invalid.";
+ } else if (err == EGL_BAD_NATIVE_PIXMAP) {
+ ret = "A NativePixmapType argument does not refer to a valid native pixmap.";
+ } else if (err == EGL_BAD_NATIVE_WINDOW) {
+ ret = "A NativeWindowType argument does not refer to a valid native window.";
+ } else {
+ ret = "Unknown EGL error";
+ }
+ return ret;
+}
+
+char *printErrorExit(char *message) {
+ EGLint err = eglGetError();
+ char buffer[80];
+ char *ret;
+ if (err == EGL_SUCCESS) {
+ ret = "The last function succeeded without error.";
+ } else if (err == EGL_NOT_INITIALIZED) {
+ ret = "EGL is not initialized, or could not be initialized, for the specified EGL display connection.";
+ } else if (err == EGL_BAD_ACCESS) {
+ ret = "EGL cannot access a requested resource (for example a context is bound in another thread).";
+ } else if (err == EGL_BAD_ALLOC) {
+ ret = "EGL failed to allocate resources for the requested operation.";
+ } else if (err == EGL_BAD_ATTRIBUTE) {
+ ret = "An unrecognized attribute or attribute value was passed in the attribute list.";
+ } else if (err == EGL_BAD_CONTEXT) {
+ ret = "An EGLContext argument does not name a valid EGL rendering context.";
+ } else if (err == EGL_BAD_CONFIG) {
+ ret = "An EGLConfig argument does not name a valid EGL frame buffer configuration.";
+ } else if (err == EGL_BAD_CURRENT_SURFACE) {
+ ret = "The current surface of the calling thread is a window, pixel buffer or pixmap that is no longer valid.";
+ } else if (err == EGL_BAD_DISPLAY) {
+ ret = "An EGLDisplay argument does not name a valid EGL display connection.";
+ } else if (err == EGL_BAD_SURFACE) {
+ ret = "An EGLSurface argument does not name a valid surface (window, pixel buffer or pixmap) configured for GL rendering.";
+ } else if (err == EGL_BAD_MATCH) {
+ ret = "Arguments are inconsistent (for example, a valid context requires buffers not supplied by a valid surface).";
+ } else if (err == EGL_BAD_PARAMETER) {
+ ret = "One or more argument values are invalid.";
+ } else if (err == EGL_BAD_NATIVE_PIXMAP) {
+ ret = "A NativePixmapType argument does not refer to a valid native pixmap.";
+ } else if (err == EGL_BAD_NATIVE_WINDOW) {
+ ret = "A NativeWindowType argument does not refer to a valid native window.";
+ } else {
+ sprintf(buffer, "unknown error code 0x%0x", err);
+ ret = buffer;
+ }
+ if (message) {
+ printf("%s\n", message);
+ }
+ printf("EGL ERROR: %s\n", ret);
+ exit(1);
+}
+
+int printConfigAttrs(EGLint *config) {
+ int cnt = 0;
+ while ((*config != EGL_NONE) && (cnt < 25)) {
+ EGLint arg = *config++;
+ EGLint val = *config++;
+ cnt++;
+ printf(" ");
+ switch (arg) {
+ case EGL_SURFACE_TYPE:
+ if (val == (EGL_PBUFFER_BIT | EGL_WINDOW_BIT)) {
+ printf("EGL_SURFACE_TYPE, EGL_PBUFFER_BIT | EGL_WINDOW_BIT,\n");
+ } else if (val == (EGL_WINDOW_BIT)) {
+ printf("EGL_SURFACE_TYPE: EGL_WINDOW_BIT,\n");
+ } else if (val == (EGL_PBUFFER_BIT)) {
+ printf("EGL_SURFACE_TYPE: EGL_PBUFFER_BIT,\n");
+ } else {
+ printf("EGL_SURFACE_TYPE, %d,\n", val);
+ }
+ break;
+ case EGL_BUFFER_SIZE:
+ printf("EGL_BUFFER_SIZE, %d,\n", val);
+ break;
+ case EGL_SAMPLE_BUFFERS:
+ printf("EGL_SAMPLE_BUFFERS, %d,\n", val);
+ break;
+ case EGL_SAMPLES:
+ printf("EGL_SAMPLES, %d,\n", val);
+ break;
+ case EGL_DEPTH_SIZE:
+ printf("EGL_DEPTH_SIZE, %d,\n", val);
+ break;
+ case EGL_RED_SIZE:
+ printf("EGL_RED_SIZE, %d,\n", val);
+ break;
+ case EGL_GREEN_SIZE:
+ printf("EGL_GREEN_SIZE, %d,\n", val);
+ break;
+ case EGL_BLUE_SIZE:
+ printf("EGL_BLUE_SIZE, %d,\n", val);
+ break;
+ case EGL_ALPHA_SIZE:
+ printf("EGL_ALPHA_SIZE, %d,\n", val);
+ break;
+ case EGL_LEVEL:
+ printf("EGL_LEVEL, %d,\n", val);
+ break;
+ case EGL_NATIVE_RENDERABLE:
+ printf("EGL_NATIVE_RENDERABLE, %d,\n", val);
+ break;
+ case EGL_STENCIL_SIZE:
+ printf("EGL_STENCIL_SIZE, %d,\n", val);
+ break;
+ case EGL_TRANSPARENT_TYPE:
+ if (val == EGL_TRANSPARENT_RGB) {
+ printf("EGL_TRANSPARENT_TYPE, EGL_TRANSPARENT_RGB,\n");
+ } else if (val == EGL_NONE) {
+ printf("EGL_TRANSPARENT_TYPE, EGL_NONE,\n");
+ } else {
+ printf("EGL_TRANSPARENT_TYPE, bad val %d\n", val);
+ }
+ break;
+ case EGL_TRANSPARENT_RED_VALUE:
+ printf("EGL_TRANSPARENT_RED_VALUE, %d,\n", val);
+ break;
+ case EGL_TRANSPARENT_GREEN_VALUE:
+ printf("EGL_TRANSPARENT_GREEN_VALUE, %d,\n", val);
+ break;
+ case EGL_TRANSPARENT_BLUE_VALUE:
+ printf("EGL_TRANSPARENT_BLUE_VALUE, %d,\n", val);
+ break;
+ case EGL_NATIVE_VISUAL_TYPE:
+ printf("EGL_NATIVE_VISUAL_TYPE, %d,\n", val);
+ break;
+ case EGL_RENDERABLE_TYPE:
+ printf("EGL_RENDERABLE_TYPE, %s,\n", val == EGL_OPENGL_ES2_BIT ? "EGL_OPENGL_ES2_BIT," : "EGL_OPENGL_ES_BIT");
+ break;
+ default:
+ printf("UNRECOGNIZED, %d, %d\n", arg, val);
+ }
+ }
+ if (*config == EGL_NONE) {
+ printf(" EGL_NONE\n");
+ } else {
+ printf(" *** ERROR exceeded arg limit *** \n");
+ }
+ return 1;
+}
+
+int printConfig(EGLDisplay display, EGLConfig config) {
+
+ int id;
+ eglGetConfigAttrib(display, config, EGL_CONFIG_ID, &id);
+
+ int red, green, blue, alpha, depth;
+ eglGetConfigAttrib(display, config, EGL_RED_SIZE, &red);
+ eglGetConfigAttrib(display, config, EGL_GREEN_SIZE, &green);
+ eglGetConfigAttrib(display, config, EGL_BLUE_SIZE, &blue);
+ eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &alpha);
+ eglGetConfigAttrib(display, config, EGL_BUFFER_SIZE, &depth);
+
+ int pwidth, phgt, psize;
+ pwidth = phgt = psize = 0;
+ eglGetConfigAttrib(display, config, EGL_MAX_PBUFFER_WIDTH, &pwidth);
+ eglGetConfigAttrib(display, config, EGL_MAX_PBUFFER_HEIGHT, &phgt);
+ eglGetConfigAttrib(display, config, EGL_MAX_PBUFFER_PIXELS, &psize);
+
+ int sbuffers, samples;
+ eglGetConfigAttrib(display, config, EGL_SAMPLE_BUFFERS, &sbuffers);
+ eglGetConfigAttrib(display, config, EGL_SAMPLES, &samples);
+
+ int stencil;
+ eglGetConfigAttrib(display, config, EGL_STENCIL_SIZE, &stencil);
+
+ int surface;
+ eglGetConfigAttrib(display, config, EGL_SURFACE_TYPE, &surface);
+
+ int transparent;
+ eglGetConfigAttrib(display, config, EGL_TRANSPARENT_TYPE, &transparent);
+
+ int caveat;
+ eglGetConfigAttrib(display, config, EGL_CONFIG_CAVEAT, &caveat);
+ char *strcaveat = "Normal";
+ if (caveat == EGL_SLOW_CONFIG) {
+ strcaveat = "Slow";
+ } else if (caveat == EGL_NON_CONFORMANT_CONFIG) {
+ strcaveat = "NonConf";
+ }
+
+ // humm, not documented as a supported element, but there all the same ?
+ int rtype = -1;
+ if (!eglGetConfigAttrib(display, config, EGL_RENDERABLE_TYPE, &rtype)) {
+ printf("failed to get EGL_RENDERABLE_TYPE\n");
+ }
+ char rstr[5];
+ char *rstrptr = rstr;
+ if ((rtype & EGL_OPENGL_ES_BIT) == EGL_OPENGL_ES_BIT) {
+ *(rstrptr++) = '1';
+ }
+ if ((rtype & EGL_OPENGL_ES2_BIT) == EGL_OPENGL_ES2_BIT) {
+ *(rstrptr++) = '2';
+ }
+ if ((rtype & EGL_OPENVG_BIT) == EGL_OPENVG_BIT) {
+ *(rstrptr++) = 'V';
+ }
+ if ((rtype & EGL_OPENGL_BIT) == EGL_OPENGL_BIT) {
+ *(rstrptr++) = 'G';
+ }
+ *rstrptr = 0;
+
+ printf(" %02d: %d%d%d%d %02d %04dx%04d %d %d,%d %d %s%s%s %s %s %s\n", id,
+ red, green, blue, alpha, depth,
+ pwidth, phgt, psize,
+ sbuffers, samples,
+ stencil,
+ ((surface & EGL_WINDOW_BIT) == EGL_WINDOW_BIT) ? "W" : "_",
+ ((surface & EGL_PBUFFER_BIT) == EGL_PBUFFER_BIT) ? "P" : "_",
+ ((surface & EGL_PIXMAP_BIT) == EGL_PIXMAP_BIT) ? "X" : "_",
+ (transparent == EGL_TRANSPARENT_RGB) ? "Trans" : "Opaqe",
+ strcaveat,
+ rstr
+ );
+
+ return 1;
+}
+
+//#endif // DEBUG
diff --git a/modules/graphics/src/main/native-prism-es2/monocle/eglUtils.h b/modules/graphics/src/main/native-prism-es2/monocle/eglUtils.h
new file mode 100644
index 0000000000..99662de2f3
--- /dev/null
+++ b/modules/graphics/src/main/native-prism-es2/monocle/eglUtils.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2014, 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.
+ */
+
+#include
+
+#include "../PrismES2Defs.h"
+
+extern int useDispman;
+extern const char *eglErrorMsg(int err);
+extern char *printErrorExit(char *message);
+extern int printConfigAttrs(EGLint *config);
+extern int printConfig(EGLDisplay display, EGLConfig config);
+
+extern ContextInfo *eglContextFromConfig(EGLDisplay *display, EGLConfig config);
+extern void setEGLAttrs(jint *attrs, int *eglAttrs);
+extern EGLSurface getDummyWindowSurface(EGLDisplay dpy,
+ EGLConfig cfg);
+extern EGLSurface getSharedWindowSurface(EGLDisplay dpy,
+ EGLConfig cfg,
+ void *nativeWindow);
+
+//#define DEBUG_EGL 1
+
+#define eglCheck() { \
+ int err; \
+ if ((err = eglGetError()) != EGL_SUCCESS) { \
+ fprintf(stderr, "EGLERROR: %s\n",eglErrorMsg(err)); \
+ }; \
+ } //end of eglCheck
+
+#ifdef DEBUG_EGL
+#define EGL_CHECK eglCheck();
+#else
+#define EGL_CHECK
+#endif
+
+