299 }
300 return true;
301 }
302
303 //
304 // A version of satisfies used for regression testing
305 //
306 final boolean satisfiesSameAs(GraphicsPrimitive other) {
307 return (methodSignature == other.methodSignature &&
308 sourceType.equals(other.sourceType) &&
309 compositeType.equals(other.compositeType) &&
310 destType.equals(other.destType));
311 }
312
313 public abstract GraphicsPrimitive makePrimitive(SurfaceType srctype,
314 CompositeType comptype,
315 SurfaceType dsttype);
316
317 public abstract GraphicsPrimitive traceWrap();
318
319 static HashMap traceMap;
320
321 public static int traceflags;
322 public static String tracefile;
323 public static PrintStream traceout;
324
325 public static final int TRACELOG = 1;
326 public static final int TRACETIMESTAMP = 2;
327 public static final int TRACECOUNTS = 4;
328
329 static {
330 GetPropertyAction gpa = new GetPropertyAction("sun.java2d.trace");
331 String trace = (String)AccessController.doPrivileged(gpa);
332 if (trace != null) {
333 boolean verbose = false;
334 int traceflags = 0;
335 StringTokenizer st = new StringTokenizer(trace, ",");
336 while (st.hasMoreTokens()) {
337 String tok = st.nextToken();
338 if (tok.equalsIgnoreCase("count")) {
339 traceflags |= GraphicsPrimitive.TRACECOUNTS;
340 } else if (tok.equalsIgnoreCase("log")) {
341 traceflags |= GraphicsPrimitive.TRACELOG;
342 } else if (tok.equalsIgnoreCase("timestamp")) {
343 traceflags |= GraphicsPrimitive.TRACETIMESTAMP;
344 } else if (tok.equalsIgnoreCase("verbose")) {
345 verbose = true;
346 } else if (tok.regionMatches(true, 0, "out:", 0, 4)) {
347 tracefile = tok.substring(4);
348 } else {
349 if (!tok.equalsIgnoreCase("help")) {
350 System.err.println("unrecognized token: "+tok);
351 }
374 System.err.println("disabled");
375 }
376 System.err.print("GraphicsPrimitive trace output to ");
377 if (tracefile == null) {
378 System.err.println("System.err");
379 } else {
380 System.err.println("file '"+tracefile+"'");
381 }
382 }
383 GraphicsPrimitive.traceflags = traceflags;
384 }
385 }
386
387 public static boolean tracingEnabled() {
388 return (traceflags != 0);
389 }
390
391 private static PrintStream getTraceOutputFile() {
392 if (traceout == null) {
393 if (tracefile != null) {
394 Object o =
395 AccessController.doPrivileged(new PrivilegedAction() {
396 public Object run() {
397 try {
398 return new FileOutputStream(tracefile);
399 } catch (FileNotFoundException e) {
400 return null;
401 }
402 }
403 });
404 if (o != null) {
405 traceout = new PrintStream((OutputStream) o);
406 } else {
407 traceout = System.err;
408 }
409 } else {
410 traceout = System.err;
411 }
412 }
413 return traceout;
414 }
415
416 public static class TraceReporter extends Thread {
417 public static void setShutdownHook() {
418 AccessController.doPrivileged(new PrivilegedAction() {
419 public Object run() {
420 TraceReporter t = new TraceReporter();
421 t.setContextClassLoader(null);
422 Runtime.getRuntime().addShutdownHook(t);
423 return null;
424 }
425 });
426 }
427
428 public void run() {
429 PrintStream ps = getTraceOutputFile();
430 Iterator iterator = traceMap.entrySet().iterator();
431 long total = 0;
432 int numprims = 0;
433 while (iterator.hasNext()) {
434 Map.Entry me = (Map.Entry) iterator.next();
435 Object prim = me.getKey();
436 int[] count = (int[]) me.getValue();
437 if (count[0] == 1) {
438 ps.print("1 call to ");
439 } else {
440 ps.print(count[0]+" calls to ");
441 }
442 ps.println(prim);
443 numprims++;
444 total += count[0];
445 }
446 if (numprims == 0) {
447 ps.println("No graphics primitives executed");
448 } else if (numprims > 1) {
449 ps.println(total+" total calls to "+
450 numprims+" different primitives");
451 }
452 }
453 }
454
455 public synchronized static void tracePrimitive(Object prim) {
456 if ((traceflags & TRACECOUNTS) != 0) {
457 if (traceMap == null) {
458 traceMap = new HashMap();
459 TraceReporter.setShutdownHook();
460 }
461 Object o = traceMap.get(prim);
462 if (o == null) {
463 o = new int[1];
464 traceMap.put(prim, o);
465 }
466 ((int[]) o)[0]++;
467 }
468 if ((traceflags & TRACELOG) != 0) {
469 PrintStream ps = getTraceOutputFile();
470 if ((traceflags & TRACETIMESTAMP) != 0) {
471 ps.print(System.currentTimeMillis()+": ");
472 }
473 ps.println(prim);
474 }
|
299 }
300 return true;
301 }
302
303 //
304 // A version of satisfies used for regression testing
305 //
306 final boolean satisfiesSameAs(GraphicsPrimitive other) {
307 return (methodSignature == other.methodSignature &&
308 sourceType.equals(other.sourceType) &&
309 compositeType.equals(other.compositeType) &&
310 destType.equals(other.destType));
311 }
312
313 public abstract GraphicsPrimitive makePrimitive(SurfaceType srctype,
314 CompositeType comptype,
315 SurfaceType dsttype);
316
317 public abstract GraphicsPrimitive traceWrap();
318
319 @SuppressWarnings("rawtypes")
320 static HashMap traceMap;
321
322 public static int traceflags;
323 public static String tracefile;
324 public static PrintStream traceout;
325
326 public static final int TRACELOG = 1;
327 public static final int TRACETIMESTAMP = 2;
328 public static final int TRACECOUNTS = 4;
329
330 static {
331 GetPropertyAction gpa = new GetPropertyAction("sun.java2d.trace");
332 String trace = AccessController.doPrivileged(gpa);
333 if (trace != null) {
334 boolean verbose = false;
335 int traceflags = 0;
336 StringTokenizer st = new StringTokenizer(trace, ",");
337 while (st.hasMoreTokens()) {
338 String tok = st.nextToken();
339 if (tok.equalsIgnoreCase("count")) {
340 traceflags |= GraphicsPrimitive.TRACECOUNTS;
341 } else if (tok.equalsIgnoreCase("log")) {
342 traceflags |= GraphicsPrimitive.TRACELOG;
343 } else if (tok.equalsIgnoreCase("timestamp")) {
344 traceflags |= GraphicsPrimitive.TRACETIMESTAMP;
345 } else if (tok.equalsIgnoreCase("verbose")) {
346 verbose = true;
347 } else if (tok.regionMatches(true, 0, "out:", 0, 4)) {
348 tracefile = tok.substring(4);
349 } else {
350 if (!tok.equalsIgnoreCase("help")) {
351 System.err.println("unrecognized token: "+tok);
352 }
375 System.err.println("disabled");
376 }
377 System.err.print("GraphicsPrimitive trace output to ");
378 if (tracefile == null) {
379 System.err.println("System.err");
380 } else {
381 System.err.println("file '"+tracefile+"'");
382 }
383 }
384 GraphicsPrimitive.traceflags = traceflags;
385 }
386 }
387
388 public static boolean tracingEnabled() {
389 return (traceflags != 0);
390 }
391
392 private static PrintStream getTraceOutputFile() {
393 if (traceout == null) {
394 if (tracefile != null) {
395 FileOutputStream o = AccessController.doPrivileged(
396 new PrivilegedAction<FileOutputStream>() {
397 public FileOutputStream run() {
398 try {
399 return new FileOutputStream(tracefile);
400 } catch (FileNotFoundException e) {
401 return null;
402 }
403 }
404 });
405 if (o != null) {
406 traceout = new PrintStream(o);
407 } else {
408 traceout = System.err;
409 }
410 } else {
411 traceout = System.err;
412 }
413 }
414 return traceout;
415 }
416
417 public static class TraceReporter extends Thread {
418 public static void setShutdownHook() {
419 AccessController.doPrivileged(new PrivilegedAction<Void>() {
420 public Void run() {
421 TraceReporter t = new TraceReporter();
422 t.setContextClassLoader(null);
423 Runtime.getRuntime().addShutdownHook(t);
424 return null;
425 }
426 });
427 }
428
429 public void run() {
430 PrintStream ps = getTraceOutputFile();
431 @SuppressWarnings("rawtypes")
432 Iterator iterator = traceMap.entrySet().iterator();
433 long total = 0;
434 int numprims = 0;
435 while (iterator.hasNext()) {
436 @SuppressWarnings("rawtypes")
437 Map.Entry me = (Map.Entry) iterator.next();
438 Object prim = me.getKey();
439 int[] count = (int[]) me.getValue();
440 if (count[0] == 1) {
441 ps.print("1 call to ");
442 } else {
443 ps.print(count[0]+" calls to ");
444 }
445 ps.println(prim);
446 numprims++;
447 total += count[0];
448 }
449 if (numprims == 0) {
450 ps.println("No graphics primitives executed");
451 } else if (numprims > 1) {
452 ps.println(total+" total calls to "+
453 numprims+" different primitives");
454 }
455 }
456 }
457
458 @SuppressWarnings({ "rawtypes", "unchecked" })
459 public synchronized static void tracePrimitive(Object prim) {
460 if ((traceflags & TRACECOUNTS) != 0) {
461 if (traceMap == null) {
462 traceMap = new HashMap();
463 TraceReporter.setShutdownHook();
464 }
465 Object o = traceMap.get(prim);
466 if (o == null) {
467 o = new int[1];
468 traceMap.put(prim, o);
469 }
470 ((int[]) o)[0]++;
471 }
472 if ((traceflags & TRACELOG) != 0) {
473 PrintStream ps = getTraceOutputFile();
474 if ((traceflags & TRACETIMESTAMP) != 0) {
475 ps.print(System.currentTimeMillis()+": ");
476 }
477 ps.println(prim);
478 }
|