META-INF.modules.java.desktop.classes.sun.awt.image.SurfaceManager Maven / Gradle / Ivy
Show all versions of java.desktop Show documentation
/*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.awt.image;
import java.awt.Color;
import java.awt.GraphicsEnvironment;
import java.awt.GraphicsConfiguration;
import java.awt.Image;
import java.awt.ImageCapabilities;
import java.awt.image.BufferedImage;
import java.awt.image.VolatileImage;
import java.util.concurrent.ConcurrentHashMap;
import java.util.Iterator;
import sun.java2d.SurfaceData;
import sun.java2d.SurfaceDataProxy;
import sun.java2d.loops.CompositeType;
/**
* The abstract base class that manages the various SurfaceData objects that
* represent an Image's contents. Subclasses can customize how the surfaces
* are organized, whether to cache the original contents in an accelerated
* surface, and so on.
*
* The SurfaceManager also maintains an arbitrary "cache" mechanism which
* allows other agents to store data in it specific to their use of this
* image. The most common use of the caching mechanism is for destination
* SurfaceData objects to store cached copies of the source image.
*/
public abstract class SurfaceManager {
public abstract static class ImageAccessor {
public abstract SurfaceManager getSurfaceManager(Image img);
public abstract void setSurfaceManager(Image img, SurfaceManager mgr);
}
private static ImageAccessor imgaccessor;
public static void setImageAccessor(ImageAccessor ia) {
if (imgaccessor != null) {
throw new InternalError("Attempt to set ImageAccessor twice");
}
imgaccessor = ia;
}
/**
* Returns the SurfaceManager object contained within the given Image.
*/
public static SurfaceManager getManager(Image img) {
SurfaceManager sMgr = imgaccessor.getSurfaceManager(img);
if (sMgr == null) {
/*
* In practice only a BufferedImage will get here.
*/
try {
BufferedImage bi = (BufferedImage) img;
sMgr = new BufImgSurfaceManager(bi);
setManager(bi, sMgr);
} catch (ClassCastException e) {
throw new IllegalArgumentException("Invalid Image variant");
}
}
return sMgr;
}
public static void setManager(Image img, SurfaceManager mgr) {
imgaccessor.setSurfaceManager(img, mgr);
}
private ConcurrentHashMap