RSLContextInvalidationTest.java revision 14851:980da45565c8
1/* 2 * Copyright (c) 2007, 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 6764257 28 * @summary Tests that the color is reset properly after save/restore context 29 * @author Dmitri.Trembovetski@sun.com: area=Graphics 30 * @modules java.desktop/sun.java2d 31 * java.desktop/sun.java2d.pipe 32 * java.desktop/sun.java2d.pipe.hw 33 * @compile -XDignore.symbol.file=true RSLContextInvalidationTest.java 34 * @run main/othervm RSLContextInvalidationTest 35 * @run main/othervm -Dsun.java2d.noddraw=true RSLContextInvalidationTest 36 * @run main/othervm -Dsun.java2d.opengl=True RSLContextInvalidationTest 37 */ 38 39import java.awt.Color; 40import java.awt.Graphics; 41import java.awt.GraphicsConfiguration; 42import java.awt.GraphicsDevice; 43import java.awt.GraphicsEnvironment; 44import java.awt.image.BufferedImage; 45import java.awt.image.VolatileImage; 46import sun.java2d.DestSurfaceProvider; 47import sun.java2d.Surface; 48import sun.java2d.pipe.RenderQueue; 49import sun.java2d.pipe.hw.*; 50 51public class RSLContextInvalidationTest { 52 53 public static void main(String[] args) { 54 GraphicsEnvironment ge = 55 GraphicsEnvironment.getLocalGraphicsEnvironment(); 56 GraphicsDevice gd = ge.getDefaultScreenDevice(); 57 GraphicsConfiguration gc = gd.getDefaultConfiguration(); 58 VolatileImage vi = gc.createCompatibleVolatileImage(100, 100); 59 vi.validate(gc); 60 VolatileImage vi1 = gc.createCompatibleVolatileImage(100, 100); 61 vi1.validate(gc); 62 63 if (!(vi instanceof DestSurfaceProvider)) { 64 System.out.println("Test considered PASSED: no HW acceleration"); 65 return; 66 } 67 68 DestSurfaceProvider p = (DestSurfaceProvider)vi; 69 Surface s = p.getDestSurface(); 70 if (!(s instanceof AccelSurface)) { 71 System.out.println("Test considered PASSED: no HW acceleration"); 72 return; 73 } 74 AccelSurface dst = (AccelSurface)s; 75 76 Graphics g = vi.createGraphics(); 77 g.drawImage(vi1, 95, 95, null); 78 g.setColor(Color.red); 79 g.fillRect(0, 0, 100, 100); 80 g.setColor(Color.black); 81 g.fillRect(0, 0, 100, 100); 82 // after this the validated context color is black 83 84 RenderQueue rq = dst.getContext().getRenderQueue(); 85 rq.lock(); 86 try { 87 dst.getContext().saveState(); 88 dst.getContext().restoreState(); 89 } finally { 90 rq.unlock(); 91 } 92 93 // this will cause ResetPaint (it will set color to extended EA=ff, 94 // which is ffffffff==Color.white) 95 g.drawImage(vi1, 95, 95, null); 96 97 // now try filling with black again, but it will come up as white 98 // because this fill rect won't validate the color properly 99 g.setColor(Color.black); 100 g.fillRect(0, 0, 100, 100); 101 102 BufferedImage bi = vi.getSnapshot(); 103 if (bi.getRGB(50, 50) != Color.black.getRGB()) { 104 throw new RuntimeException("Test FAILED: found color="+ 105 Integer.toHexString(bi.getRGB(50, 50))+" instead of "+ 106 Integer.toHexString(Color.black.getRGB())); 107 } 108 109 System.out.println("Test PASSED."); 110 } 111} 112