Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/java2d/marlin/ScaleClipTest.java
41149 views
1
/*
2
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import java.awt.BasicStroke;
25
import java.awt.Color;
26
import java.awt.Graphics2D;
27
import java.awt.RenderingHints;
28
import java.awt.geom.AffineTransform;
29
import java.awt.geom.Path2D;
30
import java.awt.image.BufferedImage;
31
import java.awt.image.Raster;
32
import java.io.File;
33
import java.io.IOException;
34
import javax.imageio.ImageIO;
35
36
/**
37
* Scaled Line Clipping rendering test
38
*
39
* @test
40
* @summary verify that scaled line is properly rendered
41
* @bug 8210335
42
*/
43
public class ScaleClipTest {
44
45
static final boolean SAVE_IMAGE = false;
46
static final int SIZE = 50;
47
48
enum SCALE_MODE {
49
ORTHO,
50
NON_ORTHO,
51
COMPLEX
52
};
53
54
public static void main(String[] args) {
55
56
// First display which renderer is tested:
57
// JDK9 only:
58
System.setProperty("sun.java2d.renderer.verbose", "true");
59
60
System.out.println("ScaleClipTest: size = " + SIZE);
61
62
final BufferedImage image = new BufferedImage(SIZE, SIZE, BufferedImage.TYPE_INT_ARGB);
63
64
boolean fail = false;
65
66
// testNegativeScale:
67
for (SCALE_MODE mode : SCALE_MODE.values()) {
68
try {
69
testNegativeScale(image, mode);
70
} catch (IllegalStateException ise) {
71
System.err.println("testNegativeScale[" + mode + "] failed:");
72
ise.printStackTrace();
73
fail = true;
74
}
75
}
76
77
// testMarginScale:
78
for (SCALE_MODE mode : SCALE_MODE.values()) {
79
try {
80
testMarginScale(image, mode);
81
} catch (IllegalStateException ise) {
82
System.err.println("testMarginScale[" + mode + "] failed:");
83
ise.printStackTrace();
84
fail = true;
85
}
86
}
87
88
// Fail at the end:
89
if (fail) {
90
throw new RuntimeException("ScaleClipTest has failures.");
91
}
92
}
93
94
private static void testNegativeScale(final BufferedImage image, final SCALE_MODE mode) {
95
96
final Graphics2D g2d = (Graphics2D) image.getGraphics();
97
try {
98
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
99
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
100
g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
101
102
g2d.setBackground(Color.WHITE);
103
g2d.clearRect(0, 0, SIZE, SIZE);
104
105
g2d.setColor(Color.BLACK);
106
107
// Bug in TransformingPathConsumer2D.adjustClipScale()
108
// non ortho scale only
109
final double scale = -1.0;
110
111
final AffineTransform at;
112
switch (mode) {
113
default:
114
case ORTHO:
115
at = AffineTransform.getScaleInstance(scale, scale);
116
break;
117
case NON_ORTHO:
118
at = AffineTransform.getScaleInstance(scale, scale + 1e-5);
119
break;
120
case COMPLEX:
121
at = AffineTransform.getScaleInstance(scale, scale);
122
at.concatenate(AffineTransform.getShearInstance(1e-4, 1e-4));
123
break;
124
}
125
g2d.setTransform(at);
126
127
// Set cap/join to reduce clip margin:
128
g2d.setStroke(new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
129
130
final Path2D p = new Path2D.Double();
131
p.moveTo(scale * 10, scale * 10);
132
p.lineTo(scale * (SIZE - 10), scale * (SIZE - 10));
133
134
g2d.draw(p);
135
136
if (SAVE_IMAGE) {
137
try {
138
final File file = new File("ScaleClipTest-testNegativeScale-" + mode + ".png");
139
140
System.out.println("Writing file: " + file.getAbsolutePath());
141
ImageIO.write(image, "PNG", file);
142
} catch (IOException ioe) {
143
ioe.printStackTrace();
144
}
145
}
146
147
// Check image:
148
// 25, 25 = black
149
checkPixel(image.getData(), 25, 25, Color.BLACK.getRGB());
150
151
} finally {
152
g2d.dispose();
153
}
154
}
155
156
private static void testMarginScale(final BufferedImage image, final SCALE_MODE mode) {
157
158
final Graphics2D g2d = (Graphics2D) image.getGraphics();
159
try {
160
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
161
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
162
g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
163
164
g2d.setBackground(Color.WHITE);
165
g2d.clearRect(0, 0, SIZE, SIZE);
166
167
g2d.setColor(Color.BLACK);
168
169
// Bug in Stroker.init()
170
// ortho scale only: scale used twice !
171
final double scale = 1e-2;
172
173
final AffineTransform at;
174
switch (mode) {
175
default:
176
case ORTHO:
177
at = AffineTransform.getScaleInstance(scale, scale);
178
break;
179
case NON_ORTHO:
180
at = AffineTransform.getScaleInstance(scale, scale + 1e-5);
181
break;
182
case COMPLEX:
183
at = AffineTransform.getScaleInstance(scale, scale);
184
at.concatenate(AffineTransform.getShearInstance(1e-4, 1e-4));
185
break;
186
}
187
g2d.setTransform(at);
188
189
final double invScale = 1.0 / scale;
190
191
// Set cap/join to reduce clip margin:
192
final float w = (float) (3.0 * invScale);
193
g2d.setStroke(new BasicStroke(w, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
194
195
final Path2D p = new Path2D.Double();
196
p.moveTo(invScale * -0.5, invScale * 10);
197
p.lineTo(invScale * -0.5, invScale * (SIZE - 10));
198
199
g2d.draw(p);
200
201
if (SAVE_IMAGE) {
202
try {
203
final File file = new File("ScaleClipTest-testMarginScale-" + mode + ".png");
204
205
System.out.println("Writing file: " + file.getAbsolutePath());
206
ImageIO.write(image, "PNG", file);
207
} catch (IOException ioe) {
208
ioe.printStackTrace();
209
}
210
}
211
212
// Check image:
213
// 0, 25 = black
214
checkPixel(image.getData(), 0, 25, Color.BLACK.getRGB());
215
} finally {
216
g2d.dispose();
217
}
218
}
219
220
private static void checkPixel(final Raster raster,
221
final int x, final int y,
222
final int expected) {
223
224
final int[] rgb = (int[]) raster.getDataElements(x, y, null);
225
226
if (rgb[0] != expected) {
227
throw new IllegalStateException("bad pixel at (" + x + ", " + y
228
+ ") = " + rgb[0] + " expected: " + expected);
229
}
230
}
231
232
}
233
234