changeset 6446:600a63b0323c

Complete work for RT-35243. Cursor now works, rendering works. Reviewed by dblaukopf
author Lisa.Selle@oracle.com
date Fri, 07 Mar 2014 13:31:12 -0500
parents 5a127bee1479
children 12161db2a30a
files buildSrc/armv6hf.gradle modules/graphics/src/main/java/com/sun/glass/ui/monocle/AcceleratedScreen.java modules/graphics/src/main/java/com/sun/glass/ui/monocle/NativePlatform.java modules/graphics/src/main/java/com/sun/glass/ui/monocle/NativePlatformFactory.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/DispmanCursor.java modules/graphics/src/main/java/com/sun/glass/ui/monocle/dispman/DispmanPlatform.java modules/graphics/src/main/java/com/sun/glass/ui/monocle/dispman/DispmanPlatformFactory.java modules/graphics/src/main/java/com/sun/glass/ui/monocle/dispman/DispmanScreen.java modules/graphics/src/main/native-glass/monocle/EGL.c modules/graphics/src/main/native-glass/monocle/dispman/DispmanAcceleratedScreen.c modules/graphics/src/main/native-glass/monocle/dispman/DispmanCursor.c modules/graphics/src/main/native-glass/monocle/dispman/DispmanScreen.c modules/graphics/src/main/native-glass/monocle/dispman/wrapped_bcm.h
diffstat 14 files changed, 875 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/buildSrc/armv6hf.gradle	Fri Mar 07 12:59:14 2014 -0500
+++ b/buildSrc/armv6hf.gradle	Fri Mar 07 13:31:12 2014 -0500
@@ -161,6 +161,8 @@
 
 def es2EglfbCFlags = [extraCFlags, "-DIS_EGLFB", "-DLINUX"].flatten()
 def es2EglfbLFlags = [extraLFlags].flatten()
+def es2MonocleCFlags = [extraCFlags, "-DIS_EGLFB", "-DLINUX"].flatten()
+def es2MonocleLFlags = [extraLFlags].flatten()
 
 def es2X11CFlags = [extraCFlags, "-DUSE_XSHM", "-DDEBUG", "-DIS_EGLX11", "-DLINUX"].flatten()
 def es2X11LFlags = [extraLFlags, "-lX11", "-lXext", "-lXdmcp", "-lXau"].flatten()
@@ -254,7 +256,7 @@
 monocle.prism.targetvram=112m
 monocle.use.egl=true
 monocle.use.gles2=true
-monocle.embedded=eglfb
+monocle.embedded=monocle
 monocle.com.sun.javafx.isEmbedded=true
 monocle.doNativeComposite=true
 monocle.com.sun.javafx.scene.control.skin.FXVK.cache=true
@@ -341,6 +343,8 @@
     "com/sun/glass/events/**",
     "com/sun/glass/ui/*",
     "com/sun/glass/ui/lens/*",
+    "com/sun/glass/ui/monocle/*",
+    "com/sun/glass/ui/monocle/dispman/*",
     "com/sun/glass/ui/monocle/linux/*",
     "com/sun/glass/ui/monocle/util/*",
     "com/sun/glass/ui/monocle/x11/*",
@@ -360,6 +364,8 @@
 
 ARMV6HF.glass.monocle = [:]
 ARMV6HF.glass.monocle.nativeSource = [
+        file("modules/graphics/src/main/native-glass/monocle"),
+        file("modules/graphics/src/main/native-glass/monocle/dispman"),
         file("modules/graphics/src/main/native-glass/monocle/linux"),
         file("modules/graphics/src/main/native-glass/monocle/util") ]
 ARMV6HF.glass.monocle.compiler = compiler
@@ -483,7 +489,7 @@
 ARMV6HF.iio.lib = "javafx_iio"
 
 ARMV6HF.prismES2 = [:]
-ARMV6HF.prismES2.variants = ["eglfb"]
+ARMV6HF.prismES2.variants = ["eglfb", "monocle"]
 ARMV6HF.prismES2.javahInclude = ["com/sun/prism/es2/**/*"]
 
 ARMV6HF.prismES2.eglfb = [:]
@@ -498,6 +504,18 @@
 ARMV6HF.prismES2.eglfb.linkFlags = es2EglfbLFlags
 ARMV6HF.prismES2.eglfb.lib = "prism_es2_eglfb"
 
+ARMV6HF.prismES2.monocle= [:]
+ARMV6HF.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")
+]
+ARMV6HF.prismES2.monocle.compiler = compiler
+ARMV6HF.prismES2.monocle.ccFlags = [ es2EglfbCFlags, "-I", ARMV6HF.glass.lensport.nativeSource ].flatten()
+ARMV6HF.prismES2.monocle.linker = linker
+ARMV6HF.prismES2.monocle.linkFlags = es2EglfbLFlags
+ARMV6HF.prismES2.monocle.lib = "prism_es2_monocle"
+
 ARMV6HF.prismES2.eglx11 = [:]
 ARMV6HF.prismES2.eglx11.nativeSource = [
     file("modules/graphics/src/main/native-prism-es2"),
--- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/AcceleratedScreen.java	Fri Mar 07 12:59:14 2014 -0500
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/AcceleratedScreen.java	Fri Mar 07 13:31:12 2014 -0500
@@ -31,7 +31,7 @@
 
     private static long glesLibraryHandle;
     private static long eglLibraryHandle;
-    private static boolean initialized = false;
+    protected static boolean initialized = false;
     long eglSurface, eglContext, eglDisplay;
 
     protected long platformGetNativeDisplay() {
@@ -48,16 +48,13 @@
         int major[] = {0}, minor[]={0};
         eglDisplay =
                 EGL.eglGetDisplay(platformGetNativeDisplay());
-
         EGL.eglInitialize(eglDisplay, major, minor);
-
         EGL.eglBindAPI(EGL.EGL_OPENGL_ES_BIT);
 
         long eglConfigs[] = {0};
         int configCount[] = {0};
 
         EGL.eglChooseConfig(eglDisplay, attributes, eglConfigs, 1, configCount);
-
         eglSurface =
                 EGL.eglCreateWindowSurface(eglDisplay, eglConfigs[0],
                         platformGetNativeWindow(), null);
--- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/NativePlatform.java	Fri Mar 07 12:59:14 2014 -0500
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/NativePlatform.java	Fri Mar 07 13:31:12 2014 -0500
@@ -33,7 +33,7 @@
     protected final RunnableProcessor runnableProcessor;
     private NativeCursor cursor;
     private NativeScreen screen;
-    private AcceleratedScreen accScreen;
+    protected AcceleratedScreen accScreen;
 
     protected NativePlatform() {
         runnableProcessor = new RunnableProcessor();
--- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/NativePlatformFactory.java	Fri Mar 07 12:59:14 2014 -0500
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/NativePlatformFactory.java	Fri Mar 07 13:31:12 2014 -0500
@@ -43,7 +43,7 @@
                 @Override
                 public String run() {
                     return System.getProperty("monocle.platform",
-                                              "MX6,OMAP,Linux,Headless");
+                                              "MX6,OMAP,Dispman,Linux,Headless");
                 }
             });
             String[] platformFactories = platformFactoryProperty.split(",");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/dispman/DispmanAcceleratedScreen.java	Fri Mar 07 13:31:12 2014 -0500
@@ -0,0 +1,44 @@
+/*
+ * 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.dispman;
+
+import com.sun.glass.ui.monocle.AcceleratedScreen;
+import com.sun.glass.ui.monocle.EGL;
+import com.sun.glass.ui.monocle.linux.LinuxSystem;
+
+public class DispmanAcceleratedScreen extends AcceleratedScreen {
+
+    public DispmanAcceleratedScreen(int[] attributes) {
+        super(attributes);
+    }
+
+    private native long _platformGetNativeWindow();
+
+    @Override
+    protected long platformGetNativeWindow() {
+        return _platformGetNativeWindow();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/dispman/DispmanCursor.java	Fri Mar 07 13:31:12 2014 -0500
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2013, 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.dispman;
+
+import com.sun.glass.ui.monocle.NativeCursor;
+import com.sun.glass.ui.Size;
+
+/** Cursor using dispman API.
+ * TODO: Can we mmap the image and location files?
+ */
+public class DispmanCursor implements NativeCursor {
+
+    private static final int CURSOR_WIDTH = 16;
+    private static final int CURSOR_HEIGHT = 16;
+
+    private native void _initDispmanCursor(int cursorWidth, int cursorHeight);
+    private native void _setVisible(boolean visible);
+    private native void _setLocation(int x, int y);
+    private native void _setImage(byte[] cursorImage);
+
+    public DispmanCursor() {
+        _initDispmanCursor(CURSOR_WIDTH, CURSOR_HEIGHT);
+    }
+
+    @Override
+    public Size getBestSize() {
+        return new Size(CURSOR_WIDTH, CURSOR_HEIGHT);
+    }
+
+    @Override
+    public void setVisibility(boolean visibility) {
+        _setVisible(visibility);
+    }
+
+    private void updateImage(boolean always) {
+        System.out.println("DispmanCursor.updateImage: not implemented");
+    }
+
+    @Override
+    public void setImage(byte[] cursorImage) {
+        _setImage(cursorImage);
+    }
+
+    @Override
+    public void setLocation(int x, int y) {
+        _setLocation(x, y);
+    }
+
+    @Override
+    public void setHotSpot(int hotspotX, int hotspotY) {
+    }
+
+    @Override
+    public void shutdown() {
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/dispman/DispmanPlatform.java	Fri Mar 07 13:31:12 2014 -0500
@@ -0,0 +1,50 @@
+package com.sun.glass.ui.monocle.dispman;/*
+ * Copyright (c) 2013, 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.
+ */
+
+import com.sun.glass.ui.monocle.AcceleratedScreen;
+import com.sun.glass.ui.monocle.NativeCursor;
+import com.sun.glass.ui.monocle.NativeScreen;
+import com.sun.glass.ui.monocle.linux.LinuxPlatform;
+
+public class DispmanPlatform extends LinuxPlatform {
+
+    @Override
+    protected NativeCursor createCursor() {
+        return new DispmanCursor();
+    }
+
+    @Override
+    protected NativeScreen createScreen() {
+        return new DispmanScreen();
+    }
+
+    @Override    public synchronized AcceleratedScreen getAcceleratedScreen(int[] attributes) {
+        if (accScreen == null) {
+            accScreen = new DispmanAcceleratedScreen(attributes);
+        }
+        return accScreen;
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/dispman/DispmanPlatformFactory.java	Fri Mar 07 13:31:12 2014 -0500
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2013, 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.dispman;
+
+import com.sun.glass.ui.monocle.NativePlatform;
+import com.sun.glass.ui.monocle.NativePlatformFactory;
+import com.sun.glass.ui.monocle.omap.OMAPPlatform;
+
+import java.io.File;
+
+public class DispmanPlatformFactory extends NativePlatformFactory {
+
+    @Override
+    protected boolean matches() {
+        return new File("/opt/vc/lib/libbcm_host.so").exists();
+    }
+
+    @Override
+    protected NativePlatform createNativePlatform() {
+        return new DispmanPlatform();
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/dispman/DispmanScreen.java	Fri Mar 07 13:31:12 2014 -0500
@@ -0,0 +1,39 @@
+/*
+ * 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.dispman;
+
+import com.sun.glass.ui.monocle.linux.FBDevScreen;
+import com.sun.glass.ui.monocle.linux.LinuxSystem;
+
+public class DispmanScreen extends FBDevScreen {
+
+    private native void wrapNativeSymbols();
+
+    public DispmanScreen() {
+        super();
+        wrapNativeSymbols();
+    }
+}
--- a/modules/graphics/src/main/native-glass/monocle/EGL.c	Fri Mar 07 12:59:14 2014 -0500
+++ b/modules/graphics/src/main/native-glass/monocle/EGL.c	Fri Mar 07 13:31:12 2014 -0500
@@ -72,7 +72,8 @@
 
 JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_monocle_EGL_eglGetDisplay
     (JNIEnv *env, jclass clazz, jlong display) {
-    EGLDisplay dpy = eglGetDisplay(display);
+    // EGLNativeDisplayType is defined differently on different systems; can be an int or a ptr so cast with care
+    EGLDisplay dpy = eglGetDisplay(((EGLNativeDisplayType) (unsigned long)(display)));
     return asJLong(dpy);
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/graphics/src/main/native-glass/monocle/dispman/DispmanAcceleratedScreen.c	Fri Mar 07 13:31:12 2014 -0500
@@ -0,0 +1,105 @@
+/* Copyright (c) 2012, 2013, 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 "com_sun_glass_ui_monocle_dispman_DispmanAcceleratedScreen.h"
+#include "Monocle.h"
+
+#include <EGL/egl.h>
+#include <fcntl.h>
+#include <linux/fb.h>
+#include <sys/ioctl.h>
+
+#ifdef USE_DISPMAN
+//Broadcom specials
+#include "wrapped_bcm.h"
+#endif /* USE_DISPMAN */
+
+JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_monocle_dispman_DispmanAcceleratedScreen__1platformGetNativeWindow
+    (JNIEnv *env, jobject obj) {
+
+#ifdef USE_DISPMAN
+
+    EGL_DISPMANX_WINDOW_T *dispmanWindow;
+    DISPMANX_DISPLAY_HANDLE_T display = 0;
+    DISPMANX_ELEMENT_HANDLE_T element;
+    DISPMANX_UPDATE_HANDLE_T update;
+    VC_RECT_T dst = { 0, 0, 0, 0 };
+    VC_RECT_T src = { 0, 0, 0, 0 };
+
+    load_bcm_symbols();
+
+    (*wr_bcm_host_init)();
+
+    dispmanWindow = (EGL_DISPMANX_WINDOW_T *)calloc(sizeof(EGL_DISPMANX_WINDOW_T), 1);
+
+    display = (*wr_vc_dispmanx_display_open)(0 /* LCD */);
+    if (display == 0) {
+        fprintf(stderr, "Dispman: Cannot open display\n");
+        return 0;
+    }
+    int fbFileHandle;
+    struct fb_var_screeninfo screenInfo;
+    fbFileHandle = open("/dev/fb0", O_RDONLY);
+    if (fbFileHandle < 0) {
+        fprintf(stderr, "Cannot open framebuffer\n");
+        return 0;
+    }
+    if (ioctl(fbFileHandle, FBIOGET_VSCREENINFO, &screenInfo)) {
+        fprintf(stderr, "Cannot get screen info\n");
+        return 0;
+    }
+    close(fbFileHandle);
+
+    dst.width = screenInfo.xres;
+    dst.height = screenInfo.yres;
+    src.width = screenInfo.xres << 16;
+    src.height = screenInfo.yres << 16;
+
+    VC_DISPMANX_ALPHA_T alpha;
+    alpha.flags = DISPMANX_FLAGS_ALPHA_FROM_SOURCE;
+    alpha.opacity = 0xff;
+    alpha.mask = (DISPMANX_RESOURCE_HANDLE_T) 0;
+    update = (*wr_vc_dispmanx_update_start)(0);
+    element = (*wr_vc_dispmanx_element_add)(
+                  update,
+                  display,
+                  1 /*layer*/,
+                  &dst,
+                  0 /*src*/,
+                  &src,
+                  DISPMANX_PROTECTION_NONE,
+                  &alpha,
+                  0 /*clamp*/,
+                  0 /*transform*/);
+
+    dispmanWindow->element = element;
+    dispmanWindow->width = screenInfo.xres;
+    dispmanWindow->height = screenInfo.yres;
+    (*wr_vc_dispmanx_update_submit_sync)(update);
+
+    return asJLong((NativeWindowType)dispmanWindow);
+#else
+    return 0l;
+#endif /* USE_DISPMAN */
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/graphics/src/main/native-glass/monocle/dispman/DispmanCursor.c	Fri Mar 07 13:31:12 2014 -0500
@@ -0,0 +1,263 @@
+/* Copyright (c) 2012, 2013, 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 <stdio.h>
+ #include <pthread.h>
+ #include <semaphore.h>
+ #include <unistd.h>
+ #include <jni.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <fcntl.h>
+ #include <linux/fb.h>
+ #include <sys/ioctl.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include "Monocle.h"
+
+ #ifdef USE_DISPMAN
+ #include "wrapped_bcm.h"
+
+ #define FB_DEVICE "/dev/fb0"
+
+typedef struct {
+    DISPMANX_ELEMENT_HANDLE_T element;
+    int screenWidth, screenHeight;
+    pthread_t thread;
+    pthread_mutex_t mutex;
+    sem_t semaphore;
+    int x, y;
+    int cursorWidth, cursorHeight;
+    jlong currentCursor;
+    jboolean isVisible;
+} DispManCursor;
+
+
+typedef struct {
+    jint width;
+    jint height;
+    jint x;
+    jint y;
+    DISPMANX_RESOURCE_HANDLE_T resource;
+} DispmanCursorImage;
+
+static DispManCursor cursor;
+
+static void addDispmanxElement();
+static void setNativeCursor(jlong nativeCursorHandle);
+static void addDispmanxElement();
+static void removeDispmanxElement();
+static void updateCursor();
+
+JNIEXPORT void JNICALL Java_com_sun_glass_ui_monocle_dispman_DispmanCursor__1initDispmanCursor
+  (JNIEnv *env, jobject obj, jint width, jint height) {
+    cursor.cursorWidth = width;
+    cursor.cursorHeight = height;
+    cursor.x = 0, cursor.y = 0;
+    cursor.element = 0;
+    cursor.currentCursor = 0;
+    cursor.isVisible = 0;
+    addDispmanxElement();
+    updateCursor();
+}
+
+JNIEXPORT void JNICALL Java_com_sun_glass_ui_monocle_dispman_DispmanCursor__1setVisible
+  (JNIEnv *env, jobject obj, jboolean isVisible)
+{
+    if (isVisible) {
+        if (!cursor.isVisible && cursor.currentCursor != 0) {
+            setNativeCursor(cursor.currentCursor);
+            DispmanCursorImage *cursorImage =
+                (DispmanCursorImage *)asPtr(cursor.currentCursor);
+            DISPMANX_UPDATE_HANDLE_T update = vc_dispmanx_update_start(0);
+            vc_dispmanx_element_change_source(update, cursor.element,
+                                              cursorImage->resource);
+            vc_dispmanx_update_submit_sync(update);
+        }
+    } else {
+        DISPMANX_UPDATE_HANDLE_T update;
+        update = vc_dispmanx_update_start(0);
+        vc_dispmanx_element_change_source(update, cursor.element, 0 );
+        vc_dispmanx_update_submit_sync(update);
+    }
+    cursor.isVisible = isVisible;
+}
+
+JNIEXPORT void JNICALL Java_com_sun_glass_ui_monocle_dispman_DispmanCursor__1setLocation
+  (JNIEnv *env, jobject obj, jint x, jint y) {
+    cursor.x = x;
+    cursor.y = y;
+    updateCursor();
+}
+
+JNIEXPORT void JNICALL Java_com_sun_glass_ui_monocle_dispman_DispmanCursor__1setImage
+  (JNIEnv *env, jobject obj, jbyteArray srcArray)
+{
+     VC_RECT_T pixelRect;
+     DISPMANX_UPDATE_HANDLE_T update;
+     int rc;
+     int i, j;
+     uint32_t imagePtr;
+     DispmanCursorImage *cursorImage = (DispmanCursorImage *)malloc(sizeof(DispmanCursorImage));
+
+     pixelRect.x = 0;
+     pixelRect.y = 0;
+     pixelRect.width = cursor.cursorWidth;
+     pixelRect.height = cursor.cursorHeight;
+
+     cursorImage->x = cursor.x;
+     cursorImage->y = cursor.y;
+     cursorImage->width = cursor.cursorWidth;
+     cursorImage->height = cursor.cursorHeight;
+     cursorImage->resource = vc_dispmanx_resource_create(VC_IMAGE_ARGB8888,
+                             cursor.cursorWidth,
+                             cursor.cursorHeight,
+                             &imagePtr);
+
+     if (cursorImage->resource == 0) {
+         fprintf(stderr, "Cannot create resource\n");
+         free(cursorImage);
+         return;
+     }
+
+     jbyte *srcBytes = (*env)->GetByteArrayElements(env, srcArray, 0);
+
+     rc = vc_dispmanx_resource_write_data(cursorImage->resource,
+                                          VC_IMAGE_ARGB8888,
+                                          cursor.cursorWidth * 4,
+                                          srcBytes,
+                                          &pixelRect);
+
+     (*env)->ReleaseByteArrayElements(env, srcArray, srcBytes, 0);
+
+     if (rc != 0) {
+         fprintf(stderr, "Cannot write pixels");
+         free(cursorImage);
+         return;
+     }
+     cursor.currentCursor = asJLong(cursorImage);
+     if (cursor.isVisible) {
+         update = vc_dispmanx_update_start(0);
+         vc_dispmanx_element_change_source(update, cursor.element, cursorImage->resource);
+         vc_dispmanx_update_submit_sync(update);
+     }
+}
+
+static void setNativeCursor(jlong nativeCursorHandle) {
+
+    DISPMANX_UPDATE_HANDLE_T update;
+    DispmanCursorImage *cursorImage = (DispmanCursorImage *)asPtr(nativeCursorHandle);
+    if (cursorImage != NULL && cursor.element != 0) {
+        if (cursorImage->width != cursor.cursorWidth ||
+                cursorImage->height != cursor.cursorHeight) {
+
+            removeDispmanxElement();
+
+            cursor.cursorWidth = cursorImage->width;
+            cursor.cursorHeight = cursorImage->height;
+
+            addDispmanxElement();
+        }
+        cursor.currentCursor = nativeCursorHandle;
+
+        if (cursor.isVisible) {
+            update = vc_dispmanx_update_start(0);
+            vc_dispmanx_element_change_source(update, cursor.element, cursorImage->resource);
+            vc_dispmanx_update_submit_sync(update);
+        }
+
+    }
+}
+
+static void addDispmanxElement() {
+
+    DISPMANX_DISPLAY_HANDLE_T display = 0;
+    DISPMANX_UPDATE_HANDLE_T update;
+    VC_DISPMANX_ALPHA_T alpha;
+    VC_RECT_T dst;
+    VC_RECT_T src = { 0, 0, cursor.cursorWidth << 16, cursor.cursorHeight << 16};
+    VC_RECT_T pixelRect = { 0, 0, cursor.cursorWidth, cursor.cursorHeight };
+    int rc;
+
+    display = vc_dispmanx_display_open(0 /* LCD */);
+    if (display == 0) {
+        fprintf(stderr, "Cannot open display\n");
+        return;
+    }
+
+    update = vc_dispmanx_update_start(0);
+    alpha.flags = DISPMANX_FLAGS_ALPHA_FROM_SOURCE;
+    alpha.opacity = 0xff;
+    alpha.mask = (DISPMANX_RESOURCE_HANDLE_T) 0;
+    dst.x = cursor.x;
+    dst.y = cursor.y;
+    dst.width = cursor.cursorWidth;
+    dst.height = cursor.cursorHeight;
+    cursor.element = vc_dispmanx_element_add(
+                         update,
+                         display,
+                         2 /*layer*/,
+                         &dst,
+                         0 /*resource*/,
+                         &src,
+                         DISPMANX_PROTECTION_NONE,
+                         &alpha,
+                         0 /*clamp*/,
+                         0 /*transform*/);
+
+    vc_dispmanx_update_submit_sync(update);
+
+}
+
+
+static void removeDispmanxElement() {
+    if (cursor.element) {
+        DISPMANX_UPDATE_HANDLE_T update;
+        update = vc_dispmanx_update_start(0);
+        vc_dispmanx_element_remove(update, cursor.element);
+        vc_dispmanx_update_submit_sync(update);
+
+        cursor.element = 0;
+    }
+}
+
+static void updateCursor() {
+    DISPMANX_UPDATE_HANDLE_T update;
+    VC_RECT_T dst;
+    dst.x = cursor.x;
+    dst.y = cursor.y;
+    dst.width = cursor.cursorWidth;
+    dst.height = cursor.cursorHeight;
+    update = vc_dispmanx_update_start(0);
+    vc_dispmanx_element_change_attributes(update,
+                                          cursor.element,
+                                          0x4 ,
+                                          0 , 0,
+                                          &dst,
+                                          0 ,
+                                          0 , 0 );
+    vc_dispmanx_update_submit_sync(update);
+}
+
+ #endif //USE_DISPMAN
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/graphics/src/main/native-glass/monocle/dispman/DispmanScreen.c	Fri Mar 07 13:31:12 2014 -0500
@@ -0,0 +1,86 @@
+/* Copyright (c) 2012, 2013, 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 "com_sun_glass_ui_monocle_dispman_DispmanScreen.h"
+#include "Monocle.h"
+
+#include <fcntl.h>
+
+#ifdef USE_DISPMAN
+//Broadcom specials
+static int bcm_is_loaded=0;
+
+#define WRAPPEDAPI
+#include "wrapped_bcm.h"
+#endif /* USE_DISPMAN */
+
+void load_bcm_symbols() {
+#ifdef USE_DISPMAN
+    if (bcm_is_loaded)
+        return;
+    bcm_is_loaded = 1;
+
+    void *lib = dlopen("libbcm_host.so", RTLD_LAZY|RTLD_GLOBAL);
+    if (!lib) {
+        return;
+    }
+
+    int error = 0;
+
+    if (!(wr_bcm_host_init = dlsym(lib,"bcm_host_init"))) error++;
+    if (!(wr_vc_dispmanx_display_close = dlsym(lib,"vc_dispmanx_display_close"))) error++;
+    if (!(wr_vc_dispmanx_display_open = dlsym(lib,"vc_dispmanx_display_open"))) error++;
+    if (!(wr_vc_dispmanx_display_get_info = dlsym(lib, "vc_dispmanx_display_get_info")))  error++; //
+    if (!(wr_vc_dispmanx_element_add = dlsym(lib,"vc_dispmanx_element_add"))) error++;
+    if (!(wr_vc_dispmanx_update_start = dlsym(lib,"vc_dispmanx_update_start"))) error++;
+    if (!(wr_vc_dispmanx_update_submit_sync = dlsym(lib,"vc_dispmanx_update_submit_sync"))) error++;
+    if (!(wr_vc_dispmanx_resource_write_data = dlsym(lib, "vc_dispmanx_resource_write_data"))) error++;
+    if (!(wr_vc_dispmanx_resource_read_data = dlsym(lib, "vc_dispmanx_resource_read_data"))) error++;
+    if (!(wr_vc_dispmanx_element_remove = dlsym(lib, "vc_dispmanx_element_remove"))) error++;
+    if (!(wr_vc_dispmanx_element_change_attributes = dlsym(lib, "vc_dispmanx_element_change_attributes"))) error++;
+    if (!(wr_vc_dispmanx_resource_create = dlsym(lib, "vc_dispmanx_resource_create"))) error++;
+    if (!(wr_vc_dispmanx_resource_delete = dlsym(lib, "vc_dispmanx_resource_delete"))) error++;
+    if (!(wr_vc_dispmanx_snapshot = dlsym(lib, "vc_dispmanx_snapshot"))) error++;
+    if (!(wr_vc_dispmanx_element_change_source = dlsym(lib, "vc_dispmanx_element_change_source"))) error++;
+
+    if (error) {
+        // handle error conditions better ?
+        fprintf(stderr, "failed to load all bcm_host symbols %d\n", error);
+        return;
+    }
+    return;
+#else
+    return;
+#endif /* USE_DISPMAN */
+}
+
+JNIEXPORT void JNICALL Java_com_sun_glass_ui_monocle_dispman_DispmanScreen_wrapNativeSymbols
+    (JNIEnv *env, jobject obj) {
+
+#ifdef USE_DISPMAN
+    load_bcm_symbols();
+#else
+    return 0l;
+#endif /* USE_DISPMAN */
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/graphics/src/main/native-glass/monocle/dispman/wrapped_bcm.h	Fri Mar 07 13:31:12 2014 -0500
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2012, 2013, 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.
+ */
+#ifndef __WRAPPED_BCM__
+#define __WRAPPED_BCM__
+
+#ifndef WRAPPEDAPI
+#define WRAPPEDAPI extern
+#endif
+
+#ifdef USE_DISPMAN
+
+#ifndef BCM_HOST_H
+#include <bcm_host.h>
+#endif
+
+#if !defined(_VC_DISPMANX_H_)
+/* for Debian 6.0 libraries */
+typedef enum {
+   VC_IMAGE_ARGB8888 = 43,  /* 32bpp with 8bit alpha at MS byte, with R, G, B (LS byte) */
+} VC_IMAGE_TYPE_T;
+#endif
+
+#define vc_dispmanx_display_close(display) (*wr_vc_dispmanx_display_close)(display)
+
+#define vc_dispmanx_display_open(device) (*wr_vc_dispmanx_display_open)(device)
+
+#define vc_dispmanx_element_add(update, display, layer, dest_rect, src, src_rect, protection, alpha, clamp, transform) (*wr_vc_dispmanx_element_add)(update, display, layer, dest_rect, src, src_rect, protection, alpha, clamp, transform)
+
+#define vc_dispmanx_update_start(priority) (*wr_vc_dispmanx_update_start)(priority)
+
+#define vc_dispmanx_update_submit_sync(update) (*wr_vc_dispmanx_update_submit_sync)(update)
+
+#define vc_dispmanx_resource_read_data(handle, p_rect, dst_address, dst_pitch) (*wr_vc_dispmanx_resource_read_data) (handle, p_rect, dst_address, dst_pitch)
+
+#define vc_dispmanx_resource_write_data(res, src_type, src_pitch, src_address, rect) (*wr_vc_dispmanx_resource_write_data)(res, src_type,src_pitch, src_address, rect)
+
+#define vc_dispmanx_element_remove(update, element) (*wr_vc_dispmanx_element_remove) (update, element)
+
+#define vc_dispmanx_element_change_attributes(update, element, change_flags, layer, opacity, dest_rect, src_rect, mask, transform) (*wr_vc_dispmanx_element_change_attributes) (update, element, change_flags, layer, opacity, dest_rect, src_rect, mask, transform)
+
+#define vc_dispmanx_resource_create(type, width, height, native_image_handle) (*wr_vc_dispmanx_resource_create) (type, width, height, native_image_handle)
+
+#define vc_dispmanx_resource_delete(res) (*wr_vc_dispmanx_resource_delete)(res )
+
+#define vc_dispmanx_snapshot(display, snapshot_resource, transform) (*wr_vc_dispmanx_snapshot) (display, snapshot_resource, transform )
+
+#define vc_dispmanx_element_change_source(update, element, src) (*wr_vc_dispmanx_element_change_source) (update, element, src )
+
+/* wrapped method declarations */
+
+WRAPPEDAPI int (*wr_vc_dispmanx_display_close)(DISPMANX_DISPLAY_HANDLE_T display);
+
+WRAPPEDAPI DISPMANX_DISPLAY_HANDLE_T (*wr_vc_dispmanx_display_open)
+                                      (uint32_t device);
+
+WRAPPEDAPI DISPMANX_ELEMENT_HANDLE_T (*wr_vc_dispmanx_element_add) 
+                                      (DISPMANX_UPDATE_HANDLE_T update,
+                                       DISPMANX_DISPLAY_HANDLE_T display,
+                                       int32_t layer, const VC_RECT_T *dest_rect, 
+                                       DISPMANX_RESOURCE_HANDLE_T src,
+                                       const VC_RECT_T *src_rect, 
+                                       DISPMANX_PROTECTION_T protection,
+                                       VC_DISPMANX_ALPHA_T *alpha, 
+                                       DISPMANX_CLAMP_T *clamp, 
+                                       DISPMANX_TRANSFORM_T transform);
+
+WRAPPEDAPI DISPMANX_UPDATE_HANDLE_T (*wr_vc_dispmanx_update_start)
+                                     (int32_t priority);
+
+WRAPPEDAPI int (*wr_vc_dispmanx_update_submit_sync)
+                (DISPMANX_UPDATE_HANDLE_T update);
+
+WRAPPEDAPI int (*wr_vc_dispmanx_resource_read_data)
+                (DISPMANX_RESOURCE_HANDLE_T handle,
+                 const VC_RECT_T *p_rect, void *dst_address, uint32_t dst_pitch);
+
+WRAPPEDAPI int (*wr_vc_dispmanx_resource_write_data)
+                (DISPMANX_RESOURCE_HANDLE_T res, VC_IMAGE_TYPE_T src_type,
+                 int src_pitch, void *src_address, const VC_RECT_T *rect);
+
+WRAPPEDAPI int (*wr_vc_dispmanx_element_remove)
+                (DISPMANX_UPDATE_HANDLE_T update,
+                 DISPMANX_ELEMENT_HANDLE_T element);
+
+WRAPPEDAPI int (*wr_vc_dispmanx_element_change_attributes)
+                (DISPMANX_UPDATE_HANDLE_T update,
+                 DISPMANX_ELEMENT_HANDLE_T element, uint32_t change_flags,
+                 int32_t layer, uint8_t opacity, const VC_RECT_T *dest_rect,
+                 const VC_RECT_T *src_rect, DISPMANX_RESOURCE_HANDLE_T mask,
+                 VC_IMAGE_TRANSFORM_T transform);
+
+WRAPPEDAPI DISPMANX_RESOURCE_HANDLE_T (*wr_vc_dispmanx_resource_create)
+                                       (VC_IMAGE_TYPE_T type, uint32_t width, 
+                                        uint32_t height, 
+                                        uint32_t *native_image_handle);
+
+WRAPPEDAPI int (*wr_vc_dispmanx_resource_delete)
+                (DISPMANX_RESOURCE_HANDLE_T res);
+
+WRAPPEDAPI int (*wr_vc_dispmanx_snapshot) (DISPMANX_DISPLAY_HANDLE_T display, 
+                DISPMANX_RESOURCE_HANDLE_T snapshot_resource,
+                VC_IMAGE_TRANSFORM_T transform);
+
+WRAPPEDAPI int (*wr_vc_dispmanx_element_change_source)
+                (DISPMANX_UPDATE_HANDLE_T update, 
+                 DISPMANX_ELEMENT_HANDLE_T element,
+                 DISPMANX_RESOURCE_HANDLE_T src);
+
+WRAPPEDAPI int (*wr_vc_dispmanx_display_get_info)(DISPMANX_DISPLAY_HANDLE_T display, DISPMANX_MODEINFO_T *pinfo);
+
+WRAPPEDAPI void (*wr_bcm_host_init)(void);
+
+WRAPPEDAPI void load_bcm_symbols();
+
+#endif // __WRAPPED_BCM__
+#endif // USE_DISPMAN