jdk/test/java/awt/Graphics2D/FillTexturePaint/FillTexturePaint.java
author serb
Fri, 12 Apr 2013 15:28:49 +0400
changeset 16840 64446d4710c4
child 21596 0e3a39f29dbc
permissions -rw-r--r--
8000629: [macosx] Blurry rendering with Java 7 on Retina display Reviewed-by: anthony, prr, flar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
     1
/*
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
     4
 *
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    10
 *
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    15
 * accompanied this code).
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    16
 *
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    20
 *
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    23
 * questions.
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    24
 */
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    25
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    26
import java.awt.AlphaComposite;
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    27
import java.awt.Color;
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    28
import java.awt.Graphics2D;
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    29
import java.awt.GraphicsConfiguration;
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    30
import java.awt.GraphicsEnvironment;
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    31
import java.awt.Rectangle;
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    32
import java.awt.TexturePaint;
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    33
import java.awt.image.BufferedImage;
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    34
import java.awt.image.VolatileImage;
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    35
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    36
/**
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    37
 * @test
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    38
 * @bug 8000629
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    39
 * @summary TexturePaint areas shouldn't separates.
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    40
 * @author Sergey Bylokhov
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    41
 */
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    42
public class FillTexturePaint {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    43
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    44
    private static TexturePaint shape;
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    45
    private static final int size = 400;
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    46
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    47
    static {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    48
        BufferedImage bi = new BufferedImage(50, 50,
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    49
                                             BufferedImage.TYPE_INT_RGB);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    50
        Graphics2D gi = bi.createGraphics();
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    51
        gi.setBackground(Color.GREEN);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    52
        gi.clearRect(0, 0, 50, 50);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    53
        shape = new TexturePaint(bi, new Rectangle(0, 0, 50, 50));
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    54
    }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    55
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    56
    public static void main(final String[] args) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    57
        GraphicsEnvironment ge =
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    58
                GraphicsEnvironment.getLocalGraphicsEnvironment();
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    59
        GraphicsConfiguration gc =
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    60
                ge.getDefaultScreenDevice().getDefaultConfiguration();
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    61
        VolatileImage vi = gc.createCompatibleVolatileImage(size, size);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    62
        while (true) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    63
            vi.validate(gc);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    64
            Graphics2D g2d = vi.createGraphics();
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    65
            g2d.setComposite(AlphaComposite.Src);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    66
            g2d.setPaint(shape);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    67
            g2d.fill(new Rectangle(0, 0, size, size));
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    68
            g2d.dispose();
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    69
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    70
            if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    71
                try {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    72
                    Thread.sleep(100);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    73
                } catch (InterruptedException ignored) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    74
                }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    75
                continue;
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    76
            }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    77
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    78
            BufferedImage bi = vi.getSnapshot();
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    79
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    80
            if (vi.contentsLost()) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    81
                try {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    82
                    Thread.sleep(100);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    83
                } catch (InterruptedException ignored) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    84
                }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    85
                continue;
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    86
            }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    87
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    88
            for (int x = 0; x < size; ++x) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    89
                for (int y = 0; y < size; ++y) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    90
                    if (bi.getRGB(x, y) != Color.GREEN.getRGB()) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    91
                        throw new RuntimeException("Test failed.");
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    92
                    }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    93
                }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    94
            }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    95
            break;
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    96
        }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    97
    }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents:
diff changeset
    98
}