Path: blob/master/test/jdk/java/awt/Graphics2D/FillTexturePaint/FillTexturePaint.java
41154 views
/*1* Copyright (c) 2013, 2016, 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* @key headful36* @bug 800062937* @summary TexturePaint areas shouldn't separates.38* @author Sergey Bylokhov39*/40public class FillTexturePaint {4142private static TexturePaint shape;43private static final int size = 400;4445static {46BufferedImage bi = new BufferedImage(50, 50,47BufferedImage.TYPE_INT_RGB);48Graphics2D gi = bi.createGraphics();49gi.setBackground(Color.GREEN);50gi.clearRect(0, 0, 50, 50);51shape = new TexturePaint(bi, new Rectangle(0, 0, 50, 50));52}5354public static void main(final String[] args) {55GraphicsEnvironment ge =56GraphicsEnvironment.getLocalGraphicsEnvironment();57GraphicsConfiguration gc =58ge.getDefaultScreenDevice().getDefaultConfiguration();59VolatileImage vi = gc.createCompatibleVolatileImage(size, size);60while (true) {61vi.validate(gc);62Graphics2D g2d = vi.createGraphics();63g2d.setComposite(AlphaComposite.Src);64g2d.setPaint(shape);65g2d.fill(new Rectangle(0, 0, size, size));66g2d.dispose();6768if (vi.validate(gc) != VolatileImage.IMAGE_OK) {69try {70Thread.sleep(100);71} catch (InterruptedException ignored) {72}73continue;74}7576BufferedImage bi = vi.getSnapshot();7778if (vi.contentsLost()) {79try {80Thread.sleep(100);81} catch (InterruptedException ignored) {82}83continue;84}8586for (int x = 0; x < size; ++x) {87for (int y = 0; y < size; ++y) {88if (bi.getRGB(x, y) != Color.GREEN.getRGB()) {89throw new RuntimeException("Test failed.");90}91}92}93break;94}95}96}979899