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