Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/java2d/DirectX/AcceleratedScaleTest/AcceleratedScaleTest.java
38918 views
/*1* Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.Color;24import java.awt.Frame;25import java.awt.Graphics;26import java.awt.Graphics2D;27import java.awt.GraphicsConfiguration;28import java.awt.GraphicsEnvironment;29import java.awt.RenderingHints;30import java.awt.Toolkit;31import java.awt.image.BufferedImage;32import java.awt.image.VolatileImage;33import java.io.File;34import java.io.IOException;35import javax.imageio.ImageIO;3637/**38* @test39* @bug 642966540* @bug 658888441* @summary Tests that the transform is correctly handled42* @author Dmitri.Trembovetski area=Graphics43* @run main AcceleratedScaleTest44* @run main/othervm -Dsun.java2d.d3d=true AcceleratedScaleTest45* @run main/othervm -Dsun.java2d.opengl=true AcceleratedScaleTest46*/47public class AcceleratedScaleTest {48private static final int IMAGE_SIZE = 200;49private static VolatileImage destVI;5051private static void initVI(GraphicsConfiguration gc) {52int res;53if (destVI == null) {54res = VolatileImage.IMAGE_INCOMPATIBLE;55} else {56res = destVI.validate(gc);57}58if (res == VolatileImage.IMAGE_INCOMPATIBLE) {59if (destVI != null) destVI.flush();60destVI = gc.createCompatibleVolatileImage(IMAGE_SIZE, IMAGE_SIZE);61destVI.validate(gc);62res = VolatileImage.IMAGE_RESTORED;63}64if (res == VolatileImage.IMAGE_RESTORED) {65Graphics vig = destVI.getGraphics();66vig.setColor(Color.red);67vig.fillRect(0, 0, destVI.getWidth(), destVI.getHeight());68vig.dispose();69}70}7172public static void main(String[] args) {73Frame f = new Frame();74f.pack();75GraphicsConfiguration gc = f.getGraphicsConfiguration();76if (gc.getColorModel().getPixelSize() < 16) {77System.out.printf("Bit depth: %d . Test considered passed.",78gc.getColorModel().getPixelSize());79f.dispose();80return;81}8283BufferedImage bi =84new BufferedImage(IMAGE_SIZE/4, IMAGE_SIZE/4,85BufferedImage.TYPE_INT_RGB);86Graphics2D g = (Graphics2D)bi.getGraphics();87g.setColor(Color.red);88g.fillRect(0, 0, bi.getWidth(), bi.getHeight());89BufferedImage snapshot;90do {91initVI(gc);92g = (Graphics2D)destVI.getGraphics();93// "accelerate" BufferedImage94for (int i = 0; i < 5; i++) {95g.drawImage(bi, 0, 0, null);96}97g.setColor(Color.white);98g.fillRect(0, 0, destVI.getWidth(), destVI.getHeight());99100// this will force the use of Transform primitive instead of101// Scale (the latter doesn't do bilinear filtering required by102// VALUE_RENDER_QUALITY, which triggers the bug in D3D pipeline103g.setRenderingHint(RenderingHints.KEY_RENDERING,104RenderingHints.VALUE_RENDER_QUALITY);105g.drawImage(bi, 0, 0, destVI.getWidth(), destVI.getHeight(), null);106g.fillRect(0, 0, destVI.getWidth(), destVI.getHeight());107108g.drawImage(bi, 0, 0, destVI.getWidth(), destVI.getHeight(), null);109110snapshot = destVI.getSnapshot();111} while (destVI.contentsLost());112113f.dispose();114int whitePixel = Color.white.getRGB();115for (int y = 0; y < snapshot.getHeight(); y++) {116for (int x = 0; x < snapshot.getWidth(); x++) {117if (snapshot.getRGB(x, y) == whitePixel) {118System.out.printf("Found untouched pixel at %dx%d\n", x, y);119System.out.println("Dumping the dest. image to " +120"AcceleratedScaleTest_dst.png");121try {122ImageIO.write(snapshot, "png",123new File("AcceleratedScaleTest_dst.png"));124} catch (IOException ex) {125ex.printStackTrace();126}127throw new RuntimeException("Test failed.");128}129}130}131System.out.println("Test Passed.");132}133134}135136137