author | pnarayanan |
Fri, 02 Mar 2018 14:39:29 +0530 | |
changeset 49217 | 3b820b878ebe |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
36874
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
1 |
/* |
49217
3b820b878ebe
8198613: Test cases result in failure or timeout when run with OpenGL backend
pnarayanan
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
36874
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 |
49217
3b820b878ebe
8198613: Test cases result in failure or timeout when run with OpenGL backend
pnarayanan
parents:
47216
diff
changeset
|
32 |
* @bug 8069348 8198613 |
36874
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.d3d=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=false -Dsun.java2d.opengl=false |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
38 |
* -Dsun.java2d.uiScale=2 CopyScaledAreaTest |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
39 |
*/ |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
40 |
public class CopyScaledAreaTest { |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
41 |
|
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
42 |
private static final int IMAGE_WIDTH = 800; |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
43 |
private static final int IMAGE_HEIGHT = 800; |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
44 |
private static final int X = 50; |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
45 |
private static final int Y = 50; |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
46 |
private static final int W = 100; |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
47 |
private static final int H = 75; |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
48 |
private static final int DX = 15; |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
49 |
private static final int DY = 10; |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
50 |
private static final int N = 3; |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
51 |
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
|
52 |
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
|
53 |
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
|
54 |
|
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
55 |
private static boolean isSupported() { |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
56 |
String d3d = System.getProperty("sun.java2d.d3d"); |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
57 |
return !Boolean.getBoolean(d3d) || getOSType() == OSType.WINDOWS; |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
58 |
} |
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 |
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
|
61 |
return (int) Math.floor(x * scale); |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
62 |
} |
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 |
private static VolatileImage createVolatileImage(GraphicsConfiguration conf) { |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
65 |
return conf.createCompatibleVolatileImage(IMAGE_WIDTH, IMAGE_HEIGHT); |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
66 |
} |
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 |
// rendering to the image |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
69 |
private static void renderOffscreen(VolatileImage vImg, |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
70 |
GraphicsConfiguration conf, |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
71 |
double scaleX, |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
72 |
double scaleY) |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
73 |
{ |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
74 |
int attempts = 0; |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
75 |
do { |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
76 |
|
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
77 |
if (attempts > 10) { |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
78 |
throw new RuntimeException("Too many attempts!"); |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
79 |
} |
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 |
if (vImg.validate(conf) == VolatileImage.IMAGE_INCOMPATIBLE) { |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
82 |
// 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
|
83 |
vImg = createVolatileImage(conf); |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
84 |
} |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
85 |
Graphics2D g = vImg.createGraphics(); |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
86 |
// |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
87 |
// miscellaneous rendering commands... |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
88 |
// |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
89 |
g.setColor(BACKGROUND_COLOR); |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
90 |
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
|
91 |
g.scale(scaleX, scaleY); |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
92 |
|
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
93 |
g.setColor(FILL_COLOR); |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
94 |
g.fillRect(X, Y, W, H); |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
95 |
|
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
96 |
for (int i = 0; i < N; i++) { |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
97 |
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
|
98 |
} |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
99 |
g.dispose(); |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
100 |
attempts++; |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
101 |
} while (vImg.contentsLost()); |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
102 |
} |
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 |
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
|
105 |
|
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
106 |
if (!isSupported()) { |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
107 |
return; |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
108 |
} |
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 |
GraphicsConfiguration graphicsConfiguration = |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
111 |
GraphicsEnvironment.getLocalGraphicsEnvironment() |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
112 |
.getDefaultScreenDevice().getDefaultConfiguration(); |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
113 |
|
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
114 |
for(double[] scales: SCALES){ |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
115 |
testScale(scales[0], scales[1], graphicsConfiguration); |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
116 |
} |
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 |
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
|
120 |
GraphicsConfiguration gc) throws Exception |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
121 |
{ |
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 |
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
|
124 |
BufferedImage.TYPE_INT_RGB); |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
125 |
Graphics g = buffImage.createGraphics(); |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
126 |
|
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
127 |
VolatileImage vImg = createVolatileImage(gc); |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
128 |
|
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
129 |
int attempts = 0; |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
130 |
do { |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
131 |
|
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
132 |
if (attempts > 10) { |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
133 |
throw new RuntimeException("Too many attempts!"); |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
134 |
} |
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 |
int returnCode = vImg.validate(gc); |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
137 |
if (returnCode == VolatileImage.IMAGE_RESTORED) { |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
138 |
// Contents need to be restored |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
139 |
renderOffscreen(vImg, gc, scaleX, scaleY); // restore contents |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
140 |
} else if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) { |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
141 |
// 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
|
142 |
vImg = createVolatileImage(gc); |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
143 |
renderOffscreen(vImg, gc, scaleX, scaleY); |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
144 |
} |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
145 |
g.drawImage(vImg, 0, 0, null); |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
146 |
attempts++; |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
147 |
} while (vImg.contentsLost()); |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
148 |
|
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
149 |
g.dispose(); |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
150 |
|
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
151 |
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
|
152 |
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
|
153 |
int w = scale(W, scaleX) - 2; |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
154 |
int h = scale(H, scaleY) - 2; |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
155 |
|
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
156 |
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
|
157 |
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
|
158 |
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
|
159 |
throw new RuntimeException("Wrong rectangle color!"); |
09abfda883d2
8069348: SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D
alexsch
parents:
diff
changeset
|
160 |
} |
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 |
} |