src/share/classes/sun/awt/image/SurfaceManager.java

Print this page




  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.awt.image;
  27 
  28 import java.awt.Color;
  29 import java.awt.GraphicsEnvironment;
  30 import java.awt.GraphicsConfiguration;
  31 import java.awt.Image;
  32 import java.awt.ImageCapabilities;
  33 import java.awt.image.BufferedImage;

  34 import java.util.concurrent.ConcurrentHashMap;
  35 import java.util.Iterator;
  36 import sun.java2d.SurfaceData;
  37 import sun.java2d.SurfaceDataProxy;
  38 import sun.java2d.loops.CompositeType;
  39 
  40 /**
  41  * The abstract base class that manages the various SurfaceData objects that
  42  * represent an Image's contents.  Subclasses can customize how the surfaces
  43  * are organized, whether to cache the original contents in an accelerated
  44  * surface, and so on.
  45  * <p>
  46  * The SurfaceManager also maintains an arbitrary "cache" mechanism which
  47  * allows other agents to store data in it specific to their use of this
  48  * image.  The most common use of the caching mechanism is for destination
  49  * SurfaceData objects to store cached copies of the source image.
  50  */
  51 public abstract class SurfaceManager {
  52 
  53     public static abstract class ImageAccessor {


 270          * being accelerated (for instance the acceleration priority
 271          * is set below the threshold needed for acceleration).
 272          * Returns a boolean that indicates if the cached object is
 273          * no longer needed and should be removed from the cache.
 274          */
 275         public boolean flush(boolean deaccelerated);
 276     }
 277 
 278     /**
 279      * Called when image's acceleration priority is changed.
 280      * <p>
 281      * The default implementation will visit all of the value objects
 282      * in the cacheMap when the priority gets set to 0.0 and flush them
 283      * if they implement the FlushableCacheData interface.
 284      */
 285     public void setAccelerationPriority(float priority) {
 286         if (priority == 0.0f) {
 287             flush(true);
 288         }
 289     }














 290 }


  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.awt.image;
  27 
  28 import java.awt.Color;
  29 import java.awt.GraphicsEnvironment;
  30 import java.awt.GraphicsConfiguration;
  31 import java.awt.Image;
  32 import java.awt.ImageCapabilities;
  33 import java.awt.image.BufferedImage;
  34 import java.awt.image.VolatileImage;
  35 import java.util.concurrent.ConcurrentHashMap;
  36 import java.util.Iterator;
  37 import sun.java2d.SurfaceData;
  38 import sun.java2d.SurfaceDataProxy;
  39 import sun.java2d.loops.CompositeType;
  40 
  41 /**
  42  * The abstract base class that manages the various SurfaceData objects that
  43  * represent an Image's contents.  Subclasses can customize how the surfaces
  44  * are organized, whether to cache the original contents in an accelerated
  45  * surface, and so on.
  46  * <p>
  47  * The SurfaceManager also maintains an arbitrary "cache" mechanism which
  48  * allows other agents to store data in it specific to their use of this
  49  * image.  The most common use of the caching mechanism is for destination
  50  * SurfaceData objects to store cached copies of the source image.
  51  */
  52 public abstract class SurfaceManager {
  53 
  54     public static abstract class ImageAccessor {


 271          * being accelerated (for instance the acceleration priority
 272          * is set below the threshold needed for acceleration).
 273          * Returns a boolean that indicates if the cached object is
 274          * no longer needed and should be removed from the cache.
 275          */
 276         public boolean flush(boolean deaccelerated);
 277     }
 278 
 279     /**
 280      * Called when image's acceleration priority is changed.
 281      * <p>
 282      * The default implementation will visit all of the value objects
 283      * in the cacheMap when the priority gets set to 0.0 and flush them
 284      * if they implement the FlushableCacheData interface.
 285      */
 286     public void setAccelerationPriority(float priority) {
 287         if (priority == 0.0f) {
 288             flush(true);
 289         }
 290     }
 291 
 292     /**
 293      * Returns a scale factor of the image. This is utility method, which
 294      * fetches information from the SurfaceData of the image.
 295      *
 296      * @see SurfaceData#getDefaultScale
 297      */
 298     public static int getImageScale(final Image img) {
 299         if (!(img instanceof VolatileImage)) {
 300             return 1;
 301         }
 302         final SurfaceManager sm = getManager(img);
 303         return sm.getPrimarySurfaceData().getDefaultScale();
 304     }
 305 }