/* * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @key headful * @bug 4678208 4771101 6328481 6588884 * @summary verify the pixelization of degenerate polylines and polygons * @run main PolyVertTest * @run main/othervm -Dsun.java2d.d3d=True PolyVertTest -hwonly * @run main/othervm -Dsun.java2d.opengl=True PolyVertTest -hwonly */ import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.awt.image.*; public class PolyVertTest { static int TESTWIDTH; static int TESTHEIGHT; static final int REG_TEST_WIDTH = 10; static final int REG_TEST_HEIGHT = 10; static final int FULL_TEST_WIDTH = 50; static final int FULL_TEST_HEIGHT = 200; static final int FRINGE = 2; static final int GREEN = Color.green.getRGB(); static final int RED = Color.red.getRGB(); static BufferedImage refImg; static BufferedImage errorImg; static Graphics errorG; static Component testCanvas; static int totalbadpixels; static int totalfuzzypixels; static int numbadtests; static int numfuzzytests; static int numframes; static int fuzzystarty; static boolean counting; static boolean showerrors; static boolean showresults; static boolean fringe; static boolean forceerror; static boolean fulltest = true; static boolean hwonly; static WindowListener windowCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { e.getWindow().hide(); if (--numframes <= 0) { System.exit(0); } } }; public PolyVertTest() { /* setBackground(Color.white); setForeground(Color.black); */ } static int polypts[][][] = { { // void polygon (no points) {}, {}, }, { // one point { 0 }, { 0 }, }, { // two points { 0, 5 }, { 0, 0 }, { 0, 0, 6, 1, 10, 0, 6, 1, 20, 0, 6, 1 }, { 0, 0, 6, 1, 10, 0, 1, 1, 15, 0, 1, 1, 20, 0, 1, 1, 25, 0, 1, 1 }, { 10, 0, 1, 1, 20, 0, 1, 1 }, }, { // open triangle { 0, 5, 5 }, { 0, 0, 5 }, { 0, 0, 6, 1, 5, 1, 1, 5, 10, 0, 6, 1, 15, 1, 1, 5, 11, 1, 1, 1, 12, 2, 1, 1, 13, 3, 1, 1, 14, 4, 1, 1, 20, 0, 6, 1, 25, 1, 1, 5, 21, 1, 1, 1, 22, 2, 1, 1, 23, 3, 1, 1, 24, 4, 1, 1 }, { 0, 0, 6, 1, 5, 1, 1, 5, 10, 0, 6, 1, 15, 1, 1, 5, 11, 1, 1, 1, 12, 2, 1, 1, 13, 3, 1, 1, 14, 4, 1, 1, 20, 0, 6, 1, 25, 1, 1, 5, 21, 1, 1, 1, 22, 2, 1, 1, 23, 3, 1, 1, 24, 4, 1, 1 }, { 10, 0, 1, 1, 20, 0, 1, 1 }, }, { // closed triangle { 0, 5, 5, 0 }, { 0, 0, 5, 0 }, { 0, 0, 6, 1, 5, 1, 1, 5, 1, 1, 1, 1, 2, 2, 1, 1, 3, 3, 1, 1, 4, 4, 1, 1, 10, 0, 6, 1, 15, 1, 1, 5, 11, 1, 1, 1, 12, 2, 1, 1, 13, 3, 1, 1, 14, 4, 1, 1, 20, 0, 6, 1, 25, 1, 1, 5, 21, 1, 1, 1, 22, 2, 1, 1, 23, 3, 1, 1, 24, 4, 1, 1 }, { 1, 0, 5, 1, 5, 1, 1, 5, 1, 1, 1, 1, 2, 2, 1, 1, 3, 3, 1, 1, 4, 4, 1, 1, 10, 0, 6, 1, 15, 1, 1, 5, 11, 1, 1, 1, 12, 2, 1, 1, 13, 3, 1, 1, 14, 4, 1, 1, 20, 0, 6, 1, 25, 1, 1, 5, 21, 1, 1, 1, 22, 2, 1, 1, 23, 3, 1, 1, 24, 4, 1, 1 }, { 0, 0, 1, 1, 10, 0, 1, 1, 20, 0, 1, 1 }, }, { // empty line { 0, 0 }, { 0, 0 }, { 0, 0, 1, 1, 10, 0, 1, 1, 20, 0, 1, 1 }, }, { // empty triangle { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 1, 1, 10, 0, 1, 1, 20, 0, 1, 1 }, }, }; public static void render(Graphics2D g2d) { g2d.setColor(Color.white); g2d.fillRect(0, 0, TESTWIDTH, TESTHEIGHT); g2d.setColor(Color.black); if (forceerror) { g2d.fillRect(2, 2, 2, 2); g2d.fillRect(15, 5, 1, 1); } if (!fulltest) { g2d.draw(new Rectangle2D.Double(5, 5, 0, 0)); return; } g2d.drawLine(10, 10, 10, 10); g2d.draw(new Line2D.Double(20, 10, 20, 10)); g2d.drawRect(10, 20, 0, 0); g2d.draw(new Rectangle2D.Double(20, 20, 0, 0)); g2d.setXORMode(Color.white); g2d.drawLine(10, 30, 10, 30); g2d.draw(new Line2D.Double(20, 30, 20, 30)); g2d.drawRect(10, 40, 0, 0); g2d.draw(new Rectangle2D.Double(20, 40, 0, 0)); g2d.setPaintMode(); int y = 50; for (int i = 0; i < polypts.length; i++) { int data[][] = polypts[i]; int xpoints[] = data[0]; int ypoints[] = data[1]; int npoints = xpoints.length; g2d.translate(10, y); g2d.drawPolyline(xpoints, ypoints, npoints); g2d.translate(10, 0); g2d.drawPolygon(xpoints, ypoints, npoints); g2d.translate(10, 0); g2d.draw(new Polygon(xpoints, ypoints, npoints)); g2d.translate(-30, -y); y += 10; } g2d.setXORMode(Color.white); for (int i = 0; i < polypts.length; i++) { int data[][] = polypts[i]; int xpoints[] = data[0]; int ypoints[] = data[1]; int npoints = xpoints.length; g2d.translate(10, y); g2d.drawPolyline(xpoints, ypoints, npoints); g2d.translate(10, 0); g2d.drawPolygon(xpoints, ypoints, npoints); g2d.translate(10, 0); g2d.draw(new Polygon(xpoints, ypoints, npoints)); g2d.translate(-30, -y); y += 10; } g2d.setPaintMode(); } public Dimension getPreferredSize() { return new Dimension(500, 500); } public static void usage(int exitcode) { System.err.println("usage: java PolyVertTest [