summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorFrancis Kung <fkung@redhat.com>2006-06-23 21:31:15 +0000
committerFrancis Kung <fkung@redhat.com>2006-06-23 21:31:15 +0000
commit6c181a1fd8daf166b48fa352fb3d8963d182c3d5 (patch)
tree57b40dac4075793566418ccc7298d2d613461959 /examples
parent09089b5ab9dd7929df57ebf15e21a5f1057a5d15 (diff)
downloadclasspath-6c181a1fd8daf166b48fa352fb3d8963d182c3d5.tar.gz
2006-06-23 Francis Kung <fkung@redhat.com>
* examples/gnu/classpath/examples/java2d/J2dBenchmarkGUI.java (Harness.actionPerformed): Process additional options. (J2dBenchmarkWrapper): Defer init call until after options are processed. (J2dBenchmarkWrapper.setAlias): New method. (J2dBenchmarkWrapper.setComposite): New method. (J2dBenchmarkWrapper.setFill): New method. (J2dBenchmarkWrapper.setRotation): New method. (J2dBenchmarkWrapper.setShear): New method. (J2dBenchmarkWrapper.setStroke): New method. (J2dBenchmarkWrapper.setTranslation): New method. (run): Add additional options to GUI. * examples/gnu/classpath/examples/java2d/J2dBenchmark.java: Added protected fields for various options. (GraphicsTest.runSet_noClipping): Reset graphics settings between tests. (GraphicsTest.runSet_withClipping): Reset graphics settings between tests. (GraphicsTest.runSet_zeroClipping): Reset graphics settings between tests. (getNextColor): Renamed to setRandom. (init): Load additional image for texturing if needed. (loadBufferedImage): New method. (main): Accept additional command-line switches. (prepareGraphics): New method. (resetGraphics): New method. (runTestSuite): Accept additional image-processing options. (setRandom): Renamed from getNextColor; generate various random options (test_drawArc): Rename getNextColor to setRandom. (test_drawCubic): Likewise. (test_drawEllipse): Likewise. (test_drawGeneralPath): Likewise. (test_drawImage): Likewise. (test_drawLine): Likewise. (test_drawQuadCurve): Likewise. (test_drawRectangle): Likewise. (test_drawRoundRectangle): Likewise. (test_drawTransparentImage): Likewise. (test_fillArc): Rename getNextColor to setRandom. (test_fillEllipse): Likewise. (test_fillGeneralPath): Likewise. (test_fillRectangle): Likewise. (test_fillRoundRectangle): Likewise. (TestRecorder.getAverage): Round the average time.
Diffstat (limited to 'examples')
-rw-r--r--examples/gnu/classpath/examples/java2d/J2dBenchmark.java407
-rw-r--r--examples/gnu/classpath/examples/java2d/J2dBenchmarkGUI.java269
2 files changed, 624 insertions, 52 deletions
diff --git a/examples/gnu/classpath/examples/java2d/J2dBenchmark.java b/examples/gnu/classpath/examples/java2d/J2dBenchmark.java
index 149d05a91..118ae2463 100644
--- a/examples/gnu/classpath/examples/java2d/J2dBenchmark.java
+++ b/examples/gnu/classpath/examples/java2d/J2dBenchmark.java
@@ -19,24 +19,30 @@
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA. */
-
package gnu.classpath.examples.java2d;
+import java.awt.AlphaComposite;
+import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Frame;
+import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Label;
+import java.awt.MediaTracker;
import java.awt.Panel;
import java.awt.Rectangle;
+import java.awt.RenderingHints;
+import java.awt.TexturePaint;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
+import java.awt.geom.AffineTransform;
import java.awt.geom.Arc2D;
import java.awt.geom.CubicCurve2D;
import java.awt.geom.Ellipse2D;
@@ -45,6 +51,7 @@ import java.awt.geom.Line2D;
import java.awt.geom.QuadCurve2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
+import java.awt.image.BufferedImage;
import java.net.URL;
import java.util.Iterator;
import java.util.Map;
@@ -124,6 +131,28 @@ public class J2dBenchmark
protected boolean doubleBufferFlag = true;
+ protected boolean gradientFlag = false;
+
+ protected String texture = null;
+
+ protected boolean strokeFlag = false;
+
+ protected float composite = 1;
+
+ protected int xtranslate = 0;
+
+ protected int ytranslate = 0;
+
+ protected double xshear = 0;
+
+ protected double yshear = 0;
+
+ protected double rotate = 0;
+
+ protected boolean antialiasFlag = false;
+
+ protected AffineTransform affineTransform = null;
+
protected int awtTests = J2DTEST_ALL;
protected int testSize = DEFAULT_TEST_SIZE;
@@ -138,17 +167,39 @@ public class J2dBenchmark
private Image gifTestImage;
+ protected BufferedImage textureImage;
+
protected TestSet testSetMap = new TestSet();
- public void init()
+ public String init()
{
+ boolean loadError = false;
pngTestImage = loadImage("aicas.png");
gifTestImage = loadImage("palme.gif");
+ if (texture != null)
+ {
+ textureImage = loadBufferedImage(texture);
+
+ if (textureImage == null)
+ {
+ logger.logp(Level.WARNING, "J2dGraphicsBenchmark", "init",
+ "Unable to load texture - defaulting "
+ + "to solid colours");
+ texture = null;
+ loadError = true;
+ }
+ }
+
setLayout(new BorderLayout());
testLabel = new Label();
add(testLabel, BorderLayout.NORTH);
add(new GraphicsTest(), BorderLayout.CENTER);
+
+ if (loadError)
+ return "Unable to load image";
+ else
+ return null;
}
void setTestContext(String testName)
@@ -195,7 +246,6 @@ public class J2dBenchmark
int i;
boolean endOfOptionsFlag;
J2dBenchmark speed = new J2dBenchmark();
- speed.init();
// Parse arguments.
i = 0;
@@ -216,7 +266,23 @@ public class J2dBenchmark
+ DEFAULT_SCREEN_WIDTH);
System.out.println(" -h|--height=<n> - screen height; default "
+ DEFAULT_SCREEN_HEIGHT);
- System.out.println(" -n|--noDoubleBuffer - disable double-buffering test");
+ System.out.println(" -d|--noDoubleBuffer - disable double-buffering test");
+ System.out.println(" -s|--testsize=<n> - size of each test; default "
+ + DEFAULT_TEST_SIZE);
+ System.out.println(" -c|--noClipping - disable clipping test");
+ System.out.println(" -z|--noZeroClipping - disable clipping to zero test");
+ System.out.println("");
+ System.out.println("Additional options:");
+ System.out.println(" --with-gradients - enable gradients (not compatible with --texture)");
+ System.out.println(" --with-stroking - enable random stroking");
+ System.out.println(" --texture=<file> - enable texturing with this file (not compatible with --with-gradients)");
+ System.out.println(" --composite=<n|-1> - set alpha composite level; -1 for random; default 1.0 (no transparency)");
+ System.out.println(" --anti-alias=<on|off> - set anti-aliasing hint (not all implementations respect this); default off");
+ System.out.println(" --x-translate=<n> - set x-axis translation; default 0");
+ System.out.println(" --y-translate=<n> - set y-axis translation; default 0");
+ System.out.println(" --x-shear=<n> - set x-axis shear; default 0");
+ System.out.println(" --y-shear=<n> - set y-axis shear; default 0");
+ System.out.println(" --rotate=<n|-1> - set rotation (radians); -1 for random; default: 0 (none)");
System.out.println("");
System.out.println("Tests: arc");
System.out.println(" cubiccurve");
@@ -283,12 +349,115 @@ public class J2dBenchmark
i += 2;
continue;
}
- else if ((args[i].equals("-n") || args[i].equals("--noDoubleBuffer")))
+ else if ((args[i].equals("-d") || args[i].equals("--noDoubleBuffer")))
{
speed.doubleBufferFlag = false;
i += 1;
continue;
}
+ else if ((args[i].startsWith("-s=") || args[i].startsWith("--testsize=")))
+ {
+ if ((i + 1) >= args.length)
+ {
+ System.err.println("ERROR: No argument given for option '"
+ + args[i] + "'!");
+ System.exit(2);
+ }
+ speed.testSize = Integer.parseInt(args[i].substring(args[i].indexOf('=') + 1));
+ i += 1;
+ continue;
+ }
+ else if ((args[i].equals("-s") || args[i].equals("--testsize")))
+ {
+ if ((i + 1) >= args.length)
+ {
+ System.err.println("ERROR: No argument given for option '"
+ + args[i] + "'!");
+ System.exit(2);
+ }
+ speed.testSize = Integer.parseInt(args[i + 1]);
+ i += 2;
+ continue;
+ }
+ else if ((args[i].equals("-c") || args[i].equals("--noClipping")))
+ {
+ speed.noClippingFlag = false;
+ i += 1;
+ continue;
+ }
+ else if ((args[i].equals("-z") || args[i].equals("--noZeroClipping")))
+ {
+ speed.zeroClippingFlag = false;
+ i += 1;
+ continue;
+ }
+ else if (args[i].equals("--with-gradients"))
+ {
+ speed.gradientFlag = true;
+ i += 1;
+ continue;
+ }
+ else if (args[i].equals("--with-stroking"))
+ {
+ speed.strokeFlag = true;
+ i += 1;
+ continue;
+ }
+ else if (args[i].startsWith("--texture="))
+ {
+ speed.texture = args[i].substring(args[i].indexOf('=') + 1);
+ i += 1;
+ continue;
+ }
+ else if (args[i].startsWith("--composite="))
+ {
+ speed.composite = Float.parseFloat(args[i].substring(args[i].indexOf('=') + 1));
+ if (speed.composite != - 1
+ && (speed.composite < 0 || speed.composite > 1))
+ {
+ System.err.println("ERROR: Invalid value for composite (must be between 0 and 1, or -1 for random)");
+ System.exit(2);
+ }
+ i += 1;
+ continue;
+ }
+ else if (args[i].startsWith("--anti-alias="))
+ {
+ speed.antialiasFlag = (args[i].substring(args[i].indexOf('=') + 1).equals("on"));
+ i += 1;
+ continue;
+ }
+ else if (args[i].startsWith("--x-translate="))
+ {
+ speed.xtranslate = Integer.parseInt(args[i].substring(args[i].indexOf('=') + 1));
+ i += 1;
+ continue;
+ }
+ else if (args[i].startsWith("--y-translate="))
+ {
+ speed.ytranslate = Integer.parseInt(args[i].substring(args[i].indexOf('=') + 1));
+ i += 1;
+ continue;
+ }
+ else if (args[i].startsWith("--x-shear="))
+ {
+ speed.xshear = Double.parseDouble(args[i].substring(args[i].indexOf('=') + 1));
+ i += 1;
+ continue;
+ }
+ else if (args[i].startsWith("--y-shear="))
+ {
+ speed.yshear = Double.parseDouble(args[i].substring(args[i].indexOf('=') + 1));
+ i += 1;
+ continue;
+ }
+ else if (args[i].startsWith("--rotate="))
+ {
+ speed.rotate = Double.parseDouble(args[i].substring(args[i].indexOf('=') + 1));
+ i += 1;
+ continue;
+ }
+
else if (args[i].equals("--"))
{
endOfOptionsFlag = true;
@@ -335,6 +504,7 @@ public class J2dBenchmark
speed.awtTests = awtTests;
// Create graphics.
+ speed.init();
final Frame frame = new Frame("J2dGraphicsBenchmark");
frame.addWindowListener(new WindowAdapter()
@@ -377,6 +547,51 @@ public class J2dBenchmark
return result;
}
+ private BufferedImage loadBufferedImage(String imageName)
+ {
+ BufferedImage result = null;
+ logger.logp(Level.INFO, "J2dGraphicsBenchmark", "loadImage",
+ "Loading image: " + imageName);
+
+ // Try to load image out of classpath before trying an absolute filename
+ URL url = getClass().getResource(imageName);
+ Image img;
+ if (url != null)
+ img = Toolkit.getDefaultToolkit().getImage(url);
+ else
+ img = Toolkit.getDefaultToolkit().getImage(imageName);
+
+ if (img != null)
+ {
+ // Wait for image to load
+ try
+ {
+ MediaTracker tracker = new MediaTracker(this);
+ tracker.addImage(img, 1);
+ tracker.waitForAll();
+
+ prepareImage(img, this);
+ result = new BufferedImage(img.getWidth(this), img.getHeight(this),
+ BufferedImage.TYPE_INT_RGB);
+ result.createGraphics().drawImage(img, 0, 0, this);
+ }
+ catch (InterruptedException e)
+ {
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ }
+
+ if (result == null)
+ {
+ logger.logp(Level.WARNING, "J2dGraphicsBenchmark", "loadBufferedImage",
+ "Could not locate image resource in class path: "
+ + imageName);
+ }
+ return result;
+ }
+
/**
* Executes the test methods.
*
@@ -385,6 +600,9 @@ public class J2dBenchmark
*/
void runTestSet(Graphics2D g, Dimension size)
{
+ // Any user-specified options (ie set transforms, rendering hints)
+ prepareGraphics((Graphics2D) g);
+
if ((awtTests & J2DTEST_ARC) != 0)
{
test_drawArc(g, size);
@@ -439,15 +657,121 @@ public class J2dBenchmark
}
/**
- * Gets a new random Color.
+ * Reset all graphics settings to the standard, default values
+ *
+ * @param g the object to apply settings to
+ */
+ private void resetGraphics(Graphics2D g)
+ {
+ g.setTransform(new AffineTransform());
+ g.setStroke(new BasicStroke());
+ g.setComposite(AlphaComposite.SrcOut);
+ }
+
+ /**
+ * Sets initial user graphics options
*
- * @returna new random Color
+ * @param g the object to apply settings to
*/
- private Color getNextColor()
+ private void prepareGraphics(Graphics2D g)
{
- return new Color((int) (Math.random() * 254) + 1,
- (int) (Math.random() * 254) + 1,
- (int) (Math.random() * 254) + 1);
+ // Transforms
+ if (affineTransform != null)
+ g.setTransform(affineTransform);
+
+ else if (xtranslate != 0 || ytranslate != 0 || xshear != 0 || yshear != 0)
+ {
+ g.translate(xtranslate, ytranslate);
+ g.shear(xshear, yshear);
+ }
+
+ if (rotate > 0)
+ g.rotate(rotate * Math.PI, screenWidth / 2, screenHeight / 2);
+
+ // Composite (transparency)
+ if (composite > 0)
+ {
+ g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
+ composite));
+ }
+
+ // Textures
+ if (texture != null)
+ g.setPaint(new TexturePaint(textureImage,
+ new Rectangle(0, 0, textureImage.getWidth(),
+ textureImage.getHeight())));
+
+ // Anti-alias setting
+ if (antialiasFlag)
+ g.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON));
+ else
+ g.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_OFF));
+ }
+
+ /**
+ * Gets new random settings
+ *
+ * @param g the object to set parameters for
+ * @param size the screen size
+ */
+ private void setRandom(Graphics2D g, Dimension size)
+ {
+ // Set colour / paint
+ if (gradientFlag)
+ {
+ Color c1 = new Color((int) (Math.random() * 254) + 1,
+ (int) (Math.random() * 254) + 1,
+ (int) (Math.random() * 254) + 1);
+
+ Color c2 = new Color((int) (Math.random() * 254) + 1,
+ (int) (Math.random() * 254) + 1,
+ (int) (Math.random() * 254) + 1);
+
+ g.setPaint(new GradientPaint(0, 0, c1, screenWidth / 5,
+ screenHeight / 5, c2, true));
+ }
+
+ else if (texture == null)
+ g.setPaint(new Color((int) (Math.random() * 254) + 1,
+ (int) (Math.random() * 254) + 1,
+ (int) (Math.random() * 254) + 1));
+
+ // Set stroke width and options
+ if (strokeFlag)
+ {
+ int cap = (int) (Math.random() * 3 + 1);
+ if (cap == 1)
+ cap = BasicStroke.CAP_SQUARE;
+ else if (cap == 2)
+ cap = BasicStroke.CAP_BUTT;
+ else
+ cap = BasicStroke.CAP_ROUND;
+
+ int join = (int) (Math.random() * 3 + 1);
+ if (join == 1)
+ join = BasicStroke.JOIN_MITER;
+ else if (join == 2)
+ join = BasicStroke.JOIN_BEVEL;
+ else
+ join = BasicStroke.JOIN_ROUND;
+
+ float[] dashes = { 10, 10 };
+ g.setStroke(new BasicStroke((int) (Math.random() * 10), cap, join, 10f,
+ dashes, 0));
+ }
+
+ // Composite / transparency
+ if (composite == - 1)
+ {
+ g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
+ (float) Math.random()));
+ }
+
+ // Transformations
+ if (rotate == - 1)
+ g.rotate(Math.random() * Math.PI * 2);
}
/**
@@ -466,7 +790,7 @@ public class J2dBenchmark
startTime = System.currentTimeMillis();
for (int i = 0; i < maxTests; i += 1)
{
- g.setColor(getNextColor());
+ setRandom(g, size);
int x = (int) (Math.random() * (size.width - minSize + 1));
int y = (int) (Math.random() * (size.height - minSize + 1));
int width = (int) (Math.random() * (size.width - x - minSize) + minSize);
@@ -499,7 +823,7 @@ public class J2dBenchmark
startTime = System.currentTimeMillis();
for (int i = 0; i < maxTests; i += 1)
{
- g.setColor(getNextColor());
+ setRandom(g, size);
int x = (int) (Math.random() * (size.width - minSize + 1));
int y = (int) (Math.random() * (size.height - minSize + 1));
int width = (int) (Math.random() * (size.width - x - minSize) + minSize);
@@ -529,7 +853,7 @@ public class J2dBenchmark
long startTime = System.currentTimeMillis();
for (int i = 0; i < maxTests; i += 1)
{
- g.setColor(getNextColor());
+ setRandom(g, size);
int x1 = (int) (Math.random() * (size.width - minSize));
int y1 = (int) (Math.random() * (size.height - minSize));
int xc1 = (int) (Math.random() * (size.width - minSize));
@@ -561,7 +885,7 @@ public class J2dBenchmark
long startTime = System.currentTimeMillis();
for (int i = 0; i < maxTests; i += 1)
{
- g.setColor(getNextColor());
+ setRandom(g, size);
int x1 = (int) (Math.random() * (size.width - minSize));
int y1 = (int) (Math.random() * (size.height - minSize));
int x2 = (int) (Math.random() * (size.width - minSize));
@@ -587,7 +911,7 @@ public class J2dBenchmark
long startTime = System.currentTimeMillis();
for (int i = 0; i < maxTests; i += 1)
{
- g.setColor(getNextColor());
+ setRandom(g, size);
int x1 = (int) (Math.random() * (size.width - minSize));
int y1 = (int) (Math.random() * (size.height - minSize));
int x2 = (int) (Math.random() * (size.width - minSize));
@@ -614,7 +938,7 @@ public class J2dBenchmark
for (int i = 0; i < maxTests; i += 1)
{
- g.setColor(getNextColor());
+ setRandom(g, size);
int points = (int) (Math.random() * 6) + 2;
GeneralPath shape = new GeneralPath();
shape.moveTo((float) Math.random() * (size.width),
@@ -648,7 +972,7 @@ public class J2dBenchmark
for (int i = 0; i < maxTests; i += 1)
{
- g.setColor(getNextColor());
+ setRandom(g, size);
int points = (int) (Math.random() * 6) + 2;
for (int j = 0; j < points; j += 1)
{
@@ -675,7 +999,7 @@ public class J2dBenchmark
long startTime = System.currentTimeMillis();
for (int i = 0; i < maxTests; i += 1)
{
- g.setColor(getNextColor());
+ setRandom(g, size);
int x1 = (int) (Math.random() * (size.width - minSize));
int y1 = (int) (Math.random() * (size.height - minSize));
int x2 = (int) (Math.random() * (size.width - minSize));
@@ -701,7 +1025,7 @@ public class J2dBenchmark
long startTime = System.currentTimeMillis();
for (int i = 0; i < maxTests; i += 1)
{
- g.setColor(getNextColor());
+ setRandom(g, size);
int x1 = (int) (Math.random() * (size.width - minSize));
int y1 = (int) (Math.random() * (size.height - minSize));
int xc = (int) (Math.random() * (size.width - minSize));
@@ -730,7 +1054,7 @@ public class J2dBenchmark
long startTime = System.currentTimeMillis();
for (int i = 0; i < maxTests; i += 1)
{
- g.setColor(getNextColor());
+ setRandom(g, size);
int x1 = (int) (Math.random() * (size.width - minSize));
int y1 = (int) (Math.random() * (size.height - minSize));
int x2 = (int) (Math.random() * (size.width - minSize));
@@ -756,7 +1080,7 @@ public class J2dBenchmark
long startTime = System.currentTimeMillis();
for (int i = 0; i < maxTests; i += 1)
{
- g.setColor(getNextColor());
+ setRandom(g, size);
int x1 = (int) (Math.random() * (size.width - minSize));
int y1 = (int) (Math.random() * (size.height - minSize));
int x2 = (int) (Math.random() * (size.width - minSize));
@@ -785,7 +1109,7 @@ public class J2dBenchmark
startTime = System.currentTimeMillis();
for (int i = 0; i < maxTests; i += 1)
{
- g.setColor(getNextColor());
+ setRandom(g, size);
int x = (int) (Math.random() * (size.width - minSize + 1));
int y = (int) (Math.random() * (size.height - minSize + 1));
int width = (int) (Math.random() * (size.width - x - minSize) + minSize);
@@ -818,7 +1142,7 @@ public class J2dBenchmark
startTime = System.currentTimeMillis();
for (int i = 0; i < maxTests; i += 1)
{
- g.setColor(getNextColor());
+ setRandom(g, size);
int x = (int) (Math.random() * (size.width - minSize + 1));
int y = (int) (Math.random() * (size.height - minSize + 1));
int width = (int) (Math.random() * (size.width - x - minSize) + minSize);
@@ -858,7 +1182,7 @@ public class J2dBenchmark
long startTime = System.currentTimeMillis();
for (int i = 0; i < maxTests; i += 1)
{
- g.setColor(getNextColor());
+ setRandom(g, size);
int x = (int) (Math.random() * (size.width - imageWidth + 1));
int y = (int) (Math.random() * (size.height - imageHeight + 1));
g.drawImage(gifTestImage, x, y, this);
@@ -878,7 +1202,7 @@ public class J2dBenchmark
if (pngTestImage == null)
{
logger.logp(Level.WARNING, "AicasGraphicsBenchmark", "runTestSet",
- "Skipping 'test_drawTransparentImage' due to missing resource.");
+ "Skipping 'drawTransparentImage' due to missing resource.");
return;
}
@@ -890,7 +1214,7 @@ public class J2dBenchmark
long startTime = System.currentTimeMillis();
for (int i = 0; i < maxTests; i += 1)
{
- g.setColor(getNextColor());
+ setRandom(g, size);
int x = (int) (Math.random() * (size.width - imageWidth + 1));
int y = (int) (Math.random() * (size.height - imageHeight + 1));
g.drawImage(pngTestImage, x, y, this);
@@ -1051,14 +1375,17 @@ public class J2dBenchmark
clipped_x = (size.width) / 2;
clipped_y = (size.height) / 2;
+ // Reset any transforms from past tests
+ resetGraphics(g);
+
Rectangle fullWindow = new Rectangle(0, 0, size.width, size.height);
g.setClip(fullWindow);
- g.setColor(Color.BLACK);
+ g.setPaint(Color.BLACK);
g.fill(fullWindow);
Rectangle windowBorder = new Rectangle(0, 0, size.width - 1,
size.width - 1);
- g.setColor(Color.WHITE);
+ g.setPaint(Color.WHITE);
g.draw(windowBorder);
Rectangle innerBorder = new Rectangle(clipped_x - 1, clipped_y - 1,
@@ -1069,7 +1396,7 @@ public class J2dBenchmark
Rectangle innerBox = new Rectangle(clipped_x, clipped_y, clipped_width,
clipped_height);
g.clip(innerBox);
- g.setColor(Color.BLACK);
+ g.setPaint(Color.BLACK);
g.fill(fullWindow);
if (context.equals(""))
@@ -1093,28 +1420,31 @@ public class J2dBenchmark
int clipped_x = (size.width - clipped_width) / 2;
int clipped_y = (size.height - clipped_height) / 2;
+ // Reset any transforms from past tests
+ resetGraphics(g);
+
Rectangle fullWindow = new Rectangle(0, 0, size.width, size.height);
g.setClip(fullWindow);
- g.setColor(Color.BLACK);
+ g.setPaint(Color.BLACK);
g.fill(fullWindow);
Rectangle windowBorder = new Rectangle(0, 0, size.width - 1,
size.height - 1);
- g.setColor(Color.GREEN);
+ g.setPaint(Color.GREEN);
g.draw(windowBorder);
Rectangle innerBorder = new Rectangle(clipped_x - 1, clipped_y - 1,
clipped_width + 2,
clipped_height + 2);
- g.setColor(Color.WHITE);
+ g.setPaint(Color.WHITE);
g.fill(innerBorder);
Rectangle innerBox = new Rectangle(clipped_x, clipped_y, clipped_width,
clipped_height);
g.clip(innerBox);
- g.setColor(Color.BLACK);
+ g.setPaint(Color.BLACK);
g.fill(fullWindow);
if (context.equals(""))
@@ -1133,8 +1463,11 @@ public class J2dBenchmark
private void runSet_noClipping(Graphics2D g, Dimension size,
String context, int runCount)
{
+ // Reset any transforms from past tests
+ resetGraphics(g);
+
Rectangle fullWindow = new Rectangle(0, 0, size.width, size.height);
- g.setColor(Color.BLACK);
+ g.setPaint(Color.BLACK);
g.fill(fullWindow);
if (context.equals(""))
@@ -1216,9 +1549,9 @@ class TestRecorder
return test;
}
- public final double getAverage()
+ public final long getAverage()
{
- return ((double) totalTime) / ((double) runCount);
+ return (totalTime / runCount);
}
public TestRecorder(String testName)
diff --git a/examples/gnu/classpath/examples/java2d/J2dBenchmarkGUI.java b/examples/gnu/classpath/examples/java2d/J2dBenchmarkGUI.java
index bcd58e2e4..bb583cbdc 100644
--- a/examples/gnu/classpath/examples/java2d/J2dBenchmarkGUI.java
+++ b/examples/gnu/classpath/examples/java2d/J2dBenchmarkGUI.java
@@ -40,6 +40,8 @@ package gnu.classpath.examples.java2d;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
@@ -55,6 +57,7 @@ import java.util.logging.LogRecord;
import javax.swing.Box;
import javax.swing.BoxLayout;
+import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
@@ -62,9 +65,11 @@ import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
+import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
+import javax.swing.border.BevelBorder;
/**
* Extends the J2dBenchmark to provide a GUI for selecting options and tests.
@@ -172,6 +177,8 @@ public class J2dBenchmarkGUI
// Allow user to select tests to run
JPanel tests = new JPanel();
tests.setLayout(new BoxLayout(tests, BoxLayout.PAGE_AXIS));
+ tests.setBorder(new BevelBorder(BevelBorder.RAISED));
+ tests.add(new JLabel("Shapes to test:"));
JCheckBox test_arcDraw = new JCheckBox("Arc", true);
tests.add(test_arcDraw);
@@ -211,6 +218,130 @@ public class J2dBenchmarkGUI
tests.add(test_image);
elements.put("test_image", test_image);
+ // Additional image-processing options
+ JPanel extras = new JPanel();
+ extras.setBorder(new BevelBorder(BevelBorder.LOWERED));
+ GridBagLayout layout = new GridBagLayout();
+ GridBagConstraints gbc = new GridBagConstraints();
+ gbc.anchor = GridBagConstraints.NORTHWEST;
+ gbc.insets = new Insets(5, 2, 15, 15);
+ extras.setLayout(layout);
+
+ // Filling (solid, gradient, or texture)
+ JPanel opt_Fill = new JPanel();
+ opt_Fill.setLayout(new BoxLayout(opt_Fill, BoxLayout.PAGE_AXIS));
+ JLabel opt_FillLabel = new JLabel("Filling:");
+ opt_FillLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
+ opt_Fill.add(opt_FillLabel);
+
+ ButtonGroup opt_FillGroup = new ButtonGroup();
+ JRadioButton opt_FillSolid = new JRadioButton("Solid colour", true);
+ opt_FillSolid.setActionCommand("solid");
+ opt_Fill.add(opt_FillSolid);
+ opt_FillGroup.add(opt_FillSolid);
+ JRadioButton opt_FillGradient = new JRadioButton("Gradient", false);
+ opt_FillGradient.setActionCommand("gradient");
+ opt_Fill.add(opt_FillGradient);
+ opt_FillGroup.add(opt_FillGradient);
+ JRadioButton opt_FillTexture = new JRadioButton("Texture", false);
+ opt_FillTexture.setActionCommand("texture");
+ opt_Fill.add(opt_FillTexture);
+ opt_FillGroup.add(opt_FillTexture);
+ JTextField opt_FillTextureFile = new JTextField("texture file");
+ opt_FillTextureFile.setAlignmentX(JComponent.LEFT_ALIGNMENT);
+ opt_Fill.add(opt_FillTextureFile);
+ elements.put("opt_FillGroup", opt_FillGroup);
+ elements.put("opt_FillTextureFile", opt_FillTextureFile);
+ layout.setConstraints(opt_Fill, gbc);
+ extras.add(opt_Fill);
+
+ // Stroke
+ JPanel opt_Stroke = new JPanel();
+ opt_Stroke.setLayout(new BoxLayout(opt_Stroke, BoxLayout.PAGE_AXIS));
+ JLabel opt_StrokeLabel = new JLabel("Stroke:");
+ opt_StrokeLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
+ opt_Stroke.add(opt_StrokeLabel);
+ JCheckBox opt_StrokeRandom = new JCheckBox("random", false);
+ elements.put("opt_StrokeRandom", opt_StrokeRandom);
+ opt_Stroke.add(opt_StrokeRandom);
+ gbc.gridwidth = GridBagConstraints.REMAINDER;
+ layout.setConstraints(opt_Stroke, gbc);
+ extras.add(opt_Stroke);
+
+ // Anti-Alias
+ JPanel opt_Alias = new JPanel();
+ opt_Alias.setLayout(new BoxLayout(opt_Alias, BoxLayout.PAGE_AXIS));
+ JLabel opt_AliasLabel = new JLabel("Anti-Aliasing:");
+ opt_AliasLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
+ opt_Alias.add(opt_AliasLabel);
+ JCheckBox opt_AliasOn = new JCheckBox("on", false);
+ elements.put("opt_AliasOn", opt_AliasOn);
+ opt_Alias.add(opt_AliasOn);
+ gbc.gridwidth = 1;
+ layout.setConstraints(opt_Alias, gbc);
+ extras.add(opt_Alias);
+
+ // Alpha composite
+ JPanel opt_Composite = new JPanel();
+ opt_Composite.setLayout(new BoxLayout(opt_Composite, BoxLayout.PAGE_AXIS));
+ JLabel opt_CompositeLabel = new JLabel("Alpha Composite:");
+ opt_CompositeLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
+ opt_Composite.add(opt_CompositeLabel);
+ JTextField opt_CompositeValue = new JTextField("1.0");
+ opt_CompositeValue.setAlignmentX(JComponent.LEFT_ALIGNMENT);
+ elements.put("opt_CompositeValue", opt_CompositeValue);
+ opt_Composite.add(opt_CompositeValue);
+ gbc.gridwidth = GridBagConstraints.REMAINDER;
+ layout.setConstraints(opt_Composite, gbc);
+ extras.add(opt_Composite);
+
+ // Transformations
+ // TODO: allow user-defined matrices for AffineTransform
+ // (backend already has hooks for it, need to create gui)
+ JLabel opt_TransformLabel = new JLabel("Transformations:");
+ opt_TransformLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
+ gbc.insets = new Insets(5, 2, 0, 15);
+ layout.setConstraints(opt_TransformLabel, gbc);
+ extras.add(opt_TransformLabel);
+
+ JPanel opt_Transform_Translate = new JPanel(new GridLayout(0, 2, 5, 5));
+ opt_Transform_Translate.add(new JLabel("x-axis translation "));
+ JTextField opt_TransformTranslateX = new JTextField("0");
+ opt_TransformTranslateX.setAlignmentX(JComponent.LEFT_ALIGNMENT);
+ opt_Transform_Translate.add(opt_TransformTranslateX);
+ elements.put("opt_TransformTranslateX", opt_TransformTranslateX);
+ opt_Transform_Translate.add(new JLabel("y-axis translation "));
+ JTextField opt_TransformTranslateY = new JTextField("0");
+ opt_TransformTranslateY.setAlignmentX(JComponent.LEFT_ALIGNMENT);
+ opt_Transform_Translate.add(opt_TransformTranslateY);
+ elements.put("opt_TransformTranslateY", opt_TransformTranslateY);
+ gbc.gridwidth = 1;
+ gbc.insets = new Insets(0, 2, 5, 15);
+ layout.setConstraints(opt_Transform_Translate, gbc);
+ extras.add(opt_Transform_Translate);
+
+ JPanel opt_Transform_Shear = new JPanel(new GridLayout(0, 2, 5, 5));
+ opt_Transform_Shear.add(new JLabel("x-axis shear "));
+ JTextField opt_TransformShearX = new JTextField("0");
+ opt_TransformShearX.setAlignmentX(JComponent.LEFT_ALIGNMENT);
+ opt_Transform_Shear.add(opt_TransformShearX);
+ elements.put("opt_TransformShearX", opt_TransformShearX);
+ opt_Transform_Shear.add(new JLabel("y-axis shear "));
+ JTextField opt_TransformShearY = new JTextField("0");
+ opt_Transform_Shear.add(opt_TransformShearY);
+ elements.put("opt_TransformShearY", opt_TransformShearY);
+ gbc.gridwidth = GridBagConstraints.REMAINDER;
+ layout.setConstraints(opt_Transform_Shear, gbc);
+ extras.add(opt_Transform_Shear);
+
+ JPanel opt_Transform_Rotate = new JPanel(new GridLayout(0, 2, 5, 5));
+ opt_Transform_Rotate.add(new JLabel("rotation (radians) "));
+ JTextField opt_TransformRotate = new JTextField("0");
+ opt_Transform_Rotate.add(opt_TransformRotate);
+ elements.put("opt_TransformRotate", opt_TransformRotate);
+ layout.setConstraints(opt_Transform_Rotate, gbc);
+ extras.add(opt_Transform_Rotate);
+
// Final submit button
JPanel submit = new JPanel();
submit.setLayout(new BoxLayout(submit, BoxLayout.PAGE_AXIS));
@@ -236,6 +367,8 @@ public class J2dBenchmarkGUI
body.setAlignmentX(JComponent.CENTER_ALIGNMENT);
panel.add(body);
+ extras.setAlignmentX(JComponent.CENTER_ALIGNMENT);
+ panel.add(extras);
submit.setAlignmentX(JComponent.CENTER_ALIGNMENT);
panel.add(submit);
@@ -324,6 +457,24 @@ public class J2dBenchmarkGUI
speed.setBuffers(((JCheckBox) elements.get("singlebuffer")).isSelected(),
((JCheckBox) elements.get("doublebuffer")).isSelected());
+ // Set additional processing options
+ speed.setFill(((ButtonGroup) elements.get("opt_FillGroup")).getSelection().getActionCommand(),
+ ((JTextField) elements.get("opt_FillTextureFile")).getText());
+
+ speed.setStroke(((JCheckBox) elements.get("opt_StrokeRandom")).isSelected());
+
+ speed.setAlias(((JCheckBox) elements.get("opt_AliasOn")).isSelected());
+
+ speed.setComposite(Float.parseFloat(((JTextField) elements.get("opt_CompositeValue")).getText()));
+
+ speed.setTranslation(Integer.parseInt(((JTextField) elements.get("opt_TransformTranslateX")).getText()),
+ Integer.parseInt(((JTextField) elements.get("opt_TransformTranslateY")).getText()));
+
+ speed.setRotation(Double.parseDouble(((JTextField) elements.get("opt_TransformRotate")).getText()));
+
+ speed.setShear(Double.parseDouble(((JTextField) elements.get("opt_TransformShearX")).getText()),
+ Double.parseDouble(((JTextField) elements.get("opt_TransformShearY")).getText()));
+
// Set tests
int testSuite = 0;
if (((JCheckBox) elements.get("test_arcDraw")).isSelected())
@@ -349,21 +500,31 @@ public class J2dBenchmarkGUI
{
speed.setTests(testSuite);
- // Create graphics.
- frame.add(speed, BorderLayout.CENTER);
- frame.setSize(Integer.parseInt(((JTextField) elements.get("width")).getText()),
- Integer.parseInt(((JTextField) elements.get("height")).getText()));
- frame.setVisible(true);
-
- // Insets are correctly set only after the native peer was created.
- Insets insets = frame.getInsets();
- frame.setSize(frame.getWidth() + insets.right + insets.left,
- frame.getHeight() + insets.top + insets.bottom);
+ String initResult = speed.init();
+
+ if (initResult == null)
+ {
+ // Create graphics.
+ frame.add(speed, BorderLayout.CENTER);
+ frame.setSize(
+ Integer.parseInt(((JTextField) elements.get("width")).getText()),
+ Integer.parseInt(((JTextField) elements.get("height")).getText()));
+ frame.setVisible(true);
+
+ // Insets are correctly set only after the native peer was
+ // created.
+ Insets insets = frame.getInsets();
+ frame.setSize(frame.getWidth() + insets.right + insets.left,
+ frame.getHeight() + insets.top + insets.bottom);
+
+ // Clear any old error messages
+ errorLabel.setText(" ");
+ }
+ else
+ errorLabel.setText(initResult);
}
else
- {
- errorLabel.setText("Please select at least one test.");
- }
+ errorLabel.setText("Please select at least one test.");
}
catch (NumberFormatException e)
{
@@ -397,8 +558,6 @@ public class J2dBenchmarkGUI
logger.addHandler(display);
myFrame = frame;
-
- super.init();
}
/**
@@ -461,6 +620,86 @@ public class J2dBenchmarkGUI
}
/**
+ * Set fill options
+ *
+ * @param type fill type: "solid", "gradient", or "texture"
+ * @param file filename to use if texturing
+ */
+ public void setFill(String type, String file)
+ {
+ if (type.equals("gradient"))
+ this.gradientFlag = true;
+ else if (type.equals("texture"))
+ {
+ this.texture = file;
+ }
+ }
+
+ /**
+ * Set stroke options
+ *
+ * @param stroke boolean flag to use random stroking or not
+ */
+ public void setStroke(boolean stroke)
+ {
+ this.strokeFlag = stroke;
+ }
+
+ /**
+ * Set anti-aliasing options
+ *
+ * @param alias boolean flag to use anti-aliasing or not
+ */
+ public void setAlias(boolean alias)
+ {
+ this.antialiasFlag = alias;
+ }
+
+ /**
+ * Set alpha composite
+ *
+ * @param alpha alpha composite
+ */
+ public void setComposite(float alpha)
+ {
+ this.composite = alpha;
+ }
+
+ /**
+ * Set translation values
+ *
+ * @param x x-axis translation
+ * @param y y-axis translation
+ */
+ public void setTranslation(int x, int y)
+ {
+ this.xtranslate = x;
+ this.ytranslate = y;
+ }
+
+ /**
+ * Set rotation
+ *
+ * @param theta angle to rotate by (radians)
+ */
+ public void setRotation(double theta)
+ {
+ this.rotate = theta;
+ }
+
+ /**
+ * Set shear values
+ *
+ * @param x x-axis shear value
+ * @param y-axis shear value
+ */
+ public void setShear(double x, double y)
+ {
+ this.xshear = x;
+ this.yshear = y;
+ }
+
+ /**
* Set tests to run
*
* @param tests bit-shifted list of tests (see J2dBenchmark constants)