Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Graphics2D/FillTexturePaint/FillTexturePaint.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*/2223import java.awt.AlphaComposite;24import java.awt.Color;25import java.awt.Graphics2D;26import java.awt.GraphicsConfiguration;27import java.awt.GraphicsEnvironment;28import java.awt.Rectangle;29import java.awt.TexturePaint;30import java.awt.image.BufferedImage;31import java.awt.image.VolatileImage;3233/**34* @test35* @bug 800062936* @summary TexturePaint areas shouldn't separates.37* @author Sergey Bylokhov38*/39public class FillTexturePaint {4041private static TexturePaint shape;42private static final int size = 400;4344static {45BufferedImage bi = new BufferedImage(50, 50,46BufferedImage.TYPE_INT_RGB);47Graphics2D gi = bi.createGraphics();48gi.setBackground(Color.GREEN);49gi.clearRect(0, 0, 50, 50);50shape = new TexturePaint(bi, new Rectangle(0, 0, 50, 50));51}5253public static void main(final String[] args) {54GraphicsEnvironment ge =55GraphicsEnvironment.getLocalGraphicsEnvironment();56GraphicsConfiguration gc =57ge.getDefaultScreenDevice().getDefaultConfiguration();58VolatileImage vi = gc.createCompatibleVolatileImage(size, size);59while (true) {60vi.validate(gc);61Graphics2D g2d = vi.createGraphics();62g2d.setComposite(AlphaComposite.Src);63g2d.setPaint(shape);64g2d.fill(new Rectangle(0, 0, size, size));65g2d.dispose();6667if (vi.validate(gc) != VolatileImage.IMAGE_OK) {68try {69Thread.sleep(100);70} catch (InterruptedException ignored) {71}72continue;73}7475BufferedImage bi = vi.getSnapshot();7677if (vi.contentsLost()) {78try {79Thread.sleep(100);80} catch (InterruptedException ignored) {81}82continue;83}8485for (int x = 0; x < size; ++x) {86for (int y = 0; y < size; ++y) {87if (bi.getRGB(x, y) != Color.GREEN.getRGB()) {88throw new RuntimeException("Test failed.");89}90}91}92break;93}94}95}969798