diff options
Diffstat (limited to 'src/nativewindow')
6 files changed, 443 insertions, 192 deletions
diff --git a/src/nativewindow/classes/javax/media/nativewindow/ProxySurface.java b/src/nativewindow/classes/javax/media/nativewindow/ProxySurface.java new file mode 100644 index 000000000..038580ce0 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/ProxySurface.java @@ -0,0 +1,150 @@ +/** + * 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 javax.media.nativewindow; + +import com.jogamp.common.util.locks.RecursiveLock; + +public abstract class ProxySurface implements NativeSurface { + protected RecursiveLock surfaceLock = new RecursiveLock(); + protected AbstractGraphicsConfiguration config; + protected long displayHandle; + protected int height; + protected int scrnIndex; + protected int width; + + public ProxySurface(AbstractGraphicsConfiguration cfg) { + invalidate(); + config = cfg; + displayHandle=cfg.getScreen().getDevice().getHandle(); + } + + void invalidate() { + displayHandle = 0; + invalidateImpl(); + } + protected abstract void invalidateImpl(); + + public final long getDisplayHandle() { + return displayHandle; + } + + public final AbstractGraphicsConfiguration getGraphicsConfiguration() { + return config; + } + + public final int getScreenIndex() { + return config.getScreen().getIndex(); + } + + public abstract long getSurfaceHandle(); + + public final int getWidth() { + return width; + } + + public final int getHeight() { + return height; + } + + public void setSize(int width, int height) { + this.width = width; + this.height = height; + } + + public boolean surfaceSwap() { + return false; + } + + public void surfaceUpdated(Object updater, NativeSurface ns, long when) { + } + + public int lockSurface() throws NativeWindowException { + surfaceLock.lock(); + int res = surfaceLock.getRecursionCount() == 0 ? LOCK_SURFACE_NOT_READY : LOCK_SUCCESS; + + if ( LOCK_SURFACE_NOT_READY == res ) { + try { + final AbstractGraphicsDevice adevice = config.getScreen().getDevice(); + adevice.lock(); + try { + res = lockSurfaceImpl(); + } finally { + if (LOCK_SURFACE_NOT_READY >= res) { + adevice.unlock(); + } + } + } finally { + if (LOCK_SURFACE_NOT_READY >= res) { + surfaceLock.unlock(); + } + } + } + return res; + } + + public final void unlockSurface() { + surfaceLock.validateLocked(); + + if (surfaceLock.getRecursionCount() == 0) { + final AbstractGraphicsDevice adevice = config.getScreen().getDevice(); + try { + unlockSurfaceImpl(); + } finally { + adevice.unlock(); + } + } + surfaceLock.unlock(); + } + + protected abstract int lockSurfaceImpl(); + + protected abstract void unlockSurfaceImpl() ; + + public final void validateSurfaceLocked() { + surfaceLock.validateLocked(); + } + + public final boolean isSurfaceLocked() { + return surfaceLock.isLocked(); + } + + public final boolean isSurfaceLockedByOtherThread() { + return surfaceLock.isLockedByOtherThread(); + } + + public final Thread getSurfaceLockOwner() { + return surfaceLock.getOwner(); + } + + public final int getSurfaceRecursionCount() { + return surfaceLock.getRecursionCount(); + } + + public abstract String toString(); +} diff --git a/src/nativewindow/classes/jogamp/nativewindow/ProxySurface.java b/src/nativewindow/classes/jogamp/nativewindow/ProxySurface.java deleted file mode 100644 index 6dfbb2a91..000000000 --- a/src/nativewindow/classes/jogamp/nativewindow/ProxySurface.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * 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 jogamp.nativewindow; - -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; - -import com.jogamp.common.util.locks.RecursiveLock; - -public class ProxySurface implements NativeSurface, SurfaceChangeable { - private RecursiveLock recurLock = new RecursiveLock(); - protected AbstractGraphicsConfiguration config; - protected long displayHandle; - protected long surfaceHandle; - protected int scrnIndex; - protected int width, height; - - public ProxySurface(AbstractGraphicsConfiguration cfg) { - this(cfg, 0); - } - - public ProxySurface(AbstractGraphicsConfiguration cfg, long handle) { - invalidate(); - config = cfg; - displayHandle=cfg.getScreen().getDevice().getHandle(); - surfaceHandle=handle; - 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 final int lockSurface() throws NativeWindowException { - recurLock.lock(); - - if(recurLock.getRecursionCount() == 0) { - config.getScreen().getDevice().lock(); - } - return LOCK_SUCCESS; - } - - public final void unlockSurface() { - recurLock.validateLocked(); - - if(recurLock.getRecursionCount()==0) { - config.getScreen().getDevice().unlock(); - } - recurLock.unlock(); - } - - public final void validateSurfaceLocked() { - recurLock.validateLocked(); - } - - public final int getSurfaceRecursionCount() { - return recurLock.getRecursionCount(); - } - - public final boolean isSurfaceLockedByOtherThread() { - return recurLock.isLockedByOtherThread(); - } - - public final boolean isSurfaceLocked() { - return recurLock.isLocked(); - } - - public final Thread getSurfaceLockOwner() { - return recurLock.getOwner(); - } - - 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 "ProxySurface[config "+config+ - ", displayHandle 0x"+Long.toHexString(getDisplayHandle())+ - ", surfaceHandle 0x"+Long.toHexString(getSurfaceHandle())+ - ", size "+getWidth()+"x"+getHeight()+"]"; - } - -} diff --git a/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java b/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java new file mode 100644 index 000000000..4c2b1c875 --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/WrappedSurface.java @@ -0,0 +1,70 @@ +/** + * 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 jogamp.nativewindow; + +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.ProxySurface; +import javax.media.nativewindow.SurfaceChangeable; + + +public class WrappedSurface extends ProxySurface implements SurfaceChangeable { + protected long surfaceHandle; + + public WrappedSurface(AbstractGraphicsConfiguration cfg) { + this(cfg, 0); + } + + public WrappedSurface(AbstractGraphicsConfiguration cfg, long handle) { + super(cfg); + surfaceHandle=handle; + } + + protected final void invalidateImpl() { + surfaceHandle = 0; + } + + public long getSurfaceHandle() { + return surfaceHandle; + } + + public void setSurfaceHandle(long surfaceHandle) { + this.surfaceHandle=surfaceHandle; + } + + protected int lockSurfaceImpl() { + return LOCK_SUCCESS; + } + + protected void unlockSurfaceImpl() { + } + + public String toString() { + return "WrappedSurface[config " + config + ", displayHandle 0x" + Long.toHexString(getDisplayHandle()) + ", surfaceHandle 0x" + Long.toHexString(getSurfaceHandle()) + ", size " + getWidth() + "x" + getHeight() + "]"; + } +} diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java index 944c08604..781882f08 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java @@ -42,6 +42,7 @@ import com.jogamp.common.util.locks.RecursiveLock; import java.awt.Component; import java.awt.Window; import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.AbstractGraphicsDevice; import javax.media.nativewindow.NativeSurface; import javax.media.nativewindow.NativeWindow; import javax.media.nativewindow.NativeWindowException; @@ -106,58 +107,60 @@ public abstract class JAWTWindow implements NativeWindow { // NativeSurface // - private RecursiveLock recurLock = new RecursiveLock(); + private RecursiveLock surfaceLock = new RecursiveLock(); protected abstract int lockSurfaceImpl() throws NativeWindowException; public final int lockSurface() throws NativeWindowException { - int res = LOCK_SURFACE_NOT_READY; + surfaceLock.lock(); + int res = surfaceLock.getRecursionCount() == 0 ? LOCK_SURFACE_NOT_READY : LOCK_SUCCESS; - recurLock.lock(); - - if(recurLock.getRecursionCount() == 0) { - config.getScreen().getDevice().lock(); + if ( LOCK_SURFACE_NOT_READY == res ) { try { - res = lockSurfaceImpl(); + final AbstractGraphicsDevice adevice = config.getScreen().getDevice(); + adevice.lock(); + try { + res = lockSurfaceImpl(); + } finally { + if (LOCK_SURFACE_NOT_READY >= res) { + adevice.unlock(); + } + } } finally { - // Unlock in case surface couldn't be locked - if(LOCK_SURFACE_NOT_READY >= res ) { - config.getScreen().getDevice().unlock(); - recurLock.unlock(); + if (LOCK_SURFACE_NOT_READY >= res) { + surfaceLock.unlock(); } } - } else { - res = LOCK_SUCCESS; } - return res; } protected abstract void unlockSurfaceImpl() throws NativeWindowException; public final void unlockSurface() { - recurLock.validateLocked(); + surfaceLock.validateLocked(); - if(recurLock.getRecursionCount()==0) { + if (surfaceLock.getRecursionCount() == 0) { + final AbstractGraphicsDevice adevice = config.getScreen().getDevice(); try { unlockSurfaceImpl(); } finally { - config.getScreen().getDevice().unlock(); + adevice.unlock(); } } - recurLock.unlock(); + surfaceLock.unlock(); } public final boolean isSurfaceLockedByOtherThread() { - return recurLock.isLockedByOtherThread(); + return surfaceLock.isLockedByOtherThread(); } public final boolean isSurfaceLocked() { - return recurLock.isLocked(); + return surfaceLock.isLocked(); } public final Thread getSurfaceLockOwner() { - return recurLock.getOwner(); + return surfaceLock.getOwner(); } public final boolean surfaceSwap() { diff --git a/src/nativewindow/classes/jogamp/nativewindow/swt/SWTAccessor.java b/src/nativewindow/classes/jogamp/nativewindow/swt/SWTAccessor.java new file mode 100644 index 000000000..7f8bccd56 --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/swt/SWTAccessor.java @@ -0,0 +1,112 @@ +/** + * 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 jogamp.nativewindow.swt; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import org.eclipse.swt.graphics.GCData; +import org.eclipse.swt.widgets.Control; + +import javax.media.nativewindow.NativeWindowException; +import com.jogamp.common.util.ReflectionUtil; + +public class SWTAccessor { + static final Method swt_control_internal_new_GC; + static final Method swt_control_internal_dispose_GC; + static final boolean swt_uses_long_handles; + static final Field swt_control_handle; + + static final String str_internal_new_GC = "internal_new_GC"; + static final String str_internal_dispose_GC = "internal_dispose_GC"; + static final String str_handle = "handle"; + + static { + Method m=null; + try { + m = ReflectionUtil.getMethod(Control.class, str_internal_new_GC, new Class[] { GCData.class }); + } catch (Exception ex) { + throw new NativeWindowException(ex); + } + swt_control_internal_new_GC = m; + + boolean swt_uses_long_tmp = false; + try { + m = Control.class.getDeclaredMethod(str_internal_dispose_GC, new Class[] { int.class, GCData.class }); + swt_uses_long_tmp = false; + } catch (NoSuchMethodException ex1) { + try { + m = Control.class.getDeclaredMethod(str_internal_dispose_GC, new Class[] { long.class, GCData.class }); + swt_uses_long_tmp = true; + } catch (NoSuchMethodException ex2) { + throw new NativeWindowException("Neither 'int' nor 'long' variant of '"+str_internal_dispose_GC+"' exist", ex2); + } + } + swt_uses_long_handles = swt_uses_long_tmp; + swt_control_internal_dispose_GC = m; + + Field f = null; + try { + f = Control.class.getField(str_handle); + } catch (Exception ex) { + throw new NativeWindowException(ex); + } + swt_control_handle = f; + } + + public static boolean isUsingLongHandles() { + return swt_uses_long_handles; + } + + public static long getHandle(Control swtControl) { + long h = 0; + try { + h = swt_control_handle.getLong(swtControl); + } catch (Exception ex) { + throw new NativeWindowException(ex); + } + return h; + } + + public static long newGC(Control swtControl, GCData gcData) { + Object o = ReflectionUtil.callMethod(swtControl, swt_control_internal_new_GC, new Object[] { gcData }); + if(o instanceof Number) { + return ((Number)o).longValue(); + } else { + throw new InternalError("SWT internal_new_GC did not return int or long but "+o.getClass()); + } + } + + public static void disposeGC(Control swtControl, long gc, GCData gcData) { + if(swt_uses_long_handles) { + ReflectionUtil.callMethod(swtControl, swt_control_internal_dispose_GC, new Object[] { new Long(gc), gcData }); + } else { + ReflectionUtil.callMethod(swtControl, swt_control_internal_dispose_GC, new Object[] { new Integer((int)gc), gcData }); + } + } +} diff --git a/src/nativewindow/classes/jogamp/nativewindow/windows/GDISurface.java b/src/nativewindow/classes/jogamp/nativewindow/windows/GDISurface.java new file mode 100644 index 000000000..68cf8af45 --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/windows/GDISurface.java @@ -0,0 +1,87 @@ +/** + * 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 jogamp.nativewindow.windows; + +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import javax.media.nativewindow.NativeWindowException; + +import javax.media.nativewindow.ProxySurface; + +/** + * GDI Surface implementation which wraps an existing window handle + * allowing the use of HDC via lockSurface()/unlockSurface() protocol. + * The latter will get and release the HDC. + * The size via getWidth()/getHeight() is invalid. + */ +public class GDISurface extends ProxySurface { + protected long windowHandle; + protected long surfaceHandle; + + public GDISurface(AbstractGraphicsConfiguration cfg, long windowHandle) { + super(cfg); + if(0 == windowHandle) { + throw new NativeWindowException("Error hwnd 0, werr: "+GDI.GetLastError()); + } + this.windowHandle=windowHandle; + } + + protected final void invalidateImpl() { + windowHandle=0; + surfaceHandle=0; + } + + protected int lockSurfaceImpl() { + if (0 != surfaceHandle) { + throw new InternalError("surface not released"); + } + surfaceHandle = GDI.GetDC(windowHandle); + return (0 != surfaceHandle) ? LOCK_SUCCESS : LOCK_SURFACE_NOT_READY; + } + + protected void unlockSurfaceImpl() { + if (0 == surfaceHandle) { + throw new InternalError("surface not acquired"); + } + GDI.ReleaseDC(windowHandle, surfaceHandle); + surfaceHandle=0; + } + + public long getSurfaceHandle() { + return surfaceHandle; + } + + public String toString() { + return "GDISurface[config "+config+ + ", displayHandle 0x"+Long.toHexString(getDisplayHandle())+ + ", windowHandle 0x"+Long.toHexString(windowHandle)+ + ", surfaceHandle 0x"+Long.toHexString(getSurfaceHandle())+ + ", size "+getWidth()+"x"+getHeight()+"]"; + } + +} |