Print this page
Added gradle and cmake project


  23  * questions.
  24  */
  25 
  26 /*
  27  * @author Charlton Innovations, Inc.
  28  */
  29 
  30 package sun.java2d.loops;
  31 
  32 import java.awt.image.BufferedImage;
  33 import java.awt.AlphaComposite;
  34 import java.awt.Rectangle;
  35 import sun.awt.image.BufImgSurfaceData;
  36 import sun.awt.util.ThreadGroupUtils;
  37 import sun.java2d.SurfaceData;
  38 import sun.java2d.pipe.Region;
  39 import java.lang.reflect.Field;
  40 import java.util.StringTokenizer;
  41 import java.util.Iterator;
  42 import java.util.HashMap;

  43 import java.util.Map;
  44 import java.io.PrintStream;
  45 import java.io.OutputStream;
  46 import java.io.FileOutputStream;
  47 import java.io.FileNotFoundException;
  48 import java.security.AccessController;
  49 import java.security.PrivilegedAction;
  50 
  51 import sun.security.action.GetPropertyAction;
  52 
  53 /**
  54  * defines interface for primitives which can be placed into
  55  * the graphic component manager framework
  56  */
  57 public abstract class GraphicsPrimitive {
  58 
  59     protected static interface GeneralBinaryOp {
  60         /**
  61          * This method allows the setupGeneralBinaryOp method to set
  62          * the converters into the General version of the Primitive.


 302         return true;
 303     }
 304 
 305     //
 306     // A version of satisfies used for regression testing
 307     //
 308     final boolean satisfiesSameAs(GraphicsPrimitive other) {
 309         return (methodSignature == other.methodSignature &&
 310                 sourceType.equals(other.sourceType) &&
 311                 compositeType.equals(other.compositeType) &&
 312                 destType.equals(other.destType));
 313     }
 314 
 315     public abstract GraphicsPrimitive makePrimitive(SurfaceType srctype,
 316                                                     CompositeType comptype,
 317                                                     SurfaceType dsttype);
 318 
 319     public abstract GraphicsPrimitive traceWrap();
 320 
 321     static HashMap<Object, int[]> traceMap;

 322 
 323     public static int traceflags;
 324     public static String tracefile;

 325     public static PrintStream traceout;


 326 
 327     public static final int TRACELOG = 1;
 328     public static final int TRACETIMESTAMP = 2;
 329     public static final int TRACECOUNTS = 4;









 330 
 331     static {
 332         GetPropertyAction gpa = new GetPropertyAction("sun.java2d.trace");
 333         String trace = AccessController.doPrivileged(gpa);
 334         if (trace != null) {
 335             boolean verbose = false;
 336             int traceflags = 0;
 337             StringTokenizer st = new StringTokenizer(trace, ",");
 338             while (st.hasMoreTokens()) {
 339                 String tok = st.nextToken();
 340                 if (tok.equalsIgnoreCase("count")) {
 341                     traceflags |= GraphicsPrimitive.TRACECOUNTS;
 342                 } else if (tok.equalsIgnoreCase("log")) {
 343                     traceflags |= GraphicsPrimitive.TRACELOG;
 344                 } else if (tok.equalsIgnoreCase("timestamp")) {
 345                     traceflags |= GraphicsPrimitive.TRACETIMESTAMP;







 346                 } else if (tok.equalsIgnoreCase("verbose")) {
 347                     verbose = true;
 348                 } else if (tok.regionMatches(true, 0, "out:", 0, 4)) {
 349                     tracefile = tok.substring(4);






 350                 } else {
 351                     if (!tok.equalsIgnoreCase("help")) {
 352                         System.err.println("unrecognized token: "+tok);
 353                     }
 354                     System.err.println("usage: -Dsun.java2d.trace="+
 355                                        "[log[,timestamp]],[count],"+
 356                                        "[out:<filename>],[help],[verbose]");
 357                 }
 358             }



 359             if (verbose) {
 360                 System.err.print("GraphicsPrimitive logging ");
 361                 if ((traceflags & GraphicsPrimitive.TRACELOG) != 0) {
 362                     System.err.println("enabled");
 363                     System.err.print("GraphicsPrimitive timetamps ");
 364                     if ((traceflags & GraphicsPrimitive.TRACETIMESTAMP) != 0) {
 365                         System.err.println("enabled");
 366                     } else {
 367                         System.err.println("disabled");
 368                     }
 369                 } else {
 370                     System.err.println("[and timestamps] disabled");
 371                 }
 372                 System.err.print("GraphicsPrimitive invocation counts ");
 373                 if ((traceflags & GraphicsPrimitive.TRACECOUNTS) != 0) {
 374                     System.err.println("enabled");
 375                 } else {
 376                     System.err.println("disabled");
 377                 }
 378                 System.err.print("GraphicsPrimitive trace output to ");


 399                             try {
 400                                 return new FileOutputStream(tracefile);
 401                             } catch (FileNotFoundException e) {
 402                                 return null;
 403                             }
 404                         }
 405                     });
 406                 if (o != null) {
 407                     traceout = new PrintStream(o);
 408                 } else {
 409                     traceout = System.err;
 410                 }
 411             } else {
 412                 traceout = System.err;
 413             }
 414         }
 415         return traceout;
 416     }
 417 
 418     public static class TraceReporter implements Runnable {
 419         public static void setShutdownHook() {





 420             AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
 421                 TraceReporter t = new TraceReporter();
 422                 Thread thread = new Thread(
 423                         ThreadGroupUtils.getRootThreadGroup(), t,
 424                         "TraceReporter", 0, false);
 425                 thread.setContextClassLoader(null);
 426                 Runtime.getRuntime().addShutdownHook(thread);
 427                 return null;
 428             });
 429         }
 430 
 431         public void run() {
 432             PrintStream ps = getTraceOutputFile();

 433             Iterator<Map.Entry<Object, int[]>> iterator =
 434                 traceMap.entrySet().iterator();
 435             long total = 0;
 436             int numprims = 0;
 437             while (iterator.hasNext()) {
 438                 Map.Entry<Object, int[]> me = iterator.next();
 439                 Object prim = me.getKey();
 440                 int[] count = me.getValue();
 441                 if (count[0] == 1) {
 442                     ps.print("1 call to ");
 443                 } else {
 444                     ps.print(count[0]+" calls to ");
 445                 }
 446                 ps.println(prim);
 447                 numprims++;
 448                 total += count[0];
 449             }
 450             if (numprims == 0) {
 451                 ps.println("No graphics primitives executed");
 452             } else if (numprims > 1) {
 453                 ps.println(total+" total calls to "+
 454                            numprims+" different primitives");









 455             }
 456         }
 457     }
 458 
 459     public static synchronized void tracePrimitive(Object prim) {




 460         if ((traceflags & TRACECOUNTS) != 0) {
 461             if (traceMap == null) {
 462                 traceMap = new HashMap<>();
 463                 TraceReporter.setShutdownHook();
 464             }
 465             int[] o = traceMap.get(prim);
 466             if (o == null) {
 467                 o = new int[1];
 468                 traceMap.put(prim, o);
 469             }
 470             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         }
 479     }
 480 








































 481     protected void setupGeneralBinaryOp(GeneralBinaryOp gbo) {
 482         int primID = gbo.getPrimTypeID();
 483         String methodSignature = gbo.getSignature();
 484         SurfaceType srctype = gbo.getSourceType();
 485         CompositeType comptype = gbo.getCompositeType();
 486         SurfaceType dsttype = gbo.getDestType();
 487         Blit convertsrc, convertdst, convertres;
 488         GraphicsPrimitive performop;
 489 
 490         convertsrc = createConverter(srctype, SurfaceType.IntArgb);
 491         performop = GraphicsPrimitiveMgr.locatePrim(primID,
 492                                                     SurfaceType.IntArgb,
 493                                                     comptype, dsttype);
 494         if (performop != null) {
 495             convertdst = null;
 496             convertres = null;
 497         } else {
 498             performop = getGeneralOp(primID, comptype);
 499             if (performop == null) {
 500                 throw new InternalError("Cannot construct general op for "+




  23  * questions.
  24  */
  25 
  26 /*
  27  * @author Charlton Innovations, Inc.
  28  */
  29 
  30 package sun.java2d.loops;
  31 
  32 import java.awt.image.BufferedImage;
  33 import java.awt.AlphaComposite;
  34 import java.awt.Rectangle;
  35 import sun.awt.image.BufImgSurfaceData;
  36 import sun.awt.util.ThreadGroupUtils;
  37 import sun.java2d.SurfaceData;
  38 import sun.java2d.pipe.Region;
  39 import java.lang.reflect.Field;
  40 import java.util.StringTokenizer;
  41 import java.util.Iterator;
  42 import java.util.HashMap;
  43 import java.util.HashSet;
  44 import java.util.Map;
  45 import java.io.PrintStream;
  46 import java.io.OutputStream;
  47 import java.io.FileOutputStream;
  48 import java.io.FileNotFoundException;
  49 import java.security.AccessController;
  50 import java.security.PrivilegedAction;
  51 
  52 import sun.security.action.GetPropertyAction;
  53 
  54 /**
  55  * defines interface for primitives which can be placed into
  56  * the graphic component manager framework
  57  */
  58 public abstract class GraphicsPrimitive {
  59 
  60     protected static interface GeneralBinaryOp {
  61         /**
  62          * This method allows the setupGeneralBinaryOp method to set
  63          * the converters into the General version of the Primitive.


 303         return true;
 304     }
 305 
 306     //
 307     // A version of satisfies used for regression testing
 308     //
 309     final boolean satisfiesSameAs(GraphicsPrimitive other) {
 310         return (methodSignature == other.methodSignature &&
 311                 sourceType.equals(other.sourceType) &&
 312                 compositeType.equals(other.compositeType) &&
 313                 destType.equals(other.destType));
 314     }
 315 
 316     public abstract GraphicsPrimitive makePrimitive(SurfaceType srctype,
 317                                                     CompositeType comptype,
 318                                                     SurfaceType dsttype);
 319 
 320     public abstract GraphicsPrimitive traceWrap();
 321 
 322     static HashMap<Object, int[]> traceMap;
 323     static HashSet<String> traceNotImplSet;
 324 
 325     public static int traceflags;
 326     public static String tracefile;
 327     public static String pname;
 328     public static PrintStream traceout;
 329     public static long treshold = 0;
 330     public static boolean verbose = false;
 331 
 332     public static final int TRACELOG = 1;
 333     public static final int TRACETIMESTAMP = 2;
 334     public static final int TRACECOUNTS = 4;
 335     public static final int TRACEPTIME = 8;
 336     public static final int TRACEPNAME = 16;
 337     public static final int TRACENOTIMPL = 32;
 338 
 339     static void showTraceUsage() {
 340         System.err.println("usage: -Dsun.java2d.trace="+
 341                 "[log[,timestamp]],[count],[ptime],[name:<substr pattern>],"+
 342                 "[out:<filename>],[td=<treshold>],[help],[verbose]");
 343     }
 344 
 345     static {
 346         GetPropertyAction gpa = new GetPropertyAction("sun.java2d.trace");
 347         String trace = AccessController.doPrivileged(gpa);
 348         if (trace != null) {

 349             int traceflags = 0;
 350             StringTokenizer st = new StringTokenizer(trace, ",");
 351             while (st.hasMoreTokens()) {
 352                 String tok = st.nextToken();
 353                 if (tok.equalsIgnoreCase("count")) {
 354                     traceflags |= GraphicsPrimitive.TRACECOUNTS;
 355                 } else if (tok.equalsIgnoreCase("log")) {
 356                     traceflags |= GraphicsPrimitive.TRACELOG;
 357                 } else if (tok.equalsIgnoreCase("timestamp")) {
 358                     traceflags |= GraphicsPrimitive.TRACETIMESTAMP;
 359                 } else if (tok.equalsIgnoreCase("ptime")) {
 360                     traceflags |=GraphicsPrimitive.TRACEPTIME;
 361                 } else if (tok.equalsIgnoreCase("notimpl")) {
 362                     traceflags |=GraphicsPrimitive.TRACENOTIMPL;
 363                 } else if (tok.regionMatches(true, 0, "name:", 0, 5)) {
 364                     traceflags |=GraphicsPrimitive.TRACEPNAME;
 365                     pname = tok.substring(6);
 366                 } else if (tok.equalsIgnoreCase("verbose")) {
 367                     verbose = true;
 368                 } else if (tok.regionMatches(true, 0, "out:", 0, 4)) {
 369                     tracefile = tok.substring(4);
 370                 } else if (tok.regionMatches(true, 0, "td=", 0, 3)) {
 371                     try {
 372                         treshold = Long.parseLong(tok.substring(3));
 373                     } catch (NumberFormatException e) {
 374                         showTraceUsage();
 375                     }
 376                 } else {
 377                     if (!tok.equalsIgnoreCase("help")) {
 378                         System.err.println("unrecognized token: "+tok);
 379                     }
 380                     showTraceUsage();


 381                 }
 382             }
 383 
 384             GraphicsPrimitiveMgr.setTraceFlags(traceflags);
 385 
 386             if (verbose) {
 387                 System.err.print("GraphicsPrimitive logging ");
 388                 if ((traceflags & GraphicsPrimitive.TRACELOG) != 0) {
 389                     System.err.println("enabled");
 390                     System.err.print("GraphicsPrimitive timetamps ");
 391                     if ((traceflags & GraphicsPrimitive.TRACETIMESTAMP) != 0) {
 392                         System.err.println("enabled");
 393                     } else {
 394                         System.err.println("disabled");
 395                     }
 396                 } else {
 397                     System.err.println("[and timestamps] disabled");
 398                 }
 399                 System.err.print("GraphicsPrimitive invocation counts ");
 400                 if ((traceflags & GraphicsPrimitive.TRACECOUNTS) != 0) {
 401                     System.err.println("enabled");
 402                 } else {
 403                     System.err.println("disabled");
 404                 }
 405                 System.err.print("GraphicsPrimitive trace output to ");


 426                             try {
 427                                 return new FileOutputStream(tracefile);
 428                             } catch (FileNotFoundException e) {
 429                                 return null;
 430                             }
 431                         }
 432                     });
 433                 if (o != null) {
 434                     traceout = new PrintStream(o);
 435                 } else {
 436                     traceout = System.err;
 437                 }
 438             } else {
 439                 traceout = System.err;
 440             }
 441         }
 442         return traceout;
 443     }
 444 
 445     public static class TraceReporter implements Runnable {
 446         private static boolean hookEnabled = false;
 447 
 448         public static synchronized void setShutdownHook() {
 449             if (hookEnabled) return;
 450             hookEnabled = true;
 451 
 452             AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
 453                 TraceReporter t = new TraceReporter();
 454                 Thread thread = new Thread(
 455                         ThreadGroupUtils.getRootThreadGroup(), t,
 456                         "TraceReporter", 0, false);
 457                 thread.setContextClassLoader(null);
 458                 Runtime.getRuntime().addShutdownHook(thread);
 459                 return null;
 460             });
 461         }
 462 
 463         public void run() {
 464             PrintStream ps = getTraceOutputFile();
 465             if (traceMap != null) {
 466                 Iterator<Map.Entry<Object, int[]>> iterator =
 467                         traceMap.entrySet().iterator();
 468                 long total = 0;
 469                 int numprims = 0;
 470                 while (iterator.hasNext()) {
 471                     Map.Entry<Object, int[]> me = iterator.next();
 472                     Object prim = me.getKey();
 473                     int[] count = me.getValue();
 474                     if (count[0] == 1) {
 475                         ps.print("1 call to ");
 476                     } else {
 477                         ps.print(count[0] + " calls to ");
 478                     }
 479                     ps.println(prim);
 480                     numprims++;
 481                     total += count[0];
 482                 }
 483                 if (numprims == 0) {
 484                     ps.println("No graphics primitives executed");
 485                 } else if (numprims > 1) {
 486                     ps.println(total + " total calls to " +
 487                             numprims + " different primitives");
 488                 }
 489             }
 490 
 491             if (traceNotImplSet != null) {
 492                 ps.println("Not implemented graphics primitives:");
 493 
 494                 for (String name : traceNotImplSet) {
 495                     ps.println(name);
 496                 }
 497             }
 498         }
 499     }
 500 
 501     public synchronized static void tracePrimitive(Object prim) {
 502         if ((traceflags & TRACEPNAME) != 0) {
 503             if (!prim.toString().contains(pname)) return;
 504         }
 505 
 506         if ((traceflags & TRACECOUNTS) != 0) {
 507             if (traceMap == null) {
 508                 traceMap = new HashMap<>();
 509                 TraceReporter.setShutdownHook();
 510             }
 511             int[] o = traceMap.get(prim);
 512             if (o == null) {
 513                 o = new int[1];
 514                 traceMap.put(prim, o);
 515             }
 516             o[0]++;
 517         }
 518         if ((traceflags & TRACELOG) != 0) {
 519             PrintStream ps = getTraceOutputFile();
 520             if ((traceflags & TRACETIMESTAMP) != 0) {
 521                 ps.print(System.currentTimeMillis()+": ");
 522             }
 523             ps.println(prim);
 524         }
 525     }
 526 
 527     public synchronized static void traceNotImplPrimitive(Object prim) {
 528         if ((traceflags & TRACEPNAME) != 0) {
 529             if (!prim.toString().contains(pname)) return;
 530         }
 531 
 532         if ((traceflags & TRACECOUNTS) != 0) {
 533             if (traceNotImplSet == null) {
 534                 traceNotImplSet = new HashSet<String>();
 535                 TraceReporter.setShutdownHook();
 536             }
 537             traceNotImplSet.add(prim.toString());
 538         }
 539         if ((traceflags & TRACELOG) != 0) {
 540             PrintStream ps = getTraceOutputFile();
 541             if ((traceflags & TRACETIMESTAMP) != 0) {
 542                 ps.print(System.currentTimeMillis()+":[NOT IMPL] ");
 543             }
 544             ps.println(prim);
 545         }
 546     }
 547 
 548     public synchronized static void tracePrimitiveTime(Object prim, long time) {
 549         if ((traceflags & TRACEPNAME) != 0) {
 550             if (!prim.toString().contains(pname)) return;
 551         }
 552         if (time > treshold && (traceflags & TRACEPTIME) != 0  && (traceflags & TRACELOG) != 0) {
 553             PrintStream ps = getTraceOutputFile();
 554             ps.println(prim + " time: " + time);
 555             if (verbose) {
 556                 final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
 557                 if (stackTrace.length > 3) {
 558                     for (int i = 3; i < stackTrace.length; i++) {
 559                         ps.println("  " + stackTrace[i].toString());
 560                     }
 561                 }
 562                 ps.println();
 563             }
 564         }
 565     }
 566 
 567     protected void setupGeneralBinaryOp(GeneralBinaryOp gbo) {
 568         int primID = gbo.getPrimTypeID();
 569         String methodSignature = gbo.getSignature();
 570         SurfaceType srctype = gbo.getSourceType();
 571         CompositeType comptype = gbo.getCompositeType();
 572         SurfaceType dsttype = gbo.getDestType();
 573         Blit convertsrc, convertdst, convertres;
 574         GraphicsPrimitive performop;
 575 
 576         convertsrc = createConverter(srctype, SurfaceType.IntArgb);
 577         performop = GraphicsPrimitiveMgr.locatePrim(primID,
 578                                                     SurfaceType.IntArgb,
 579                                                     comptype, dsttype);
 580         if (performop != null) {
 581             convertdst = null;
 582             convertres = null;
 583         } else {
 584             performop = getGeneralOp(primID, comptype);
 585             if (performop == null) {
 586                 throw new InternalError("Cannot construct general op for "+