jdk/test/sun/java2d/pipe/hw/RSLContextInvalidationTest/RSLContextInvalidationTest.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 1732 cbd1ef3625fc
child 31448 1066345d2a8a
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1732
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1732
diff changeset
     2
 * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
1732
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
     4
 *
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
     7
 * published by the Free Software Foundation.
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
     8
 *
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    13
 * accompanied this code).
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    14
 *
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1732
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1732
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1732
diff changeset
    21
 * questions.
1732
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    22
 */
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    23
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    24
/*
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    25
 * @test
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    26
 * @bug 6764257
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    27
 * @summary Tests that the color is reset properly after save/restore context
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    28
 * @author Dmitri.Trembovetski@sun.com: area=Graphics
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    29
 * @compile -XDignore.symbol.file=true RSLContextInvalidationTest.java
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    30
 * @run main/othervm RSLContextInvalidationTest
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    31
 * @run main/othervm -Dsun.java2d.noddraw=true RSLContextInvalidationTest
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    32
 * @run main/othervm -Dsun.java2d.opengl=True RSLContextInvalidationTest
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    33
 */
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    34
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    35
import java.awt.Color;
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    36
import java.awt.Graphics;
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    37
import java.awt.GraphicsConfiguration;
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    38
import java.awt.GraphicsDevice;
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    39
import java.awt.GraphicsEnvironment;
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    40
import java.awt.image.BufferedImage;
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    41
import java.awt.image.VolatileImage;
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    42
import sun.java2d.DestSurfaceProvider;
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    43
import sun.java2d.Surface;
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    44
import sun.java2d.pipe.RenderQueue;
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    45
import sun.java2d.pipe.hw.*;
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    46
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    47
public class RSLContextInvalidationTest {
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    48
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    49
    public static void main(String[] args) {
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    50
        GraphicsEnvironment ge =
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    51
            GraphicsEnvironment.getLocalGraphicsEnvironment();
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    52
        GraphicsDevice gd = ge.getDefaultScreenDevice();
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    53
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    54
        VolatileImage vi = gc.createCompatibleVolatileImage(100, 100);
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    55
        vi.validate(gc);
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    56
        VolatileImage vi1 = gc.createCompatibleVolatileImage(100, 100);
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    57
        vi1.validate(gc);
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    58
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    59
        if (!(vi instanceof DestSurfaceProvider)) {
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    60
            System.out.println("Test considered PASSED: no HW acceleration");
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    61
            return;
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    62
        }
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    63
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    64
        DestSurfaceProvider p = (DestSurfaceProvider)vi;
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    65
        Surface s = p.getDestSurface();
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    66
        if (!(s instanceof AccelSurface)) {
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    67
            System.out.println("Test considered PASSED: no HW acceleration");
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    68
            return;
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    69
        }
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    70
        AccelSurface dst = (AccelSurface)s;
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    71
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    72
        Graphics g = vi.createGraphics();
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    73
        g.drawImage(vi1, 95, 95, null);
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    74
        g.setColor(Color.red);
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    75
        g.fillRect(0, 0, 100, 100);
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    76
        g.setColor(Color.black);
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    77
        g.fillRect(0, 0, 100, 100);
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    78
        // after this the validated context color is black
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    79
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    80
        RenderQueue rq = dst.getContext().getRenderQueue();
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    81
        rq.lock();
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    82
        try {
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    83
            dst.getContext().saveState();
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    84
            dst.getContext().restoreState();
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    85
        } finally {
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    86
            rq.unlock();
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    87
        }
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    88
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    89
        // this will cause ResetPaint (it will set color to extended EA=ff,
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    90
        // which is ffffffff==Color.white)
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    91
        g.drawImage(vi1, 95, 95, null);
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    92
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    93
        // now try filling with black again, but it will come up as white
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    94
        // because this fill rect won't validate the color properly
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    95
        g.setColor(Color.black);
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    96
        g.fillRect(0, 0, 100, 100);
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    97
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    98
        BufferedImage bi = vi.getSnapshot();
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
    99
        if (bi.getRGB(50, 50) != Color.black.getRGB()) {
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
   100
            throw new RuntimeException("Test FAILED: found color="+
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
   101
                Integer.toHexString(bi.getRGB(50, 50))+" instead of "+
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
   102
                Integer.toHexString(Color.black.getRGB()));
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
   103
        }
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
   104
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
   105
        System.out.println("Test PASSED.");
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
   106
    }
cbd1ef3625fc 6764257: D3D/OGL: color is not reset properly after save/restoreState() [RSL]
tdv
parents:
diff changeset
   107
}