Path: blob/master/src/java.desktop/share/classes/sun/java2d/NullSurfaceData.java
41152 views
/*1* Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d;2627import java.awt.Rectangle;28import java.awt.image.Raster;29import java.awt.image.ColorModel;30import java.awt.GraphicsConfiguration;3132import sun.java2d.StateTrackable.State;33import sun.java2d.loops.SurfaceType;34import sun.java2d.pipe.NullPipe;3536/**37* This class provides an empty implementation of the SurfaceData38* abstract superclass. All operations on it translate into NOP39* or harmless operations.40*/41public class NullSurfaceData extends SurfaceData {42public static final SurfaceData theInstance = new NullSurfaceData();4344private NullSurfaceData() {45super(State.IMMUTABLE, SurfaceType.Any, ColorModel.getRGBdefault());46}4748/**49* Sets this SurfaceData object to the invalid state. All Graphics50* objects must get a new SurfaceData object via the refresh method51* and revalidate their pipelines before continuing.52*/53public void invalidate() {54}5556/**57* Return a new SurfaceData object that represents the current state58* of the destination that this SurfaceData object describes.59* This method is typically called when the SurfaceData is invalidated.60*/61public SurfaceData getReplacement() {62return this;63}6465private static final NullPipe nullpipe = new NullPipe();6667public void validatePipe(SunGraphics2D sg2d) {68sg2d.drawpipe = nullpipe;69sg2d.fillpipe = nullpipe;70sg2d.shapepipe = nullpipe;71sg2d.textpipe = nullpipe;72sg2d.imagepipe = nullpipe;73}7475public GraphicsConfiguration getDeviceConfiguration() {76return null;77}7879/**80* Return a readable Raster which contains the pixels for the81* specified rectangular region of the destination surface.82* The coordinate origin of the returned Raster is the same as83* the device space origin of the destination surface.84* In some cases the returned Raster might also be writeable.85* In most cases, the returned Raster might contain more pixels86* than requested.87*88* @see #useTightBBoxes89*/90public Raster getRaster(int x, int y, int w, int h) {91throw new InvalidPipeException("should be NOP");92}9394/**95* Does the pixel accessibility of the destination surface96* suggest that rendering algorithms might want to take97* extra time to calculate a more accurate bounding box for98* the operation being performed?99* The typical case when this will be true is when a copy of100* the pixels has to be made when doing a getRaster. The101* fewer pixels copied, the faster the operation will go.102*103* @see #getRaster104*/105public boolean useTightBBoxes() {106return false;107}108109/**110* Returns the pixel data for the specified Argb value packed111* into an integer for easy storage and conveyance.112*/113public int pixelFor(int rgb) {114return rgb;115}116117/**118* Returns the Argb representation for the specified integer value119* which is packed in the format of the associated ColorModel.120*/121public int rgbFor(int pixel) {122return pixel;123}124125/**126* Returns the bounds of the destination surface.127*/128public Rectangle getBounds() {129return new Rectangle();130}131132/**133* Performs Security Permissions checks to see if a Custom134* Composite object should be allowed access to the pixels135* of this surface.136*/137protected void checkCustomComposite() {138return;139}140141/**142* Performs a copyarea within this surface. Returns143* false if there is no algorithm to perform the copyarea144* given the current settings of the SunGraphics2D.145*/146public boolean copyArea(SunGraphics2D sg2d,147int x, int y, int w, int h, int dx, int dy)148{149return true;150}151152/**153* Returns destination Image associated with this SurfaceData (null)154*/155public Object getDestination() {156return null;157}158}159160161