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