Path: blob/master/test/jdk/sun/java2d/XRenderBlitsTest.java
41144 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 698559327* @summary Test verifies that rendering standard images to screen does28* not caiuse a crash in case of XRender.29* @run main/othervm -Dsun.java2d.xrender=True XRenderBlitsTest30*/3132import java.awt.Color;33import java.awt.Component;34import java.awt.Dimension;35import java.awt.Frame;36import java.awt.Graphics;37import java.awt.Graphics2D;38import java.awt.image.BufferedImage;39import java.util.ArrayList;40import java.util.concurrent.CountDownLatch;4142public class XRenderBlitsTest {4344private static final int w = 10;45private static final int h = 10;4647public static void main(String[] args) {48final CountDownLatch done = new CountDownLatch(1);4950final ArrayList<BufferedImage> images = new ArrayList<BufferedImage>();5152int type = BufferedImage.TYPE_INT_RGB;53do {54BufferedImage img = new BufferedImage(w, h, type++);55Graphics2D g2d = img.createGraphics();56g2d.setColor(Color.pink);57g2d.fillRect(0, 0, w, h);58g2d.dispose();5960images.add(img);61} while (type <= BufferedImage.TYPE_BYTE_INDEXED);6263Frame f = new Frame("Draw images");64Component c = new Component() {6566@Override67public Dimension getPreferredSize() {68return new Dimension(w * images.size(), h);69}7071@Override72public void paint(Graphics g) {73int x = 0;74for (BufferedImage img : images) {75System.out.println("Draw image " + img.getType());76g.drawImage(img, x, 0, this);77x += w;78}79done.countDown();80}81};82f.add("Center", c);83f.pack();84f.setVisible(true);8586// now wait for test results87try {88done.await();89} catch (InterruptedException e) {90}91System.out.println("Test passed");92f.dispose();93}94}959697