jdk/test/sun/java2d/OpenGL/bug7181438.java
author bae
Mon, 03 Dec 2012 16:26:47 +0400
changeset 14646 94eed98a7ecb
parent 13237 184b8add9324
child 39056 d99e63b6d962
permissions -rw-r--r--
7124347: [macosx] java.lang.InternalError: not implemented yet on call Graphics2D.drawRenderedImage Reviewed-by: prr, flar
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
/*
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
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
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    34
 * @bug 7181438
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    35
 * @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
    36
 * 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
    37
 * @author Sergey Bylokhov
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    38
 * @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
    39
 */
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    40
public final class bug7181438 {
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    41
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    42
    private static final int SIZE = 500;
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    43
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    44
    public static void main(final String[] args) {
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    45
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    46
        final BufferedImage bi = createBufferedImage();
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    47
        final VolatileImage vi = createVolatileImage();
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    48
        final Graphics s2dVi = vi.getGraphics();
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    49
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    50
        //sw->texture->surface blit
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    51
        s2dVi.drawImage(bi, 0, 0, null);
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    52
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    53
        final BufferedImage results = vi.getSnapshot();
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    54
        for (int i = 0; i < SIZE; ++i) {
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    55
            for (int j = 0; j < SIZE; ++j) {
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    56
                //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
    57
                if (results.getRGB(i, j) != 0xFF000000) {
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    58
                    throw new RuntimeException("Failed: Wrong alpha");
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    59
                }
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
        System.out.println("Passed");
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    63
    }
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
    private static VolatileImage createVolatileImage() {
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    67
        final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    68
        final GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    69
        return gc.createCompatibleVolatileImage(SIZE, SIZE,
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    70
                                                Transparency.TRANSLUCENT);
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    71
    }
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
    private static BufferedImage createBufferedImage() {
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    74
        final BufferedImage bi = new BufferedImage(SIZE, SIZE,
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    75
                                                   BufferedImage.TYPE_INT_RGB);
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    76
        final Graphics bg = bi.getGraphics();
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    77
        //Black color and alpha = 0
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    78
        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
    79
        bg.fillRect(0, 0, SIZE, SIZE);
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    80
        bg.dispose();
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    81
        return bi;
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    82
    }
184b8add9324 7181438: [OGL] Incorrect alpha used, during blit from SW to the texture.
serb
parents:
diff changeset
    83
}