Path: blob/master/test/jdk/performance/client/RenderPerfTest/src/renderperf/RenderPerfTest.java
41154 views
/*1* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package renderperf;2425import java.awt.AlphaComposite;26import java.awt.Color;27import java.awt.Dimension;28import java.awt.Font;29import java.awt.Graphics;30import java.awt.Graphics2D;31import java.awt.Image;32import java.awt.LinearGradientPaint;33import java.awt.RadialGradientPaint;34import java.awt.RenderingHints;35import java.awt.Robot;3637import java.awt.event.WindowAdapter;38import java.awt.event.WindowEvent;39import java.awt.geom.AffineTransform;40import java.awt.geom.Ellipse2D;41import java.awt.geom.Point2D;42import java.awt.geom.QuadCurve2D;4344import java.awt.image.BufferedImage;45import java.awt.image.DataBuffer;46import java.awt.image.DataBufferByte;47import java.awt.image.DataBufferInt;48import java.awt.image.DataBufferShort;4950import java.io.IOException;51import java.lang.reflect.InvocationTargetException;52import java.lang.reflect.Method;53import java.util.HashSet;54import java.util.Objects;55import java.util.concurrent.CountDownLatch;56import java.util.concurrent.atomic.AtomicBoolean;5758import javax.imageio.ImageIO;59import javax.swing.JFrame;60import javax.swing.JPanel;61import javax.swing.SwingUtilities;62import javax.swing.Timer;63import javax.swing.WindowConstants;6465public class RenderPerfTest {66private static HashSet<String> ignoredTests = new HashSet<>();6768static {69ignoredTests.add("testWiredBoxAA");70}7172private final static int N = 1000;73private final static float WIDTH = 800;74private final static float HEIGHT = 800;75private final static float R = 25;76private final static int BW = 50;77private final static int BH = 50;78private final static int COUNT = 300;79private final static int DELAY = 10;80private final static int RESOLUTION = 5;81private final static int COLOR_TOLERANCE = 10;82private final static int MAX_MEASURE_TIME = 5000;838485interface Configurable {86void configure(Graphics2D g2d);87}8889interface Renderable {90void setup(Graphics2D g2d);91void render(Graphics2D g2d);92void update();93}9495static class Particles {96private float[] bx;97private float[] by;98private float[] vx;99private float[] vy;100private float r;101private int n;102103private float x0;104private float y0;105private float width;106private float height;107108Particles(int n, float r, float x0, float y0, float width, float height) {109bx = new float[n];110by = new float[n];111vx = new float[n];112vy = new float[n];113this.n = n;114this.r = r;115this.x0 = x0;116this.y0 = y0;117this.width = width;118this.height = height;119for (int i = 0; i < n; i++) {120bx[i] = (float) (x0 + r + 0.1 + Math.random() * (width - 2 * r - 0.2 - x0));121by[i] = (float) (y0 + r + 0.1 + Math.random() * (height - 2 * r - 0.2 - y0));122vx[i] = 0.1f * (float) (Math.random() * 2 * r - r);123vy[i] = 0.1f * (float) (Math.random() * 2 * r - r);124}125126}127128void render(Graphics2D g2d, ParticleRenderer renderer) {129for (int i = 0; i < n; i++) {130renderer.render(g2d, i, bx, by, vx, vy);131}132}133134void update() {135for (int i = 0; i < n; i++) {136bx[i] += vx[i];137if (bx[i] + r > width || bx[i] - r < x0) vx[i] = -vx[i];138by[i] += vy[i];139if (by[i] + r > height || by[i] - r < y0) vy[i] = -vy[i];140}141142}143144}145146ParticleRenderable createPR(ParticleRenderer renderer) {147return new ParticleRenderable(renderer);148}149150static class ParticleRenderable implements Renderable {151ParticleRenderer renderer;152Configurable configure;153154ParticleRenderable(ParticleRenderer renderer, Configurable configure) {155this.renderer = renderer;156this.configure = configure;157}158159ParticleRenderable(ParticleRenderer renderer) {160this(renderer, null);161}162163@Override164public void setup(Graphics2D g2d) {165if (configure != null) configure.configure(g2d);166}167168@Override169public void render(Graphics2D g2d) {170balls.render(g2d, renderer);171}172173@Override174public void update() {175balls.update();176}177178public ParticleRenderable configure(Configurable configure) {179this.configure = configure;180return this;181}182}183184interface ParticleRenderer {185void render(Graphics2D g2d, int id, float[] x, float[] y, float[] vx, float[] vy);186187}188189static class FlatParticleRenderer implements ParticleRenderer {190Color[] colors;191float r;192193FlatParticleRenderer(int n, float r) {194colors = new Color[n];195this.r = r;196for (int i = 0; i < n; i++) {197colors[i] = new Color((float) Math.random(),198(float) Math.random(), (float) Math.random());199}200}201202@Override203public void render(Graphics2D g2d, int id, float[] x, float[] y, float[] vx, float[] vy) {204g2d.setColor(colors[id % colors.length]);205g2d.fillOval((int)(x[id] - r), (int)(y[id] - r), (int)(2*r), (int)(2*r));206}207208}209210static class ClipFlatParticleRenderer extends FlatParticleRenderer {211212ClipFlatParticleRenderer(int n, float r) {213super(n, r);214}215216@Override217public void render(Graphics2D g2d, int id, float[] x, float[] y, float[] vx, float[] vy) {218if ((id % 10) == 0) {219g2d.setColor(colors[id % colors.length]);220g2d.setClip(new Ellipse2D.Double((int) (x[id] - r), (int) (y[id] - r), (int) (2 * r), (int) (2 * r)));221g2d.fillRect((int) (x[id] - 2 * r), (int) (y[id] - 2 * r), (int) (4 * r), (int) (4 * r));222}223}224225}226static class WhiteTextParticleRenderer implements ParticleRenderer {227float r;228229WhiteTextParticleRenderer(float r) {230this.r = r;231}232233void setPaint(Graphics2D g2d, int id) {234g2d.setColor(Color.WHITE);235}236237@Override238public void render(Graphics2D g2d, int id, float[] x, float[] y, float[] vx, float[] vy) {239setPaint(g2d, id);240g2d.drawString("The quick brown fox jumps over the lazy dog",241(int)(x[id] - r), (int)(y[id] - r));242g2d.drawString("The quick brown fox jumps over the lazy dog",243(int)(x[id] - r), (int)y[id]);244g2d.drawString("The quick brown fox jumps over the lazy dog",245(int)(x[id] - r), (int)(y[id] + r));246}247}248249static class TextParticleRenderer extends WhiteTextParticleRenderer {250Color[] colors;251252float r;253254TextParticleRenderer(int n, float r) {255super(r);256colors = new Color[n];257this.r = r;258for (int i = 0; i < n; i++) {259colors[i] = new Color((float) Math.random(),260(float) Math.random(), (float) Math.random());261}262}263264void setPaint(Graphics2D g2d, int id) {265g2d.setColor(colors[id % colors.length]);266}267}268269static class LargeTextParticleRenderer extends TextParticleRenderer {270271LargeTextParticleRenderer(int n, float r) {272super(n, r);273}274275@Override276public void render(Graphics2D g2d, int id, float[] x, float[] y, float[] vx, float[] vy) {277setPaint(g2d, id);278Font font = new Font("LucidaGrande", Font.PLAIN, 32);279g2d.setFont(font);280g2d.drawString("The quick brown fox jumps over the lazy dog",281(int)(x[id] - r), (int)(y[id] - r));282g2d.drawString("The quick brown fox jumps over the lazy dog",283(int)(x[id] - r), (int)y[id]);284g2d.drawString("The quick brown fox jumps over the lazy dog",285(int)(x[id] - r), (int)(y[id] + r));286}287}288289static class FlatOvalRotParticleRenderer extends FlatParticleRenderer {290291292FlatOvalRotParticleRenderer(int n, float r) {293super(n, r);294}295296void setPaint(Graphics2D g2d, int id) {297g2d.setColor(colors[id % colors.length]);298}299300@Override301public void render(Graphics2D g2d, int id, float[] x, float[] y, float[] vx, float[] vy) {302setPaint(g2d, id);303if (Math.abs(vx[id] + vy[id]) > 0.001) {304AffineTransform t = (AffineTransform) g2d.getTransform().clone();305double l = vx[id] / Math.sqrt(vx[id] * vx[id] + vy[id] * vy[id]);306if (vy[id] < 0) {307l = -l;308}309g2d.translate(x[id], y[id]);310g2d.rotate(Math.acos(l));311g2d.fillOval(-(int)r, (int)(-0.5*r), (int) (2 * r), (int)r);312g2d.setTransform(t);313} else {314g2d.fillOval((int)(x[id] - r), (int)(y[id] - 0.5*r),315(int) (2 * r), (int) r);316}317}318}319320static class LinGradOvalRotParticleRenderer extends FlatOvalRotParticleRenderer {321322323LinGradOvalRotParticleRenderer(int n, float r) {324super(n, r);325}326327@Override328void setPaint(Graphics2D g2d, int id) {329Point2D start = new Point2D.Double(- r, - 0.5*r);330Point2D end = new Point2D.Double( 2 * r, r);331float[] dist = {0.0f, 1.0f};332Color[] cls = {colors[id %colors.length], colors[(colors.length - id) %colors.length]};333LinearGradientPaint p =334new LinearGradientPaint(start, end, dist, cls);335g2d.setPaint(p);336}337}338339static class LinGrad3OvalRotParticleRenderer extends FlatOvalRotParticleRenderer {340341342LinGrad3OvalRotParticleRenderer(int n, float r) {343super(n, r);344}345346@Override347void setPaint(Graphics2D g2d, int id) {348Point2D start = new Point2D.Double(- r, - 0.5*r);349Point2D end = new Point2D.Double( 2 * r, r);350float[] dist = {0.0f, 0.5f, 1.0f};351Color[] cls = {352colors[id %colors.length],353colors[(colors.length - id) %colors.length],354colors[(id*5) %colors.length]};355LinearGradientPaint p =356new LinearGradientPaint(start, end, dist, cls);357g2d.setPaint(p);358}359}360361static class RadGrad3OvalRotParticleRenderer extends FlatOvalRotParticleRenderer {362363364RadGrad3OvalRotParticleRenderer(int n, float r) {365super(n, r);366}367368@Override369void setPaint(Graphics2D g2d, int id) {370Point2D start = new Point2D.Double();371float[] dist = {0.0f, 0.5f, 1.0f};372Color[] cls = {373colors[id %colors.length],374colors[(colors.length - id) %colors.length],375colors[(id*5) %colors.length]};376RadialGradientPaint p =377new RadialGradientPaint(start, r, dist, cls);378g2d.setPaint(p);379}380}381382static class FlatBoxParticleRenderer extends FlatParticleRenderer {383384385FlatBoxParticleRenderer(int n, float r) {386super(n, r);387}388@Override389public void render(Graphics2D g2d, int id, float[] x, float[] y, float[] vx, float[] vy) {390g2d.setColor(colors[id % colors.length]);391g2d.fillRect((int)(x[id] - r), (int)(y[id] - r), (int)(2*r), (int)(2*r));392393}394395}396397static class ClipFlatBoxParticleRenderer extends FlatParticleRenderer {398399400ClipFlatBoxParticleRenderer(int n, float r) {401super(n, r);402}403@Override404public void render(Graphics2D g2d, int id, float[] x, float[] y, float[] vx, float[] vy) {405if ((id % 10) == 0) {406g2d.setColor(colors[id % colors.length]);407g2d.setClip((int) (x[id] - r), (int) (y[id] - r), (int) (2 * r), (int) (2 * r));408g2d.fillRect((int) (x[id] - 2 * r), (int) (y[id] - 2 * r), (int) (4 * r), (int) (4 * r));409}410}411}412413static class ImgParticleRenderer extends FlatParticleRenderer {414BufferedImage dukeImg;415416ImgParticleRenderer(int n, float r) {417super(n, r);418try {419dukeImg = ImageIO.read(420Objects.requireNonNull(421RenderPerfTest.class.getClassLoader().getResourceAsStream(422"renderperf/images/duke.png")));423} catch (IOException e) {424throw new RuntimeException(e);425}426}427428@Override429public void render(Graphics2D g2d, int id, float[] x, float[] y, float[] vx, float[] vy) {430g2d.setColor(colors[id % colors.length]);431g2d.drawImage(dukeImg, (int)(x[id] - r), (int)(y[id] - r), (int)(2*r), (int)(2*r), null);432}433434}435436static class FlatBoxRotParticleRenderer extends FlatParticleRenderer {437438439FlatBoxRotParticleRenderer(int n, float r) {440super(n, r);441}442@Override443public void render(Graphics2D g2d, int id, float[] x, float[] y, float[] vx, float[] vy) {444g2d.setColor(colors[id % colors.length]);445if (Math.abs(vx[id] + vy[id]) > 0.001) {446AffineTransform t = (AffineTransform) g2d.getTransform().clone();447double l = vx[id] / Math.sqrt(vx[id] * vx[id] + vy[id] * vy[id]);448if (vy[id] < 0) {449l = -l;450}451g2d.translate(x[id], y[id]);452g2d.rotate(Math.acos(l));453g2d.fillRect(-(int)r, -(int)r, (int) (2 * r), (int) (2 * r));454g2d.setTransform(t);455} else {456g2d.fillRect((int)(x[id] - r), (int)(y[id] - r),457(int) (2 * r), (int) (2 * r));458}459}460}461462static class WiredParticleRenderer extends FlatParticleRenderer {463464465WiredParticleRenderer(int n, float r) {466super(n, r);467}468@Override469public void render(Graphics2D g2d, int id, float[] x, float[] y, float[] vx, float[] vy) {470g2d.setColor(colors[id % colors.length]);471g2d.drawOval((int)(x[id] - r), (int)(y[id] - r), (int)(2*r), (int)(2*r));472}473474}475static class WiredBoxParticleRenderer extends FlatParticleRenderer {476477WiredBoxParticleRenderer(int n, float r) {478super(n, r);479}480481@Override482public void render(Graphics2D g2d, int id, float[] x, float[] y, float[] vx, float[] vy) {483g2d.setColor(colors[id % colors.length]);484g2d.drawRect((int)(x[id] - r), (int)(y[id] - r), (int)(2*r), (int)(2*r));485}486487}488static class SegParticleRenderer extends FlatParticleRenderer {489490SegParticleRenderer(int n, float r) {491super(n, r);492}493494@Override495public void render(Graphics2D g2d, int id, float[] x, float[] y, float[] vx, float[] vy) {496double v = Math.sqrt(vx[id]*vx[id]+vy[id]*vy[id]);497float nvx = (float) (vx[id]/v);498float nvy = (float) (vy[id]/v);499g2d.setColor(colors[id % colors.length]);500g2d.drawLine((int)(x[id] - r*nvx), (int)(y[id] - r*nvy),501(int)(x[id] + 2*r*nvx), (int)(y[id] + 2*r*nvy));502}503504}505506507static class WiredQuadParticleRenderer extends FlatParticleRenderer {508509WiredQuadParticleRenderer(int n, float r) {510super(n, r);511}512513@Override514public void render(Graphics2D g2d, int id, float[] x, float[] y, float[] vx, float[] vy) {515if (id > 2 && (id % 3) == 0) {516g2d.setColor(colors[id % colors.length]);517g2d.draw(new QuadCurve2D.Float(x[id-3], y[id-3], x[id-2], y[id-2], x[id-1], y[id-1]));518}519520}521}522523static class FlatQuadParticleRenderer extends FlatParticleRenderer {524525FlatQuadParticleRenderer(int n, float r) {526super(n, r);527}528529@Override530public void render(Graphics2D g2d, int id, float[] x, float[] y, float[] vx, float[] vy) {531if (id > 2 && (id % 3) == 0) {532g2d.setColor(colors[id % colors.length]);533g2d.fill(new QuadCurve2D.Float(x[id-3], y[id-3], x[id-2], y[id-2], x[id-1], y[id-1]));534}535536}537}538539static class BlitImageParticleRenderer extends FlatParticleRenderer {540BufferedImage image;541542BlitImageParticleRenderer(int n, float r, BufferedImage img) {543super(n, r);544image = img;545fill(image);546}547548@Override549public void render(Graphics2D g2d, int id, float[] x, float[] y, float[] vx, float[] vy) {550g2d.drawImage(image, (int)(x[id] - r), (int)(y[id] - r), (int)(2*r), (int)(2*r), null);551}552553private static void fill(final Image image) {554final Graphics2D graphics = (Graphics2D) image.getGraphics();555graphics.setComposite(AlphaComposite.Src);556for (int i = 0; i < image.getHeight(null); ++i) {557graphics.setColor(new Color(i, 0, 0));558graphics.fillRect(0, i, image.getWidth(null), 1);559}560graphics.dispose();561}562563}564565static class SwBlitImageParticleRenderer extends BlitImageParticleRenderer {566567SwBlitImageParticleRenderer(int n, float r, final int type) {568super(n, r, makeUnmanagedBI(type));569}570571private static BufferedImage makeUnmanagedBI(final int type) {572final BufferedImage bi = new BufferedImage(17, 33, type);573final DataBuffer db = bi.getRaster().getDataBuffer();574if (db instanceof DataBufferInt) {575((DataBufferInt) db).getData();576} else if (db instanceof DataBufferShort) {577((DataBufferShort) db).getData();578} else if (db instanceof DataBufferByte) {579((DataBufferByte) db).getData();580}581bi.setAccelerationPriority(0.0f);582return bi;583}584}585586static class SurfaceBlitImageParticleRenderer extends BlitImageParticleRenderer {587588SurfaceBlitImageParticleRenderer(int n, float r, final int type) {589super(n, r, makeManagedBI(type));590}591592private static BufferedImage makeManagedBI(final int type) {593final BufferedImage bi = new BufferedImage(17, 33, type);594bi.setAccelerationPriority(1.0f);595return bi;596}597}598599static class PerfMeter {600private String name;601private int frame = 0;602603private JPanel panel;604605private long time;606private double execTime = 0;607private Color expColor = Color.RED;608AtomicBoolean waiting = new AtomicBoolean(false);609private double fps;610611PerfMeter(String name) {612this.name = name;613}614615PerfMeter exec(final Renderable renderable) throws Exception {616final CountDownLatch latch = new CountDownLatch(COUNT);617final CountDownLatch latchFrame = new CountDownLatch(1);618final long endTime = System.currentTimeMillis() + MAX_MEASURE_TIME;619620final JFrame f = new JFrame();621f.addWindowListener(new WindowAdapter() {622@Override623public void windowClosed(WindowEvent e) {624latchFrame.countDown();625}626});627628SwingUtilities.invokeAndWait(new Runnable() {629@Override630public void run() {631632panel = new JPanel()633{634@Override635protected void paintComponent(Graphics g) {636637super.paintComponent(g);638time = System.nanoTime();639Graphics2D g2d = (Graphics2D) g.create();640renderable.setup(g2d);641renderable.render(g2d);642g2d.setColor(expColor);643g.fillRect(0, 0, BW, BH);644}645};646647panel.setPreferredSize(new Dimension((int)(WIDTH + BW), (int)(HEIGHT + BH)));648panel.setBackground(Color.BLACK);649f.add(panel);650f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);651f.pack();652f.setVisible(true);653}654});655Robot robot = new Robot();656657Timer timer = new Timer(DELAY, e -> {658659if (waiting.compareAndSet(false, true)) {660Color c = robot.getPixelColor(661panel.getTopLevelAncestor().getX() + panel.getTopLevelAncestor().getInsets().left + BW / 2,662panel.getTopLevelAncestor().getY() + panel.getTopLevelAncestor().getInsets().top + BW / 2);663if (isAlmostEqual(c, Color.BLUE)) {664expColor = Color.RED;665} else {666expColor = Color.BLUE;667}668renderable.update();669panel.getParent().repaint();670671} else {672while (!isAlmostEqual(673robot.getPixelColor(674panel.getTopLevelAncestor().getX() + panel.getTopLevelAncestor().getInsets().left + BW/2,675panel.getTopLevelAncestor().getY() + panel.getTopLevelAncestor().getInsets().top + BH/2),676expColor))677{678try {679Thread.sleep(RESOLUTION);680} catch (InterruptedException ex) {681ex.printStackTrace();682}683}684time = System.nanoTime() - time;685execTime += time;686frame++;687waiting.set(false);688}689690if (System.currentTimeMillis() < endTime) {691latch.countDown();692} else {693while(latch.getCount() > 0) latch.countDown();694}695});696timer.start();697latch.await();698SwingUtilities.invokeAndWait(() -> {699timer.stop();700f.setVisible(false);701f.dispose();702});703704latchFrame.await();705if (execTime != 0 && frame != 0) {706fps = 1e9 / (execTime / frame);707} else {708fps = 0;709}710711return this;712}713714private void report() {715System.err.println(name + " : " + String.format("%.2f FPS", fps));716}717718private boolean isAlmostEqual(Color c1, Color c2) {719return Math.abs(c1.getRed() - c2.getRed()) < COLOR_TOLERANCE ||720Math.abs(c1.getGreen() - c2.getGreen()) < COLOR_TOLERANCE ||721Math.abs(c1.getBlue() - c2.getBlue()) < COLOR_TOLERANCE;722723}724}725726private static final Particles balls = new Particles(N, R, BW, BH, WIDTH, HEIGHT);727private static final ParticleRenderer flatRenderer = new FlatParticleRenderer(N, R);728private static final ParticleRenderer clipFlatRenderer = new ClipFlatParticleRenderer(N, R);729private static final ParticleRenderer flatOvalRotRenderer = new FlatOvalRotParticleRenderer(N, R);730private static final ParticleRenderer flatBoxRenderer = new FlatBoxParticleRenderer(N, R);731private static final ParticleRenderer clipFlatBoxParticleRenderer = new ClipFlatBoxParticleRenderer(N, R);732private static final ParticleRenderer flatBoxRotRenderer = new FlatBoxRotParticleRenderer(N, R);733private static final ParticleRenderer linGradOvalRotRenderer = new LinGradOvalRotParticleRenderer(N, R);734private static final ParticleRenderer linGrad3OvalRotRenderer = new LinGrad3OvalRotParticleRenderer(N, R);735private static final ParticleRenderer radGrad3OvalRotRenderer = new RadGrad3OvalRotParticleRenderer(N, R);736private static final ParticleRenderer wiredRenderer = new WiredParticleRenderer(N, R);737private static final ParticleRenderer wiredBoxRenderer = new WiredBoxParticleRenderer(N, R);738private static final ParticleRenderer segRenderer = new SegParticleRenderer(N, R);739private static final ParticleRenderer flatQuadRenderer = new FlatQuadParticleRenderer(N, R);740private static final ParticleRenderer wiredQuadRenderer = new WiredQuadParticleRenderer(N, R);741private static final ParticleRenderer imgRenderer = new ImgParticleRenderer(N, R);742private static final ParticleRenderer textRenderer = new TextParticleRenderer(N, R);743private static final ParticleRenderer largeTextRenderer = new LargeTextParticleRenderer(N, R);744private static final ParticleRenderer whiteTextRenderer = new WhiteTextParticleRenderer(R);745private static final ParticleRenderer argbSwBlitImageRenderer = new SwBlitImageParticleRenderer(N, R, BufferedImage.TYPE_INT_ARGB);746private static final ParticleRenderer bgrSwBlitImageRenderer = new SwBlitImageParticleRenderer(N, R, BufferedImage.TYPE_INT_BGR);747private static final ParticleRenderer argbSurfaceBlitImageRenderer = new SurfaceBlitImageParticleRenderer(N, R, BufferedImage.TYPE_INT_ARGB);748private static final ParticleRenderer bgrSurfaceBlitImageRenderer = new SurfaceBlitImageParticleRenderer(N, R, BufferedImage.TYPE_INT_BGR);749750private static final Configurable AA = (Graphics2D g2d) ->751g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,752RenderingHints.VALUE_ANTIALIAS_ON);753754private static final Configurable TextLCD = (Graphics2D g2d) ->755g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,756RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);757758private static final Configurable TextAA = (Graphics2D g2d) ->759g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,760RenderingHints.VALUE_TEXT_ANTIALIAS_ON);761762private static final Configurable XORMode = (Graphics2D g2d) ->763{g2d.setXORMode(Color.WHITE);};764765private static final Configurable XORModeLCDText = (Graphics2D g2d) ->766{g2d.setXORMode(Color.WHITE);767g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,768RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);};769770771public void testFlatOval() throws Exception {772(new PerfMeter("FlatOval")).exec(createPR(flatRenderer)).report();773}774775public void testFlatOvalAA() throws Exception {776(new PerfMeter("FlatOvalAA")).exec(createPR(flatRenderer).configure(AA)).report();777}778779public void testClipFlatOval() throws Exception {780(new PerfMeter("ClipFlatOval")).exec(createPR(clipFlatRenderer)).report();781}782783public void testClipFlatOvalAA() throws Exception {784(new PerfMeter("ClipFlatOvalAA")).exec(createPR(clipFlatRenderer).configure(AA)).report();785}786787public void testFlatBox() throws Exception {788(new PerfMeter("FlatBox")).exec(createPR(flatBoxRenderer)).report();789}790791public void testFlatBoxAA() throws Exception {792(new PerfMeter("FlatBoxAA")).exec(createPR(flatBoxRenderer).configure(AA)).report();793}794795public void testClipFlatBox() throws Exception {796(new PerfMeter("ClipFlatBox")).exec(createPR(clipFlatBoxParticleRenderer)).report();797}798799public void testClipFlatBoxAA() throws Exception {800(new PerfMeter("ClipFlatBoxAA")).exec(createPR(clipFlatBoxParticleRenderer).configure(AA)).report();801}802803public void testImage() throws Exception {804(new PerfMeter("Image")).exec(createPR(imgRenderer)).report();805}806807public void testImageAA() throws Exception {808(new PerfMeter("ImageAA")).exec(createPR(imgRenderer).configure(AA)).report();809}810811public void testRotatedBox() throws Exception {812(new PerfMeter("RotatedBox")).exec(createPR(flatBoxRotRenderer)).report();813}814815public void testRotatedBoxAA() throws Exception {816(new PerfMeter("RotatedBoxAA")).exec(createPR(flatBoxRotRenderer).configure(AA)).report();817}818819public void testRotatedOval() throws Exception {820(new PerfMeter("RotatedOval")).exec(createPR(flatOvalRotRenderer)).report();821}822823public void testRotatedOvalAA() throws Exception {824(new PerfMeter("RotatedOvalAA")).exec(createPR(flatOvalRotRenderer).configure(AA)).report();825}826827public void testLinGrad3RotatedOval() throws Exception {828(new PerfMeter("LinGrad3RotatedOval")).exec(createPR(linGrad3OvalRotRenderer)).report();829}830831public void testLinGrad3RotatedOvalAA() throws Exception {832(new PerfMeter("LinGrad3RotatedOvalAA")).exec(createPR(linGrad3OvalRotRenderer).configure(AA)).report();833}834835public void testRadGrad3RotatedOval() throws Exception {836(new PerfMeter("RadGrad3RotatedOval")).exec(createPR(radGrad3OvalRotRenderer)).report();837}838839public void testRadGrad3RotatedOvalAA() throws Exception {840(new PerfMeter("RadGrad3RotatedOvalAA")).exec(createPR(radGrad3OvalRotRenderer).configure(AA)).report();841}842843public void testLinGradRotatedOval() throws Exception {844(new PerfMeter("LinGradRotatedOval")).exec(createPR(linGradOvalRotRenderer)).report();845}846847public void testLinGradRotatedOvalAA() throws Exception {848(new PerfMeter("LinGradRotatedOvalAA")).exec(createPR(linGradOvalRotRenderer).configure(AA)).report();849}850851public void testWiredBubbles() throws Exception {852(new PerfMeter("WiredBubbles")).exec(createPR(wiredRenderer)).report();853}854855public void testWiredBubblesAA() throws Exception {856(new PerfMeter("WiredBubblesAA")).exec(createPR(wiredRenderer).configure(AA)).report();857}858859public void testWiredBox() throws Exception {860(new PerfMeter("WiredBox")).exec(createPR(wiredBoxRenderer)).report();861}862863public void testWiredBoxAA() throws Exception {864(new PerfMeter("WiredBoxAA")).exec(createPR(wiredBoxRenderer).configure(AA)).report();865}866867public void testLines() throws Exception {868(new PerfMeter("Lines")).exec(createPR(segRenderer)).report();869}870871public void testLinesAA() throws Exception {872(new PerfMeter("LinesAA")).exec(createPR(segRenderer).configure(AA)).report();873}874875public void testFlatQuad() throws Exception {876(new PerfMeter("FlatQuad")).exec(createPR(flatQuadRenderer)).report();877}878879public void testFlatQuadAA() throws Exception {880(new PerfMeter("FlatQuadAA")).exec(createPR(flatQuadRenderer).configure(AA)).report();881}882883public void testWiredQuad() throws Exception {884(new PerfMeter("WiredQuad")).exec(createPR(wiredQuadRenderer)).report();885}886887public void testWiredQuadAA() throws Exception {888(new PerfMeter("WiredQuadAA")).exec(createPR(wiredQuadRenderer).configure(AA)).report();889}890891public void testTextNoAA() throws Exception {892(new PerfMeter("TextNoAA")).exec(createPR(textRenderer)).report();893}894895public void testTextLCD() throws Exception {896(new PerfMeter("TextLCD")).exec(createPR(textRenderer).configure(TextLCD)).report();897}898899public void testTextGray() throws Exception {900(new PerfMeter("TextGray")).exec(createPR(textRenderer).configure(TextAA)).report();901}902903public void testLargeTextNoAA() throws Exception {904(new PerfMeter("LargeTextNoAA")).exec(createPR(largeTextRenderer)).report();905}906907public void testLargeTextLCD() throws Exception {908(new PerfMeter("LargeTextLCD")).exec(createPR(largeTextRenderer).configure(TextLCD)).report();909}910911public void testLargeTextGray() throws Exception {912(new PerfMeter("LargeTextGray")).exec(createPR(largeTextRenderer).configure(TextAA)).report();913}914public void testWhiteTextNoAA() throws Exception {915(new PerfMeter("WhiteTextNoAA")).exec(createPR(whiteTextRenderer)).report();916}917918public void testWhiteTextLCD() throws Exception {919(new PerfMeter("WhiteTextLCD")).exec(createPR(whiteTextRenderer).configure(TextLCD)).report();920}921922public void testWhiteTextGray() throws Exception {923(new PerfMeter("WhiteTextGray")).exec(createPR(whiteTextRenderer).configure(TextAA)).report();924}925926public void testArgbSwBlitImage() throws Exception {927(new PerfMeter("ArgbSwBlitImage")).exec(createPR(argbSwBlitImageRenderer)).report();928}929930public void testBgrSwBlitImage() throws Exception {931(new PerfMeter("BgrSwBlitImage")).exec(createPR(bgrSwBlitImageRenderer)).report();932}933934public void testArgbSurfaceBlitImage() throws Exception {935(new PerfMeter("ArgbSurfaceBlitImageRenderer")).exec(createPR(argbSurfaceBlitImageRenderer)).report();936}937938public void testBgrSurfaceBlitImage() throws Exception {939(new PerfMeter("BgrSurfaceBlitImage")).exec(createPR(bgrSurfaceBlitImageRenderer)).report();940}941942public void testFlatOval_XOR() throws Exception {943(new PerfMeter("FlatOval_XOR")).exec(createPR(flatRenderer).configure(XORMode)).report();944}945946public void testRotatedBox_XOR() throws Exception {947(new PerfMeter("RotatedBox_XOR")).exec(createPR(flatBoxRotRenderer).configure(XORMode)).report();948}949950public void testLines_XOR() throws Exception {951(new PerfMeter("Lines_XOR")).exec(createPR(segRenderer).configure(XORMode)).report();952}953954public void testImage_XOR() throws Exception {955(new PerfMeter("Image_XOR")).exec(createPR(imgRenderer).configure(XORMode)).report();956}957958public void testTextNoAA_XOR() throws Exception {959(new PerfMeter("TextNoAA_XOR")).exec(createPR(textRenderer).configure(XORMode)).report();960}961962public void testTextLCD_XOR() throws Exception {963(new PerfMeter("TextLCD_XOR")).exec(createPR(textRenderer).configure(XORModeLCDText)).report();964}965966public static void main(String[] args)967throws InvocationTargetException, IllegalAccessException, NoSuchMethodException968{969RenderPerfTest test = new RenderPerfTest();970971if (args.length > 0) {972for (String testCase : args) {973Method m = RenderPerfTest.class.getDeclaredMethod("test" + testCase);974m.invoke(test);975}976} else {977Method[] methods = RenderPerfTest.class.getDeclaredMethods();978for (Method m : methods) {979if (m.getName().startsWith("test") && !ignoredTests.contains(m.getName())) {980m.invoke(test);981}982}983}984}985}986987988