jdk/test/java/awt/Graphics2D/DrawString/LCDTextSrcEa.java
author goetz
Tue, 14 Jun 2016 10:44:59 +0200
changeset 39056 d99e63b6d962
parent 7751 3ffe25b53aad
permissions -rw-r--r--
8159690: [TESTBUG] Mark headful tests with @key headful. Reviewed-by: simonis, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7751
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
     1
/*
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 7751
diff changeset
     2
 * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
7751
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
     4
 *
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
     8
 *
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    13
 * accompanied this code).
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    14
 *
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    18
 *
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    21
 * questions.
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    22
 */
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    23
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    24
/**
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    25
 * @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 7751
diff changeset
    26
 * @key headful
7751
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    27
 * @bug 6996867
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    28
 * @summary Render as LCD Text in SrcEa composite mode.
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    29
 */
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    30
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    31
import java.awt.*;
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    32
import java.awt.event.*;
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    33
import java.awt.image.*;
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    34
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    35
public class LCDTextSrcEa extends Component {
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    36
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    37
    static int SZ=150;
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    38
    BufferedImage target =
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    39
        new BufferedImage(SZ, SZ, BufferedImage.TYPE_INT_RGB);
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    40
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    41
    public static void main(String args[]) {
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    42
        Frame f = new Frame("LCD Text SrcEa Test");
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    43
        f.addWindowListener(new WindowAdapter() {
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    44
            @Override
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    45
            public void windowClosing(WindowEvent e) {
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    46
                System.exit(0);
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    47
            }
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    48
        });
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    49
        LCDTextSrcEa td = new LCDTextSrcEa();
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    50
        f.add("Center", td);
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    51
        f.pack();
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    52
        f.setVisible(true);
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    53
    }
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    54
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    55
    public Dimension getPreferredSize() {
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    56
        return new Dimension(SZ,SZ);
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    57
    }
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    58
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    59
    public void paint(Graphics gx) {
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    60
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    61
        Graphics2D g2d = (Graphics2D) target.getGraphics();
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    62
        g2d.setColor(Color.white);
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    63
        g2d.fillRect(0, 0, getWidth(), getHeight());
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    64
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    65
        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 0.01f));
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    66
        g2d.setRenderingHint(
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    67
                RenderingHints.KEY_TEXT_ANTIALIASING,
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    68
                RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VBGR);
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    69
        g2d.setRenderingHint(
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    70
               RenderingHints.KEY_ANTIALIASING,
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    71
               RenderingHints.VALUE_ANTIALIAS_ON);
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    72
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    73
        g2d.setColor(Color.black);
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    74
        g2d.drawString("Some sample text.", 10, 20);
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    75
        gx.drawImage(target, 0, 0, null);
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    76
        boolean nongrey = false;
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    77
        //Test BI: should be some non-greyscale color
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    78
        for (int px=0;px<SZ;px++) {
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    79
            for (int py=0;py<SZ;py++) {
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    80
                int rgb = target.getRGB(px, py);
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    81
                int r = (rgb & 0xff0000) >> 16;
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    82
                int g = (rgb & 0x00ff00) >> 8;
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    83
                int b = (rgb & 0x0000ff);
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    84
                if (r != g || r !=b || g != b) {
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    85
                     nongrey=true;
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    86
                     break;
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    87
                }
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    88
            }
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    89
        }
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    90
        if (!nongrey) {
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    91
            throw new RuntimeException("No LCD text found");
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    92
        }
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    93
    }
3ffe25b53aad 6996867: Garbage rendering of LCD text with SRC composite mode
prr
parents:
diff changeset
    94
}