test/jdk/sun/java2d/DrawXORModeTest.java
author lancea
Thu, 14 Nov 2019 10:54:32 -0500
changeset 59083 3e4d8b5856f3
parent 47216 71c04702a3d5
permissions -rw-r--r--
8234080: jdk/nio/zipfs/CRCWriteTest.java fails Reviewed-by: clanger, amlu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23685
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
     1
/*
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 23685
diff changeset
     2
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
23685
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
     4
 *
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
     8
 *
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    13
 * accompanied this code).
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    14
 *
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    18
 *
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    21
 * questions.
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    22
 */
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    23
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    24
/*
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    25
 * @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 23685
diff changeset
    26
 * @key headful
23685
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    27
 * @bug     8036022
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    28
 * @summary Test verifies that drawing shapes with XOR composite
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    29
 *          does not trigger an InternalError in GDI surface data.
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    30
 * @run main/othervm -Dsun.java2d.d3d=True DrawXORModeTest
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    31
 */
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    32
import java.awt.BasicStroke;
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    33
import java.awt.Color;
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    34
import java.awt.Component;
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    35
import java.awt.Dimension;
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    36
import java.awt.Frame;
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    37
import java.awt.Graphics;
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    38
import java.awt.Graphics2D;
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    39
import java.awt.Stroke;
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    40
import java.awt.geom.Line2D;
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    41
import java.util.concurrent.CountDownLatch;
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    42
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    43
public class DrawXORModeTest extends Component {
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    44
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    45
    public static void main(String[] args) {
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    46
        final DrawXORModeTest c = new DrawXORModeTest();
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    47
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    48
        final Frame f = new Frame("XOR mode test");
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    49
        f.add(c);
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    50
        f.pack();
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    51
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    52
        f.setVisible(true);
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    53
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    54
        try {
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    55
            c.checkResult();
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    56
        } finally {
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    57
            f.dispose();
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    58
        }
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    59
    }
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    60
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    61
    @Override
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    62
    public void paint(Graphics g) {
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    63
        if (g == null || !(g instanceof Graphics2D)) {
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    64
            return;
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    65
        }
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    66
        g.setColor(Color.white);
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    67
        g.setXORMode(Color.black);
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    68
        Graphics2D dg = (Graphics2D) g;
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    69
        Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT,
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    70
                BasicStroke.JOIN_MITER,
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    71
                10.0f,
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    72
                new float[]{1.0f, 1.0f},
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    73
                0.0f);
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    74
        dg.setStroke(stroke);
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    75
        try {
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    76
            dg.draw(new Line2D.Float(10, 10, 20, 20));
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    77
        } catch (Throwable e) {
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    78
            synchronized (this) {
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    79
                theError = e;
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    80
            }
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    81
        } finally {
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    82
            didDraw.countDown();
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    83
        }
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    84
    }
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    85
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    86
    @Override
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    87
    public Dimension getPreferredSize() {
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    88
        return new Dimension(400, 100);
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    89
    }
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    90
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    91
    public void checkResult() {
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    92
        try {
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    93
            didDraw.await();
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    94
        } catch (InterruptedException e) {
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    95
        }
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    96
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    97
        synchronized (this) {
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    98
            if (theError != null) {
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
    99
                System.out.println("Error: " + theError);
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
   100
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
   101
                throw new RuntimeException("Test FAILED.");
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
   102
            }
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
   103
        }
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
   104
        System.out.println("Test PASSED.");
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
   105
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
   106
    }
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
   107
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
   108
    private Throwable theError = null;
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
   109
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
   110
    private final CountDownLatch didDraw = new CountDownLatch(1);
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents:
diff changeset
   111
}