Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/java2d/pipe/hw/RSLContextInvalidationTest/RSLContextInvalidationTest.java
38867 views
/*1* Copyright (c) 2007, 2008, 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 676425726* @summary Tests that the color is reset properly after save/restore context27* @author [email protected]: area=Graphics28* @compile -XDignore.symbol.file=true RSLContextInvalidationTest.java29* @run main/othervm RSLContextInvalidationTest30* @run main/othervm -Dsun.java2d.noddraw=true RSLContextInvalidationTest31* @run main/othervm -Dsun.java2d.opengl=True RSLContextInvalidationTest32*/3334import java.awt.Color;35import java.awt.Graphics;36import java.awt.GraphicsConfiguration;37import java.awt.GraphicsDevice;38import java.awt.GraphicsEnvironment;39import java.awt.image.BufferedImage;40import java.awt.image.VolatileImage;41import sun.java2d.DestSurfaceProvider;42import sun.java2d.Surface;43import sun.java2d.pipe.RenderQueue;44import sun.java2d.pipe.hw.*;4546public class RSLContextInvalidationTest {4748public static void main(String[] args) {49GraphicsEnvironment ge =50GraphicsEnvironment.getLocalGraphicsEnvironment();51GraphicsDevice gd = ge.getDefaultScreenDevice();52GraphicsConfiguration gc = gd.getDefaultConfiguration();53VolatileImage vi = gc.createCompatibleVolatileImage(100, 100);54vi.validate(gc);55VolatileImage vi1 = gc.createCompatibleVolatileImage(100, 100);56vi1.validate(gc);5758if (!(vi instanceof DestSurfaceProvider)) {59System.out.println("Test considered PASSED: no HW acceleration");60return;61}6263DestSurfaceProvider p = (DestSurfaceProvider)vi;64Surface s = p.getDestSurface();65if (!(s instanceof AccelSurface)) {66System.out.println("Test considered PASSED: no HW acceleration");67return;68}69AccelSurface dst = (AccelSurface)s;7071Graphics g = vi.createGraphics();72g.drawImage(vi1, 95, 95, null);73g.setColor(Color.red);74g.fillRect(0, 0, 100, 100);75g.setColor(Color.black);76g.fillRect(0, 0, 100, 100);77// after this the validated context color is black7879RenderQueue rq = dst.getContext().getRenderQueue();80rq.lock();81try {82dst.getContext().saveState();83dst.getContext().restoreState();84} finally {85rq.unlock();86}8788// this will cause ResetPaint (it will set color to extended EA=ff,89// which is ffffffff==Color.white)90g.drawImage(vi1, 95, 95, null);9192// now try filling with black again, but it will come up as white93// because this fill rect won't validate the color properly94g.setColor(Color.black);95g.fillRect(0, 0, 100, 100);9697BufferedImage bi = vi.getSnapshot();98if (bi.getRGB(50, 50) != Color.black.getRGB()) {99throw new RuntimeException("Test FAILED: found color="+100Integer.toHexString(bi.getRGB(50, 50))+" instead of "+101Integer.toHexString(Color.black.getRGB()));102}103104System.out.println("Test PASSED.");105}106}107108109