aboutsummaryrefslogtreecommitdiffstats
path: root/src/nativewindow
diff options
context:
space:
mode:
Diffstat (limited to 'src/nativewindow')
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/JAWTWindow.java26
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/macosx/MacOSXJAWTWindow.java56
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/windows/WindowsJAWTWindow.java59
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/jawt/x11/X11JAWTWindow.java57
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/util/Rectangle.java59
5 files changed, 146 insertions, 111 deletions
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+"]");
+ }
+}
+