Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/java2d/XRenderBlitsTest.java
38833 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 698559326* @summary Test verifies that rendering standard images to screen does27* not caiuse a crash in case of XRender.28* @run main/othervm -Dsun.java2d.xrender=True XRenderBlitsTest29*/3031import java.awt.Color;32import java.awt.Component;33import java.awt.Dimension;34import java.awt.Frame;35import java.awt.Graphics;36import java.awt.Graphics2D;37import java.awt.image.BufferedImage;38import java.util.ArrayList;39import java.util.concurrent.CountDownLatch;4041public class XRenderBlitsTest {4243private static final int w = 10;44private static final int h = 10;4546public static void main(String[] args) {47final CountDownLatch done = new CountDownLatch(1);4849final ArrayList<BufferedImage> images = new ArrayList<BufferedImage>();5051int type = BufferedImage.TYPE_INT_RGB;52do {53BufferedImage img = new BufferedImage(w, h, type++);54Graphics2D g2d = img.createGraphics();55g2d.setColor(Color.pink);56g2d.fillRect(0, 0, w, h);57g2d.dispose();5859images.add(img);60} while (type <= BufferedImage.TYPE_BYTE_INDEXED);6162Frame f = new Frame("Draw images");63Component c = new Component() {6465@Override66public Dimension getPreferredSize() {67return new Dimension(w * images.size(), h);68}6970@Override71public void paint(Graphics g) {72int x = 0;73for (BufferedImage img : images) {74System.out.println("Draw image " + img.getType());75g.drawImage(img, x, 0, this);76x += w;77}78done.countDown();79}80};81f.add("Center", c);82f.pack();83f.setVisible(true);8485// now wait for test results86try {87done.await();88} catch (InterruptedException e) {89}90System.out.println("Test passed");91f.dispose();92}93}949596