diff options
Diffstat (limited to 'src/nativewindow/classes')
7 files changed, 92 insertions, 32 deletions
diff --git a/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java b/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java index e844c4f3e..79d69c703 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java +++ b/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java @@ -44,7 +44,7 @@ package javax.media.nativewindow; 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 CapabilitiesImmutable, Cloneable { +public class Capabilities implements CapabilitiesImmutable, Cloneable, Comparable { private int redBits = 8; private int greenBits = 8; private int blueBits = 8; @@ -114,6 +114,30 @@ public class Capabilities implements CapabilitiesImmutable, Cloneable { return res; } + /** comparing RGBA values only */ + public int compareTo(Object o) { + if ( ! ( o instanceof Capabilities ) ) { + Class c = (null != o) ? o.getClass() : null ; + throw new ClassCastException("Not a Capabilities object: " + c); + } + + final Capabilities caps = (Capabilities) o; + + final int a = ( alphaBits > 0 ) ? alphaBits : 1; + final int rgba = redBits * greenBits * blueBits * a; + + final int xa = ( caps.alphaBits ) > 0 ? caps.alphaBits : 1; + final int xrgba = caps.redBits * caps.greenBits * caps.blueBits * xa; + + if(rgba > xrgba) { + return 1; + } else if(rgba < xrgba) { + return -1; + } + + return 0; // they are equal: RGBA + } + /** 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. */ @@ -274,25 +298,31 @@ public class Capabilities implements CapabilitiesImmutable, Cloneable { A value of -1 is interpreted as any value. */ public void setTransparentAlphaValue(int transValueAlpha) { transparentValueAlpha=transValueAlpha; } + public StringBuffer toString(StringBuffer sink) { + if(null == sink) { + sink = new StringBuffer(); + } + if(onscreen) { + sink.append("on-scr"); + } else { + sink.append("offscr"); + } + sink.append(", rgba ").append(redBits).append("/").append(greenBits).append("/").append(blueBits).append("/").append(alphaBits); + if(backgroundOpaque) { + sink.append(", opaque"); + } else { + sink.append(", trans-rgba 0x").append(Integer.toHexString(transparentValueRed)).append("/").append(Integer.toHexString(transparentValueGreen)).append("/").append(Integer.toHexString(transparentValueBlue)).append("/").append(Integer.toHexString(transparentValueAlpha)); + } + return sink; + } /** 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("]"); + msg.append("Caps["); + toString(msg); + 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 index 94b0f68af..a306363dc 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesChooser.java +++ b/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesChooser.java @@ -39,6 +39,8 @@ package javax.media.nativewindow; +import java.util.List; + /** 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 @@ -63,6 +65,6 @@ public interface CapabilitiesChooser { choice to some other CapabilitiesChooser object. */ public int chooseCapabilities(CapabilitiesImmutable desired, - CapabilitiesImmutable[] available, + List /*<CapabilitiesImmutable>*/ available, int windowSystemRecommendedChoice); } diff --git a/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesImmutable.java b/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesImmutable.java index 72828b9f0..3aae8c8fb 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesImmutable.java +++ b/src/nativewindow/classes/javax/media/nativewindow/CapabilitiesImmutable.java @@ -109,6 +109,9 @@ public interface CapabilitiesImmutable extends WriteCloneable { /** hash code over the immutable attributes of both objects */ int hashCode(); + /** Return a textual representation of this object. Use the given StringBuffer [optional]. */ + StringBuffer toString(StringBuffer sink); + /** Returns a textual representation of this object. */ String toString(); } diff --git a/src/nativewindow/classes/javax/media/nativewindow/DefaultCapabilitiesChooser.java b/src/nativewindow/classes/javax/media/nativewindow/DefaultCapabilitiesChooser.java index 856c29420..b43db8292 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/DefaultCapabilitiesChooser.java +++ b/src/nativewindow/classes/javax/media/nativewindow/DefaultCapabilitiesChooser.java @@ -1,5 +1,6 @@ /* * 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 @@ -39,6 +40,8 @@ package javax.media.nativewindow; +import java.util.List; + /** <P> The default implementation of the {@link CapabilitiesChooser} interface, which provides consistent visual selection behavior across platforms. The precise algorithm is @@ -63,37 +66,38 @@ package javax.media.nativewindow; public class DefaultCapabilitiesChooser implements CapabilitiesChooser { private static final boolean DEBUG = false; // FIXME: Debug.debug("DefaultCapabilitiesChooser"); - public int chooseCapabilities(CapabilitiesImmutable desired, - CapabilitiesImmutable[] available, - int windowSystemRecommendedChoice) { + public int chooseCapabilities(final CapabilitiesImmutable desired, + final List /*<CapabilitiesImmutable>*/ available, + final int windowSystemRecommendedChoice) { if (DEBUG) { System.err.println("Desired: " + desired); - for (int i = 0; i < available.length; i++) { - System.err.println("Available " + i + ": " + available[i]); + for (int i = 0; i < available.size(); i++) { + System.err.println("Available " + i + ": " + available.get(i)); } System.err.println("Window system's recommended choice: " + windowSystemRecommendedChoice); } + final int availnum = available.size(); if (windowSystemRecommendedChoice >= 0 && - windowSystemRecommendedChoice < available.length && - available[windowSystemRecommendedChoice] != null) { + windowSystemRecommendedChoice < availnum && + null != available.get(windowSystemRecommendedChoice)) { if (DEBUG) { System.err.println("Choosing window system's recommended choice of " + windowSystemRecommendedChoice); - System.err.println(available[windowSystemRecommendedChoice]); + System.err.println(available.get(windowSystemRecommendedChoice)); } return windowSystemRecommendedChoice; } // Create score array - int[] scores = new int[available.length]; + int[] scores = new int[availnum]; int NO_SCORE = -9999999; int COLOR_MISMATCH_PENALTY_SCALE = 36; - for (int i = 0; i < scores.length; i++) { + for (int i = 0; i < availnum; i++) { scores[i] = NO_SCORE; } // Compute score for each - for (int i = 0; i < scores.length; i++) { - CapabilitiesImmutable cur = available[i]; + for (int i = 0; i < availnum; i++) { + CapabilitiesImmutable cur = (CapabilitiesImmutable) available.get(i); if (cur == null) { continue; } @@ -107,7 +111,7 @@ public class DefaultCapabilitiesChooser implements CapabilitiesChooser { if (DEBUG) { System.err.print("Scores: ["); - for (int i = 0; i < available.length; i++) { + for (int i = 0; i < availnum; i++) { if (i > 0) { System.err.print(","); } @@ -119,7 +123,7 @@ public class DefaultCapabilitiesChooser implements CapabilitiesChooser { // Ready to select. Choose score closest to 0. int scoreClosestToZero = NO_SCORE; int chosenIndex = -1; - for (int i = 0; i < scores.length; i++) { + for (int i = 0; i < availnum; i++) { int score = scores[i]; if (score == NO_SCORE) { continue; @@ -138,7 +142,7 @@ public class DefaultCapabilitiesChooser implements CapabilitiesChooser { if (DEBUG) { System.err.println("Chosen index: " + chosenIndex); System.err.println("Chosen capabilities:"); - System.err.println(available[chosenIndex]); + System.err.println(available.get(chosenIndex)); } return chosenIndex; diff --git a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java index 42020488c..c728c1634 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java +++ b/src/nativewindow/classes/javax/media/nativewindow/DefaultGraphicsConfiguration.java @@ -111,4 +111,12 @@ public class DefaultGraphicsConfiguration implements Cloneable, AbstractGraphics ",\n\trequested " + capabilitiesRequested+ "]"; } + + public static String toHexString(int val) { + return "0x"+Integer.toHexString(val); + } + + public static String toHexString(long val) { + return "0x"+Long.toHexString(val); + } } diff --git a/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java index ba047c1f6..ad1bc3634 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java +++ b/src/nativewindow/classes/javax/media/nativewindow/GraphicsConfigurationFactory.java @@ -68,6 +68,18 @@ public abstract class GraphicsConfigurationFactory { initialize(); } + protected static String getThreadName() { + return Thread.currentThread().getName(); + } + + protected static String toHexString(int val) { + return "0x" + Integer.toHexString(val); + } + + protected static String toHexString(long val) { + return "0x" + Long.toHexString(val); + } + /** Creates a new NativeWindowFactory instance. End users do not need to call this method. */ protected GraphicsConfigurationFactory() { diff --git a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java index 01c734702..7b5f19047 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java +++ b/src/nativewindow/classes/javax/media/nativewindow/x11/X11GraphicsConfiguration.java @@ -32,8 +32,9 @@ package javax.media.nativewindow.x11; -import com.jogamp.common.util.ReflectionUtil; import javax.media.nativewindow.*; + +import com.jogamp.common.util.ReflectionUtil; import com.jogamp.nativewindow.impl.x11.XVisualInfo; /** Encapsulates a graphics configuration, or OpenGL pixel format, on |