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