jdk/test/java/awt/Graphics/CopyScaledArea/CopyScaledAreaTest.java
author goetz
Tue, 14 Jun 2016 10:44:59 +0200
changeset 39056 d99e63b6d962
parent 36874 09abfda883d2
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:
36874
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
     1
/*
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
     4
 *
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
     7
 * published by the Free Software Foundation.
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
     8
 *
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    13
 * accompanied this code).
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    14
 *
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    18
 *
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    21
 * questions.
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    22
 */
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    23
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    24
import java.awt.*;
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    25
import java.awt.image.BufferedImage;
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    26
import java.awt.image.VolatileImage;
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    27
import static sun.awt.OSInfo.*;
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    28
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    29
/**
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    30
 * @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 36874
diff changeset
    31
 * @key headful
36874
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    32
 * @bug 8069348
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    33
 * @summary SunGraphics2D.copyArea() does not properly work for scaled graphics
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    34
 * @modules java.desktop/sun.awt
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    35
 * @run main/othervm -Dsun.java2d.uiScale=2 CopyScaledAreaTest
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    36
 * @run main/othervm -Dsun.java2d.opengl=true -Dsun.java2d.uiScale=2 CopyScaledAreaTest
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    37
 * @run main/othervm -Dsun.java2d.d3d=true    -Dsun.java2d.uiScale=2 CopyScaledAreaTest
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    38
 * @run main/othervm -Dsun.java2d.d3d=false   -Dsun.java2d.opengl=false
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    39
 *                   -Dsun.java2d.uiScale=2 CopyScaledAreaTest
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    40
 */
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    41
public class CopyScaledAreaTest {
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    42
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    43
    private static final int IMAGE_WIDTH = 800;
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    44
    private static final int IMAGE_HEIGHT = 800;
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    45
    private static final int X = 50;
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    46
    private static final int Y = 50;
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    47
    private static final int W = 100;
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    48
    private static final int H = 75;
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    49
    private static final int DX = 15;
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    50
    private static final int DY = 10;
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    51
    private static final int N = 3;
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    52
    private static final Color BACKGROUND_COLOR = Color.YELLOW;
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    53
    private static final Color FILL_COLOR = Color.ORANGE;
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    54
    private static final double[][] SCALES = {{1.3, 1.4}, {0.3, 2.3}, {2.7, 0.1}};
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    55
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    56
    private static boolean isSupported() {
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    57
        String d3d = System.getProperty("sun.java2d.d3d");
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    58
        return !Boolean.getBoolean(d3d) || getOSType() == OSType.WINDOWS;
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    59
    }
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    60
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    61
    private static int scale(int x, double scale) {
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    62
        return (int) Math.floor(x * scale);
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    63
    }
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    64
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    65
    private static VolatileImage createVolatileImage(GraphicsConfiguration conf) {
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    66
        return conf.createCompatibleVolatileImage(IMAGE_WIDTH, IMAGE_HEIGHT);
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    67
    }
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    68
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    69
    // rendering to the image
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    70
    private static void renderOffscreen(VolatileImage vImg,
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    71
                                        GraphicsConfiguration conf,
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    72
                                        double scaleX,
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    73
                                        double scaleY)
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    74
    {
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    75
        int attempts = 0;
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    76
        do {
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    77
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    78
            if (attempts > 10) {
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    79
                throw new RuntimeException("Too many attempts!");
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    80
            }
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    81
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    82
            if (vImg.validate(conf) == VolatileImage.IMAGE_INCOMPATIBLE) {
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    83
                // old vImg doesn't work with new GraphicsConfig; re-create it
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    84
                vImg = createVolatileImage(conf);
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    85
            }
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    86
            Graphics2D g = vImg.createGraphics();
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    87
            //
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    88
            // miscellaneous rendering commands...
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    89
            //
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    90
            g.setColor(BACKGROUND_COLOR);
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    91
            g.fillRect(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT);
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    92
            g.scale(scaleX, scaleY);
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    93
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    94
            g.setColor(FILL_COLOR);
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    95
            g.fillRect(X, Y, W, H);
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    96
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    97
            for (int i = 0; i < N; i++) {
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    98
                g.copyArea(X + i * DX, Y + i * DY, W, H, DX, DY);
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
    99
            }
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   100
            g.dispose();
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   101
            attempts++;
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   102
        } while (vImg.contentsLost());
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   103
    }
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   104
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   105
    public static void main(String[] args) throws Exception {
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   106
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   107
        if (!isSupported()) {
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   108
            return;
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   109
        }
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   110
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   111
        GraphicsConfiguration graphicsConfiguration =
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   112
                GraphicsEnvironment.getLocalGraphicsEnvironment()
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   113
                .getDefaultScreenDevice().getDefaultConfiguration();
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   114
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   115
        for(double[] scales: SCALES){
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   116
            testScale(scales[0], scales[1], graphicsConfiguration);
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   117
        }
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   118
    }
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   119
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   120
    private static void testScale(double scaleX, double scaleY,
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   121
                                  GraphicsConfiguration gc) throws Exception
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   122
    {
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   123
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   124
        BufferedImage buffImage = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT,
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   125
                                                    BufferedImage.TYPE_INT_RGB);
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   126
        Graphics g = buffImage.createGraphics();
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   127
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   128
        VolatileImage vImg = createVolatileImage(gc);
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   129
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   130
        int attempts = 0;
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   131
        do {
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   132
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   133
            if (attempts > 10) {
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   134
                throw new RuntimeException("Too many attempts!");
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   135
            }
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   136
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   137
            int returnCode = vImg.validate(gc);
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   138
            if (returnCode == VolatileImage.IMAGE_RESTORED) {
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   139
                // Contents need to be restored
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   140
                renderOffscreen(vImg, gc, scaleX, scaleY); // restore contents
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   141
            } else if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) {
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   142
                // old vImg doesn't work with new GraphicsConfig; re-create it
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   143
                vImg = createVolatileImage(gc);
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   144
                renderOffscreen(vImg, gc, scaleX, scaleY);
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   145
            }
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   146
            g.drawImage(vImg, 0, 0, null);
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   147
            attempts++;
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   148
        } while (vImg.contentsLost());
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   149
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   150
        g.dispose();
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   151
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   152
        int x = scale(X + N * DX, scaleX) + 1;
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   153
        int y = scale(Y + N * DY, scaleY) + 1;
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   154
        int w = scale(W, scaleX) - 2;
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   155
        int h = scale(H, scaleY) - 2;
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   156
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   157
        for (int i = x; i < x + w; i++) {
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   158
            for (int j = y; j < y + h; j++) {
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   159
                if (buffImage.getRGB(i, j) != FILL_COLOR.getRGB()) {
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   160
                    throw new RuntimeException("Wrong rectangle color!");
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   161
                }
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   162
            }
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   163
        }
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   164
    }
09abfda883d2 8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff changeset
   165
}