Print this page
Added gradle and cmake project
Split |
Close |
Expand all |
Collapse all |
--- old/src/java.desktop/share/classes/sun/java2d/loops/GraphicsPrimitiveMgr.java
+++ new/src/java.desktop/share/classes/sun/java2d/loops/GraphicsPrimitiveMgr.java
1 1 /*
2 2 * Copyright (c) 1997, 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 /*
27 27 * @author Charlton Innovations, Inc.
28 28 */
29 29
30 30 package sun.java2d.loops;
31 31
32 32 import java.util.Comparator;
33 33 import java.util.Arrays;
34 34 import sun.java2d.SunGraphics2D;
35 35
36 36 /**
37 37 * GraphicsComponentMgr provides services to
38 38 * 1. register primitives for later use
39 39 * 2. locate an instance of a primitve based on characteristics
40 40 */
41 41 public final class GraphicsPrimitiveMgr {
42 42
43 43 private static final boolean debugTrace = false;
↓ open down ↓ |
43 lines elided |
↑ open up ↑ |
44 44 private static GraphicsPrimitive[] primitives;
45 45 private static GraphicsPrimitive[] generalPrimitives;
46 46 private static boolean needssort = true;
47 47
48 48 private static native void initIDs(Class<?> GP, Class<?> ST, Class<?> CT,
49 49 Class<?> SG2D, Class<?> Color, Class<?> AT,
50 50 Class<?> XORComp, Class<?> AlphaComp,
51 51 Class<?> Path2D, Class<?> Path2DFloat,
52 52 Class<?> SHints);
53 53 private static native void registerNativeLoops();
54 + static native void setTraceFlags(int traceflags);
54 55
55 56 static {
56 57 initIDs(GraphicsPrimitive.class,
57 58 SurfaceType.class,
58 59 CompositeType.class,
59 60 SunGraphics2D.class,
60 61 java.awt.Color.class,
61 62 java.awt.geom.AffineTransform.class,
62 63 XORComposite.class,
63 64 java.awt.AlphaComposite.class,
64 65 java.awt.geom.Path2D.class,
65 66 java.awt.geom.Path2D.Float.class,
66 67 sun.awt.SunHints.class);
67 68 CustomComponent.register();
68 69 GeneralRenderer.register();
69 70 registerNativeLoops();
70 71 }
71 72
72 73 private static class PrimitiveSpec {
73 74 public int uniqueID;
74 75 }
75 76
76 77 private static Comparator<GraphicsPrimitive> primSorter =
77 78 new Comparator<GraphicsPrimitive>() {
78 79 public int compare(GraphicsPrimitive o1, GraphicsPrimitive o2) {
79 80 int id1 = o1.getUniqueID();
80 81 int id2 = o2.getUniqueID();
81 82
82 83 return (id1 == id2 ? 0 : (id1 < id2 ? -1 : 1));
83 84 }
84 85 };
85 86
86 87 private static Comparator<Object> primFinder = new Comparator<Object>() {
87 88 public int compare(Object o1, Object o2) {
88 89 int id1 = ((GraphicsPrimitive) o1).getUniqueID();
89 90 int id2 = ((PrimitiveSpec) o2).uniqueID;
90 91
91 92 return (id1 == id2 ? 0 : (id1 < id2 ? -1 : 1));
92 93 }
93 94 };
94 95
95 96 /**
96 97 * Ensure that noone can instantiate this class.
97 98 */
98 99 private GraphicsPrimitiveMgr() {
99 100 }
100 101
101 102 public static synchronized void register(GraphicsPrimitive[] newPrimitives)
102 103 {
103 104 GraphicsPrimitive[] devCollection = primitives;
104 105 int oldSize = 0;
105 106 int newSize = newPrimitives.length;
106 107 if (debugTrace) {
107 108 writeLog("Registering " + newSize + " primitives");
108 109 for (int i = 0; i < newSize; i++) {
109 110 writeLog(newPrimitives[i].toString());
110 111 }
111 112 }
112 113 if (devCollection != null) {
113 114 oldSize = devCollection.length;
114 115 }
115 116 GraphicsPrimitive[] temp = new GraphicsPrimitive[oldSize + newSize];
116 117 if (devCollection != null) {
117 118 System.arraycopy(devCollection, 0, temp, 0, oldSize);
118 119 }
119 120 System.arraycopy(newPrimitives, 0, temp, oldSize, newSize);
120 121 needssort = true;
121 122 primitives = temp;
122 123 }
123 124
124 125 public static synchronized void registerGeneral(GraphicsPrimitive gen) {
125 126 if (generalPrimitives == null) {
126 127 generalPrimitives = new GraphicsPrimitive[] {gen};
127 128 return;
128 129 }
129 130 int len = generalPrimitives.length;
130 131 GraphicsPrimitive[] newGen = new GraphicsPrimitive[len + 1];
131 132 System.arraycopy(generalPrimitives, 0, newGen, 0, len);
132 133 newGen[len] = gen;
133 134 generalPrimitives = newGen;
134 135 }
135 136
136 137 public static synchronized GraphicsPrimitive locate(int primTypeID,
137 138 SurfaceType dsttype)
138 139 {
139 140 return locate(primTypeID,
140 141 SurfaceType.OpaqueColor,
141 142 CompositeType.Src,
142 143 dsttype);
143 144 }
144 145
145 146 public static synchronized GraphicsPrimitive locate(int primTypeID,
146 147 SurfaceType srctype,
147 148 CompositeType comptype,
148 149 SurfaceType dsttype)
149 150 {
150 151 /*
151 152 System.out.println("Looking for:");
152 153 System.out.println(" method: "+signature);
153 154 System.out.println(" from: "+srctype);
154 155 System.out.println(" by: "+comptype);
155 156 System.out.println(" to: "+dsttype);
156 157 */
157 158 GraphicsPrimitive prim = locatePrim(primTypeID,
158 159 srctype, comptype, dsttype);
159 160
160 161 if (prim == null) {
161 162 //System.out.println("Trying general loop");
162 163 prim = locateGeneral(primTypeID);
163 164 if (prim != null) {
164 165 prim = prim.makePrimitive(srctype, comptype, dsttype);
165 166 if (prim != null && GraphicsPrimitive.traceflags != 0) {
166 167 prim = prim.traceWrap();
167 168 }
168 169 }
169 170 }
170 171 return prim;
171 172 }
172 173
173 174 public static synchronized GraphicsPrimitive
174 175 locatePrim(int primTypeID,
175 176 SurfaceType srctype,
176 177 CompositeType comptype,
177 178 SurfaceType dsttype)
178 179 {
179 180 /*
180 181 System.out.println("Looking for:");
181 182 System.out.println(" method: "+signature);
182 183 System.out.println(" from: "+srctype);
183 184 System.out.println(" by: "+comptype);
184 185 System.out.println(" to: "+dsttype);
185 186 */
186 187 SurfaceType src, dst;
187 188 CompositeType cmp;
188 189 GraphicsPrimitive prim;
189 190 PrimitiveSpec spec = new PrimitiveSpec();
190 191
191 192 for (dst = dsttype; dst != null; dst = dst.getSuperType()) {
192 193 for (src = srctype; src != null; src = src.getSuperType()) {
193 194 for (cmp = comptype; cmp != null; cmp = cmp.getSuperType()) {
194 195 /*
195 196 System.out.println("Trying:");
196 197 System.out.println(" method: "+spec.methodSignature);
197 198 System.out.println(" from: "+spec.sourceType);
198 199 System.out.println(" by: "+spec.compType);
199 200 System.out.println(" to: "+spec.destType);
200 201 */
201 202
202 203 spec.uniqueID =
203 204 GraphicsPrimitive.makeUniqueID(primTypeID, src, cmp, dst);
204 205 prim = locate(spec);
205 206 if (prim != null) {
206 207 //System.out.println("<GPMgr> Found: " + prim + " in " + i + " steps");
207 208 return prim;
208 209 }
209 210 }
210 211 }
211 212 }
212 213 return null;
213 214 }
214 215
215 216 private static GraphicsPrimitive locateGeneral(int primTypeID) {
216 217 if (generalPrimitives == null) {
217 218 return null;
218 219 }
219 220 for (int i = 0; i < generalPrimitives.length; i++) {
220 221 GraphicsPrimitive prim = generalPrimitives[i];
221 222 if (prim.getPrimTypeID() == primTypeID) {
222 223 return prim;
223 224 }
224 225 }
225 226 return null;
226 227 //throw new InternalError("No general handler registered for"+signature);
227 228 }
228 229
229 230 private static GraphicsPrimitive locate(PrimitiveSpec spec) {
230 231 if (needssort) {
231 232 if (GraphicsPrimitive.traceflags != 0) {
232 233 for (int i = 0; i < primitives.length; i++) {
233 234 primitives[i] = primitives[i].traceWrap();
234 235 }
235 236 }
236 237 Arrays.sort(primitives, primSorter);
237 238 needssort = false;
238 239 }
239 240 GraphicsPrimitive[] devCollection = primitives;
240 241 if (devCollection == null) {
241 242 return null;
242 243 }
243 244 int index = Arrays.binarySearch(devCollection, spec, primFinder);
244 245 if (index >= 0) {
245 246 GraphicsPrimitive prim = devCollection[index];
246 247 if (prim instanceof GraphicsPrimitiveProxy) {
247 248 prim = ((GraphicsPrimitiveProxy) prim).instantiate();
248 249 devCollection[index] = prim;
249 250 if (debugTrace) {
250 251 writeLog("Instantiated graphics primitive " + prim);
251 252 }
252 253 }
253 254 if (debugTrace) {
254 255 writeLog("Lookup found[" + index + "]["+ prim + "]");
255 256 }
256 257 return prim;
257 258 }
258 259 if (debugTrace) {
259 260 writeLog("Lookup found nothing for:");
260 261 writeLog(" " + spec.uniqueID);
261 262 }
262 263 return null;
263 264 }
264 265
265 266 private static void writeLog(String str) {
266 267 if (debugTrace) {
267 268 System.err.println(str);
268 269 }
269 270 }
270 271
271 272 /**
272 273 * Test that all of the GraphicsPrimitiveProxy objects actually
273 274 * resolve to something. Throws a RuntimeException if anything
274 275 * is wrong, an has no effect if all is well.
275 276 */
276 277 // This is only really meant to be called from GraphicsPrimitiveProxyTest
277 278 // in the regression tests directory, but it has to be here because
278 279 // it needs access to a private data structure. It is not very
279 280 // big, though.
280 281 public static void testPrimitiveInstantiation() {
281 282 testPrimitiveInstantiation(false);
282 283 }
283 284
284 285 public static void testPrimitiveInstantiation(boolean verbose) {
285 286 int resolved = 0;
286 287 int unresolved = 0;
287 288 GraphicsPrimitive[] prims = primitives;
288 289 for (int j = 0; j < prims.length; j++) {
289 290 GraphicsPrimitive p = prims[j];
290 291 if (p instanceof GraphicsPrimitiveProxy) {
291 292 GraphicsPrimitive r = ((GraphicsPrimitiveProxy) p).instantiate();
292 293 if (!r.getSignature().equals(p.getSignature()) ||
293 294 r.getUniqueID() != p.getUniqueID()) {
294 295 System.out.println("r.getSignature == "+r.getSignature());
295 296 System.out.println("r.getUniqueID == " + r.getUniqueID());
296 297 System.out.println("p.getSignature == "+p.getSignature());
297 298 System.out.println("p.getUniqueID == " + p.getUniqueID());
298 299 throw new RuntimeException("Primitive " + p
299 300 + " returns wrong signature for "
300 301 + r.getClass());
301 302 }
302 303 // instantiate checks that p.satisfiesSameAs(r)
303 304 unresolved++;
304 305 p = r;
305 306 if (verbose) {
306 307 System.out.println(p);
307 308 }
308 309 } else {
309 310 if (verbose) {
310 311 System.out.println(p + " (not proxied).");
311 312 }
312 313 resolved++;
313 314 }
314 315 }
315 316 System.out.println(resolved+
316 317 " graphics primitives were not proxied.");
317 318 System.out.println(unresolved+
318 319 " proxied graphics primitives resolved correctly.");
319 320 System.out.println(resolved+unresolved+
320 321 " total graphics primitives");
321 322 }
322 323
323 324 public static void main(String[] argv) {
324 325 // REMIND: Should trigger loading of platform primitives somehow...
325 326 if (needssort) {
326 327 Arrays.sort(primitives, primSorter);
327 328 needssort = false;
328 329 }
329 330 testPrimitiveInstantiation(argv.length > 0);
330 331 }
331 332 }
↓ open down ↓ |
268 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX