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