Path: blob/master/test/jdk/sun/java2d/marlin/StrokedLinePerf.java
41149 views
/*1* Copyright (c) 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*/2223import java.awt.BasicStroke;24import java.awt.Graphics2D;25import java.awt.RenderingHints;26import java.awt.Stroke;27import java.awt.geom.Line2D;28import java.awt.image.BufferedImage;2930import static java.awt.image.BufferedImage.TYPE_INT_ARGB_PRE;3132/**33* @test34* @bug 701893235* @summary fix LoopPipe.getStrokedSpans() performance (clipping enabled by Marlin renderer)36* @run main/othervm/timeout=10 -Dsun.java2d.renderer=sun.java2d.marlin.DMarlinRenderingEngine StrokedLinePerf37*/38public class StrokedLinePerf {3940public static void main(String[] unused) {41BufferedImage bi = new BufferedImage(400, 400, TYPE_INT_ARGB_PRE);42test(bi, true);43test(bi, false);44}4546private static void test(BufferedImage bi, boolean useAA) {47final long start = System.nanoTime();4849final Graphics2D g2d = bi.createGraphics();5051g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,52(useAA) ? RenderingHints.VALUE_ANTIALIAS_ON53: RenderingHints.VALUE_ANTIALIAS_OFF);5455Stroke stroke = new BasicStroke(2.0f, 1, 0, 1.0f, new float[]{0.0f, 4.0f}, 0.0f);56g2d.setStroke(stroke);5758//Large values to trigger crash / infinite loop.59g2d.draw(new Line2D.Double(4.0, 1.794369841E9, 567.0, -2.147483648E9));6061System.out.println("StrokedLinePerf(" + useAA + "): Test duration= " + (1e-6 * (System.nanoTime() - start)) + " ms.");62g2d.dispose();63}64}656667