diff options
Diffstat (limited to 'src/nativewindow/classes/javax')
35 files changed, 3637 insertions, 0 deletions
diff --git a/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsConfiguration.java new file mode 100644 index 000000000..e53f75251 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsConfiguration.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 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 javax.media.nativewindow; + +/** A marker interface describing a graphics configuration, visual, or + pixel format in a toolkit-independent manner. */ + +public interface AbstractGraphicsConfiguration extends Cloneable { + /** + * Return the screen this graphics configuration is valid for + */ + public AbstractGraphicsScreen getScreen(); + + /** + * Return the capabilities reflecting this graphics configuration, + * which may differ from the capabilites used to choose this configuration. + * + * @return A copy of the Capabilities to avoid mutation by the user. + */ + public Capabilities getChosenCapabilities(); + + /** + * Return the capabilities used to choose this graphics configuration. + * + * These may be used to reconfigure the NativeWindow in case + * the device changes in a multi screen environment. + * + * @return A copy of the Capabilities to avoid mutation by the user. + */ + public Capabilities getRequestedCapabilities(); + + /** + * In case this instance already reflects a native configuration, + * return this one. + * Otherwise return the encapsuled native configuration, + * as it shall be included e.g. in the AWT case. + */ + public AbstractGraphicsConfiguration getNativeGraphicsConfiguration(); +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsDevice.java new file mode 100644 index 000000000..581df5163 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsDevice.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2005 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. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.nativewindow; + +/** A interface describing a graphics device in a + toolkit-independent manner. + */ + +public interface AbstractGraphicsDevice extends Cloneable { + /** + * Returns the type of the underlying subsystem, ie + * NativeWindowFactory.TYPE_KD, NativeWindowFactory.TYPE_X11, .. + */ + public String getType(); + + /** + * Returns the native handle of the underlying native device, + * if such thing exist. + */ + public long getHandle(); + + /** + * Optionally locking the device, utilizing eg {@link javax.media.nativewindow.ToolkitLock}. + * The lock implementation must be recursive. + */ + public void lock(); + + /** + * Optionally unlocking the device, utilizing eg {@link javax.media.nativewindow.ToolkitLock}. + * The lock implementation must be recursive. + */ + public void unlock(); + + /** + * Optionally closing the device.<br> + * The default implementation is a NOP operation, returning false.<br> + * The specific implementing, ie {@link javax.media.nativewindow.x11.X11GraphicsDevice}, + * shall have a enable/disable like {@link javax.media.nativewindow.x11.X11GraphicsDevice#setCloseDisplay(boolean, boolean)},<br> + * which shall be invoked at creation time to determine ownership/role of freeing the resource.<br> + * + * @return true if a specialized closing operation was successfully issued, otherwise false, + * ie no native closing operation was issued, which doesn't imply an error at all. + */ + public boolean close(); +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsScreen.java new file mode 100644 index 000000000..eb2cc9120 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/AbstractGraphicsScreen.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 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 javax.media.nativewindow; + +/** A interface describing a graphics screen in a + toolkit-independent manner. + */ + +public interface AbstractGraphicsScreen extends Cloneable { + /** + * Return the device this graphics configuration is valid for + */ + public AbstractGraphicsDevice getDevice(); + + /** Returns the screen index this graphics screen is valid for + */ + public int getIndex(); +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java b/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java new file mode 100644 index 000000000..6c875ab40 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java @@ -0,0 +1,279 @@ +/* + * 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 javax.media.nativewindow; + +/** Specifies a set of capabilities that a window's rendering context + must support, such as color depth per channel. It currently + contains the minimal number of routines which allow configuration + on all supported window systems. */ + +public class Capabilities implements Cloneable { + private int redBits = 8; + private int greenBits = 8; + private int blueBits = 8; + private int alphaBits = 0; + + // Support for transparent windows containing OpenGL content + private boolean backgroundOpaque = true; + private int transparentValueRed = -1; + private int transparentValueGreen = -1; + private int transparentValueBlue = -1; + private int transparentValueAlpha = -1; + + // Switch for on- or offscreen + private boolean onscreen = true; + + /** Creates a Capabilities object. All attributes are in a default + state. + */ + public Capabilities() {} + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException e) { + throw new NativeWindowException(e); + } + } + + public boolean equals(Object obj) { + if(this == obj) { return true; } + if(!(obj instanceof Capabilities)) { + return false; + } + Capabilities other = (Capabilities)obj; + boolean res = other.getRedBits()==redBits && + other.getGreenBits()==greenBits && + other.getBlueBits()==blueBits && + other.getAlphaBits()==alphaBits && + other.isBackgroundOpaque()==backgroundOpaque && + other.isOnscreen()==onscreen; + if(!backgroundOpaque) { + res = res && other.getTransparentRedValue()==transparentValueRed && + other.getTransparentGreenValue()==transparentValueGreen && + other.getTransparentBlueValue()==transparentValueBlue && + other.getTransparentAlphaValue()==transparentValueAlpha; + } + + return res; + } + + /** Returns the number of bits requested for the color buffer's red + component. On some systems only the color depth, which is the + sum of the red, green, and blue bits, is considered. */ + public int getRedBits() { + return redBits; + } + + /** Sets the number of bits requested for the color buffer's red + component. On some systems only the color depth, which is the + sum of the red, green, and blue bits, is considered. */ + public void setRedBits(int redBits) { + this.redBits = redBits; + } + + /** Returns the number of bits requested for the color buffer's + green component. On some systems only the color depth, which is + the sum of the red, green, and blue bits, is considered. */ + public int getGreenBits() { + return greenBits; + } + + /** Sets the number of bits requested for the color buffer's green + component. On some systems only the color depth, which is the + sum of the red, green, and blue bits, is considered. */ + public void setGreenBits(int greenBits) { + this.greenBits = greenBits; + } + + /** Returns the number of bits requested for the color buffer's blue + component. On some systems only the color depth, which is the + sum of the red, green, and blue bits, is considered. */ + public int getBlueBits() { + return blueBits; + } + + /** Sets the number of bits requested for the color buffer's blue + component. On some systems only the color depth, which is the + sum of the red, green, and blue bits, is considered. */ + public void setBlueBits(int blueBits) { + this.blueBits = blueBits; + } + + /** Returns the number of bits requested for the color buffer's + alpha component. On some systems only the color depth, which is + the sum of the red, green, and blue bits, is considered. */ + public int getAlphaBits() { + return alphaBits; + } + + /** Sets the number of bits requested for the color buffer's alpha + component. On some systems only the color depth, which is the + sum of the red, green, and blue bits, is considered. */ + public void setAlphaBits(int alphaBits) { + this.alphaBits = alphaBits; + } + + /** For on-screen OpenGL contexts on some platforms, sets whether + the background of the context should be considered opaque. On + supported platforms, setting this to false, in conjunction with + the transparency values, may allow + hardware-accelerated OpenGL content inside of windows of + arbitrary shape. To achieve this effect it is necessary to use + an OpenGL clear color with an alpha less than 1.0. The default + value for this flag is <code>true</code>; setting it to false + may incur a certain performance penalty, so it is not + recommended to arbitrarily set it to false.<br> + If not set already, the transparency values for red, green, blue and alpha + are set to their default value, which is half of the value range + of the framebuffer's corresponding component, + ie <code> redValue = ( 1 << ( redBits - 1 ) ) -1 </code>. + */ + public void setBackgroundOpaque(boolean opaque) { + backgroundOpaque = opaque; + if(!opaque) { + if(transparentValueRed<0) + transparentValueRed = ( 1 << ( getRedBits() - 1 ) ) - 1 ; + if(transparentValueGreen<0) + transparentValueGreen = ( 1 << ( getGreenBits() - 1 ) ) - 1 ; + if(transparentValueBlue<0) + transparentValueBlue = ( 1 << ( getBlueBits() - 1 ) ) - 1 ; + if(transparentValueAlpha<0) + transparentValueAlpha = ( 1 << ( getAlphaBits() - 1 ) ) - 1 ; + } + } + + /** Indicates whether the background of this OpenGL context should + be considered opaque. Defaults to true. + + @see #setBackgroundOpaque + */ + public boolean isBackgroundOpaque() { + return backgroundOpaque; + } + + /** Sets whether the drawable surface supports onscreen. + Defaults to true. + */ + public void setOnscreen(boolean onscreen) { + this.onscreen=onscreen; + } + + /** Indicates whether the drawable surface is onscreen. + Defaults to true. + */ + public boolean isOnscreen() { + return onscreen; + } + + /** Gets the transparent red value for the frame buffer configuration. + * This value is undefined if {@link #isBackgroundOpaque()} equals true. + * @see #setTransparentRedValue + */ + public int getTransparentRedValue() { return transparentValueRed; } + + /** Gets the transparent green value for the frame buffer configuration. + * This value is undefined if {@link #isBackgroundOpaque()} equals true. + * @see #setTransparentGreenValue + */ + public int getTransparentGreenValue() { return transparentValueGreen; } + + /** Gets the transparent blue value for the frame buffer configuration. + * This value is undefined if {@link #isBackgroundOpaque()} equals true. + * @see #setTransparentBlueValue + */ + public int getTransparentBlueValue() { return transparentValueBlue; } + + /** Gets the transparent alpha value for the frame buffer configuration. + * This value is undefined if {@link #isBackgroundOpaque()} equals true. + * @see #setTransparentAlphaValue + */ + public int getTransparentAlphaValue() { return transparentValueAlpha; } + + /** Sets the transparent red value for the frame buffer configuration, + ranging from 0 to the maximum frame buffer value for red. + This value is ignored if {@link #isBackgroundOpaque()} equals true.<br> + It defaults to half of the frambuffer value for red. <br> + A value of -1 is interpreted as any value. */ + public void setTransparentRedValue(int transValueRed) { transparentValueRed=transValueRed; } + + /** Sets the transparent green value for the frame buffer configuration, + ranging from 0 to the maximum frame buffer value for green. + This value is ignored if {@link #isBackgroundOpaque()} equals true.<br> + It defaults to half of the frambuffer value for green.<br> + A value of -1 is interpreted as any value. */ + public void setTransparentGreenValue(int transValueGreen) { transparentValueGreen=transValueGreen; } + + /** Sets the transparent blue value for the frame buffer configuration, + ranging from 0 to the maximum frame buffer value for blue. + This value is ignored if {@link #isBackgroundOpaque()} equals true.<br> + It defaults to half of the frambuffer value for blue.<br> + A value of -1 is interpreted as any value. */ + public void setTransparentBlueValue(int transValueBlue) { transparentValueBlue=transValueBlue; } + + /** Sets the transparent alpha value for the frame buffer configuration, + ranging from 0 to the maximum frame buffer value for alpha. + This value is ignored if {@link #isBackgroundOpaque()} equals true.<br> + It defaults to half of the frambuffer value for alpha.<br> + A value of -1 is interpreted as any value. */ + public void setTransparentAlphaValue(int transValueAlpha) { transparentValueAlpha=transValueAlpha; } + + + /** Returns a textual representation of this Capabilities + object. */ + public String toString() { + StringBuffer msg = new StringBuffer(); + msg.append("Capabilities["); + msg.append("Onscreen: "+ onscreen + + ", Red: " + redBits + + ", Green: " + greenBits + + ", Blue: " + blueBits + + ", Alpha: " + alphaBits + + ", Opaque: " + backgroundOpaque); + if(!backgroundOpaque) { + msg.append(", Transparent RGBA: [0x"+ Integer.toHexString(transparentValueRed)+ + " 0x"+ Integer.toHexString(transparentValueGreen)+ + " 0x"+ Integer.toHexString(transparentValueBlue)+ + " 0x"+ Integer.toHexString(transparentValueAlpha)+"] "); + } + msg.append("]"); + return msg.toString(); + } +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesChooser.java b/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesChooser.java new file mode 100644 index 000000000..d61ebd4ef --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesChooser.java @@ -0,0 +1,68 @@ +/* + * 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 javax.media.nativewindow; + +/** Provides a mechanism by which applications can customize the + window type selection for a given {@link Capabilities}. + Developers can implement this interface and pass an instance into + the method {@link GraphicsConfigurationFactory#chooseGraphicsConfiguration}; the chooser + will be called at window creation time. */ + +public interface CapabilitiesChooser { + /** Chooses the index (0..available.length - 1) of the {@link + Capabilities} most closely matching the desired one from the + list of all supported. Some of the entries in the + <code>available</code> array may be null; the chooser must + ignore these. The <em>windowSystemRecommendedChoice</em> + parameter may be provided to the chooser by the underlying + window system; if this index is valid, it is recommended, but + not necessarily required, that the chooser select that entry. + + <P> <em>Note:</em> this method is called automatically by the + {@link GraphicsConfigurationFactory#chooseGraphicsConfiguration} method + when an instance of this class is passed in to it. + It should generally not be + invoked by users directly, unless it is desired to delegate the + choice to some other CapabilitiesChooser object. + */ + public int chooseCapabilities(Capabilities desired, + Capabilities[] available, + int windowSystemRecommendedChoice); +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/DefaultCapabilitiesChooser.java b/src/nativewindow/classes/javax/media/nativewindow/DefaultCapabilitiesChooser.java new file mode 100644 index 000000000..cead0a4a8 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/DefaultCapabilitiesChooser.java @@ -0,0 +1,153 @@ +/* + * 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 javax.media.nativewindow; + +/** <P> The default implementation of the {@link + CapabilitiesChooser} interface, which provides consistent visual + selection behavior across platforms. The precise algorithm is + deliberately left loosely specified. Some properties are: </P> + + <LI> Attempts to match as closely as possible the given + Capabilities, but will select one with fewer capabilities (i.e., + lower color depth) if necessary. + + <LI> If there is no exact match, prefers a more-capable visual to + a less-capable one. + + <LI> If there is more than one exact match, chooses an arbitrary + one. + + <LI> If a valid windowSystemRecommendedChoice parameter is + supplied, chooses that instead of using the cross-platform code. + + </UL> +*/ + +public class DefaultCapabilitiesChooser implements CapabilitiesChooser { + private static final boolean DEBUG = false; // FIXME: Debug.debug("DefaultCapabilitiesChooser"); + + public int chooseCapabilities(Capabilities desired, + Capabilities[] available, + int windowSystemRecommendedChoice) { + if (DEBUG) { + System.err.println("Desired: " + desired); + for (int i = 0; i < available.length; i++) { + System.err.println("Available " + i + ": " + available[i]); + } + System.err.println("Window system's recommended choice: " + windowSystemRecommendedChoice); + } + + if (windowSystemRecommendedChoice >= 0 && + windowSystemRecommendedChoice < available.length && + available[windowSystemRecommendedChoice] != null) { + if (DEBUG) { + System.err.println("Choosing window system's recommended choice of " + windowSystemRecommendedChoice); + System.err.println(available[windowSystemRecommendedChoice]); + } + return windowSystemRecommendedChoice; + } + + // Create score array + int[] scores = new int[available.length]; + int NO_SCORE = -9999999; + int COLOR_MISMATCH_PENALTY_SCALE = 36; + for (int i = 0; i < scores.length; i++) { + scores[i] = NO_SCORE; + } + // Compute score for each + for (int i = 0; i < scores.length; i++) { + Capabilities cur = available[i]; + if (cur == null) { + continue; + } + int score = 0; + // Compute difference in color depth + score += (COLOR_MISMATCH_PENALTY_SCALE * + ((cur.getRedBits() + cur.getGreenBits() + cur.getBlueBits() + cur.getAlphaBits()) - + (desired.getRedBits() + desired.getGreenBits() + desired.getBlueBits() + desired.getAlphaBits()))); + scores[i] = score; + } + + if (DEBUG) { + System.err.print("Scores: ["); + for (int i = 0; i < available.length; i++) { + if (i > 0) { + System.err.print(","); + } + System.err.print(" " + scores[i]); + } + System.err.println(" ]"); + } + + // Ready to select. Choose score closest to 0. + int scoreClosestToZero = NO_SCORE; + int chosenIndex = -1; + for (int i = 0; i < scores.length; i++) { + int score = scores[i]; + if (score == NO_SCORE) { + continue; + } + // Don't substitute a positive score for a smaller negative score + if ((scoreClosestToZero == NO_SCORE) || + (Math.abs(score) < Math.abs(scoreClosestToZero) && + ((sign(scoreClosestToZero) < 0) || (sign(score) > 0)))) { + scoreClosestToZero = score; + chosenIndex = i; + } + } + if (chosenIndex < 0) { + throw new NativeWindowException("Unable to select one of the provided Capabilities"); + } + if (DEBUG) { + System.err.println("Chosen index: " + chosenIndex); + System.err.println("Chosen capabilities:"); + System.err.println(available[chosenIndex]); + } + + return chosenIndex; + } + + private static int sign(int score) { + if (score < 0) { + return -1; + } + return 1; + } +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java new file mode 100644 index 000000000..47f02c7cc --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java @@ -0,0 +1,103 @@ +/* + * 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 javax.media.nativewindow; + +public class DefaultGraphicsConfiguration implements Cloneable, AbstractGraphicsConfiguration { + private AbstractGraphicsScreen screen; + protected Capabilities capabilitiesChosen; + protected Capabilities capabilitiesRequested; + + public DefaultGraphicsConfiguration(AbstractGraphicsScreen screen, + Capabilities capsChosen, Capabilities capsRequested) { + this.screen = screen; + this.capabilitiesChosen = capsChosen; + this.capabilitiesRequested = capsRequested; + } + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException e) { + throw new NativeWindowException(e); + } + } + + public AbstractGraphicsScreen getScreen() { + return screen; + } + + public Capabilities getChosenCapabilities() { + return (null!=capabilitiesChosen)?(Capabilities)capabilitiesChosen.clone():null; + } + + public Capabilities getRequestedCapabilities() { + return (null!=capabilitiesRequested)?(Capabilities)capabilitiesRequested.clone():null; + } + + public AbstractGraphicsConfiguration getNativeGraphicsConfiguration() { + return this; + } + + /** + * Set the capabilities to a new value. + * + * The use case for setting the Capabilities at a later time is + * a change of the graphics device in a multi-screen environment.<br> + * + * A copy of the passed object is being used. + * + * @see javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration(Capabilities, CapabilitiesChooser, AbstractGraphicsScreen) + */ + protected void setChosenCapabilities(Capabilities capsChosen) { + capabilitiesChosen = (Capabilities) capsChosen.clone(); + } + + /** + * Set a new screen. + * + * the use case for setting a new screen at a later time is + * a change of the graphics device in a multi-screen environment.<br> + * + * A copy of the passed object is being used. + */ + protected void setScreen(DefaultGraphicsScreen screen) { + this.screen = (AbstractGraphicsScreen) screen.clone(); + } + + public String toString() { + return getClass().toString()+"[" + screen + + ",\n\tchosen " + capabilitiesChosen+ + ",\n\trequested " + capabilitiesRequested+ + "]"; + } +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java new file mode 100644 index 000000000..4e91eb2a7 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsDevice.java @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2008 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. + */ + +package javax.media.nativewindow; + +import com.jogamp.nativewindow.impl.NativeWindowFactoryImpl; + +public class DefaultGraphicsDevice implements Cloneable, AbstractGraphicsDevice { + private String type; + protected long handle; + protected ToolkitLock toolkitLock; + + /** + * Create an instance with the system default {@link ToolkitLock}, + * gathered via {@link NativeWindowFactory#createDefaultToolkitLock()}. + * @param type + */ + public DefaultGraphicsDevice(String type) { + this.type = type; + this.handle = 0; + setToolkitLock( NativeWindowFactory.getDefaultToolkitLock(type) ); + } + + /** + * Create an instance with the system default {@link ToolkitLock}. + * gathered via {@link NativeWindowFactory#createDefaultToolkitLock()}. + * @param type + * @param handle + */ + public DefaultGraphicsDevice(String type, long handle) { + this.type = type; + this.handle = handle; + setToolkitLock( NativeWindowFactory.createDefaultToolkitLock(type, handle) ); + } + + /** + * Create an instance with the given {@link ToolkitLock} instance. + * @param type + * @param handle + * @param locker + */ + public DefaultGraphicsDevice(String type, long handle, ToolkitLock locker) { + this.type = type; + this.handle = handle; + setToolkitLock( locker ); + } + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException e) { + throw new NativeWindowException(e); + } + } + + public String getType() { + return type; + } + + public long getHandle() { + return handle; + } + + /** + * No lock is performed on the graphics device per default, + * instead the aggregated recursive {@link ToolkitLock#lock()} is invoked. + * + * @see DefaultGraphicsDevice#DefaultGraphicsDevice(java.lang.String, long) + * @see DefaultGraphicsDevice#DefaultGraphicsDevice(java.lang.String, long, javax.media.nativewindow.ToolkitLock) + */ + public final void lock() { + toolkitLock.lock(); + } + + /** + * No lock is performed on the graphics device per default, + * instead the aggregated recursive {@link ToolkitLock#unlock()} is invoked. + * + * @see DefaultGraphicsDevice#DefaultGraphicsDevice(java.lang.String, long) + * @see DefaultGraphicsDevice#DefaultGraphicsDevice(java.lang.String, long, javax.media.nativewindow.ToolkitLock) + */ + public final void unlock() { + toolkitLock.unlock(); + } + + public boolean close() { + return false; + } + + public String toString() { + return getClass().toString()+"[type "+getType()+", handle 0x"+Long.toHexString(getHandle())+"]"; + } + + /** + * Set the internal ToolkitLock, which is used within the + * {@link #lock()} and {@link #unlock()} implementation. + * + * @param locker the ToolkitLock, if null, {@link com.jogamp.nativewindow.impl.NullToolkitLock} is being used + */ + protected void setToolkitLock(ToolkitLock locker) { + this.toolkitLock = ( null == locker ) ? NativeWindowFactoryImpl.getNullToolkitLock() : locker ; + } + + /** + * @return the used ToolkitLock + * + * @see DefaultGraphicsDevice#DefaultGraphicsDevice(java.lang.String, long) + * @see DefaultGraphicsDevice#DefaultGraphicsDevice(java.lang.String, long, javax.media.nativewindow.ToolkitLock) + */ + public final ToolkitLock getToolkitLock() { + return toolkitLock; + } +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsScreen.java new file mode 100644 index 000000000..0af32c9ec --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsScreen.java @@ -0,0 +1,71 @@ +/* + * 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 javax.media.nativewindow; + +public class DefaultGraphicsScreen implements Cloneable, AbstractGraphicsScreen { + AbstractGraphicsDevice device; + private int idx; + + public DefaultGraphicsScreen(AbstractGraphicsDevice device, int idx) { + this.device = device; + this.idx = idx; + } + + public static AbstractGraphicsScreen createScreenDevice(int screenIdx) { + return new DefaultGraphicsScreen(new DefaultGraphicsDevice(NativeWindowFactory.TYPE_DEFAULT), screenIdx); + } + + public static AbstractGraphicsScreen createDefault() { + return createScreenDevice(0); + } + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException e) { + throw new NativeWindowException(e); + } + } + + public AbstractGraphicsDevice getDevice() { + return device; + } + + public int getIndex() { + return idx; + } + + public String toString() { + return getClass().toString()+"["+device+", idx "+idx+"]"; + } +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java new file mode 100644 index 000000000..1d3a7445f --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java @@ -0,0 +1,224 @@ +/* + * Copyright (c) 2008-2009 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 javax.media.nativewindow; + +import java.lang.reflect.*; +import java.util.*; + +import com.jogamp.common.util.*; +import com.jogamp.nativewindow.impl.*; + +/** + * Provides the mechanism by which the graphics configuration for a + * window can be chosen before the window is created. The graphics + * configuration decides parameters related to hardware accelerated rendering such + * as the OpenGL pixel format. <br> + * On some window systems (EGL/OpenKODE and X11 in particular) it is necessary to + * choose the graphics configuration early at window creation time. <br> + * Note that the selection of the graphics configuration is an algorithm which does not have + * strong dependencies on the particular Java window toolkit in use + * (e.g., AWT) and therefore it is strongly desirable to factor this + * functionality out of the core {@link NativeWindowFactory} so that + * new window toolkits can replace just the {@link + * NativeWindowFactory} and reuse the graphics configuration selection + * algorithm provided by, for example, an OpenGL binding. + */ + +public abstract class GraphicsConfigurationFactory { + protected static final boolean DEBUG = Debug.debug("GraphicsConfiguration"); + + private static Map/*<Class, NativeWindowFactory>*/ registeredFactories = + Collections.synchronizedMap(new HashMap()); + private static Class abstractGraphicsDeviceClass; + + static { + initialize(); + } + + /** Creates a new NativeWindowFactory instance. End users do not + need to call this method. */ + protected GraphicsConfigurationFactory() { + } + + private static void initialize() { + abstractGraphicsDeviceClass = javax.media.nativewindow.AbstractGraphicsDevice.class; + + if (NativeWindowFactory.TYPE_X11.equals(NativeWindowFactory.getNativeWindowType(true))) { + try { + GraphicsConfigurationFactory factory = (GraphicsConfigurationFactory) + ReflectionUtil.createInstance("com.jogamp.nativewindow.impl.x11.X11GraphicsConfigurationFactory", null, + GraphicsConfigurationFactory.class.getClassLoader()); + registerFactory(javax.media.nativewindow.x11.X11GraphicsDevice.class, factory); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + // Register the default no-op factory for arbitrary + // AbstractGraphicsDevice implementations, including + // AWTGraphicsDevice instances -- the OpenGL binding will take + // care of handling AWTGraphicsDevices on X11 platforms (as + // well as X11GraphicsDevices in non-AWT situations) + registerFactory(abstractGraphicsDeviceClass, new GraphicsConfigurationFactoryImpl()); + } + + /** Returns the factory for use with the given type of + AbstractGraphicsDevice. */ + public static GraphicsConfigurationFactory getFactory(AbstractGraphicsDevice device) { + if (device == null) { + return getFactory(AbstractGraphicsDevice.class); + } + return getFactory(device.getClass()); + } + + /** + * Returns the graphics configuration factory for use with the + * given class, which must implement the {@link + * AbstractGraphicsDevice} interface. + * + * @throws IllegalArgumentException if the given class does not implement AbstractGraphicsDevice + */ + public static GraphicsConfigurationFactory getFactory(Class abstractGraphicsDeviceImplementor) + throws IllegalArgumentException, NativeWindowException + { + if (!(abstractGraphicsDeviceClass.isAssignableFrom(abstractGraphicsDeviceImplementor))) { + throw new IllegalArgumentException("Given class must implement AbstractGraphicsDevice"); + } + + GraphicsConfigurationFactory factory = null; + Class clazz = abstractGraphicsDeviceImplementor; + while (clazz != null) { + factory = + (GraphicsConfigurationFactory) registeredFactories.get(clazz); + if (factory != null) { + if(DEBUG) { + System.err.println("GraphicsConfigurationFactory.getFactory() "+abstractGraphicsDeviceImplementor+" -> "+factory); + } + return factory; + } + clazz = clazz.getSuperclass(); + } + // Return the default + factory = (GraphicsConfigurationFactory)registeredFactories.get(abstractGraphicsDeviceClass); + if(DEBUG) { + System.err.println("GraphicsConfigurationFactory.getFactory() DEFAULT "+abstractGraphicsDeviceClass+" -> "+factory); + } + return factory; + } + + /** Registers a GraphicsConfigurationFactory handling graphics + * device objects of the given class. This does not need to be + * called by end users, only implementors of new + * GraphicsConfigurationFactory subclasses. + * + * @throws IllegalArgumentException if the given class does not implement AbstractGraphicsDevice + */ + protected static void registerFactory(Class abstractGraphicsDeviceImplementor, GraphicsConfigurationFactory factory) + throws IllegalArgumentException + { + if (!(abstractGraphicsDeviceClass.isAssignableFrom(abstractGraphicsDeviceImplementor))) { + throw new IllegalArgumentException("Given class must implement AbstractGraphicsDevice"); + } + if(DEBUG) { + System.err.println("GraphicsConfigurationFactory.registerFactory() "+abstractGraphicsDeviceImplementor+" -> "+factory); + } + registeredFactories.put(abstractGraphicsDeviceImplementor, factory); + } + + /** + * <P> Selects a graphics configuration on the specified graphics + * device compatible with the supplied {@link Capabilities}. Some + * platforms (e.g.: X11, EGL, KD) require the graphics configuration + * to be specified when the native window is created. + * These architectures have seperated their device, screen, window and drawable + * context and hence are capable of quering the capabilities for each screen. + * A fully established window is not required.</P> + * + * <P>Other platforms (e.g. Windows, MacOSX) don't offer the mentioned seperation + * and hence need a fully established window and it's drawable. + * Here the validation of the capabilities is performed later. + * In this case, the AbstractGraphicsConfiguration implementation + * must allow an overwrite of the Capabilites, for example + * {@link DefaultGraphicsConfiguration#setChosenCapabilities DefaultGraphicsConfiguration.setChosenCapabilities(..)}. + * </P> + * + * <P> + * This method is mainly intended to be both used and implemented by the + * OpenGL binding.</P> + * + * <P> The concrete data type of the passed graphics device and + * returned graphics configuration must be specified in the + * documentation binding this particular API to the underlying + * window toolkit. The Reference Implementation accepts {@link + * javax.media.nativewindow.awt.AWTGraphicsDevice AWTGraphicsDevice} objects and returns {@link + * javax.media.nativewindow.awt.AWTGraphicsConfiguration AWTGraphicsConfiguration} objects. On + * X11 platforms where the AWT is not in use, it also accepts + * {@link javax.media.nativewindow.x11.X11GraphicsDevice + * X11GraphicsDevice} objects and returns {@link + * javax.media.nativewindow.x11.X11GraphicsConfiguration + * X11GraphicsConfiguration} objects.</P> + * + * @throws IllegalArgumentException if the data type of the passed + * AbstractGraphicsDevice is not supported by this + * NativeWindowFactory. + * @throws NativeWindowException if any window system-specific errors caused + * the selection of the graphics configuration to fail. + * + * @see javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration(Capabilities, CapabilitiesChooser, AbstractGraphicsScreen) + * @see javax.media.nativewindow.DefaultGraphicsConfiguration#setChosenCapabilities(Capabilities caps) + */ + public final AbstractGraphicsConfiguration + chooseGraphicsConfiguration(Capabilities capabilities, + CapabilitiesChooser chooser, + AbstractGraphicsScreen screen) + throws IllegalArgumentException, NativeWindowException { + if(null==screen) { + throw new NativeWindowException("Screen is null"); + } + AbstractGraphicsDevice device = screen.getDevice(); + if(null==device) { + throw new NativeWindowException("Screen's Device is null"); + } + device.lock(); + try { + return chooseGraphicsConfigurationImpl(capabilities, chooser, screen); + } finally { + device.unlock(); + } + } + + protected abstract AbstractGraphicsConfiguration + chooseGraphicsConfigurationImpl(Capabilities capabilities, + CapabilitiesChooser chooser, + AbstractGraphicsScreen screen) + throws IllegalArgumentException, NativeWindowException; +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeSurface.java b/src/nativewindow/classes/javax/media/nativewindow/NativeSurface.java new file mode 100644 index 000000000..a5b71fbf8 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeSurface.java @@ -0,0 +1,163 @@ +/** + * 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; + +/** Provides low-level information required for + hardware-accelerated rendering using a surface in a platform-independent manner.<P> + + A NativeSurface created for a particular on- or offscreen component is + expected to have the same lifetime as that component. As long as + the component is alive and realized/visible, NativeSurface must be able + provide information such as the surface handle while it is locked.<P> +*/ +public interface NativeSurface extends SurfaceUpdatedListener { + /** Unlocked state */ + public static final int LOCK_SURFACE_UNLOCKED = 0; + + /** Returned by {@link #lockSurface()} if the surface is not ready to be locked. */ + public static final int LOCK_SURFACE_NOT_READY = 1; + + /** Returned by {@link #lockSurface()} if the surface is locked, but has changed. */ + public static final int LOCK_SURFACE_CHANGED = 2; + + /** Returned by {@link #lockSurface()} if the surface is locked, and is unchanged. */ + public static final int LOCK_SUCCESS = 3; + + /** + * Lock the surface of this native window<P> + * + * The surface handle, see {@link #lockSurface()}, <br> + * shall be valid after a successfull call, + * ie return a value other than {@link #LOCK_SURFACE_NOT_READY}.<P> + * + * This call is blocking until the surface has been locked + * or a timeout is reached. The latter will throw a runtime exception. <P> + * + * This call allows recursion from the same thread.<P> + * + * The implementation may want to aquire the + * application level {@link com.jogamp.common.util.locks.RecursiveLock} + * first before proceeding with a native surface lock. <P> + * + * The implementation shall also invoke {@link AbstractGraphicsDevice#lock()} + * for the initial lock (recursive count zero).<P> + * + * @return {@link #LOCK_SUCCESS}, {@link #LOCK_SURFACE_CHANGED} or {@link #LOCK_SURFACE_NOT_READY}. + * + * @throws RuntimeException after timeout when waiting for the surface lock + * + * @see com.jogamp.common.util.locks.RecursiveLock + */ + public int lockSurface(); + + /** + * Unlock the surface of this native window + * + * Shall not modify the surface handle, see {@link #lockSurface()} <P> + * + * The implementation shall also invoke {@link AbstractGraphicsDevice#unlock()} + * for the final unlock (recursive count zero).<P> + * + * @throws RuntimeException if surface is not locked + * + * @see #lockSurface + * @see com.jogamp.common.util.locks.RecursiveLock + */ + public void unlockSurface() throws NativeWindowException ; + + /** + * Return if surface is locked by another thread, ie not the current one + */ + public boolean isSurfaceLockedByOtherThread(); + + /** + * Return if surface is locked + */ + public boolean isSurfaceLocked(); + + /** + * Return the locking owner's Thread, or null if not locked. + */ + public Thread getSurfaceLockOwner(); + + /** + * Provide a mechanism to utilize custom (pre-) swap surface + * code. This method is called before the render toolkit (e.g. JOGL) + * swaps the buffer/surface. The implementation may itself apply the swapping, + * in which case true shall be returned. + * + * @return true if this method completed swapping the surface, + * otherwise false, in which case eg the GLDrawable + * implementation has to swap the code. + */ + public boolean surfaceSwap(); + + /** + * Returns the handle to the surface for this NativeSurface. <P> + * + * The surface handle should be set/update by {@link #lockSurface()}, + * where {@link #unlockSurface()} is not allowed to modify it. + * After {@link #unlockSurface()} it is no more guaranteed + * that the surface handle is still valid. + * + * The surface handle shall reflect the platform one + * for all drawable surface operations, e.g. opengl, swap-buffer. <P> + * + * On X11 this returns an entity of type Window, + * since there is no differentiation of surface and window there. <BR> + * On Microsoft Windows this returns an entity of type HDC. + */ + public long getSurfaceHandle(); + + /** Returns the current width of this surface. */ + public int getWidth(); + + /** Returns the current height of this surface. */ + public int getHeight(); + + /** + * Returns the graphics configuration corresponding to this window. + * @see javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration(Capabilities, CapabilitiesChooser, AbstractGraphicsScreen) + */ + public AbstractGraphicsConfiguration getGraphicsConfiguration(); + + /** + * Convenience: Get display handle from + * AbstractGraphicsConfiguration . AbstractGraphicsScreen . AbstractGraphicsDevice + */ + public long getDisplayHandle(); + + /** + * Convenience: Get display handle from + * AbstractGraphicsConfiguration . AbstractGraphicsScreen + */ + public int getScreenIndex(); + +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java new file mode 100644 index 000000000..d65cc8c18 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java @@ -0,0 +1,93 @@ +/* + * 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. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package javax.media.nativewindow; + +import javax.media.nativewindow.util.Point; + +/** Extend the {@link NativeSurface} interface with windowing + information such as window handle and position.<P> + + A window toolkit such as the AWT may either implement this interface + directly with one of its components, or provide and register an + implementation of {@link NativeWindowFactory NativeWindowFactory} + which can create NativeWindow objects for its components. <P> +*/ +public interface NativeWindow extends NativeSurface { + + /** + * destroys the window and releases + * windowing related resources. + */ + public void destroy(); + + /** + * @return The parent NativeWindow, or null if this NativeWindow is top level. + */ + public NativeWindow getParent(); + + /** + * Returns the window handle for this NativeWindow. <P> + * + * The window handle shall reflect the platform one + * for all window related operations, e.g. open, close, resize. <P> + * + * On X11 this returns an entity of type Window. <BR> + * On Microsoft Windows this returns an entity of type HWND. + */ + public long getWindowHandle(); + + /** Returns the current x position of this window, relative to it's parent. */ + public int getX(); + + /** Returns the current y position of this window, relative to it's parent. */ + public int getY(); + + /** + * Returns the current absolute location of this window. + * @param point if not null, + * {@link javax.media.nativewindow.util.Point#translate(javax.media.nativewindow.util.Point)} + * the passed {@link javax.media.nativewindow.util.Point} by this location on the screen and return it. + * @return either the passed non null translated point by the screen location of this NativeWindow, + * or a new instance with the screen location of this NativeWindow. + */ + public Point getLocationOnScreen(Point point); + +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowException.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowException.java new file mode 100644 index 000000000..593c1e7d6 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowException.java @@ -0,0 +1,68 @@ +/* + * 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 javax.media.nativewindow; + +/** A generic exception for OpenGL errors used throughout the binding + as a substitute for {@link RuntimeException}. */ + +public class NativeWindowException extends RuntimeException { + /** Constructs a NativeWindowException object. */ + public NativeWindowException() { + super(); + } + + /** Constructs a NativeWindowException object with the specified detail + message. */ + public NativeWindowException(String message) { + super(message); + } + + /** Constructs a NativeWindowException object with the specified detail + message and root cause. */ + public NativeWindowException(String message, Throwable cause) { + super(message, cause); + } + + /** Constructs a NativeWindowException object with the specified root + cause. */ + public NativeWindowException(Throwable cause) { + super(cause); + } +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java new file mode 100644 index 000000000..49b398b6f --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java @@ -0,0 +1,417 @@ +/* + * Copyright (c) 2008-2009 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. + */ + +package javax.media.nativewindow; + +import java.security.*; +import java.util.*; + +import com.jogamp.common.util.*; +import com.jogamp.common.jvm.JVMUtil; +import com.jogamp.nativewindow.impl.*; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; + +/** Provides a pluggable mechanism for arbitrary window toolkits to + adapt their components to the {@link NativeWindow} interface, + which provides a platform-independent mechanism of accessing the + information required to perform operations like + hardware-accelerated rendering using the OpenGL API. */ + +public abstract class NativeWindowFactory { + protected static final boolean DEBUG = Debug.debug("NativeWindow"); + + /** OpenKODE/EGL type, as retrieved with {@link #getNativeWindowType(boolean)}*/ + public static final String TYPE_EGL = "EGL"; + + /** Microsoft Windows type, as retrieved with {@link #getNativeWindowType(boolean)} */ + public static final String TYPE_WINDOWS = "Windows"; + + /** X11 type, as retrieved with {@link #getNativeWindowType(boolean)} */ + public static final String TYPE_X11 = "X11"; + + /** Mac OS X type, as retrieved with {@link #getNativeWindowType(boolean)} */ + public static final String TYPE_MACOSX = "MacOSX"; + + /** Generic AWT type, as retrieved with {@link #getNativeWindowType(boolean)} */ + public static final String TYPE_AWT = "AWT"; + + /** Generic DEFAULT type, where platform implementation don't care, as retrieved with {@link #getNativeWindowType(boolean)} */ + public static final String TYPE_DEFAULT = "default"; + + private static NativeWindowFactory defaultFactory; + private static Map/*<Class, NativeWindowFactory>*/ registeredFactories; + private static Class nativeWindowClass; + private static String nativeWindowingTypePure; + private static String nativeOSNamePure; + private static String nativeWindowingTypeCustom; + private static String nativeOSNameCustom; + private static boolean isAWTAvailable; + public static final String AWTComponentClassName = "java.awt.Component" ; + public static final String JAWTUtilClassName = "com.jogamp.nativewindow.impl.jawt.JAWTUtil" ; + public static final String X11UtilClassName = "com.jogamp.nativewindow.impl.x11.X11Util"; + public static final String X11JAWTToolkitLockClassName = "com.jogamp.nativewindow.impl.jawt.x11.X11JAWTToolkitLock" ; + public static final String X11ToolkitLockClassName = "com.jogamp.nativewindow.impl.x11.X11ToolkitLock" ; + private static Class jawtUtilClass; + private static Method jawtUtilGetJAWTToolkitMethod; + private static Method jawtUtilInitMethod; + private static Class x11JAWTToolkitLockClass; + private static Constructor x11JAWTToolkitLockConstructor; + private static Class x11ToolkitLockClass; + private static Constructor x11ToolkitLockConstructor; + private static boolean isFirstUIActionOnProcess; + + /** Creates a new NativeWindowFactory instance. End users do not + need to call this method. */ + protected NativeWindowFactory() { + } + + private static String _getNativeWindowingType(String osNameLowerCase) { + if (osNameLowerCase.startsWith("kd")) { + return TYPE_EGL; + } else if (osNameLowerCase.startsWith("wind")) { + return TYPE_WINDOWS; + } else if (osNameLowerCase.startsWith("mac os x") || + osNameLowerCase.startsWith("darwin")) { + return TYPE_MACOSX; + } else if (osNameLowerCase.equals("awt")) { + return TYPE_AWT; + } else { + return TYPE_X11; + } + } + + static { + JVMUtil.initSingleton(); + } + + static boolean initialized = false; + + /** + * Static one time initialization of this factory.<br> + * This initialization method <b>must be called</b> once by the program or utilizing modules!<br> + * @param firstUIActionOnProcess Should be <code>true</code> if called before the first UI action of the running program, + * otherwise <code>false</code>. + */ + public static synchronized void initSingleton(final boolean firstUIActionOnProcess) { + if(!initialized) { + initialized = true; + + if(DEBUG) { + Throwable td = new Throwable("Info: NativeWindowFactory.initSingleton("+firstUIActionOnProcess+")"); + td.printStackTrace(); + } + + // Gather the windowing OS first + AccessControlContext acc = AccessController.getContext(); + nativeOSNamePure = Debug.getProperty("os.name", false, acc); + nativeWindowingTypePure = _getNativeWindowingType(nativeOSNamePure.toLowerCase()); + nativeOSNameCustom = Debug.getProperty("nativewindow.ws.name", true, acc); + if(null==nativeOSNameCustom||nativeOSNameCustom.length()==0) { + nativeOSNameCustom = nativeOSNamePure; + nativeWindowingTypeCustom = nativeWindowingTypePure; + } else { + nativeWindowingTypeCustom = nativeOSNameCustom; + } + + ClassLoader cl = NativeWindowFactory.class.getClassLoader(); + + if( TYPE_X11.equals(nativeWindowingTypePure) ) { + // explicit initialization of X11Util + ReflectionUtil.callStaticMethod(X11UtilClassName, "initSingleton", + new Class[] { boolean.class }, + new Object[] { new Boolean(firstUIActionOnProcess) }, cl ); + } + isFirstUIActionOnProcess = firstUIActionOnProcess; + + if( !Debug.getBooleanProperty("java.awt.headless", true, acc) && + ReflectionUtil.isClassAvailable(AWTComponentClassName, cl) && + ReflectionUtil.isClassAvailable("javax.media.nativewindow.awt.AWTGraphicsDevice", cl) ) { + + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + try { + jawtUtilClass = Class.forName(JAWTUtilClassName, false, NativeWindowFactory.class.getClassLoader()); + jawtUtilInitMethod = jawtUtilClass.getDeclaredMethod("initSingleton", null); + jawtUtilInitMethod.setAccessible(true); + jawtUtilGetJAWTToolkitMethod = jawtUtilClass.getDeclaredMethod("getJAWTToolkitLock", new Class[]{}); + jawtUtilGetJAWTToolkitMethod.setAccessible(true); + } catch (Exception e) { + // Either not a Sun JDK or the interfaces have changed since 1.4.2 / 1.5 + } + return null; + } + }); + if(null != jawtUtilClass && null != jawtUtilGetJAWTToolkitMethod && null != jawtUtilInitMethod) { + ReflectionUtil.callMethod(null, jawtUtilInitMethod, null); + + Object resO = ReflectionUtil.callStaticMethod(JAWTUtilClassName, "isHeadlessMode", null, null, cl ); + if(resO instanceof Boolean) { + // AWT is only available in case all above classes are available + // and AWT is not int headless mode + isAWTAvailable = ((Boolean)resO).equals(Boolean.FALSE); + } else { + isAWTAvailable = false; + } + } else { + isAWTAvailable = false; + } + } else { + isAWTAvailable = false; + } + + registeredFactories = Collections.synchronizedMap(new HashMap()); + + // register our default factory -> NativeWindow + NativeWindowFactory factory = new NativeWindowFactoryImpl(); + nativeWindowClass = javax.media.nativewindow.NativeWindow.class; + registerFactory(nativeWindowClass, factory); + defaultFactory = factory; + + if ( isAWTAvailable ) { + // register either our default factory or (if exist) the X11/AWT one -> AWT Component + registerFactory(ReflectionUtil.getClass(AWTComponentClassName, false, cl), factory); + } + + if( TYPE_X11 == nativeWindowingTypePure ) { + // passing through RuntimeException if not exists intended + x11ToolkitLockClass = ReflectionUtil.getClass(X11ToolkitLockClassName, false, cl); + x11ToolkitLockConstructor = ReflectionUtil.getConstructor(x11ToolkitLockClass, new Class[] { long.class } ); + if( isAWTAvailable() ) { + x11JAWTToolkitLockClass = ReflectionUtil.getClass(X11JAWTToolkitLockClassName, false, cl); + x11JAWTToolkitLockConstructor = ReflectionUtil.getConstructor(x11JAWTToolkitLockClass, new Class[] { long.class } ); + } + } + + if(DEBUG) { + System.err.println("NativeWindowFactory firstUIActionOnProcess "+firstUIActionOnProcess); + System.err.println("NativeWindowFactory isAWTAvailable "+isAWTAvailable+", defaultFactory "+factory); + } + } + } + + /** @return true if initialized with <b>{@link #initSingleton(boolean) initSingleton(firstUIActionOnProcess==true)}</b>, + otherwise false. */ + public static boolean isFirstUIActionOnProcess() { + return isFirstUIActionOnProcess; + } + + /** @return true if not headless, AWT Component and NativeWindow's AWT part available */ + public static boolean isAWTAvailable() { return isAWTAvailable; } + + /** + * @param useCustom if false return the native value, if true return a custom value if set, otherwise fallback to the native value. + * @return the native OS name + */ + public static String getNativeOSName(boolean useCustom) { + return useCustom?nativeOSNameCustom:nativeOSNamePure; + } + + /** + * @param useCustom if false return the native value, if true return a custom value if set, otherwise fallback to the native value. + * @return a define native window type, like {@link #TYPE_X11}, .. + */ + public static String getNativeWindowType(boolean useCustom) { + return useCustom?nativeWindowingTypeCustom:nativeWindowingTypePure; + } + + /** Sets the default NativeWindowFactory. */ + public static void setDefaultFactory(NativeWindowFactory factory) { + defaultFactory = factory; + } + + /** Gets the default NativeWindowFactory. */ + public static NativeWindowFactory getDefaultFactory() { + return defaultFactory; + } + + /** + * Provides the system default {@link ToolkitLock}, a singleton instance. + * <br> + * This is a {@link com.jogamp.nativewindow.impl.jawt.JAWTToolkitLock} + * in case of a <b>X11 system</b> <em>and</em> <b>AWT availability</b> and if + * this factory has been initialized with <b>{@link #initSingleton(boolean) initSingleton(firstUIActionOnProcess==true)}</b>, <br> + * otherwise {@link com.jogamp.nativewindow.impl.NullToolkitLock} is returned. + */ + public static ToolkitLock getDefaultToolkitLock() { + return getDefaultToolkitLock(getNativeWindowType(false)); + } + + /** + * Provides the default {@link ToolkitLock} for <code>type</code>, a singleton instance. + * <br> + * This is a {@link com.jogamp.nativewindow.impl.jawt.JAWTToolkitLock} + * in case of a <b>X11 type</b> or <b>AWT type / X11 system</b> <em>and</em> <b>AWT availability</b> and if + * this factory has been initialized with <b>{@link #initSingleton(boolean) initSingleton(firstUIActionOnProcess==true)}</b>, <br> + * otherwise {@link com.jogamp.nativewindow.impl.NullToolkitLock} is returned. + */ + public static ToolkitLock getDefaultToolkitLock(String type) { + if( isAWTAvailable() && !isFirstUIActionOnProcess() && + ( TYPE_X11 == type || TYPE_AWT == type && TYPE_X11 == getNativeWindowType(false) ) ) { + return getAWTToolkitLock(); + } + return NativeWindowFactoryImpl.getNullToolkitLock(); + } + + protected static ToolkitLock getAWTToolkitLock() { + Object resO = ReflectionUtil.callMethod(null, jawtUtilGetJAWTToolkitMethod, null); + + if(resO instanceof ToolkitLock) { + return (ToolkitLock) resO; + } else { + throw new RuntimeException("JAWTUtil.getJAWTToolkitLock() didn't return a ToolkitLock"); + } + } + + public static ToolkitLock getNullToolkitLock() { + return NativeWindowFactoryImpl.getNullToolkitLock(); + } + /** + * Creates the default {@link ToolkitLock} for <code>type</code> and <code>deviceHandle</code>. + * <br> + * This is a {@link com.jogamp.nativewindow.impl.jawt.x11.X11JAWTToolkitLock} + * in case of a <b>X11 type</b> <em>and</em> <b>AWT availability</b> and if + * this factory has been initialized with <b>{@link #initSingleton(boolean) initSingleton(firstUIActionOnProcess==true)}</b>, <br> + * or a {@link com.jogamp.nativewindow.impl.x11.X11ToolkitLock} + * in case of a <b>X11 type</b> <em>and</em> <b>no AWT availability</b> and if + * this factory has been initialized with <b>{@link #initSingleton(boolean) initSingleton(firstUIActionOnProcess==true)}</b>, <br> + * otherwise {@link com.jogamp.nativewindow.impl.NullToolkitLock} is returned. + */ + public static ToolkitLock createDefaultToolkitLock(String type, long deviceHandle) { + if( TYPE_X11 == type ) { + if( 0== deviceHandle ) { + throw new RuntimeException("JAWTUtil.createDefaultToolkitLock() called with NULL device but on X11"); + } + if( !isFirstUIActionOnProcess() ) { + if( isAWTAvailable() ) { + return createX11AWTToolkitLock(deviceHandle); + } else { + return createX11ToolkitLock(deviceHandle); + } + } + } + return NativeWindowFactoryImpl.getNullToolkitLock(); + } + + public static ToolkitLock createDefaultToolkitLockNoAWT(String type, long deviceHandle) { + if( TYPE_X11 == type ) { + if( 0== deviceHandle ) { + throw new RuntimeException("JAWTUtil.createDefaultToolkitLockNoAWT() called with NULL device but on X11"); + } + if( !isFirstUIActionOnProcess() ) { + return createX11ToolkitLock(deviceHandle); + } + } + return NativeWindowFactoryImpl.getNullToolkitLock(); + } + + protected static ToolkitLock createX11AWTToolkitLock(long deviceHandle) { + try { + return (ToolkitLock) x11JAWTToolkitLockConstructor.newInstance(new Object[]{new Long(deviceHandle)}); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + } + + protected static ToolkitLock createX11ToolkitLock(long deviceHandle) { + try { + return (ToolkitLock) x11ToolkitLockConstructor.newInstance(new Object[]{new Long(deviceHandle)}); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + } + + + /** Returns the appropriate NativeWindowFactory to handle window + objects of the given type. The windowClass might be {@link + NativeWindow NativeWindow}, in which case the client has + already assumed the responsibility of creating a compatible + NativeWindow implementation, or it might be that of a toolkit + class like {@link java.awt.Component Component}. */ + public static NativeWindowFactory getFactory(Class windowClass) throws IllegalArgumentException { + if (nativeWindowClass.isAssignableFrom(windowClass)) { + return (NativeWindowFactory) registeredFactories.get(nativeWindowClass); + } + Class clazz = windowClass; + while (clazz != null) { + NativeWindowFactory factory = (NativeWindowFactory) registeredFactories.get(clazz); + if (factory != null) { + return factory; + } + clazz = clazz.getSuperclass(); + } + throw new IllegalArgumentException("No registered NativeWindowFactory for class " + windowClass.getName()); + } + + /** Registers a NativeWindowFactory handling window objects of the + given class. This does not need to be called by end users, + only implementors of new NativeWindowFactory subclasses. */ + protected static void registerFactory(Class windowClass, NativeWindowFactory factory) { + if(DEBUG) { + System.err.println("NativeWindowFactory.registerFactory() "+windowClass+" -> "+factory); + } + registeredFactories.put(windowClass, factory); + } + + /** Converts the given window object and it's + {@link AbstractGraphicsConfiguration AbstractGraphicsConfiguration} into a + {@link NativeWindow NativeWindow} which can be operated upon by a custom + toolkit, e.g. {@link javax.media.opengl.GLDrawableFactory javax.media.opengl.GLDrawableFactory}.<br> + The object may be a component for a particular window toolkit, such as an AWT + Canvas. It may also be a NativeWindow object itself.<br> + You shall utilize {@link javax.media.nativewindow.GraphicsConfigurationFactory GraphicsConfigurationFactory} + to construct a proper {@link AbstractGraphicsConfiguration AbstractGraphicsConfiguration}.<br> + The particular implementation of the + NativeWindowFactory is responsible for handling objects from a + particular window toolkit. The built-in NativeWindowFactory + handles NativeWindow instances as well as AWT Components.<br> + + @throws IllegalArgumentException if the given window object + could not be handled by any of the registered + NativeWindowFactory instances + + @see javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration(Capabilities, CapabilitiesChooser, AbstractGraphicsScreen) + */ + public static NativeWindow getNativeWindow(Object winObj, AbstractGraphicsConfiguration config) throws IllegalArgumentException, NativeWindowException { + if (winObj == null) { + throw new IllegalArgumentException("Null window object"); + } + + return getFactory(winObj.getClass()).getNativeWindowImpl(winObj, config); + } + + /** Performs the conversion from a toolkit's window object to a + NativeWindow. Implementors of concrete NativeWindowFactory + subclasses should override this method. */ + protected abstract NativeWindow getNativeWindowImpl(Object winObj, AbstractGraphicsConfiguration config) throws IllegalArgumentException; +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/SurfaceChangeable.java b/src/nativewindow/classes/javax/media/nativewindow/SurfaceChangeable.java new file mode 100644 index 000000000..fc32b57b3 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/SurfaceChangeable.java @@ -0,0 +1,48 @@ +/* + * 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 javax.media.nativewindow; + +public interface SurfaceChangeable { + + public void setSurfaceHandle(long surfaceHandle); + public void setSize(int width, int height); + +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/SurfaceUpdatedListener.java b/src/nativewindow/classes/javax/media/nativewindow/SurfaceUpdatedListener.java new file mode 100644 index 000000000..88e805d14 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/SurfaceUpdatedListener.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2008 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. + * + */ + +package javax.media.nativewindow; + +public interface SurfaceUpdatedListener { + /** Notification of a surface update event. + * + * @param updater is the caller object who updated the surface, + * e.g. a JOGL GLDrawable. + * @param ns the updated NativeSurface + * @param when the time in ms, when the surface was updated + */ + public void surfaceUpdated(Object updater, NativeSurface ns, long when) ; +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/ToolkitLock.java b/src/nativewindow/classes/javax/media/nativewindow/ToolkitLock.java new file mode 100644 index 000000000..226998860 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/ToolkitLock.java @@ -0,0 +1,45 @@ +/** + * 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.nativewindow.impl.Debug; +import java.security.AccessController; + +/** + * Marker for a singleton global recursive blocking lock implementation, + * optionally locking a native windowing toolkit as well. + * <br> + * One use case is the AWT locking on X11, see {@link com.jogamp.nativewindow.impl.jawt.JAWTToolkitLock}. + */ +public interface ToolkitLock { + public static final boolean TRACE_LOCK = Debug.isPropertyDefined("nativewindow.debug.ToolkitLock.TraceLock", true, AccessController.getContext()); + + public void lock(); + public void unlock(); +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java new file mode 100644 index 000000000..f56248e67 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsConfiguration.java @@ -0,0 +1,168 @@ +/* + * Copyright (c) 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 javax.media.nativewindow.awt; + +import javax.media.nativewindow.*; +import java.awt.Component; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.awt.Transparency; +import java.awt.image.ColorModel; +import javax.media.nativewindow.AbstractGraphicsConfiguration; +import com.jogamp.nativewindow.impl.Debug; + +/** A wrapper for an AWT GraphicsConfiguration allowing it to be + handled in a toolkit-independent manner. */ + +public class AWTGraphicsConfiguration extends DefaultGraphicsConfiguration implements Cloneable { + private GraphicsConfiguration config; + AbstractGraphicsConfiguration encapsulated; + + public AWTGraphicsConfiguration(AWTGraphicsScreen screen, + Capabilities capsChosen, Capabilities capsRequested, + GraphicsConfiguration config, AbstractGraphicsConfiguration encapsulated) { + super(screen, capsChosen, capsRequested); + this.config = config; + this.encapsulated=encapsulated; + } + + public AWTGraphicsConfiguration(AWTGraphicsScreen screen, Capabilities capsChosen, Capabilities capsRequested, GraphicsConfiguration config) { + super(screen, capsChosen, capsRequested); + this.config = config; + this.encapsulated=null; + } + + /** + * @param capsChosen if null, <code>capsRequested</code> is copied and aligned + * with the graphics capabilties of the AWT Component to produce the chosen Capabilties. + * Otherwise the <code>capsChosen</code> is used. + */ + public static AWTGraphicsConfiguration create(Component awtComp, Capabilities capsChosen, Capabilities capsRequested) + { + AWTGraphicsScreen awtScreen = null; + AWTGraphicsDevice awtDevice = null; + GraphicsDevice awtGraphicsDevice = null; + GraphicsConfiguration awtGfxConfig = awtComp.getGraphicsConfiguration(); + if(null!=awtGfxConfig) { + awtGraphicsDevice = awtGfxConfig.getDevice(); + if(null!=awtGraphicsDevice) { + // Create Device/Screen + awtDevice = new AWTGraphicsDevice(awtGraphicsDevice); + awtScreen = new AWTGraphicsScreen(awtDevice); + } + } + if(null==awtScreen) { + // use defaults since no native peer is available yet + awtScreen = (AWTGraphicsScreen) AWTGraphicsScreen.createScreenDevice(-1); + awtDevice = (AWTGraphicsDevice) awtScreen.getDevice(); + awtGraphicsDevice = awtDevice.getGraphicsDevice(); + } + + if(null==capsChosen) { + capsChosen = (Capabilities) capsRequested.clone() ; + GraphicsConfiguration gc = awtGraphicsDevice.getDefaultConfiguration(); + setupCapabilitiesRGBABits(capsChosen, gc); + } + return new AWTGraphicsConfiguration(awtScreen, capsChosen, capsRequested, awtGfxConfig); + } + + public Object clone() { + return super.clone(); + } + + public GraphicsConfiguration getGraphicsConfiguration() { + return config; + } + + public AbstractGraphicsConfiguration getNativeGraphicsConfiguration() { + return (null!=encapsulated)?encapsulated:this; + } + + /** + * Sets up the Capabilities' RGBA size based on the given GraphicsConfiguration's ColorModel. + * + * @param capabilities the Capabilities object whose red, green, blue, and alpha bits will be set + * @param gc the GraphicsConfiguration from which to derive the RGBA bit depths + * @return the passed Capabilities + */ + public static Capabilities setupCapabilitiesRGBABits(Capabilities capabilities, GraphicsConfiguration gc) { + int cmTransparency = capabilities.isBackgroundOpaque()?Transparency.OPAQUE:Transparency.TRANSLUCENT; + ColorModel cm = gc.getColorModel(cmTransparency); + if(null==cm && !capabilities.isBackgroundOpaque()) { + capabilities.setBackgroundOpaque(true); + cmTransparency = Transparency.OPAQUE; + cm = gc.getColorModel(cmTransparency); + } + if(null==cm) { + throw new NativeWindowException("Could not determine AWT ColorModel"); + } + int cmBitsPerPixel = cm.getPixelSize(); + int bitsPerPixel = 0; + int[] bitesPerComponent = cm.getComponentSize(); + if(bitesPerComponent.length>=3) { + capabilities.setRedBits(bitesPerComponent[0]); + bitsPerPixel += bitesPerComponent[0]; + capabilities.setGreenBits(bitesPerComponent[1]); + bitsPerPixel += bitesPerComponent[1]; + capabilities.setBlueBits(bitesPerComponent[2]); + bitsPerPixel += bitesPerComponent[2]; + } + if(bitesPerComponent.length>=4) { + capabilities.setAlphaBits(bitesPerComponent[3]); + bitsPerPixel += bitesPerComponent[3]; + } else { + capabilities.setAlphaBits(0); + } + if(Debug.debugAll()) { + if(cmBitsPerPixel!=bitsPerPixel) { + System.err.println("AWT Colormodel bits per components/pixel mismatch: "+bitsPerPixel+" != "+cmBitsPerPixel); + } + } + return capabilities; + } + + public String toString() { + return getClass().toString()+"[" + getScreen() + + ",\n\tchosen " + capabilitiesChosen+ + ",\n\trequested " + capabilitiesRequested+ + ",\n\t" + config + + ",\n\tencapsulated "+encapsulated+"]"; + } +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java new file mode 100644 index 000000000..e91261211 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsDevice.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 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 javax.media.nativewindow.awt; + +import javax.media.nativewindow.*; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import javax.media.nativewindow.AbstractGraphicsDevice; + +/** A wrapper for an AWT GraphicsDevice allowing it to be + handled in a toolkit-independent manner. */ + +public class AWTGraphicsDevice extends DefaultGraphicsDevice implements Cloneable { + private GraphicsDevice device; + private String subType; + + protected AWTGraphicsDevice(GraphicsDevice device) { + super(NativeWindowFactory.TYPE_AWT); + this.device = device; + this.subType = null; + } + + public static AbstractGraphicsDevice createDevice(GraphicsDevice awtDevice) { + if(null==awtDevice) { + awtDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); + } + return new AWTGraphicsDevice(awtDevice); + } + + public Object clone() { + return super.clone(); + } + + public GraphicsDevice getGraphicsDevice() { + return device; + } + + /** + * In case the native handle was specified, e.g. using X11, + * we shall be able to mark it.<br> + * This will also set the subType, queried with {@link #getSubType()} + * and reset the ToolkitLock type with {@link NativeWindowFactory#createDefaultToolkitLock(java.lang.String, long)} + * and {@link #setToolkitLock(javax.media.nativewindow.ToolkitLock)}. + */ + public void setSubType(String subType, long handle) { + this.handle = handle; + this.subType = subType; + setToolkitLock( NativeWindowFactory.createDefaultToolkitLock(subType, handle) ); + } + + public String getSubType() { + return subType; + } + + public String toString() { + return getClass().toString()+"[type "+getType()+"[subType "+getSubType()+"], awtDevice "+device+", handle 0x"+Long.toHexString(getHandle())+"]"; + } +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java new file mode 100644 index 000000000..6cbf2ee71 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/awt/AWTGraphicsScreen.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 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 javax.media.nativewindow.awt; + +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import javax.media.nativewindow.*; +import javax.media.nativewindow.AbstractGraphicsDevice; +import com.jogamp.nativewindow.impl.*; + +/** A wrapper for an AWT GraphicsDevice (screen) allowing it to be + handled in a toolkit-independent manner. */ + +public class AWTGraphicsScreen extends DefaultGraphicsScreen implements Cloneable { + + public AWTGraphicsScreen(AWTGraphicsDevice device) { + super(device, findScreenIndex(device.getGraphicsDevice())); + } + + public static GraphicsDevice getScreenDevice(int index) { + if(index<0) return null; + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + GraphicsDevice[] gs = ge.getScreenDevices(); + if(index<gs.length) { + return gs[index]; + } + return null; + } + + public static int findScreenIndex(GraphicsDevice awtDevice) { + if(null==awtDevice) return -1; + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + GraphicsDevice[] gs = ge.getScreenDevices(); + for (int j = 0; j < gs.length; j++) { + if(gs[j] == awtDevice) return j; + } + return -1; + } + + public static AbstractGraphicsScreen createScreenDevice(GraphicsDevice awtDevice) { + AWTGraphicsDevice device = (AWTGraphicsDevice) AWTGraphicsDevice.createDevice(awtDevice); + return new AWTGraphicsScreen(device); + } + + public static AbstractGraphicsScreen createScreenDevice(int index) { + GraphicsDevice awtDevice = getScreenDevice(index); + return createScreenDevice(awtDevice); + } + + public static AbstractGraphicsScreen createDefault() { + return createScreenDevice(-1); + } + + public Object clone() { + return super.clone(); + } +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/egl/EGLGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/egl/EGLGraphicsDevice.java new file mode 100644 index 000000000..49c337359 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/egl/EGLGraphicsDevice.java @@ -0,0 +1,50 @@ +/* + * 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 javax.media.nativewindow.egl; + +import javax.media.nativewindow.*; + +/** Encapsulates a graphics device on EGL platforms. + */ + +public class EGLGraphicsDevice extends DefaultGraphicsDevice implements Cloneable { + /** Constructs a new EGLGraphicsDevice corresponding to the given EGL display handle. */ + public EGLGraphicsDevice(long eglDisplay) { + super(NativeWindowFactory.TYPE_EGL, eglDisplay); + } + + public Object clone() { + return super.clone(); + } +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/macosx/MacOSXGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/macosx/MacOSXGraphicsDevice.java new file mode 100644 index 000000000..3669ebd12 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/macosx/MacOSXGraphicsDevice.java @@ -0,0 +1,50 @@ +/* + * 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 javax.media.nativewindow.macosx; + +import javax.media.nativewindow.*; + +/** Encapsulates a graphics device on MacOSX platforms. + */ + +public class MacOSXGraphicsDevice extends DefaultGraphicsDevice implements Cloneable { + /** Constructs a new MacOSXGraphicsDevice */ + public MacOSXGraphicsDevice() { + super(NativeWindowFactory.TYPE_MACOSX); + } + + public Object clone() { + return super.clone(); + } +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/package.html b/src/nativewindow/classes/javax/media/nativewindow/package.html new file mode 100644 index 000000000..1eb1cef08 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/package.html @@ -0,0 +1,112 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html> +<head> + <title>NativeWindow Protocol Draft Public Review Specification</title> +</head> + <body> + +<h2><i>NativeWindow Protocol</i> Specification Overview</h2> + +<h3>Preface</h3> + This specification, an optional set of packages, describing a <i>protocol</i> for a + <i>native windowing interface</i> binding to Java(TM).<br> + Currently specified <i>native windowing systems</i> are:<br><br> + <ul> + <li> EGL/OpenKODE Windowing System</li> + <li> X11 Windowing System</li> + <li> Microsoft Windows</li> + <li> Apple MacOSX</li> + <li> Java's AWT</li> + </ul> + <br> + However, any other native windowing system may be added to the implementation, + using a generic string identifier and an optional specialisation of:<br><br> + <ul> + <li>{@link javax.media.nativewindow.AbstractGraphicsDevice AbstractGraphicsDevice},<br> + <br> + Shall return the new string identifier with {@link javax.media.nativewindow.AbstractGraphicsDevice#getType() getType()}</li><br> + <li>{@link javax.media.nativewindow.AbstractGraphicsScreen AbstractGraphicsScreen}</li> + <li>{@link javax.media.nativewindow.AbstractGraphicsConfiguration AbstractGraphicsConfiguration}</li><br> + </ul> + <br> + The implementor has to provide the following:<br><br> + <ul> + <li> The specialisation of the abstract class {@link javax.media.nativewindow.NativeWindowFactory NativeWindowFactory}<br> + <br> + shall be registered with {@link javax.media.nativewindow.NativeWindowFactory#registerFactory NativeWindowFactory.registerFactory(..)}.</li><br> + + <li> The specialisation of the abstract class {@link javax.media.nativewindow.GraphicsConfigurationFactory GraphicsConfigurationFactory}<br> + <br> + shall be registered with {@link javax.media.nativewindow.GraphicsConfigurationFactory#registerFactory GraphicsConfigurationFactory.registerFactory(..)}.</li><br> + </ul><br> + This protocol <i>does not</i> describe how to <i>create</i> native windows, but how to <i>bind</i> a native surface to an implementation of + and window to an implementation of {@link javax.media.nativewindow.NativeSurface NativeSurface}.<br> + {@link javax.media.nativewindow.NativeWindow NativeWindow} specializes the NativeSurface.<br> + However, an implementation of this protocol (e.g. {@link com.jogamp.newt}) may support the creation.<br> + +<h3>Dependencies</h3> + This binding has dependencies to the following:<br><br> + <ul> + <li> Either of the following Java implementations:<br> + <ul> + <li> <a href="http://java.sun.com/j2se/1.4.2/docs/api/">Java SE 1.4 or later</a> </li><br> + <li> <a href="http://java.sun.com/javame/technology/cdc/">Java ME CDC 1.1.2 (JSR 218)</a> and + <a href="http://java.sun.com/products/foundation/">Foundation Profile 1.1.2 (JSR 219)</a><br> + and either of the following <i>java.nio</i> implementations:<br> + <ul> + <li> <a href="http://java.sun.com/javame/reference/apis/jsr239/java/nio/package-summary.html"> JSR239 <i>java.nio</i> subset</a> </li> + <li> <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/nio/package-summary.html"> Java 1.4 <i>java.nio</i> implementation</a> </li> + </ul><br> + </ul> + </ul> + <br> + +<h3>Package Structure</h3> + The packages defined by this specification include:<br><br> +<ul> + <li>The <b>javax.media.nativewindow</b> package<br> + <br> + This package contains Java bindings for a native windowing system.<br> + Subsequent packages contain marker type classes, containing native characteristics of the windowing system.</li><br><br> + <ul> + <li>The <b>javax.media.nativewindow.awt</b> package<br> + <br> + This sub package contains classes to cover the native characteristics of the AWT windowing system.</li><br> + + <li>The <b>javax.media.nativewindow.x11</b> package<br> + <br> + This sub package contains classes to cover the native characteristics of the X11 windowing system.</li><br> + + <li>The <b>javax.media.nativewindow.windows</b> package<br> + <br> + This sub package contains classes to cover the native characteristics of the Windows windowing system.</li><br> + + <li>The <b>javax.media.nativewindow.macosx</b> package<br> + <br> + This sub package contains classes to cover the native characteristics of the MacOSX windowing system.</li><br> + + <li>The <b>javax.media.nativewindow.egl</b> package<br> + <br> + This sub package contains classes to cover the native characteristics of the EGL/OpenKODE windowing system.</li><br> + </ul> +</ul> + +<h3>Factory Model</h3> +Running on a platform with a supported windowing system, the factory model shall be used +to instantiate a native window, see {@link javax.media.nativewindow.NativeWindowFactory NativeWindowFactory}.<br> +The implementor has to specialize +All supported +Regardless of the knowledge of the underly +<br> + +<h3>Revision History<br> + </h3> + +<ul> +<li> Early Draft Review, June 2009 +</ul> + <br> + <br> + <br> +</body> +</html> diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/Dimension.java b/src/nativewindow/classes/javax/media/nativewindow/util/Dimension.java new file mode 100644 index 000000000..a970be158 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/util/Dimension.java @@ -0,0 +1,97 @@ +/** + * Copyright 2010 JogAmp Community. 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: + * + * 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.util; + +public class Dimension implements Cloneable, DimensionReadOnly { + int width; + int height; + + public Dimension() { + this(0, 0); + } + + public Dimension(int width, int height) { + if(width<0 || height<0) { + throw new IllegalArgumentException("width and height must be within: ["+0+".."+Integer.MAX_VALUE+"]"); + } + this.width=width; + this.height=height; + } + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException ex) { + throw new InternalError(); + } + } + + public int getWidth() { return width; } + public int getHeight() { return height; } + + public void setWidth(int width) { + this.width = width; + } + public void setHeight(int height) { + this.height = height; + } + public Dimension scale(int s) { + width *= s; + height *= s; + return this; + } + public Dimension add(Dimension pd) { + width += pd.width ; + height += pd.height ; + return this; + } + + public String toString() { + return new String(width+" x "+height); + } + + public boolean equals(Object obj) { + if(this == obj) { return true; } + if (obj instanceof Dimension) { + Dimension p = (Dimension)obj; + return height == p.height && + width == p.width ; + } + return false; + } + + public int hashCode() { + // 31 * x == (x << 5) - x + int hash = 31 + width; + hash = ((hash << 5) - hash) + height; + return hash; + } +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/DimensionReadOnly.java b/src/nativewindow/classes/javax/media/nativewindow/util/DimensionReadOnly.java new file mode 100644 index 000000000..442afd4ba --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/util/DimensionReadOnly.java @@ -0,0 +1,55 @@ +/** + * Copyright 2010 JogAmp Community. 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: + * + * 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.util; + +/** Immutable Dimension Interface, consisting of it's read only components:<br> + * <ul> + * <li><code>width</code></li> + * <li><code>height</code></li> + * </ul> + */ +public interface DimensionReadOnly extends Cloneable { + + int getHeight(); + + int getWidth(); + + /** + * Checks whether two dimensions objects are equal. Two instances + * of <code>DimensionReadOnly</code> are equal if two components + * <code>height</code> and <code>width</code> are equal. + * @return <code>true</code> if the two dimensions are equal; + * otherwise <code>false</code>. + */ + boolean equals(Object obj); + + int hashCode(); + +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/Insets.java b/src/nativewindow/classes/javax/media/nativewindow/util/Insets.java new file mode 100644 index 000000000..96a45b7b1 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/util/Insets.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2009 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. + * + */ +package javax.media.nativewindow.util; + +/** + * Simple class representing insets. + * + * @author tdv + */ +public class Insets implements Cloneable { + public int top; + public int left; + public int bottom; + public int right; + public int hash; + + /** + * Creates and initializes a new <code>Insets</code> object with the + * specified top, left, bottom, and right insets. + * @param top the inset from the top. + * @param left the inset from the left. + * @param bottom the inset from the bottom. + * @param right the inset from the right. + */ + public Insets(int top, int left, int bottom, int right) { + this.top = top; + this.left = left; + this.bottom = bottom; + this.right = right; + this.hash = computeHashCode(); + } + + /** + * Checks whether two insets objects are equal. Two instances + * of <code>Insets</code> are equal if the four integer values + * of the fields <code>top</code>, <code>left</code>, + * <code>bottom</code>, and <code>right</code> are all equal. + * @return <code>true</code> if the two insets are equal; + * otherwise <code>false</code>. + */ + public boolean equals(Object obj) { + if(this == obj) { return true; } + if (obj instanceof Insets) { + Insets insets = (Insets)obj; + return ((top == insets.top) && (left == insets.left) && + (bottom == insets.bottom) && (right == insets.right)); + } + return false; + } + + /** + * Returns the hash code for this Insets. + * + * @return a hash code for this Insets. + */ + public int hashCode() { + return hash; + } + + public String toString() { + return getClass().getName() + "[top=" + top + ",left=" + left + + ",bottom=" + bottom + ",right=" + right + "]"; + } + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException ex) { + throw new InternalError(); + } + } + + protected int computeHashCode() { + int sum1 = left + bottom; + int sum2 = right + top; + int val1 = sum1 * (sum1 + 1)/2 + left; + int val2 = sum2 * (sum2 + 1)/2 + top; + int sum3 = val1 + val2; + return sum3 * (sum3 + 1)/2 + val2; + } +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/Point.java b/src/nativewindow/classes/javax/media/nativewindow/util/Point.java new file mode 100644 index 000000000..6db0ecfe2 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/util/Point.java @@ -0,0 +1,96 @@ +/** + * Copyright 2010 JogAmp Community. 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: + * + * 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.util; + +public class Point implements Cloneable, PointReadOnly { + int x; + int y; + + public Point(int x, int y) { + this.x=x; + this.y=y; + } + + public Point() { + this(0, 0); + } + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException ex) { + throw new InternalError(); + } + } + + public boolean equals(Object obj) { + if(this == obj) { return true; } + if (obj instanceof Point) { + Point p = (Point)obj; + return y == p.y && x == p.x; + } + return false; + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + + public int hashCode() { + // 31 * x == (x << 5) - x + int hash = 31 + x; + hash = ((hash << 5) - hash) + y; + return hash; + } + + public String toString() { + return new String( x + " / " + y ); + } + + public void setX(int x) { this.x = x; } + public void setY(int y) { this.y = y; } + + public Point translate(Point pd) { + x += pd.x ; + y += pd.y ; + return this; + } + + public Point translate(int dx, int dy) { + x += dx ; + y += dy ; + return this; + } + +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/PointReadOnly.java b/src/nativewindow/classes/javax/media/nativewindow/util/PointReadOnly.java new file mode 100644 index 000000000..9caaf7fee --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/util/PointReadOnly.java @@ -0,0 +1,50 @@ +/** + * Copyright 2010 JogAmp Community. 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: + * + * 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.util; + +/** Immutable Point interface */ +public interface PointReadOnly extends Cloneable { + + int getX(); + + int getY(); + + /** + * Checks whether two points objects are equal. Two instances + * of <code>PointReadOnly</code> are equal if the two components + * <code>y</code> and <code>x</code> are equal. + * @return <code>true</code> if the two points are equal; + * otherwise <code>false</code>. + */ + public boolean equals(Object obj); + + public int hashCode(); + +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/Rectangle.java b/src/nativewindow/classes/javax/media/nativewindow/util/Rectangle.java new file mode 100644 index 000000000..ba24bc64e --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/util/Rectangle.java @@ -0,0 +1,88 @@ +/** + * 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.util; + +public class Rectangle implements Cloneable, RectangleReadOnly { + 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; + } + + protected Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException ex) { + throw new InternalError(); + } + } + + 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 boolean equals(Object obj) { + if(this == obj) { return true; } + if (obj instanceof Rectangle) { + Rectangle rect = (Rectangle)obj; + return (y == rect.y) && (x == rect.x) && + (height == rect.height) && (width == rect.width); + } + return false; + } + + public int hashCode() { + int sum1 = x + height; + int sum2 = width + y; + int val1 = sum1 * (sum1 + 1)/2 + x; + int val2 = sum2 * (sum2 + 1)/2 + y; + int sum3 = val1 + val2; + return sum3 * (sum3 + 1)/2 + val2; + } + + public String toString() { + return new String("[ "+x+" / "+y+" "+width+" x "+height+" ]"); + } +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/RectangleReadOnly.java b/src/nativewindow/classes/javax/media/nativewindow/util/RectangleReadOnly.java new file mode 100644 index 000000000..81a5a9f86 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/util/RectangleReadOnly.java @@ -0,0 +1,54 @@ +/** + * 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.util; + +/** Immutable Rectangle interface */ +public interface RectangleReadOnly extends Cloneable { + + int getHeight(); + + int getWidth(); + + int getX(); + + int getY(); + + /** + * Checks whether two rect objects are equal. Two instances + * of <code>Rectangle</code> are equal if the four integer values + * of the fields <code>y</code>, <code>x</code>, + * <code>height</code>, and <code>width</code> are all equal. + * @return <code>true</code> if the two rectangles are equal; + * otherwise <code>false</code>. + */ + boolean equals(Object obj); + + int hashCode(); + +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/SurfaceSize.java b/src/nativewindow/classes/javax/media/nativewindow/util/SurfaceSize.java new file mode 100644 index 000000000..ea098b967 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/util/SurfaceSize.java @@ -0,0 +1,95 @@ +/** + * Copyright 2010 JogAmp Community. 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: + * + * 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.util; + +/** Immutable SurfaceSize Class, consisting of it's read only components:<br> + * <ul> + * <li>{@link javax.media.nativewindow.util.DimensionReadOnly} size in pixels</li> + * <li><code>bits per pixel</code></li> + * </ul> + */ +public class SurfaceSize implements Cloneable { + DimensionReadOnly resolution; + int bitsPerPixel; + + public SurfaceSize(DimensionReadOnly resolution, int bitsPerPixel) { + if(null==resolution || bitsPerPixel<=0) { + throw new IllegalArgumentException("resolution must be set and bitsPerPixel greater 0"); + } + this.resolution=resolution; + this.bitsPerPixel=bitsPerPixel; + } + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException ex) { + throw new InternalError(); + } + } + + public final DimensionReadOnly getResolution() { + return resolution; + } + + public final int getBitsPerPixel() { + return bitsPerPixel; + } + + public final String toString() { + return new String("[ "+resolution+" x "+bitsPerPixel+" bpp ]"); + } + + /** + * Checks whether two size objects are equal. Two instances + * of <code>SurfaceSize</code> are equal if the two components + * <code>resolution</code> and <code>bitsPerPixel</code> + * are equal. + * @return <code>true</code> if the two dimensions are equal; + * otherwise <code>false</code>. + */ + public final boolean equals(Object obj) { + if(this == obj) { return true; } + if (obj instanceof SurfaceSize) { + SurfaceSize p = (SurfaceSize)obj; + return getResolution().equals(p.getResolution()) && + getBitsPerPixel() == p.getBitsPerPixel(); + } + return false; + } + + public final int hashCode() { + // 31 * x == (x << 5) - x + int hash = 31 + getResolution().hashCode(); + hash = ((hash << 5) - hash) + getBitsPerPixel(); + return hash; + } +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/windows/WindowsGraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/windows/WindowsGraphicsDevice.java new file mode 100644 index 000000000..69dde49af --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/windows/WindowsGraphicsDevice.java @@ -0,0 +1,50 @@ +/* + * 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 javax.media.nativewindow.windows; + +import javax.media.nativewindow.*; + +/** Encapsulates a graphics device on Windows platforms. + */ + +public class WindowsGraphicsDevice extends DefaultGraphicsDevice implements Cloneable { + /** Constructs a new WindowsGraphicsDevice */ + public WindowsGraphicsDevice() { + super(NativeWindowFactory.TYPE_WINDOWS); + } + + public Object clone() { + return super.clone(); + } +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java new file mode 100644 index 000000000..5659dcdcc --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java @@ -0,0 +1,76 @@ +/* + * 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 javax.media.nativewindow.x11; + +import javax.media.nativewindow.*; +import com.jogamp.nativewindow.impl.x11.XVisualInfo; + +/** Encapsulates a graphics configuration, or OpenGL pixel format, on + X11 platforms. Objects of this type are returned from {@link + javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration + GraphicsConfigurationFactory.chooseGraphicsConfiguration()} on X11 + platforms when toolkits other than the AWT are being used. */ + +public class X11GraphicsConfiguration extends DefaultGraphicsConfiguration implements Cloneable { + private XVisualInfo info; + + public X11GraphicsConfiguration(X11GraphicsScreen screen, + Capabilities capsChosen, Capabilities capsRequested, + XVisualInfo info) { + super(screen, capsChosen, capsRequested); + this.info = info; + } + + public Object clone() { + return super.clone(); + } + + public XVisualInfo getXVisualInfo() { + return info; + } + + protected void setXVisualInfo(XVisualInfo info) { + this.info = info; + } + + public long getVisualID() { + return (null!=info)?info.getVisualid():0; + } + + public String toString() { + return getClass().toString()+"["+getScreen()+", visualID 0x" + Long.toHexString(getVisualID()) + + ",\n\tchosen " + capabilitiesChosen+ + ",\n\trequested " + capabilitiesRequested+ + "]"; + } +} diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java new file mode 100644 index 000000000..c60597661 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsDevice.java @@ -0,0 +1,81 @@ +/* + * 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 javax.media.nativewindow.x11; + +import com.jogamp.nativewindow.impl.x11.X11Util; +import javax.media.nativewindow.*; + +/** Encapsulates a graphics device on X11 platforms. + */ + +public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneable { + boolean closeDisplay = false; + + /** Constructs a new X11GraphicsDevice corresponding to the given native display handle and default + * {@link javax.media.nativewindow.ToolkitLock} via {@link NativeWindowFactory#createDefaultToolkitLock(java.lang.String, long)}. + */ + public X11GraphicsDevice(long display) { + super(NativeWindowFactory.TYPE_X11, display); + if(0==display) { + throw new NativeWindowException("null display"); + } + } + + /** + * @param display the Display connection + * @param locker custom {@link javax.media.nativewindow.ToolkitLock}, eg to force null locking in NEWT + */ + public X11GraphicsDevice(long display, ToolkitLock locker) { + super(NativeWindowFactory.TYPE_X11, display, locker); + if(0==display) { + throw new NativeWindowException("null display"); + } + } + + public Object clone() { + return super.clone(); + } + + public void setCloseDisplay(boolean close) { + closeDisplay = close; + } + public boolean close() { + if(closeDisplay && 0 != handle) { + X11Util.closeDisplay(handle); + handle = 0; + return true; + } + return true; + } +} + diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.java new file mode 100644 index 000000000..dca0d1de3 --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsScreen.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 javax.media.nativewindow.x11; + +import javax.media.nativewindow.*; +import com.jogamp.nativewindow.impl.x11.X11Util; + +/** Encapsulates a screen index on X11 + platforms. Objects of this type are passed to {@link + javax.media.nativewindow.GraphicsConfigurationFactory#chooseGraphicsConfiguration + GraphicsConfigurationFactory.chooseGraphicsConfiguration()} on X11 + platforms when toolkits other than the AWT are being used. */ + +public class X11GraphicsScreen extends DefaultGraphicsScreen implements Cloneable { + + /** Constructs a new X11GraphicsScreen corresponding to the given native screen index. */ + public X11GraphicsScreen(X11GraphicsDevice device, int screen) { + super(device, fetchScreen(device, screen)); + } + + public static AbstractGraphicsScreen createScreenDevice(long display, int screenIdx) { + if(0==display) throw new NativeWindowException("display is null"); + return new X11GraphicsScreen(new X11GraphicsDevice(display), screenIdx); + } + + public long getDefaultVisualID() { + // It still could be an AWT hold handle .. + long display = getDevice().getHandle(); + int scrnIdx = X11Util.DefaultScreen(display); + return X11Util.DefaultVisualID(display, scrnIdx); + } + + private static int fetchScreen(X11GraphicsDevice device, int screen) { + // It still could be an AWT hold handle .. + long display = device.getHandle(); + if(X11Util.XineramaEnabled(display)) { + screen = 0; // Xinerama -> 1 screen + } + return screen; + } + + public Object clone() { + return super.clone(); + } +} |