test/jdk/java/awt/ColorClass/AlphaColorTest.java
author psadhukhan
Tue, 12 Nov 2019 12:29:09 +0530
changeset 59185 571089680cb2
parent 59167 2cf90f3e8195
permissions -rw-r--r--
8233910: java/awt/ColorClass/AlphaColorTest.java is failing intermittently in nightly lnux-x64 system Reviewed-by: serb, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51305
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
     1
/*
55701
20c686ec8135 8227392: Colors with alpha are painted incorrectly on Linux, after JDK-8214579
alitvinov
parents: 51305
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
51305
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
     4
 *
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
     8
 *
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    13
 * accompanied this code).
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    14
 *
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    18
 *
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    21
 * questions.
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    22
 */
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    23
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    24
/**
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    25
 * @test
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    26
 * @key headful
59185
571089680cb2 8233910: java/awt/ColorClass/AlphaColorTest.java is failing intermittently in nightly lnux-x64 system
psadhukhan
parents: 59167
diff changeset
    27
 * @bug 8204931 8227392 8224825 8233910
51305
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    28
 * @summary test alpha colors are blended with background.
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    29
 */
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    30
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    31
import java.awt.Color;
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    32
import java.awt.Component;
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    33
import java.awt.Dimension;
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    34
import java.awt.Frame;
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    35
import java.awt.Graphics;
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    36
import java.awt.Robot;
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    37
import javax.swing.SwingUtilities;
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    38
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    39
public class AlphaColorTest extends Component {
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    40
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    41
    private Color color;
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    42
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    43
    public AlphaColorTest(Color c) {
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    44
       this.color = c;
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    45
    }
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    46
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    47
    public void paint(Graphics g) {
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    48
        g.setColor(color);
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    49
        g.fillRect(0, 0, getSize().width, getSize().height);
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    50
    }
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    51
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    52
    public Dimension getPreferredSize() {
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    53
        return getSize();
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    54
    }
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    55
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    56
    public Dimension getSize() {
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    57
        return new Dimension(200, 200);
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    58
    }
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    59
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    60
    public static void main(String args[]) throws Exception {
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    61
        SwingUtilities.invokeAndWait(() -> createAndShowGUI());
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    62
        Robot robot = new Robot();
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    63
        robot.delay(5000);
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    64
        robot.waitForIdle();
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    65
        Color c = robot.getPixelColor(frame.getX() + 100, frame.getY() + 100);
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    66
        int red = c.getRed();
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    67
        frame.dispose();
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    68
        // Should be 126-128, but be tolerant of gamma correction.
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    69
        if (red < 122 || red > 132) {
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    70
            throw new RuntimeException("Color is not as expected. Got " + c);
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    71
        }
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    72
     }
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    73
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    74
    static Frame frame;
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    75
    private static void createAndShowGUI() {
55701
20c686ec8135 8227392: Colors with alpha are painted incorrectly on Linux, after JDK-8214579
alitvinov
parents: 51305
diff changeset
    76
        frame = new Frame("Alpha Color Test") {
20c686ec8135 8227392: Colors with alpha are painted incorrectly on Linux, after JDK-8214579
alitvinov
parents: 51305
diff changeset
    77
            @Override
20c686ec8135 8227392: Colors with alpha are painted incorrectly on Linux, after JDK-8214579
alitvinov
parents: 51305
diff changeset
    78
            public void paint(Graphics g) {
20c686ec8135 8227392: Colors with alpha are painted incorrectly on Linux, after JDK-8214579
alitvinov
parents: 51305
diff changeset
    79
                g.setColor(Color.black);
20c686ec8135 8227392: Colors with alpha are painted incorrectly on Linux, after JDK-8214579
alitvinov
parents: 51305
diff changeset
    80
                g.fillRect(0, 0, getWidth(), getHeight());
20c686ec8135 8227392: Colors with alpha are painted incorrectly on Linux, after JDK-8214579
alitvinov
parents: 51305
diff changeset
    81
                super.paint(g);
20c686ec8135 8227392: Colors with alpha are painted incorrectly on Linux, after JDK-8214579
alitvinov
parents: 51305
diff changeset
    82
            }
20c686ec8135 8227392: Colors with alpha are painted incorrectly on Linux, after JDK-8214579
alitvinov
parents: 51305
diff changeset
    83
        };
51305
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    84
        Color color = new Color(255, 255, 255, 127);
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    85
        frame.add("Center", new AlphaColorTest(color));
59185
571089680cb2 8233910: java/awt/ColorClass/AlphaColorTest.java is failing intermittently in nightly lnux-x64 system
psadhukhan
parents: 59167
diff changeset
    86
        frame.setUndecorated(true);
571089680cb2 8233910: java/awt/ColorClass/AlphaColorTest.java is failing intermittently in nightly lnux-x64 system
psadhukhan
parents: 59167
diff changeset
    87
        frame.setLocationRelativeTo(null);
51305
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    88
        frame.pack();
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    89
        frame.setVisible(true);
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    90
    }
331888ea4a78 8204931: Colors with alpha are painted incorrectly on Linux
prr
parents:
diff changeset
    91
}