src/demo/share/java2d/J2DBench/src/j2dbench/Destinations.java

Print this page


   1 /*
   2  * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
   3  *
   4  * Redistribution and use in source and binary forms, with or without
   5  * modification, are permitted provided that the following conditions
   6  * are met:
   7  *
   8  *   - Redistributions of source code must retain the above copyright
   9  *     notice, this list of conditions and the following disclaimer.
  10  *
  11  *   - Redistributions in binary form must reproduce the above copyright
  12  *     notice, this list of conditions and the following disclaimer in the
  13  *     documentation and/or other materials provided with the distribution.
  14  *
  15  *   - Neither the name of Oracle nor the names of its
  16  *     contributors may be used to endorse or promote products derived
  17  *     from this software without specific prior written permission.
  18  *
  19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR


  40 
  41 package j2dbench;
  42 
  43 import java.awt.Image;
  44 import java.awt.Component;
  45 import java.awt.GraphicsConfiguration;
  46 import java.awt.Transparency;
  47 import java.awt.color.ColorSpace;
  48 import java.awt.image.BufferedImage;
  49 import java.awt.image.ComponentColorModel;
  50 import java.awt.image.DataBuffer;
  51 import java.awt.image.WritableRaster;
  52 
  53 import j2dbench.tests.GraphicsTests;
  54 import j2dbench.tests.ImageTests;
  55 
  56 public abstract class Destinations extends Option.Enable {
  57     public static Group.EnableSet destroot;
  58     public static Group bufimgdestroot;
  59     public static Group compatimgdestroot;

  60 
  61     public static void init() {
  62         destroot = new Group.EnableSet(TestEnvironment.globaloptroot,
  63                                        "dest", "Output Destination Options");
  64 
  65         new Screen();
  66         new OffScreen();
  67 
  68         if (GraphicsTests.hasGraphics2D) {
  69             if (ImageTests.hasCompatImage) {
  70                 compatimgdestroot =
  71                     new Group.EnableSet(destroot, "compatimg",
  72                                         "Compatible Image Destinations");
  73                 compatimgdestroot.setHorizontal();
  74 
  75                 new CompatImg();
  76                 new CompatImg(Transparency.OPAQUE);
  77                 new CompatImg(Transparency.BITMASK);
  78                 new CompatImg(Transparency.TRANSLUCENT);
  79             }
  80 
  81             if (ImageTests.hasVolatileImage) {














  82                 new VolatileImg();
  83             }

  84 
  85             bufimgdestroot = new Group.EnableSet(destroot, "bufimg",
  86                                                  "BufferedImage Destinations");
  87 
  88             new BufImg(BufferedImage.TYPE_INT_RGB);
  89             new BufImg(BufferedImage.TYPE_INT_ARGB);
  90             new BufImg(BufferedImage.TYPE_INT_ARGB_PRE);
  91             new BufImg(BufferedImage.TYPE_3BYTE_BGR);
  92             new BufImg(BufferedImage.TYPE_BYTE_INDEXED);
  93             new BufImg(BufferedImage.TYPE_BYTE_GRAY);


  94             new CustomImg();
  95         }
  96     }
  97 
  98     public Destinations(Group parent,
  99                         String nodename, String description,
 100                         boolean defenabled)
 101     {
 102         super(parent, nodename, description, defenabled);
 103     }
 104 
 105     public void modifyTest(TestEnvironment env) {
 106         setDestination(env);
 107     }
 108 
 109     public void restoreTest(TestEnvironment env) {
 110         env.setTestImage(null);
 111     }
 112 
 113     public String getAbbreviatedModifierDescription(Object val) {


 189         }
 190 
 191         public String getModifierValueName(Object val) {
 192             return ModifierNames[transparency];
 193         }
 194 
 195         public void setDestination(TestEnvironment env) {
 196             Component c = env.getCanvas();
 197             GraphicsConfiguration gc = c.getGraphicsConfiguration();
 198             int w = env.getWidth();
 199             int h = env.getHeight();
 200             if (transparency == 0) {
 201                 env.setTestImage(gc.createCompatibleImage(w, h));
 202             } else {
 203                 env.setTestImage(gc.createCompatibleImage(w, h, transparency));
 204             }
 205         }
 206     }
 207 
 208     public static class VolatileImg extends Destinations {






























 209         public VolatileImg() {
 210             super(destroot, "volimg", "Output to Volatile Image", false);
 211         }
 212 
 213         public String getModifierValueName(Object val) {
 214             return "VolatileImg";




 215         }
 216 
 217         public void setDestination(TestEnvironment env) {




 218             Component c = env.getCanvas();
 219             env.setTestImage(c.createVolatileImage(env.getWidth(),
 220                                                    env.getHeight()));






 221         }
 222     }
 223 
 224 
 225     public static class BufImg extends Destinations {
 226         int type;
 227         Image img;
 228 
 229         public static String ShortNames[] = {
 230             "custom",
 231             "IntXrgb",
 232             "IntArgb",
 233             "IntArgbPre",
 234             "IntXbgr",
 235             "3ByteBgr",
 236             "4ByteAbgr",
 237             "4ByteAbgrPre",
 238             "Short565",
 239             "Short555",
 240             "ByteGray",


   1 /*
   2  * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
   3  *
   4  * Redistribution and use in source and binary forms, with or without
   5  * modification, are permitted provided that the following conditions
   6  * are met:
   7  *
   8  *   - Redistributions of source code must retain the above copyright
   9  *     notice, this list of conditions and the following disclaimer.
  10  *
  11  *   - Redistributions in binary form must reproduce the above copyright
  12  *     notice, this list of conditions and the following disclaimer in the
  13  *     documentation and/or other materials provided with the distribution.
  14  *
  15  *   - Neither the name of Oracle nor the names of its
  16  *     contributors may be used to endorse or promote products derived
  17  *     from this software without specific prior written permission.
  18  *
  19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR


  40 
  41 package j2dbench;
  42 
  43 import java.awt.Image;
  44 import java.awt.Component;
  45 import java.awt.GraphicsConfiguration;
  46 import java.awt.Transparency;
  47 import java.awt.color.ColorSpace;
  48 import java.awt.image.BufferedImage;
  49 import java.awt.image.ComponentColorModel;
  50 import java.awt.image.DataBuffer;
  51 import java.awt.image.WritableRaster;
  52 
  53 import j2dbench.tests.GraphicsTests;
  54 import j2dbench.tests.ImageTests;
  55 
  56 public abstract class Destinations extends Option.Enable {
  57     public static Group.EnableSet destroot;
  58     public static Group bufimgdestroot;
  59     public static Group compatimgdestroot;
  60     public static Group volimgdestroot;
  61 
  62     public static void init() {
  63         destroot = new Group.EnableSet(TestEnvironment.globaloptroot,
  64                                        "dest", "Output Destination Options");
  65 
  66         new Screen();
  67         new OffScreen();
  68 
  69         if (GraphicsTests.hasGraphics2D) {
  70             if (ImageTests.hasCompatImage) {
  71                 compatimgdestroot =
  72                     new Group.EnableSet(destroot, "compatimg",
  73                                         "Compatible Image Destinations");
  74                 compatimgdestroot.setHorizontal();
  75 
  76                 new CompatImg();
  77                 new CompatImg(Transparency.OPAQUE);
  78                 new CompatImg(Transparency.BITMASK);
  79                 new CompatImg(Transparency.TRANSLUCENT);
  80             }
  81 
  82             if (ImageTests.hasVolatileImage) {
  83                 if(ImageTests.hasTransparentVolatileImage) {
  84                     volimgdestroot = new Group.EnableSet(destroot, "volimg",
  85                                                          "Output to Volatile Image");
  86 
  87                     volimgdestroot.setHorizontal();
  88                     new VolatileImg();
  89                     new VolatileImg(Transparency.OPAQUE);
  90                     new VolatileImg(Transparency.BITMASK);
  91                     new VolatileImg(Transparency.TRANSLUCENT);
  92                 } else if (ImageTests.hasVolatileImage){
  93                     volimgdestroot = new Group.EnableSet(destroot, "volimg",
  94                                                          "Output to Volatile Image");
  95 
  96                     volimgdestroot.setHorizontal();
  97                     new VolatileImg();
  98                 }
  99             }
 100 
 101             bufimgdestroot = new Group.EnableSet(destroot, "bufimg",
 102                                                  "BufferedImage Destinations");
 103 
 104             new BufImg(BufferedImage.TYPE_INT_RGB);
 105             new BufImg(BufferedImage.TYPE_INT_ARGB);
 106             new BufImg(BufferedImage.TYPE_INT_ARGB_PRE);
 107             new BufImg(BufferedImage.TYPE_3BYTE_BGR);
 108             new BufImg(BufferedImage.TYPE_BYTE_INDEXED);
 109             new BufImg(BufferedImage.TYPE_BYTE_GRAY);
 110             new BufImg(BufferedImage.TYPE_4BYTE_ABGR);
 111             new BufImg(BufferedImage.TYPE_4BYTE_ABGR_PRE);
 112             new CustomImg();
 113         }
 114     }
 115 
 116     public Destinations(Group parent,
 117                         String nodename, String description,
 118                         boolean defenabled)
 119     {
 120         super(parent, nodename, description, defenabled);
 121     }
 122 
 123     public void modifyTest(TestEnvironment env) {
 124         setDestination(env);
 125     }
 126 
 127     public void restoreTest(TestEnvironment env) {
 128         env.setTestImage(null);
 129     }
 130 
 131     public String getAbbreviatedModifierDescription(Object val) {


 207         }
 208 
 209         public String getModifierValueName(Object val) {
 210             return ModifierNames[transparency];
 211         }
 212 
 213         public void setDestination(TestEnvironment env) {
 214             Component c = env.getCanvas();
 215             GraphicsConfiguration gc = c.getGraphicsConfiguration();
 216             int w = env.getWidth();
 217             int h = env.getHeight();
 218             if (transparency == 0) {
 219                 env.setTestImage(gc.createCompatibleImage(w, h));
 220             } else {
 221                 env.setTestImage(gc.createCompatibleImage(w, h, transparency));
 222             }
 223         }
 224     }
 225 
 226     public static class VolatileImg extends Destinations {
 227         private final int transparency;
 228 
 229         public static final String[] ShortNames = {
 230                 "volimg",
 231                 "opqvolimg",
 232                 "bmvolimg",
 233                 "transvolimg",
 234         };
 235 
 236         public static final String[] ShortDescriptions = {
 237                 "Default",
 238                 "Opaque",
 239                 "Bitmask",
 240                 "Translucent",
 241         };
 242 
 243         public static final String[] LongDescriptions = {
 244                 "Default VolatileImg Image",
 245                 "Opaque VolatileImg Image",
 246                 "Bitmask VolatileImg Image",
 247                 "Translucent VolatileImg Image",
 248         };
 249 
 250         public static final String[] ModifierNames = {
 251                 "VolatileImg()",
 252                 "VolatileImg(Opaque)",
 253                 "VolatileImg(Bitmask)",
 254                 "VolatileImg(Translucent)",
 255         };
 256 
 257         public VolatileImg() {
 258             this(0);
 259         }
 260 
 261         public VolatileImg(final int transparency) {
 262             super(volimgdestroot,
 263                   ShortNames[transparency],
 264                   ShortDescriptions[transparency],
 265                   false);
 266             this.transparency = transparency;
 267         }
 268 
 269         public String getModifierValueName(final Object val) {
 270             return ModifierNames[transparency];
 271         }
 272 
 273         public void setDestination(final TestEnvironment env) {
 274             Component c = env.getCanvas();
 275             GraphicsConfiguration gc = c.getGraphicsConfiguration();
 276             int w = env.getWidth();
 277             int h = env.getHeight();
 278             if (transparency == 0) {
 279                 env.setTestImage(gc.createCompatibleVolatileImage(w, h));
 280             } else {
 281                 env.setTestImage(gc.createCompatibleVolatileImage(w, h, transparency));
 282             }
 283         }
 284     }
 285 
 286 
 287     public static class BufImg extends Destinations {
 288         int type;
 289         Image img;
 290 
 291         public static String ShortNames[] = {
 292             "custom",
 293             "IntXrgb",
 294             "IntArgb",
 295             "IntArgbPre",
 296             "IntXbgr",
 297             "3ByteBgr",
 298             "4ByteAbgr",
 299             "4ByteAbgrPre",
 300             "Short565",
 301             "Short555",
 302             "ByteGray",