From 8949675c20e3fc064d170b509391fadbdb970611 Mon Sep 17 00:00:00 2001
From: sg215889 <sg215889@jordan.goethel.localnet>
Date: Mon, 27 Jul 2009 19:25:33 -0700
Subject: Add Custom NativeWindow Type 'BroadcomEGL'
 (-Dnativewindow.ws.name=BroadcomEGL): 1st Draft of supporting broadcom's
 proprietary EGL mapping

---
 src/newt/classes/com/sun/javafx/newt/Display.java  |   7 +-
 .../classes/com/sun/javafx/newt/NewtFactory.java   |   5 +-
 src/newt/classes/com/sun/javafx/newt/Screen.java   |   2 +
 src/newt/classes/com/sun/javafx/newt/Window.java   |   2 +
 .../javafx/newt/opengl/broadcom/BCEGLDisplay.java  |  82 ++++++++++++++
 .../javafx/newt/opengl/broadcom/BCEGLScreen.java   |  64 +++++++++++
 .../javafx/newt/opengl/broadcom/BCEGLWindow.java   | 126 +++++++++++++++++++++
 .../com/sun/javafx/newt/opengl/egl/EGLDisplay.java |  85 --------------
 8 files changed, 281 insertions(+), 92 deletions(-)
 create mode 100644 src/newt/classes/com/sun/javafx/newt/opengl/broadcom/BCEGLDisplay.java
 create mode 100755 src/newt/classes/com/sun/javafx/newt/opengl/broadcom/BCEGLScreen.java
 create mode 100755 src/newt/classes/com/sun/javafx/newt/opengl/broadcom/BCEGLWindow.java
 delete mode 100644 src/newt/classes/com/sun/javafx/newt/opengl/egl/EGLDisplay.java

(limited to 'src/newt/classes/com/sun')

diff --git a/src/newt/classes/com/sun/javafx/newt/Display.java b/src/newt/classes/com/sun/javafx/newt/Display.java
index bdac08dab..04fdb0181 100755
--- a/src/newt/classes/com/sun/javafx/newt/Display.java
+++ b/src/newt/classes/com/sun/javafx/newt/Display.java
@@ -45,16 +45,15 @@ public abstract class Display implements Runnable {
     {
         Class displayClass = null;
         if (NativeWindowFactory.TYPE_EGL.equals(type)) {
-            // displayClass = Class.forName("com.sun.javafx.newt.opengl.kd.KDDisplay");
-            displayClass = Class.forName("com.sun.javafx.newt.opengl.egl.EGLDisplay");
+            displayClass = Class.forName("com.sun.javafx.newt.opengl.kd.KDDisplay");
         } else if (NativeWindowFactory.TYPE_WINDOWS.equals(type)) {
             displayClass = Class.forName("com.sun.javafx.newt.windows.WindowsDisplay");
         } else if (NativeWindowFactory.TYPE_MACOSX.equals(type)) {
             displayClass = Class.forName("com.sun.javafx.newt.macosx.MacDisplay");
         } else if (NativeWindowFactory.TYPE_X11.equals(type)) {
             displayClass = Class.forName("com.sun.javafx.newt.x11.X11Display");
-        } else if (NativeWindowFactory.TYPE_AWT.equals(type)) {
-            displayClass = Class.forName("com.sun.javafx.newt.awt.AWTDisplay");
+        } else if (NewtFactory.TYPE_BROADCOM_EGL.equals(type)) {
+            displayClass = Class.forName("com.sun.javafx.newt.opengl.broadcom.BCEGLDisplay");
         } else {
             throw new RuntimeException("Unknown display type \"" + type + "\"");
         }
diff --git a/src/newt/classes/com/sun/javafx/newt/NewtFactory.java b/src/newt/classes/com/sun/javafx/newt/NewtFactory.java
index b88e1e49e..dbae30a4b 100755
--- a/src/newt/classes/com/sun/javafx/newt/NewtFactory.java
+++ b/src/newt/classes/com/sun/javafx/newt/NewtFactory.java
@@ -39,6 +39,8 @@ import java.util.Iterator;
 import com.sun.nativewindow.impl.jvm.JVMUtil;
 
 public abstract class NewtFactory {
+    public static final String TYPE_BROADCOM_EGL = "BroadcomEGL";
+
     // Work-around for initialization order problems on Mac OS X
     // between native Newt and (apparently) Fmod
     static {
@@ -50,7 +52,6 @@ public abstract class NewtFactory {
      * Create a Display entity, incl native creation
      */
     public static Display createDisplay(String name) {
-        System.out.println("NewtFactory: NAME: " + name);
       return Display.create(NativeWindowFactory.getNativeWindowType(true), name);
     }
 
@@ -58,8 +59,6 @@ public abstract class NewtFactory {
      * Create a Display entity using the given implementation type, incl native creation
      */
     public static Display createDisplay(String type, String name) {
-        System.out.println("NewtFactory: TYPE: " + type);
-        System.out.println("NewtFactory: NAME: " + name);
       return Display.create(type, name);
     }
 
diff --git a/src/newt/classes/com/sun/javafx/newt/Screen.java b/src/newt/classes/com/sun/javafx/newt/Screen.java
index 2566041a8..57ed34211 100755
--- a/src/newt/classes/com/sun/javafx/newt/Screen.java
+++ b/src/newt/classes/com/sun/javafx/newt/Screen.java
@@ -54,6 +54,8 @@ public abstract class Screen {
             screenClass = Class.forName("com.sun.javafx.newt.x11.X11Screen");
         } else if (NativeWindowFactory.TYPE_AWT.equals(type)) {
             screenClass = Class.forName("com.sun.javafx.newt.awt.AWTScreen");
+        } else if (NewtFactory.TYPE_BROADCOM_EGL.equals(type)) {
+            screenClass = Class.forName("com.sun.javafx.newt.opengl.broadcom.BCEGLScreen");
         } else {
             throw new RuntimeException("Unknown window type \"" + type + "\"");
         }
diff --git a/src/newt/classes/com/sun/javafx/newt/Window.java b/src/newt/classes/com/sun/javafx/newt/Window.java
index 36eafd32d..a1168d12d 100755
--- a/src/newt/classes/com/sun/javafx/newt/Window.java
+++ b/src/newt/classes/com/sun/javafx/newt/Window.java
@@ -74,6 +74,8 @@ public abstract class Window implements NativeWindow
             windowClass = Class.forName("com.sun.javafx.newt.x11.X11Window");
         } else if (NativeWindowFactory.TYPE_AWT.equals(type)) {
             windowClass = Class.forName("com.sun.javafx.newt.awt.AWTWindow");
+        } else if (NewtFactory.TYPE_BROADCOM_EGL.equals(type)) {
+            windowClass = Class.forName("com.sun.javafx.newt.opengl.broadcom.BCEGLWindow");
         } else {
             throw new NativeWindowException("Unknown window type \"" + type + "\"");
         }
diff --git a/src/newt/classes/com/sun/javafx/newt/opengl/broadcom/BCEGLDisplay.java b/src/newt/classes/com/sun/javafx/newt/opengl/broadcom/BCEGLDisplay.java
new file mode 100644
index 000000000..abf9859c5
--- /dev/null
+++ b/src/newt/classes/com/sun/javafx/newt/opengl/broadcom/BCEGLDisplay.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 
+ * - Redistribution of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * 
+ * - Redistribution in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * 
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * 
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ * 
+ */
+
+package com.sun.javafx.newt.opengl.broadcom;
+
+import com.sun.javafx.newt.*;
+import com.sun.javafx.newt.impl.*;
+import com.sun.opengl.impl.egl.*;
+import javax.media.nativewindow.*;
+import javax.media.nativewindow.egl.*;
+
+public class BCEGLDisplay extends Display {
+
+    static {
+        NativeLibLoader.loadNEWT();
+
+        if (!BCEGLWindow.initIDs()) {
+            throw new NativeWindowException("Failed to initialize BCEGLWindow jmethodIDs");
+        }
+    }
+
+    public static void initSingleton() {
+        // just exist to ensure static init has been run
+    }
+
+
+    public BCEGLDisplay() {
+    }
+
+    protected void createNative() {
+        long handle = CreateDisplay(BCEGLScreen.fixedWidth, BCEGLScreen.fixedHeight);
+        if (handle == EGL.EGL_NO_DISPLAY) {
+            throw new NativeWindowException("BC EGL CreateDisplay failed");
+        }
+        aDevice = new EGLGraphicsDevice(handle);
+    }
+
+    protected void closeNative() {
+        if (aDevice.getHandle() != EGL.EGL_NO_DISPLAY) {
+            DestroyDisplay(aDevice.getHandle());
+        }
+    }
+
+    protected void dispatchMessages() {
+        DispatchMessages();
+    }
+
+    private native long CreateDisplay(int width, int height);
+    private native void DestroyDisplay(long dpy);
+    private native void DispatchMessages();
+}
+
diff --git a/src/newt/classes/com/sun/javafx/newt/opengl/broadcom/BCEGLScreen.java b/src/newt/classes/com/sun/javafx/newt/opengl/broadcom/BCEGLScreen.java
new file mode 100755
index 000000000..165081cde
--- /dev/null
+++ b/src/newt/classes/com/sun/javafx/newt/opengl/broadcom/BCEGLScreen.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 
+ * - Redistribution of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * 
+ * - Redistribution in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * 
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * 
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ * 
+ */
+
+package com.sun.javafx.newt.opengl.broadcom;
+
+import com.sun.javafx.newt.*;
+import com.sun.javafx.newt.impl.*;
+import javax.media.nativewindow.*;
+
+public class BCEGLScreen extends Screen {
+
+    static {
+        BCEGLDisplay.initSingleton();
+    }
+
+
+    public BCEGLScreen() {
+    }
+
+    protected void createNative(int index) {
+        aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index);
+        setScreenSize(fixedWidth, fixedHeight);
+    }
+
+    protected void closeNative() { }
+
+    //----------------------------------------------------------------------
+    // Internals only
+    //
+
+    static final int fixedWidth = 1920;
+    static final int fixedHeight = 1080;
+}
+
diff --git a/src/newt/classes/com/sun/javafx/newt/opengl/broadcom/BCEGLWindow.java b/src/newt/classes/com/sun/javafx/newt/opengl/broadcom/BCEGLWindow.java
new file mode 100755
index 000000000..a91a91598
--- /dev/null
+++ b/src/newt/classes/com/sun/javafx/newt/opengl/broadcom/BCEGLWindow.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 
+ * - Redistribution of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * 
+ * - Redistribution in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * 
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * 
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ * 
+ */
+
+package com.sun.javafx.newt.opengl.broadcom;
+
+import com.sun.javafx.newt.*;
+import com.sun.javafx.newt.impl.*;
+import com.sun.opengl.impl.egl.*;
+import javax.media.nativewindow.*;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+import javax.media.nativewindow.NativeWindowException;
+
+public class BCEGLWindow extends Window {
+    static {
+        BCEGLDisplay.initSingleton();
+    }
+
+    public BCEGLWindow() {
+    }
+
+    protected void createNative(Capabilities caps) {
+        // just save the GLProfile here, create window later ..
+        glProfile = ((GLCapabilities)caps).getGLProfile();
+    }
+
+    protected void closeNative() {
+        if(0!=windowHandleClose) {
+            CloseWindow(getDisplayHandle(), windowHandleClose);
+        }
+    }
+
+    public void setVisible(boolean visible) {
+        if(this.visible!=visible) {
+            this.visible=visible;
+            if ( 0==windowHandle ) {
+                windowHandle = realizeWindow(true, width, height);
+                if (0 == windowHandle) {
+                    throw new NativeWindowException("Error native Window Handle is null");
+                }
+            }
+            clearEventMask();
+        }
+    }
+
+    public void setSize(int width, int height) {
+        if(0!=windowHandle) {
+            // n/a in BroadcomEGL
+            System.err.println("setSize n/a in BroadcomEGL with realized window");
+        } else {
+            this.width = width;
+            this.height = height;
+        }
+    }
+
+    public void setPosition(int x, int y) {
+        // n/a in BroadcomEGL
+        System.err.println("setPosition n/a in BroadcomEGL");
+    }
+
+    public boolean setFullscreen(boolean fullscreen) {
+        // n/a in BroadcomEGL
+        System.err.println("setFullscreen n/a in BroadcomEGL");
+        return false;
+    }
+
+    //----------------------------------------------------------------------
+    // Internals only
+    //
+
+    protected static native boolean initIDs();
+    private        native long CreateWindow(long eglDisplayHandle, boolean chromaKey, int width, int height);
+    private        native void CloseWindow(long eglDisplayHandle, long eglWindowHandle);
+
+
+    private long realizeWindow(boolean chromaKey, int width, int height) {
+        long handle = CreateWindow(getDisplayHandle(), chromaKey, width, height);
+        if (0 == handle) {
+            throw new NativeWindowException("Error native Window Handle is null");
+        }
+        windowHandleClose = handle;
+        return handle;
+    }
+
+    private void windowCreated(int cfgID, int width, int height) {
+        this.width = width;
+        this.height = height;
+        config = EGLGraphicsConfiguration.create(glProfile, screen.getGraphicsScreen(), cfgID);
+        if (config == null) {
+            throw new NativeWindowException("Error creating EGLGraphicsConfiguration from id: "+cfgID+", "+this);
+        }
+    }
+
+    private long   windowHandleClose;
+    private GLProfile glProfile;
+}
diff --git a/src/newt/classes/com/sun/javafx/newt/opengl/egl/EGLDisplay.java b/src/newt/classes/com/sun/javafx/newt/opengl/egl/EGLDisplay.java
deleted file mode 100644
index bebb7ccf2..000000000
--- a/src/newt/classes/com/sun/javafx/newt/opengl/egl/EGLDisplay.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
- * 
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- * 
- * - Redistribution of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * 
- * - Redistribution in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * 
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- * 
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- * 
- */
-
-package com.sun.javafx.newt.opengl.egl;
-
-import com.sun.javafx.newt.*;
-import com.sun.javafx.newt.impl.*;
-import com.sun.opengl.impl.egl.*;
-import javax.media.nativewindow.*;
-import javax.media.nativewindow.egl.*;
-
-public class EGLDisplay extends Display {
-
-    static {
-        NativeLibLoader.loadNEWT();
-
-        System.loadLibrary("EglUtil");
-    }
-
-    public static void initSingleton() {
-        // just exist to ensure static init has been run
-    }
-
-
-    public EGLDisplay() {
-    }
-
-    protected void createNative() {
-        try {
-            int windowWidth = 1920, windowHeight = 1080;
-            int width[] = { windowWidth };
-            int height[] = { windowHeight };
-            long eglDisplayHandle = 
-                    EGL.EGLUtil_CreateDisplayByNative(windowWidth, windowHeight);
-            long eglSurfaceHandle = 
-                    EGL.EGLUtil_CreateWindowByNative(eglDisplayHandle, 1,
-                                                      width, 0, height, 0);
-        } catch (Throwable th) {
-            th.printStackTrace();
-        }
-    }
-
-    protected void closeNative() {
-        if (aDevice.getHandle() != EGL.EGL_NO_DISPLAY) {
-            EGL.eglTerminate(aDevice.getHandle());
-        }
-    }
-
-    protected void dispatchMessages() {
-        DispatchMessages();
-    }
-
-    private native void DispatchMessages();
-}
-
-- 
cgit v1.2.3