sun/java2d/SunGraphics2D/EmptyClipRenderingTest.java
Print this page
*** 1,14 ****
! /**
! * @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
*/
import java.awt.AWTException;
import java.awt.Canvas;
import java.awt.Color;
--- 1,26 ----
! /*
! * 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;
import java.awt.Canvas;
import java.awt.Color;
*** 30,49 ****
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import javax.imageio.ImageIO;
import sun.awt.ConstrainableGraphics;
- import sun.java2d.SunGraphics2D;
public class EmptyClipRenderingTest {
static final int IMG_W = 400;
static final int IMG_H = 400;
// generated rectangles
static HashSet<Rectangle> rects;
! volatile boolean onscreenTestCompleted = false;
private static boolean showErrors = false;
public EmptyClipRenderingTest() {
// initialize clip/render region rectangles
initClips();
--- 42,71 ----
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import javax.imageio.ImageIO;
import sun.awt.ConstrainableGraphics;
+ /**
+ * @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;
// generated rectangles
static HashSet<Rectangle> rects;
! volatile boolean isActivated = false;
! volatile boolean isPainted;
private static boolean showErrors = false;
public EmptyClipRenderingTest() {
// initialize clip/render region rectangles
initClips();
*** 131,180 ****
*/
private BufferedImage testOnscreen() throws HeadlessException {
final Canvas destComponent;
final Object lock = new Object();
Frame f = new Frame("Test Frame");
f.add(destComponent = new Canvas() {
! public void paint(Graphics g) {}
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());
synchronized (lock) {
! onscreenTestCompleted = true;
lock.notify();
}
}
}
});
f.pack();
f.setVisible(true);
synchronized(lock) {
! while (!onscreenTestCompleted) {
try {
lock.wait(100);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
! Robot r = null;
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()));
f.setVisible(false);
f.dispose();
return bi;
}
--- 153,215 ----
*/
private BufferedImage testOnscreen() throws HeadlessException {
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) {
! isPainted = true;
! }
public Dimension getPreferredSize() {
return new Dimension(IMG_W, IMG_H);
}
});
f.addWindowListener(new WindowAdapter() {
public void windowActivated(WindowEvent e) {
! if (!isActivated) {
synchronized (lock) {
! isActivated = true;
lock.notify();
}
}
}
});
f.pack();
+ f.setLocationRelativeTo(null);
f.setVisible(true);
synchronized(lock) {
! while (!isActivated) {
try {
lock.wait(100);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
! Robot r;
try {
r = new Robot();
} catch (AWTException ex) {
throw new RuntimeException("Can't create Robot");
}
+ 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;
}