OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [examples/] [gnu/] [classpath/] [examples/] [java2d/] [J2dBenchmark.java] - Blame information for rev 781

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 781 jeremybenn
/* J2dBenchmark.java -- Benchmarking utility for java2d,
2
   based on the Aicas AWT benchmarker
3
 Copyright (C) 2006 Free Software Foundation, Inc.
4
 
5
 This file is part of GNU Classpath examples.
6
 
7
 GNU Classpath is free software; you can redistribute it and/or modify
8
 it under the terms of the GNU General Public License as published by
9
 the Free Software Foundation; either version 2, or (at your option)
10
 any later version.
11
 
12
 GNU Classpath is distributed in the hope that it will be useful, but
13
 WITHOUT ANY WARRANTY; without even the implied warranty of
14
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 General Public License for more details.
16
 
17
 You should have received a copy of the GNU General Public License
18
 along with GNU Classpath; see the file COPYING.  If not, write to the
19
 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20
 02110-1301 USA. */
21
 
22
package gnu.classpath.examples.java2d;
23
 
24
import java.awt.AlphaComposite;
25
import java.awt.BasicStroke;
26
import java.awt.BorderLayout;
27
import java.awt.Canvas;
28
import java.awt.Color;
29
import java.awt.Dimension;
30
import java.awt.Frame;
31
import java.awt.GradientPaint;
32
import java.awt.Graphics;
33
import java.awt.Graphics2D;
34
import java.awt.Image;
35
import java.awt.Insets;
36
import java.awt.Label;
37
import java.awt.MediaTracker;
38
import java.awt.Panel;
39
import java.awt.Rectangle;
40
import java.awt.RenderingHints;
41
import java.awt.TexturePaint;
42
import java.awt.Toolkit;
43
import java.awt.event.WindowAdapter;
44
import java.awt.event.WindowEvent;
45
import java.awt.geom.AffineTransform;
46
import java.awt.geom.Arc2D;
47
import java.awt.geom.CubicCurve2D;
48
import java.awt.geom.Ellipse2D;
49
import java.awt.geom.GeneralPath;
50
import java.awt.geom.Line2D;
51
import java.awt.geom.QuadCurve2D;
52
import java.awt.geom.Rectangle2D;
53
import java.awt.geom.RoundRectangle2D;
54
import java.awt.image.BufferedImage;
55
import java.net.URL;
56
import java.util.Iterator;
57
import java.util.Map;
58
import java.util.StringTokenizer;
59
import java.util.TreeMap;
60
import java.util.logging.Level;
61
import java.util.logging.Logger;
62
 
63
public class J2dBenchmark
64
    extends Panel
65
{
66
  /**
67
   * Default number of test-iterations.
68
   */
69
  protected static final int DEFAULT_TEST_SIZE = 1000;
70
 
71
  /**
72
   * Default screen size.
73
   */
74
  protected static final int DEFAULT_SCREEN_WIDTH = 320;
75
 
76
  protected static final int DEFAULT_SCREEN_HEIGHT = 240;
77
 
78
  /**
79
   * Java2D tests.
80
   */
81
  protected static final int J2DTEST_ARC = 1 << 0;
82
 
83
  protected static final int J2DTEST_CUBICCURVE = 1 << 1;
84
 
85
  protected static final int J2DTEST_ELLIPSE = 1 << 2;
86
 
87
  protected static final int J2DTEST_GENERALPATH = 1 << 3;
88
 
89
  protected static final int J2DTEST_LINE = 1 << 4;
90
 
91
  protected static final int J2DTEST_QUADCURVE = 1 << 5;
92
 
93
  protected static final int J2DTEST_RECTANGLE = 1 << 6;
94
 
95
  protected static final int J2DTEST_ROUNDRECTANGLE = 1 << 7;
96
 
97
  protected static final int J2DTEST_IMAGE = 1 << 8;
98
 
99
  protected static final int J2DTEST_NONE = 0;
100
 
101
  /*
102
  private static final int J2DTEST_ALL = J2DTEST_ARC | J2DTEST_CUBICCURVE
103
                                         | J2DTEST_ELLIPSE
104
                                         | J2DTEST_GENERALPATH | J2DTEST_LINE
105
                                         | J2DTEST_QUADCURVE
106
                                         | J2DTEST_RECTANGLE
107
                                         | J2DTEST_ROUNDRECTANGLE
108
                                         | J2DTEST_IMAGE;
109
  */
110
  private static final int J2DTEST_ALL = J2DTEST_ARC | J2DTEST_CUBICCURVE
111
                                         | J2DTEST_ELLIPSE
112
                                         | J2DTEST_LINE
113
                                         | J2DTEST_QUADCURVE
114
                                         | J2DTEST_RECTANGLE
115
                                         | J2DTEST_ROUNDRECTANGLE
116
                                         | J2DTEST_IMAGE;
117
 
118
  int iterations = 1;
119
 
120
  protected int screenWidth = DEFAULT_SCREEN_WIDTH;
121
 
122
  protected int screenHeight = DEFAULT_SCREEN_HEIGHT;
123
 
124
  protected boolean noClippingFlag = true;
125
 
126
  protected boolean withClippingFlag = true;
127
 
128
  protected boolean zeroClippingFlag = true;
129
 
130
  protected boolean singleBufferFlag = true;
131
 
132
  protected boolean doubleBufferFlag = true;
133
 
134
  protected boolean gradientFlag = false;
135
 
136
  protected String texture = null;
137
 
138
  protected boolean strokeFlag = false;
139
 
140
  protected float composite = 1;
141
 
142
  protected int xtranslate = 0;
143
 
144
  protected int ytranslate = 0;
145
 
146
  protected double xshear = 0;
147
 
148
  protected double yshear = 0;
149
 
150
  protected double rotate = 0;
151
 
152
  protected boolean antialiasFlag = false;
153
 
154
  protected AffineTransform affineTransform = null;
155
 
156
  protected int awtTests = J2DTEST_ALL;
157
 
158
  protected int testSize = DEFAULT_TEST_SIZE;
159
 
160
  private Label testLabel;
161
 
162
  private String testContext = "";
163
 
164
  Logger logger = Logger.getLogger("J2dGraphicsBenchmark");
165
 
166
  private Image pngTestImage;
167
 
168
  private Image gifTestImage;
169
 
170
  protected BufferedImage textureImage;
171
 
172
  protected TestSet testSetMap = new TestSet();
173
 
174
  public String init()
175
  {
176
    boolean loadError = false;
177
    pngTestImage = loadImage("../icons/aicas.png");
178
    gifTestImage = loadImage("../icons/palme.gif");
179
 
180
    if (texture != null)
181
      {
182
        textureImage = loadBufferedImage(texture);
183
 
184
        if (textureImage == null)
185
          {
186
            logger.logp(Level.WARNING, "J2dGraphicsBenchmark", "init",
187
                        "Unable to load texture - defaulting "
188
                            + "to solid colours");
189
            texture = null;
190
            loadError = true;
191
          }
192
      }
193
 
194
    setLayout(new BorderLayout());
195
    testLabel = new Label();
196
    add(testLabel, BorderLayout.NORTH);
197
    add(new GraphicsTest(), BorderLayout.CENTER);
198
 
199
    if (loadError)
200
      return "Unable to load image";
201
    else
202
      return null;
203
  }
204
 
205
  void setTestContext(String testName)
206
  {
207
    logger.logp(Level.INFO, "J2dGraphicsBenchmark", "recordTest",
208
                "--- Starting new test context: " + testName);
209
    testContext = testName;
210
    testLabel.setText(testName);
211
  }
212
 
213
  private void recordTest(String testName, long time)
214
  {
215
    logger.logp(Level.INFO, "J2dGraphicsBenchmark", "recordTest",
216
                testContext + ": " + testName + " duration (ms): " + time);
217
    TestRecorder recorder = testSetMap.getTest(testName);
218
    if (recorder == null)
219
      {
220
        recorder = new TestRecorder(testName);
221
        testSetMap.putTest(testName, recorder);
222
      }
223
    recorder.addRun(time);
224
  }
225
 
226
  void printReport()
227
  {
228
    for (Iterator i = testSetMap.testIterator(); i.hasNext();)
229
      {
230
        TestRecorder recorder = testSetMap.getTest((String) i.next());
231
        System.out.println("TEST " + recorder.getTestName() + ": average "
232
                           + recorder.getAverage() + "ms ["
233
                           + recorder.getMinTime() + "-"
234
                           + recorder.getMaxTime() + "]");
235
      }
236
  }
237
 
238
  void testComplete()
239
  {
240
    System.exit(0);
241
  }
242
 
243
  public static void main(String[] args)
244
  {
245
    int awtTests;
246
    int i;
247
    boolean endOfOptionsFlag;
248
    J2dBenchmark speed = new J2dBenchmark();
249
 
250
    // Parse arguments.
251
    i = 0;
252
    endOfOptionsFlag = false;
253
    awtTests = J2DTEST_NONE;
254
    while (i < args.length)
255
      {
256
        if (! endOfOptionsFlag)
257
          {
258
            if (args[i].equals("--help") || args[i].equals("-help")
259
                || args[i].equals("-h"))
260
              {
261
                System.out.println("Usage: J2dBenchmark [<options>] [<test>  ...]");
262
                System.out.println("");
263
                System.out.println("Options: -i|--iterations=<n|-1> - number of iterations (-1 is infinite; default "
264
                                   + speed.iterations + ")");
265
                System.out.println("         -w|--width=<n>         - screen width; default "
266
                                   + DEFAULT_SCREEN_WIDTH);
267
                System.out.println("         -h|--height=<n>        - screen height; default "
268
                                   + DEFAULT_SCREEN_HEIGHT);
269
                System.out.println("         -d|--noDoubleBuffer    - disable double-buffering test");
270
                System.out.println("         -s|--testsize=<n>      - size of each test; default "
271
                                   + DEFAULT_TEST_SIZE);
272
                System.out.println("         -c|--noClipping        - disable clipping test");
273
                System.out.println("         -z|--noZeroClipping    - disable clipping to zero test");
274
                System.out.println("");
275
                System.out.println("Additional options:");
276
                System.out.println("         --with-gradients       - enable gradients (not compatible with --texture)");
277
                System.out.println("         --with-stroking        - enable random stroking");
278
                System.out.println("         --texture=<file>       - enable texturing with this file (not compatible with --with-gradients)");
279
                System.out.println("         --composite=<n|-1>     - set alpha composite level; -1 for random; default 1.0 (no transparency)");
280
                System.out.println("         --anti-alias=<on|off>  - set anti-aliasing hint (not all implementations respect this); default off");
281
                System.out.println("         --x-translate=<n>      - set x-axis translation; default 0");
282
                System.out.println("         --y-translate=<n>      - set y-axis translation; default 0");
283
                System.out.println("         --x-shear=<n>          - set x-axis shear; default 0");
284
                System.out.println("         --y-shear=<n>          - set y-axis shear; default 0");
285
                System.out.println("         --rotate=<n|-1>        - set rotation (radians); -1 for random; default: 0 (none)");
286
                System.out.println("");
287
                System.out.println("Tests: arc");
288
                System.out.println("       cubiccurve");
289
                System.out.println("       ellipse");
290
                // System.out.println(" generalpath");
291
                System.out.println("       line");
292
                System.out.println("       quadcurve");
293
                System.out.println("       rectangle");
294
                System.out.println("       roundrectangle");
295
                System.out.println("       image");
296
                System.exit(1);
297
              }
298
            else if ((args[i].startsWith("-i=") || args[i].startsWith("--iterations=")))
299
              {
300
                speed.iterations = Integer.parseInt(args[i].substring(args[i].indexOf('=') + 1));
301
                i += 1;
302
                continue;
303
              }
304
            else if ((args[i].equals("-i") || args[i].equals("--iterations")))
305
              {
306
                if ((i + 1) >= args.length)
307
                  {
308
                    System.err.println("ERROR: No argument given for option '"
309
                                       + args[i] + "'!");
310
                    System.exit(2);
311
                  }
312
                speed.iterations = Integer.parseInt(args[i + 1]);
313
                i += 2;
314
                continue;
315
              }
316
            else if ((args[i].startsWith("-w=") || args[i].startsWith("--width=")))
317
              {
318
                speed.screenWidth = Integer.parseInt(args[i].substring(args[i].indexOf('=') + 1));
319
                i += 1;
320
                continue;
321
              }
322
            else if ((args[i].equals("-w") || args[i].equals("--width")))
323
              {
324
                if ((i + 1) >= args.length)
325
                  {
326
                    System.err.println("ERROR: No argument given for option '"
327
                                       + args[i] + "'!");
328
                    System.exit(2);
329
                  }
330
                speed.screenWidth = Integer.parseInt(args[i + 1]);
331
                i += 2;
332
                continue;
333
              }
334
            else if ((args[i].startsWith("-h=") || args[i].startsWith("--height=")))
335
              {
336
                speed.screenHeight = Integer.parseInt(args[i].substring(args[i].indexOf('=') + 1));
337
                i += 1;
338
                continue;
339
              }
340
            else if ((args[i].equals("-h") || args[i].equals("--height")))
341
              {
342
                if ((i + 1) >= args.length)
343
                  {
344
                    System.err.println("ERROR: No argument given for option '"
345
                                       + args[i] + "'!");
346
                    System.exit(2);
347
                  }
348
                speed.screenHeight = Integer.parseInt(args[i + 1]);
349
                i += 2;
350
                continue;
351
              }
352
            else if ((args[i].equals("-d") || args[i].equals("--noDoubleBuffer")))
353
              {
354
                speed.doubleBufferFlag = false;
355
                i += 1;
356
                continue;
357
              }
358
            else if ((args[i].startsWith("-s=") || args[i].startsWith("--testsize=")))
359
              {
360
                if ((i + 1) >= args.length)
361
                  {
362
                    System.err.println("ERROR: No argument given for option '"
363
                                       + args[i] + "'!");
364
                    System.exit(2);
365
                  }
366
                speed.testSize = Integer.parseInt(args[i].substring(args[i].indexOf('=') + 1));
367
                i += 1;
368
                continue;
369
              }
370
            else if ((args[i].equals("-s") || args[i].equals("--testsize")))
371
              {
372
                if ((i + 1) >= args.length)
373
                  {
374
                    System.err.println("ERROR: No argument given for option '"
375
                                       + args[i] + "'!");
376
                    System.exit(2);
377
                  }
378
                speed.testSize = Integer.parseInt(args[i + 1]);
379
                i += 2;
380
                continue;
381
              }
382
            else if ((args[i].equals("-c") || args[i].equals("--noClipping")))
383
              {
384
                speed.noClippingFlag = false;
385
                i += 1;
386
                continue;
387
              }
388
            else if ((args[i].equals("-z") || args[i].equals("--noZeroClipping")))
389
              {
390
                speed.zeroClippingFlag = false;
391
                i += 1;
392
                continue;
393
              }
394
            else if (args[i].equals("--with-gradients"))
395
              {
396
                speed.gradientFlag = true;
397
                i += 1;
398
                continue;
399
              }
400
            else if (args[i].equals("--with-stroking"))
401
              {
402
                speed.strokeFlag = true;
403
                i += 1;
404
                continue;
405
              }
406
            else if (args[i].startsWith("--texture="))
407
              {
408
                speed.texture = args[i].substring(args[i].indexOf('=') + 1);
409
                i += 1;
410
                continue;
411
              }
412
            else if (args[i].startsWith("--composite="))
413
              {
414
                speed.composite = Float.parseFloat(args[i].substring(args[i].indexOf('=') + 1));
415
                if (speed.composite != - 1
416
                    && (speed.composite < 0 || speed.composite > 1))
417
                  {
418
                    System.err.println("ERROR: Invalid value for composite (must be between 0 and 1, or -1 for random)");
419
                    System.exit(2);
420
                  }
421
                i += 1;
422
                continue;
423
              }
424
            else if (args[i].startsWith("--anti-alias="))
425
              {
426
                speed.antialiasFlag = (args[i].substring(args[i].indexOf('=') + 1).equals("on"));
427
                i += 1;
428
                continue;
429
              }
430
            else if (args[i].startsWith("--x-translate="))
431
              {
432
                speed.xtranslate = Integer.parseInt(args[i].substring(args[i].indexOf('=') + 1));
433
                i += 1;
434
                continue;
435
              }
436
            else if (args[i].startsWith("--y-translate="))
437
              {
438
                speed.ytranslate = Integer.parseInt(args[i].substring(args[i].indexOf('=') + 1));
439
                i += 1;
440
                continue;
441
              }
442
            else if (args[i].startsWith("--x-shear="))
443
              {
444
                speed.xshear = Double.parseDouble(args[i].substring(args[i].indexOf('=') + 1));
445
                i += 1;
446
                continue;
447
              }
448
            else if (args[i].startsWith("--y-shear="))
449
              {
450
                speed.yshear = Double.parseDouble(args[i].substring(args[i].indexOf('=') + 1));
451
                i += 1;
452
                continue;
453
              }
454
            else if (args[i].startsWith("--rotate="))
455
              {
456
                speed.rotate = Double.parseDouble(args[i].substring(args[i].indexOf('=') + 1));
457
                i += 1;
458
                continue;
459
              }
460
 
461
            else if (args[i].equals("--"))
462
              {
463
                endOfOptionsFlag = true;
464
                i += 1;
465
                continue;
466
              }
467
            else if (args[i].startsWith("-"))
468
              {
469
                System.err.println("ERROR: Unknown option '" + args[i] + "'!");
470
                System.exit(2);
471
              }
472
          }
473
        StringTokenizer tokenizer = new StringTokenizer(args[i], " +,");
474
        while (tokenizer.hasMoreTokens())
475
          {
476
            String s = tokenizer.nextToken().toLowerCase();
477
            if (s.equals("arc"))
478
              awtTests |= J2DTEST_ARC;
479
            else if (s.equals("cubiccurve"))
480
              awtTests |= J2DTEST_CUBICCURVE;
481
            else if (s.equals("ellipse"))
482
              awtTests |= J2DTEST_ELLIPSE;
483
            else if (s.equals("generalpath"))
484
              awtTests |= J2DTEST_GENERALPATH;
485
            else if (s.equals("line"))
486
              awtTests |= J2DTEST_LINE;
487
            else if (s.equals("quadcurve"))
488
              awtTests |= J2DTEST_QUADCURVE;
489
            else if (s.equals("rectangle"))
490
              awtTests |= J2DTEST_RECTANGLE;
491
            else if (s.equals("roundrectangle"))
492
              awtTests |= J2DTEST_ROUNDRECTANGLE;
493
            else if (s.equals("image"))
494
              awtTests |= J2DTEST_IMAGE;
495
            else
496
              {
497
                System.err.println("Unknown AWT test '" + s + "'!");
498
                System.exit(2);
499
              }
500
          }
501
        i += 1;
502
      }
503
    if (awtTests != J2DTEST_NONE)
504
      speed.awtTests = awtTests;
505
 
506
    // Create graphics.
507
    speed.init();
508
    final Frame frame = new Frame("J2dGraphicsBenchmark");
509
 
510
    frame.addWindowListener(new WindowAdapter()
511
    {
512
      public void windowClosing(WindowEvent e)
513
      {
514
        frame.setVisible(false);
515
        System.exit(0);
516
      }
517
    });
518
 
519
    frame.add(speed, BorderLayout.CENTER);
520
    frame.setSize(speed.screenWidth, speed.screenHeight);
521
    frame.setVisible(true);
522
 
523
    // Insets are correctly set only after the native peer was created.
524
    Insets insets = frame.getInsets();
525
    // The internal size of the frame should be 320x240.
526
    frame.setSize(320 + insets.right + insets.left, 240 + insets.top
527
                                                    + insets.bottom);
528
  }
529
 
530
  private Image loadImage(String imageName)
531
  {
532
    Image result = null;
533
    logger.logp(Level.INFO, "J2dGraphicsBenchmark", "loadImage",
534
                "Loading image: " + imageName);
535
    URL url = getClass().getResource(imageName);
536
    if (url != null)
537
      {
538
        result = Toolkit.getDefaultToolkit().getImage(url);
539
        prepareImage(result, this);
540
      }
541
    else
542
      {
543
        logger.logp(Level.WARNING, "J2dGraphicsBenchmark", "loadImage",
544
                    "Could not locate image resource in class path: "
545
                        + imageName);
546
      }
547
    return result;
548
  }
549
 
550
  private BufferedImage loadBufferedImage(String imageName)
551
  {
552
    BufferedImage result = null;
553
    logger.logp(Level.INFO, "J2dGraphicsBenchmark", "loadImage",
554
                "Loading image: " + imageName);
555
 
556
    // Try to load image out of classpath before trying an absolute filename
557
    URL url = getClass().getResource(imageName);
558
    Image img;
559
    if (url != null)
560
      img = Toolkit.getDefaultToolkit().getImage(url);
561
    else
562
      img = Toolkit.getDefaultToolkit().getImage(imageName);
563
 
564
    if (img != null)
565
      {
566
        // Wait for image to load
567
        try
568
          {
569
            MediaTracker tracker = new MediaTracker(this);
570
            tracker.addImage(img, 1);
571
            tracker.waitForAll();
572
 
573
            prepareImage(img, this);
574
            result = new BufferedImage(img.getWidth(this), img.getHeight(this),
575
                                       BufferedImage.TYPE_INT_RGB);
576
            result.createGraphics().drawImage(img, 0, 0, this);
577
          }
578
        catch (InterruptedException e)
579
          {
580
          }
581
        catch (IllegalArgumentException e)
582
          {
583
          }
584
      }
585
 
586
    if (result == null)
587
      {
588
        logger.logp(Level.WARNING, "J2dGraphicsBenchmark", "loadBufferedImage",
589
                    "Could not locate image resource in class path: "
590
                        + imageName);
591
      }
592
    return result;
593
  }
594
 
595
  /**
596
   * Executes the test methods.
597
   *
598
   * @param g The Graphics2D object that is used to paint.
599
   * @param size The size of the canvas.
600
   */
601
  void runTestSet(Graphics2D g, Dimension size)
602
  {
603
    // Any user-specified options (ie set transforms, rendering hints)
604
    prepareGraphics(g);
605
 
606
    if ((awtTests & J2DTEST_ARC) != 0)
607
      {
608
        test_drawArc(g, size);
609
        test_fillArc(g, size);
610
      }
611
 
612
    if ((awtTests & J2DTEST_CUBICCURVE) != 0)
613
      {
614
        test_drawCubicCurve(g, size);
615
      }
616
 
617
    if ((awtTests & J2DTEST_ELLIPSE) != 0)
618
      {
619
        test_drawEllipse(g, size);
620
        test_fillEllipse(g, size);
621
      }
622
 
623
    if ((awtTests & J2DTEST_GENERALPATH) != 0)
624
      {
625
        // Current implementation doesn't work
626
        test_drawGeneralPath(g, size);
627
        test_fillGeneralPath(g, size);
628
      }
629
 
630
    if ((awtTests & J2DTEST_LINE) != 0)
631
      {
632
        test_drawLine(g, size);
633
      }
634
 
635
    if ((awtTests & J2DTEST_QUADCURVE) != 0)
636
      {
637
        test_drawQuadCurve(g, size);
638
      }
639
 
640
    if ((awtTests & J2DTEST_RECTANGLE) != 0)
641
      {
642
        test_drawRectangle(g, size);
643
        test_fillRectangle(g, size);
644
      }
645
 
646
    if ((awtTests & J2DTEST_ROUNDRECTANGLE) != 0)
647
      {
648
        test_drawRoundRectangle(g, size);
649
        test_fillRoundRectangle(g, size);
650
      }
651
 
652
    if ((awtTests & J2DTEST_IMAGE) != 0)
653
      {
654
        test_drawImage(g, size);
655
        test_drawTransparentImage(g, size);
656
      }
657
  }
658
 
659
  /**
660
   * Reset all graphics settings to the standard, default values
661
   *
662
   * @param g the object to apply settings to
663
   */
664
  private void resetGraphics(Graphics2D g)
665
  {
666
    g.setTransform(new AffineTransform());
667
    g.setStroke(new BasicStroke());
668
    g.setComposite(AlphaComposite.SrcOut);
669
  }
670
 
671
  /**
672
   * Sets initial user graphics options
673
   *
674
   * @param g the object to apply settings to
675
   */
676
  private void prepareGraphics(Graphics2D g)
677
  {
678
    // Transforms
679
    if (affineTransform != null)
680
      g.setTransform(affineTransform);
681
 
682
    else if (xtranslate != 0 || ytranslate != 0 || xshear != 0 || yshear != 0)
683
      {
684
        g.translate(xtranslate, ytranslate);
685
        g.shear(xshear, yshear);
686
      }
687
 
688
    if (rotate > 0)
689
      g.rotate(rotate * Math.PI, screenWidth / 2, screenHeight / 2);
690
 
691
    // Composite (transparency)
692
    if (composite > 0)
693
      {
694
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
695
                                                  composite));
696
      }
697
 
698
    // Textures
699
    if (texture != null)
700
      g.setPaint(new TexturePaint(textureImage,
701
                                  new Rectangle(0, 0, textureImage.getWidth(),
702
                                                textureImage.getHeight())));
703
 
704
    // Anti-alias setting
705
    if (antialiasFlag)
706
      g.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING,
707
                                             RenderingHints.VALUE_ANTIALIAS_ON));
708
    else
709
      g.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING,
710
                                             RenderingHints.VALUE_ANTIALIAS_OFF));
711
  }
712
 
713
  /**
714
   * Gets new random settings
715
   *
716
   * @param g the object to set parameters for
717
   * @param size the screen size
718
   */
719
  private void setRandom(Graphics2D g, Dimension size)
720
  {
721
    // Set colour / paint
722
    if (gradientFlag)
723
      {
724
        Color c1 = new Color((int) (Math.random() * 254) + 1,
725
                             (int) (Math.random() * 254) + 1,
726
                             (int) (Math.random() * 254) + 1);
727
 
728
        Color c2 = new Color((int) (Math.random() * 254) + 1,
729
                             (int) (Math.random() * 254) + 1,
730
                             (int) (Math.random() * 254) + 1);
731
 
732
        g.setPaint(new GradientPaint(0, 0, c1, screenWidth / 5,
733
                                     screenHeight / 5, c2, true));
734
      }
735
 
736
    else if (texture == null)
737
      g.setPaint(new Color((int) (Math.random() * 254) + 1,
738
                           (int) (Math.random() * 254) + 1,
739
                           (int) (Math.random() * 254) + 1));
740
 
741
    // Set stroke width and options
742
    if (strokeFlag)
743
      {
744
        int cap = (int) (Math.random() * 3 + 1);
745
        if (cap == 1)
746
          cap = BasicStroke.CAP_SQUARE;
747
        else if (cap == 2)
748
          cap = BasicStroke.CAP_BUTT;
749
        else
750
          cap = BasicStroke.CAP_ROUND;
751
 
752
        int join = (int) (Math.random() * 3 + 1);
753
        if (join == 1)
754
          join = BasicStroke.JOIN_MITER;
755
        else if (join == 2)
756
          join = BasicStroke.JOIN_BEVEL;
757
        else
758
          join = BasicStroke.JOIN_ROUND;
759
 
760
        float[] dashes = { 10, 10 };
761
        g.setStroke(new BasicStroke((int) (Math.random() * 10), cap, join, 10f,
762
                                    dashes, 0));
763
      }
764
 
765
    // Composite / transparency
766
    if (composite == - 1)
767
      {
768
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
769
                                                  (float) Math.random()));
770
      }
771
 
772
    // Transformations
773
    if (rotate == - 1)
774
      g.rotate(Math.random() * Math.PI * 2);
775
  }
776
 
777
  /**
778
   * Draws random arcs within the given dimensions.
779
   *
780
   * @param g The Graphics2D object that is used to paint.
781
   * @param size The size of the canvas.
782
   */
783
  private void test_drawArc(Graphics2D g, Dimension size)
784
  {
785
    int maxTests = testSize;
786
    int minSize;
787
    long startTime;
788
    long endTime;
789
    minSize = 10;
790
    startTime = System.currentTimeMillis();
791
    for (int i = 0; i < maxTests; i += 1)
792
      {
793
        setRandom(g, size);
794
        int x = (int) (Math.random() * (size.width - minSize + 1));
795
        int y = (int) (Math.random() * (size.height - minSize + 1));
796
        int width = (int) (Math.random() * (size.width - x - minSize) + minSize);
797
        int height = (int) (Math.random() * (size.height - y - minSize) + minSize);
798
        int startAngle = (int) (Math.random() * 360);
799
        int arcAngle = (int) (Math.random() * 360 - startAngle);
800
 
801
        Arc2D arc = new Arc2D.Double(x, y, width, height, startAngle, arcAngle,
802
                                     Arc2D.OPEN);
803
        g.draw(arc);
804
      }
805
    endTime = System.currentTimeMillis();
806
    recordTest("draw(Arc2D.Double) " + maxTests + " times",
807
               (endTime - startTime));
808
  }
809
 
810
  /**
811
   * Draws random filled arcs within the given dimensions.
812
   *
813
   * @param g The Graphics2D object that is used to paint.
814
   * @param size The size of the canvas.
815
   */
816
  private void test_fillArc(Graphics2D g, Dimension size)
817
  {
818
    int maxTests = testSize;
819
    int minSize;
820
    long startTime;
821
    long endTime;
822
    minSize = 10;
823
    startTime = System.currentTimeMillis();
824
    for (int i = 0; i < maxTests; i += 1)
825
      {
826
        setRandom(g, size);
827
        int x = (int) (Math.random() * (size.width - minSize + 1));
828
        int y = (int) (Math.random() * (size.height - minSize + 1));
829
        int width = (int) (Math.random() * (size.width - x - minSize) + minSize);
830
        int height = (int) (Math.random() * (size.height - y - minSize) + minSize);
831
        int startAngle = (int) (Math.random() * 360);
832
        int arcAngle = (int) (Math.random() * 360);
833
 
834
        Arc2D arc = new Arc2D.Double(x, y, width, height, startAngle, arcAngle,
835
                                     Arc2D.OPEN);
836
        g.fill(arc);
837
      }
838
    endTime = System.currentTimeMillis();
839
    recordTest("fill(Arc2D.Double) " + maxTests + " times",
840
               (endTime - startTime));
841
  }
842
 
843
  /**
844
   * Draws random cubic curves within the given dimensions.
845
   *
846
   * @param g The Graphics2D object that is used to paint.
847
   * @param size The size of the canvas.
848
   */
849
  private void test_drawCubicCurve(Graphics2D g, Dimension size)
850
  {
851
    int maxTests = testSize;
852
    int minSize = 10;
853
    long startTime = System.currentTimeMillis();
854
    for (int i = 0; i < maxTests; i += 1)
855
      {
856
        setRandom(g, size);
857
        int x1 = (int) (Math.random() * (size.width - minSize));
858
        int y1 = (int) (Math.random() * (size.height - minSize));
859
        int xc1 = (int) (Math.random() * (size.width - minSize));
860
        int yc1 = (int) (Math.random() * (size.height - minSize));
861
        int xc2 = (int) (Math.random() * (size.width - minSize));
862
        int yc2 = (int) (Math.random() * (size.height - minSize));
863
        int x2 = (int) (Math.random() * (size.width - minSize));
864
        int y2 = (int) (Math.random() * (size.height - minSize));
865
 
866
        CubicCurve2D curve = new CubicCurve2D.Double(x1, y1, xc1, yc1, xc2,
867
                                                     yc2, x2, y2);
868
        g.draw(curve);
869
      }
870
    long endTime = System.currentTimeMillis();
871
    recordTest("draw(CubicCurve2D.Double) " + maxTests + " times",
872
               (endTime - startTime));
873
  }
874
 
875
  /**
876
   * Draws random ellipses within the given dimensions.
877
   *
878
   * @param g The Graphics2D object that is used to paint.
879
   * @param size The size of the canvas.
880
   */
881
  private void test_drawEllipse(Graphics2D g, Dimension size)
882
  {
883
    int maxTests = testSize;
884
    int minSize = 10;
885
    long startTime = System.currentTimeMillis();
886
    for (int i = 0; i < maxTests; i += 1)
887
      {
888
        setRandom(g, size);
889
        int x1 = (int) (Math.random() * (size.width - minSize));
890
        int y1 = (int) (Math.random() * (size.height - minSize));
891
        int x2 = (int) (Math.random() * (size.width - minSize));
892
        int y2 = (int) (Math.random() * (size.height - minSize));
893
        Ellipse2D ellipse = new Ellipse2D.Double(x1, y1, x2, y2);
894
        g.draw(ellipse);
895
      }
896
    long endTime = System.currentTimeMillis();
897
    recordTest("draw(Ellipse.Double) " + maxTests + " times",
898
               (endTime - startTime));
899
  }
900
 
901
  /**
902
   * Draws random ellipses within the given dimensions.
903
   *
904
   * @param g The Graphics2D object that is used to paint.
905
   * @param size The size of the canvas.
906
   */
907
  private void test_fillEllipse(Graphics2D g, Dimension size)
908
  {
909
    int maxTests = testSize;
910
    int minSize = 10;
911
    long startTime = System.currentTimeMillis();
912
    for (int i = 0; i < maxTests; i += 1)
913
      {
914
        setRandom(g, size);
915
        int x1 = (int) (Math.random() * (size.width - minSize));
916
        int y1 = (int) (Math.random() * (size.height - minSize));
917
        int x2 = (int) (Math.random() * (size.width - minSize));
918
        int y2 = (int) (Math.random() * (size.height - minSize));
919
        Ellipse2D ellipse = new Ellipse2D.Double(x1, y1, x2, y2);
920
        g.fill(ellipse);
921
      }
922
    long endTime = System.currentTimeMillis();
923
    recordTest("fill(Ellipse.Double) " + maxTests + " times",
924
               (endTime - startTime));
925
  }
926
 
927
  // TODO: fix the GeneralPath methods.
928
  /**
929
   * Draws random polygons within the given dimensions.
930
   *
931
   * @param g The Graphics2D object that is used to paint.
932
   * @param size The size of the canvas.
933
   */
934
  private void test_drawGeneralPath(Graphics2D g, Dimension size)
935
  {
936
    int maxTests = testSize;
937
    long startTime = System.currentTimeMillis();
938
 
939
    for (int i = 0; i < maxTests; i += 1)
940
      {
941
        setRandom(g, size);
942
        int points = (int) (Math.random() * 6) + 2;
943
        GeneralPath shape = new GeneralPath();
944
        shape.moveTo((float) Math.random() * (size.width),
945
                     (float) Math.random() * (size.height));
946
        for (int j = 0; j < points; j += 1)
947
          {
948
            shape.lineTo((float) (Math.random() * (size.width)),
949
                         (float) (Math.random() * (size.height)));
950
          }
951
        g.draw(shape);
952
      }
953
    long endTime = System.currentTimeMillis();
954
    recordTest("draw(GeneralPath) " + maxTests + " times",
955
               (endTime - startTime));
956
  }
957
 
958
  /**
959
   * Draws random filled polygons within the given dimensions.
960
   *
961
   * @param g The Graphics2D object that is used to paint.
962
   * @param size The size of the canvas.
963
   */
964
  private void test_fillGeneralPath(Graphics2D g, Dimension size)
965
  {
966
    int maxTests = testSize;
967
    long startTime = System.currentTimeMillis();
968
 
969
    GeneralPath shape = new GeneralPath();
970
    shape.moveTo((float) Math.random() * (size.width), (float) Math.random()
971
                                                       * (size.height));
972
 
973
    for (int i = 0; i < maxTests; i += 1)
974
      {
975
        setRandom(g, size);
976
        int points = (int) (Math.random() * 6) + 2;
977
        for (int j = 0; j < points; j += 1)
978
          {
979
            shape.lineTo((float) (Math.random() * (size.width)),
980
                         (float) (Math.random() * (size.height)));
981
          }
982
        g.fill(shape);
983
      }
984
    long endTime = System.currentTimeMillis();
985
    recordTest("fill(GeneralPath) " + maxTests + " times",
986
               (endTime - startTime));
987
  }
988
 
989
  /**
990
   * Draws random lines within the given dimensions.
991
   *
992
   * @param g The Graphics2D object that is used to paint.
993
   * @param size The size of the canvas.
994
   */
995
  private void test_drawLine(Graphics2D g, Dimension size)
996
  {
997
    int maxTests = testSize;
998
    int minSize = 10;
999
    long startTime = System.currentTimeMillis();
1000
    for (int i = 0; i < maxTests; i += 1)
1001
      {
1002
        setRandom(g, size);
1003
        int x1 = (int) (Math.random() * (size.width - minSize));
1004
        int y1 = (int) (Math.random() * (size.height - minSize));
1005
        int x2 = (int) (Math.random() * (size.width - minSize));
1006
        int y2 = (int) (Math.random() * (size.height - minSize));
1007
        Line2D line = new Line2D.Double(x1, y1, x2, y2);
1008
        g.draw(line);
1009
      }
1010
    long endTime = System.currentTimeMillis();
1011
    recordTest("draw(Line2D.Double) " + maxTests + " times",
1012
               (endTime - startTime));
1013
  }
1014
 
1015
  /**
1016
   * Draws random quadratic curves within the given dimensions.
1017
   *
1018
   * @param g The Graphics2D object that is used to paint.
1019
   * @param size The size of the canvas.
1020
   */
1021
  private void test_drawQuadCurve(Graphics2D g, Dimension size)
1022
  {
1023
    int maxTests = testSize;
1024
    int minSize = 10;
1025
    long startTime = System.currentTimeMillis();
1026
    for (int i = 0; i < maxTests; i += 1)
1027
      {
1028
        setRandom(g, size);
1029
        int x1 = (int) (Math.random() * (size.width - minSize));
1030
        int y1 = (int) (Math.random() * (size.height - minSize));
1031
        int xc = (int) (Math.random() * (size.width - minSize));
1032
        int yc = (int) (Math.random() * (size.height - minSize));
1033
        int x2 = (int) (Math.random() * (size.width - minSize));
1034
        int y2 = (int) (Math.random() * (size.height - minSize));
1035
 
1036
        QuadCurve2D curve = new QuadCurve2D.Double(x1, y1, xc, yc, x2, y2);
1037
        g.draw(curve);
1038
      }
1039
    long endTime = System.currentTimeMillis();
1040
    recordTest("draw(QuadCurve2D.Double) " + maxTests + " times",
1041
               (endTime - startTime));
1042
  }
1043
 
1044
  /**
1045
   * Draws random rectangles within the given dimensions.
1046
   *
1047
   * @param g The Graphics2D object that is used to paint.
1048
   * @param size The size of the canvas.
1049
   */
1050
  private void test_drawRectangle(Graphics2D g, Dimension size)
1051
  {
1052
    int maxTests = testSize;
1053
    int minSize = 10;
1054
    long startTime = System.currentTimeMillis();
1055
    for (int i = 0; i < maxTests; i += 1)
1056
      {
1057
        setRandom(g, size);
1058
        int x1 = (int) (Math.random() * (size.width - minSize));
1059
        int y1 = (int) (Math.random() * (size.height - minSize));
1060
        int x2 = (int) (Math.random() * (size.width - minSize));
1061
        int y2 = (int) (Math.random() * (size.height - minSize));
1062
        Rectangle2D rect = new Rectangle2D.Double(x1, y1, x2, y2);
1063
        g.draw(rect);
1064
      }
1065
    long endTime = System.currentTimeMillis();
1066
    recordTest("draw(Rectangle.Double) " + maxTests + " times",
1067
               (endTime - startTime));
1068
  }
1069
 
1070
  /**
1071
   * Draws random rectangles within the given dimensions.
1072
   *
1073
   * @param g The Graphics2D object that is used to paint.
1074
   * @param size The size of the canvas.
1075
   */
1076
  private void test_fillRectangle(Graphics2D g, Dimension size)
1077
  {
1078
    int maxTests = testSize;
1079
    int minSize = 10;
1080
    long startTime = System.currentTimeMillis();
1081
    for (int i = 0; i < maxTests; i += 1)
1082
      {
1083
        setRandom(g, size);
1084
        int x1 = (int) (Math.random() * (size.width - minSize));
1085
        int y1 = (int) (Math.random() * (size.height - minSize));
1086
        int x2 = (int) (Math.random() * (size.width - minSize));
1087
        int y2 = (int) (Math.random() * (size.height - minSize));
1088
        Rectangle2D rect = new Rectangle2D.Double(x1, y1, x2, y2);
1089
        g.fill(rect);
1090
      }
1091
    long endTime = System.currentTimeMillis();
1092
    recordTest("fill(Rectangle.Double) " + maxTests + " times",
1093
               (endTime - startTime));
1094
  }
1095
 
1096
  /**
1097
   * Draws random rounded rectangles within the given dimensions.
1098
   *
1099
   * @param g The Graphics2D object that is used to paint.
1100
   * @param size The size of the canvas.
1101
   */
1102
  private void test_drawRoundRectangle(Graphics2D g, Dimension size)
1103
  {
1104
    int maxTests = testSize;
1105
    int minSize;
1106
    long startTime;
1107
    long endTime;
1108
    minSize = 10;
1109
    startTime = System.currentTimeMillis();
1110
    for (int i = 0; i < maxTests; i += 1)
1111
      {
1112
        setRandom(g, size);
1113
        int x = (int) (Math.random() * (size.width - minSize + 1));
1114
        int y = (int) (Math.random() * (size.height - minSize + 1));
1115
        int width = (int) (Math.random() * (size.width - x - minSize) + minSize);
1116
        int height = (int) (Math.random() * (size.height - y - minSize) + minSize);
1117
        int arcWidth = (int) (Math.random() * (width - 1) + 1);
1118
        int arcHeight = (int) (Math.random() * (height - 1) + 5);
1119
        RoundRectangle2D rect = new RoundRectangle2D.Double(x, y, width,
1120
                                                            height, arcWidth,
1121
                                                            arcHeight);
1122
        g.draw(rect);
1123
      }
1124
    endTime = System.currentTimeMillis();
1125
    recordTest("draw(RoundRectangle.Double) " + maxTests + " times",
1126
               (endTime - startTime));
1127
  }
1128
 
1129
  /**
1130
   * Draws random filled rounded rectangles within the given dimensions.
1131
   *
1132
   * @param g The Graphics2D object that is used to paint.
1133
   * @param size The size of the canvas.
1134
   */
1135
  private void test_fillRoundRectangle(Graphics2D g, Dimension size)
1136
  {
1137
    int maxTests = testSize;
1138
    int minSize;
1139
    long startTime;
1140
    long endTime;
1141
    minSize = 10;
1142
    startTime = System.currentTimeMillis();
1143
    for (int i = 0; i < maxTests; i += 1)
1144
      {
1145
        setRandom(g, size);
1146
        int x = (int) (Math.random() * (size.width - minSize + 1));
1147
        int y = (int) (Math.random() * (size.height - minSize + 1));
1148
        int width = (int) (Math.random() * (size.width - x - minSize) + minSize);
1149
        int height = (int) (Math.random() * (size.height - y - minSize) + minSize);
1150
        int arcWidth = (int) (Math.random() * (width - 1) + 1);
1151
        int arcHeight = (int) (Math.random() * (height - 1) + 5);
1152
        RoundRectangle2D rect = new RoundRectangle2D.Double(x, y, width,
1153
                                                            height, arcWidth,
1154
                                                            arcHeight);
1155
        g.fill(rect);
1156
      }
1157
    endTime = System.currentTimeMillis();
1158
    recordTest("fill(RoundRectangle.Double) " + maxTests + " times",
1159
               (endTime - startTime));
1160
  }
1161
 
1162
  /**
1163
   * Draws random images within the given dimensions.
1164
   *
1165
   * @param g The Graphics2D object that is used to paint.
1166
   * @param size The size of the canvas.
1167
   */
1168
  private void test_drawImage(Graphics2D g, Dimension size)
1169
  {
1170
    if (gifTestImage == null)
1171
      {
1172
        logger.logp(Level.WARNING, "J2dGraphicsBenchmark", "runTestSet",
1173
                    "Skipping 'test_drawImage' due to missing resource.");
1174
        return;
1175
      }
1176
 
1177
    int maxTests = testSize / 2;
1178
    if (maxTests == 0)
1179
      maxTests = 1;
1180
    int imageWidth = gifTestImage.getWidth(this);
1181
    int imageHeight = gifTestImage.getHeight(this);
1182
    long startTime = System.currentTimeMillis();
1183
    for (int i = 0; i < maxTests; i += 1)
1184
      {
1185
        setRandom(g, size);
1186
        int x = (int) (Math.random() * (size.width - imageWidth + 1));
1187
        int y = (int) (Math.random() * (size.height - imageHeight + 1));
1188
        g.drawImage(gifTestImage, x, y, this);
1189
      }
1190
    long endTime = System.currentTimeMillis();
1191
    recordTest("drawImage " + maxTests + " times", (endTime - startTime));
1192
  }
1193
 
1194
  /**
1195
   * Draws random transparent images within the given dimensions.
1196
   *
1197
   * @param g The Graphics object that is used to paint.
1198
   * @param size The size of the canvas.
1199
   */
1200
  private void test_drawTransparentImage(Graphics2D g, Dimension size)
1201
  {
1202
    if (pngTestImage == null)
1203
      {
1204
        logger.logp(Level.WARNING, "AicasGraphicsBenchmark", "runTestSet",
1205
                    "Skipping 'drawTransparentImage' due to missing resource.");
1206
        return;
1207
      }
1208
 
1209
    int maxTests = testSize / 5;
1210
    if (maxTests == 0)
1211
      maxTests = 1;
1212
    int imageWidth = pngTestImage.getWidth(this);
1213
    int imageHeight = pngTestImage.getHeight(this);
1214
    long startTime = System.currentTimeMillis();
1215
    for (int i = 0; i < maxTests; i += 1)
1216
      {
1217
        setRandom(g, size);
1218
        int x = (int) (Math.random() * (size.width - imageWidth + 1));
1219
        int y = (int) (Math.random() * (size.height - imageHeight + 1));
1220
        g.drawImage(pngTestImage, x, y, this);
1221
      }
1222
    long endTime = System.currentTimeMillis();
1223
    recordTest("draw transparent image " + maxTests + " times",
1224
               (endTime - startTime));
1225
  }
1226
 
1227
  private class GraphicsTest
1228
      extends Canvas
1229
      implements Runnable
1230
  {
1231
    Thread paintThread;
1232
 
1233
    boolean done = false;
1234
 
1235
    boolean doPaint = false;
1236
 
1237
    boolean withClipping = false;
1238
 
1239
    public GraphicsTest()
1240
    {
1241
      paintThread = new Thread(this);
1242
      paintThread.start();
1243
    }
1244
 
1245
    public void run()
1246
    {
1247
      int runCount = 0;
1248
      while (! done)
1249
        {
1250
          runCount++;
1251
 
1252
          try
1253
            {
1254
              synchronized (this)
1255
                {
1256
                  while (! doPaint)
1257
                    {
1258
                      try
1259
                        {
1260
                          wait(200);
1261
                        }
1262
                      catch (InterruptedException exception)
1263
                        {
1264
                          return;
1265
                        }
1266
                    }
1267
                }
1268
 
1269
              // if (iterations != 0)
1270
              // System.out.println("--- run...("
1271
              // + runCount
1272
              // + "/"
1273
              // + iterations
1274
              // + ") ------------------------------------------------------");
1275
 
1276
              Graphics g = getGraphics();
1277
              Dimension size = getSize();
1278
 
1279
              if (singleBufferFlag)
1280
                {
1281
                  logger.logp(Level.INFO, "J2dGraphicsBenchmark.GraphicsTest",
1282
                              "run",
1283
                              "Start testing non-double-buffered drawing");
1284
 
1285
                  if (noClippingFlag)
1286
                    runSet_noClipping((Graphics2D) g, size, runCount);
1287
 
1288
                  if (withClippingFlag)
1289
                    runSet_withClipping((Graphics2D) g, size, runCount);
1290
 
1291
                  if (zeroClippingFlag)
1292
                    runSet_zeroClipping((Graphics2D) g, size, runCount);
1293
 
1294
                  g.dispose();
1295
                }
1296
 
1297
              if (doubleBufferFlag)
1298
                {
1299
                  logger.logp(Level.INFO, "J2dGraphicsBenchmark.GraphicsTest",
1300
                              "run", "Start testing double-buffered drawing");
1301
                  Graphics canvas = getGraphics();
1302
                  Image doublebuffer = createImage(size.width, size.height);
1303
 
1304
                  if (noClippingFlag)
1305
                    {
1306
                      g = doublebuffer.getGraphics();
1307
                      runSet_noClipping((Graphics2D) g, size,
1308
                                        "double buffering", runCount);
1309
                      g.dispose();
1310
                      canvas.drawImage(doublebuffer, 0, 0, this);
1311
                    }
1312
 
1313
                  if (withClippingFlag)
1314
                    {
1315
                      g = doublebuffer.getGraphics();
1316
                      runSet_withClipping((Graphics2D) g, size,
1317
                                          "double buffering", runCount);
1318
                      g.dispose();
1319
                      canvas.drawImage(doublebuffer, 0, 0, this);
1320
                    }
1321
 
1322
                  if (zeroClippingFlag)
1323
                    {
1324
                      g = doublebuffer.getGraphics();
1325
                      runSet_zeroClipping((Graphics2D) g, size,
1326
                                          "double buffering", runCount);
1327
                      g.dispose();
1328
                      canvas.drawImage(doublebuffer, 0, 0, this);
1329
                      canvas.dispose();
1330
                    }
1331
                }
1332
 
1333
              printReport();
1334
 
1335
              if (iterations != 1)
1336
                {
1337
                  if (iterations != - 1)
1338
                    iterations--;
1339
                }
1340
              else
1341
                {
1342
                  // System.out.println("--- done
1343
                  // --------------------------------------------------------");
1344
                  synchronized (this)
1345
                    {
1346
                      doPaint = false;
1347
                    }
1348
                  done = true;
1349
                }
1350
            }
1351
          catch (Error error)
1352
            {
1353
              System.err.println("Error: " + error);
1354
              System.exit(129);
1355
            }
1356
        }
1357
      testComplete();
1358
    }
1359
 
1360
    private void runSet_zeroClipping(Graphics2D g, Dimension size, int runCount)
1361
    {
1362
      runSet_zeroClipping(g, size, "", runCount);
1363
    }
1364
 
1365
    private void runSet_zeroClipping(Graphics2D g, Dimension size,
1366
                                     String context, int runCount)
1367
    {
1368
      int clipped_width;
1369
      int clipped_height;
1370
      int clipped_x;
1371
      int clipped_y;
1372
 
1373
      clipped_width = 0;
1374
      clipped_height = 0;
1375
      clipped_x = (size.width) / 2;
1376
      clipped_y = (size.height) / 2;
1377
 
1378
      // Reset any transforms from past tests
1379
      resetGraphics(g);
1380
 
1381
      Rectangle fullWindow = new Rectangle(0, 0, size.width, size.height);
1382
      g.setClip(fullWindow);
1383
      g.setPaint(Color.BLACK);
1384
      g.fill(fullWindow);
1385
 
1386
      Rectangle windowBorder = new Rectangle(0, 0, size.width - 1,
1387
                                             size.width - 1);
1388
      g.setPaint(Color.WHITE);
1389
      g.draw(windowBorder);
1390
 
1391
      Rectangle innerBorder = new Rectangle(clipped_x - 1, clipped_y - 1,
1392
                                            clipped_width + 2,
1393
                                            clipped_height + 2);
1394
      g.fill(innerBorder);
1395
 
1396
      Rectangle innerBox = new Rectangle(clipped_x, clipped_y, clipped_width,
1397
                                         clipped_height);
1398
      g.clip(innerBox);
1399
      g.setPaint(Color.BLACK);
1400
      g.fill(fullWindow);
1401
 
1402
      if (context.equals(""))
1403
        setTestContext("(" + runCount + ") clipping to zero");
1404
      else
1405
        setTestContext("(" + runCount + ") clipping to zero (" + context + ")");
1406
 
1407
      runTestSet(g, size);
1408
    }
1409
 
1410
    private void runSet_withClipping(Graphics2D g, Dimension size, int runCount)
1411
    {
1412
      runSet_withClipping(g, size, "", runCount);
1413
    }
1414
 
1415
    private void runSet_withClipping(Graphics2D g, Dimension size,
1416
                                     String context, int runCount)
1417
    {
1418
      int clipped_width = 2 * size.width / 3;
1419
      int clipped_height = 2 * size.height / 3;
1420
      int clipped_x = (size.width - clipped_width) / 2;
1421
      int clipped_y = (size.height - clipped_height) / 2;
1422
 
1423
      // Reset any transforms from past tests
1424
      resetGraphics(g);
1425
 
1426
      Rectangle fullWindow = new Rectangle(0, 0, size.width, size.height);
1427
      g.setClip(fullWindow);
1428
 
1429
      g.setPaint(Color.BLACK);
1430
      g.fill(fullWindow);
1431
 
1432
      Rectangle windowBorder = new Rectangle(0, 0, size.width - 1,
1433
                                             size.height - 1);
1434
      g.setPaint(Color.GREEN);
1435
      g.draw(windowBorder);
1436
 
1437
      Rectangle innerBorder = new Rectangle(clipped_x - 1, clipped_y - 1,
1438
                                            clipped_width + 2,
1439
                                            clipped_height + 2);
1440
      g.setPaint(Color.WHITE);
1441
      g.fill(innerBorder);
1442
 
1443
      Rectangle innerBox = new Rectangle(clipped_x, clipped_y, clipped_width,
1444
                                         clipped_height);
1445
      g.clip(innerBox);
1446
 
1447
      g.setPaint(Color.BLACK);
1448
      g.fill(fullWindow);
1449
 
1450
      if (context.equals(""))
1451
        setTestContext("(" + runCount + ") with clipping ");
1452
      else
1453
        setTestContext("(" + runCount + ") with clipping (" + context + ")");
1454
 
1455
      runTestSet(g, size);
1456
    }
1457
 
1458
    private void runSet_noClipping(Graphics2D g, Dimension size, int runCount)
1459
    {
1460
      runSet_noClipping(g, size, "", runCount);
1461
    }
1462
 
1463
    private void runSet_noClipping(Graphics2D g, Dimension size,
1464
                                   String context, int runCount)
1465
    {
1466
      // Reset any transforms from past tests
1467
      resetGraphics(g);
1468
 
1469
      Rectangle fullWindow = new Rectangle(0, 0, size.width, size.height);
1470
      g.setPaint(Color.BLACK);
1471
      g.fill(fullWindow);
1472
 
1473
      if (context.equals(""))
1474
        setTestContext("(" + runCount + ") without clipping");
1475
      else
1476
        setTestContext("(" + runCount + ") without clipping (" + context + ")");
1477
 
1478
      runTestSet(g, size);
1479
    }
1480
 
1481
    public void paint(Graphics g)
1482
    {
1483
      synchronized (this)
1484
        {
1485
          doPaint = true;
1486
          notify();
1487
        }
1488
    }
1489
  }
1490
}
1491
 
1492
class TestContext
1493
{
1494
}
1495
 
1496
class TestSet
1497
{
1498
  private Map testsMap = new TreeMap();
1499
 
1500
  public void putTest(String testName, TestRecorder recoder)
1501
  {
1502
    testsMap.put(testName, recoder);
1503
  }
1504
 
1505
  public TestRecorder getTest(String testName)
1506
  {
1507
    return (TestRecorder) testsMap.get(testName);
1508
  }
1509
 
1510
  public Iterator testIterator()
1511
  {
1512
    return testsMap.keySet().iterator();
1513
  }
1514
}
1515
 
1516
class TestRecorder
1517
{
1518
  String test;
1519
 
1520
  long totalTime = 0;
1521
 
1522
  long minTime = Long.MAX_VALUE;
1523
 
1524
  long maxTime = Long.MIN_VALUE;
1525
 
1526
  int runCount = 0;
1527
 
1528
  /**
1529
   * @return Returns the maxTime.
1530
   */
1531
  public final long getMaxTime()
1532
  {
1533
    return maxTime;
1534
  }
1535
 
1536
  /**
1537
   * @return Returns the minTime.
1538
   */
1539
  public final long getMinTime()
1540
  {
1541
    return minTime;
1542
  }
1543
 
1544
  /**
1545
   * @return Returns the test name.
1546
   */
1547
  public final String getTestName()
1548
  {
1549
    return test;
1550
  }
1551
 
1552
  public final long getAverage()
1553
  {
1554
    return (totalTime / runCount);
1555
  }
1556
 
1557
  public TestRecorder(String testName)
1558
  {
1559
    test = testName;
1560
  }
1561
 
1562
  public void addRun(long time)
1563
  {
1564
    totalTime += time;
1565
    if (minTime > time)
1566
      minTime = time;
1567
    if (maxTime < time)
1568
      maxTime = time;
1569
    runCount += 1;
1570
  }
1571
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.