Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/java2d/DirectX/DrawBitmaskToSurfaceTest.java
38840 views
/*1* Copyright (c) 2011, 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* @bug 699711626* @summary Test verifies that rendering of images with bitmap transparency27* to a D3D surface does not cause an ClassCastException.28*29* @run main/othervm -Dsun.java2d.d3d=True DrawBitmaskToSurfaceTest30*/3132import java.awt.Graphics;33import java.awt.Image;34import java.awt.image.BufferedImage;35import java.awt.image.IndexColorModel;36import java.util.concurrent.CountDownLatch;37import javax.swing.JFrame;3839public class DrawBitmaskToSurfaceTest extends JFrame {4041private final Image src;42private static java.util.concurrent.CountDownLatch latch = null;43private static Throwable theError = null;4445public DrawBitmaskToSurfaceTest() {46src = createTestImage();47}4849private static Image createTestImage() {50byte[] r = new byte[]{(byte)0x00, (byte)0x80, (byte)0xff, (byte)0xff};51byte[] g = new byte[]{(byte)0x00, (byte)0x80, (byte)0xff, (byte)0x00};52byte[] b = new byte[]{(byte)0x00, (byte)0x80, (byte)0xff, (byte)0x00};5354IndexColorModel icm = new IndexColorModel(2, 4, r, g, b, 3);5556BufferedImage img = new BufferedImage(100, 100,57BufferedImage.TYPE_BYTE_INDEXED,58icm);59return img;60}6162@Override63public void paint(final Graphics g) {64try {65System.err.println("paint frame....");66g.drawImage(src, 30, 30, this);67} catch (Throwable e) {68theError = e;69} finally {70if (latch != null) {71latch.countDown();72}73}74}7576public static void main(final String[] args) throws Exception {77final JFrame frame = new DrawBitmaskToSurfaceTest();78frame.setBounds(10, 350, 200, 200);79frame.setVisible(true);8081Thread.sleep(2000);8283System.err.println("Change frame bounds...");84latch = new CountDownLatch(1);85frame.setBounds(10, 350, 90, 90);86frame.repaint();8788try {89if (latch.getCount() > 0) {90latch.await();91}92} catch (InterruptedException e) {93}9495frame.dispose();9697if (theError != null) {98throw new RuntimeException("Test failed.", theError);99}100101System.err.println("Test passed");102}103}104105106