Path: blob/master/test/jdk/sun/java2d/DirectX/DrawBitmaskToSurfaceTest.java
41149 views
/*1* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @key headful26* @bug 699711627* @summary Test verifies that rendering of images with bitmap transparency28* to a D3D surface does not cause an ClassCastException.29*30* @run main/othervm -Dsun.java2d.d3d=True DrawBitmaskToSurfaceTest31*/3233import java.awt.Graphics;34import java.awt.Image;35import java.awt.image.BufferedImage;36import java.awt.image.IndexColorModel;37import java.util.concurrent.CountDownLatch;38import javax.swing.JFrame;3940public class DrawBitmaskToSurfaceTest extends JFrame {4142private final Image src;43private static java.util.concurrent.CountDownLatch latch = null;44private static Throwable theError = null;4546public DrawBitmaskToSurfaceTest() {47src = createTestImage();48}4950private static Image createTestImage() {51byte[] r = new byte[]{(byte)0x00, (byte)0x80, (byte)0xff, (byte)0xff};52byte[] g = new byte[]{(byte)0x00, (byte)0x80, (byte)0xff, (byte)0x00};53byte[] b = new byte[]{(byte)0x00, (byte)0x80, (byte)0xff, (byte)0x00};5455IndexColorModel icm = new IndexColorModel(2, 4, r, g, b, 3);5657BufferedImage img = new BufferedImage(100, 100,58BufferedImage.TYPE_BYTE_INDEXED,59icm);60return img;61}6263@Override64public void paint(final Graphics g) {65try {66System.err.println("paint frame....");67g.drawImage(src, 30, 30, this);68} catch (Throwable e) {69theError = e;70} finally {71if (latch != null) {72latch.countDown();73}74}75}7677public static void main(final String[] args) throws Exception {78final JFrame frame = new DrawBitmaskToSurfaceTest();79frame.setBounds(10, 350, 200, 200);80frame.setVisible(true);8182Thread.sleep(2000);8384System.err.println("Change frame bounds...");85latch = new CountDownLatch(1);86frame.setBounds(10, 350, 90, 90);87frame.repaint();8889try {90if (latch.getCount() > 0) {91latch.await();92}93} catch (InterruptedException e) {94}9596frame.dispose();9798if (theError != null) {99throw new RuntimeException("Test failed.", theError);100}101102System.err.println("Test passed");103}104}105106107