2
* Copyright (c) 2001, 2007, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
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).
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.
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
26
package sun.awt.image;
28
import java.awt.Point;
29
import java.awt.Rectangle;
30
import java.awt.Image;
31
import java.awt.image.DataBuffer;
32
import java.awt.image.DataBufferByte;
33
import java.awt.image.DataBufferUShort;
34
import java.awt.image.DataBufferInt;
35
import java.awt.image.SampleModel;
36
import java.awt.image.WritableRaster;
38
import sun.java2d.StateTrackable.State;
39
//import sun.java2d.SurfaceData;
40
import sun.java2d.StateTrackableDelegate;
43
* This class exists as a middle layer between WritableRaster and its
44
* implementation specific subclasses (ByteComponentRaster, ShortBandedRaster,
46
* It provides utilities to steal the data arrays from the standard DataBuffer
47
* types and also steals the StateTrackableDelegate from the associated
48
* DataBuffer so that it can be updated when the data is changed.
50
public class SunWritableRaster extends WritableRaster {
51
private static DataStealer stealer;
53
public static interface DataStealer {
54
public byte[] getData(DataBufferByte dbb, int bank);
55
public short[] getData(DataBufferUShort dbus, int bank);
56
public int[] getData(DataBufferInt dbi, int bank);
57
public StateTrackableDelegate getTrackable(DataBuffer db);
58
public void setTrackable(DataBuffer db, StateTrackableDelegate trackable);
61
public static void setDataStealer(DataStealer ds) {
62
if (stealer != null) {
63
throw new InternalError("Attempt to set DataStealer twice");
68
public static byte[] stealData(DataBufferByte dbb, int bank) {
69
return stealer.getData(dbb, bank);
72
public static short[] stealData(DataBufferUShort dbus, int bank) {
73
return stealer.getData(dbus, bank);
76
public static int[] stealData(DataBufferInt dbi, int bank) {
77
return stealer.getData(dbi, bank);
80
public static StateTrackableDelegate stealTrackable(DataBuffer db) {
81
return stealer.getTrackable(db);
84
public static void markDirty(DataBuffer db) {
85
stealer.getTrackable(db).markDirty();
88
public static void setTrackable(DataBuffer db, StateTrackableDelegate trackable) {
89
stealer.setTrackable(db, trackable);
92
public static void makeTrackable(DataBuffer db) {
93
stealer.setTrackable(db, StateTrackableDelegate.createInstance(State.STABLE));
96
public static void markDirty(WritableRaster wr) {
97
if (wr instanceof SunWritableRaster) {
98
((SunWritableRaster) wr).markDirty();
100
markDirty(wr.getDataBuffer());
104
public static void markDirty(Image img) {
105
// SurfaceData.getPrimarySurfaceData(img).markDirty();
108
private StateTrackableDelegate theTrackable;
110
public SunWritableRaster(SampleModel sampleModel, Point origin) {
111
super(sampleModel, origin);
112
theTrackable = stealTrackable(dataBuffer);
115
public SunWritableRaster(SampleModel sampleModel,
116
DataBuffer dataBuffer,
119
super(sampleModel, dataBuffer, origin);
120
theTrackable = stealTrackable(dataBuffer);
123
public SunWritableRaster(SampleModel sampleModel,
124
DataBuffer dataBuffer,
126
Point sampleModelTranslate,
127
WritableRaster parent)
129
super(sampleModel, dataBuffer, aRegion, sampleModelTranslate, parent);
130
theTrackable = stealTrackable(dataBuffer);
134
* Mark the TrackableDelegate of the associated DataBuffer dirty.
136
public final void markDirty() {
137
theTrackable.markDirty();