From 018c7e8660dc0af68bd129be9af5094d04d0b431 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 6 Oct 2010 16:04:06 +0200 Subject: NativeWindow/NativeSurface Refactoring ; Added mouseClick NEWT/AWT unit test NativeWindow/NativeSurface Refactoring - Using NativeSurface interface - NativeWindow extends NativeSurface, adds getLocationOnScreen(Point) - NativeWindow add: getParent() - NativeWindow/Surface: Removed 'invalidate()', use 'destroy()' if you must. - NullWindow -> ProxySurface impl NativeSurface - JOGL: Uses NativeSurface only. - GLDrawable.getNativeWindow() -> GLDrawable.getNativeSurface() Added mouseClick NEWT/AWT unit test JOGL: - GLAnimatorControl add: resetCounter() - NEWT: - GLWindow counters: return GLWindow counters always - WindowImpl - requestFocus() wait until done - reparent: readded requestFocusImpl(true), native impl skips java focusAction if reparented - X11Window: Add XRaiseWindow() in requestFocus() --- .../com/jogamp/nativewindow/impl/NullWindow.java | 145 -------------------- .../com/jogamp/nativewindow/impl/ProxySurface.java | 149 +++++++++++++++++++++ .../jogamp/nativewindow/impl/jawt/JAWTWindow.java | 96 +++++++++---- .../impl/jawt/windows/WindowsJAWTWindow.java | 3 +- .../com/jogamp/nativewindow/util/Rectangle.java | 61 --------- 5 files changed, 220 insertions(+), 234 deletions(-) delete mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/NullWindow.java create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/impl/ProxySurface.java delete mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/util/Rectangle.java (limited to 'src/nativewindow/classes/com/jogamp') diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NullWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NullWindow.java deleted file mode 100644 index fc6242968..000000000 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NullWindow.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2003 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. - * - * You acknowledge that this software is not designed or intended for use - * in the design, construction, operation or maintenance of any nuclear - * facility. - */ - -package com.jogamp.nativewindow.impl; - -import javax.media.nativewindow.*; -import com.jogamp.nativewindow.impl.RecursiveToolkitLock; - -public class NullWindow implements NativeWindow, SurfaceChangeable { - private RecursiveToolkitLock recurLock = new RecursiveToolkitLock(); - protected int width, height, scrnIndex; - protected long surfaceHandle, displayHandle; - protected AbstractGraphicsConfiguration config; - - public NullWindow(AbstractGraphicsConfiguration cfg) { - invalidate(); - config = cfg; - displayHandle=cfg.getScreen().getDevice().getHandle(); - scrnIndex=cfg.getScreen().getIndex(); - } - - protected void init(Object windowObject) throws NativeWindowException { - } - - protected void initNative() throws NativeWindowException { - } - - public void destroy() { - invalidate(); - } - - public synchronized void invalidate() { - displayHandle=0; - scrnIndex=-1; - surfaceHandle=0; - } - - public synchronized int lockSurface() throws NativeWindowException { - recurLock.lock(); - return LOCK_SUCCESS; - } - - public synchronized void unlockSurface() { - recurLock.unlock(); - } - - public synchronized boolean isSurfaceLockedByOtherThread() { - return recurLock.isLockedByOtherThread(); - } - - public synchronized boolean isSurfaceLocked() { - return recurLock.isLocked(); - } - - public Thread getSurfaceLockOwner() { - return recurLock.getOwner(); - } - - public Exception getSurfaceLockStack() { - return recurLock.getLockedStack(); - } - - public boolean surfaceSwap() { - return false; - } - - public void surfaceUpdated(Object updater, NativeWindow window, long when) { } - - public long getDisplayHandle() { - return displayHandle; - } - public int getScreenIndex() { - return scrnIndex; - } - public long getWindowHandle() { - return 0; - } - public long getSurfaceHandle() { - return surfaceHandle; - } - public void setSurfaceHandle(long surfaceHandle) { - this.surfaceHandle=surfaceHandle; - } - public AbstractGraphicsConfiguration getGraphicsConfiguration() { - return config; - } - - public final boolean isTerminalObject() { - return true; - } - - public void setSize(int width, int height) { - this.width=width; - this.height=height; - } - - public int getWidth() { - return width; - } - - public int getHeight() { - return height; - } - - public String toString() { - return "NullWindow[config "+config+ - ", displayHandle 0x"+Long.toHexString(getDisplayHandle())+ - ", surfaceHandle 0x"+Long.toHexString(getSurfaceHandle())+ - ", size "+getWidth()+"x"+getHeight()+"]"; - } - -} diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/ProxySurface.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/ProxySurface.java new file mode 100644 index 000000000..5e6487ae8 --- /dev/null +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/ProxySurface.java @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010 JogAmp Community. 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. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ + +package com.jogamp.nativewindow.impl; + +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.NativeWindow; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.SurfaceChangeable; + +public class ProxySurface implements NativeSurface, SurfaceChangeable { + private RecursiveToolkitLock recurLock = new RecursiveToolkitLock(); + protected int width, height, scrnIndex; + protected long surfaceHandle, displayHandle; + protected AbstractGraphicsConfiguration config; + + public ProxySurface(AbstractGraphicsConfiguration cfg) { + invalidate(); + config = cfg; + displayHandle=cfg.getScreen().getDevice().getHandle(); + scrnIndex=cfg.getScreen().getIndex(); + } + + protected void init(Object windowObject) throws NativeWindowException { + } + + protected void initNative() throws NativeWindowException { + } + + public NativeWindow getParent() { + return null; + } + + public void destroy() { + invalidate(); + } + + public synchronized void invalidate() { + displayHandle=0; + scrnIndex=-1; + surfaceHandle=0; + } + + public synchronized int lockSurface() throws NativeWindowException { + recurLock.lock(); + return LOCK_SUCCESS; + } + + public synchronized void unlockSurface() { + recurLock.unlock(); + } + + public synchronized boolean isSurfaceLockedByOtherThread() { + return recurLock.isLockedByOtherThread(); + } + + public synchronized boolean isSurfaceLocked() { + return recurLock.isLocked(); + } + + public Thread getSurfaceLockOwner() { + return recurLock.getOwner(); + } + + public Exception getSurfaceLockStack() { + return recurLock.getLockedStack(); + } + + public boolean surfaceSwap() { + return false; + } + + public long getSurfaceHandle() { + return surfaceHandle; + } + + public int getWidth() { + return width; + } + + public int getHeight() { + return height; + } + + public AbstractGraphicsConfiguration getGraphicsConfiguration() { + return config; + } + + public void surfaceUpdated(Object updater, NativeSurface ns, long when) { } + + public long getDisplayHandle() { + return displayHandle; + } + public int getScreenIndex() { + return scrnIndex; + } + + public void setSurfaceHandle(long surfaceHandle) { + this.surfaceHandle=surfaceHandle; + } + + public void setSize(int width, int height) { + this.width=width; + this.height=height; + } + + public String toString() { + return "NullWindow[config "+config+ + ", displayHandle 0x"+Long.toHexString(getDisplayHandle())+ + ", surfaceHandle 0x"+Long.toHexString(getSurfaceHandle())+ + ", size "+getWidth()+"x"+getHeight()+"]"; + } + +} diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTWindow.java index 1cd63235d..0cb861453 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTWindow.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -36,14 +37,14 @@ package com.jogamp.nativewindow.impl.jawt; -import com.jogamp.nativewindow.impl.*; -import com.jogamp.nativewindow.util.Rectangle; import java.awt.Component; import java.awt.Window; import java.awt.GraphicsEnvironment; import javax.media.nativewindow.*; import com.jogamp.nativewindow.impl.*; +import javax.media.nativewindow.util.Point; +import javax.media.nativewindow.util.Rectangle; public abstract class JAWTWindow implements NativeWindow { protected static final boolean DEBUG = Debug.debug("JAWT"); @@ -79,21 +80,12 @@ public abstract class JAWTWindow implements NativeWindow { protected abstract void initNative() throws NativeWindowException; - public synchronized void invalidate() { + protected synchronized void invalidate() { component = null; drawable= 0; bounds = new Rectangle(); } - public synchronized void destroy() { - if(null!=component) { - if(component instanceof Window) { - ((Window)component).dispose(); - } - } - invalidate(); - } - protected void updateBounds(JAWT_Rectangle jawtBounds) { bounds.setX(jawtBounds.getX()); bounds.setY(jawtBounds.getY()); @@ -101,6 +93,25 @@ public abstract class JAWTWindow implements NativeWindow { bounds.setHeight(jawtBounds.getHeight()); } + /** @return the JAWT_DrawingSurfaceInfo's (JAWT_Rectangle) bounds, updated with lock */ + public Rectangle getBounds() { return bounds; } + + public Component getAWTComponent() { + return component; + } + + // + // SurfaceUpdateListener + // + + public void surfaceUpdated(Object updater, NativeSurface ns, long when) { + // nop + } + + // + // NativeSurface + // + private RecursiveToolkitLock recurLock = new RecursiveToolkitLock(); protected abstract int lockSurfaceImpl() throws NativeWindowException; @@ -148,15 +159,6 @@ public abstract class JAWTWindow implements NativeWindow { public void surfaceUpdated(Object updater, NativeWindow window, long when) { } - public long getDisplayHandle() { - return config.getScreen().getDevice().getHandle(); - } - public int getScreenIndex() { - return config.getScreen().getIndex(); - } - public long getWindowHandle() { - return drawable; - } public long getSurfaceHandle() { return drawable; } @@ -164,8 +166,12 @@ public abstract class JAWTWindow implements NativeWindow { return config; } - public Object getWrappedWindow() { - return component; + public long getDisplayHandle() { + return config.getScreen().getDevice().getHandle(); + } + + public int getScreenIndex() { + return config.getScreen().getIndex(); } public void setSize(int width, int height) { @@ -180,8 +186,44 @@ public abstract class JAWTWindow implements NativeWindow { return component.getHeight(); } - /** @return the JAWT_DrawingSurfaceInfo's (JAWT_Rectangle) bounds, updated with lock */ - public Rectangle getBounds() { return bounds; } + // + // NativeWindow + // + + public synchronized void destroy() { + if(null!=component) { + if(component instanceof Window) { + ((Window)component).dispose(); + } + } + invalidate(); + } + + public NativeWindow getParent() { + return null; + } + + public long getWindowHandle() { + return drawable; + } + + public int getX() { + return component.getX(); + } + + public int getY() { + return component.getY(); + } + + public Point getLocationOnScreen(Point point) { + java.awt.Point awtLOS = component.getLocationOnScreen(); + int dx = (int) ( awtLOS.getX() + .5 ) ; + int dy = (int) ( awtLOS.getY() + .5 ) ; + if(null!=point) { + return point.translate(dx, dy); + } + return new Point(dx, dy); + } public String toString() { StringBuffer sb = new StringBuffer(); @@ -191,14 +233,14 @@ public abstract class JAWTWindow implements NativeWindow { ", surfaceHandle 0x"+Long.toHexString(getSurfaceHandle())+ ", bounds "+bounds); if(null!=component) { - sb.append(", pos "+component.getX()+"/"+component.getY()+", size "+getWidth()+"x"+getHeight()+ + sb.append(", pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+ ", visible "+component.isVisible()); } else { sb.append(", component NULL"); } sb.append(", lockedExt "+isSurfaceLockedByOtherThread()+ ",\n\tconfig "+config+ - ",\n\twrappedWindow "+getWrappedWindow()+"]"); + ",\n\tawtComponent "+getAWTComponent()+"]"); return sb.toString(); } diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java index c3b3682fd..b6da7166d 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -56,7 +57,7 @@ public class WindowsJAWTWindow extends JAWTWindow { protected void initNative() throws NativeWindowException { } - public synchronized void invalidate() { + protected synchronized void invalidate() { super.invalidate(); windowHandle = 0; } diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/util/Rectangle.java b/src/nativewindow/classes/com/jogamp/nativewindow/util/Rectangle.java deleted file mode 100644 index 9f7711443..000000000 --- a/src/nativewindow/classes/com/jogamp/nativewindow/util/Rectangle.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Copyright 2010 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions 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. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ - - -package com.jogamp.nativewindow.util; - -public class Rectangle { - int x; - int y; - int width; - int height; - - public Rectangle() { - this(0, 0, 0, 0); - } - - public Rectangle(int x, int y, int width, int height) { - this.x=x; - this.y=y; - this.width=width; - this.height=height; - } - public int getX() { return x; } - public int getY() { return y; } - public int getWidth() { return width; } - public int getHeight() { return height; } - public void setX(int x) { this.x = x; } - public void setY(int y) { this.y = y; } - public void setWidth(int width) { this.width = width; } - public void setHeight(int height) { this.height = height; } - - public String toString() { - return new String("Rect["+x+"/"+y+" "+width+"x"+height+"]"); - } -} - -- cgit v1.2.3