1 /* AnimationApplet.java -- An example of an old-style AWT applet
2 Copyright (C) 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath examples.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 package gnu.classpath.examples.awt;
23 import java.awt.BorderLayout;
24 import java.awt.Canvas;
25 import java.awt.Color;
26 import java.awt.Dimension;
27 import java.awt.Frame;
28 import java.awt.Graphics;
29 import java.awt.Image;
30 import java.awt.Insets;
31 import java.awt.Label;
32 import java.awt.Panel;
33 import java.awt.Toolkit;
34 import java.awt.event.WindowAdapter;
35 import java.awt.event.WindowEvent;
37 import java.util.Iterator;
39 import java.util.StringTokenizer;
40 import java.util.TreeMap;
41 import java.util.logging.Level;
42 import java.util.logging.Logger;
44 public class AicasGraphicsBenchmark extends Panel
47 * Default number of test-iterations.
49 private static final int DEFAULT_TEST_SIZE = 1000;
52 * Default screen size.
54 private static final int DEFAULT_SCREEN_WIDTH = 320;
55 private static final int DEFAULT_SCREEN_HEIGHT = 240;
60 private static final int AWTTEST_LINES = 1 << 0;
61 private static final int AWTTEST_RECT = 1 << 1;
62 private static final int AWTTEST_POLYLINE = 1 << 2;
63 private static final int AWTTEST_POLYGON = 1 << 3;
64 private static final int AWTTEST_ARC = 1 << 4;
65 private static final int AWTTEST_OVAL = 1 << 5;
66 private static final int AWTTEST_ROUNDRECT = 1 << 6;
67 private static final int AWTTEST_STRING = 1 << 7;
68 private static final int AWTTEST_TRANSPARENTIMAGE = 1 << 8;
69 private static final int AWTTEST_IMAGE = 1 << 9;
71 private static final int AWTTEST_NONE = 0;
72 private static final int AWTTEST_ALL = AWTTEST_LINES
80 | AWTTEST_TRANSPARENTIMAGE
85 private int screenWidth = DEFAULT_SCREEN_WIDTH;
86 private int screenHeight = DEFAULT_SCREEN_HEIGHT;
87 boolean doubleBufferFlag = true;
88 private int awtTests = AWTTEST_ALL;
90 private Label testLabel;
92 private String testContext = "";
94 Logger logger = Logger.getLogger("AicasGraphicsBenchmark");
96 private Image pngTestImage;
97 private Image gifTestImage;
99 private TestSet testSetMap = new TestSet();
101 public AicasGraphicsBenchmark()
103 pngTestImage = loadImage("../icons/aicas.png");
104 gifTestImage = loadImage("../icons/palme.gif");
106 setLayout(new BorderLayout());
107 testLabel = new Label();
108 add(testLabel,BorderLayout.NORTH);
109 add(new GraphicsTest(),BorderLayout.CENTER);
112 void setTestContext(String testName)
114 logger.logp(Level.INFO, "AicasGraphicsBenchmark", "recordTest",
115 "--- Starting new test context: " + testName);
116 testContext = testName;
117 testLabel.setText(testName);
120 private void recordTest(String testName, long time)
122 logger.logp(Level.INFO, "AicasGraphicsBenchmark", "recordTest",
123 testContext + ": " + testName + " duration (ms): " + time);
124 TestRecorder recorder = testSetMap.getTest(testName);
125 if (recorder == null)
127 recorder = new TestRecorder(testName);
128 testSetMap.putTest(testName,recorder);
130 recorder.addRun(time);
135 for (Iterator i = testSetMap.testIterator(); i.hasNext(); )
137 TestRecorder recorder = testSetMap.getTest((String)i.next());
138 System.out.println("TEST " + recorder.getTestName() + ": average "
139 + recorder.getAverage() + "ms ["
140 + recorder.getMinTime() + "-" + recorder.getMaxTime()
145 public static void main(String[] args)
149 boolean endOfOptionsFlag;
150 AicasGraphicsBenchmark speed= new AicasGraphicsBenchmark();
154 endOfOptionsFlag = false;
155 awtTests = AWTTEST_NONE;
156 while (i < args.length)
158 if (!endOfOptionsFlag)
160 if (args[i].equals("--help") || args[i].equals("-help")
161 || args[i].equals("-h"))
163 System.out.println("Usage: AicasGraphicsBenchmark [<options>] [<test> ...]");
164 System.out.println("");
165 System.out.println("Options: -i|--iterations=<n|-1> - number of iterations (-1 is infinite)");
166 System.out.println(" -w|--width=<n> - screen width; default "+DEFAULT_SCREEN_WIDTH);
167 System.out.println(" -h|--height=<n> - screen height; default "+DEFAULT_SCREEN_HEIGHT);
168 System.out.println(" -n|--noDoubleBuffer - disable double-buffering test");
169 System.out.println("");
170 System.out.println("Tests: line");
171 System.out.println(" rect");
172 System.out.println(" polyline");
173 System.out.println(" polygon");
174 System.out.println(" arc");
175 System.out.println(" oval");
176 System.out.println(" roundrect");
177 System.out.println(" string");
178 System.out.println(" transparentimage");
179 System.out.println(" image");
182 else if ((args[i].startsWith("-i=")
183 || args[i].startsWith("--iterations=")))
186 Integer.parseInt(args[i].substring(args[i].indexOf('=') + 1));
190 else if ((args[i].equals("-i") || args[i].equals("--iterations")))
192 if ((i + 1) >= args.length)
194 System.err.println("ERROR: No argument given for option '"
198 speed.iterations = Integer.parseInt(args[i + 1]);
202 else if ((args[i].startsWith("-w=")
203 || args[i].startsWith("--width=")))
206 Integer.parseInt(args[i].substring(args[i].indexOf('=') + 1));
210 else if ((args[i].equals("-w") || args[i].equals("--width")))
212 if ((i + 1) >= args.length)
214 System.err.println("ERROR: No argument given for option '"
218 speed.screenWidth = Integer.parseInt(args[i + 1]);
222 else if ((args[i].startsWith("-h=")
223 || args[i].startsWith("--height=")))
226 Integer.parseInt(args[i].substring(args[i].indexOf('=') + 1));
230 else if ((args[i].equals("-h") || args[i].equals("--height")))
232 if ((i+1) >= args.length)
234 System.err.println("ERROR: No argument given for option '"
238 speed.screenHeight = Integer.parseInt(args[i + 1]);
242 else if ((args[i].equals("-n")
243 || args[i].equals("--noDoubleBuffer")))
245 speed.doubleBufferFlag = false;
249 else if (args[i].equals("--"))
251 endOfOptionsFlag = true;
255 else if (args[i].startsWith("-"))
257 System.err.println("ERROR: Unknown option '" + args[i] + "'!");
261 StringTokenizer tokenizer = new StringTokenizer(args[i], " +,");
262 while (tokenizer.hasMoreTokens())
264 String s = tokenizer.nextToken().toLowerCase();
265 if (s.equals("line"))
266 awtTests |= AWTTEST_LINES;
267 else if (s.equals("rect"))
268 awtTests |= AWTTEST_RECT;
269 else if (s.equals("polyline"))
270 awtTests |= AWTTEST_POLYLINE;
271 else if (s.equals("polygon"))
272 awtTests |= AWTTEST_POLYGON;
273 else if (s.equals("arc"))
274 awtTests |= AWTTEST_ARC;
275 else if (s.equals("oval"))
276 awtTests |= AWTTEST_OVAL;
277 else if (s.equals("roundrect"))
278 awtTests |= AWTTEST_ROUNDRECT;
279 else if (s.equals("string"))
280 awtTests |= AWTTEST_STRING;
281 else if (s.equals("transparentimage"))
282 awtTests |= AWTTEST_TRANSPARENTIMAGE;
283 else if (s.equals("image"))
284 awtTests |= AWTTEST_IMAGE;
287 System.err.println("Unknown AWT test '" + s + "'!");
293 if (awtTests != AWTTEST_NONE)
294 speed.awtTests = awtTests;
297 final Frame frame = new Frame("AicasGraphicsBenchmark");
299 frame.addWindowListener(new WindowAdapter()
301 public void windowClosing(WindowEvent e)
303 frame.setVisible(false);
308 frame.add(speed,BorderLayout.CENTER);
309 frame.setSize(speed.screenWidth,speed.screenHeight);
310 frame.setVisible(true);
312 // Insets are correctly set only after the native peer was created.
313 Insets insets = frame.getInsets();
314 // The internal size of the frame should be 320x240.
315 frame.setSize(320 + insets.right + insets.left,
316 240 + insets.top + insets.bottom);
319 private Image loadImage(String imageName)
322 logger.logp(Level.INFO, "AicasGraphicsBenchmark", "loadImage",
323 "Loading image: " + imageName);
324 URL url = getClass().getResource(imageName);
327 result = Toolkit.getDefaultToolkit().getImage(url);
328 prepareImage(result, this);
332 logger.logp(Level.WARNING, "AicasGraphicsBenchmark", "loadImage",
333 "Could not locate image resource in class path: "
340 * Executes the test methods.
342 * @param g The Graphics object that is used to paint.
343 * @param size The size of the canvas.
345 void runTestSet(Graphics g, Dimension size)
347 if ((awtTests & AWTTEST_LINES) != 0)
348 test_drawLine(g, size);
349 if ((awtTests & AWTTEST_RECT) != 0)
350 test_drawRect(g, size);
351 if ((awtTests & AWTTEST_RECT) != 0)
352 test_fillRect(g, size);
353 if ((awtTests & AWTTEST_POLYLINE) != 0)
354 test_drawPolyline(g, size);
355 if ((awtTests & AWTTEST_POLYGON) != 0)
356 test_drawPolygon(g, size);
357 if ((awtTests & AWTTEST_POLYGON) != 0)
358 test_fillPolygon(g,size);
359 if ((awtTests & AWTTEST_ARC) != 0)
360 test_drawArc(g,size);
361 if ((awtTests & AWTTEST_ARC) != 0)
362 test_fillArc(g,size);
363 if ((awtTests & AWTTEST_OVAL) != 0)
364 test_drawOval(g, size);
365 if ((awtTests & AWTTEST_OVAL) != 0)
366 test_fillOval(g, size);
367 if ((awtTests & AWTTEST_ROUNDRECT) != 0)
368 test_fillRoundRect(g, size);
369 if ((awtTests & AWTTEST_STRING) != 0)
370 test_drawString(g, size);
371 if ((awtTests & AWTTEST_TRANSPARENTIMAGE) != 0)
372 test_drawTransparentImage(g,size);
373 if ((awtTests & AWTTEST_IMAGE) != 0)
374 test_drawImage(g,size);
378 * Gets a new random Color.
380 * @returna new random Color
382 private Color getNextColor()
384 return new Color((int) (Math.random() * 254) + 1,
385 (int) (Math.random() * 254) + 1,
386 (int) (Math.random() * 254) + 1);
390 * Draws random lines within the given dimensions.
392 * @param g The Graphics object that is used to paint.
393 * @param size The size of the canvas.
395 private void test_drawLine(Graphics g, Dimension size)
397 int maxTests = DEFAULT_TEST_SIZE;
399 long startTime = System.currentTimeMillis();
400 for (int i=0; i < maxTests; i += 1)
402 g.setColor(getNextColor());
403 int x1 = (int) (Math.random() * (size.width-minSize));
404 int y1 = (int) (Math.random() * (size.height-minSize));
405 int x2 = (int) (Math.random() * (size.width-minSize));
406 int y2 = (int) (Math.random() * (size.height-minSize));
407 g.drawLine(x1, y1, x2, y2);
409 long endTime = System.currentTimeMillis();
410 recordTest("drawLine " + maxTests + " times", (endTime-startTime));
414 * Draws random rectangles within the given dimensions.
416 * @param g The Graphics object that is used to paint.
417 * @param size The size of the canvas.
419 private void test_drawRect(Graphics g, Dimension size)
421 int maxTests = DEFAULT_TEST_SIZE;
423 long startTime = System.currentTimeMillis();
424 for (int i=0; i < maxTests; i += 1)
426 g.setColor(getNextColor());
427 int x1 = (int) (Math.random() * (size.width-minSize));
428 int y1 = (int) (Math.random() * (size.height-minSize));
429 int x2 = (int) (Math.random() * (size.width-minSize));
430 int y2 = (int) (Math.random() * (size.height-minSize));
431 g.drawRect(x1, y1, x2, y2);
433 long endTime = System.currentTimeMillis();
434 recordTest("drawRect " + maxTests + " times", (endTime-startTime));
438 * Draws random rectangles within the given dimensions.
440 * @param g The Graphics object that is used to paint.
441 * @param size The size of the canvas.
443 private void test_fillRect(Graphics g, Dimension size)
445 int maxTests = DEFAULT_TEST_SIZE;
447 long startTime = System.currentTimeMillis();
448 for (int i = 0; i < maxTests; i += 1)
450 g.setColor(getNextColor());
451 int x1 = (int) (Math.random() * (size.width-minSize));
452 int y1 = (int) (Math.random() * (size.height-minSize));
453 int x2 = (int) (Math.random() * (size.width-minSize));
454 int y2 = (int) (Math.random() * (size.height-minSize));
455 g.fillRect(x1, y1, x2, y2);
457 long endTime = System.currentTimeMillis();
458 recordTest("fillRect " + maxTests + " times", (endTime-startTime));
462 * Draws random polylines within the given dimensions.
464 * @param g The Graphics object that is used to paint.
465 * @param size The size of the canvas.
467 private void test_drawPolyline(Graphics g, Dimension size)
469 int maxTests = DEFAULT_TEST_SIZE;
470 long startTime = System.currentTimeMillis();
471 for (int i=0; i < maxTests; i += 1)
473 g.setColor(getNextColor());
474 int points = (int)(Math.random() * 6) + 3;
475 int[] x_coords = new int[points];
476 int[] y_coords = new int[points];
477 for (int j = 0; j < points; j+=1)
479 x_coords[j] = (int)(Math.random() * (size.width));
480 y_coords[j] = (int)(Math.random() * (size.height));
482 g.drawPolyline(x_coords,y_coords, points);
484 long endTime = System.currentTimeMillis();
485 recordTest("drawPolyline " + maxTests + " times", (endTime-startTime));
489 * Draws random polygons within the given dimensions.
490 * @param g The Graphics object that is used to paint.
491 * @param size The size of the canvas.
493 private void test_drawPolygon(Graphics g, Dimension size)
495 int maxTests = DEFAULT_TEST_SIZE;
496 long startTime = System.currentTimeMillis();
497 for (int i=0; i < maxTests; i += 1)
499 g.setColor(getNextColor());
500 int points = (int) (Math.random() * 6) + 3;
501 int[] xcoords = new int[points];
502 int[] ycoords = new int[points];
503 for(int j = 0; j < points; j+=1)
505 xcoords[j] = (int) (Math.random() * (size.width));
506 ycoords[j] = (int) (Math.random() * (size.height));
508 g.drawPolygon(xcoords, ycoords, points);
510 long endTime = System.currentTimeMillis();
511 recordTest("drawPolygon " + maxTests + " times", (endTime-startTime));
515 * Draws random filled polygons within the given dimensions.
517 * @param g The Graphics object that is used to paint.
518 * @param size The size of the canvas.
520 private void test_fillPolygon(Graphics g, Dimension size)
522 int maxTests = DEFAULT_TEST_SIZE;
523 long startTime = System.currentTimeMillis();
524 for (int i=0; i < maxTests; i += 1)
526 g.setColor(getNextColor());
527 int points = (int) (Math.random() * 6) + 3;
528 int[] xcoords = new int[points];
529 int[] ycoords = new int[points];
530 for (int j = 0; j < points; j+=1)
532 xcoords[j] = (int) (Math.random() * (size.width));
533 ycoords[j] = (int) (Math.random() * (size.height));
535 g.fillPolygon(xcoords, ycoords, points);
537 long endTime = System.currentTimeMillis();
538 recordTest("fillPolygon " + maxTests + " times", (endTime-startTime));
542 * Draws random arcs within the given dimensions.
544 * @param g The Graphics object that is used to paint.
545 * @param size The size of the canvas.
547 private void test_drawArc(Graphics g, Dimension size)
549 int maxTests = DEFAULT_TEST_SIZE;
554 startTime = System.currentTimeMillis();
555 for (int i=0; i < maxTests; i += 1)
557 g.setColor(getNextColor());
558 int x = (int) (Math.random() * (size.width - minSize + 1));
559 int y = (int) (Math.random() * (size.height - minSize + 1));
560 int width = (int) (Math.random() * (size.width - x - minSize) + minSize);
561 int height = (int) (Math.random() * (size.height - y - minSize) + minSize);
562 int startAngle = (int) (Math.random() * 360);
563 int arcAngle = (int) (Math.random() * 360 - startAngle);
564 g.drawArc(x, y, width, height, startAngle, arcAngle);
566 endTime = System.currentTimeMillis();
567 recordTest("drawArc " + maxTests + " times", (endTime-startTime));
571 * Draws random filled arcs within the given dimensions.
572 * @param g The Graphics object that is used to paint.
573 * @param size The size of the canvas.
575 private void test_fillArc(Graphics g, Dimension size)
577 int maxTests = DEFAULT_TEST_SIZE;
582 startTime = System.currentTimeMillis();
583 for (int i = 0; i < maxTests; i += 1)
585 g.setColor(getNextColor());
586 int x = (int) (Math.random() * (size.width - minSize + 1));
587 int y = (int) (Math.random() * (size.height - minSize + 1));
588 int width = (int)(Math.random() * (size.width - x - minSize) + minSize);
589 int height = (int)(Math.random() * (size.height - y - minSize) + minSize);
590 int startAngle = (int)(Math.random() * 360);
591 int arcAngle = (int)(Math.random() * 360);
592 g.fillArc(x, y, width, height, startAngle, arcAngle);
595 endTime = System.currentTimeMillis();
596 recordTest("fillArc " + maxTests + " times", (endTime - startTime));
600 * Draws random ovals within the given dimensions.
602 * @param g The Graphics object that is used to paint.
603 * @param size The size of the canvas.
605 private void test_drawOval(Graphics g, Dimension size)
607 int maxTests = DEFAULT_TEST_SIZE;
612 startTime = System.currentTimeMillis();
613 for (int i = 0; i < maxTests; i += 1)
615 g.setColor(getNextColor());
616 int x = (int)(Math.random() * (size.width - minSize + 1));
617 int y = (int)(Math.random() * (size.height - minSize + 1));
618 int width = (int)(Math.random() * (size.width - x - minSize) + minSize);
619 int height = (int)(Math.random() * (size.height - y - minSize) + minSize);
620 g.drawOval(x, y, Math.min(width, height), Math.min(width, height));
622 endTime = System.currentTimeMillis();
623 recordTest("drawOval " + maxTests + " times", (endTime-startTime));
627 * Draws random filled ovals within the given dimensions.
629 * @param g The Graphics object that is used to paint.
630 * @param size The size of the canvas.
632 private void test_fillOval(Graphics g, Dimension size)
634 int maxTests = DEFAULT_TEST_SIZE;
639 startTime = System.currentTimeMillis();
640 for (int i = 0; i < maxTests; i += 1)
642 g.setColor(getNextColor());
643 int x = (int) (Math.random() * (size.width - minSize + 1));
644 int y = (int) (Math.random() * (size.height - minSize + 1));
645 int width = (int) (Math.random() * (size.width - x - minSize) + minSize);
646 int height = (int) (Math.random() * (size.height - y - minSize) + minSize);
647 g.fillOval(x, y, width,height);
649 endTime = System.currentTimeMillis();
650 recordTest("fillOval " + maxTests + " times", (endTime-startTime));
654 * Draws random filled rounded rectangles within the given dimensions.
656 * @param g The Graphics object that is used to paint.
657 * @param size The size of the canvas.
659 private void test_fillRoundRect(Graphics g, Dimension size)
661 int maxTests = DEFAULT_TEST_SIZE;
666 startTime = System.currentTimeMillis();
667 for (int i=0; i < maxTests; i+=1)
669 g.setColor(getNextColor());
670 int x = (int) (Math.random() * (size.width - minSize + 1));
671 int y = (int) (Math.random() * (size.height - minSize + 1));
672 int width = (int) (Math.random() * (size.width - x - minSize) + minSize);
673 int height = (int) (Math.random() * (size.height - y - minSize) + minSize);
674 int arcWidth = (int) (Math.random() * (width - 1) + 1);
675 int arcHeight = (int) (Math.random() * (height - 1) + 5);
676 g.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
678 endTime = System.currentTimeMillis();
679 recordTest("fillRoundRect " + maxTests + " times", (endTime-startTime));
683 * Draws random images within the given dimensions.
685 * @param g The Graphics object that is used to paint.
686 * @param size The size of the canvas.
688 private void test_drawImage(Graphics g, Dimension size)
690 if (gifTestImage == null)
692 logger.logp(Level.WARNING, "AicasGraphicsBenchmark", "runTestSet",
693 "Skipping 'test_drawImage' due to missing resource.");
697 int maxTests = DEFAULT_TEST_SIZE / 2;
700 int imageWidth = gifTestImage.getWidth(this);
701 int imageHeight = gifTestImage.getHeight(this);
702 long startTime = System.currentTimeMillis();
703 for (int i = 0; i < maxTests; i += 1)
705 g.setColor(getNextColor());
706 int x = (int) (Math.random() * (size.width - imageWidth + 1));
707 int y = (int) (Math.random() * (size.height - imageHeight + 1));
708 g.drawImage(gifTestImage, x, y, this);
710 long endTime = System.currentTimeMillis();
711 recordTest("drawImage " + maxTests + " times", (endTime-startTime));
715 * Draws random transparent images within the given dimensions.
717 * @param g The Graphics object that is used to paint.
718 * @param size The size of the canvas.
720 private void test_drawTransparentImage(Graphics g, Dimension size)
722 if (pngTestImage == null)
724 logger.logp(Level.WARNING, "AicasGraphicsBenchmark", "runTestSet",
725 "Skipping 'test_drawTransparentImage' due to missing resource.");
730 int maxTests = DEFAULT_TEST_SIZE / 5;
733 int imageWidth = pngTestImage.getWidth(this);
734 int imageHeight = pngTestImage.getHeight(this);
735 long startTime = System.currentTimeMillis();
736 for (int i = 0; i < maxTests; i += 1)
738 g.setColor(getNextColor());
739 int x = (int) (Math.random() * (size.width - imageWidth + 1));
740 int y = (int) (Math.random() * (size.height - imageHeight + 1));
741 g.drawImage(pngTestImage, x, y, this);
743 long endTime = System.currentTimeMillis();
744 recordTest("draw transparent image " + maxTests + " times",
745 (endTime-startTime));
749 * Draws random strings within the given dimensions.
751 * @param g The Graphics object that is used to paint.
752 * @param size The size of the canvas.
754 private void test_drawString(Graphics g, Dimension size)
756 int maxTests = DEFAULT_TEST_SIZE;
757 String testString = "HelloWorld";
758 int stringWidth = g.getFontMetrics().stringWidth(testString);
759 int stringHeight = g.getFontMetrics().getHeight();
761 long startTime = System.currentTimeMillis();
762 for(int i = 0; i < maxTests; i += 1)
764 g.setColor(getNextColor());
765 g.drawString(testString, (int) (Math.random() * (size.width - stringWidth + 1)),(int)(Math.random() * (size.height - stringHeight + 1)) + stringHeight);
767 long endTime = System.currentTimeMillis();
768 recordTest("drawString " + maxTests + " times", (endTime-startTime));
771 private class GraphicsTest extends Canvas implements Runnable
774 boolean done = false;
775 boolean doPaint = false;
776 boolean withClipping = false;
778 public GraphicsTest()
780 paintThread = new Thread(this);
801 catch (InterruptedException exception)
809 System.out.println("--- run...(" + runCount + "/" + iterations
810 + ") ------------------------------------------------------");
812 Graphics g = getGraphics();
813 Dimension size = getSize();
814 logger.logp(Level.INFO, "AicasGraphicsBenchmark.GraphicsTest", "run",
815 "Start testing non-double-buffered drawing");
816 runSet_noClipping(g,size);
817 runSet_zeroClipping(g, size);
818 runSet_withClipping(g, size);
821 if (doubleBufferFlag)
823 logger.logp(Level.INFO, "AicasGraphicsBenchmark.GraphicsTest",
824 "run", "Start testing double-buffered drawing");
825 Graphics canvas = getGraphics();
826 Image doublebuffer = createImage(size.width,size.height);
827 g = doublebuffer.getGraphics();
828 runSet_noClipping(g,size);
830 canvas.drawImage(doublebuffer, 0, 0, this);
832 g = doublebuffer.getGraphics();
833 runSet_withClipping(g, size);
835 canvas.drawImage(doublebuffer, 0, 0, this);
837 g = doublebuffer.getGraphics();
838 runSet_zeroClipping(g, size);
840 canvas.drawImage(doublebuffer, 0, 0, this);
848 if (iterations != -1)
853 System.out.println("--- done --------------------------------------------------------");
863 System.err.println("Error: " + error);
870 private void runSet_zeroClipping(Graphics g, Dimension size)
879 clipped_x = (size.width) / 2;
880 clipped_y = (size.height) / 2;
881 g.setClip(0, 0, size.width, size.height);
882 g.setColor(Color.BLACK);
883 g.fillRect(0, 0, size.width, size.height);
884 g.setColor(Color.WHITE);
885 g.drawRect(0, 0, size.width - 1, size.height - 1);
886 g.fillRect(clipped_x - 1, clipped_y - 1, clipped_width + 2, clipped_height + 2);
888 g.clipRect(clipped_x, clipped_y, clipped_width, clipped_height);
889 g.setColor(Color.BLACK);
890 g.fillRect(0, 0, size.width, size.height);
892 setTestContext("clipping to zero");
897 private void runSet_withClipping(Graphics g, Dimension size)
899 int clipped_width = 2 * size.width / 3;
900 int clipped_height = 2 * size.height / 3;
901 int clipped_x = (size.width - clipped_width) / 2;
902 int clipped_y = (size.height - clipped_height) / 2;
904 g.setClip(0,0,size.width,size.height);
906 g.setColor(Color.BLACK);
907 g.fillRect(0, 0, size.width, size.height);
908 g.setColor(Color.GREEN);
909 g.drawRect(0, 0, size.width - 1, size.height - 1);
910 g.setColor(Color.WHITE);
911 g.fillRect(clipped_x - 1, clipped_y - 1, clipped_width + 2, clipped_height + 2);
913 g.clipRect(clipped_x, clipped_y, clipped_width, clipped_height);
914 g.setColor(Color.BLACK);
915 g.fillRect(0, 0, size.width, size.height);
917 setTestContext("with clipping");
922 public void runSet_noClipping(Graphics g, Dimension size)
924 g.setColor(Color.BLACK);
925 g.fillRect(0, 0, size.width, size.height);
927 setTestContext("without clipping");
932 public void paint(Graphics g)
949 private Map testsMap = new TreeMap();
951 public void putTest(String testName, TestRecorder recoder)
953 testsMap.put(testName,recoder);
956 public TestRecorder getTest(String testName)
958 return (TestRecorder)testsMap.get(testName);
961 public Iterator testIterator()
963 return testsMap.keySet().iterator();
971 long minTime = Long.MAX_VALUE;
972 long maxTime = Long.MIN_VALUE;
976 * @return Returns the maxTime.
978 public final long getMaxTime()
984 * @return Returns the minTime.
986 public final long getMinTime()
992 * @return Returns the test name.
994 public final String getTestName()
999 public final double getAverage()
1001 return ((double)totalTime) / ((double)runCount);
1004 public TestRecorder(String testName)
1009 public void addRun(long time)