author | tdv |
Tue, 22 Jul 2008 11:24:32 -0700 | |
changeset 888 | c7009cf0001f |
parent 887 | 0aab8d3fa11a |
child 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
2 | 1 |
/* |
888
c7009cf0001f
6728492: typo in copyrights in some files touched by the d3d pipeline port
tdv
parents:
887
diff
changeset
|
2 |
* Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
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. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
package sun.awt.image; |
|
27 |
||
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; |
|
37 |
||
887 | 38 |
import sun.java2d.StateTrackable.State; |
2 | 39 |
import sun.java2d.SurfaceData; |
40 |
import sun.java2d.StateTrackableDelegate; |
|
41 |
||
42 |
/** |
|
43 |
* This class exists as a middle layer between WritableRaster and its |
|
44 |
* implementation specific subclasses (ByteComponentRaster, ShortBandedRaster, |
|
45 |
* etc). |
|
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. |
|
49 |
*/ |
|
50 |
public class SunWritableRaster extends WritableRaster { |
|
51 |
private static DataStealer stealer; |
|
52 |
||
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); |
|
887 | 58 |
public void setTrackable(DataBuffer db, StateTrackableDelegate trackable); |
2 | 59 |
} |
60 |
||
61 |
public static void setDataStealer(DataStealer ds) { |
|
62 |
if (stealer != null) { |
|
63 |
throw new InternalError("Attempt to set DataStealer twice"); |
|
64 |
} |
|
65 |
stealer = ds; |
|
66 |
} |
|
67 |
||
68 |
public static byte[] stealData(DataBufferByte dbb, int bank) { |
|
69 |
return stealer.getData(dbb, bank); |
|
70 |
} |
|
71 |
||
72 |
public static short[] stealData(DataBufferUShort dbus, int bank) { |
|
73 |
return stealer.getData(dbus, bank); |
|
74 |
} |
|
75 |
||
76 |
public static int[] stealData(DataBufferInt dbi, int bank) { |
|
77 |
return stealer.getData(dbi, bank); |
|
78 |
} |
|
79 |
||
80 |
public static StateTrackableDelegate stealTrackable(DataBuffer db) { |
|
81 |
return stealer.getTrackable(db); |
|
82 |
} |
|
83 |
||
887 | 84 |
public static void setTrackable(DataBuffer db, StateTrackableDelegate trackable) { |
85 |
stealer.setTrackable(db, trackable); |
|
86 |
} |
|
87 |
||
88 |
public static void makeTrackable(DataBuffer db) { |
|
89 |
stealer.setTrackable(db, StateTrackableDelegate.createInstance(State.STABLE)); |
|
90 |
} |
|
91 |
||
2 | 92 |
public static void markDirty(DataBuffer db) { |
93 |
stealer.getTrackable(db).markDirty(); |
|
94 |
} |
|
95 |
||
96 |
public static void markDirty(WritableRaster wr) { |
|
97 |
if (wr instanceof SunWritableRaster) { |
|
98 |
((SunWritableRaster) wr).markDirty(); |
|
99 |
} else { |
|
100 |
markDirty(wr.getDataBuffer()); |
|
101 |
} |
|
102 |
} |
|
103 |
||
104 |
public static void markDirty(Image img) { |
|
105 |
SurfaceData.getPrimarySurfaceData(img).markDirty(); |
|
106 |
} |
|
107 |
||
108 |
private StateTrackableDelegate theTrackable; |
|
109 |
||
110 |
public SunWritableRaster(SampleModel sampleModel, Point origin) { |
|
111 |
super(sampleModel, origin); |
|
112 |
theTrackable = stealTrackable(dataBuffer); |
|
113 |
} |
|
114 |
||
115 |
public SunWritableRaster(SampleModel sampleModel, |
|
116 |
DataBuffer dataBuffer, |
|
117 |
Point origin) |
|
118 |
{ |
|
119 |
super(sampleModel, dataBuffer, origin); |
|
120 |
theTrackable = stealTrackable(dataBuffer); |
|
121 |
} |
|
122 |
||
123 |
public SunWritableRaster(SampleModel sampleModel, |
|
124 |
DataBuffer dataBuffer, |
|
125 |
Rectangle aRegion, |
|
126 |
Point sampleModelTranslate, |
|
127 |
WritableRaster parent) |
|
128 |
{ |
|
129 |
super(sampleModel, dataBuffer, aRegion, sampleModelTranslate, parent); |
|
130 |
theTrackable = stealTrackable(dataBuffer); |
|
131 |
} |
|
132 |
||
133 |
/** |
|
134 |
* Mark the TrackableDelegate of the associated DataBuffer dirty. |
|
135 |
*/ |
|
136 |
public final void markDirty() { |
|
137 |
theTrackable.markDirty(); |
|
138 |
} |
|
139 |
} |