Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Graphics2D/FlipDrawImage/FlipDrawImage.java
38828 views
/*1* Copyright (c) 2013, 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*/222324import java.awt.AlphaComposite;25import java.awt.Color;26import java.awt.Graphics2D;27import java.awt.GraphicsConfiguration;28import java.awt.GraphicsEnvironment;29import java.awt.image.BufferedImage;30import java.awt.image.VolatileImage;3132/**33* @test34* @bug 800062935* @author Sergey Bylokhov36*/37public final class FlipDrawImage {3839private static final int width = 400;40private static final int height = 400;4142public static void main(final String[] args) {43GraphicsEnvironment ge =44GraphicsEnvironment.getLocalGraphicsEnvironment();45GraphicsConfiguration gc =46ge.getDefaultScreenDevice().getDefaultConfiguration();47VolatileImage vi = gc.createCompatibleVolatileImage(width, height);48final BufferedImage bi = new BufferedImage(width, height,49BufferedImage.TYPE_INT_ARGB);50while (true) {51vi.validate(gc);52Graphics2D g2d = vi.createGraphics();53g2d.setColor(Color.red);54g2d.fillRect(0, 0, width, height);55g2d.setColor(Color.green);56g2d.fillRect(0, 0, width / 2, height / 2);57g2d.dispose();5859if (vi.validate(gc) != VolatileImage.IMAGE_OK) {60try {61Thread.sleep(100);62} catch (InterruptedException ignored) {63}64continue;65}6667Graphics2D g = bi.createGraphics();68g.setComposite(AlphaComposite.Src);69g.setColor(Color.BLUE);70g.fillRect(0, 0, width, height);71// destination width and height are flipped and scale is used.72g.drawImage(vi, width / 2, height / 2, -width / 2, -height / 2,73null, null);74g.dispose();7576if (vi.contentsLost()) {77try {78Thread.sleep(100);79} catch (InterruptedException ignored) {80}81continue;82}8384for (int x = 0; x < width; ++x) {85for (int y = 0; y < height; ++y) {86if (x < width / 2 && y < height / 2) {87if (x >= width / 4 && y >= height / 4) {88if (bi.getRGB(x, y) != Color.green.getRGB()) {89throw new RuntimeException("Test failed.");90}91} else if (bi.getRGB(x, y) != Color.red.getRGB()) {92throw new RuntimeException("Test failed.");93}94} else {95if (bi.getRGB(x, y) != Color.BLUE.getRGB()) {96throw new RuntimeException("Test failed.");97}98}99}100}101break;102}103}104}105106107