diff options
author | Michael Bien <[email protected]> | 2009-08-08 21:43:30 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2009-08-08 21:43:30 +0200 |
commit | 8ef9d7364a942c19ec5e1f306e08193e83f4fea6 (patch) | |
tree | 6dcf95825d2933992199a7062b15e38d3f721c95 /src/newt | |
parent | 2a8e9876ca4567de3b08813c280d006f9b2c32e6 (diff) | |
parent | fb3e50b4e7e11df911a83ab7966cf8f293c20da2 (diff) |
Merge branch 'master' of ssh://[email protected]/jogl~jogl-git
Diffstat (limited to 'src/newt')
14 files changed, 583 insertions, 45 deletions
diff --git a/src/newt/classes/com/sun/javafx/newt/Display.java b/src/newt/classes/com/sun/javafx/newt/Display.java index 5032477c9..38d0021ce 100755 --- a/src/newt/classes/com/sun/javafx/newt/Display.java +++ b/src/newt/classes/com/sun/javafx/newt/Display.java @@ -54,6 +54,8 @@ public abstract class Display implements Runnable { 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 b5a555455..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 { 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..e2903bd62 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 + "\""); } @@ -267,6 +269,12 @@ public abstract class Window implements NativeWindow y=0; } + public boolean surfaceSwap() { + return false; + } + + public void surfaceUpdated() {} + protected void clearEventMask() { eventMask=0; } diff --git a/src/newt/classes/com/sun/javafx/newt/impl/NativeLibLoader.java b/src/newt/classes/com/sun/javafx/newt/impl/NativeLibLoader.java index 6316e750f..d96c56f6e 100644 --- a/src/newt/classes/com/sun/javafx/newt/impl/NativeLibLoader.java +++ b/src/newt/classes/com/sun/javafx/newt/impl/NativeLibLoader.java @@ -53,8 +53,7 @@ public class NativeLibLoader extends NativeLibLoaderBase { public static void loadNEWT() { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { - String[] preload = { "nativewindow" }; - loadLibrary("newt", preload, true); + loadLibrary("newt", null, true); return null; } }); diff --git a/src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java b/src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java index 8ecfe6216..9f4454681 100644 --- a/src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java +++ b/src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java @@ -441,10 +441,12 @@ public class GLWindow extends Window implements GLAutoDrawable { return context.getGL(); } - public void setGL(GL gl) { + public GL setGL(GL gl) { if (context != null) { context.setGL(gl); + return gl; } + return null; } public void addGLEventListener(GLEventListener listener) { @@ -654,6 +656,19 @@ public class GLWindow extends Window implements GLAutoDrawable { return null; } + public boolean surfaceSwap() { + if(null!=drawable) return drawable.getNativeWindow().surfaceSwap(); + return super.surfaceSwap(); + } + + public void surfaceUpdated() { + if(null!=drawable) { + drawable.getNativeWindow().surfaceUpdated(); + } else { + super.surfaceUpdated(); + } + } + public long getWindowHandle() { if(null!=drawable) return drawable.getNativeWindow().getWindowHandle(); return super.getWindowHandle(); 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..dbe126c91 --- /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() { + // n/a .. 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..ddee07c49 --- /dev/null +++ b/src/newt/classes/com/sun/javafx/newt/opengl/broadcom/BCEGLWindow.java @@ -0,0 +1,154 @@ +/* + * 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) { + // query a good configuration .. even thought we drop this one + // and reuse the EGLUtil choosen one later. + config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen()); + if (config == null) { + throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); + } + setSizeImpl(getScreen().getWidth(), getScreen().getHeight()); + } + + 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) { + System.err.println("setSize "+width+"x"+height+" n/a in BroadcomEGL"); + } + + void setSizeImpl(int width, int height) { + if(0!=windowHandle) { + // n/a in BroadcomEGL + System.err.println("BCEGLWindow.setSizeImpl n/a in BroadcomEGL with realized window"); + } else { + if(DEBUG_IMPLEMENTATION) { + Exception e = new Exception("BCEGLWindow.setSizeImpl() "+this.width+"x"+this.height+" -> "+width+"x"+height); + e.printStackTrace(); + } + 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; + } + + public boolean surfaceSwap() { + if ( 0!=windowHandle ) { + SwapWindow(getDisplayHandle(), windowHandle); + return true; + } + 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 native void SwapWindow(long eglDisplayHandle, long eglWindowHandle); + + + private long realizeWindow(boolean chromaKey, int width, int height) { + if(DEBUG_IMPLEMENTATION) { + System.out.println("BCEGLWindow.realizeWindow() with: chroma "+chromaKey+", "+width+"x"+height+", "+config); + } + 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; + GLCapabilities capsReq = (GLCapabilities) config.getRequestedCapabilities(); + config = EGLGraphicsConfiguration.create(capsReq, screen.getGraphicsScreen(), cfgID); + if (config == null) { + throw new NativeWindowException("Error creating EGLGraphicsConfiguration from id: "+cfgID+", "+this); + } + if(DEBUG_IMPLEMENTATION) { + System.out.println("BCEGLWindow.windowCreated(): 0x"+Integer.toHexString(cfgID)+", "+width+"x"+height+", "+config); + } + } + + private long windowHandleClose; +} diff --git a/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDWindow.java b/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDWindow.java index df0134c8e..1265fa9e2 100755 --- a/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDWindow.java +++ b/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDWindow.java @@ -79,7 +79,7 @@ public class KDWindow extends Window { } public void setVisible(boolean visible) { - if(this.visible!=visible) { + if(0!=eglWindowHandle && this.visible!=visible) { this.visible=visible; setVisible0(eglWindowHandle, visible); if ( 0==windowHandle ) { @@ -93,7 +93,9 @@ public class KDWindow extends Window { } public void setSize(int width, int height) { - setSize0(eglWindowHandle, width, height); + if(0!=eglWindowHandle) { + setSize0(eglWindowHandle, width, height); + } } public void setPosition(int x, int y) { @@ -102,7 +104,7 @@ public class KDWindow extends Window { } public boolean setFullscreen(boolean fullscreen) { - if(this.fullscreen!=fullscreen) { + if(0!=eglWindowHandle && this.fullscreen!=fullscreen) { this.fullscreen=fullscreen; if(this.fullscreen) { setFullScreen0(eglWindowHandle, true); diff --git a/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java b/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java index c42aaa6d9..18dc7dae3 100755 --- a/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java +++ b/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java @@ -54,12 +54,12 @@ public class WindowsWindow extends Window { } public long getSurfaceHandle() { - if (hdc == 0) { + if (hdc == 0 && 0!=windowHandle) { hdc = GetDC(windowHandle); hmon = MonitorFromWindow(windowHandle); if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { Exception e = new Exception("!!! Window new surface handle "+Thread.currentThread().getName()+ - ",HDC 0x"+Long.toHexString(hdc)+", HMON 0x"+Long.toHexString(hmon)); + ", HWND 0x"+Long.toHexString(windowHandle)+", HDC 0x"+Long.toHexString(hdc)+", HMON 0x"+Long.toHexString(hmon)); e.printStackTrace(); } } @@ -67,21 +67,23 @@ public class WindowsWindow extends Window { } public boolean hasDeviceChanged() { - long _hmon = MonitorFromWindow(windowHandle); - if (hmon != _hmon) { - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - Exception e = new Exception("!!! Window Device Changed "+Thread.currentThread().getName()+ - ", HMON 0x"+Long.toHexString(hmon)+" -> 0x"+Long.toHexString(_hmon)); - e.printStackTrace(); + if(0!=windowHandle) { + long _hmon = MonitorFromWindow(windowHandle); + if (hmon != _hmon) { + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + Exception e = new Exception("!!! Window Device Changed "+Thread.currentThread().getName()+ + ", HMON 0x"+Long.toHexString(hmon)+" -> 0x"+Long.toHexString(_hmon)); + e.printStackTrace(); + } + hmon = _hmon; + return true; } - hmon = _hmon; - return true; } return false; } public void disposeSurfaceHandle() { - if (hdc != 0) { + if (0!=hdc && 0!=windowHandle) { ReleaseDC(windowHandle, hdc); hdc=0; if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { @@ -103,6 +105,11 @@ public class WindowsWindow extends Window { throw new NativeWindowException("Error creating window"); } windowHandleClose = windowHandle; + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + Exception e = new Exception("!!! Window new window handle "+Thread.currentThread().getName()+ + ", HWND 0x"+Long.toHexString(windowHandle)); + e.printStackTrace(); + } } protected void closeNative() { @@ -124,7 +131,7 @@ public class WindowsWindow extends Window { } public void setVisible(boolean visible) { - if(this.visible!=visible) { + if(this.visible!=visible && 0!=windowHandle) { this.visible=visible; setVisible0(windowHandle, visible); } @@ -132,7 +139,7 @@ public class WindowsWindow extends Window { // @Override public void setSize(int width, int height) { - if (width != this.width || this.height != height) { + if (0!=windowHandle && (width != this.width || this.height != height)) { if(!fullscreen) { nfs_width=width; nfs_height=height; @@ -145,7 +152,7 @@ public class WindowsWindow extends Window { //@Override public void setPosition(int x, int y) { - if (this.x != x || this.y != y) { + if (0!=windowHandle && (this.x != x || this.y != y)) { if(!fullscreen) { nfs_x=x; nfs_y=y; @@ -157,7 +164,7 @@ public class WindowsWindow extends Window { } public boolean setFullscreen(boolean fullscreen) { - if(this.fullscreen!=fullscreen) { + if(0!=windowHandle && (this.fullscreen!=fullscreen)) { int x,y,w,h; this.fullscreen=fullscreen; if(fullscreen) { @@ -191,7 +198,7 @@ public class WindowsWindow extends Window { if (title == null) { title = ""; } - if (!title.equals(getTitle())) { + if (0!=windowHandle && !title.equals(getTitle())) { super.setTitle(title); setTitle(windowHandle, title); } diff --git a/src/newt/classes/com/sun/javafx/newt/x11/X11Window.java b/src/newt/classes/com/sun/javafx/newt/x11/X11Window.java index bd6bb42c2..380c968d1 100755 --- a/src/newt/classes/com/sun/javafx/newt/x11/X11Window.java +++ b/src/newt/classes/com/sun/javafx/newt/x11/X11Window.java @@ -84,7 +84,7 @@ public class X11Window extends Window { } public void setVisible(boolean visible) { - if(this.visible!=visible) { + if(0!=windowHandle && this.visible!=visible) { this.visible=visible; setVisible0(getDisplayHandle(), windowHandle, visible); clearEventMask(); @@ -96,6 +96,7 @@ public class X11Window extends Window { } public void setSize(int width, int height) { + if(0==windowHandle) return; if(!fullscreen) { nfs_width=width; nfs_height=height; @@ -104,6 +105,7 @@ public class X11Window extends Window { } public void setPosition(int x, int y) { + if(0==windowHandle) return; if(!fullscreen) { nfs_x=x; nfs_y=y; @@ -112,7 +114,7 @@ public class X11Window extends Window { } public boolean setFullscreen(boolean fullscreen) { - if(this.fullscreen!=fullscreen) { + if(0!=windowHandle && this.fullscreen!=fullscreen) { int x,y,w,h; this.fullscreen=fullscreen; if(fullscreen) { diff --git a/src/newt/native/BroadcomEGL.c b/src/newt/native/BroadcomEGL.c new file mode 100755 index 000000000..d529de667 --- /dev/null +++ b/src/newt/native/BroadcomEGL.c @@ -0,0 +1,195 @@ +/* + * 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_CreateDisplayByNative( GLuint uiWidth, GLuint uiHeight ); +void EGLUtil_DestroyDisplay( EGLDisplay eglDisplay ); + +EGLSurface EGLUtil_CreateWindowByNative( 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_CreateDisplayByNative( (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; + DBG_PRINT( "[DestroyDisplay] dpy %p\n", dpy); + + EGLUtil_DestroyDisplay(dpy); + + DBG_PRINT( "[DestroyDisplay] X\n"); +} + +/** + * 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; + } + DBG_PRINT( "[RealizeWindow.Create] dpy %p %ux%u\n", dpy, uiWidth, uiHeight); + + window = EGLUtil_CreateWindowByNative( dpy, chromaKey, &uiWidth, &uiHeight ); + + 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: win %p, cfgid %d, %ux%u\n", window, cfgID, uiWidth, uiHeight); + + // release and destroy already made context .. + EGLContext ctx = eglGetCurrentContext(); + DBG_PRINT( "[RealizeWindow.Create] ctx %p - KEEP ALIVE \n", ctx); + /*eglMakeCurrent(dpy, + EGL_NO_SURFACE, + EGL_NO_SURFACE, + EGL_NO_CONTEXT); */ + DBG_PRINT( "[RealizeWindow.Create] 2\n"); + // eglDestroyContext(dpy, ctx); // culprit ? FIXME ? + DBG_PRINT( "[RealizeWindow.Create] 2 - eglDestroyContext - DISABLED - Duh ?\n"); + + DBG_PRINT( "[RealizeWindow.Create] X\n"); + + 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; + + DBG_PRINT( "[CloseWindow] dpy %p, win %p\n", dpy, surf); + + EGLUtil_DestroyWindow(dpy, surf); + + DBG_PRINT( "[CloseWindow] X\n"); +} + +JNIEXPORT void JNICALL Java_com_sun_javafx_newt_opengl_broadcom_BCEGLWindow_SwapWindow + (JNIEnv *env, jobject obj, jlong display, jlong window) +{ + EGLDisplay dpy = (EGLDisplay) (intptr_t) display; + EGLSurface surf = (EGLSurface) (intptr_t) window; + + DBG_PRINT( "[SwapWindow] dpy %p, win %p\n", dpy, surf); + + EGLUtil_SwapWindow( dpy, surf ); + + DBG_PRINT( "[SwapWindow] X\n"); +} + diff --git a/src/newt/native/KDWindow.c b/src/newt/native/KDWindow.c index 682edff24..6c7aa7731 100755 --- a/src/newt/native/KDWindow.c +++ b/src/newt/native/KDWindow.c @@ -39,20 +39,24 @@ #include <stdio.h> #include <string.h> -/* This typedef is apparently needed for Microsoft compilers before VC8, - and on Windows CE */ -#if (_MSC_VER < 1400) || defined(UNDER_CE) - #ifdef _WIN64 - typedef long long intptr_t; +#ifdef _WIN32 + /* This typedef is apparently needed for Microsoft compilers before VC8, + and on Windows CE */ + #if (_MSC_VER < 1400) || defined(UNDER_CE) + #ifdef _WIN64 + typedef long long intptr_t; + #else + typedef int intptr_t; + #endif + #elif _MSC_VER <= 1500 + #ifdef _WIN64 // [ + typedef __int64 intptr_t; + #else // _WIN64 ][ + typedef int intptr_t; + #endif // _WIN64 ] #else - typedef int intptr_t; + #include <inttypes.h> #endif -#elif _MSC_VER <= 1500 - #ifdef _WIN64 // [ - typedef __int64 intptr_t; - #else // _WIN64 ][ - typedef int intptr_t; - #endif // _WIN64 ] #else #include <inttypes.h> #endif @@ -99,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; @@ -196,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 @@ -224,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; @@ -266,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; @@ -281,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; @@ -295,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; @@ -308,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; @@ -319,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; |