430N/A/*
2362N/A * Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved.
430N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
430N/A *
430N/A * This code is free software; you can redistribute it and/or modify it
430N/A * under the terms of the GNU General Public License version 2 only, as
430N/A * published by the Free Software Foundation.
430N/A *
430N/A * This code is distributed in the hope that it will be useful, but WITHOUT
430N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
430N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
430N/A * version 2 for more details (a copy is included in the LICENSE file that
430N/A * accompanied this code).
430N/A *
430N/A * You should have received a copy of the GNU General Public License version
430N/A * 2 along with this work; if not, write to the Free Software Foundation,
430N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
430N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
430N/A */
430N/A
430N/A/*
430N/A * @test
430N/A * @bug 4678208 4771101 6328481 6588884
430N/A * @summary verify the pixelization of degenerate polylines and polygons
430N/A * @run main PolyVertTest
430N/A * @run main/othervm -Dsun.java2d.d3d=True PolyVertTest -hwonly
430N/A * @run main/othervm -Dsun.java2d.opengl=True PolyVertTest -hwonly
430N/A */
430N/A
430N/Aimport java.awt.*;
430N/Aimport java.awt.event.*;
430N/Aimport java.awt.geom.*;
430N/Aimport java.awt.image.*;
430N/A
430N/Apublic class PolyVertTest {
430N/A static int TESTWIDTH;
430N/A static int TESTHEIGHT;
430N/A static final int REG_TEST_WIDTH = 10;
430N/A static final int REG_TEST_HEIGHT = 10;
430N/A static final int FULL_TEST_WIDTH = 50;
430N/A static final int FULL_TEST_HEIGHT = 200;
430N/A
430N/A static final int FRINGE = 2;
430N/A static final int GREEN = Color.green.getRGB();
430N/A static final int RED = Color.red.getRGB();
430N/A
430N/A static BufferedImage refImg;
430N/A static BufferedImage errorImg;
430N/A static Graphics errorG;
430N/A static Component testCanvas;
430N/A
430N/A static int totalbadpixels;
430N/A static int totalfuzzypixels;
430N/A static int numbadtests;
430N/A static int numfuzzytests;
430N/A static int numframes;
430N/A static int fuzzystarty;
430N/A
430N/A static boolean counting;
430N/A static boolean showerrors;
430N/A static boolean showresults;
430N/A static boolean fringe;
430N/A static boolean forceerror;
430N/A static boolean fulltest = true;
430N/A static boolean hwonly;
430N/A
430N/A static WindowListener windowCloser = new WindowAdapter() {
430N/A public void windowClosing(WindowEvent e) {
430N/A e.getWindow().hide();
430N/A if (--numframes <= 0) {
430N/A System.exit(0);
430N/A }
430N/A }
430N/A };
430N/A
430N/A public PolyVertTest() {
430N/A /*
430N/A setBackground(Color.white);
430N/A setForeground(Color.black);
430N/A */
430N/A }
430N/A
430N/A static int polypts[][][] = {
430N/A {
430N/A // void polygon (no points)
430N/A {}, {},
430N/A },
430N/A {
430N/A // one point
430N/A { 0 }, { 0 },
430N/A },
430N/A {
430N/A // two points
430N/A { 0, 5 }, { 0, 0 },
430N/A { 0, 0, 6, 1,
430N/A 10, 0, 6, 1,
430N/A 20, 0, 6, 1 },
430N/A { 0, 0, 6, 1,
430N/A 10, 0, 1, 1, 15, 0, 1, 1,
430N/A 20, 0, 1, 1, 25, 0, 1, 1 },
430N/A { 10, 0, 1, 1,
430N/A 20, 0, 1, 1 },
430N/A },
430N/A {
430N/A // open triangle
430N/A { 0, 5, 5 }, { 0, 0, 5 },
430N/A
430N/A { 0, 0, 6, 1, 5, 1, 1, 5,
430N/A
430N/A 10, 0, 6, 1, 15, 1, 1, 5, 11, 1, 1, 1,
430N/A 12, 2, 1, 1, 13, 3, 1, 1, 14, 4, 1, 1,
430N/A
430N/A 20, 0, 6, 1, 25, 1, 1, 5, 21, 1, 1, 1,
430N/A 22, 2, 1, 1, 23, 3, 1, 1, 24, 4, 1, 1 },
430N/A
430N/A { 0, 0, 6, 1, 5, 1, 1, 5,
430N/A
430N/A 10, 0, 6, 1, 15, 1, 1, 5, 11, 1, 1, 1,
430N/A 12, 2, 1, 1, 13, 3, 1, 1, 14, 4, 1, 1,
430N/A
430N/A 20, 0, 6, 1, 25, 1, 1, 5, 21, 1, 1, 1,
430N/A 22, 2, 1, 1, 23, 3, 1, 1, 24, 4, 1, 1 },
430N/A
430N/A { 10, 0, 1, 1,
430N/A 20, 0, 1, 1 },
430N/A },
430N/A {
430N/A // closed triangle
430N/A { 0, 5, 5, 0 }, { 0, 0, 5, 0 },
430N/A
430N/A { 0, 0, 6, 1, 5, 1, 1, 5, 1, 1, 1, 1,
430N/A 2, 2, 1, 1, 3, 3, 1, 1, 4, 4, 1, 1,
430N/A
430N/A 10, 0, 6, 1, 15, 1, 1, 5, 11, 1, 1, 1,
430N/A 12, 2, 1, 1, 13, 3, 1, 1, 14, 4, 1, 1,
430N/A
430N/A 20, 0, 6, 1, 25, 1, 1, 5, 21, 1, 1, 1,
430N/A 22, 2, 1, 1, 23, 3, 1, 1, 24, 4, 1, 1 },
430N/A
430N/A { 1, 0, 5, 1, 5, 1, 1, 5, 1, 1, 1, 1,
430N/A 2, 2, 1, 1, 3, 3, 1, 1, 4, 4, 1, 1,
430N/A
430N/A 10, 0, 6, 1, 15, 1, 1, 5, 11, 1, 1, 1,
430N/A 12, 2, 1, 1, 13, 3, 1, 1, 14, 4, 1, 1,
430N/A
430N/A 20, 0, 6, 1, 25, 1, 1, 5, 21, 1, 1, 1,
430N/A 22, 2, 1, 1, 23, 3, 1, 1, 24, 4, 1, 1 },
430N/A
430N/A { 0, 0, 1, 1,
430N/A 10, 0, 1, 1,
430N/A 20, 0, 1, 1 },
430N/A },
430N/A {
430N/A // empty line
430N/A { 0, 0 }, { 0, 0 },
430N/A { 0, 0, 1, 1,
430N/A 10, 0, 1, 1,
430N/A 20, 0, 1, 1 },
430N/A },
430N/A {
430N/A // empty triangle
430N/A { 0, 0, 0 }, { 0, 0, 0 },
430N/A { 0, 0, 1, 1,
430N/A 10, 0, 1, 1,
430N/A 20, 0, 1, 1 },
430N/A },
430N/A };
430N/A
430N/A public static void render(Graphics2D g2d) {
430N/A g2d.setColor(Color.white);
430N/A g2d.fillRect(0, 0, TESTWIDTH, TESTHEIGHT);
430N/A g2d.setColor(Color.black);
430N/A
430N/A if (forceerror) {
430N/A g2d.fillRect(2, 2, 2, 2);
430N/A g2d.fillRect(15, 5, 1, 1);
430N/A }
430N/A
430N/A if (!fulltest) {
430N/A g2d.draw(new Rectangle2D.Double(5, 5, 0, 0));
430N/A return;
430N/A }
430N/A
430N/A g2d.drawLine(10, 10, 10, 10);
430N/A g2d.draw(new Line2D.Double(20, 10, 20, 10));
430N/A
430N/A g2d.drawRect(10, 20, 0, 0);
430N/A g2d.draw(new Rectangle2D.Double(20, 20, 0, 0));
430N/A
430N/A g2d.setXORMode(Color.white);
430N/A
430N/A g2d.drawLine(10, 30, 10, 30);
430N/A g2d.draw(new Line2D.Double(20, 30, 20, 30));
430N/A
430N/A g2d.drawRect(10, 40, 0, 0);
430N/A g2d.draw(new Rectangle2D.Double(20, 40, 0, 0));
430N/A
430N/A g2d.setPaintMode();
430N/A
430N/A int y = 50;
430N/A for (int i = 0; i < polypts.length; i++) {
430N/A int data[][] = polypts[i];
430N/A int xpoints[] = data[0];
430N/A int ypoints[] = data[1];
430N/A int npoints = xpoints.length;
430N/A g2d.translate(10, y);
430N/A g2d.drawPolyline(xpoints, ypoints, npoints);
430N/A g2d.translate(10, 0);
430N/A g2d.drawPolygon(xpoints, ypoints, npoints);
430N/A g2d.translate(10, 0);
430N/A g2d.draw(new Polygon(xpoints, ypoints, npoints));
430N/A g2d.translate(-30, -y);
430N/A y += 10;
430N/A }
430N/A g2d.setXORMode(Color.white);
430N/A for (int i = 0; i < polypts.length; i++) {
430N/A int data[][] = polypts[i];
430N/A int xpoints[] = data[0];
430N/A int ypoints[] = data[1];
430N/A int npoints = xpoints.length;
430N/A g2d.translate(10, y);
430N/A g2d.drawPolyline(xpoints, ypoints, npoints);
430N/A g2d.translate(10, 0);
430N/A g2d.drawPolygon(xpoints, ypoints, npoints);
430N/A g2d.translate(10, 0);
430N/A g2d.draw(new Polygon(xpoints, ypoints, npoints));
430N/A g2d.translate(-30, -y);
430N/A y += 10;
430N/A }
430N/A g2d.setPaintMode();
430N/A }
430N/A
430N/A public Dimension getPreferredSize() {
430N/A return new Dimension(500, 500);
430N/A }
430N/A
430N/A public static void usage(int exitcode) {
430N/A System.err.println("usage: java PolyVertTest [<option>]*");
430N/A System.err.println(" -usage "+
430N/A "print this usage summary");
430N/A System.err.println(" -count "+
430N/A "run all tests and accumulate error counts");
430N/A System.err.println(" -forceerror "+
430N/A "force at least one error in each test");
430N/A System.err.println(" -fringe "+
430N/A "draw a yellow fringe around problems");
430N/A System.err.println(" -showerrors "+
430N/A "display results window for tests with problems");
430N/A System.err.println(" -showresults "+
430N/A "display results window for all tests");
430N/A System.err.println(" -quicktest "+
430N/A "only run test cases reported in bug reports");
430N/A System.err.println(" -fulltest "+
430N/A "run full suite of test cases for a 'unit test'");
430N/A System.err.println(" -hwonly "+
430N/A "only run tests for screen and VolatileImage");
430N/A System.exit(exitcode);
430N/A }
430N/A
430N/A public static void main(String argv[]) {
430N/A for (int i = 0; i < argv.length; i++) {
430N/A String arg = argv[i];
430N/A if (arg.equalsIgnoreCase("-count")) {
430N/A counting = true;
430N/A } else if (arg.equalsIgnoreCase("-forceerror")) {
430N/A forceerror = true;
430N/A } else if (arg.equalsIgnoreCase("-fringe")) {
430N/A fringe = true;
430N/A } else if (arg.equalsIgnoreCase("-showerrors")) {
430N/A showerrors = true;
430N/A } else if (arg.equalsIgnoreCase("-showresults")) {
430N/A showresults = true;
430N/A } else if (arg.equalsIgnoreCase("-quicktest")) {
430N/A fulltest = false;
430N/A } else if (arg.equalsIgnoreCase("-fulltest")) {
430N/A fulltest = true;
430N/A } else if (arg.equalsIgnoreCase("-hwonly")) {
430N/A hwonly = true;
430N/A } else if (arg.equalsIgnoreCase("-usage")) {
430N/A usage(0);
430N/A } else {
430N/A System.err.println("unknown option: "+arg);
430N/A usage(1);
430N/A }
430N/A }
430N/A
430N/A if (fulltest) {
430N/A TESTWIDTH = FULL_TEST_WIDTH;
430N/A TESTHEIGHT = FULL_TEST_HEIGHT;
430N/A } else {
430N/A TESTWIDTH = REG_TEST_WIDTH;
430N/A TESTHEIGHT = REG_TEST_HEIGHT;
430N/A }
430N/A
430N/A // Prevents premature exit by the WindowAdapter if the user
430N/A // closes the last visible results window before we've
430N/A // finished our tests.
430N/A numframes++;
430N/A
430N/A makeReferenceImage();
430N/A testScreen();
430N/A testVolatileImage();
430N/A if (!hwonly) {
430N/A testBufferedImage();
430N/A testOffscreen();
430N/A testCompatibleImages();
430N/A }
430N/A if (totalfuzzypixels > 0) {
430N/A System.err.println(totalfuzzypixels+" fuzzy pixels found in "+
430N/A numfuzzytests+" tests");
430N/A }
430N/A if (totalbadpixels > 0) {
430N/A throw new RuntimeException(totalbadpixels+" bad pixels found in "+
430N/A numbadtests+" tests");
430N/A }
430N/A System.out.println("Test done - no bad pixels found");
430N/A
430N/A --numframes;
430N/A
430N/A if (counting || ((showresults || showerrors) && numframes == 0)) {
430N/A System.exit(0);
430N/A }
430N/A }
430N/A
430N/A public static void makeReferenceImage() {
430N/A refImg = new BufferedImage(TESTWIDTH, TESTHEIGHT,
430N/A BufferedImage.TYPE_INT_RGB);
430N/A Graphics g = refImg.getGraphics();
430N/A
430N/A g.setColor(Color.white);
430N/A g.fillRect(0, 0, TESTWIDTH, TESTHEIGHT);
430N/A
430N/A g.setColor(Color.black);
430N/A
430N/A if (!fulltest) {
430N/A g.fillRect(5, 5, 1, 1);
430N/A g.dispose();
430N/A return;
430N/A }
430N/A
430N/A for (int y = 10; y < 50; y += 10) {
430N/A g.fillRect(10, y, 1, 1);
430N/A g.fillRect(20, y, 1, 1);
430N/A }
430N/A int y = 50;
430N/A for (int i = 0; i < polypts.length; i++) {
430N/A int data[][] = polypts[i];
430N/A g.translate(10, y);
430N/A if (data.length > 2) {
430N/A int rectvals[] = data[2];
430N/A for (int j = 0; j < rectvals.length; j += 4) {
430N/A g.fillRect(rectvals[j+0], rectvals[j+1],
430N/A rectvals[j+2], rectvals[j+3]);
430N/A }
430N/A }
430N/A g.translate(-10, -y);
430N/A y += 10;
430N/A }
430N/A fuzzystarty = y;
430N/A for (int i = 0; i < polypts.length; i++) {
430N/A int data[][] = polypts[i];
430N/A g.translate(10, y);
430N/A if (data.length > 2) {
430N/A int rectvals[] = data.length > 3 ? data[3] : data[2];
430N/A for (int j = 0; j < rectvals.length; j += 4) {
430N/A g.fillRect(rectvals[j+0], rectvals[j+1],
430N/A rectvals[j+2], rectvals[j+3]);
430N/A }
430N/A }
430N/A g.translate(-10, -y);
430N/A y += 10;
430N/A }
430N/A g.dispose();
430N/A }
430N/A
430N/A public static void initerrorbuf() {
430N/A if (errorImg == null) {
430N/A droperrorbuf();
430N/A errorImg = new BufferedImage(TESTWIDTH, TESTHEIGHT,
430N/A BufferedImage.TYPE_INT_RGB);
430N/A }
430N/A if (errorG == null) {
430N/A errorG = errorImg.getGraphics();
430N/A }
430N/A errorG.setColor(Color.green);
430N/A errorG.fillRect(0, 0, TESTWIDTH, TESTHEIGHT);
430N/A errorG.setColor(Color.red);
430N/A }
430N/A
430N/A public static void droperrorbuf() {
430N/A errorImg = null;
430N/A if (errorG != null) {
430N/A errorG.dispose();
430N/A }
430N/A errorG = null;
430N/A }
430N/A
430N/A public static void test(Image img, String name) {
430N/A Graphics2D g2d = (Graphics2D) img.getGraphics();
430N/A render(g2d);
430N/A g2d.dispose();
430N/A verify(img, name);
430N/A }
430N/A
430N/A public static void test(BufferedImage bimg, String name) {
430N/A Graphics2D g2d = bimg.createGraphics();
430N/A render(g2d);
430N/A g2d.dispose();
430N/A verify(bimg, name);
430N/A }
430N/A
430N/A public static void verify(Image img, String name) {
430N/A BufferedImage bimg;
430N/A if (img instanceof BufferedImage) {
430N/A bimg = (BufferedImage) img;
430N/A } else {
430N/A bimg = new BufferedImage(TESTWIDTH, TESTHEIGHT,
430N/A BufferedImage.TYPE_INT_RGB);
430N/A Graphics g = bimg.getGraphics();
430N/A g.drawImage(img, 0, 0, null);
430N/A g.dispose();
430N/A }
430N/A verify(bimg, name);
430N/A }
430N/A
430N/A public static boolean isFuzzyPixel(int X, int Y) {
430N/A int ytrans = fuzzystarty;
430N/A if (!fulltest || Y < ytrans) {
430N/A return false;
430N/A }
430N/A for (int i = 0; i < polypts.length; i++) {
430N/A int data[][] = polypts[i];
430N/A if (data.length > 4) {
430N/A int rectvals[] = data[4];
430N/A for (int j = 0; j < rectvals.length; j += 4) {
430N/A int rectx = rectvals[j+0] + 10;
430N/A int recty = rectvals[j+1] + ytrans;
430N/A int rectw = rectvals[j+2];
430N/A int recth = rectvals[j+3];
430N/A if (X >= rectx && Y >= recty &&
430N/A X < rectx + rectw && Y < recty + recth)
430N/A {
430N/A return true;
430N/A }
430N/A }
430N/A }
430N/A ytrans += 10;
430N/A }
430N/A return false;
430N/A }
430N/A
430N/A public static void verify(BufferedImage bimg, String name) {
430N/A int numbadpixels = 0;
430N/A int numfuzzypixels = 0;
430N/A for (int y = 0; y < TESTHEIGHT; y++) {
430N/A for (int x = 0; x < TESTWIDTH; x++) {
430N/A if (refImg.getRGB(x, y) != bimg.getRGB(x, y)) {
430N/A boolean isfuzzy = isFuzzyPixel(x, y);
430N/A if (showerrors || showresults) {
430N/A if (errorG == null) {
430N/A initerrorbuf();
430N/A }
430N/A errorG.setColor(isfuzzy ? Color.blue : Color.red);
430N/A errorG.fillRect(x, y, 1, 1);
430N/A } else if (!counting && !isfuzzy) {
430N/A throw new RuntimeException("Error at "+x+", "+y+
430N/A " while testing: "+name);
430N/A }
430N/A if (isfuzzy) {
430N/A numfuzzypixels++;
430N/A } else {
430N/A numbadpixels++;
430N/A }
430N/A }
430N/A }
430N/A }
430N/A if (numbadpixels > 0 || numfuzzypixels > 0) {
430N/A if (numbadpixels > 0) {
430N/A totalbadpixels += numbadpixels;
430N/A numbadtests++;
430N/A }
430N/A if (numfuzzypixels > 0) {
430N/A totalfuzzypixels += numfuzzypixels;
430N/A numfuzzytests++;
430N/A }
430N/A System.out.println(numbadpixels+" bad pixels and "+
430N/A numfuzzypixels+" questionable pixels "+
430N/A "found while testing "+name);
430N/A if (showerrors || showresults) {
430N/A displaydiffs(bimg, name);
430N/A }
430N/A } else if (showresults) {
430N/A if (errorG == null) {
430N/A initerrorbuf();
430N/A }
430N/A displaydiffs(bimg, name);
430N/A }
430N/A }
430N/A
430N/A public static void displaydiffs(BufferedImage bimg, String name) {
430N/A if (fringe) {
430N/A errorG.setColor(Color.yellow);
430N/A for (int y = 0; y < TESTHEIGHT; y++) {
430N/A for (int x = 0; x < TESTWIDTH; x++) {
430N/A if (errorImg.getRGB(x, y) == RED) {
430N/A for (int iy = y-FRINGE; iy <= y+FRINGE; iy++) {
430N/A for (int ix = x-FRINGE; ix <= x+FRINGE; ix++) {
430N/A if (ix >= 0 && ix < TESTWIDTH &&
430N/A iy >= 0 && iy < TESTHEIGHT &&
430N/A errorImg.getRGB(ix, iy) == GREEN)
430N/A {
430N/A errorG.fillRect(ix, iy, 1, 1);
430N/A }
430N/A }
430N/A }
430N/A }
430N/A }
430N/A }
430N/A }
430N/A Frame f = new Frame("Results for "+name);
430N/A f.setLayout(new BorderLayout());
430N/A f.addWindowListener(windowCloser);
430N/A ++numframes;
430N/A Panel p = new Panel();
430N/A p.add(new ImageCanvas(bimg));
430N/A p.add(new ImageCanvas(errorImg));
430N/A p.add(new ImageCanvas(refImg));
430N/A f.add(p, "Center");
430N/A droperrorbuf();
430N/A f.pack();
430N/A f.show();
430N/A }
430N/A
430N/A public static void testBufferedImage() {
430N/A testBufferedImage(BufferedImage.TYPE_INT_RGB, "IntXrgb");
430N/A testBufferedImage(BufferedImage.TYPE_INT_ARGB, "IntArgb");
430N/A testBufferedImage(BufferedImage.TYPE_3BYTE_BGR, "ThreeByte");
430N/A testBufferedImage(BufferedImage.TYPE_4BYTE_ABGR, "FourByte");
430N/A testBufferedImage(BufferedImage.TYPE_USHORT_555_RGB, "UShort555");
430N/A testBufferedImage(BufferedImage.TYPE_BYTE_GRAY, "ByteGray");
430N/A testBufferedImage(BufferedImage.TYPE_BYTE_INDEXED, "Indexed");
430N/A }
430N/A
430N/A public static void testBufferedImage(int type, String name) {
430N/A BufferedImage bimg = new BufferedImage(TESTWIDTH, TESTHEIGHT, type);
430N/A test(bimg, name);
430N/A }
430N/A
430N/A public static void testScreen() {
430N/A Frame f = new Frame("PolyVertTest");
430N/A TestCanvas child = new TestCanvas();
430N/A testCanvas = child;
430N/A f.add(child);
430N/A f.pack();
430N/A f.show();
430N/A BufferedImage bimg = child.getImage();
430N/A f.hide();
430N/A verify(bimg, "Screen");
430N/A }
430N/A
430N/A public static void testOffscreen() {
430N/A Image img = testCanvas.createImage(TESTWIDTH, TESTHEIGHT);
430N/A test(img, "Offscreen");
430N/A }
430N/A
430N/A public static void testCompatibleImages() {
430N/A GraphicsEnvironment genv =
430N/A GraphicsEnvironment.getLocalGraphicsEnvironment();
430N/A GraphicsDevice gdevs[] = genv.getScreenDevices();
430N/A for (int i = 0; i < gdevs.length; i++) {
430N/A testCompatibleImages(gdevs[i]);
430N/A }
430N/A }
430N/A
430N/A public static void testCompatibleImages(GraphicsDevice gdev) {
430N/A GraphicsConfiguration gconfigs[] = gdev.getConfigurations();
430N/A for (int i = 0; i < gconfigs.length; i++) {
430N/A testCompatibleImages(gconfigs[i]);
430N/A }
430N/A }
430N/A
430N/A public static void testCompatibleImages(GraphicsConfiguration gconfig) {
430N/A test(gconfig.createCompatibleImage(TESTWIDTH, TESTHEIGHT),
430N/A gconfig+".createCompat()");
430N/A test(gconfig.createCompatibleImage(TESTWIDTH, TESTHEIGHT,
430N/A Transparency.OPAQUE),
430N/A gconfig+".createCompat(OPAQUE)");
430N/A test(gconfig.createCompatibleImage(TESTWIDTH, TESTHEIGHT,
430N/A Transparency.BITMASK),
430N/A gconfig+".createCompat(BITMASK)");
430N/A test(gconfig.createCompatibleImage(TESTWIDTH, TESTHEIGHT,
430N/A Transparency.TRANSLUCENT),
430N/A gconfig+".createCompat(TRANSLUCENT)");
430N/A test(gconfig.createCompatibleVolatileImage(TESTWIDTH, TESTHEIGHT),
430N/A gconfig+".createCompatVolatile()");
430N/A }
430N/A
430N/A public static void testVolatileImage() {
430N/A Image img = testCanvas.createVolatileImage(TESTWIDTH, TESTHEIGHT);
430N/A test(img, "Volatile");
430N/A }
430N/A
430N/A public static class ImageCanvas extends Canvas {
430N/A BufferedImage bimg;
430N/A
430N/A public ImageCanvas(BufferedImage bimg) {
430N/A this.bimg = bimg;
430N/A }
430N/A
430N/A public Dimension getPreferredSize() {
430N/A return new Dimension(bimg.getWidth(), bimg.getHeight());
430N/A }
430N/A
430N/A public void paint(Graphics g) {
430N/A g.drawImage(bimg, 0, 0, null);
430N/A }
430N/A }
430N/A
430N/A public static class TestCanvas extends Canvas {
430N/A BufferedImage bimg;
430N/A
430N/A public Dimension getPreferredSize() {
430N/A return new Dimension(TESTWIDTH, TESTHEIGHT);
430N/A }
430N/A
430N/A public void paint(Graphics g) {
430N/A if (bimg != null ||
430N/A getWidth() < TESTWIDTH ||
430N/A getHeight() < TESTHEIGHT)
430N/A {
430N/A return;
430N/A }
430N/A render((Graphics2D) g);
430N/A Toolkit.getDefaultToolkit().sync();
430N/A Point p = getLocationOnScreen();
430N/A Rectangle r = new Rectangle(p.x, p.y, TESTWIDTH, TESTHEIGHT);
430N/A try {
430N/A bimg = new Robot().createScreenCapture(r);
430N/A } catch (AWTException e) {
430N/A e.printStackTrace();
430N/A }
430N/A synchronized (this) {
430N/A notifyAll();
430N/A }
430N/A }
430N/A
430N/A public synchronized BufferedImage getImage() {
430N/A while (bimg == null) {
430N/A try {
430N/A wait();
430N/A } catch (InterruptedException e) {
430N/A return null;
430N/A }
430N/A }
430N/A return bimg;
430N/A }
430N/A }
430N/A}