diff options
author | sg215889 <[email protected]> | 2009-07-27 19:25:33 -0700 |
---|---|---|
committer | sg215889 <[email protected]> | 2009-07-27 19:25:33 -0700 |
commit | 8949675c20e3fc064d170b509391fadbdb970611 (patch) | |
tree | b52aa71703fb3916ee97b03e72691b78d5569029 /src | |
parent | 1b390d8cc911045e6cf8b581cc897b6da1f39f92 (diff) |
Add Custom NativeWindow Type 'BroadcomEGL' (-Dnativewindow.ws.name=BroadcomEGL): 1st Draft of supporting broadcom's proprietary EGL mapping
Diffstat (limited to 'src')
-rwxr-xr-x | src/jogl/classes/com/sun/opengl/impl/egl/EGLDrawable.java | 38 | ||||
-rw-r--r-- | src/jogl/classes/com/sun/opengl/impl/egl/EGLGraphicsConfiguration.java | 19 | ||||
-rw-r--r-- | src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java | 4 | ||||
-rwxr-xr-x | src/newt/classes/com/sun/javafx/newt/Display.java | 7 | ||||
-rwxr-xr-x | src/newt/classes/com/sun/javafx/newt/NewtFactory.java | 5 | ||||
-rwxr-xr-x | src/newt/classes/com/sun/javafx/newt/Screen.java | 2 | ||||
-rwxr-xr-x | src/newt/classes/com/sun/javafx/newt/Window.java | 2 | ||||
-rw-r--r-- | src/newt/classes/com/sun/javafx/newt/opengl/broadcom/BCEGLDisplay.java (renamed from src/newt/classes/com/sun/javafx/newt/opengl/egl/EGLDisplay.java) | 29 | ||||
-rwxr-xr-x | src/newt/classes/com/sun/javafx/newt/opengl/broadcom/BCEGLScreen.java | 64 | ||||
-rwxr-xr-x | src/newt/classes/com/sun/javafx/newt/opengl/broadcom/BCEGLWindow.java | 126 | ||||
-rwxr-xr-x | src/newt/native/BroadcomEGL.c | 170 | ||||
-rwxr-xr-x | src/newt/native/KDWindow.c | 18 |
12 files changed, 438 insertions, 46 deletions
diff --git a/src/jogl/classes/com/sun/opengl/impl/egl/EGLDrawable.java b/src/jogl/classes/com/sun/opengl/impl/egl/EGLDrawable.java index d2907c83d..aabc6f263 100755 --- a/src/jogl/classes/com/sun/opengl/impl/egl/EGLDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/egl/EGLDrawable.java @@ -45,10 +45,10 @@ import javax.media.opengl.*; public abstract class EGLDrawable extends GLDrawableImpl { protected boolean ownEGLDisplay = false; + protected boolean ownEGLSurface = false; private EGLGraphicsConfiguration eglConfig; protected long eglDisplay; protected long eglSurface; - private int[] tmp = new int[1]; protected EGLDrawable(EGLDrawableFactory factory, NativeWindow component) throws GLException { @@ -78,13 +78,16 @@ public abstract class EGLDrawable extends GLDrawableImpl { protected abstract long createSurface(long eglDpy, _EGLConfig eglNativeCfg); private void recreateSurface() { - if(EGL.EGL_NO_SURFACE!=eglSurface) { - EGL.eglDestroySurface(eglDisplay, eglSurface); - } - eglSurface = createSurface(eglDisplay, eglConfig.getNativeConfig()); + if(ownEGLSurface) { + // create a new EGLSurface .. + if(EGL.EGL_NO_SURFACE!=eglSurface) { + EGL.eglDestroySurface(eglDisplay, eglSurface); + } + eglSurface = createSurface(eglDisplay, eglConfig.getNativeConfig()); - if(DEBUG) { - System.err.println("setSurface using component: handle 0x"+Long.toHexString(component.getWindowHandle())+" -> 0x"+Long.toHexString(eglSurface)); + if(DEBUG) { + System.err.println("setSurface using component: handle 0x"+Long.toHexString(component.getWindowHandle())+" -> 0x"+Long.toHexString(eglSurface)); + } } } @@ -110,13 +113,28 @@ public abstract class EGLDrawable extends GLDrawableImpl { if (null == eglConfig) { throw new GLException("Null EGLGraphicsConfiguration from "+aConfig); } - eglConfig.updateGraphicsConfiguration(); + int[] tmp = new int[1]; + if (EGL.eglQuerySurface(eglDisplay, component.getWindowHandle(), EGL.EGL_CONFIG_ID, tmp, 0)) { + // component holds static EGLSurface + eglSurface = component.getWindowHandle(); + if(DEBUG) { + System.err.println("setSurface re-using component's EGLSurface: handle 0x"+Long.toHexString(eglSurface)); + } + } else { + // EGLSurface is ours .. + ownEGLSurface=true; + + eglConfig.updateGraphicsConfiguration(); + } } else { throw new GLException("EGLGraphicsConfiguration doesn't carry a EGLGraphicsDevice: "+aConfig); } } else { // create a new EGL config .. ownEGLDisplay=true; + // EGLSurface is ours .. + ownEGLSurface=true; + long nDisplay; if( NativeWindowFactory.TYPE_WINDOWS.equals(NativeWindowFactory.getNativeWindowType(false)) ) { nDisplay = component.getSurfaceHandle(); // don't even ask .. @@ -153,7 +171,7 @@ public abstract class EGLDrawable extends GLDrawableImpl { } finally { unlockSurface(); } - } else if (eglSurface != EGL.EGL_NO_SURFACE) { + } else if (ownEGLSurface && eglSurface != EGL.EGL_NO_SURFACE) { // Destroy the window surface if (!EGL.eglDestroySurface(eglDisplay, eglSurface)) { throw new GLException("Error destroying window surface (eglDestroySurface)"); @@ -168,6 +186,7 @@ public abstract class EGLDrawable extends GLDrawableImpl { } public int getWidth() { + int[] tmp = new int[1]; if (!EGL.eglQuerySurface(eglDisplay, eglSurface, EGL.EGL_WIDTH, tmp, 0)) { throw new GLException("Error querying surface width"); } @@ -175,6 +194,7 @@ public abstract class EGLDrawable extends GLDrawableImpl { } public int getHeight() { + int[] tmp = new int[1]; if (!EGL.eglQuerySurface(eglDisplay, eglSurface, EGL.EGL_HEIGHT, tmp, 0)) { throw new GLException("Error querying surface height"); } diff --git a/src/jogl/classes/com/sun/opengl/impl/egl/EGLGraphicsConfiguration.java b/src/jogl/classes/com/sun/opengl/impl/egl/EGLGraphicsConfiguration.java index 4f04bb57a..08fbae5bc 100644 --- a/src/jogl/classes/com/sun/opengl/impl/egl/EGLGraphicsConfiguration.java +++ b/src/jogl/classes/com/sun/opengl/impl/egl/EGLGraphicsConfiguration.java @@ -37,6 +37,7 @@ package com.sun.opengl.impl.egl; import java.util.*; import javax.media.nativewindow.*; +import javax.media.nativewindow.egl.*; import javax.media.opengl.*; import com.sun.opengl.impl.*; import com.sun.gluegen.runtime.NativeLibrary; @@ -52,15 +53,29 @@ public class EGLGraphicsConfiguration extends DefaultGraphicsConfiguration imple return configID; } - public EGLGraphicsConfiguration(AbstractGraphicsScreen screen, + public EGLGraphicsConfiguration(AbstractGraphicsScreen absScreen, GLCapabilities capsChosen, GLCapabilities capsRequested, GLCapabilitiesChooser chooser, _EGLConfig cfg, int cfgID) { - super(screen, capsChosen, capsRequested); + super(absScreen, capsChosen, capsRequested); this.chooser = chooser; _config = cfg; configID = cfgID; } + public static EGLGraphicsConfiguration create(GLProfile glp, AbstractGraphicsScreen absScreen, int cfgID) { + AbstractGraphicsDevice absDevice = absScreen.getDevice(); + if(null==absDevice || !(absDevice instanceof EGLGraphicsDevice)) { + throw new GLException("GraphicsDevice must be a valid EGLGraphicsDevice"); + } + long dpy = absDevice.getHandle(); + if (dpy == EGL.EGL_NO_DISPLAY) { + throw new GLException("Invalid EGL display: "+absDevice); + } + _EGLConfig _cfg = EGLConfigId2EGLConfig(glp, dpy, cfgID); + GLCapabilities caps = EGLConfig2Capabilities(glp, dpy, _cfg); + return new EGLGraphicsConfiguration(absScreen, caps, caps, new DefaultGLCapabilitiesChooser(), _cfg, cfgID); + } + public Object clone() { return super.clone(); } diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java index fd6eb458e..cbd485649 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java @@ -80,7 +80,7 @@ public abstract class NativeWindowFactory { } private static String _getNativeWindowingType(String osNameLowerCase) { - if (osNameLowerCase.startsWith("kd") || osNameLowerCase.startsWith("linux")) { + if (osNameLowerCase.startsWith("kd")) { return TYPE_EGL; } else if (osNameLowerCase.startsWith("wind")) { return TYPE_WINDOWS; @@ -101,8 +101,6 @@ public abstract class NativeWindowFactory { AccessControlContext acc = AccessController.getContext(); nativeOSNamePure = Debug.getProperty("os.name", false, acc); nativeOSNameCustom = Debug.getProperty("nativewindow.ws.name", true, acc); - System.out.println(nativeOSNamePure); - System.out.println(nativeOSNameCustom); if(null==nativeOSNameCustom||nativeOSNameCustom.length()==0) { nativeOSNameCustom = nativeOSNamePure; } 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/egl/EGLDisplay.java b/src/newt/classes/com/sun/javafx/newt/opengl/broadcom/BCEGLDisplay.java index bebb7ccf2..abf9859c5 100644 --- a/src/newt/classes/com/sun/javafx/newt/opengl/egl/EGLDisplay.java +++ b/src/newt/classes/com/sun/javafx/newt/opengl/broadcom/BCEGLDisplay.java @@ -31,7 +31,7 @@ * */ -package com.sun.javafx.newt.opengl.egl; +package com.sun.javafx.newt.opengl.broadcom; import com.sun.javafx.newt.*; import com.sun.javafx.newt.impl.*; @@ -39,12 +39,14 @@ import com.sun.opengl.impl.egl.*; import javax.media.nativewindow.*; import javax.media.nativewindow.egl.*; -public class EGLDisplay extends Display { +public class BCEGLDisplay extends Display { static { NativeLibLoader.loadNEWT(); - System.loadLibrary("EglUtil"); + if (!BCEGLWindow.initIDs()) { + throw new NativeWindowException("Failed to initialize BCEGLWindow jmethodIDs"); + } } public static void initSingleton() { @@ -52,27 +54,20 @@ public class EGLDisplay extends Display { } - public EGLDisplay() { + public BCEGLDisplay() { } 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(); + 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) { - EGL.eglTerminate(aDevice.getHandle()); + DestroyDisplay(aDevice.getHandle()); } } @@ -80,6 +75,8 @@ public class EGLDisplay extends Display { 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/native/BroadcomEGL.c b/src/newt/native/BroadcomEGL.c new file mode 100755 index 000000000..8afa71a47 --- /dev/null +++ b/src/newt/native/BroadcomEGL.c @@ -0,0 +1,170 @@ +/* + * 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. + * + */ + +#ifdef _WIN32 + #include <windows.h> +#else + #include <inttypes.h> +#endif + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "com_sun_javafx_newt_opengl_broadcom_BCEGLWindow.h" + +#include "EventListener.h" +#include "MouseEvent.h" +#include "KeyEvent.h" + +#include <EGL/egl.h> + +typedef unsigned int GLuint; + +EGLDisplay EGLUtil_CreateDisplay( GLuint uiWidth, GLuint uiHeight ); +void EGLUtil_DestroyDisplay( EGLDisplay eglDisplay ); + +EGLSurface EGLUtil_CreateWindow( EGLDisplay eglDisplay, /* bool */ GLuint bChromakey, GLuint *puiWidth, GLuint *puiHeight ); +void EGLUtil_DestroyWindow( EGLDisplay eglDisplay, EGLSurface eglSurface ); +void EGLUtil_SwapWindow( EGLDisplay eglDisplay, EGLSurface eglSurface ); + +#define VERBOSE_ON 1 + +#ifdef VERBOSE_ON + #define DBG_PRINT(...) fprintf(stdout, __VA_ARGS__) +#else + #define DBG_PRINT(...) +#endif + +static jmethodID windowCreatedID = NULL; + +/** + * Display + */ + +JNIEXPORT void JNICALL Java_com_sun_javafx_newt_opengl_broadcom_BCEGLDisplay_DispatchMessages + (JNIEnv *env, jobject obj) +{ + // FIXME: n/a + (void) env; + (void) obj; +} + +JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_opengl_broadcom_BCEGLDisplay_CreateDisplay + (JNIEnv *env, jobject obj, jint width, jint height) +{ + (void) env; + (void) obj; + EGLDisplay dpy = EGLUtil_CreateDisplay( (GLuint) width, (GLuint) height ); + if(NULL==dpy) { + fprintf(stderr, "[CreateDisplay] failed: NULL\n"); + } else { + DBG_PRINT( "[CreateDisplay] ok: %p, %ux%u\n", dpy, width, height); + } + return (jlong) (intptr_t) dpy; +} + +JNIEXPORT void JNICALL Java_com_sun_javafx_newt_opengl_broadcom_BCEGLDisplay_DestroyDisplay + (JNIEnv *env, jobject obj, jlong display) +{ + EGLDisplay dpy = (EGLDisplay)(intptr_t)display; + (void) env; + (void) obj; + EGLUtil_DestroyDisplay(dpy); +} + +/** + * Window + */ + +JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_opengl_broadcom_BCEGLWindow_initIDs + (JNIEnv *env, jclass clazz) +{ + windowCreatedID = (*env)->GetMethodID(env, clazz, "windowCreated", "(III)V"); + if (windowCreatedID == NULL) { + DBG_PRINT( "initIDs failed\n" ); + return JNI_FALSE; + } + DBG_PRINT( "initIDs ok\n" ); + return JNI_TRUE; +} + +JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_opengl_broadcom_BCEGLWindow_CreateWindow + (JNIEnv *env, jobject obj, jlong display, jboolean chromaKey, jint width, jint height) +{ + EGLDisplay dpy = (EGLDisplay)(intptr_t)display; + EGLSurface window = 0; + GLuint uiWidth=(GLuint)width, uiHeight=(GLuint)height; + + if(dpy==NULL) { + fprintf(stderr, "[RealizeWindow] invalid display connection..\n"); + return 0; + } + + window = EGLUtil_CreateWindow( dpy, chromaKey, &uiWidth, &uiHeight ); + // EGLUtil_DestroyWindow( dpy, window ); + + if(NULL==window) { + fprintf(stderr, "[RealizeWindow.Create] failed: NULL\n"); + return 0; + } + EGLint cfgID=0; + if(EGL_FALSE==eglQuerySurface(dpy, window, EGL_CONFIG_ID, &cfgID)) { + fprintf(stderr, "[RealizeWindow.ConfigID] failed: window %p\n", window); + EGLUtil_DestroyWindow(dpy, window); + return 0; + } + (*env)->CallVoidMethod(env, obj, windowCreatedID, (jint) cfgID, (jint)uiWidth, (jint)uiHeight); + DBG_PRINT( "[RealizeWindow.Create] ok: %p, cfgid %d, %ux%u\n", window, cfgID, uiWidth, uiHeight); + + // release and destroy already made context .. + EGLContext ctx = eglGetCurrentContext(); + eglMakeCurrent(dpy, + EGL_NO_SURFACE, + EGL_NO_SURFACE, + EGL_NO_CONTEXT); + eglDestroyContext(dpy, ctx); + + return (jlong) (intptr_t) window; +} + +JNIEXPORT void JNICALL Java_com_sun_javafx_newt_opengl_broadcom_BCEGLWindow_CloseWindow + (JNIEnv *env, jobject obj, jlong display, jlong window) +{ + EGLDisplay dpy = (EGLDisplay)(intptr_t)display; + EGLSurface surf = (EGLSurface) (intptr_t) window; + EGLUtil_DestroyWindow(dpy, surf); + + DBG_PRINT( "[CloseWindow]\n"); +} + diff --git a/src/newt/native/KDWindow.c b/src/newt/native/KDWindow.c index 8e57237b3..6c7aa7731 100755 --- a/src/newt/native/KDWindow.c +++ b/src/newt/native/KDWindow.c @@ -103,7 +103,7 @@ static jmethodID sendKeyEventID = NULL; * Display */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_kd_KDDisplay_DispatchMessages +JNIEXPORT void JNICALL Java_com_sun_javafx_newt_opengl_kd_KDDisplay_DispatchMessages (JNIEnv *env, jobject obj) { const KDEvent * evt; @@ -200,7 +200,7 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_kd_KDDisplay_DispatchMessages * Window */ -JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_kd_KDWindow_initIDs +JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_opengl_kd_KDWindow_initIDs (JNIEnv *env, jclass clazz) { #ifdef VERBOSE_ON @@ -228,7 +228,7 @@ JNIEXPORT jboolean JNICALL Java_com_sun_javafx_newt_kd_KDWindow_initIDs return JNI_TRUE; } -JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_kd_KDWindow_CreateWindow +JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_opengl_kd_KDWindow_CreateWindow (JNIEnv *env, jobject obj, jlong display, jintArray jAttrs) { jint * attrs = NULL; @@ -270,7 +270,7 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_kd_KDWindow_CreateWindow return (jlong) (intptr_t) window; } -JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_kd_KDWindow_RealizeWindow +JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_opengl_kd_KDWindow_RealizeWindow (JNIEnv *env, jobject obj, jlong window) { KDWindow *w = (KDWindow*) (intptr_t) window; @@ -285,7 +285,7 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_kd_KDWindow_RealizeWindow return (jlong) (intptr_t) nativeWindow; } -JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_kd_KDWindow_CloseWindow +JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_opengl_kd_KDWindow_CloseWindow (JNIEnv *env, jobject obj, jlong window, jlong juserData) { KDWindow *w = (KDWindow*) (intptr_t) window; @@ -299,11 +299,11 @@ JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_kd_KDWindow_CloseWindow } /* - * Class: com_sun_javafx_newt_kd_KDWindow + * Class: com_sun_javafx_newt_opengl_kd_KDWindow * Method: setVisible0 * Signature: (JJZ)V */ -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_kd_KDWindow_setVisible0 +JNIEXPORT void JNICALL Java_com_sun_javafx_newt_opengl_kd_KDWindow_setVisible0 (JNIEnv *env, jobject obj, jlong window, jboolean visible) { KDWindow *w = (KDWindow*) (intptr_t) window; @@ -312,7 +312,7 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_kd_KDWindow_setVisible0 DBG_PRINT( "[setVisible] v=%d\n", visible); } -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_kd_KDWindow_setFullScreen0 +JNIEXPORT void JNICALL Java_com_sun_javafx_newt_opengl_kd_KDWindow_setFullScreen0 (JNIEnv *env, jobject obj, jlong window, jboolean fullscreen) { KDWindow *w = (KDWindow*) (intptr_t) window; @@ -323,7 +323,7 @@ JNIEXPORT void JNICALL Java_com_sun_javafx_newt_kd_KDWindow_setFullScreen0 (void)res; } -JNIEXPORT void JNICALL Java_com_sun_javafx_newt_kd_KDWindow_setSize0 +JNIEXPORT void JNICALL Java_com_sun_javafx_newt_opengl_kd_KDWindow_setSize0 (JNIEnv *env, jobject obj, jlong window, jint width, jint height) { KDWindow *w = (KDWindow*) (intptr_t) window; |