jdk/test/sun/java2d/DirectX/DrawBitmaskToSurfaceTest.java
author dlong
Sun, 27 Jan 2013 01:07:09 -0800
changeset 15483 113ca9e9c1bb
parent 10778 679a05f08d57
child 39056 d99e63b6d962
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10778
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
     1
/*
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
     4
 *
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
     7
 * published by the Free Software Foundation.
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
     8
 *
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    13
 * accompanied this code).
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    14
 *
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    18
 *
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    21
 * questions.
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    22
 */
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    23
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    24
/*
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    25
 * @test
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    26
 * @bug     6997116
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    27
 * @summary Test verifies that rendering of images with bitmap transparency
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    28
 *          to a D3D surface does not cause an ClassCastException.
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    29
 *
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    30
 * @run main/othervm -Dsun.java2d.d3d=True DrawBitmaskToSurfaceTest
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    31
 */
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    32
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    33
import java.awt.Graphics;
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    34
import java.awt.Image;
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    35
import java.awt.image.BufferedImage;
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    36
import java.awt.image.IndexColorModel;
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    37
import java.util.concurrent.CountDownLatch;
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    38
import javax.swing.JFrame;
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    39
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    40
public class DrawBitmaskToSurfaceTest extends JFrame {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    41
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    42
    private final Image src;
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    43
    private static java.util.concurrent.CountDownLatch latch = null;
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    44
    private static Throwable theError = null;
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    45
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    46
    public DrawBitmaskToSurfaceTest() {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    47
        src = createTestImage();
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    48
    }
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    49
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    50
    private static Image createTestImage() {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    51
        byte[] r = new byte[]{(byte)0x00, (byte)0x80, (byte)0xff, (byte)0xff};
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    52
        byte[] g = new byte[]{(byte)0x00, (byte)0x80, (byte)0xff, (byte)0x00};
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    53
        byte[] b = new byte[]{(byte)0x00, (byte)0x80, (byte)0xff, (byte)0x00};
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    54
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    55
        IndexColorModel icm = new IndexColorModel(2, 4, r, g, b, 3);
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    56
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    57
        BufferedImage img = new BufferedImage(100, 100,
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    58
                                              BufferedImage.TYPE_BYTE_INDEXED,
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    59
                                              icm);
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    60
        return img;
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    61
    }
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    62
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    63
    @Override
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    64
    public void paint(final Graphics g) {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    65
        try {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    66
            System.err.println("paint frame....");
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    67
            g.drawImage(src, 30, 30, this);
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    68
        } catch (Throwable e) {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    69
            theError = e;
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    70
        } finally {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    71
            if (latch != null) {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    72
                latch.countDown();
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    73
            }
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    74
        }
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    75
    }
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    76
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    77
    public static void main(final String[] args) throws Exception {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    78
        final JFrame frame = new DrawBitmaskToSurfaceTest();
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    79
        frame.setBounds(10, 350, 200, 200);
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    80
        frame.setVisible(true);
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    81
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    82
        Thread.sleep(2000);
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    83
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    84
        System.err.println("Change frame bounds...");
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    85
        latch = new CountDownLatch(1);
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    86
        frame.setBounds(10, 350, 90, 90);
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    87
        frame.repaint();
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    88
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    89
        try {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    90
            if (latch.getCount() > 0) {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    91
                latch.await();
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    92
            }
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    93
        } catch (InterruptedException e) {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    94
        }
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    95
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    96
        frame.dispose();
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    97
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    98
        if (theError != null) {
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
    99
            throw new RuntimeException("Test failed.", theError);
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
   100
        }
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
   101
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
   102
        System.err.println("Test passed");
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
   103
    }
679a05f08d57 6997116: The case automatically failed due to java.lang.ClassCastException.
bae
parents:
diff changeset
   104
}