Print this page
Added gradle and cmake project
Split |
Close |
Expand all |
Collapse all |
--- old/src/java.desktop/share/classes/sun/java2d/loops/Blit.java
+++ new/src/java.desktop/share/classes/sun/java2d/loops/Blit.java
1 1 /*
2 2 * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation. Oracle designates this
8 8 * particular file as subject to the "Classpath" exception as provided
9 9 * by Oracle in the LICENSE file that accompanied this code.
10 10 *
11 11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 14 * version 2 for more details (a copy is included in the LICENSE file that
15 15 * accompanied this code).
16 16 *
17 17 * You should have received a copy of the GNU General Public License version
18 18 * 2 along with this work; if not, write to the Free Software Foundation,
19 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 20 *
21 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 22 * or visit www.oracle.com if you need additional information or have any
23 23 * questions.
24 24 */
25 25
26 26 package sun.java2d.loops;
27 27
28 28 import java.awt.Composite;
29 29 import java.awt.CompositeContext;
30 30 import java.awt.RenderingHints;
31 31 import java.awt.image.ColorModel;
32 32 import java.awt.image.Raster;
33 33 import java.awt.image.WritableRaster;
34 34 import java.lang.ref.WeakReference;
35 35 import sun.java2d.loops.GraphicsPrimitive;
36 36 import sun.java2d.SurfaceData;
37 37 import sun.java2d.pipe.Region;
38 38 import sun.java2d.pipe.SpanIterator;
39 39
40 40 /**
41 41 * Blit
42 42 * 1) copies rectangle of pixels from one surface to another
43 43 * 2) performs compositing of colors based upon a Composite
44 44 * parameter
45 45 *
46 46 * precise behavior is undefined if the source surface
47 47 * and the destination surface are the same surface
48 48 * with overlapping regions of pixels
49 49 */
50 50
51 51 public class Blit extends GraphicsPrimitive
52 52 {
53 53 public static final String methodSignature = "Blit(...)".toString();
54 54
55 55 public static final int primTypeID = makePrimTypeID();
56 56
57 57 private static RenderCache blitcache = new RenderCache(20);
58 58
59 59 public static Blit locate(SurfaceType srctype,
60 60 CompositeType comptype,
61 61 SurfaceType dsttype)
62 62 {
63 63 return (Blit)
64 64 GraphicsPrimitiveMgr.locate(primTypeID,
65 65 srctype, comptype, dsttype);
66 66 }
67 67
68 68 public static Blit getFromCache(SurfaceType src,
69 69 CompositeType comp,
70 70 SurfaceType dst)
71 71 {
72 72 Object o = blitcache.get(src, comp, dst);
73 73 if (o != null) {
74 74 return (Blit) o;
75 75 }
76 76
77 77 Blit blit = locate(src, comp, dst);
78 78 if (blit == null) {
79 79 System.out.println("blit loop not found for:");
80 80 System.out.println("src: "+src);
81 81 System.out.println("comp: "+comp);
82 82 System.out.println("dst: "+dst);
83 83 } else {
84 84 blitcache.put(src, comp, dst, blit);
85 85 }
86 86 return blit;
87 87 }
88 88
89 89 protected Blit(SurfaceType srctype,
90 90 CompositeType comptype,
91 91 SurfaceType dsttype)
92 92 {
93 93 super(methodSignature, primTypeID, srctype, comptype, dsttype);
94 94 }
95 95
96 96 public Blit(long pNativePrim,
97 97 SurfaceType srctype,
98 98 CompositeType comptype,
99 99 SurfaceType dsttype)
100 100 {
101 101 super(pNativePrim, methodSignature, primTypeID, srctype, comptype, dsttype);
102 102 }
103 103
104 104 /**
105 105 * All Blit implementors must have this invoker method
106 106 */
107 107 public native void Blit(SurfaceData src, SurfaceData dst,
108 108 Composite comp, Region clip,
109 109 int srcx, int srcy,
110 110 int dstx, int dsty,
111 111 int width, int height);
112 112
113 113 static {
114 114 GraphicsPrimitiveMgr.registerGeneral(new Blit(null, null, null));
115 115 }
116 116
117 117 public GraphicsPrimitive makePrimitive(SurfaceType srctype,
118 118 CompositeType comptype,
119 119 SurfaceType dsttype)
120 120 {
121 121 /*
122 122 System.out.println("Constructing general blit for:");
123 123 System.out.println("src: "+srctype);
124 124 System.out.println("comp: "+comptype);
125 125 System.out.println("dst: "+dsttype);
126 126 */
127 127
128 128 if (comptype.isDerivedFrom(CompositeType.Xor)) {
129 129 GeneralXorBlit gxb = new GeneralXorBlit(srctype,
130 130 comptype,
131 131 dsttype);
132 132 setupGeneralBinaryOp(gxb);
133 133 return gxb;
134 134 } else if (comptype.isDerivedFrom(CompositeType.AnyAlpha)) {
135 135 return new GeneralMaskBlit(srctype, comptype, dsttype);
136 136 } else {
137 137 return AnyBlit.instance;
138 138 }
139 139 }
140 140
141 141 private static class AnyBlit extends Blit {
142 142 public static AnyBlit instance = new AnyBlit();
143 143
144 144 public AnyBlit() {
145 145 super(SurfaceType.Any, CompositeType.Any, SurfaceType.Any);
146 146 }
147 147
148 148 public void Blit(SurfaceData srcData,
149 149 SurfaceData dstData,
150 150 Composite comp,
151 151 Region clip,
152 152 int srcx, int srcy,
153 153 int dstx, int dsty,
154 154 int width, int height)
155 155 {
156 156 ColorModel srcCM = srcData.getColorModel();
157 157 ColorModel dstCM = dstData.getColorModel();
158 158 // REMIND: Should get RenderingHints from sg2d
159 159 CompositeContext ctx = comp.createContext(srcCM, dstCM,
160 160 new RenderingHints(null));
161 161 Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
162 162 WritableRaster dstRas =
163 163 (WritableRaster) dstData.getRaster(dstx, dsty, width, height);
164 164
165 165 if (clip == null) {
166 166 clip = Region.getInstanceXYWH(dstx, dsty, width, height);
167 167 }
168 168 int[] span = {dstx, dsty, dstx+width, dsty+height};
169 169 SpanIterator si = clip.getSpanIterator(span);
170 170 srcx -= dstx;
171 171 srcy -= dsty;
172 172 while (si.nextSpan(span)) {
173 173 int w = span[2] - span[0];
174 174 int h = span[3] - span[1];
175 175 Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
176 176 w, h, 0, 0, null);
177 177 WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
178 178 w, h, 0, 0, null);
179 179 ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
180 180 }
181 181 ctx.dispose();
182 182 }
183 183 }
184 184
185 185 private static class GeneralMaskBlit extends Blit {
186 186 MaskBlit performop;
187 187
188 188 public GeneralMaskBlit(SurfaceType srctype,
189 189 CompositeType comptype,
190 190 SurfaceType dsttype)
191 191 {
192 192 super(srctype, comptype, dsttype);
193 193 performop = MaskBlit.locate(srctype, comptype, dsttype);
194 194 }
195 195
196 196 public void Blit(SurfaceData srcData,
197 197 SurfaceData dstData,
198 198 Composite comp,
199 199 Region clip,
200 200 int srcx, int srcy,
201 201 int dstx, int dsty,
202 202 int width, int height)
203 203 {
204 204 performop.MaskBlit(srcData, dstData, comp, clip,
205 205 srcx, srcy, dstx, dsty,
206 206 width, height,
207 207 null, 0, 0);
208 208 }
209 209 }
210 210
211 211 private static class GeneralXorBlit
212 212 extends Blit
213 213 implements GeneralBinaryOp
214 214 {
215 215 Blit convertsrc;
216 216 Blit convertdst;
217 217 Blit performop;
218 218 Blit convertresult;
219 219
220 220 WeakReference<SurfaceData> srcTmp;
221 221 WeakReference<SurfaceData> dstTmp;
222 222
223 223 public GeneralXorBlit(SurfaceType srctype,
224 224 CompositeType comptype,
225 225 SurfaceType dsttype)
226 226 {
227 227 super(srctype, comptype, dsttype);
228 228 }
229 229
230 230 public void setPrimitives(Blit srcconverter,
231 231 Blit dstconverter,
232 232 GraphicsPrimitive genericop,
233 233 Blit resconverter)
234 234 {
235 235 this.convertsrc = srcconverter;
236 236 this.convertdst = dstconverter;
237 237 this.performop = (Blit) genericop;
238 238 this.convertresult = resconverter;
239 239 }
240 240
241 241 public synchronized void Blit(SurfaceData srcData,
242 242 SurfaceData dstData,
243 243 Composite comp,
244 244 Region clip,
245 245 int srcx, int srcy,
246 246 int dstx, int dsty,
247 247 int width, int height)
248 248 {
249 249 SurfaceData src, dst;
250 250 Region opclip;
251 251 int sx, sy, dx, dy;
252 252
253 253 if (convertsrc == null) {
254 254 src = srcData;
255 255 sx = srcx;
256 256 sy = srcy;
257 257 } else {
258 258 SurfaceData cachedSrc = null;
259 259 if (srcTmp != null) {
260 260 cachedSrc = srcTmp.get();
261 261 }
262 262 src = convertFrom(convertsrc, srcData, srcx, srcy,
263 263 width, height, cachedSrc);
264 264 sx = 0;
265 265 sy = 0;
266 266 if (src != cachedSrc) {
267 267 srcTmp = new WeakReference<>(src);
268 268 }
269 269 }
270 270
271 271 if (convertdst == null) {
272 272 dst = dstData;
273 273 dx = dstx;
274 274 dy = dsty;
275 275 opclip = clip;
276 276 } else {
277 277 // assert: convertresult != null
278 278 SurfaceData cachedDst = null;
279 279 if (dstTmp != null) {
280 280 cachedDst = dstTmp.get();
281 281 }
282 282 dst = convertFrom(convertdst, dstData, dstx, dsty,
283 283 width, height, cachedDst);
284 284 dx = 0;
285 285 dy = 0;
286 286 opclip = null;
287 287 if (dst != cachedDst) {
288 288 dstTmp = new WeakReference<>(dst);
289 289 }
290 290 }
291 291
292 292 performop.Blit(src, dst, comp, opclip,
293 293 sx, sy, dx, dy,
294 294 width, height);
295 295
296 296 if (convertresult != null) {
297 297 // assert: convertdst != null
298 298 convertTo(convertresult, dst, dstData, clip,
299 299 dstx, dsty, width, height);
300 300 }
301 301 }
302 302 }
303 303
304 304 public GraphicsPrimitive traceWrap() {
305 305 return new TraceBlit(this);
306 306 }
307 307
308 308 private static class TraceBlit extends Blit {
309 309 Blit target;
310 310
311 311 public TraceBlit(Blit target) {
312 312 super(target.getSourceType(),
313 313 target.getCompositeType(),
314 314 target.getDestType());
315 315 this.target = target;
316 316 }
↓ open down ↓ |
316 lines elided |
↑ open up ↑ |
317 317
318 318 public GraphicsPrimitive traceWrap() {
319 319 return this;
320 320 }
321 321
322 322 public void Blit(SurfaceData src, SurfaceData dst,
323 323 Composite comp, Region clip,
324 324 int srcx, int srcy, int dstx, int dsty,
325 325 int width, int height)
326 326 {
327 - tracePrimitive(target);
327 + if ((traceflags & TRACEPTIME) == 0) {
328 + tracePrimitive(target);
329 + }
330 + long time = System.nanoTime();
328 331 target.Blit(src, dst, comp, clip,
329 332 srcx, srcy, dstx, dsty, width, height);
333 + tracePrimitiveTime(target, System.nanoTime() - time);
330 334 }
331 335 }
332 336 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX