jdk/test/java/awt/image/VolatileImage/BitmaskVolatileImage.java
author goetz
Tue, 14 Jun 2016 10:44:59 +0200
changeset 39056 d99e63b6d962
parent 31661 a5cb86f2253b
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:
31661
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
     1
/*
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
     4
 *
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
     8
 *
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    13
 * accompanied this code).
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    14
 *
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    18
 *
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    21
 * questions.
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    22
 */
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    23
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    24
import java.awt.AlphaComposite;
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    25
import java.awt.Color;
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    26
import java.awt.Graphics2D;
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    27
import java.awt.GraphicsConfiguration;
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    28
import java.awt.GraphicsEnvironment;
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    29
import java.awt.Image;
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    30
import java.awt.image.BufferedImage;
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    31
import java.awt.image.VolatileImage;
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    32
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    33
import static java.awt.Transparency.BITMASK;
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    34
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    35
/**
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    36
 * @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 31661
diff changeset
    37
 * @key headful
31661
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    38
 * @bug 7188942
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    39
 * @summary We should get correct volatile image, when we use BITMASK
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    40
 *          transparency
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    41
 */
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    42
public final class BitmaskVolatileImage {
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    43
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    44
    public static final int S = 8;
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    45
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    46
    public static void main(final String[] args) {
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    47
        GraphicsConfiguration gc =
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    48
                GraphicsEnvironment.getLocalGraphicsEnvironment()
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    49
                        .getDefaultScreenDevice().getDefaultConfiguration();
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    50
        VolatileImage vi = gc.createCompatibleVolatileImage(S, S, BITMASK);
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    51
        BufferedImage ci = gc.createCompatibleImage(S, S, BITMASK);
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    52
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    53
        int attempt = 0;
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    54
        do {
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    55
            if (++attempt > 10) {
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    56
                throw new RuntimeException("Too many attempts: " + attempt);
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    57
            }
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    58
            vi.validate(gc);
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    59
            test(vi, ci, gc);
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    60
        } while (vi.contentsLost());
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    61
    }
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    62
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    63
    private static void test(VolatileImage vi, BufferedImage ci, GraphicsConfiguration gc) {
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    64
        for (int r = 0; r <= 255; ++r) {
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    65
            for (int a = 0; a <= 255; ++a) {
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    66
                fill(vi, new Color(r, 0, 0, a));
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    67
                fill(ci, new Color(r, 0, 0, a));
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    68
                validate(ci, vi.getSnapshot());
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    69
            }
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    70
        }
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    71
    }
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    72
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    73
    private static void fill(Image image, Color color) {
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    74
        Graphics2D g2d = (Graphics2D) image.getGraphics();
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    75
        g2d.setColor(color);
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    76
        g2d.setComposite(AlphaComposite.Src);
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    77
        g2d.fillRect(0, 0, S, S);
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    78
        g2d.dispose();
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    79
    }
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    80
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    81
    private static void validate(BufferedImage ci, BufferedImage snapshot) {
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    82
        for (int y = 0; y < ci.getHeight(); y++) {
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    83
            for (int x = 0; x < ci.getWidth(); x++) {
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    84
                int ci_rgb = ci.getRGB(x, y);
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    85
                int vi_rgb = snapshot.getRGB(x, y);
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    86
                if (ci_rgb != vi_rgb) {
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    87
                    System.err.println("Exp:" + Integer.toHexString(ci_rgb));
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    88
                    System.err.println("Actual:" + Integer.toHexString(vi_rgb));
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    89
                    throw new RuntimeException("Colors mismatch!");
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    90
                }
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    91
            }
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    92
        }
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    93
    }
a5cb86f2253b 7188942: Remove support of pbuffers in OGL Java2d pipeline
serb
parents:
diff changeset
    94
}