changeset 7144:ff8eb4ea1dbd

Fix for RT-37085 [Monocle] FX crash on ODROID U3 Reviewed by dblaukopf. Tested with HelloSanity.
author Lisa.Selle@oracle.com
date Wed, 28 May 2014 09:43:01 -0400
parents 799e04084e72
children 18272f18897a
files modules/graphics/src/main/java/com/sun/glass/ui/monocle/AcceleratedScreen.java modules/graphics/src/main/java/com/sun/glass/ui/monocle/GLException.java modules/graphics/src/main/java/com/sun/glass/ui/monocle/NativePlatform.java modules/graphics/src/main/java/com/sun/glass/ui/monocle/dispman/DispmanAcceleratedScreen.java modules/graphics/src/main/java/com/sun/glass/ui/monocle/dispman/DispmanPlatform.java modules/graphics/src/main/java/com/sun/glass/ui/monocle/linux/LinuxSystem.java modules/graphics/src/main/java/com/sun/glass/ui/monocle/mx6/MX6AcceleratedScreen.java modules/graphics/src/main/java/com/sun/glass/ui/monocle/mx6/MX6Platform.java modules/graphics/src/main/java/com/sun/glass/ui/monocle/omapx11/OMAPX11Platform.java modules/graphics/src/main/java/com/sun/glass/ui/monocle/x11/X.java modules/graphics/src/main/java/com/sun/glass/ui/monocle/x11/X11AcceleratedScreen.java modules/graphics/src/main/java/com/sun/glass/ui/monocle/x11/X11Platform.java modules/graphics/src/main/java/com/sun/prism/es2/MonocleGLFactory.java modules/graphics/src/main/native-glass/monocle/EGL.c modules/graphics/src/main/native-glass/monocle/linux/LinuxSystem.c modules/graphics/src/main/native-glass/monocle/x11/X11.c
diffstat 16 files changed, 137 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/AcceleratedScreen.java	Wed May 28 11:31:13 2014 +0300
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/AcceleratedScreen.java	Wed May 28 09:43:01 2014 -0400
@@ -43,12 +43,15 @@
         return 0L;
     }
 
-    public AcceleratedScreen(int[] attributes) {
+    public AcceleratedScreen(int[] attributes) throws GLException {
         initPlatformLibraries();
 
         int major[] = {0}, minor[]={0};
         eglDisplay =
                 EGL.eglGetDisplay(platformGetNativeDisplay());
+        if (eglDisplay == EGL.EGL_NO_DISPLAY) {
+            throw new GLException(EGL.eglGetError(), "Could not get EGL display");
+        }
         EGL.eglInitialize(eglDisplay, major, minor);
         EGL.eglBindAPI(EGL.EGL_OPENGL_ES_BIT);
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/GLException.java	Wed May 28 09:43:01 2014 -0400
@@ -0,0 +1,34 @@
+/*
+ * 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.glass.ui.monocle;
+
+public class GLException extends Exception {
+
+    public GLException(int errorCode, String message) {
+        super("0x" + Integer.toHexString(errorCode) + ": " + message);
+    }
+
+}
--- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/NativePlatform.java	Wed May 28 11:31:13 2014 +0300
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/NativePlatform.java	Wed May 28 09:43:01 2014 -0400
@@ -80,7 +80,8 @@
         return screen;
     }
 
-    public synchronized AcceleratedScreen getAcceleratedScreen(int[] attributes) {
+    public synchronized AcceleratedScreen getAcceleratedScreen(int[] attributes)
+            throws GLException {
         if (accScreen == null) {
             accScreen = new AcceleratedScreen(attributes);
         }
--- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/dispman/DispmanAcceleratedScreen.java	Wed May 28 11:31:13 2014 +0300
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/dispman/DispmanAcceleratedScreen.java	Wed May 28 09:43:01 2014 -0400
@@ -26,12 +26,11 @@
 package com.sun.glass.ui.monocle.dispman;
 
 import com.sun.glass.ui.monocle.AcceleratedScreen;
-import com.sun.glass.ui.monocle.EGL;
-import com.sun.glass.ui.monocle.linux.LinuxSystem;
+import com.sun.glass.ui.monocle.GLException;
 
 public class DispmanAcceleratedScreen extends AcceleratedScreen {
 
-    public DispmanAcceleratedScreen(int[] attributes) {
+    public DispmanAcceleratedScreen(int[] attributes) throws GLException {
         super(attributes);
     }
 
--- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/dispman/DispmanPlatform.java	Wed May 28 11:31:13 2014 +0300
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/dispman/DispmanPlatform.java	Wed May 28 09:43:01 2014 -0400
@@ -24,6 +24,7 @@
  */
 
 import com.sun.glass.ui.monocle.AcceleratedScreen;
+import com.sun.glass.ui.monocle.GLException;
 import com.sun.glass.ui.monocle.NativeCursor;
 import com.sun.glass.ui.monocle.NativeScreen;
 import com.sun.glass.ui.monocle.linux.LinuxPlatform;
@@ -40,7 +41,8 @@
         return new DispmanScreen();
     }
 
-    @Override    public synchronized AcceleratedScreen getAcceleratedScreen(int[] attributes) {
+    @Override public synchronized AcceleratedScreen getAcceleratedScreen(int[] attributes)
+            throws GLException{
         if (accScreen == null) {
             accScreen = new DispmanAcceleratedScreen(attributes);
         }
--- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/linux/LinuxSystem.java	Wed May 28 11:31:13 2014 +0300
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/linux/LinuxSystem.java	Wed May 28 09:43:01 2014 -0400
@@ -159,12 +159,17 @@
     // mman.h
     public static final long PROT_READ = 0x1l;
     public static final long PROT_WRITE = 0x2l;
+    public static final long MAP_PRIVATE = 0x02l;
+    public static final long MAP_ANONYMOUS = 0x20l;
     public static final long MAP_SHARED = 0x1l;
     public static final long MAP_FAILED = 0xffffffffl;
     public native long mmap(long addr, long length, long prot, long flags,
                             long fd, long offset);
     public native int munmap(long addr, long length);
 
+    // string.h
+    public native long memcpy(long destAddr, long srcAddr, long length);
+
     public String getErrorMessage() {
         return strerror(errno());
     }
--- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/mx6/MX6AcceleratedScreen.java	Wed May 28 11:31:13 2014 +0300
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/mx6/MX6AcceleratedScreen.java	Wed May 28 09:43:01 2014 -0400
@@ -26,7 +26,7 @@
 package com.sun.glass.ui.monocle.mx6;
 
 import com.sun.glass.ui.monocle.AcceleratedScreen;
-import com.sun.glass.ui.monocle.linux.LinuxSystem;
+import com.sun.glass.ui.monocle.GLException;
 
 public class MX6AcceleratedScreen extends AcceleratedScreen {
 
@@ -38,7 +38,7 @@
 
     private native long _platformGetNativeDisplay(long methodHandle);
 
-    public MX6AcceleratedScreen(int[] attributes) {
+    public MX6AcceleratedScreen(int[] attributes) throws GLException {
         super(attributes);
     }
 
--- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/mx6/MX6Platform.java	Wed May 28 11:31:13 2014 +0300
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/mx6/MX6Platform.java	Wed May 28 09:43:01 2014 -0400
@@ -26,6 +26,7 @@
 package com.sun.glass.ui.monocle.mx6;
 
 import com.sun.glass.ui.monocle.AcceleratedScreen;
+import com.sun.glass.ui.monocle.GLException;
 import com.sun.glass.ui.monocle.NativeCursor;
 import com.sun.glass.ui.monocle.linux.LinuxPlatform;
 
@@ -37,7 +38,8 @@
     }
 
     @Override
-    public synchronized AcceleratedScreen getAcceleratedScreen(int[] attributes) {
+    public synchronized AcceleratedScreen getAcceleratedScreen(int[] attributes)
+            throws GLException {
         if (accScreen == null) {
             accScreen = new MX6AcceleratedScreen(attributes);
         }
--- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/omapx11/OMAPX11Platform.java	Wed May 28 11:31:13 2014 +0300
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/omapx11/OMAPX11Platform.java	Wed May 28 09:43:01 2014 -0400
@@ -24,6 +24,7 @@
  */
 
 import com.sun.glass.ui.monocle.AcceleratedScreen;
+import com.sun.glass.ui.monocle.GLException;
 import com.sun.glass.ui.monocle.NativeScreen;
 import com.sun.glass.ui.monocle.omap.OMAPPlatform;
 import com.sun.glass.ui.monocle.x11.X11AcceleratedScreen;
@@ -38,7 +39,7 @@
 
     @Override
     public synchronized AcceleratedScreen getAcceleratedScreen(
-            int[] attributes) {
+            int[] attributes) throws GLException {
         if (accScreen == null) {
             accScreen = new X11AcceleratedScreen(attributes);
         }
--- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/x11/X.java	Wed May 28 11:31:13 2014 +0300
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/x11/X.java	Wed May 28 09:43:01 2014 -0400
@@ -113,6 +113,13 @@
         static native void setDataLong(long p, int index, long element);
     }
 
+    static class XDisplay extends C.Structure {
+        XDisplay(long p) {
+            super(p);
+        }
+        public native int sizeof();
+    }
+
     static native long XOpenDisplay(String displayName);
     static native long DefaultScreenOfDisplay(long display);
     static native long RootWindowOfScreen(long screen);
--- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/x11/X11AcceleratedScreen.java	Wed May 28 11:31:13 2014 +0300
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/x11/X11AcceleratedScreen.java	Wed May 28 09:43:01 2014 -0400
@@ -1,4 +1,4 @@
-package com.sun.glass.ui.monocle.x11;/*
+/*
  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -23,16 +23,50 @@
  * questions.
  */
 
+package com.sun.glass.ui.monocle.x11;
+
 import com.sun.glass.ui.monocle.AcceleratedScreen;
+import com.sun.glass.ui.monocle.GLException;
 import com.sun.glass.ui.monocle.NativePlatformFactory;
+import com.sun.glass.ui.monocle.linux.LinuxSystem;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 
 public class X11AcceleratedScreen extends AcceleratedScreen {
+    private X.XDisplay nativeDisplay;
 
-    public X11AcceleratedScreen(int[] attributes) {
+    public X11AcceleratedScreen(int[] attributes) throws GLException {
         super(attributes);
     }
 
     @Override
+    protected long platformGetNativeDisplay() {
+        if (nativeDisplay == null) {
+            boolean doMaliWorkaround =
+                    AccessController.doPrivileged(
+                            (PrivilegedAction<Boolean>) () ->
+                                    Boolean.getBoolean(
+                                            "monocle.maliSignedStruct"));
+            X.XDisplay display = new X.XDisplay(X.XOpenDisplay(null));
+            if (doMaliWorkaround) {
+                long address = 0x7000000;
+                nativeDisplay = new X.XDisplay(
+                        ls.mmap(address, display.sizeof(),
+                                LinuxSystem.PROT_READ | LinuxSystem.PROT_WRITE,
+                                LinuxSystem.MAP_PRIVATE
+                                        | LinuxSystem.MAP_ANONYMOUS,
+                                -1, 0)
+                );
+                ls.memcpy(nativeDisplay.p, display.p, display.sizeof());
+            } else {
+                nativeDisplay = display;
+            }
+        }
+        return nativeDisplay.p;
+    }
+
+    @Override
     protected long platformGetNativeWindow() {
         return NativePlatformFactory.getNativePlatform()
                 .getScreen().getNativeHandle();
--- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/x11/X11Platform.java	Wed May 28 11:31:13 2014 +0300
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/x11/X11Platform.java	Wed May 28 09:43:01 2014 -0400
@@ -24,6 +24,7 @@
  */
 
 import com.sun.glass.ui.monocle.AcceleratedScreen;
+import com.sun.glass.ui.monocle.GLException;
 import com.sun.glass.ui.monocle.NativeCursor;
 import com.sun.glass.ui.monocle.NativePlatform;
 import com.sun.glass.ui.monocle.NativeScreen;
@@ -67,7 +68,7 @@
 
     @Override
     public synchronized AcceleratedScreen getAcceleratedScreen(
-            int[] attributes) {
+            int[] attributes) throws GLException {
         if (accScreen == null) {
             accScreen = new X11AcceleratedScreen(attributes);
         }
--- a/modules/graphics/src/main/java/com/sun/prism/es2/MonocleGLFactory.java	Wed May 28 11:31:13 2014 +0300
+++ b/modules/graphics/src/main/java/com/sun/prism/es2/MonocleGLFactory.java	Wed May 28 09:43:01 2014 -0400
@@ -25,6 +25,7 @@
 
 package com.sun.prism.es2;
 
+import com.sun.glass.ui.monocle.GLException;
 import com.sun.glass.ui.monocle.NativePlatformFactory;
 import com.sun.prism.es2.GLPixelFormat.Attributes;
 import java.util.HashMap;
@@ -103,20 +104,27 @@
         attrArr[GLPixelFormat.Attributes.DOUBLEBUFFER] = attrs.isDoubleBuffer() ? 1 : 0;
         attrArr[GLPixelFormat.Attributes.ONSCREEN] = attrs.isOnScreen() ? 1 : 0;
 
-        accScreen = NativePlatformFactory.getNativePlatform().getAcceleratedScreen(attrArr);
+        try {
+            accScreen = NativePlatformFactory.getNativePlatform().getAcceleratedScreen(
 
-        accScreen.enableRendering(true);
+                    attrArr);
 
-        nativeCtxInfo = nPopulateNativeCtxInfo(accScreen.getGLHandle());
+            accScreen.enableRendering(true);
 
-        accScreen.enableRendering(false);
+            nativeCtxInfo = nPopulateNativeCtxInfo(accScreen.getGLHandle());
 
-        if (nativeCtxInfo == 0) {
-            // current pipe doesn't support this pixelFormat request
+            accScreen.enableRendering(false);
+
+            if (nativeCtxInfo == 0) {
+                // current pipe doesn't support this pixelFormat request
+                return false;
+            } else {
+                gl2 = nGetIsGL2(nativeCtxInfo);
+                return true;
+            }
+        } catch (GLException e) {
+            e.printStackTrace();
             return false;
-        } else {
-            gl2 = nGetIsGL2(nativeCtxInfo);
-            return true;
         }
     }
 
--- a/modules/graphics/src/main/native-glass/monocle/EGL.c	Wed May 28 11:31:13 2014 +0300
+++ b/modules/graphics/src/main/native-glass/monocle/EGL.c	Wed May 28 09:43:01 2014 -0400
@@ -30,7 +30,6 @@
 
 #include <stdlib.h>
 
-
 void setEGLAttrs(jint *attrs, int *eglAttrs) {
     int index = 0;
 
@@ -196,6 +195,10 @@
     }
 }
 
+JNIEXPORT jint  JNICALL Java_com_sun_glass_ui_monocle_EGL_eglGetError
+    (JNIEnv *UNUSED(env), jclass UNUSED(clazz)) {
+    return (jint)eglGetError();
+}
 
 
 
@@ -208,3 +211,4 @@
 
 
 
+
--- a/modules/graphics/src/main/native-glass/monocle/linux/LinuxSystem.c	Wed May 28 11:31:13 2014 +0300
+++ b/modules/graphics/src/main/native-glass/monocle/linux/LinuxSystem.c	Wed May 28 09:43:01 2014 -0400
@@ -299,3 +299,9 @@
   (JNIEnv *UNUSED(env), jobject UNUSED(obj), jlong addr, jlong length) {
     return (jint) munmap(asPtr(addr), (size_t) length);
 }
+
+JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_monocle_linux_LinuxSystem_memcpy
+  (JNIEnv *UNUSED(env), jobject UNUSED(obj), jlong destAddr, jlong srcAddr,
+   jlong length) {
+    return asJLong(memcpy(asPtr(destAddr), asPtr(srcAddr), (size_t)(length)));
+}
--- a/modules/graphics/src/main/native-glass/monocle/x11/X11.c	Wed May 28 11:31:13 2014 +0300
+++ b/modules/graphics/src/main/native-glass/monocle/x11/X11.c	Wed May 28 09:43:01 2014 -0400
@@ -25,6 +25,7 @@
 
 #include "com_sun_glass_ui_monocle_x11_X.h"
 #include <X11/Xlib.h>
+#include <X11/Xlibint.h>
 #include "Monocle.h"
 
 JNIEXPORT jlong JNICALL
@@ -276,3 +277,9 @@
     XClientMessageEvent *event = (XClientMessageEvent *) asPtr(eventL);
     event->data.l[index] = (long) element;
 }
+
+JNIEXPORT jint JNICALL
+ Java_com_sun_glass_ui_monocle_x11_X_00024XDisplay_sizeof
+ (JNIEnv *UNUSED(env), jclass UNUSED(clazz)) {
+    return (jint) sizeof(struct _XDisplay);
+}