6084N/A/*
6084N/A * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
6084N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6084N/A *
6084N/A * This code is free software; you can redistribute it and/or modify it
6084N/A * under the terms of the GNU General Public License version 2 only, as
6084N/A * published by the Free Software Foundation.
6084N/A *
6084N/A * This code is distributed in the hope that it will be useful, but WITHOUT
6084N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6084N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6084N/A * version 2 for more details (a copy is included in the LICENSE file that
6084N/A * accompanied this code).
6084N/A *
6084N/A * You should have received a copy of the GNU General Public License version
6084N/A * 2 along with this work; if not, write to the Free Software Foundation,
6084N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6084N/A *
6084N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6084N/A * or visit www.oracle.com if you need additional information or have any
6084N/A * questions.
6084N/A */
6084N/A
6084N/A
6084N/Aimport java.awt.AlphaComposite;
6084N/Aimport java.awt.Color;
6084N/Aimport java.awt.Graphics2D;
6084N/Aimport java.awt.GraphicsConfiguration;
6084N/Aimport java.awt.GraphicsEnvironment;
6084N/Aimport java.awt.image.BufferedImage;
6084N/Aimport java.awt.image.VolatileImage;
6084N/A
6084N/A/**
6084N/A * @test
6084N/A * @bug 8000629
6084N/A * @summary Temporary backbuffer in the DrawImage should not fill background
6084N/A * outside of source image bounds.
6084N/A * @author Sergey Bylokhov
6084N/A */
6084N/Apublic final class IncorrectBounds {
6084N/A
6084N/A private static final int width = 400;
6084N/A private static final int height = 400;
6084N/A
6084N/A public static void main(final String[] args) {
6084N/A GraphicsEnvironment ge =
6084N/A GraphicsEnvironment.getLocalGraphicsEnvironment();
6084N/A GraphicsConfiguration gc =
6084N/A ge.getDefaultScreenDevice().getDefaultConfiguration();
6084N/A VolatileImage vi = gc.createCompatibleVolatileImage(width / 4,
6084N/A height / 4);
6084N/A final BufferedImage bi = new BufferedImage(width, height,
6084N/A BufferedImage.TYPE_INT_ARGB);
6084N/A while (true) {
6084N/A vi.validate(gc);
6084N/A Graphics2D g2d = vi.createGraphics();
6084N/A g2d.setColor(Color.green);
6084N/A g2d.fillRect(0, 0, width / 4, height / 4);
6084N/A g2d.dispose();
6084N/A
6084N/A if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
6084N/A try {
6084N/A Thread.sleep(100);
6084N/A } catch (InterruptedException ignored) {
6084N/A }
6084N/A continue;
6084N/A }
6084N/A
6084N/A Graphics2D g = bi.createGraphics();
6084N/A g.setComposite(AlphaComposite.Src);
6084N/A g.setColor(Color.red);
6084N/A g.fillRect(0, 0, width, height);
6084N/A // Use sx and sy outside of VI bounds.
6084N/A g.drawImage(vi, 0, 0, width / 2, height / 2, 0, 0, width * 2,
6084N/A height * 2, null);
6084N/A g.dispose();
6084N/A
6084N/A if (vi.contentsLost()) {
6084N/A try {
6084N/A Thread.sleep(100);
6084N/A } catch (InterruptedException ignored) {
6084N/A }
6084N/A continue;
6084N/A }
6084N/A
6084N/A for (int x = 0; x < width; ++x) {
6084N/A for (int y = 0; y < height; ++y) {
6084N/A if (x < width / 16 && y < height / 16) {
6084N/A if (bi.getRGB(x, y) != Color.green.getRGB()) {
6084N/A throw new RuntimeException("Test failed.");
6084N/A }
6084N/A } else {
6084N/A if (bi.getRGB(x, y) != Color.red.getRGB()) {
6084N/A throw new RuntimeException("Test failed.");
6084N/A }
6084N/A }
6084N/A }
6084N/A }
6084N/A break;
6084N/A }
6084N/A }
6084N/A}