jdk/test/sun/java2d/OpenGL/bug7181438.java
author goetz
Tue, 14 Jun 2016 10:44:59 +0200
changeset 39056 d99e63b6d962
parent 13237 184b8add9324
permissions -rw-r--r--
8159690: [TESTBUG] Mark headful tests with @key headful. Reviewed-by: simonis, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13237
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
     1
/*
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 13237
diff changeset
     2
 * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
13237
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
     4
 *
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
     8
 *
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    13
 * accompanied this code).
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    14
 *
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    18
 *
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    21
 * questions.
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    22
 */
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    23
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    24
import java.awt.Color;
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    25
import java.awt.Graphics;
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    26
import java.awt.GraphicsConfiguration;
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    27
import java.awt.GraphicsEnvironment;
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    28
import java.awt.Transparency;
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    29
import java.awt.image.BufferedImage;
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    30
import java.awt.image.VolatileImage;
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    31
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    32
/**
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    33
 * @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 13237
diff changeset
    34
 * @key headful
13237
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    35
 * @bug 7181438
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    36
 * @summary Verifies that we get correct alpha, when we draw opaque
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    37
 * BufferedImage to non opaque VolatileImage via intermediate opaque texture.
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    38
 * @author Sergey Bylokhov
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    39
 * @run main/othervm -Dsun.java2d.accthreshold=0 bug7181438
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    40
 */
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    41
public final class bug7181438 {
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    42
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    43
    private static final int SIZE = 500;
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    44
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    45
    public static void main(final String[] args) {
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    46
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    47
        final BufferedImage bi = createBufferedImage();
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    48
        final VolatileImage vi = createVolatileImage();
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    49
        final Graphics s2dVi = vi.getGraphics();
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    50
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    51
        //sw->texture->surface blit
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    52
        s2dVi.drawImage(bi, 0, 0, null);
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    53
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    54
        final BufferedImage results = vi.getSnapshot();
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    55
        for (int i = 0; i < SIZE; ++i) {
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    56
            for (int j = 0; j < SIZE; ++j) {
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    57
                //Image should be opaque: (black color and alpha = 255)
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    58
                if (results.getRGB(i, j) != 0xFF000000) {
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    59
                    throw new RuntimeException("Failed: Wrong alpha");
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    60
                }
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    61
            }
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    62
        }
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    63
        System.out.println("Passed");
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    64
    }
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    65
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    66
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    67
    private static VolatileImage createVolatileImage() {
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    68
        final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    69
        final GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    70
        return gc.createCompatibleVolatileImage(SIZE, SIZE,
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    71
                                                Transparency.TRANSLUCENT);
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    72
    }
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    73
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    74
    private static BufferedImage createBufferedImage() {
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    75
        final BufferedImage bi = new BufferedImage(SIZE, SIZE,
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    76
                                                   BufferedImage.TYPE_INT_RGB);
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    77
        final Graphics bg = bi.getGraphics();
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    78
        //Black color and alpha = 0
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    79
        bg.setColor(new Color(0, 0, 0, 0));
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    80
        bg.fillRect(0, 0, SIZE, SIZE);
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    81
        bg.dispose();
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    82
        return bi;
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    83
    }
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    84
}