001: /*
002: * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.awt.image;
027:
028: import java.awt.Point;
029: import java.awt.Rectangle;
030: import java.awt.Image;
031: import java.awt.image.DataBuffer;
032: import java.awt.image.DataBufferByte;
033: import java.awt.image.DataBufferUShort;
034: import java.awt.image.DataBufferInt;
035: import java.awt.image.SampleModel;
036: import java.awt.image.WritableRaster;
037:
038: import sun.java2d.SurfaceData;
039: import sun.java2d.StateTrackableDelegate;
040:
041: /**
042: * This class exists as a middle layer between WritableRaster and its
043: * implementation specific subclasses (ByteComponentRaster, ShortBandedRaster,
044: * etc).
045: * It provides utilities to steal the data arrays from the standard DataBuffer
046: * types and also steals the StateTrackableDelegate from the associated
047: * DataBuffer so that it can be updated when the data is changed.
048: */
049: public class SunWritableRaster extends WritableRaster {
050: private static DataStealer stealer;
051:
052: public static interface DataStealer {
053: public byte[] getData(DataBufferByte dbb, int bank);
054:
055: public short[] getData(DataBufferUShort dbus, int bank);
056:
057: public int[] getData(DataBufferInt dbi, int bank);
058:
059: public StateTrackableDelegate getTrackable(DataBuffer db);
060: }
061:
062: public static void setDataStealer(DataStealer ds) {
063: if (stealer != null) {
064: throw new InternalError("Attempt to set DataStealer twice");
065: }
066: stealer = ds;
067: }
068:
069: public static byte[] stealData(DataBufferByte dbb, int bank) {
070: return stealer.getData(dbb, bank);
071: }
072:
073: public static short[] stealData(DataBufferUShort dbus, int bank) {
074: return stealer.getData(dbus, bank);
075: }
076:
077: public static int[] stealData(DataBufferInt dbi, int bank) {
078: return stealer.getData(dbi, bank);
079: }
080:
081: public static StateTrackableDelegate stealTrackable(DataBuffer db) {
082: return stealer.getTrackable(db);
083: }
084:
085: public static void markDirty(DataBuffer db) {
086: stealer.getTrackable(db).markDirty();
087: }
088:
089: public static void markDirty(WritableRaster wr) {
090: if (wr instanceof SunWritableRaster) {
091: ((SunWritableRaster) wr).markDirty();
092: } else {
093: markDirty(wr.getDataBuffer());
094: }
095: }
096:
097: public static void markDirty(Image img) {
098: SurfaceData.getPrimarySurfaceData(img).markDirty();
099: }
100:
101: private StateTrackableDelegate theTrackable;
102:
103: public SunWritableRaster(SampleModel sampleModel, Point origin) {
104: super (sampleModel, origin);
105: theTrackable = stealTrackable(dataBuffer);
106: }
107:
108: public SunWritableRaster(SampleModel sampleModel,
109: DataBuffer dataBuffer, Point origin) {
110: super (sampleModel, dataBuffer, origin);
111: theTrackable = stealTrackable(dataBuffer);
112: }
113:
114: public SunWritableRaster(SampleModel sampleModel,
115: DataBuffer dataBuffer, Rectangle aRegion,
116: Point sampleModelTranslate, WritableRaster parent) {
117: super (sampleModel, dataBuffer, aRegion, sampleModelTranslate,
118: parent);
119: theTrackable = stealTrackable(dataBuffer);
120: }
121:
122: /**
123: * Mark the TrackableDelegate of the associated DataBuffer dirty.
124: */
125: public final void markDirty() {
126: theTrackable.markDirty();
127: }
128: }
|