|
1 /* |
|
2 * Copyright (c) 2011, 2016, 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 * @key headful |
|
27 * @bug 6985593 |
|
28 * @summary Test verifies that rendering standard images to screen does |
|
29 * not caiuse a crash in case of XRender. |
|
30 * @run main/othervm -Dsun.java2d.xrender=True XRenderBlitsTest |
|
31 */ |
|
32 |
|
33 import java.awt.Color; |
|
34 import java.awt.Component; |
|
35 import java.awt.Dimension; |
|
36 import java.awt.Frame; |
|
37 import java.awt.Graphics; |
|
38 import java.awt.Graphics2D; |
|
39 import java.awt.image.BufferedImage; |
|
40 import java.util.ArrayList; |
|
41 import java.util.concurrent.CountDownLatch; |
|
42 |
|
43 public class XRenderBlitsTest { |
|
44 |
|
45 private static final int w = 10; |
|
46 private static final int h = 10; |
|
47 |
|
48 public static void main(String[] args) { |
|
49 final CountDownLatch done = new CountDownLatch(1); |
|
50 |
|
51 final ArrayList<BufferedImage> images = new ArrayList<BufferedImage>(); |
|
52 |
|
53 int type = BufferedImage.TYPE_INT_RGB; |
|
54 do { |
|
55 BufferedImage img = new BufferedImage(w, h, type++); |
|
56 Graphics2D g2d = img.createGraphics(); |
|
57 g2d.setColor(Color.pink); |
|
58 g2d.fillRect(0, 0, w, h); |
|
59 g2d.dispose(); |
|
60 |
|
61 images.add(img); |
|
62 } while (type <= BufferedImage.TYPE_BYTE_INDEXED); |
|
63 |
|
64 Frame f = new Frame("Draw images"); |
|
65 Component c = new Component() { |
|
66 |
|
67 @Override |
|
68 public Dimension getPreferredSize() { |
|
69 return new Dimension(w * images.size(), h); |
|
70 } |
|
71 |
|
72 @Override |
|
73 public void paint(Graphics g) { |
|
74 int x = 0; |
|
75 for (BufferedImage img : images) { |
|
76 System.out.println("Draw image " + img.getType()); |
|
77 g.drawImage(img, x, 0, this); |
|
78 x += w; |
|
79 } |
|
80 done.countDown(); |
|
81 } |
|
82 }; |
|
83 f.add("Center", c); |
|
84 f.pack(); |
|
85 f.setVisible(true); |
|
86 |
|
87 // now wait for test results |
|
88 try { |
|
89 done.await(); |
|
90 } catch (InterruptedException e) { |
|
91 } |
|
92 System.out.println("Test passed"); |
|
93 f.dispose(); |
|
94 } |
|
95 } |