From 944bef5e70e0e8fe85a147fa7304c35f18d1957b Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 27 May 2010 14:25:37 +0200 Subject: Fix NativeWindow JAWT Code Generation and Bounds Access - Restructure: JAWT gluegen, use common jawt-common.cfg - Fix: Use proper capacity for GetDrawingSurface and GetDrawingSurfaceInfo - Fix: JAWTWindow maintains AWT bounds - Fix: JAWTWindow locking/unlocking decoupled with abstract implementation, which allows clear code and simpler unlock code. --- make/build-nativewindow.xml | 4 +- make/config/nativewindow/jawt-common.cfg | 26 ++++ make/config/nativewindow/jawt-macosx.cfg | 18 +-- make/config/nativewindow/jawt-win32.cfg | 17 +-- make/config/nativewindow/jawt-x11.cfg | 17 +-- .../jogamp/nativewindow/impl/jawt/JAWTWindow.java | 26 +++- .../impl/jawt/macosx/MacOSXJAWTWindow.java | 56 ++++----- .../impl/jawt/windows/WindowsJAWTWindow.java | 59 ++++----- .../nativewindow/impl/jawt/x11/X11JAWTWindow.java | 57 ++++----- .../com/jogamp/nativewindow/util/Rectangle.java | 59 +++++++++ .../com/jogamp/newt/awt/NewtFactoryAWT.java | 139 +++++++++++++++++++++ .../com/jogamp/newt/impl/awt/AWTNewtFactory.java | 139 --------------------- 12 files changed, 316 insertions(+), 301 deletions(-) create mode 100644 make/config/nativewindow/jawt-common.cfg create mode 100644 src/nativewindow/classes/com/jogamp/nativewindow/util/Rectangle.java create mode 100644 src/newt/classes/com/jogamp/newt/awt/NewtFactoryAWT.java delete mode 100644 src/newt/classes/com/jogamp/newt/impl/awt/AWTNewtFactory.java diff --git a/make/build-nativewindow.xml b/make/build-nativewindow.xml index b087a5ba7..861dc00c5 100644 --- a/make/build-nativewindow.xml +++ b/make/build-nativewindow.xml @@ -73,7 +73,7 @@ + value="javax/media/nativewindow/*, javax/media/nativewindow/egl/*, javax/media/nativewindow/macosx/*, javax/media/nativewindow/windows/*, com/jogamp/nativewindow/util/*, com/jogamp/nativewindow/impl/*, com/jogamp/nativewindow/impl/jvm/*"/> @@ -155,7 +155,7 @@ - + diff --git a/make/config/nativewindow/jawt-common.cfg b/make/config/nativewindow/jawt-common.cfg new file mode 100644 index 000000000..4ed0a88f1 --- /dev/null +++ b/make/config/nativewindow/jawt-common.cfg @@ -0,0 +1,26 @@ +# Common JAWT config file +Style AllStatic +Package com.jogamp.nativewindow.impl.jawt +JavaClass JAWTFactory +JavaOutputDir gensrc/classes +#NativeOutputDir gensrc/native/ + +HierarchicalNativeOutput false + +Opaque boolean jboolean +Opaque long struct jawt_DrawingSurface* + +ReturnValueCapacity GetDrawingSurface sizeof(JAWT_DrawingSurface) +ReturnValueCapacity GetDrawingSurfaceInfo sizeof(JAWT_DrawingSurfaceInfo) + +IgnoreField JAWT GetComponent +IgnoreField JAWT_DrawingSurfaceInfo platformInfo + +IncludeAs CustomJavaCode JAWT jawt-CustomJavaCode.java + +CustomCCode #include + +import java.security.* +import com.jogamp.nativewindow.impl.jawt.* + +IncludeAs CustomJavaCode JAWT_DrawingSurfaceInfo jawt-DrawingSurfaceInfo-CustomJavaCode.java diff --git a/make/config/nativewindow/jawt-macosx.cfg b/make/config/nativewindow/jawt-macosx.cfg index dea1a27b7..e018af0dc 100644 --- a/make/config/nativewindow/jawt-macosx.cfg +++ b/make/config/nativewindow/jawt-macosx.cfg @@ -1,30 +1,14 @@ # This .cfg file is used to generate the interface to the JAWT, which # is used by the MacOSXOnscreenGLContext. -Style AllStatic -Package com.jogamp.nativewindow.impl.jawt -JavaClass JAWTFactory -JavaOutputDir gensrc/classes +Include jawt-common.cfg NativeOutputDir gensrc/native/MacOSX -HierarchicalNativeOutput false - -Opaque boolean jboolean Opaque long void * Opaque long NSView * -IgnoreField JAWT GetComponent -IgnoreField JAWT_DrawingSurfaceInfo platformInfo - -IncludeAs CustomJavaCode JAWT jawt-CustomJavaCode.java - CustomCCode #include -CustomCCode #include CustomCCode #include -import java.security.* -import com.jogamp.nativewindow.impl.jawt.* StructPackage JAWT_MacOSXDrawingSurfaceInfo com.jogamp.nativewindow.impl.jawt.macosx EmitStruct JAWT_MacOSXDrawingSurfaceInfo Implements JAWT_MacOSXDrawingSurfaceInfo JAWT_PlatformInfo - -IncludeAs CustomJavaCode JAWT_DrawingSurfaceInfo jawt-DrawingSurfaceInfo-CustomJavaCode.java diff --git a/make/config/nativewindow/jawt-win32.cfg b/make/config/nativewindow/jawt-win32.cfg index af0c7ce29..00b3a3322 100644 --- a/make/config/nativewindow/jawt-win32.cfg +++ b/make/config/nativewindow/jawt-win32.cfg @@ -1,30 +1,15 @@ # This .cfg file is used to generate the interface to the JAWT, which # is used by the WindowsOnscreenGLContext. -Style AllStatic -Package com.jogamp.nativewindow.impl.jawt -JavaClass JAWTFactory -JavaOutputDir gensrc/classes +Include jawt-common.cfg NativeOutputDir gensrc/native/Windows -HierarchicalNativeOutput false - -Opaque boolean jboolean Opaque long HDC -IgnoreField JAWT GetComponent -IgnoreField JAWT_DrawingSurfaceInfo platformInfo IgnoreField JAWT_Win32DrawingSurfaceInfo null IgnoreField JAWT_Win32DrawingSurfaceInfo hpalette -IncludeAs CustomJavaCode JAWT jawt-CustomJavaCode.java - -CustomCCode #include Include ../intptr.cfg -import java.security.* -import com.jogamp.nativewindow.impl.jawt.* StructPackage JAWT_Win32DrawingSurfaceInfo com.jogamp.nativewindow.impl.jawt.windows EmitStruct JAWT_Win32DrawingSurfaceInfo Implements JAWT_Win32DrawingSurfaceInfo JAWT_PlatformInfo - -IncludeAs CustomJavaCode JAWT_DrawingSurfaceInfo jawt-DrawingSurfaceInfo-CustomJavaCode.java diff --git a/make/config/nativewindow/jawt-x11.cfg b/make/config/nativewindow/jawt-x11.cfg index ccfe009dd..4e7ed267b 100644 --- a/make/config/nativewindow/jawt-x11.cfg +++ b/make/config/nativewindow/jawt-x11.cfg @@ -1,30 +1,15 @@ # This .cfg file is used to generate the interface to the JAWT, which # is used by the X11OnscreenGLContext. -Style AllStatic -Package com.jogamp.nativewindow.impl.jawt -JavaClass JAWTFactory -JavaOutputDir gensrc/classes +Include jawt-common.cfg NativeOutputDir gensrc/native/X11 -HierarchicalNativeOutput false - -Opaque boolean jboolean Opaque long Drawable Opaque long Display * -IgnoreField JAWT GetComponent -IgnoreField JAWT_DrawingSurfaceInfo platformInfo IgnoreField JAWT_X11DrawingSurfaceInfo GetAWTColor -IncludeAs CustomJavaCode JAWT jawt-CustomJavaCode.java - CustomCCode #include -CustomCCode #include -import java.security.* -import com.jogamp.nativewindow.impl.jawt.* StructPackage JAWT_X11DrawingSurfaceInfo com.jogamp.nativewindow.impl.jawt.x11 EmitStruct JAWT_X11DrawingSurfaceInfo Implements JAWT_X11DrawingSurfaceInfo JAWT_PlatformInfo - -IncludeAs CustomJavaCode JAWT_DrawingSurfaceInfo jawt-DrawingSurfaceInfo-CustomJavaCode.java 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 d0529878f..68e61cd85 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTWindow.java @@ -37,6 +37,7 @@ 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; @@ -60,6 +61,7 @@ public abstract class JAWTWindow implements NativeWindow { // lifetime: valid after lock, forever until invalidate protected long drawable; + protected Rectangle bounds; public JAWTWindow(Object comp, AbstractGraphicsConfiguration config) { if (config == null) { @@ -80,6 +82,7 @@ public abstract class JAWTWindow implements NativeWindow { public synchronized void invalidate() { component = null; drawable= 0; + bounds = new Rectangle(); } public synchronized void destroy() { @@ -91,9 +94,18 @@ public abstract class JAWTWindow implements NativeWindow { invalidate(); } + protected void updateBounds(JAWT_Rectangle jawtBounds) { + bounds.setX(jawtBounds.getX()); + bounds.setY(jawtBounds.getY()); + bounds.setWidth(jawtBounds.getWidth()); + bounds.setHeight(jawtBounds.getHeight()); + } + private volatile Exception lockedStack = null; - public synchronized int lockSurface() throws NativeWindowException { + protected abstract int lockSurfaceImpl() throws NativeWindowException; + + public final synchronized int lockSurface() throws NativeWindowException { // We have to be the owner of the JAWT ToolkitLock 'lock' to benefit from it's // recursive and blocking lock capabitlites. // Otherwise a followup ToolkitLock would deadlock, @@ -107,15 +119,18 @@ public abstract class JAWTWindow implements NativeWindow { } lockedStack = new Exception("JAWT Surface previously locked by "+Thread.currentThread().getName()); - return LOCK_SUCCESS; + return lockSurfaceImpl(); } + protected abstract void unlockSurfaceImpl() throws NativeWindowException; + public synchronized void unlockSurface() { if (null!=lockedStack) { lockedStack = null; } else { throw new NativeWindowException("JAWT Surface not locked"); } + unlockSurfaceImpl(); NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock(); } @@ -165,12 +180,16 @@ 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; } + public String toString() { StringBuffer sb = new StringBuffer(); sb.append("JAWT-Window["+ "windowHandle 0x"+Long.toHexString(getWindowHandle())+ - ", surfaceHandle 0x"+Long.toHexString(getSurfaceHandle())); + ", surfaceHandle 0x"+Long.toHexString(getSurfaceHandle())+ + ", bounds "+bounds); if(null!=component) { sb.append(", pos "+component.getX()+"/"+component.getY()+", size "+getWidth()+"x"+getHeight()+ ", visible "+component.isVisible()); @@ -183,4 +202,5 @@ public abstract class JAWTWindow implements NativeWindow { return sb.toString(); } + } diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java index 967d43d60..ed932ff91 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java @@ -57,20 +57,18 @@ public class MacOSXJAWTWindow extends JAWTWindow { protected void initNative() throws NativeWindowException { } - public int lockSurface() throws NativeWindowException { - int ret = super.lockSurface(); - if(NativeWindow.LOCK_SUCCESS != ret) { - return ret; - } + protected int lockSurfaceImpl() throws NativeWindowException { + int ret = NativeWindow.LOCK_SUCCESS; ds = JAWT.getJAWT().GetDrawingSurface(component); if (ds == null) { // Widget not yet realized - super.unlockSurface(); + unlockSurface(); return NativeWindow.LOCK_SURFACE_NOT_READY; } int res = ds.Lock(); - if ((res & JAWTFactory.JAWT_LOCK_ERROR) != 0) { - super.unlockSurface(); + dsLocked = ( 0 == ( res & JAWTFactory.JAWT_LOCK_ERROR ) ) ; + if (!dsLocked) { + unlockSurface(); throw new NativeWindowException("Unable to lock surface"); } // See whether the surface changed and if so destroy the old @@ -92,56 +90,44 @@ public class MacOSXJAWTWindow extends JAWTWindow { dsi = ds.GetDrawingSurfaceInfo(); } if (dsi == null) { - // Widget not yet realized - ds.Unlock(); - JAWT.getJAWT().FreeDrawingSurface(ds); - ds = null; - super.unlockSurface(); + unlockSurface(); return NativeWindow.LOCK_SURFACE_NOT_READY; } firstLock = false; macosxdsi = (JAWT_MacOSXDrawingSurfaceInfo) dsi.platformInfo(); if (macosxdsi == null) { - // Widget not yet realized - ds.FreeDrawingSurfaceInfo(dsi); - ds.Unlock(); - JAWT.getJAWT().FreeDrawingSurface(ds); - ds = null; - dsi = null; - super.unlockSurface(); + unlockSurface(); return NativeWindow.LOCK_SURFACE_NOT_READY; } drawable = macosxdsi.getCocoaViewRef(); if (drawable == 0) { - // Widget not yet realized - ds.FreeDrawingSurfaceInfo(dsi); - ds.Unlock(); - JAWT.getJAWT().FreeDrawingSurface(ds); - ds = null; - dsi = null; - macosxdsi = null; - super.unlockSurface(); + unlockSurface(); return NativeWindow.LOCK_SURFACE_NOT_READY; + } else { + updateBounds(dsi.getBounds()); } return ret; } - public void unlockSurface() throws NativeWindowException { - if(!isSurfaceLocked()) { - throw new RuntimeException("JAWTWindow not locked"); + protected void unlockSurfaceImpl() throws NativeWindowException { + if(null!=ds) { + if (null!=dsi) { + ds.FreeDrawingSurfaceInfo(dsi); + } + if (dsLocked) { + ds.Unlock(); + } + JAWT.getJAWT().FreeDrawingSurface(ds); } - ds.FreeDrawingSurfaceInfo(dsi); - ds.Unlock(); - JAWT.getJAWT().FreeDrawingSurface(ds); ds = null; dsi = null; macosxdsi = null; - super.unlockSurface(); } // Variables for lockSurface/unlockSurface private JAWT_DrawingSurface ds; + private boolean dsLocked; private JAWT_DrawingSurfaceInfo dsi; private JAWT_MacOSXDrawingSurfaceInfo macosxdsi; 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 7d680dfa0..c3b3682fd 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 @@ -61,12 +61,8 @@ public class WindowsJAWTWindow extends JAWTWindow { windowHandle = 0; } - public int lockSurface() throws NativeWindowException { - int ret = super.lockSurface(); - if(LOCK_SUCCESS != ret) { - return ret; - } - + protected int lockSurfaceImpl() throws NativeWindowException { + int ret = NativeWindow.LOCK_SUCCESS; long startTime; if (PROFILING) { startTime = System.currentTimeMillis(); @@ -74,12 +70,13 @@ public class WindowsJAWTWindow extends JAWTWindow { ds = JAWT.getJAWT().GetDrawingSurface(component); if (ds == null) { // Widget not yet realized - super.unlockSurface(); + unlockSurface(); return LOCK_SURFACE_NOT_READY; } int res = ds.Lock(); - if ((res & JAWTFactory.JAWT_LOCK_ERROR) != 0) { - super.unlockSurface(); + dsLocked = ( 0 == ( res & JAWTFactory.JAWT_LOCK_ERROR ) ) ; + if (!dsLocked) { + unlockSurface(); throw new NativeWindowException("Unable to lock surface"); } // See whether the surface changed and if so destroy the old @@ -92,36 +89,21 @@ public class WindowsJAWTWindow extends JAWTWindow { } dsi = ds.GetDrawingSurfaceInfo(); if (dsi == null) { - // Widget not yet realized - ds.Unlock(); - JAWT.getJAWT().FreeDrawingSurface(ds); - ds = null; - super.unlockSurface(); + unlockSurface(); return LOCK_SURFACE_NOT_READY; } win32dsi = (JAWT_Win32DrawingSurfaceInfo) dsi.platformInfo(); if (win32dsi == null) { - // Widget not yet realized - ds.FreeDrawingSurfaceInfo(dsi); - ds.Unlock(); - JAWT.getJAWT().FreeDrawingSurface(ds); - ds = null; - dsi = null; - super.unlockSurface(); + unlockSurface(); return LOCK_SURFACE_NOT_READY; } windowHandle = win32dsi.getHandle(); drawable = win32dsi.getHdc(); if (windowHandle == 0 || drawable == 0) { - // Widget not yet realized - ds.FreeDrawingSurfaceInfo(dsi); - ds.Unlock(); - JAWT.getJAWT().FreeDrawingSurface(ds); - ds = null; - dsi = null; - win32dsi = null; - super.unlockSurface(); + unlockSurface(); return LOCK_SURFACE_NOT_READY; + } else { + updateBounds(dsi.getBounds()); } if (PROFILING) { long endTime = System.currentTimeMillis(); @@ -136,21 +118,23 @@ public class WindowsJAWTWindow extends JAWTWindow { return ret; } - public void unlockSurface() { - if(!isSurfaceLocked()) { - throw new RuntimeException("JAWTWindow not locked"); - } + protected void unlockSurfaceImpl() throws NativeWindowException { long startTime = 0; if (PROFILING) { startTime = System.currentTimeMillis(); } - ds.FreeDrawingSurfaceInfo(dsi); - ds.Unlock(); - JAWT.getJAWT().FreeDrawingSurface(ds); + if(null!=ds) { + if (null!=dsi) { + ds.FreeDrawingSurfaceInfo(dsi); + } + if (dsLocked) { + ds.Unlock(); + } + JAWT.getJAWT().FreeDrawingSurface(ds); + } ds = null; dsi = null; win32dsi = null; - super.unlockSurface(); if (PROFILING) { long endTime = System.currentTimeMillis(); profilingUnlockSurfaceTime += (endTime - startTime); @@ -169,6 +153,7 @@ public class WindowsJAWTWindow extends JAWTWindow { // Variables for lockSurface/unlockSurface private JAWT_DrawingSurface ds; + private boolean dsLocked; private JAWT_DrawingSurfaceInfo dsi; private JAWT_Win32DrawingSurfaceInfo win32dsi; private long profilingLockSurfaceTime = 0; diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11JAWTWindow.java index 77bf93204..f7151d9f1 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11JAWTWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11JAWTWindow.java @@ -69,20 +69,18 @@ public class X11JAWTWindow extends JAWTWindow { } } - public synchronized int lockSurface() throws NativeWindowException { - int ret = super.lockSurface(); - if(LOCK_SUCCESS != ret) { - return ret; - } + protected int lockSurfaceImpl() throws NativeWindowException { + int ret = NativeWindow.LOCK_SUCCESS; ds = JAWT.getJAWT().GetDrawingSurface(component); if (ds == null) { // Widget not yet realized - super.unlockSurface(); + unlockSurface(); return LOCK_SURFACE_NOT_READY; } int res = ds.Lock(); - if ((res & JAWTFactory.JAWT_LOCK_ERROR) != 0) { - super.unlockSurface(); + dsLocked = ( 0 == ( res & JAWTFactory.JAWT_LOCK_ERROR ) ) ; + if (!dsLocked) { + unlockSurface(); throw new NativeWindowException("Unable to lock surface"); } // See whether the surface changed and if so destroy the old @@ -95,55 +93,42 @@ public class X11JAWTWindow extends JAWTWindow { } dsi = ds.GetDrawingSurfaceInfo(); if (dsi == null) { - // Widget not yet realized - ds.Unlock(); - JAWT.getJAWT().FreeDrawingSurface(ds); - ds = null; - super.unlockSurface(); + unlockSurface(); return LOCK_SURFACE_NOT_READY; } x11dsi = (JAWT_X11DrawingSurfaceInfo) dsi.platformInfo(); if (x11dsi == null) { - // Widget not yet realized - ds.FreeDrawingSurfaceInfo(dsi); - ds.Unlock(); - JAWT.getJAWT().FreeDrawingSurface(ds); - ds = null; - dsi = null; - super.unlockSurface(); + unlockSurface(); return LOCK_SURFACE_NOT_READY; } drawable = x11dsi.getDrawable(); if (drawable == 0) { - // Widget not yet realized - ds.FreeDrawingSurfaceInfo(dsi); - ds.Unlock(); - JAWT.getJAWT().FreeDrawingSurface(ds); - ds = null; - dsi = null; - x11dsi = null; - drawable = 0; - super.unlockSurface(); + unlockSurface(); return LOCK_SURFACE_NOT_READY; + } else { + updateBounds(dsi.getBounds()); } return ret; } - public synchronized void unlockSurface() { - if(!isSurfaceLocked()) { - throw new RuntimeException("JAWTWindow not locked"); + protected void unlockSurfaceImpl() throws NativeWindowException { + if(null!=ds) { + if (null!=dsi) { + ds.FreeDrawingSurfaceInfo(dsi); + } + if (dsLocked) { + ds.Unlock(); + } + JAWT.getJAWT().FreeDrawingSurface(ds); } - ds.FreeDrawingSurfaceInfo(dsi); - ds.Unlock(); - JAWT.getJAWT().FreeDrawingSurface(ds); ds = null; dsi = null; x11dsi = null; - super.unlockSurface(); } // Variables for lockSurface/unlockSurface private JAWT_DrawingSurface ds; + private boolean dsLocked; private JAWT_DrawingSurfaceInfo dsi; private JAWT_X11DrawingSurfaceInfo x11dsi; diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/util/Rectangle.java b/src/nativewindow/classes/com/jogamp/nativewindow/util/Rectangle.java new file mode 100644 index 000000000..9f487f847 --- /dev/null +++ b/src/nativewindow/classes/com/jogamp/nativewindow/util/Rectangle.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2010, Sven Gothel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the name of Sven Gothel nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 Sven Gothel 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. + */ + +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+"]"); + } +} + diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtFactoryAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtFactoryAWT.java new file mode 100644 index 000000000..e0f86b1a9 --- /dev/null +++ b/src/newt/classes/com/jogamp/newt/awt/NewtFactoryAWT.java @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2010 Sven Gothel. 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 Sven Gothel 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 + * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.jogamp.newt.impl.awt; + +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.awt.Component; +import java.awt.Canvas; + +import javax.media.opengl.*; +import javax.media.nativewindow.*; +import javax.media.nativewindow.awt.*; + +import com.jogamp.newt.event.awt.AWTParentWindowAdapter; +import com.jogamp.newt.Display; +import com.jogamp.newt.Screen; +import com.jogamp.newt.Window; +import com.jogamp.newt.NewtFactory; +import com.jogamp.common.util.ReflectionUtil; + +public class AWTNewtFactory extends NewtFactory { + + /** + * Wraps an AWT component into a {@link javax.media.nativewindow.NativeWindow} utilizing the {@link javax.media.nativewindow.NativeWindowFactory},
+ * using a configuration agnostic dummy {@link javax.media.nativewindow.DefaultGraphicsConfiguration}.
+ *

+ * The actual wrapping implementation is {@link com.jogamp.nativewindow.impl.jawt.JAWTWindow}.

+ *

+ * Purpose of this wrapping is to access the AWT window handle,
+ * not to actually render into it.
+ * Hence the dummy configuration only.

+ * + * @param awtCompObject must be of type java.awt.Component + */ + public static NativeWindow getNativeWindow(Object awtCompObject, Capabilities capsRequested) { + if(null==awtCompObject) { + throw new NativeWindowException("Null AWT Component"); + } + if( ! (awtCompObject instanceof java.awt.Component) ) { + throw new NativeWindowException("AWT Component not a java.awt.Component"); + } + return getNativeWindow( (java.awt.Component) awtCompObject, capsRequested ); + } + + public static NativeWindow getNativeWindow(java.awt.Component awtComp, Capabilities capsRequested) { + DefaultGraphicsConfiguration config = + AWTGraphicsConfiguration.create(awtComp, (Capabilities) capsRequested.clone(), capsRequested); + NativeWindow awtNative = NativeWindowFactory.getNativeWindow(awtComp, config); // a JAWTWindow + return awtNative; + } + + /** + * Creates a native NEWT child window to a AWT parent window.
+ *

+ * First we create a {@link javax.media.nativewindow.NativeWindow} presentation of the given {@link java.awt.Component}, + * utilizing {@link #getNativeWindow(java.awt.Component)}.
+ * The actual wrapping implementation is {@link com.jogamp.nativewindow.impl.jawt.JAWTWindow}.

+ *

+ * Second we create a child {@link com.jogamp.newt.Window}, + * utilizing {@link com.jogamp.newt.NewtFactory#createWindowImpl(java.lang.String, javax.media.nativewindow.NativeWindow, com.jogamp.newt.Screen, javax.media.nativewindow.Capabilities, boolean)}, + * passing the created {@link javax.media.nativewindow.NativeWindow}.

+ + *

+ * Third we attach a {@link com.jogamp.newt.event.awt.AWTParentWindowAdapter} to the given AWT component.
+ * The adapter passes window related events to our new child window, look at the implementation

+ * + *

+ * Forth we pass the parents visibility to the new Window

+ * + * @param awtParentObject must be of type java.awt.Component + * @param undecorated only impacts if the window is in top-level state, while attached to a parent window it's rendered undecorated always + * @return The successful created child window, or null if the AWT parent is not ready yet (no valid peers) + */ + public static Window createNativeChildWindow(Object awtParentObject, Capabilities newtCaps, boolean undecorated) { + if( null == awtParentObject ) { + throw new NativeWindowException("Null AWT Parent Component"); + } + if( ! (awtParentObject instanceof java.awt.Component) ) { + throw new NativeWindowException("AWT Parent Component not a java.awt.Component"); + } + java.awt.Component awtParent = (java.awt.Component) awtParentObject; + + // Generate a complete JAWT NativeWindow from the AWT Component + NativeWindow parent = getNativeWindow(awtParent, newtCaps); + if(null==parent) { + throw new NativeWindowException("Null NativeWindow from parent: "+awtParent); + } + + // Get parent's NativeWindow details + AWTGraphicsConfiguration parentConfig = (AWTGraphicsConfiguration) parent.getGraphicsConfiguration(); + AWTGraphicsScreen parentScreen = (AWTGraphicsScreen) parentConfig.getScreen(); + AWTGraphicsDevice parentDevice = (AWTGraphicsDevice) parentScreen.getDevice(); + + // Prep NEWT's Display and Screen according to the parent + final String type = NativeWindowFactory.getNativeWindowType(true); + Display display = NewtFactory.wrapDisplay(type, parentDevice.getHandle()); + Screen screen = NewtFactory.createScreen(type, display, parentScreen.getIndex()); + + // NEWT Window creation and add event handler for proper propagation AWT -> NEWT + // and copy size/visible state + Window window = NewtFactory.createWindowImpl(type, parent, screen, newtCaps, undecorated); + new AWTParentWindowAdapter(window).addTo(awtParent); + window.setSize(awtParent.getWidth(), awtParent.getHeight()); + window.setVisible(awtParent.isVisible()); + + return window; + } +} + diff --git a/src/newt/classes/com/jogamp/newt/impl/awt/AWTNewtFactory.java b/src/newt/classes/com/jogamp/newt/impl/awt/AWTNewtFactory.java deleted file mode 100644 index e0f86b1a9..000000000 --- a/src/newt/classes/com/jogamp/newt/impl/awt/AWTNewtFactory.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2010 Sven Gothel. 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 Sven Gothel 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 - * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - */ - -package com.jogamp.newt.impl.awt; - -import java.awt.GraphicsConfiguration; -import java.awt.GraphicsDevice; -import java.awt.Component; -import java.awt.Canvas; - -import javax.media.opengl.*; -import javax.media.nativewindow.*; -import javax.media.nativewindow.awt.*; - -import com.jogamp.newt.event.awt.AWTParentWindowAdapter; -import com.jogamp.newt.Display; -import com.jogamp.newt.Screen; -import com.jogamp.newt.Window; -import com.jogamp.newt.NewtFactory; -import com.jogamp.common.util.ReflectionUtil; - -public class AWTNewtFactory extends NewtFactory { - - /** - * Wraps an AWT component into a {@link javax.media.nativewindow.NativeWindow} utilizing the {@link javax.media.nativewindow.NativeWindowFactory},
- * using a configuration agnostic dummy {@link javax.media.nativewindow.DefaultGraphicsConfiguration}.
- *

- * The actual wrapping implementation is {@link com.jogamp.nativewindow.impl.jawt.JAWTWindow}.

- *

- * Purpose of this wrapping is to access the AWT window handle,
- * not to actually render into it.
- * Hence the dummy configuration only.

- * - * @param awtCompObject must be of type java.awt.Component - */ - public static NativeWindow getNativeWindow(Object awtCompObject, Capabilities capsRequested) { - if(null==awtCompObject) { - throw new NativeWindowException("Null AWT Component"); - } - if( ! (awtCompObject instanceof java.awt.Component) ) { - throw new NativeWindowException("AWT Component not a java.awt.Component"); - } - return getNativeWindow( (java.awt.Component) awtCompObject, capsRequested ); - } - - public static NativeWindow getNativeWindow(java.awt.Component awtComp, Capabilities capsRequested) { - DefaultGraphicsConfiguration config = - AWTGraphicsConfiguration.create(awtComp, (Capabilities) capsRequested.clone(), capsRequested); - NativeWindow awtNative = NativeWindowFactory.getNativeWindow(awtComp, config); // a JAWTWindow - return awtNative; - } - - /** - * Creates a native NEWT child window to a AWT parent window.
- *

- * First we create a {@link javax.media.nativewindow.NativeWindow} presentation of the given {@link java.awt.Component}, - * utilizing {@link #getNativeWindow(java.awt.Component)}.
- * The actual wrapping implementation is {@link com.jogamp.nativewindow.impl.jawt.JAWTWindow}.

- *

- * Second we create a child {@link com.jogamp.newt.Window}, - * utilizing {@link com.jogamp.newt.NewtFactory#createWindowImpl(java.lang.String, javax.media.nativewindow.NativeWindow, com.jogamp.newt.Screen, javax.media.nativewindow.Capabilities, boolean)}, - * passing the created {@link javax.media.nativewindow.NativeWindow}.

- - *

- * Third we attach a {@link com.jogamp.newt.event.awt.AWTParentWindowAdapter} to the given AWT component.
- * The adapter passes window related events to our new child window, look at the implementation

- * - *

- * Forth we pass the parents visibility to the new Window

- * - * @param awtParentObject must be of type java.awt.Component - * @param undecorated only impacts if the window is in top-level state, while attached to a parent window it's rendered undecorated always - * @return The successful created child window, or null if the AWT parent is not ready yet (no valid peers) - */ - public static Window createNativeChildWindow(Object awtParentObject, Capabilities newtCaps, boolean undecorated) { - if( null == awtParentObject ) { - throw new NativeWindowException("Null AWT Parent Component"); - } - if( ! (awtParentObject instanceof java.awt.Component) ) { - throw new NativeWindowException("AWT Parent Component not a java.awt.Component"); - } - java.awt.Component awtParent = (java.awt.Component) awtParentObject; - - // Generate a complete JAWT NativeWindow from the AWT Component - NativeWindow parent = getNativeWindow(awtParent, newtCaps); - if(null==parent) { - throw new NativeWindowException("Null NativeWindow from parent: "+awtParent); - } - - // Get parent's NativeWindow details - AWTGraphicsConfiguration parentConfig = (AWTGraphicsConfiguration) parent.getGraphicsConfiguration(); - AWTGraphicsScreen parentScreen = (AWTGraphicsScreen) parentConfig.getScreen(); - AWTGraphicsDevice parentDevice = (AWTGraphicsDevice) parentScreen.getDevice(); - - // Prep NEWT's Display and Screen according to the parent - final String type = NativeWindowFactory.getNativeWindowType(true); - Display display = NewtFactory.wrapDisplay(type, parentDevice.getHandle()); - Screen screen = NewtFactory.createScreen(type, display, parentScreen.getIndex()); - - // NEWT Window creation and add event handler for proper propagation AWT -> NEWT - // and copy size/visible state - Window window = NewtFactory.createWindowImpl(type, parent, screen, newtCaps, undecorated); - new AWTParentWindowAdapter(window).addTo(awtParent); - window.setSize(awtParent.getWidth(), awtParent.getHeight()); - window.setVisible(awtParent.isVisible()); - - return window; - } -} - -- cgit v1.2.3