Path: blob/jdk8u272-b10-aarch32-20201026/jdk/test/sun/java2d/OpenGL/bug7181438.java
48795 views
/*1* Copyright (c) 2012, 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.Color;24import java.awt.Graphics;25import java.awt.GraphicsConfiguration;26import java.awt.GraphicsEnvironment;27import java.awt.Transparency;28import java.awt.image.BufferedImage;29import java.awt.image.VolatileImage;3031/**32* @test33* @bug 718143834* @summary Verifies that we get correct alpha, when we draw opaque35* BufferedImage to non opaque VolatileImage via intermediate opaque texture.36* @author Sergey Bylokhov37* @run main/othervm -Dsun.java2d.accthreshold=0 bug718143838*/39public final class bug7181438 {4041private static final int SIZE = 500;4243public static void main(final String[] args) {4445final BufferedImage bi = createBufferedImage();46final VolatileImage vi = createVolatileImage();47final Graphics s2dVi = vi.getGraphics();4849//sw->texture->surface blit50s2dVi.drawImage(bi, 0, 0, null);5152final BufferedImage results = vi.getSnapshot();53for (int i = 0; i < SIZE; ++i) {54for (int j = 0; j < SIZE; ++j) {55//Image should be opaque: (black color and alpha = 255)56if (results.getRGB(i, j) != 0xFF000000) {57throw new RuntimeException("Failed: Wrong alpha");58}59}60}61System.out.println("Passed");62}636465private static VolatileImage createVolatileImage() {66final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();67final GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();68return gc.createCompatibleVolatileImage(SIZE, SIZE,69Transparency.TRANSLUCENT);70}7172private static BufferedImage createBufferedImage() {73final BufferedImage bi = new BufferedImage(SIZE, SIZE,74BufferedImage.TYPE_INT_RGB);75final Graphics bg = bi.getGraphics();76//Black color and alpha = 077bg.setColor(new Color(0, 0, 0, 0));78bg.fillRect(0, 0, SIZE, SIZE);79bg.dispose();80return bi;81}82}838485