--- old/sun/java2d/SunGraphics2D/EmptyClipRenderingTest.java 2014-12-01 22:22:45.136093000 +0400 +++ new/sun/java2d/SunGraphics2D/EmptyClipRenderingTest.java 2014-12-01 22:22:44.885479500 +0400 @@ -1,12 +1,24 @@ -/** - * @test - * @bug 6335200 6419610 - * @summary Tests that we don't render anything if specific empty clip is set - * @author Dmitri.Trembovetski@Sun.COM: area=Graphics - * @run main EmptyClipRenderingTest - * @run main/othervm -Dsun.java2d.noddraw=true EmptyClipRenderingTest - * @run main/othervm -Dsun.java2d.pmoffscreen=true EmptyClipRenderingTest - * @run main/othervm -Dsun.java2d.opengl=true EmptyClipRenderingTest +/* + * Copyright (c) 2014, 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. */ import java.awt.AWTException; @@ -32,8 +44,17 @@ import java.util.HashSet; import javax.imageio.ImageIO; import sun.awt.ConstrainableGraphics; -import sun.java2d.SunGraphics2D; +/** + * @test + * @bug 6335200 6419610 + * @summary Tests that we don't render anything if specific empty clip is set + * @author Dmitri.Trembovetski@Sun.COM: area=Graphics + * @run main EmptyClipRenderingTest + * @run main/othervm -Dsun.java2d.noddraw=true EmptyClipRenderingTest + * @run main/othervm -Dsun.java2d.pmoffscreen=true EmptyClipRenderingTest + * @run main/othervm -Dsun.java2d.opengl=true EmptyClipRenderingTest + */ public class EmptyClipRenderingTest { static final int IMG_W = 400; static final int IMG_H = 400; @@ -41,7 +62,8 @@ // generated rectangles static HashSet rects; - volatile boolean onscreenTestCompleted = false; + volatile boolean isActivated = false; + volatile boolean isPainted; private static boolean showErrors = false; public EmptyClipRenderingTest() { @@ -133,27 +155,30 @@ final Canvas destComponent; final Object lock = new Object(); Frame f = new Frame("Test Frame"); + f.setUndecorated(true); f.add(destComponent = new Canvas() { - public void paint(Graphics g) {} + public void paint(Graphics g) { + isPainted = true; + } public Dimension getPreferredSize() { return new Dimension(IMG_W, IMG_H); } }); f.addWindowListener(new WindowAdapter() { public void windowActivated(WindowEvent e) { - if (!onscreenTestCompleted){ - runTest((Graphics2D)destComponent.getGraphics()); + if (!isActivated) { synchronized (lock) { - onscreenTestCompleted = true; + isActivated = true; lock.notify(); } } } }); f.pack(); + f.setLocationRelativeTo(null); f.setVisible(true); synchronized(lock) { - while (!onscreenTestCompleted) { + while (!isActivated) { try { lock.wait(100); } catch (InterruptedException ex) { @@ -161,18 +186,28 @@ } } } - Robot r = null; + Robot r; try { r = new Robot(); } catch (AWTException ex) { throw new RuntimeException("Can't create Robot"); } - Toolkit.getDefaultToolkit().sync(); - BufferedImage bi = r.createScreenCapture( - new Rectangle(destComponent.getLocationOnScreen().x, - destComponent.getLocationOnScreen().y, - destComponent.getWidth(), - destComponent.getHeight())); + BufferedImage bi; + int attempt = 0; + do { + if (++attempt > 10) { + throw new RuntimeException("Too many attempts: " + attempt); + } + isPainted = false; + runTest((Graphics2D) destComponent.getGraphics()); + r.waitForIdle(); + Toolkit.getDefaultToolkit().sync(); + bi = r.createScreenCapture( + new Rectangle(destComponent.getLocationOnScreen().x, + destComponent.getLocationOnScreen().y, + destComponent.getWidth(), + destComponent.getHeight())); + } while (isPainted); f.setVisible(false); f.dispose(); return bi;