430N/A/*
2362N/A * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
430N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
430N/A *
430N/A * This code is free software; you can redistribute it and/or modify it
430N/A * under the terms of the GNU General Public License version 2 only, as
430N/A * published by the Free Software Foundation.
430N/A *
430N/A * This code is distributed in the hope that it will be useful, but WITHOUT
430N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
430N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
430N/A * version 2 for more details (a copy is included in the LICENSE file that
430N/A * accompanied this code).
430N/A *
430N/A * You should have received a copy of the GNU General Public License version
430N/A * 2 along with this work; if not, write to the Free Software Foundation,
430N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
430N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
430N/A */
430N/A
430N/A/*
430N/A * @test
430N/A * @bug 6659345
430N/A * @summary Tests that various paints work correctly when preceeded by a
430N/A * textured operaiton.
430N/A * @author Dmitri.Trembovetski@sun.com: area=Graphics
430N/A * @run main/othervm AccelPaintsTest
430N/A * @run main/othervm -Dsun.java2d.opengl=True AccelPaintsTest
430N/A */
430N/A
430N/Aimport java.awt.Color;
430N/Aimport java.awt.Dimension;
430N/Aimport java.awt.EventQueue;
430N/Aimport java.awt.GradientPaint;
430N/Aimport java.awt.Graphics;
430N/Aimport java.awt.Graphics2D;
430N/Aimport java.awt.GraphicsConfiguration;
430N/Aimport java.awt.GraphicsEnvironment;
430N/Aimport java.awt.LinearGradientPaint;
430N/Aimport java.awt.MultipleGradientPaint.CycleMethod;
430N/Aimport java.awt.Paint;
430N/Aimport java.awt.RadialGradientPaint;
430N/Aimport java.awt.Rectangle;
430N/Aimport java.awt.Shape;
430N/Aimport java.awt.TexturePaint;
430N/Aimport java.awt.Transparency;
430N/Aimport java.awt.geom.Rectangle2D;
430N/Aimport java.awt.image.BufferedImage;
430N/Aimport java.awt.image.VolatileImage;
430N/Aimport java.io.File;
430N/Aimport java.io.IOException;
430N/Aimport java.lang.reflect.InvocationTargetException;
430N/Aimport javax.imageio.ImageIO;
430N/Aimport javax.swing.JFrame;
430N/Aimport javax.swing.JPanel;
430N/A
430N/Apublic class AccelPaintsTest extends JPanel {
430N/A BufferedImage bi =
430N/A new BufferedImage(80, 100, BufferedImage.TYPE_INT_ARGB_PRE);
430N/A
430N/A RadialGradientPaint rgp =
430N/A new RadialGradientPaint(100, 100, 100, new float[] {0f, 0.2f, 0.6f, 1f},
430N/A new Color[] { Color.red,
430N/A Color.yellow,
430N/A Color.blue,
430N/A Color.green},
430N/A CycleMethod.REFLECT);
430N/A LinearGradientPaint lgp =
430N/A new LinearGradientPaint(30, 30, 120, 130, new float[] {0f, 0.2f, 0.6f, 1f},
430N/A new Color[] {Color.red,
430N/A Color.yellow,
430N/A Color.blue,
430N/A Color.green});
430N/A GradientPaint gp =
430N/A new GradientPaint(30, 30, Color.red, 120, 130, Color.yellow, true);
430N/A
430N/A TexturePaint tp =
430N/A new TexturePaint(bi, new Rectangle2D.Float(30, 30, 120, 130));
430N/A
430N/A
430N/A public AccelPaintsTest() {
430N/A Graphics g = bi.getGraphics();
430N/A g.setColor(Color.blue);
430N/A g.fillRect(0, 0, bi.getWidth(), bi.getHeight());
430N/A
430N/A setPreferredSize(new Dimension(250, 4*120));
430N/A }
430N/A
430N/A private void renderWithPaint(Graphics2D g2d, Paint p) {
430N/A g2d.drawImage(bi, 130, 30, null);
430N/A
430N/A g2d.setPaint(p);
430N/A g2d.fillRect(30, 30, 80, 100);
430N/A }
430N/A
430N/A private void render(Graphics2D g2d) {
430N/A renderWithPaint(g2d, rgp);
430N/A g2d.translate(0, 100);
430N/A
430N/A renderWithPaint(g2d, lgp);
430N/A g2d.translate(0, 100);
430N/A
430N/A renderWithPaint(g2d, gp);
430N/A g2d.translate(0, 100);
430N/A
430N/A renderWithPaint(g2d, tp);
430N/A g2d.translate(0, 100);
430N/A }
430N/A
430N/A private void test() {
430N/A GraphicsConfiguration gc =
430N/A GraphicsEnvironment.getLocalGraphicsEnvironment().
430N/A getDefaultScreenDevice().getDefaultConfiguration();
430N/A if (gc.getColorModel().getPixelSize() < 16) {
430N/A System.out.println("<16 bit depth detected, test passed");
430N/A return;
430N/A }
430N/A
430N/A VolatileImage vi =
430N/A gc.createCompatibleVolatileImage(250, 4*120, Transparency.OPAQUE);
430N/A BufferedImage res;
430N/A do {
430N/A vi.validate(gc);
430N/A Graphics2D g2d = vi.createGraphics();
430N/A g2d.setColor(Color.white);
430N/A g2d.fillRect(0, 0, vi.getWidth(), vi.getHeight());
430N/A
430N/A render(g2d);
430N/A
430N/A res = vi.getSnapshot();
430N/A } while (vi.contentsLost());
430N/A
430N/A for (int y = 0; y < bi.getHeight(); y++) {
430N/A for (int x = 0; x < bi.getWidth(); x++) {
430N/A if (res.getRGB(x, y) == Color.black.getRGB()) {
430N/A System.err.printf("Test FAILED: found black at %d,%d\n",
430N/A x, y);
430N/A try {
430N/A String fileName = "AccelPaintsTest.png";
430N/A ImageIO.write(res, "png", new File(fileName));
430N/A System.err.println("Dumped rendering to " + fileName);
430N/A } catch (IOException e) {}
430N/A throw new RuntimeException("Test FAILED: found black");
430N/A }
430N/A }
430N/A }
430N/A }
430N/A
430N/A protected void paintComponent(Graphics g) {
430N/A super.paintComponent(g);
430N/A Graphics2D g2d = (Graphics2D)g;
430N/A
430N/A render(g2d);
430N/A }
430N/A
430N/A public static void main(String[] args)
430N/A throws InterruptedException, InvocationTargetException
430N/A {
430N/A
430N/A if (args.length > 0 && args[0].equals("-show")) {
430N/A EventQueue.invokeAndWait(new Runnable() {
430N/A public void run() {
430N/A JFrame f = new JFrame("RadialGradientTest");
430N/A f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
430N/A AccelPaintsTest t = new AccelPaintsTest();
430N/A f.add(t);
430N/A f.pack();
430N/A f.setVisible(true);
430N/A }
430N/A });
430N/A } else {
430N/A AccelPaintsTest t = new AccelPaintsTest();
430N/A t.test();
430N/A System.out.println("Test Passed.");
430N/A }
430N/A }
430N/A}