undefect. CWE-407 — 63 sites patched across 27 ecosystems

Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com

Patches, unit tests, benchmarks, whitepaper, and outreach briefs.
Public domain — no copyright claimed. Use freely.
This commit is contained in:
russell@unturf.com 2026-03-26 17:11:57 -04:00
commit 0a580b313d
70422 changed files with 17213626 additions and 0 deletions

View file

@ -0,0 +1,180 @@
/*
* Copyright (c) 2007, 2018, 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 6659345 8198613
* @summary Tests that various paints work correctly when preceeded by a
* textured operaiton.
* @author Dmitri.Trembovetski@sun.com: area=Graphics
* @run main/othervm AccelPaintsTest
*/
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.LinearGradientPaint;
import java.awt.MultipleGradientPaint.CycleMethod;
import java.awt.Paint;
import java.awt.RadialGradientPaint;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.TexturePaint;
import java.awt.Transparency;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.VolatileImage;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class AccelPaintsTest extends JPanel {
BufferedImage bi =
new BufferedImage(80, 100, BufferedImage.TYPE_INT_ARGB_PRE);
RadialGradientPaint rgp =
new RadialGradientPaint(100, 100, 100, new float[] {0f, 0.2f, 0.6f, 1f},
new Color[] { Color.red,
Color.yellow,
Color.blue,
Color.green},
CycleMethod.REFLECT);
LinearGradientPaint lgp =
new LinearGradientPaint(30, 30, 120, 130, new float[] {0f, 0.2f, 0.6f, 1f},
new Color[] {Color.red,
Color.yellow,
Color.blue,
Color.green});
GradientPaint gp =
new GradientPaint(30, 30, Color.red, 120, 130, Color.yellow, true);
TexturePaint tp =
new TexturePaint(bi, new Rectangle2D.Float(30, 30, 120, 130));
public AccelPaintsTest() {
Graphics g = bi.getGraphics();
g.setColor(Color.blue);
g.fillRect(0, 0, bi.getWidth(), bi.getHeight());
setPreferredSize(new Dimension(250, 4*120));
}
private void renderWithPaint(Graphics2D g2d, Paint p) {
g2d.drawImage(bi, 130, 30, null);
g2d.setPaint(p);
g2d.fillRect(30, 30, 80, 100);
}
private void render(Graphics2D g2d) {
renderWithPaint(g2d, rgp);
g2d.translate(0, 100);
renderWithPaint(g2d, lgp);
g2d.translate(0, 100);
renderWithPaint(g2d, gp);
g2d.translate(0, 100);
renderWithPaint(g2d, tp);
g2d.translate(0, 100);
}
private void test() {
GraphicsConfiguration gc =
GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().getDefaultConfiguration();
if (gc.getColorModel().getPixelSize() < 16) {
System.out.println("<16 bit depth detected, test passed");
return;
}
VolatileImage vi =
gc.createCompatibleVolatileImage(250, 4*120, Transparency.OPAQUE);
BufferedImage res;
do {
vi.validate(gc);
Graphics2D g2d = vi.createGraphics();
g2d.setColor(Color.white);
g2d.fillRect(0, 0, vi.getWidth(), vi.getHeight());
render(g2d);
res = vi.getSnapshot();
} while (vi.contentsLost());
for (int y = 0; y < bi.getHeight(); y++) {
for (int x = 0; x < bi.getWidth(); x++) {
if (res.getRGB(x, y) == Color.black.getRGB()) {
System.err.printf("Test FAILED: found black at %d,%d\n",
x, y);
try {
String fileName = "AccelPaintsTest.png";
ImageIO.write(res, "png", new File(fileName));
System.err.println("Dumped rendering to " + fileName);
} catch (IOException e) {}
throw new RuntimeException("Test FAILED: found black");
}
}
}
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
render(g2d);
}
public static void main(String[] args)
throws InterruptedException, InvocationTargetException
{
if (args.length > 0 && args[0].equals("-show")) {
EventQueue.invokeAndWait(new Runnable() {
public void run() {
JFrame f = new JFrame("RadialGradientTest");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
AccelPaintsTest t = new AccelPaintsTest();
f.add(t);
f.pack();
f.setVisible(true);
}
});
} else {
AccelPaintsTest t = new AccelPaintsTest();
t.test();
System.out.println("Test Passed.");
}
}
}

View file

@ -0,0 +1,134 @@
/*
* Copyright (c) 2006, 2018, 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.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.awt.image.VolatileImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
/**
* @test
* @key headful
* @bug 6429665 6588884 8198613
* @summary Tests that the transform is correctly handled
* @author Dmitri.Trembovetski area=Graphics
* @run main AcceleratedScaleTest
* @run main/othervm -Dsun.java2d.d3d=true AcceleratedScaleTest
*/
public class AcceleratedScaleTest {
private static final int IMAGE_SIZE = 200;
private static VolatileImage destVI;
private static void initVI(GraphicsConfiguration gc) {
int res;
if (destVI == null) {
res = VolatileImage.IMAGE_INCOMPATIBLE;
} else {
res = destVI.validate(gc);
}
if (res == VolatileImage.IMAGE_INCOMPATIBLE) {
if (destVI != null) destVI.flush();
destVI = gc.createCompatibleVolatileImage(IMAGE_SIZE, IMAGE_SIZE);
destVI.validate(gc);
res = VolatileImage.IMAGE_RESTORED;
}
if (res == VolatileImage.IMAGE_RESTORED) {
Graphics vig = destVI.getGraphics();
vig.setColor(Color.red);
vig.fillRect(0, 0, destVI.getWidth(), destVI.getHeight());
vig.dispose();
}
}
public static void main(String[] args) {
Frame f = new Frame();
f.pack();
GraphicsConfiguration gc = f.getGraphicsConfiguration();
if (gc.getColorModel().getPixelSize() < 16) {
System.out.printf("Bit depth: %d . Test considered passed.",
gc.getColorModel().getPixelSize());
f.dispose();
return;
}
BufferedImage bi =
new BufferedImage(IMAGE_SIZE/4, IMAGE_SIZE/4,
BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D)bi.getGraphics();
g.setColor(Color.red);
g.fillRect(0, 0, bi.getWidth(), bi.getHeight());
BufferedImage snapshot;
do {
initVI(gc);
g = (Graphics2D)destVI.getGraphics();
// "accelerate" BufferedImage
for (int i = 0; i < 5; i++) {
g.drawImage(bi, 0, 0, null);
}
g.setColor(Color.white);
g.fillRect(0, 0, destVI.getWidth(), destVI.getHeight());
// this will force the use of Transform primitive instead of
// Scale (the latter doesn't do bilinear filtering required by
// VALUE_RENDER_QUALITY, which triggers the bug in D3D pipeline
g.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
g.drawImage(bi, 0, 0, destVI.getWidth(), destVI.getHeight(), null);
g.fillRect(0, 0, destVI.getWidth(), destVI.getHeight());
g.drawImage(bi, 0, 0, destVI.getWidth(), destVI.getHeight(), null);
snapshot = destVI.getSnapshot();
} while (destVI.contentsLost());
f.dispose();
int whitePixel = Color.white.getRGB();
for (int y = 0; y < snapshot.getHeight(); y++) {
for (int x = 0; x < snapshot.getWidth(); x++) {
if (snapshot.getRGB(x, y) == whitePixel) {
System.out.printf("Found untouched pixel at %dx%d\n", x, y);
System.out.println("Dumping the dest. image to " +
"AcceleratedScaleTest_dst.png");
try {
ImageIO.write(snapshot, "png",
new File("AcceleratedScaleTest_dst.png"));
} catch (IOException ex) {
ex.printStackTrace();
}
throw new RuntimeException("Test failed.");
}
}
}
System.out.println("Test Passed.");
}
}

View file

@ -0,0 +1,105 @@
/*
* Copyright (c) 2011, 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 6997116
* @summary Test verifies that rendering of images with bitmap transparency
* to a D3D surface does not cause an ClassCastException.
*
* @run main/othervm -Dsun.java2d.d3d=True DrawBitmaskToSurfaceTest
*/
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.IndexColorModel;
import java.util.concurrent.CountDownLatch;
import javax.swing.JFrame;
public class DrawBitmaskToSurfaceTest extends JFrame {
private final Image src;
private static java.util.concurrent.CountDownLatch latch = null;
private static Throwable theError = null;
public DrawBitmaskToSurfaceTest() {
src = createTestImage();
}
private static Image createTestImage() {
byte[] r = new byte[]{(byte)0x00, (byte)0x80, (byte)0xff, (byte)0xff};
byte[] g = new byte[]{(byte)0x00, (byte)0x80, (byte)0xff, (byte)0x00};
byte[] b = new byte[]{(byte)0x00, (byte)0x80, (byte)0xff, (byte)0x00};
IndexColorModel icm = new IndexColorModel(2, 4, r, g, b, 3);
BufferedImage img = new BufferedImage(100, 100,
BufferedImage.TYPE_BYTE_INDEXED,
icm);
return img;
}
@Override
public void paint(final Graphics g) {
try {
System.err.println("paint frame....");
g.drawImage(src, 30, 30, this);
} catch (Throwable e) {
theError = e;
} finally {
if (latch != null) {
latch.countDown();
}
}
}
public static void main(final String[] args) throws Exception {
final JFrame frame = new DrawBitmaskToSurfaceTest();
frame.setBounds(10, 350, 200, 200);
frame.setVisible(true);
Thread.sleep(2000);
System.err.println("Change frame bounds...");
latch = new CountDownLatch(1);
frame.setBounds(10, 350, 90, 90);
frame.repaint();
try {
if (latch.getCount() > 0) {
latch.await();
}
} catch (InterruptedException e) {
}
frame.dispose();
if (theError != null) {
throw new RuntimeException("Test failed.", theError);
}
System.err.println("Test passed");
}
}

View file

@ -0,0 +1,52 @@
/*
* Copyright (c) 2007, 2017, 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 6668439
* @summary Verifies that no exceptions are thrown when frame is resized to 0x0
* @author Dmitri.Trembovetski@sun.com: area=Graphics
* @run main/othervm IAEforEmptyFrameTest
* @run main/othervm -Dsun.java2d.d3d=false IAEforEmptyFrameTest
*/
import javax.swing.JFrame;
public class IAEforEmptyFrameTest {
public static void main(String[] args) {
JFrame f = null;
try {
f = new JFrame("IAEforEmptyFrameTest");
f.setUndecorated(true);
f.setBounds(100, 100, 320, 240);
f.setVisible(true);
try { Thread.sleep(1000); } catch (Exception z) {}
f.setBounds(0, 0, 0, 0);
try { Thread.sleep(1000); } catch (Exception z) {}
f.dispose();
} finally {
f.dispose();
};
}
}

View file

@ -0,0 +1,117 @@
/*
* Copyright (c) 2007, 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 6648018
* @summary Tests that we don't run into infinite validation loop when copying
a VolatileImage to the screen
* @author Dmitri.Trembovetski@sun.com: area=Graphics
* @run main/othervm InfiniteValidationLoopTest
* @run main/othervm -Dsun.java2d.d3d=false InfiniteValidationLoopTest
*/
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import static java.awt.image.VolatileImage.*;
import java.awt.image.VolatileImage;
import java.util.concurrent.CountDownLatch;
public class InfiniteValidationLoopTest extends Frame {
private static volatile boolean failed = false;
private static final int LOOP_THRESHOLD = 50;
private static volatile CountDownLatch latch;
private VolatileImage vi;
public InfiniteValidationLoopTest() {
super("InfiniteValidationLoopTest");
}
@Override
public void paint(Graphics g) {
try {
runTest(g);
} finally {
latch.countDown();
}
}
private void runTest(Graphics g) {
int status = IMAGE_OK;
int count1 = 0;
do {
GraphicsConfiguration gc = getGraphicsConfiguration();
int count2 = 0;
while (vi == null || (status = vi.validate(gc)) != IMAGE_OK) {
if (++count2 > LOOP_THRESHOLD) {
System.err.println("Infinite loop detected: count2="+count2);
failed = true;
return;
}
if (vi == null || status == IMAGE_INCOMPATIBLE) {
if (vi != null) { vi.flush(); vi = null; }
vi = gc.createCompatibleVolatileImage(100, 100);
continue;
}
if (status == IMAGE_RESTORED) {
Graphics gg = vi.getGraphics();
gg.setColor(Color.green);
gg.fillRect(0, 0, vi.getWidth(), vi.getHeight());
break;
}
}
g.drawImage(vi, getInsets().left, getInsets().top, null);
if (++count1 > LOOP_THRESHOLD) {
System.err.println("Infinite loop detected: count1="+count1);
failed = true;
return;
}
} while (vi.contentsLost());
}
public static void main(String[] args) {
latch = new CountDownLatch(1);
InfiniteValidationLoopTest t1 = new InfiniteValidationLoopTest();
t1.pack();
t1.setSize(200, 200);
t1.setVisible(true);
try { latch.await(); } catch (InterruptedException ex) {}
t1.dispose();
latch = new CountDownLatch(1);
t1 = new InfiniteValidationLoopTest();
t1.pack();
t1.setSize(50, 50);
t1.setVisible(true);
try { latch.await(); } catch (InterruptedException ex) {}
t1.dispose();
if (failed) {
throw new
RuntimeException("Failed: infinite validattion loop detected");
}
System.out.println("Test PASSED");
}
}

View file

@ -0,0 +1,211 @@
/*
* Copyright (c) 2008, 2018, 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
* @bug 6728834 6749060 8198613
* @summary Tests that LCD AA text rendering works properly with destinations
* being VolatileImage of all transparency types
* @author Dmitri.Trembovetski: area=Graphics
* @run main/manual/othervm -Dsun.java2d.d3d=false NonOpaqueDestLCDAATest
* @run main/manual/othervm NonOpaqueDestLCDAATest
*/
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.awt.image.VolatileImage;
import java.io.File;
import java.util.concurrent.CountDownLatch;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import static java.awt.Transparency.*;
public class NonOpaqueDestLCDAATest extends JFrame implements ActionListener {
private static volatile boolean passed = true;
private static CountDownLatch complete = new CountDownLatch(1);
public NonOpaqueDestLCDAATest() {
JTextArea desc = new JTextArea();
desc.setText(
"\n Instructions: the three text strings below should appear" +
" readable, without smudges or misshapen bold glyphs.\n" +
" You may need a magnifier to notice some bad colorfringing in "+
" in SW Translucent case, especially in vertical stems.\n\n"+
" Basically text rendered to TRANSLUCENT destination should look"+
" similar to one rendered to OPAQUE - it may differ in whether or" +
" not it's LCD, but it should look 'correct'\n\n"+
"If the text looks fine the test PASSED otherwise it FAILED.\n");
desc.setEditable(false);
desc.setBackground(Color.black);
desc.setForeground(Color.green);
add("North", desc);
JPanel renderPanel = new JPanel() {
@Override
public void paintComponent(Graphics g) {
render(g, getWidth(), getHeight());
}
};
renderPanel.setPreferredSize(new Dimension(1024, 650));
renderPanel.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
images = null;
}
});
add("Center", renderPanel);
JButton passedBtn = new JButton("Passed");
JButton failedBtn = new JButton("Failed");
passedBtn.addActionListener(this);
failedBtn.addActionListener(this);
JPanel p = new JPanel();
p.add(passedBtn);
p.add(failedBtn);
add("South", p);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
complete.countDown();
}
});
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public void render(Graphics g, int w, int h) {
initImages(w, h);
g.setColor(new Color(0xAD, 0xD8, 0xE6));
g.fillRect(0, 0, w, h);
Graphics2D g2d = (Graphics2D) g.create();
for (Image im : images) {
g2d.drawImage(im, 0, 0, null);
g2d.translate(0, im.getHeight(null));
}
}
String tr[] = { "OPAQUE", "BITMASK", "TRANSLUCENT" };
@Override
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("Passed")) {
passed = true;
System.out.println("Test Passed");
} else if (e.getActionCommand().equals("Failed")) {
System.out.println("Test Failed");
for (int i = 0; i < images.length; i++) {
String f = "NonOpaqueDestLCDAATest_"+tr[i];
try {
if (images[i] instanceof VolatileImage) {
f += "_vi.png";
ImageIO.write(((VolatileImage)images[i]).
getSnapshot(), "png", new File(f));
} else {
f += "_bi.png";
ImageIO.write((BufferedImage)images[i],
"png", new File(f));
}
System.out.printf("Dumped %s image to %s\n", tr[i], f);
} catch (Throwable t) {}
}
passed = false;
}
dispose();
complete.countDown();
}
static void clear(Graphics2D g, int type, int w, int h) {
Graphics2D gg = (Graphics2D) g.create();
if (type > OPAQUE) {
gg.setColor(new Color(0, 0, 0, 0));
gg.setComposite(AlphaComposite.Src);
} else {
gg.setColor(new Color(0xAD, 0xD8, 0xE6));
}
gg.fillRect(0, 0, w, h);
}
private void render(Image im, int type, String s) {
Graphics2D g2d = (Graphics2D) im.getGraphics();
clear(g2d, type, im.getWidth(null), im.getHeight(null));
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
Font f = new Font("Dialog", Font.BOLD, 40);// g2d.getFont().deriveFont(32.0f);
g2d.setColor(Color.white);
g2d.setFont(g2d.getFont().deriveFont(36.0f));
g2d.drawString(s, 10, im.getHeight(null) / 2);
}
Image images[];
private void initImages(int w, int h) {
if (images == null) {
images = new Image[6];
GraphicsConfiguration gc = getGraphicsConfiguration();
for (int i = OPAQUE; i <= TRANSLUCENT; i++) {
VolatileImage vi =
gc.createCompatibleVolatileImage(w,h/images.length,i);
images[i-1] = vi;
vi.validate(gc);
String s = "LCD AA Text rendered to " + tr[i - 1] + " HW destination";
render(vi, i, s);
s = "LCD AA Text rendered to " + tr[i - 1] + " SW destination";
images[i-1+3] = gc.createCompatibleImage(w, h/images.length, i);
render(images[i-1+3], i, s);
}
}
}
public static void main(String[] args) throws InterruptedException {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
NonOpaqueDestLCDAATest t = new NonOpaqueDestLCDAATest();
t.pack();
t.setVisible(true);
}
});
complete.await();
if (!passed) {
throw new RuntimeException("Test Failed!");
}
}
}

View file

@ -0,0 +1,237 @@
/*
* Copyright (c) 2007, 2022, 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 6664068 6666931
* @summary Tests that resizing a window to which a tight loop is rendering
* doesn't produce artifacts or crashes
* @run main/othervm OnScreenRenderingResizeTest
* @run main/othervm -Dsun.java2d.d3d=false OnScreenRenderingResizeTest
*/
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.EventQueue;
import java.awt.image.BufferedImage;
import java.awt.image.VolatileImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class OnScreenRenderingResizeTest {
private static volatile boolean nocheck = false;
private static int FRAME_W;
private static int FRAME_H;
private static int IMAGE_W;
private static int IMAGE_H;
private static final int tolerance = 12;
private static long RUN_TIME = 1000*20;
private static final Color renderColor = Color.green;
private static final Color bgColor = Color.white;
private static Frame frame;
private static void createAndShowGUI() {
frame = new Frame() {
public void paint(Graphics g) {}
public void update(Graphics g) {}
};
frame.setBackground(bgColor);
frame.setUndecorated(true);
frame.setAlwaysOnTop(true);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) throws Exception {
for (String arg : args) {
if ("-inf".equals(arg)) {
System.err.println("Test will run indefinitely");
RUN_TIME = Long.MAX_VALUE;
} else if ("-nocheck".equals(arg)) {
System.err.println("Test will not check rendering results");
nocheck = true;
} else {
System.err.println("Usage: OnScreenRenderingResizeTest" +
" [-inf][-nocheck]");
}
}
try {
EventQueue.invokeAndWait(new Runnable() {
public void run() {
createAndShowGUI();
}
});
Thread.sleep(2000);
} catch (Exception ex) {
ex.printStackTrace();
}
try {
GraphicsConfiguration gc = frame.getGraphicsConfiguration();
Rectangle gcBounds = gc.getBounds();
FRAME_W = (gcBounds.width / 4);
FRAME_H = (gcBounds.height / 4);
IMAGE_W = (gcBounds.width / 8);
IMAGE_H = (gcBounds.height / 8);
frame.setBounds(gcBounds.width / 4, gcBounds.height / 4,
FRAME_W, FRAME_H);
BufferedImage output =
new BufferedImage(IMAGE_W, IMAGE_H,
BufferedImage.TYPE_INT_RGB);
output.setAccelerationPriority(0.0f);
Graphics g = output.getGraphics();
g.setColor(renderColor);
g.fillRect(0, 0, IMAGE_W, IMAGE_H);
int maxW = gcBounds.width / 2;
int maxH = gcBounds.height / 2;
int minW = FRAME_W;
int minH = FRAME_H;
int incW = 10, incH = 10, cnt = 0;
Robot robot = null;
if (!nocheck && gc.getColorModel().getPixelSize() > 8) {
try {
robot = new Robot();
robot.setAutoDelay(100);
robot.mouseMove(0,0);
} catch (AWTException ex) {
System.err.println("Robot creation failed, continuing.");
}
} else {
System.err.println("No screen rendering checks.");
}
VolatileImage vi = gc.
createCompatibleVolatileImage(IMAGE_W, IMAGE_H);
vi.validate(gc);
long timeStarted = System.currentTimeMillis();
while ((System.currentTimeMillis() - timeStarted) < RUN_TIME) {
if (++cnt > 100) {
int w = frame.getWidth() + incW;
int h = frame.getHeight() + incH;
if (w < minW || w > maxW ) {
incW = -incW;
}
if (h < minH || h > maxH ) {
incH = -incH;
}
frame.setSize(w, h);
if (robot != null) {
robot.waitForIdle();
}
cnt = 0;
}
// try to put the device into non-default state, for example,
// this operation below will set the transform
vi.validate(gc);
Graphics2D vig = (Graphics2D)vi.getGraphics();
vig.rotate(30.0f, IMAGE_W/2, IMAGE_H/2);
vig.drawImage(output, 0, 0,
IMAGE_W, IMAGE_H, null);
frame.getGraphics().
drawImage(output, 0, 0, null);
if (cnt == 90 && robot != null) {
robot.waitForIdle();
// area where we blit and should be either white or green
Point p = frame.getLocationOnScreen();
p.translate(10, 10);
BufferedImage bi =
robot.createScreenCapture(
new Rectangle(p.x, p.y,
(IMAGE_W / 2), (IMAGE_H / 2)));
int accepted1[] = {Color.white.getRGB(),
Color.green.getRGB()};
checkBI(bi, accepted1);
// the area where we didn't render should stay white
robot.waitForIdle();
p = frame.getLocationOnScreen();
p.translate(10, IMAGE_H + 10);
bi = robot.createScreenCapture(
new Rectangle(p.x, p.y,
frame.getWidth() - 20,
frame.getHeight() - 20 - (IMAGE_H)));
int accepted2[] = { Color.white.getRGB() };
checkBI(bi, accepted2);
}
Thread.yield();
}
} finally {
frame.dispose();
}
System.out.println("Test Passed");
}
private static void checkBI(BufferedImage bi, int accepted[]) {
for (int x = 0; x < bi.getWidth(); x++) {
for (int y = 0; y < bi.getHeight(); y++) {
int actual = bi.getRGB(x, y);
int alpha = (actual >> 24) & 0xFF;
int red = (actual >> 16) & 0xFF;
int green = (actual >> 8) & 0xFF;
int blue = (actual) & 0xFF;
boolean found = false;
for (int acc : accepted) {
int accAlpha = (acc >> 24) & 0xFF;
int accRed = (acc >> 16) & 0xFF;
int accGreen = (acc >> 8) & 0xFF;
int accBlue = (acc) & 0xFF;
if (!(Math.abs(alpha - accAlpha) > tolerance ||
Math.abs(red - accRed) > tolerance ||
Math.abs(green - accGreen) > tolerance ||
Math.abs(blue - accBlue) > tolerance)) {
found = true;
break;
}
}
if (!found) {
try {
String name = "OnScreenRenderingResizeTest.png";
ImageIO.write(bi, "png", new File(name));
System.out.println("Screen shot file: " + name);
} catch (IOException ex) {}
throw new
RuntimeException("Test failed at " + x + "-" + y +
" rgb=0x" + Integer.
toHexString(actual));
}
}
}
}
}

View file

@ -0,0 +1,75 @@
/*
* Copyright (c) 2007, 2018, 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 6764257 8198613
* @summary Tests that the alpha in opaque images doesn't affect result of alpha
* compositing
* @author Dmitri.Trembovetski@sun.com: area=Graphics
* @run main/othervm OpaqueImageToSurfaceBlitTest
* @run main/othervm -Dsun.java2d.noddraw=true OpaqueImageToSurfaceBlitTest
*/
import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.awt.image.VolatileImage;
public class OpaqueImageToSurfaceBlitTest {
public static void main(String[] args) {
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
VolatileImage vi = gc.createCompatibleVolatileImage(16, 16);
vi.validate(gc);
BufferedImage bi =
new BufferedImage(2, 2, BufferedImage.TYPE_INT_RGB);
int data[] = ((DataBufferInt)bi.getRaster().getDataBuffer()).getData();
data[0] = 0x0000007f;
data[1] = 0x0000007f;
data[2] = 0xff00007f;
data[3] = 0xff00007f;
Graphics2D g = vi.createGraphics();
g.setComposite(AlphaComposite.SrcOver.derive(0.999f));
g.drawImage(bi, 0, 0, null);
bi = vi.getSnapshot();
if (bi.getRGB(0, 0) != bi.getRGB(1, 1)) {
throw new RuntimeException("Test FAILED: color at 0x0 ="+
Integer.toHexString(bi.getRGB(0, 0))+" differs from 1x1 ="+
Integer.toHexString(bi.getRGB(1,1)));
}
System.out.println("Test PASSED.");
}
}

View file

@ -0,0 +1,150 @@
/*
* Copyright (c) 2007, 2018, 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 6694230 8198613
* @summary Tests that components overriding getInsets paint correctly
* @author Dmitri.Trembovetski@sun.com: area=Graphics
* @run main/othervm OverriddenInsetsTest
*/
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GraphicsEnvironment;
import java.awt.Insets;
import java.awt.Panel;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import javax.imageio.ImageIO;
public class OverriddenInsetsTest {
public static final Insets INSETS1 = new Insets(25,25,0,0);
public static final Insets INSETS2 = new Insets(100,100,0,0);
static final CountDownLatch lock = new CountDownLatch(1);
static boolean failed = false;
public static void main(String[] args) {
if (GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().getDefaultConfiguration().
getColorModel().getPixelSize() < 16)
{
System.out.println("<16 bit mode detected, test passed");
}
final Frame f = new Frame("OverriddenInsetsTest");
f.setSize(260,260);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
f.setVisible(false);
System.exit(0);
}
});
f.setBackground(Color.gray);
Panel p1 = new Panel() {
public Insets getInsets() {
return INSETS1;
}
};
p1.setLayout(null);
p1.setSize(250, 250);
Panel p = new Panel(){
@Override
public Insets getInsets() {
return INSETS2;
}
public void paint(Graphics g) {
// make sure Vista is done with its effects
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {}
g.setColor(Color.red);
g.drawRect(0,0,getWidth()-1,getHeight()-1 );
g.setColor(Color.blue);
g.fillRect(0,0,getWidth()/2,getHeight()/2);
Point p = getLocationOnScreen();
try {
Robot r = new Robot();
BufferedImage bi =
r.createScreenCapture(new
Rectangle(p.x, p.y, getWidth()/2, getHeight()/2));
for (int y = 0; y < bi.getHeight(); y++) {
for (int x = 0; x < bi.getWidth(); x++) {
if (bi.getRGB(x, y) != Color.blue.getRGB()) {
failed = true;
System.err.printf("Test failed at %d %d c=%x\n",
x, y, bi.getRGB(x, y));
String name = "OverriddenInsetsTest_res.png";
try {
ImageIO.write(bi, "png", new File(name));
System.out.println("Dumped res to: "+name);
} catch (IOException e) {}
return;
}
}
}
} catch (Exception e) {
failed = true;
} finally {
lock.countDown();
}
}
};
p.setSize(200, 200);
p1.add(p);
p.setLocation(50, 50);
f.add(p1);
f.setVisible(true);
try {
lock.await();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
if (args.length <= 0 || !"-show".equals(args[0])) {
f.dispose();
}
if (failed) {
throw new RuntimeException("Test FAILED.");
}
System.out.println("Test PASSED");
}
}

View file

@ -0,0 +1,175 @@
/*
* Copyright (c) 2007, 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 6648018 6652662
* @summary Verifies that rendering to a cached onscreen Graphics works
* @author Dmitri.Trembovetski@sun.com: area=Graphics
* @run main/othervm RenderingToCachedGraphicsTest
* @run main/othervm -Dsun.java2d.d3d=false RenderingToCachedGraphicsTest
*/
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GraphicsEnvironment;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import static java.awt.image.VolatileImage.*;
import java.awt.image.VolatileImage;
import java.io.File;
import java.util.concurrent.CountDownLatch;
import javax.imageio.ImageIO;
public class RenderingToCachedGraphicsTest extends Frame {
private static volatile boolean failed = false;
private static volatile CountDownLatch latch;
private Graphics cachedGraphics;
private Canvas renderCanvas;
public RenderingToCachedGraphicsTest() {
super("Test starts in 2 seconds");
renderCanvas = new Canvas() {
@Override
public void paint(Graphics g) {
if (getWidth() < 100 || getHeight() < 100) {
repaint();
return;
}
// wait for a bit so that Vista's Window manager's animation
// effects on window's appearance are completed (6652662)
try { Thread.sleep(2000); } catch (InterruptedException ex) {}
try {
runTest();
} catch (Throwable t) {
failed = true;
} finally {
latch.countDown();
}
}
@Override
public void update(Graphics g) {}
};
add("Center", renderCanvas);
}
private void runTest() {
// this will cause screen update manager to dump the accelerated surface
// for this canvas
renderCanvas.createBufferStrategy(2);
BufferStrategy bs = renderCanvas.getBufferStrategy();
do {
Graphics bsg = bs.getDrawGraphics();
bsg.setColor(Color.blue);
bsg.fillRect(0, 0,
renderCanvas.getWidth(), renderCanvas.getHeight());
} while (bs.contentsLost() || bs.contentsRestored());
// grab the "unaccelerated" onscreen surface
cachedGraphics = renderCanvas.getGraphics();
cachedGraphics.setColor(Color.red);
cachedGraphics.fillRect(0, 0, getWidth(), getHeight());
bs.dispose();
bs = null;
// now the update manager should be able to accelerate onscreen
// rendering to it again
cachedGraphics.setColor(Color.green);
// this causes restoration of the new accelerated onscreen surface
// (it is created in "lost" state)
cachedGraphics.fillRect(0, 0,
renderCanvas.getWidth(),
renderCanvas.getHeight());
Toolkit.getDefaultToolkit().sync();
// and now we should be able to render to it
cachedGraphics.fillRect(0, 0,
renderCanvas.getWidth(),
renderCanvas.getHeight());
Toolkit.getDefaultToolkit().sync();
Robot robot = null;
try {
robot = new Robot();
} catch (Exception e) {
e.printStackTrace();
failed = true;
return;
}
Point p = renderCanvas.getLocationOnScreen();
Rectangle r = new Rectangle(p.x, p.y,
renderCanvas.getWidth(),
renderCanvas.getHeight());
BufferedImage bi = robot.createScreenCapture(r);
for (int y = 0; y < bi.getHeight(); y++) {
for (int x = 0; x < bi.getWidth(); x++) {
if (bi.getRGB(x, y) != Color.green.getRGB()) {
System.err.println("Colors mismatch!");
String name = "RenderingToCachedGraphicsTest.png";
try {
ImageIO.write(bi, "png", new File(name));
System.err.println("Dumped grabbed image to: "+name);
} catch (Exception e) {}
failed = true;
return;
}
}
}
}
public static void main(String[] args) {
int depth = GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().getDefaultConfiguration().
getColorModel().getPixelSize();
if (depth < 16) {
System.out.println("Test PASSED (depth < 16bit)");
return;
}
latch = new CountDownLatch(1);
RenderingToCachedGraphicsTest t1 = new RenderingToCachedGraphicsTest();
t1.pack();
t1.setSize(300, 300);
t1.setVisible(true);
try { latch.await(); } catch (InterruptedException ex) {}
t1.dispose();
if (failed) {
throw new
RuntimeException("Failed: rendering didn't show up");
}
System.out.println("Test PASSED");
}
}

View file

@ -0,0 +1,109 @@
/*
* Copyright (c) 2007, 2018, 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 6705443 8198613
* @summary tests that we don't crash during exit if font strikes were disposed
* during the lifetime of the application
*
* @run main/othervm -Dsun.java2d.font.reftype=weak StrikeDisposalCrashTest
* @run main/othervm -Dsun.java2d.font.reftype=weak -Dsun.java2d.noddraw=true StrikeDisposalCrashTest
*/
import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.image.VolatileImage;
public class StrikeDisposalCrashTest {
public static void main(String[] args) {
System.setProperty("sun.java2d.font.reftype", "weak");
GraphicsDevice gd[] =
GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
Frame frames[] = new Frame[gd.length];
for (int i = 0; i < frames.length; i++) {
GraphicsConfiguration gc = gd[i].getDefaultConfiguration();
Frame f = new Frame("Frame on "+gc, gc);
f.setSize(100, 100);
f.setLocation(gc.getBounds().x, gc.getBounds().y);
f.pack();
frames[i] = f;
}
Font f1 = new Font("Dialog", Font.PLAIN, 10);
Font f2 = new Font("Dialog", Font.ITALIC, 12);
for (int i = 0; i < frames.length/2; i++) {
// making sure the glyphs are cached in the accel. cache on
// one frame, then the other
renderText(frames[i], f1);
renderText(frames[frames.length -1 - i], f1);
// and now the other way around, with different glyphs
renderText(frames[frames.length -1 - i], f2);
renderText(frames[i], f2);
}
// try to force strike disposal (note that we have to use
// -Dsun.java2d.font.reftype=weak to facilitate the disposal)
System.gc();
System.runFinalization();
System.gc();
System.runFinalization();
for (Frame f : frames) {
f.dispose();
}
System.err.println("Exiting. If the test crashed after this it FAILED");
}
private static final String text =
"The quick brown fox jumps over the lazy dog 1234567890";
private static void renderText(Frame frame, Font f1) {
VolatileImage vi = frame.createVolatileImage(256, 32);
vi.validate(frame.getGraphicsConfiguration());
Graphics2D g = vi.createGraphics();
g.setFont(f1);
g.drawString(text, 0, vi.getHeight()/2);
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g.drawString(text, 0, vi.getHeight()/2);
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
g.drawString(text, 0, vi.getHeight()/2);
Toolkit.getDefaultToolkit().sync();
}
}

View file

@ -0,0 +1,146 @@
/*
* Copyright (c) 2007, 2018, 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 6630702 8198613
* @summary Tests that scrolling after paint() is performed correctly.
* This is really only applicable to Vista
* @author Dmitri.Trembovetski@sun.com: area=Graphics
* @run main/othervm SwingOnScreenScrollingTest
*/
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.GraphicsEnvironment;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
public class SwingOnScreenScrollingTest extends JPanel {
static JScrollPane pane;
static SwingOnScreenScrollingTest test;
public SwingOnScreenScrollingTest() {
}
public static void main(String[] args) {
int size = GraphicsEnvironment.
getLocalGraphicsEnvironment().
getDefaultScreenDevice().
getDefaultConfiguration().getColorModel().getPixelSize();
if (size < 16) {
System.err.println("<16 bit display mode detected. Test PASSED");
return;
}
final JFrame f = new JFrame("SwingOnScreenScrollingTest");
try {
EventQueue.invokeAndWait(new Runnable() {
public void run() {
test = new SwingOnScreenScrollingTest();
pane = new JScrollPane(test);
f.add(pane);
f.pack();
f.setSize(100, 200);
f.setVisible(true);
}
});
} catch (InvocationTargetException ex) {
ex.printStackTrace();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
EventQueue.invokeLater(new Runnable() {
public void run() {
BufferedImage bi;
bi = new BufferedImage(100, 300,
BufferedImage.TYPE_INT_RGB);
Graphics gg = bi.getGraphics();
test.paint(gg);
for (int y = 80; y < 200; y +=10) {
test.scrollRectToVisible(new Rectangle(0, y, 100, 100));
try {
Thread.sleep(200);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
Point p = pane.getViewport().getLocationOnScreen();
Robot r = null;
try {
r = new Robot();
} catch (AWTException ex) {
throw new RuntimeException(ex);
}
bi = r.createScreenCapture(new Rectangle(p.x+5, p.y+5, 30, 30));
for (int y = 0; y < bi.getHeight(); y++) {
for (int x = 0; x < bi.getHeight(); x++) {
int rgb = bi.getRGB(x, y);
if (bi.getRGB(x, y) != Color.red.getRGB()) {
System.err.printf("Test Failed at (%d,%d) c=0x%x\n",
x, y, rgb);
try {
String name =
"SwingOnScreenScrollingTest_out.png";
ImageIO.write(bi, "png", new File(name));
System.err.println("Wrote grabbed image to "+
name);
} catch (Throwable ex) {}
throw new RuntimeException("Test failed");
}
}
}
System.out.println("Test PASSED.");
f.dispose();
}
});
}
protected void paintComponent(Graphics g) {
g.setColor(Color.green);
g.fillRect(0, 0, getWidth(), 100);
g.setColor(Color.red);
g.fillRect(0, 100, getWidth(), getHeight()-100);
}
public Dimension getPreferredSize() {
return new Dimension(100, 300);
}
}

View file

@ -0,0 +1,219 @@
/*
* Copyright (c) 2007, 2018, 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 6689025 8023483 8198613
* @summary Tests that transformed Paints are rendered correctly
* @author Dmitri.Trembovetski@sun.com: area=Graphics
* @run main/othervm TransformedPaintTest
*/
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.LinearGradientPaint;
import java.awt.MultipleGradientPaint.CycleMethod;
import java.awt.Paint;
import java.awt.RadialGradientPaint;
import java.awt.TexturePaint;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.VolatileImage;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TransformedPaintTest {
private static enum PaintType {
COLOR,
GRADIENT,
LINEAR_GRADIENT,
RADIAL_GRADIENT,
TEXTURE
};
private static final int CELL_SIZE = 100;
private static final int R_WIDTH = 3 * CELL_SIZE;
private static final int R_HEIGHT = PaintType.values().length * CELL_SIZE;
private Paint createPaint(PaintType type, int startx, int starty,
int w, int h)
{
// make sure that the blue color doesn't show up when filling a
// w by h rect
w++; h++;
int endx = startx + w;
int endy = starty + h;
Rectangle2D.Float r = new Rectangle2D.Float(startx, starty, w, h);
switch (type) {
case COLOR: return Color.red;
case GRADIENT: return
new GradientPaint(startx, starty, Color.red,
endx, endy, Color.green);
case LINEAR_GRADIENT: return
new LinearGradientPaint(startx, starty, endx, endy,
new float[] { 0.0f, 0.999f, 1.0f },
new Color[] { Color.red, Color.green, Color.blue });
case RADIAL_GRADIENT: return
new RadialGradientPaint(startx, starty,
(float)Math.sqrt(w * w + h * h),
new float[] { 0.0f, 0.999f, 1.0f },
new Color[] { Color.red, Color.green, Color.blue },
CycleMethod.NO_CYCLE);
case TEXTURE: {
BufferedImage bi =
new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D) bi.getGraphics();
g.setPaint(createPaint(PaintType.LINEAR_GRADIENT, 0, 0, w, h));
g.fillRect(0, 0, w, h);
return new TexturePaint(bi, r);
}
}
return Color.green;
}
private void renderLine(PaintType type, Graphics2D g,
int startx, int starty, int w, int h)
{
Paint p = createPaint(type, startx, starty, w, h);
g.setPaint(p);
// first, no transform
g.fillRect(startx, starty, w, h);
// translation only
g.translate(w, 0);
g.fillRect(startx, starty, w, h);
g.translate(-w, 0);
// complex transform
g.translate(startx + w*2, starty);
g.rotate(Math.toRadians(90), w/2, h/2);
g.translate(-startx, -starty);
g.fillRect(startx, starty, w, h);
}
private void render(Graphics2D g, int w, int h) {
int paintTypes = PaintType.values().length;
int ystep = h / paintTypes;
int y = 0;
for (PaintType type : PaintType.values()) {
renderLine(type, (Graphics2D)g.create(),
0, y, h / paintTypes, h / paintTypes);
y += ystep;
}
}
private void checkBI(BufferedImage bi) {
for (int y = 0; y < bi.getHeight(); y++) {
for (int x = 0; x < bi.getWidth(); x++) {
if (bi.getRGB(x, y) == Color.blue.getRGB()) {
try {
String fileName = "TransformedPaintTest_res.png";
ImageIO.write(bi, "png", new File(fileName));
System.err.println("Dumped image to: " + fileName);
} catch (IOException ex) {}
throw new RuntimeException("Test failed, blue color found");
}
}
}
}
private void runTest() {
GraphicsConfiguration gc = GraphicsEnvironment.
getLocalGraphicsEnvironment().getDefaultScreenDevice().
getDefaultConfiguration();
if (gc.getColorModel().getPixelSize() < 16) {
System.out.println("8-bit desktop depth found, test passed");
return;
}
VolatileImage vi = gc.createCompatibleVolatileImage(R_WIDTH, R_HEIGHT);
BufferedImage bi = null;
do {
vi.validate(gc);
Graphics2D g = vi.createGraphics();
render(g, vi.getWidth(), vi.getHeight());
bi = vi.getSnapshot();
} while (vi.contentsLost());
checkBI(bi);
System.out.println("Test PASSED.");
}
private static void showFrame(final TransformedPaintTest t) {
JFrame f = new JFrame("TransformedPaintTest");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final BufferedImage bi =
new BufferedImage(R_WIDTH, R_HEIGHT, BufferedImage.TYPE_INT_RGB);
JPanel p = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
t.render(g2d, R_WIDTH, R_HEIGHT);
t.render(bi.createGraphics(), R_WIDTH, R_HEIGHT);
g2d.drawImage(bi, R_WIDTH + 5, 0, null);
g.setColor(Color.black);
g.drawString("Rendered to Back Buffer", 10, 20);
g.drawString("Rendered to BufferedImage", R_WIDTH + 15, 20);
}
};
p.setPreferredSize(new Dimension(2 * R_WIDTH + 5, R_HEIGHT));
f.add(p);
f.pack();
f.setVisible(true);
}
public static void main(String[] args) throws
InterruptedException, InvocationTargetException
{
boolean show = (args.length > 0 && "-show".equals(args[0]));
final TransformedPaintTest t = new TransformedPaintTest();
if (show) {
EventQueue.invokeAndWait(new Runnable() {
public void run() {
showFrame(t);
}
});
} else {
t.runTest();
}
}
}