From acdd8ef2e4af64871c62b8b9b84af83a32fd1aba Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 30 May 2008 13:35:03 +0000 Subject: Completing com.sun.javafx.newt.* package, WIP, working under X11/ES1.1. - Fixed: - EGLDrawable[Factory] - Object target is a 'long[3]' with [display, screen, window] native handles. Depending on the platform, display and screen handles may be 0. - Moved EGL.eglGetDisplay and EGL.eglInitialize from EGLDrawableFactory -> EGLDrawable, since the factory has no notion of the native handles, but the display is necessary. - newt.*: - Added Display and Screen abstraction - Added 'long[] Window.getHandles()', to feed EGLDrawableFactory.getGLDrawable() with the 3 native handles. - MouseEvent: - Java: Clicked and Dragged working - native/X11: SelectInput with proper args - KeyEvent: - native/X11: added XSetInputFocus and XLookupString git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1652 232f8b59-042b-4e1e-8c03-345bb8c30851 --- src/classes/com/sun/javafx/newt/Display.java | 69 ++++++++++++++++++++ src/classes/com/sun/javafx/newt/KeyEvent.java | 12 +++- src/classes/com/sun/javafx/newt/MouseEvent.java | 16 ++++- src/classes/com/sun/javafx/newt/Screen.java | 75 ++++++++++++++++++++++ src/classes/com/sun/javafx/newt/Window.java | 56 +++++++++++++--- .../com/sun/javafx/newt/windows/WindowsWindow.java | 15 ++++- src/classes/com/sun/javafx/newt/x11/X11Window.java | 33 ++++++---- .../com/sun/opengl/impl/egl/EGLDrawable.java | 38 +++++++++-- .../sun/opengl/impl/egl/EGLDrawableFactory.java | 34 +++------- 9 files changed, 292 insertions(+), 56 deletions(-) create mode 100755 src/classes/com/sun/javafx/newt/Display.java create mode 100755 src/classes/com/sun/javafx/newt/Screen.java (limited to 'src/classes/com') diff --git a/src/classes/com/sun/javafx/newt/Display.java b/src/classes/com/sun/javafx/newt/Display.java new file mode 100755 index 000000000..7be9a1b12 --- /dev/null +++ b/src/classes/com/sun/javafx/newt/Display.java @@ -0,0 +1,69 @@ +/* + * 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; + +public class Display { + + public Display() { + this(null); + } + + public Display(String name) { + this.name=name; + this.handle=-1; + } + + public String getName() { + return name; + } + + public long getHandle() { + return handle; + } + + /** + * native handle + * + * write once .. + */ + public void setHandle(long handle) { + if(this.handle<0) { + this.handle=handle; + } + } + + protected String name; + protected long handle; +} + diff --git a/src/classes/com/sun/javafx/newt/KeyEvent.java b/src/classes/com/sun/javafx/newt/KeyEvent.java index 96df883df..47d7d1f7d 100644 --- a/src/classes/com/sun/javafx/newt/KeyEvent.java +++ b/src/classes/com/sun/javafx/newt/KeyEvent.java @@ -56,7 +56,17 @@ public class KeyEvent extends InputEvent } public String toString() { - return "KeyEvent[code "+keyCode+", char "+keyChar+", "+super.toString(); + return "KeyEvent["+getEventTypeString(eventType)+ + ", code "+keyCode+", char "+keyChar+", "+super.toString(); + } + + public static String getEventTypeString(int type) { + switch(type) { + case EVENT_KEY_PRESSED: return "EVENT_KEY_PRESSED"; + case EVENT_KEY_RELEASED: return "EVENT_KEY_RELEASED"; + case EVENT_KEY_TYPED: return "EVENT_KEY_TYPED"; + default: return "unknown"; + } } public boolean isActionKey() { diff --git a/src/classes/com/sun/javafx/newt/MouseEvent.java b/src/classes/com/sun/javafx/newt/MouseEvent.java index 99026bd7b..19b5f2b93 100644 --- a/src/classes/com/sun/javafx/newt/MouseEvent.java +++ b/src/classes/com/sun/javafx/newt/MouseEvent.java @@ -69,7 +69,21 @@ public class MouseEvent extends InputEvent } public String toString() { - return "MouseEvent["+x+"/"+y+", button "+button+", count "+clickCount+", "+super.toString(); + return "MouseEvent["+getEventTypeString(eventType)+ + ", "+x+"/"+y+", button "+button+", count "+clickCount+", "+super.toString(); + } + + public static String getEventTypeString(int type) { + switch(type) { + case EVENT_MOUSE_CLICKED: return "EVENT_MOUSE_CLICKED"; + case EVENT_MOUSE_ENTERED: return "EVENT_MOUSE_ENTERED"; + case EVENT_MOUSE_EXITED: return "EVENT_MOUSE_EXITED"; + case EVENT_MOUSE_PRESSED: return "EVENT_MOUSE_PRESSED"; + case EVENT_MOUSE_RELEASED: return "EVENT_MOUSE_RELEASED"; + case EVENT_MOUSE_MOVED: return "EVENT_MOUSE_MOVED"; + case EVENT_MOUSE_DRAGGED: return "EVENT_MOUSE_DRAGGED"; + default: return "unknown"; + } } private int eventType, x, y, clickCount, button; diff --git a/src/classes/com/sun/javafx/newt/Screen.java b/src/classes/com/sun/javafx/newt/Screen.java new file mode 100755 index 000000000..b698a0248 --- /dev/null +++ b/src/classes/com/sun/javafx/newt/Screen.java @@ -0,0 +1,75 @@ +/* + * 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; + +public class Screen { + + public Screen(Display display) { + this(display, 0); + } + + public Screen(Display display, int idx) { + this.display=display; + this.index=idx; + this.handle=-1; + } + + public Display getDisplay() { + return display; + } + + public int getIndex() { + return index; + } + + public long getHandle() { + return handle; + } + + /** + * native handle + * + * write once .. + */ + public void setHandle(long handle) { + if(this.handle<0) { + this.handle=handle; + } + } + + protected Display display; + protected int index; + protected long handle; +} + diff --git a/src/classes/com/sun/javafx/newt/Window.java b/src/classes/com/sun/javafx/newt/Window.java index 2bfcf1265..27610cdf2 100755 --- a/src/classes/com/sun/javafx/newt/Window.java +++ b/src/classes/com/sun/javafx/newt/Window.java @@ -37,6 +37,9 @@ import java.util.ArrayList; import java.util.Iterator; public abstract class Window { + public static final boolean DEBUG_MOUSE_EVENT = false; + public static final boolean DEBUG_KEY_EVENT = false; + /** OpenKODE window type */ public static final String KD = "KD"; @@ -50,7 +53,7 @@ public abstract class Window { public static final String MACOSX = "MacOSX"; /** Creates a Window of the default type for the current operating system. */ - public static Window create(long visualID) { + public static Window create(Screen screen, long visualID) { String osName = System.getProperty("os.name"); String osNameLowerCase = osName.toLowerCase(); String windowType; @@ -62,7 +65,7 @@ public abstract class Window { windowType = X11; } Window window = create(windowType); - window.initNative(visualID); + window.initNative(screen, visualID); return window; } @@ -87,7 +90,19 @@ public abstract class Window { } } - protected abstract void initNative(long visualID); + + /** + * [ display, screen, window ] + */ + public long[] getHandles() { + long[] handles = new long[3]; + handles[0] = getScreen().getDisplay().getHandle(); + handles[1] = getScreen().getHandle(); + handles[2] = getWindowHandle(); + return handles; + } + + protected abstract void initNative(Screen screen, long visualID); public abstract void setVisible(boolean visible); public abstract void setSize(int width, int height); @@ -101,9 +116,18 @@ public abstract class Window { public abstract boolean isFullscreen(); public abstract int getDisplayWidth(); public abstract int getDisplayHeight(); + + public abstract Screen getScreen(); public abstract long getWindowHandle(); + public abstract void pumpMessages(); + public String toString() { + return "Window[handle "+getWindowHandle()+ + ", pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+ + ", visible "+isVisible()+"]"; + } + // // MouseListener Support // @@ -132,6 +156,10 @@ public abstract class Window { public static final int ClickTimeout = 200; private void sendMouseEvent(int eventType, int modifiers, int x, int y, int button) { + if(DEBUG_MOUSE_EVENT) { + System.out.println("sendMouseEvent: "+MouseEvent.getEventTypeString(eventType)+ + ", mod "+modifiers+", pos "+x+"/"+y+", button "+button); + } long when = System.currentTimeMillis(); MouseEvent eClicked = null; MouseEvent e = null; @@ -151,18 +179,26 @@ public abstract class Window { if(when-lastMousePressed0)?displayHandle:EGL.EGL_DEFAULT_DISPLAY); + if (display == EGL.EGL_NO_DISPLAY) { + throw new GLException("eglGetDisplay failed"); + } + if (!EGL.eglInitialize(display, null, null)) { + throw new GLException("eglInitialize failed"); + } int[] attrs = factory.glCapabilities2AttribList(capabilities); _EGLConfig[] configs = new _EGLConfig[1]; int[] numConfigs = new int[1]; @@ -76,6 +88,10 @@ public class EGLDrawable implements GLDrawable { return display; } + public void shutdown() { + EGL.eglTerminate(display); + } + public _EGLConfig getConfig() { return config; } @@ -91,7 +107,7 @@ public class EGLDrawable implements GLDrawable { public void setRealized(boolean realized) { if (realized) { // Create the window surface - surface = EGL.eglCreateWindowSurface(display, config, nativeWindow, null); + surface = EGL.eglCreateWindowSurface(display, config, windowHandle, null); if (surface == EGL.EGL_NO_SURFACE) { throw new GLException("Creation of window surface (eglCreateWindowSurface) failed"); } @@ -134,4 +150,14 @@ public class EGLDrawable implements GLDrawable { // FIXME return null; } + + public String toString() { + return "EGLDrawable[ displayHandle " + displayHandle + + ", screenHandle "+ screenHandle + + ", windowHandle "+ windowHandle + + ", display " + display + + ", config " + config + + ", surface " + surface + + "]"; + } } diff --git a/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java b/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java index b66d1d33e..516f6d5a9 100755 --- a/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java +++ b/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java @@ -48,28 +48,11 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { // We need more than one of these on certain devices (the NVidia APX 2500 in particular) private List/**/ glesLibraries; - // FIXME: this state should probably not be here - private long display; - private _EGLConfig config; - public EGLDrawableFactory(String profile) { super(profile); loadGLESLibrary(); EGL.resetProcAddressTable(this); - - // FIXME: this initialization sequence needs to be refactored - // at least for X11 platforms to allow a little window - // system-specific code to run (to open the display, in - // particular) - - display = EGL.eglGetDisplay(EGL.EGL_DEFAULT_DISPLAY); - if (display == EGL.EGL_NO_DISPLAY) { - throw new GLException("eglGetDisplay failed"); - } - if (!EGL.eglInitialize(display, null, null)) { - throw new GLException("eglInitialize failed"); - } } private void loadGLESLibrary() { @@ -113,10 +96,6 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { glesLibraries = libs; } - public void shutdown() { - EGL.eglTerminate(display); - } - public AbstractGraphicsConfiguration chooseGraphicsConfiguration(GLCapabilities capabilities, GLCapabilitiesChooser chooser, AbstractGraphicsDevice device) { @@ -126,7 +105,14 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { public GLDrawable getGLDrawable(Object target, GLCapabilities capabilities, GLCapabilitiesChooser chooser) { - return new EGLDrawable(((Long) target).longValue(), + if( !(target instanceof long[]) ) { + throw new GLException("target is not instanceof long[]"); + } + long[] targetHandles = (long[])target; + if(targetHandles.length!=3) { + throw new GLException("target handle array != 3 [display, screen, window]"); + } + return new EGLDrawable(targetHandles[0], targetHandles[1], targetHandles[2], capabilities, chooser); } @@ -189,10 +175,6 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { return false; } - public long getDisplay() { - return display; - } - public int[] glCapabilities2AttribList(GLCapabilities caps) { int[] attrs = new int[] { EGL.EGL_DEPTH_SIZE, caps.getDepthBits(), -- cgit v1.2.3