5234N/A/*
5234N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
5234N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5234N/A *
5234N/A * This code is free software; you can redistribute it and/or modify it
5234N/A * under the terms of the GNU General Public License version 2 only, as
5234N/A * published by the Free Software Foundation.
5234N/A *
5234N/A * This code is distributed in the hope that it will be useful, but WITHOUT
5234N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5234N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5234N/A * version 2 for more details (a copy is included in the LICENSE file that
5234N/A * accompanied this code).
5234N/A *
5234N/A * You should have received a copy of the GNU General Public License version
5234N/A * 2 along with this work; if not, write to the Free Software Foundation,
5234N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5234N/A *
5234N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5234N/A * or visit www.oracle.com if you need additional information or have any
5234N/A * questions.
5234N/A */
5234N/A
5234N/Aimport java.awt.Color;
5234N/Aimport java.awt.Graphics;
5234N/Aimport java.awt.GraphicsConfiguration;
5234N/Aimport java.awt.GraphicsEnvironment;
5234N/Aimport java.awt.Transparency;
5234N/Aimport java.awt.image.BufferedImage;
5234N/Aimport java.awt.image.VolatileImage;
5234N/A
5234N/A/**
5234N/A * @test
5234N/A * @bug 7181438
5234N/A * @summary Verifies that we get correct alpha, when we draw opaque
5234N/A * BufferedImage to non opaque VolatileImage via intermediate opaque texture.
5234N/A * @author Sergey Bylokhov
5234N/A * @run main/othervm -Dsun.java2d.accthreshold=0 bug7181438
5234N/A */
5234N/Apublic final class bug7181438 {
5234N/A
5234N/A private static final int SIZE = 500;
5234N/A
5234N/A public static void main(final String[] args) {
5234N/A
5234N/A final BufferedImage bi = createBufferedImage();
5234N/A final VolatileImage vi = createVolatileImage();
5234N/A final Graphics s2dVi = vi.getGraphics();
5234N/A
5234N/A //sw->texture->surface blit
5234N/A s2dVi.drawImage(bi, 0, 0, null);
5234N/A
5234N/A final BufferedImage results = vi.getSnapshot();
5234N/A for (int i = 0; i < SIZE; ++i) {
5234N/A for (int j = 0; j < SIZE; ++j) {
5234N/A //Image should be opaque: (black color and alpha = 255)
5234N/A if (results.getRGB(i, j) != 0xFF000000) {
5234N/A throw new RuntimeException("Failed: Wrong alpha");
5234N/A }
5234N/A }
5234N/A }
5234N/A System.out.println("Passed");
5234N/A }
5234N/A
5234N/A
5234N/A private static VolatileImage createVolatileImage() {
5234N/A final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
5234N/A final GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
5234N/A return gc.createCompatibleVolatileImage(SIZE, SIZE,
5234N/A Transparency.TRANSLUCENT);
5234N/A }
5234N/A
5234N/A private static BufferedImage createBufferedImage() {
5234N/A final BufferedImage bi = new BufferedImage(SIZE, SIZE,
5234N/A BufferedImage.TYPE_INT_RGB);
5234N/A final Graphics bg = bi.getGraphics();
5234N/A //Black color and alpha = 0
5234N/A bg.setColor(new Color(0, 0, 0, 0));
5234N/A bg.fillRect(0, 0, SIZE, SIZE);
5234N/A bg.dispose();
5234N/A return bi;
5234N/A }
5234N/A}