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

Print this page




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  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 {
  55         public abstract SurfaceManager getSurfaceManager(Image img);
  56         public abstract void setSurfaceManager(Image img, SurfaceManager mgr);
  57     }
  58 
  59     private static ImageAccessor imgaccessor;


 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 }


   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  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.GraphicsEnvironment;
  29 import java.awt.GraphicsConfiguration;
  30 import java.awt.Image;
  31 import java.awt.ImageCapabilities;
  32 import java.awt.image.BufferedImage;
  33 import java.awt.image.VolatileImage;
  34 import java.util.concurrent.ConcurrentHashMap;
  35 import java.util.Iterator;
  36 import sun.java2d.SurfaceData;
  37 import sun.java2d.SurfaceDataProxy;

  38 
  39 /**
  40  * The abstract base class that manages the various SurfaceData objects that
  41  * represent an Image's contents.  Subclasses can customize how the surfaces
  42  * are organized, whether to cache the original contents in an accelerated
  43  * surface, and so on.
  44  * <p>
  45  * The SurfaceManager also maintains an arbitrary "cache" mechanism which
  46  * allows other agents to store data in it specific to their use of this
  47  * image.  The most common use of the caching mechanism is for destination
  48  * SurfaceData objects to store cached copies of the source image.
  49  */
  50 public abstract class SurfaceManager {
  51 
  52     public static abstract class ImageAccessor {
  53         public abstract SurfaceManager getSurfaceManager(Image img);
  54         public abstract void setSurfaceManager(Image img, SurfaceManager mgr);
  55     }
  56 
  57     private static ImageAccessor imgaccessor;


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