diff options
Diffstat (limited to 'src/nativewindow/classes/com/sun/nwi')
15 files changed, 1684 insertions, 0 deletions
diff --git a/src/nativewindow/classes/com/sun/nwi/impl/Debug.java b/src/nativewindow/classes/com/sun/nwi/impl/Debug.java new file mode 100644 index 000000000..73379e87b --- /dev/null +++ b/src/nativewindow/classes/com/sun/nwi/impl/Debug.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2003-2005 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. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.sun.nwi.impl; + +import java.security.*; + +/** Helper routines for logging and debugging. */ + +public class Debug { + // Some common properties + private static boolean verbose; + private static boolean debugAll; + + static { + verbose = isPropertyDefined("nwi.verbose"); + debugAll = isPropertyDefined("nwi.debug"); + if (verbose) { + Package p = Package.getPackage("javax.media.nwi"); + System.err.println("NWI specification version " + p.getSpecificationVersion()); + System.err.println("NWI implementation version " + p.getImplementationVersion()); + System.err.println("NWI implementation vendor " + p.getImplementationVendor()); + } + } + + public static boolean getBooleanProperty(final String property) { + Boolean b = (Boolean) AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + boolean val = Boolean.getBoolean(property); + return (val ? Boolean.TRUE : Boolean.FALSE); + } + }); + return b.booleanValue(); + } + + public static boolean isPropertyDefined(final String property) { + Boolean b = (Boolean) AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + String val = System.getProperty(property); + return (val != null ? Boolean.TRUE : Boolean.FALSE); + } + }); + return b.booleanValue(); + } + + public static boolean verbose() { + return verbose; + } + + public static boolean debugAll() { + return debugAll; + } + + public static boolean debug(String subcomponent) { + return debugAll() || isPropertyDefined("nwi.debug." + subcomponent); + } +} diff --git a/src/nativewindow/classes/com/sun/nwi/impl/NWReflection.java b/src/nativewindow/classes/com/sun/nwi/impl/NWReflection.java new file mode 100644 index 000000000..51037af28 --- /dev/null +++ b/src/nativewindow/classes/com/sun/nwi/impl/NWReflection.java @@ -0,0 +1,149 @@ +/* + * 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.sun.nwi.impl; + +import java.lang.reflect.*; +import javax.media.nwi.*; + +public final class NWReflection { + public static final boolean DEBUG = Debug.debug("NWReflection"); + + public static final boolean isClassAvailable(String clazzName) { + try { + Class clazz = Class.forName(clazzName); + return null!=clazz; + } catch (Throwable e) { } + return false; + } + + public static final Class getClass(String clazzName) { + try { + return Class.forName(clazzName); + } catch (Throwable e) { } + return null; + } + + public static final Constructor getConstructor(String clazzName, Class[] cstrArgTypes) { + Class factoryClass = null; + Constructor factory = null; + + try { + factoryClass = Class.forName(clazzName); + if (factoryClass == null) { + throw new NWException(clazzName + " not available"); + } + try { + factory = factoryClass.getDeclaredConstructor( cstrArgTypes ); + } catch(NoSuchMethodException nsme) { + throw new NWException("Constructor: '" + clazzName + "("+cstrArgTypes+")' not found"); + } + return factory; + } catch (Throwable e) { + if (DEBUG) { + e.printStackTrace(); + } + throw new NWException(e); + } + } + + public static final Constructor getConstructor(String clazzName) { + return getConstructor(clazzName, new Class[0]); + } + + public static final Object createInstance(String clazzName, Class[] cstrArgTypes, Object[] cstrArgs) { + Constructor factory = null; + + try { + factory = getConstructor(clazzName, cstrArgTypes); + return factory.newInstance( cstrArgs ) ; + } catch (Exception e) { + throw new NWException(e); + } + } + + public static final Object createInstance(String clazzName, Object[] cstrArgs) { + Class[] cstrArgTypes = new Class[cstrArgs.length]; + for(int i=0; i<cstrArgs.length; i++) { + cstrArgTypes[i] = cstrArgs[i].getClass(); + } + return createInstance(clazzName, cstrArgTypes, cstrArgs); + } + + public static final Object createInstance(String clazzName) { + return createInstance(clazzName, new Class[0], null); + } + + public static final boolean instanceOf(Object obj, String clazzName) { + return instanceOf(obj.getClass(), clazzName); + } + public static final boolean instanceOf(Class clazz, String clazzName) { + do { + if(clazz.getName().equals(clazzName)) { + return true; + } + clazz = clazz.getSuperclass(); + } while (clazz!=null); + return false; + } + + public static final boolean implementationOf(Object obj, String faceName) { + return implementationOf(obj.getClass(), faceName); + } + public static final boolean implementationOf(Class clazz, String faceName) { + do { + Class[] clazzes = clazz.getInterfaces(); + for(int i=clazzes.length-1; i>=0; i--) { + Class face = clazzes[i]; + if(face.getName().equals(faceName)) { + return true; + } + } + clazz = clazz.getSuperclass(); + } while (clazz!=null); + return false; + } + + public static boolean isAWTComponent(Object target) { + return instanceOf(target, "java.awt.Component"); + } + + public static boolean isAWTComponent(Class clazz) { + return instanceOf(clazz, "java.awt.Component"); + } + +} + diff --git a/src/nativewindow/classes/com/sun/nwi/impl/NativeLibLoaderBase.java b/src/nativewindow/classes/com/sun/nwi/impl/NativeLibLoaderBase.java new file mode 100644 index 000000000..9e072fec0 --- /dev/null +++ b/src/nativewindow/classes/com/sun/nwi/impl/NativeLibLoaderBase.java @@ -0,0 +1,115 @@ +/* + * 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. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.sun.nwi.impl; + +// FIXME: refactor Java SE dependencies +//import java.awt.Toolkit; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.HashSet; + +public class NativeLibLoaderBase { + public interface LoaderAction { + /** + * Loads the library specified by libname. Optionally preloads the libraries specified by + * preload. The implementation should ignore, if the preload-libraries have already been + * loaded. + * @param libname the library to load + * @param preload the libraries to load before loading the main library if not null + * @param preloadIgnoreError true, if errors during loading the preload-libraries should be ignored + */ + void loadLibrary(String libname, String[] preload, + boolean preloadIgnoreError); + } + + private static class DefaultAction implements LoaderAction { + public void loadLibrary(String libname, String[] preload, + boolean preloadIgnoreError) { + if (null!=preload) { + for (int i=0; i<preload.length; i++) { + try { + System.loadLibrary(preload[i]); + } + catch (UnsatisfiedLinkError e) { + if (!preloadIgnoreError && e.getMessage().indexOf("already loaded") < 0) { + throw e; + } + } + } + } + System.loadLibrary(libname); + } + } + + private static final HashSet loaded = new HashSet(); + private static LoaderAction loaderAction = new DefaultAction(); + + public static void disableLoading() { + setLoadingAction(null); + } + + public static void enableLoading() { + setLoadingAction(new DefaultAction()); + } + + public static synchronized void setLoadingAction(LoaderAction action) { + loaderAction = action; + } + + protected static synchronized void loadLibrary(String libname, String[] preload, + boolean preloadIgnoreError) { + if (loaderAction != null && !loaded.contains(libname)) + { + loaderAction.loadLibrary(libname, preload, preloadIgnoreError); + loaded.add(libname); + } + } + + public static void loadNWI(final String ossuffix) { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + loadLibrary("nwi_"+ossuffix, null, false); + return null; + } + }); + } +} diff --git a/src/nativewindow/classes/com/sun/nwi/impl/NativeWindowFactoryImpl.java b/src/nativewindow/classes/com/sun/nwi/impl/NativeWindowFactoryImpl.java new file mode 100644 index 000000000..ce164204c --- /dev/null +++ b/src/nativewindow/classes/com/sun/nwi/impl/NativeWindowFactoryImpl.java @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.sun.nwi.impl; + +import java.lang.reflect.*; +import java.security.*; + +import javax.media.nwi.*; + +public class NativeWindowFactoryImpl extends NativeWindowFactory { + protected static final boolean DEBUG = Debug.debug("NativeWindowFactoryImpl"); + + // This subclass of NativeWindowFactory handles the case of + // NativeWindows and AWT Components being passed in + protected NativeWindow getNativeWindowImpl(Object winObj) throws IllegalArgumentException { + if (null == winObj) { + throw new IllegalArgumentException("winObj is null"); + } + if (winObj instanceof NativeWindow) { + // Use the NativeWindow directly + return (NativeWindow) winObj; + } + + if (NWReflection.isAWTComponent(winObj)) { + return getAWTNativeWindow(winObj); + } + + throw new IllegalArgumentException("Target window object type " + + winObj.getClass().getName() + " is unsupported; expected " + + "javax.media.nwi.NativeWindow or java.awt.Component"); + } + + private Constructor nativeWindowConstructor = null; + + private NativeWindow getAWTNativeWindow(Object winObj) { + if (nativeWindowConstructor == null) { + try { + String osName = System.getProperty("os.name"); + String osNameLowerCase = osName.toLowerCase(); + String windowClassName = null; + + // We break compile-time dependencies on the AWT here to + // make it easier to run this code on mobile devices + + if (osNameLowerCase.startsWith("wind")) { + windowClassName = "com.sun.nwi.impl.jawt.windows.WindowsJAWTWindow"; + } else if (osNameLowerCase.startsWith("mac os x")) { + windowClassName = "com.sun.nwi.impl.jawt.macosx.MacOSXJAWTWindow"; + } else { + // Assume Linux, Solaris, etc. Should probably test for these explicitly. + windowClassName = "com.sun.nwi.impl.jawt.x11.X11JAWTWindow"; + } + + if (windowClassName == null) { + throw new IllegalArgumentException("OS " + osName + " not yet supported"); + } + + nativeWindowConstructor = NWReflection.getConstructor(windowClassName, new Class[] { Object.class }); + } catch (Exception e) { + throw (IllegalArgumentException) new IllegalArgumentException().initCause(e); + } + } + + try { + return (NativeWindow) nativeWindowConstructor.newInstance(new Object[] { winObj }); + } catch (Exception ie) { + throw (IllegalArgumentException) new IllegalArgumentException().initCause(ie); + } + } + + // All platforms except for X11 perform the OpenGL pixel format + // selection lazily + public AbstractGraphicsConfiguration chooseGraphicsConfiguration(NWCapabilities capabilities, + NWCapabilitiesChooser chooser, + AbstractGraphicsDevice device) { + return null; + } + + // On most platforms the toolkit lock is a no-op + private ToolkitLock toolkitLock = new ToolkitLock() { + public void lock() { + } + + public void unlock() { + } + }; + + public ToolkitLock getToolkitLock() { + return toolkitLock; + } +} diff --git a/src/nativewindow/classes/com/sun/nwi/impl/NullWindow.java b/src/nativewindow/classes/com/sun/nwi/impl/NullWindow.java new file mode 100644 index 000000000..727d3dd03 --- /dev/null +++ b/src/nativewindow/classes/com/sun/nwi/impl/NullWindow.java @@ -0,0 +1,128 @@ +/* + * 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.sun.nwi.impl; + +import javax.media.nwi.*; + +public class NullWindow implements NativeWindow { + protected boolean locked; + protected int width, height, scrnIndex; + protected long windowHandle, surfaceHandle, displayHandle; + + + public NullWindow() { + locked=false; + scrnIndex=-1; + } + + protected void init(Object windowObject) throws NativeWindowException { + } + + protected void initNative() throws NativeWindowException { + } + + public synchronized void invalidate() { + locked = false; + } + + public synchronized int lockSurface() throws NativeWindowException { + if (locked) { + throw new NativeWindowException("Surface already locked"); + } + locked = true; + return LOCK_SUCCESS; + } + + public synchronized void unlockSurface() { + if (locked) { + locked = false; + } + } + + public synchronized boolean isSurfaceLocked() { + return locked; + } + + public long getDisplayHandle() { + return windowHandle; + } + public void setDisplayHandle(long handle) { + windowHandle=handle; + } + public long getScreenHandle() { + return 0; + } + public int getScreenIndex() { + return scrnIndex; + } + public void setScreenIndex(int idx) { + scrnIndex=idx; + } + public long getWindowHandle() { + return windowHandle; + } + public long getSurfaceHandle() { + return surfaceHandle; + } + public void setSurfaceHandle(long handle) { + surfaceHandle=handle; + } + public long getVisualID() { + return 0; + } + + public Object getWrappedWindow() { + return null; + } + + 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; + } +} diff --git a/src/nativewindow/classes/com/sun/nwi/impl/jawt/JAWTNativeLibLoader.java b/src/nativewindow/classes/com/sun/nwi/impl/jawt/JAWTNativeLibLoader.java new file mode 100644 index 000000000..064a85b65 --- /dev/null +++ b/src/nativewindow/classes/com/sun/nwi/impl/jawt/JAWTNativeLibLoader.java @@ -0,0 +1,71 @@ +/* + * 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. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.sun.nwi.impl.jawt; + +import com.sun.nwi.impl.*; + +import java.awt.Toolkit; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; + +public class JAWTNativeLibLoader extends NativeLibLoaderBase { + public static void loadAWTImpl() { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + // Make sure that awt.dll is loaded before loading jawt.dll. Otherwise + // a Dialog with "awt.dll not found" might pop up. + // See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4481947. + Toolkit.getDefaultToolkit(); + + // Must pre-load JAWT on all non-Mac platforms to + // ensure references from jogl_awt shared object + // will succeed since JAWT shared object isn't in + // default library path + boolean isOSX = System.getProperty("os.name").equals("Mac OS X"); + String[] preload = { "jawt" }; + + loadLibrary("nwi_awt", (isOSX)?null:preload, false); + return null; + } + }); + } +} diff --git a/src/nativewindow/classes/com/sun/nwi/impl/jawt/JAWTUtil.java b/src/nativewindow/classes/com/sun/nwi/impl/jawt/JAWTUtil.java new file mode 100644 index 000000000..887513523 --- /dev/null +++ b/src/nativewindow/classes/com/sun/nwi/impl/jawt/JAWTUtil.java @@ -0,0 +1,94 @@ +/* + * 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.sun.nwi.impl.jawt; + +import com.sun.nwi.impl.*; + +import javax.media.nwi.*; + +import java.awt.GraphicsEnvironment; + +public class JAWTUtil { + static { + NativeLibLoaderBase.loadNWI("awt"); + } + + // See whether we're running in headless mode + private static boolean headlessMode; + + static { + lockedToolkit = false; + headlessMode = GraphicsEnvironment.isHeadless(); + } + + private static boolean lockedToolkit; + + public static synchronized void lockToolkit() throws NWException { + if (lockedToolkit) { + throw new NWException("Toolkit already locked"); + } + lockedToolkit = true; + + if (headlessMode) { + // Workaround for running (to some degree) in headless + // environments but still supporting rendering via pbuffers + // For full correctness, would need to implement a Lock class + return; + } + + JAWT.getJAWT().Lock(); + } + + public static synchronized void unlockToolkit() { + if (lockedToolkit) { + if (headlessMode) { + // Workaround for running (to some degree) in headless + // environments but still supporting rendering via pbuffers + // For full correctness, would need to implement a Lock class + return; + } + + JAWT.getJAWT().Unlock(); + lockedToolkit = false; + } + } + + public static boolean isToolkitLocked() { + return lockedToolkit; + } +} + diff --git a/src/nativewindow/classes/com/sun/nwi/impl/jawt/JAWTWindow.java b/src/nativewindow/classes/com/sun/nwi/impl/jawt/JAWTWindow.java new file mode 100644 index 000000000..1311f3b4b --- /dev/null +++ b/src/nativewindow/classes/com/sun/nwi/impl/jawt/JAWTWindow.java @@ -0,0 +1,157 @@ +/* + * 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.sun.nwi.impl.jawt; + +import com.sun.nwi.impl.*; + +import java.awt.Component; +import java.awt.GraphicsEnvironment; +import javax.media.nwi.*; +import javax.media.nwi.*; +import com.sun.nwi.impl.*; + +public abstract class JAWTWindow implements NativeWindow { + protected static final boolean DEBUG = Debug.debug("GLDrawable"); + + // See whether we're running in headless mode + private static boolean headlessMode; + + static { + headlessMode = GraphicsEnvironment.isHeadless(); + } + + // lifetime: forever + protected Component component; + protected boolean locked; + + // lifetime: valid after lock, forever until invalidate + protected long display; + protected long screen; + protected long drawable; + protected long visualID; + protected int screenIndex; + + public JAWTWindow(Object comp) { + init((Component)comp); + } + + protected void init(Component windowObject) throws NativeWindowException { + invalidate(); + this.component = windowObject; + initNative(); + } + + protected abstract void initNative() throws NativeWindowException; + + public synchronized void invalidate() { + locked = false; + component = null; + display= 0; + screen= 0; + screenIndex = -1; + drawable= 0; + visualID = 0; + } + + public synchronized int lockSurface() throws NativeWindowException { + if (locked) { + throw new NativeWindowException("Surface already locked"); + } + locked = true; + return LOCK_SUCCESS; + } + + public synchronized void unlockSurface() { + if (locked) { + locked = false; + } + } + + public synchronized boolean isSurfaceLocked() { + return locked; + } + + public long getDisplayHandle() { + return display; + } + public long getScreenHandle() { + return screen; + } + public int getScreenIndex() { + return screenIndex; + } + public long getWindowHandle() { + return drawable; + } + public long getSurfaceHandle() { + return drawable; + } + public long getVisualID() { + return visualID; + } + + public Object getWrappedWindow() { + return component; + } + + public void setSize(int width, int height) { + component.setSize(width, height); + } + + public int getWidth() { + return component.getWidth(); + } + + public int getHeight() { + return component.getHeight(); + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + + sb.append("JAWT-Window[windowHandle "+getWindowHandle()+ + ", surfaceHandle "+getSurfaceHandle()+ + ", pos "+component.getX()+"/"+component.getY()+", size "+getWidth()+"x"+getHeight()+ + ", visible "+component.isVisible()+ + ", wrappedWindow "+getWrappedWindow()+ + ", visualID "+visualID+ + ", screen handle/index "+getScreenHandle()+"/"+getScreenIndex() + + ", display handle "+getDisplayHandle()+"]"); + + return sb.toString(); + } +} diff --git a/src/nativewindow/classes/com/sun/nwi/impl/jawt/JAWT_PlatformInfo.java b/src/nativewindow/classes/com/sun/nwi/impl/jawt/JAWT_PlatformInfo.java new file mode 100644 index 000000000..c71bdc918 --- /dev/null +++ b/src/nativewindow/classes/com/sun/nwi/impl/jawt/JAWT_PlatformInfo.java @@ -0,0 +1,47 @@ +/* + * 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. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.sun.nwi.impl.jawt; + +import com.sun.nwi.impl.*; + +/** Marker class for all window system-specific JAWT data structures. */ + +public interface JAWT_PlatformInfo { +} diff --git a/src/nativewindow/classes/com/sun/nwi/impl/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/com/sun/nwi/impl/jawt/macosx/MacOSXJAWTWindow.java new file mode 100644 index 000000000..4d911da36 --- /dev/null +++ b/src/nativewindow/classes/com/sun/nwi/impl/jawt/macosx/MacOSXJAWTWindow.java @@ -0,0 +1,151 @@ +/* + * 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. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.sun.nwi.impl.jawt.macosx; + +import com.sun.nwi.impl.jawt.*; +import com.sun.nwi.impl.*; + +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; + +import javax.media.nwi.*; +import javax.media.nwi.*; +import java.security.*; + +public class MacOSXJAWTWindow extends JAWTWindow { + + public MacOSXJAWTWindow(Object comp) { + super(comp); + } + + protected void initNative() throws NativeWindowException { + } + + public int lockSurface() throws NativeWindowException { + int ret = super.lockSurface(); + if(NativeWindow.LOCK_SUCCESS != ret) { + return ret; + } + ds = JAWT.getJAWT().GetDrawingSurface(component); + if (ds == null) { + // Widget not yet realized + return NativeWindow.LOCK_SURFACE_NOT_READY; + } + int res = ds.Lock(); + if ((res & JAWTFactory.JAWT_LOCK_ERROR) != 0) { + throw new NWException("Unable to lock surface"); + } + // See whether the surface changed and if so destroy the old + // OpenGL context so it will be recreated (NOTE: removeNotify + // should handle this case, but it may be possible that race + // conditions can cause this code to be triggered -- should test + // more) + if ((res & JAWTFactory.JAWT_LOCK_SURFACE_CHANGED) != 0) { + ret = NativeWindow.LOCK_SURFACE_CHANGED; + } + if (firstLock) { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + dsi = ds.GetDrawingSurfaceInfo(); + return null; + } + }); + } else { + dsi = ds.GetDrawingSurfaceInfo(); + } + if (dsi == null) { + // Widget not yet realized + ds.Unlock(); + JAWT.getJAWT().FreeDrawingSurface(ds); + ds = null; + 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; + return NativeWindow.LOCK_SURFACE_NOT_READY; + } + drawable = macosxdsi.cocoaViewRef(); + // FIXME: Are the followup abstractions available ? would it be usefull ? + display = 0; + visualID = 0; + screen= 0; + screenIndex = 0; + + if (drawable == 0) { + // Widget not yet realized + ds.FreeDrawingSurfaceInfo(dsi); + ds.Unlock(); + JAWT.getJAWT().FreeDrawingSurface(ds); + ds = null; + dsi = null; + macosxdsi = null; + return NativeWindow.LOCK_SURFACE_NOT_READY; + } + return ret; + } + + public void unlockSurface() throws NWException { + if(!isSurfaceLocked()) return; + 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 JAWT_DrawingSurfaceInfo dsi; + private JAWT_MacOSXDrawingSurfaceInfo macosxdsi; + + // Workaround for instance of 4796548 + private boolean firstLock = true; + +} + diff --git a/src/nativewindow/classes/com/sun/nwi/impl/jawt/windows/WindowsJAWTWindow.java b/src/nativewindow/classes/com/sun/nwi/impl/jawt/windows/WindowsJAWTWindow.java new file mode 100644 index 000000000..cf5c0f328 --- /dev/null +++ b/src/nativewindow/classes/com/sun/nwi/impl/jawt/windows/WindowsJAWTWindow.java @@ -0,0 +1,161 @@ +/* + * 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. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.sun.nwi.impl.jawt.windows; + +import com.sun.nwi.impl.jawt.*; + +import javax.media.nwi.*; +import com.sun.nwi.impl.*; + +public class WindowsJAWTWindow extends JAWTWindow { + + public static final boolean PROFILING = false; // FIXME + public static final int PROFILING_TICKS = 600; // FIXME + + public WindowsJAWTWindow(Object comp) { + super(comp); + } + + protected void initNative() throws NativeWindowException { + } + + public int lockSurface() throws NativeWindowException { + int ret = super.lockSurface(); + if(LOCK_SUCCESS != ret) { + return ret; + } + + long startTime; + if (PROFILING) { + startTime = System.currentTimeMillis(); + } + ds = JAWT.getJAWT().GetDrawingSurface(component); + if (ds == null) { + // Widget not yet realized + return LOCK_SURFACE_NOT_READY; + } + int res = ds.Lock(); + if ((res & JAWTFactory.JAWT_LOCK_ERROR) != 0) { + throw new NWException("Unable to lock surface"); + } + // See whether the surface changed and if so destroy the old + // OpenGL context so it will be recreated (NOTE: removeNotify + // should handle this case, but it may be possible that race + // conditions can cause this code to be triggered -- should test + // more) + if ((res & JAWTFactory.JAWT_LOCK_SURFACE_CHANGED) != 0) { + ret = LOCK_SURFACE_CHANGED; + } + dsi = ds.GetDrawingSurfaceInfo(); + if (dsi == null) { + // Widget not yet realized + ds.Unlock(); + JAWT.getJAWT().FreeDrawingSurface(ds); + ds = null; + return LOCK_SURFACE_NOT_READY; + } + win32dsi = (JAWT_Win32DrawingSurfaceInfo) dsi.platformInfo(); + drawable = win32dsi.hdc(); + // FIXME: Are the followup abstractions available ? would it be usefull ? + display = 0; + visualID = 0; + screen= 0; + screenIndex = 0; + + if (drawable == 0) { + // Widget not yet realized + ds.FreeDrawingSurfaceInfo(dsi); + ds.Unlock(); + JAWT.getJAWT().FreeDrawingSurface(ds); + ds = null; + dsi = null; + win32dsi = null; + return LOCK_SURFACE_NOT_READY; + } + if (PROFILING) { + long endTime = System.currentTimeMillis(); + profilingLockSurfaceTime += (endTime - startTime); + if (++profilingLockSurfaceTicks == PROFILING_TICKS) { + System.err.println("LockSurface calls: " + profilingLockSurfaceTime + " ms / " + PROFILING_TICKS + " calls (" + + ((float) profilingLockSurfaceTime / (float) PROFILING_TICKS) + " ms/call)"); + profilingLockSurfaceTime = 0; + profilingLockSurfaceTicks = 0; + } + } + return ret; + } + + public void unlockSurface() { + if(!isSurfaceLocked()) return; + long startTime = 0; + if (PROFILING) { + startTime = System.currentTimeMillis(); + } + ds.FreeDrawingSurfaceInfo(dsi); + ds.Unlock(); + JAWT.getJAWT().FreeDrawingSurface(ds); + ds = null; + dsi = null; + win32dsi = null; + drawable = 0; + super.unlockSurface(); + if (PROFILING) { + long endTime = System.currentTimeMillis(); + profilingUnlockSurfaceTime += (endTime - startTime); + if (++profilingUnlockSurfaceTicks == PROFILING_TICKS) { + System.err.println("UnlockSurface calls: " + profilingUnlockSurfaceTime + " ms / " + PROFILING_TICKS + " calls (" + + ((float) profilingUnlockSurfaceTime / (float) PROFILING_TICKS) + " ms/call)"); + profilingUnlockSurfaceTime = 0; + profilingUnlockSurfaceTicks = 0; + } + } + } + + // Variables for lockSurface/unlockSurface + private JAWT_DrawingSurface ds; + private JAWT_DrawingSurfaceInfo dsi; + private JAWT_Win32DrawingSurfaceInfo win32dsi; + private long profilingLockSurfaceTime = 0; + private int profilingLockSurfaceTicks = 0; + private long profilingUnlockSurfaceTime = 0; + private int profilingUnlockSurfaceTicks = 0; + +} + diff --git a/src/nativewindow/classes/com/sun/nwi/impl/jawt/x11/X11JAWTWindow.java b/src/nativewindow/classes/com/sun/nwi/impl/jawt/x11/X11JAWTWindow.java new file mode 100644 index 000000000..16fcb6b57 --- /dev/null +++ b/src/nativewindow/classes/com/sun/nwi/impl/jawt/x11/X11JAWTWindow.java @@ -0,0 +1,133 @@ +/* + * 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.sun.nwi.impl.jawt.x11; + +import com.sun.nwi.impl.x11.*; +import com.sun.nwi.impl.jawt.*; +import com.sun.nwi.impl.*; + +import javax.media.nwi.*; +import javax.media.nwi.*; + +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; + +public class X11JAWTWindow extends JAWTWindow { + + public X11JAWTWindow(Object comp) { + super(comp); + } + + protected void initNative() throws NativeWindowException { + } + + public synchronized int lockSurface() throws NativeWindowException { + int ret = super.lockSurface(); + if(LOCK_SUCCESS != ret) { + return ret; + } + ds = JAWT.getJAWT().GetDrawingSurface(component); + if (ds == null) { + // Widget not yet realized + return LOCK_SURFACE_NOT_READY; + } + int res = ds.Lock(); + if ((res & JAWTFactory.JAWT_LOCK_ERROR) != 0) { + throw new NativeWindowException("Unable to lock surface"); + } + // See whether the surface changed and if so destroy the old + // OpenGL context so it will be recreated (NOTE: removeNotify + // should handle this case, but it may be possible that race + // conditions can cause this code to be triggered -- should test + // more) + if ((res & JAWTFactory.JAWT_LOCK_SURFACE_CHANGED) != 0) { + ret = LOCK_SURFACE_CHANGED; + } + dsi = ds.GetDrawingSurfaceInfo(); + if (dsi == null) { + // Widget not yet realized + ds.Unlock(); + JAWT.getJAWT().FreeDrawingSurface(ds); + ds = null; + return LOCK_SURFACE_NOT_READY; + } + x11dsi = (JAWT_X11DrawingSurfaceInfo) dsi.platformInfo(); + display = x11dsi.display(); + drawable = x11dsi.drawable(); + visualID = x11dsi.visualID(); + screen= 0; + if (X11Lib.XineramaEnabled(display)) { + screenIndex = 0; + } else { + GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); + screenIndex = X11SunJDKReflection.graphicsDeviceGetScreen(device); + } + if (display == 0 || drawable == 0) { + // Widget not yet realized + ds.FreeDrawingSurfaceInfo(dsi); + ds.Unlock(); + JAWT.getJAWT().FreeDrawingSurface(ds); + ds = null; + dsi = null; + x11dsi = null; + display = 0; + drawable = 0; + visualID = 0; + screen= 0; + screenIndex = -1; + return LOCK_SURFACE_NOT_READY; + } + return ret; + } + + public synchronized void unlockSurface() { + if(!isSurfaceLocked()) return; + 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 JAWT_DrawingSurfaceInfo dsi; + private JAWT_X11DrawingSurfaceInfo x11dsi; + +} diff --git a/src/nativewindow/classes/com/sun/nwi/impl/jawt/x11/X11SunJDKReflection.java b/src/nativewindow/classes/com/sun/nwi/impl/jawt/x11/X11SunJDKReflection.java new file mode 100644 index 000000000..d7d8daee4 --- /dev/null +++ b/src/nativewindow/classes/com/sun/nwi/impl/jawt/x11/X11SunJDKReflection.java @@ -0,0 +1,103 @@ +/* + * 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. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.sun.nwi.impl.jawt.x11; + +import com.sun.nwi.impl.x11.*; + +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.lang.reflect.*; +import java.security.*; + +/** This class encapsulates the reflection routines necessary to peek + inside a few data structures in the AWT implementation on X11 for + the purposes of correctly enumerating the available visuals. */ + +public class X11SunJDKReflection { + private static Class x11GraphicsDeviceClass; + private static Method x11GraphicsDeviceGetScreenMethod; + private static Class x11GraphicsConfigClass; + private static Method x11GraphicsConfigGetVisualMethod; + private static boolean initted; + + static { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + try { + x11GraphicsDeviceClass = Class.forName("sun.awt.X11GraphicsDevice"); + x11GraphicsDeviceGetScreenMethod = x11GraphicsDeviceClass.getDeclaredMethod("getScreen", new Class[] {}); + x11GraphicsDeviceGetScreenMethod.setAccessible(true); + + x11GraphicsConfigClass = Class.forName("sun.awt.X11GraphicsConfig"); + x11GraphicsConfigGetVisualMethod = x11GraphicsConfigClass.getDeclaredMethod("getVisual", new Class[] {}); + x11GraphicsConfigGetVisualMethod.setAccessible(true); + initted = true; + } catch (Exception e) { + // Either not a Sun JDK or the interfaces have changed since 1.4.2 / 1.5 + } + return null; + } + }); + } + + public static int graphicsDeviceGetScreen(GraphicsDevice device) { + if (!initted) { + return 0; + } + + try { + return ((Integer) x11GraphicsDeviceGetScreenMethod.invoke(device, new Object[] {})).intValue(); + } catch (Exception e) { + return 0; + } + } + + public static int graphicsConfigurationGetVisualID(GraphicsConfiguration config) { + if (!initted) { + return 0; + } + + try { + return ((Integer) x11GraphicsConfigGetVisualMethod.invoke(config, new Object[] {})).intValue(); + } catch (Exception e) { + return 0; + } + } +} diff --git a/src/nativewindow/classes/com/sun/nwi/impl/x11/X11Util.java b/src/nativewindow/classes/com/sun/nwi/impl/x11/X11Util.java new file mode 100644 index 000000000..b38dd5959 --- /dev/null +++ b/src/nativewindow/classes/com/sun/nwi/impl/x11/X11Util.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.sun.nwi.impl.x11; + +import javax.media.nwi.*; + +import com.sun.nwi.impl.*; + +public class X11Util { + static { + NativeLibLoaderBase.loadNWI("x11"); + } + + private static final boolean DEBUG = Debug.debug("X11Util"); + + private X11Util() {} + + // Display connection for use by visual selection algorithm and by all offscreen surfaces + private static long staticDisplay=0; + private static boolean xineramaEnabled=false; + public static long getDisplayConnection() { + if (staticDisplay == 0) { + NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); + try { + staticDisplay = X11Lib.XOpenDisplay(null); + if (staticDisplay != 0) { + xineramaEnabled = X11Lib.XineramaEnabled(staticDisplay); + } + } finally { + NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock(); + } + if (staticDisplay == 0) { + throw new NWException("Unable to open default display"); + } + } + return staticDisplay; + } + + public static boolean isXineramaEnabled() { + if (staticDisplay == 0) { + getDisplayConnection(); // will set xineramaEnabled + } + return xineramaEnabled; + } +} diff --git a/src/nativewindow/classes/com/sun/nwi/impl/x11/awt/X11AWTNativeWindowFactory.java b/src/nativewindow/classes/com/sun/nwi/impl/x11/awt/X11AWTNativeWindowFactory.java new file mode 100644 index 000000000..87feb5f50 --- /dev/null +++ b/src/nativewindow/classes/com/sun/nwi/impl/x11/awt/X11AWTNativeWindowFactory.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.sun.nwi.impl.x11.awt; + +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import javax.media.nwi.*; + +import com.sun.nwi.impl.*; +import com.sun.nwi.impl.jawt.*; +import com.sun.nwi.impl.jawt.x11.*; +import com.sun.nwi.impl.x11.*; + +public class X11AWTNativeWindowFactory extends NativeWindowFactoryImpl { + + // When running the AWT on X11 platforms, we use the AWT native + // interface (JAWT) to lock and unlock the toolkit + private ToolkitLock toolkitLock = new ToolkitLock() { + private Thread owner; + private int recursionCount; + + public synchronized void lock() { + Thread cur = Thread.currentThread(); + if (owner == cur) { + ++recursionCount; + return; + } + while (owner != null) { + try { + wait(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + owner = cur; + JAWTUtil.lockToolkit(); + } + + public synchronized void unlock() { + if (owner != Thread.currentThread()) { + throw new RuntimeException("Not owner"); + } + if (recursionCount > 0) { + --recursionCount; + return; + } + owner = null; + JAWTUtil.unlockToolkit(); + } + }; + + public ToolkitLock getToolkitLock() { + return toolkitLock; + } +} |