Print this page
rev 54883 : JDK-8220154 Improve java2d rendering performance on macOS by using Metal framework
Split |
Close |
Expand all |
Collapse all |
--- old/src/java.desktop/share/classes/sun/java2d/loops/MaskBlit.java
+++ new/src/java.desktop/share/classes/sun/java2d/loops/MaskBlit.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.lang.ref.WeakReference;
30 30 import sun.java2d.loops.GraphicsPrimitive;
31 31 import sun.java2d.SurfaceData;
32 32 import sun.java2d.pipe.Region;
33 33
34 34 /**
35 35 * MaskBlit
36 36 * 1) copies rectangle of pixels from one surface to another
37 37 * 2) performs compositing of colors based upon a Composite
38 38 * parameter
39 39 * 3) blends result of composite with destination using an
40 40 * alpha coverage mask
41 41 * 4) the mask may be null in which case it should be treated
42 42 * as if it were an array of all opaque values (0xff)
43 43 *
44 44 * precise behavior is undefined if the source surface
45 45 * and the destination surface are the same surface
46 46 * with overlapping regions of pixels
47 47 */
48 48
49 49 public class MaskBlit extends GraphicsPrimitive
50 50 {
51 51 public static final String methodSignature = "MaskBlit(...)".toString();
52 52
53 53 public static final int primTypeID = makePrimTypeID();
54 54
55 55 private static RenderCache blitcache = new RenderCache(20);
56 56
57 57 public static MaskBlit locate(SurfaceType srctype,
58 58 CompositeType comptype,
59 59 SurfaceType dsttype)
60 60 {
61 61 return (MaskBlit)
62 62 GraphicsPrimitiveMgr.locate(primTypeID,
63 63 srctype, comptype, dsttype);
64 64 }
65 65
66 66 public static MaskBlit getFromCache(SurfaceType src,
67 67 CompositeType comp,
68 68 SurfaceType dst)
69 69 {
70 70 Object o = blitcache.get(src, comp, dst);
71 71 if (o != null) {
72 72 return (MaskBlit) o;
73 73 }
74 74 MaskBlit blit = locate(src, comp, dst);
75 75 if (blit == null) {
76 76 System.out.println("mask blit loop not found for:");
77 77 System.out.println("src: "+src);
78 78 System.out.println("comp: "+comp);
79 79 System.out.println("dst: "+dst);
80 80 } else {
81 81 blitcache.put(src, comp, dst, blit);
82 82 }
83 83 return blit;
84 84 }
85 85
86 86 protected MaskBlit(SurfaceType srctype,
87 87 CompositeType comptype,
88 88 SurfaceType dsttype)
89 89 {
90 90 super(methodSignature, primTypeID, srctype, comptype, dsttype);
91 91 }
92 92
93 93 public MaskBlit(long pNativePrim,
94 94 SurfaceType srctype,
95 95 CompositeType comptype,
96 96 SurfaceType dsttype)
97 97 {
98 98 super(pNativePrim, methodSignature, primTypeID, srctype, comptype, dsttype);
99 99 }
100 100
101 101 /**
102 102 * All MaskBlit implementors must have this invoker method
103 103 */
104 104 public native void MaskBlit(SurfaceData src, SurfaceData dst,
105 105 Composite comp, Region clip,
106 106 int srcx, int srcy,
107 107 int dstx, int dsty,
108 108 int width, int height,
109 109 byte[] mask, int maskoff, int maskscan);
110 110
111 111 static {
112 112 GraphicsPrimitiveMgr.registerGeneral(new MaskBlit(null, null, null));
113 113 }
114 114
115 115 public GraphicsPrimitive makePrimitive(SurfaceType srctype,
116 116 CompositeType comptype,
117 117 SurfaceType dsttype)
118 118 {
119 119 /*
120 120 new Throwable().printStackTrace();
121 121 System.out.println("Constructing general maskblit for:");
122 122 System.out.println("src: "+srctype);
123 123 System.out.println("comp: "+comptype);
124 124 System.out.println("dst: "+dsttype);
125 125 */
126 126
127 127 if (CompositeType.Xor.equals(comptype)) {
128 128 throw new InternalError("Cannot construct MaskBlit for " +
129 129 "XOR mode");
130 130 }
131 131
132 132 General ob = new General(srctype, comptype, dsttype);
133 133 setupGeneralBinaryOp(ob);
134 134 return ob;
135 135 }
136 136
137 137 private static class General
138 138 extends MaskBlit
139 139 implements GeneralBinaryOp
140 140 {
141 141 Blit convertsrc;
142 142 Blit convertdst;
143 143 MaskBlit performop;
144 144 Blit convertresult;
145 145
146 146 WeakReference<SurfaceData> srcTmp;
147 147 WeakReference<SurfaceData> dstTmp;
148 148
149 149 public General(SurfaceType srctype,
150 150 CompositeType comptype,
151 151 SurfaceType dsttype)
152 152 {
153 153 super(srctype, comptype, dsttype);
154 154 }
155 155
156 156 public void setPrimitives(Blit srcconverter,
157 157 Blit dstconverter,
158 158 GraphicsPrimitive genericop,
159 159 Blit resconverter)
160 160 {
161 161 this.convertsrc = srcconverter;
162 162 this.convertdst = dstconverter;
163 163 this.performop = (MaskBlit) genericop;
164 164 this.convertresult = resconverter;
165 165 }
166 166
167 167 public synchronized void MaskBlit(SurfaceData srcData,
168 168 SurfaceData dstData,
169 169 Composite comp,
170 170 Region clip,
171 171 int srcx, int srcy,
172 172 int dstx, int dsty,
173 173 int width, int height,
174 174 byte[] mask, int offset, int scan)
175 175 {
176 176 SurfaceData src, dst;
177 177 Region opclip;
178 178 int sx, sy, dx, dy;
179 179
180 180 if (convertsrc == null) {
181 181 src = srcData;
182 182 sx = srcx;
183 183 sy = srcy;
184 184 } else {
185 185 SurfaceData cachedSrc = null;
186 186 if (srcTmp != null) {
187 187 cachedSrc = srcTmp.get();
188 188 }
189 189 src = convertFrom(convertsrc, srcData, srcx, srcy,
190 190 width, height, cachedSrc);
191 191 sx = 0;
192 192 sy = 0;
193 193 if (src != cachedSrc) {
194 194 srcTmp = new WeakReference<>(src);
195 195 }
196 196 }
197 197
198 198 if (convertdst == null) {
199 199 dst = dstData;
200 200 dx = dstx;
201 201 dy = dsty;
202 202 opclip = clip;
203 203 } else {
204 204 // assert: convertresult != null
205 205 SurfaceData cachedDst = null;
206 206 if (dstTmp != null) {
207 207 cachedDst = dstTmp.get();
208 208 }
209 209 dst = convertFrom(convertdst, dstData, dstx, dsty,
210 210 width, height, cachedDst);
211 211 dx = 0;
212 212 dy = 0;
213 213 opclip = null;
214 214 if (dst != cachedDst) {
215 215 dstTmp = new WeakReference<>(dst);
216 216 }
217 217 }
218 218
219 219 performop.MaskBlit(src, dst, comp, opclip,
220 220 sx, sy, dx, dy, width, height,
221 221 mask, offset, scan);
222 222
223 223 if (convertresult != null) {
224 224 // assert: convertdst != null
225 225 convertTo(convertresult, dst, dstData, clip,
226 226 dstx, dsty, width, height);
227 227 }
228 228 }
229 229 }
230 230
231 231 public GraphicsPrimitive traceWrap() {
232 232 return new TraceMaskBlit(this);
233 233 }
234 234
235 235 private static class TraceMaskBlit extends MaskBlit {
236 236 MaskBlit target;
237 237
238 238 public TraceMaskBlit(MaskBlit target) {
239 239 // We need to have the same NativePrim as our
240 240 // target in case we are used with a TransformHelper
241 241 super(target.getNativePrim(),
242 242 target.getSourceType(),
243 243 target.getCompositeType(),
244 244 target.getDestType());
245 245 this.target = target;
246 246 }
247 247
↓ open down ↓ |
247 lines elided |
↑ open up ↑ |
248 248 public GraphicsPrimitive traceWrap() {
249 249 return this;
250 250 }
251 251
252 252 public void MaskBlit(SurfaceData src, SurfaceData dst,
253 253 Composite comp, Region clip,
254 254 int srcx, int srcy, int dstx, int dsty,
255 255 int width, int height,
256 256 byte[] mask, int maskoff, int maskscan)
257 257 {
258 - tracePrimitive(target);
258 + if ((traceflags & TRACEPTIME) == 0) {
259 + tracePrimitive(target);
260 + }
261 + long time = System.nanoTime();
259 262 target.MaskBlit(src, dst, comp, clip,
260 263 srcx, srcy, dstx, dsty, width, height,
261 264 mask, maskoff, maskscan);
265 + tracePrimitiveTime(target, System.nanoTime() - time);
262 266 }
263 267 }
264 268 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX