jdk/test/sun/java2d/SunGraphics2D/SurfaceDestination/SurfaceDestination.java
author goetz
Tue, 14 Jun 2016 10:44:59 +0200
changeset 39056 d99e63b6d962
parent 32492 0808495400e5
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:
32492
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
     1
/*
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
     4
 *
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
     8
 *
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    13
 * accompanied this code).
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    14
 *
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    18
 *
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    21
 * questions.
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    22
 */
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    23
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    24
import java.awt.Component;
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    25
import java.awt.Frame;
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    26
import java.awt.Graphics;
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    27
import java.awt.GraphicsConfiguration;
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    28
import java.awt.GraphicsDevice;
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    29
import java.awt.GraphicsEnvironment;
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    30
import java.awt.Image;
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    31
import java.awt.Window;
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    32
import java.awt.image.BufferedImage;
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    33
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    34
import sun.java2d.SunGraphics2D;
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    35
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    36
import static java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment;
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    37
import static java.awt.Transparency.BITMASK;
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    38
import static java.awt.Transparency.OPAQUE;
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    39
import static java.awt.Transparency.TRANSLUCENT;
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    40
import static java.awt.image.BufferedImage.TYPE_INT_ARGB;
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    41
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    42
/**
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    43
 * @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 32492
diff changeset
    44
 * @key headful
32492
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    45
 * @bug 8134603
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    46
 * @modules java.desktop/sun.java2d
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    47
 * @run main/othervm SurfaceDestination
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    48
 */
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    49
public final class SurfaceDestination {
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    50
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    51
    public static void main(final String[] args) {
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    52
        final GraphicsEnvironment lge = getLocalGraphicsEnvironment();
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    53
        final GraphicsDevice dev = lge.getDefaultScreenDevice();
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    54
        final GraphicsConfiguration config = dev.getDefaultConfiguration();
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    55
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    56
        test(config.createCompatibleImage(10, 10).getGraphics());
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    57
        test(config.createCompatibleImage(10, 10, OPAQUE).getGraphics());
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    58
        test(config.createCompatibleImage(10, 10, BITMASK).getGraphics());
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    59
        test(config.createCompatibleImage(10, 10, TRANSLUCENT).getGraphics());
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    60
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    61
        test(new BufferedImage(10, 10, TYPE_INT_ARGB).getGraphics());
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    62
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    63
        final Window frame = new Frame();
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    64
        frame.pack();
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    65
        try {
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    66
            test(frame.getGraphics());
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    67
            test(frame.createImage(10, 10).getGraphics());
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    68
        } finally {
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    69
            frame.dispose();
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    70
        }
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    71
    }
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    72
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    73
    private static void test(final Graphics graphics) {
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    74
        try {
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    75
            if (graphics instanceof SunGraphics2D) {
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    76
                final Object dst = ((SunGraphics2D) graphics).getDestination();
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    77
                if (!(dst instanceof Image) && !(dst instanceof Component)) {
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    78
                    throw new RuntimeException("Wrong type:" + dst);
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    79
                }
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    80
            }
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    81
        } finally {
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    82
            graphics.dispose();
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    83
        }
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    84
    }
0808495400e5 8134603: Incorrect destination is used in CGLLayer surface
serb
parents:
diff changeset
    85
}