src/share/classes/sun/java2d/loops/SurfaceType.java

Print this page




  39  * generalized) way.
  40  * <p>
  41  * A more specific description of a surface is considered a "subtype"
  42  * and a more general description is considered a "supertype".  Thus,
  43  * the deriveSubType method provides a way to create a new SurfaceType
  44  * that is related to but more specific than an existing SurfaceType and
  45  * the getSuperType method provides a way to ask a given SurfaceType
  46  * for a more general way to describe the same surface.
  47  * <p>
  48  * Note that you cannot construct a brand new root for a chain since
  49  * the constructor is private.  Every chain of types must at some point
  50  * derive from the Any node provided here using the deriveSubType()
  51  * method.  The presence of this common Any node on every chain
  52  * ensures that all chains end with the DESC_ANY descriptor so that
  53  * a suitable General GraphicsPrimitive object can be obtained for
  54  * the indicated surface if all of the more specific searches fail.
  55  */
  56 public final class SurfaceType {
  57 
  58     private static int unusedUID = 1;
  59     private static HashMap surfaceUIDMap = new HashMap(100);
  60 
  61     /*
  62      * CONSTANTS USED BY ALL PRIMITIVES TO DESCRIBE THE SURFACES
  63      * THEY CAN OPERATE ON
  64      */
  65 
  66     /**
  67      * surface is unknown color model or sample model.
  68      */
  69     public static final String
  70         DESC_ANY            = "Any Surface";
  71 
  72     /**
  73      * common surface formats defined in BufferedImage
  74      */
  75     public static final String
  76         DESC_INT_RGB        = "Integer RGB";
  77     public static final String
  78         DESC_INT_ARGB       = "Integer ARGB";
  79     public static final String


 385     private String desc;
 386     private SurfaceType next;
 387     protected PixelConverter pixelConverter;
 388 
 389     private SurfaceType(SurfaceType parent, String desc,
 390                         PixelConverter pixelConverter) {
 391         next = parent;
 392         this.desc = desc;
 393         this.uniqueID = makeUniqueID(desc);
 394         this.pixelConverter = pixelConverter;
 395     }
 396 
 397     private SurfaceType(SurfaceType parent, String desc) {
 398         next = parent;
 399         this.desc = desc;
 400         this.uniqueID = makeUniqueID(desc);
 401         this.pixelConverter = parent.pixelConverter;
 402     }
 403 
 404     public synchronized static final int makeUniqueID(String desc) {
 405         Integer i = (Integer) surfaceUIDMap.get((Object) desc);
 406 
 407         if (i == null) {
 408             if (unusedUID > 255) {
 409                 throw new InternalError("surface type id overflow");
 410             }
 411             i = Integer.valueOf(unusedUID++);
 412             surfaceUIDMap.put(desc, i);
 413         }
 414         return i.intValue();
 415     }
 416 
 417     public int getUniqueID() {
 418         return uniqueID;
 419     }
 420 
 421     public String getDescriptor() {
 422         return desc;
 423     }
 424 
 425     public SurfaceType getSuperType() {




  39  * generalized) way.
  40  * <p>
  41  * A more specific description of a surface is considered a "subtype"
  42  * and a more general description is considered a "supertype".  Thus,
  43  * the deriveSubType method provides a way to create a new SurfaceType
  44  * that is related to but more specific than an existing SurfaceType and
  45  * the getSuperType method provides a way to ask a given SurfaceType
  46  * for a more general way to describe the same surface.
  47  * <p>
  48  * Note that you cannot construct a brand new root for a chain since
  49  * the constructor is private.  Every chain of types must at some point
  50  * derive from the Any node provided here using the deriveSubType()
  51  * method.  The presence of this common Any node on every chain
  52  * ensures that all chains end with the DESC_ANY descriptor so that
  53  * a suitable General GraphicsPrimitive object can be obtained for
  54  * the indicated surface if all of the more specific searches fail.
  55  */
  56 public final class SurfaceType {
  57 
  58     private static int unusedUID = 1;
  59     private static HashMap<String, Integer> surfaceUIDMap = new HashMap<>(100);
  60 
  61     /*
  62      * CONSTANTS USED BY ALL PRIMITIVES TO DESCRIBE THE SURFACES
  63      * THEY CAN OPERATE ON
  64      */
  65 
  66     /**
  67      * surface is unknown color model or sample model.
  68      */
  69     public static final String
  70         DESC_ANY            = "Any Surface";
  71 
  72     /**
  73      * common surface formats defined in BufferedImage
  74      */
  75     public static final String
  76         DESC_INT_RGB        = "Integer RGB";
  77     public static final String
  78         DESC_INT_ARGB       = "Integer ARGB";
  79     public static final String


 385     private String desc;
 386     private SurfaceType next;
 387     protected PixelConverter pixelConverter;
 388 
 389     private SurfaceType(SurfaceType parent, String desc,
 390                         PixelConverter pixelConverter) {
 391         next = parent;
 392         this.desc = desc;
 393         this.uniqueID = makeUniqueID(desc);
 394         this.pixelConverter = pixelConverter;
 395     }
 396 
 397     private SurfaceType(SurfaceType parent, String desc) {
 398         next = parent;
 399         this.desc = desc;
 400         this.uniqueID = makeUniqueID(desc);
 401         this.pixelConverter = parent.pixelConverter;
 402     }
 403 
 404     public synchronized static final int makeUniqueID(String desc) {
 405         Integer i = surfaceUIDMap.get(desc);
 406 
 407         if (i == null) {
 408             if (unusedUID > 255) {
 409                 throw new InternalError("surface type id overflow");
 410             }
 411             i = Integer.valueOf(unusedUID++);
 412             surfaceUIDMap.put(desc, i);
 413         }
 414         return i.intValue();
 415     }
 416 
 417     public int getUniqueID() {
 418         return uniqueID;
 419     }
 420 
 421     public String getDescriptor() {
 422         return desc;
 423     }
 424 
 425     public SurfaceType getSuperType() {