Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/java2d/DirectX/AcceleratedScaleTest/AcceleratedScaleTest.java
41153 views
1
/*
2
* Copyright (c) 2006, 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.Color;
25
import java.awt.Frame;
26
import java.awt.Graphics;
27
import java.awt.Graphics2D;
28
import java.awt.GraphicsConfiguration;
29
import java.awt.GraphicsEnvironment;
30
import java.awt.RenderingHints;
31
import java.awt.Toolkit;
32
import java.awt.image.BufferedImage;
33
import java.awt.image.VolatileImage;
34
import java.io.File;
35
import java.io.IOException;
36
import javax.imageio.ImageIO;
37
38
/**
39
* @test
40
* @key headful
41
* @bug 6429665 6588884 8198613
42
* @summary Tests that the transform is correctly handled
43
* @author Dmitri.Trembovetski area=Graphics
44
* @run main AcceleratedScaleTest
45
* @run main/othervm -Dsun.java2d.d3d=true AcceleratedScaleTest
46
*/
47
public class AcceleratedScaleTest {
48
private static final int IMAGE_SIZE = 200;
49
private static VolatileImage destVI;
50
51
private static void initVI(GraphicsConfiguration gc) {
52
int res;
53
if (destVI == null) {
54
res = VolatileImage.IMAGE_INCOMPATIBLE;
55
} else {
56
res = destVI.validate(gc);
57
}
58
if (res == VolatileImage.IMAGE_INCOMPATIBLE) {
59
if (destVI != null) destVI.flush();
60
destVI = gc.createCompatibleVolatileImage(IMAGE_SIZE, IMAGE_SIZE);
61
destVI.validate(gc);
62
res = VolatileImage.IMAGE_RESTORED;
63
}
64
if (res == VolatileImage.IMAGE_RESTORED) {
65
Graphics vig = destVI.getGraphics();
66
vig.setColor(Color.red);
67
vig.fillRect(0, 0, destVI.getWidth(), destVI.getHeight());
68
vig.dispose();
69
}
70
}
71
72
public static void main(String[] args) {
73
Frame f = new Frame();
74
f.pack();
75
GraphicsConfiguration gc = f.getGraphicsConfiguration();
76
if (gc.getColorModel().getPixelSize() < 16) {
77
System.out.printf("Bit depth: %d . Test considered passed.",
78
gc.getColorModel().getPixelSize());
79
f.dispose();
80
return;
81
}
82
83
BufferedImage bi =
84
new BufferedImage(IMAGE_SIZE/4, IMAGE_SIZE/4,
85
BufferedImage.TYPE_INT_RGB);
86
Graphics2D g = (Graphics2D)bi.getGraphics();
87
g.setColor(Color.red);
88
g.fillRect(0, 0, bi.getWidth(), bi.getHeight());
89
BufferedImage snapshot;
90
do {
91
initVI(gc);
92
g = (Graphics2D)destVI.getGraphics();
93
// "accelerate" BufferedImage
94
for (int i = 0; i < 5; i++) {
95
g.drawImage(bi, 0, 0, null);
96
}
97
g.setColor(Color.white);
98
g.fillRect(0, 0, destVI.getWidth(), destVI.getHeight());
99
100
// this will force the use of Transform primitive instead of
101
// Scale (the latter doesn't do bilinear filtering required by
102
// VALUE_RENDER_QUALITY, which triggers the bug in D3D pipeline
103
g.setRenderingHint(RenderingHints.KEY_RENDERING,
104
RenderingHints.VALUE_RENDER_QUALITY);
105
g.drawImage(bi, 0, 0, destVI.getWidth(), destVI.getHeight(), null);
106
g.fillRect(0, 0, destVI.getWidth(), destVI.getHeight());
107
108
g.drawImage(bi, 0, 0, destVI.getWidth(), destVI.getHeight(), null);
109
110
snapshot = destVI.getSnapshot();
111
} while (destVI.contentsLost());
112
113
f.dispose();
114
int whitePixel = Color.white.getRGB();
115
for (int y = 0; y < snapshot.getHeight(); y++) {
116
for (int x = 0; x < snapshot.getWidth(); x++) {
117
if (snapshot.getRGB(x, y) == whitePixel) {
118
System.out.printf("Found untouched pixel at %dx%d\n", x, y);
119
System.out.println("Dumping the dest. image to " +
120
"AcceleratedScaleTest_dst.png");
121
try {
122
ImageIO.write(snapshot, "png",
123
new File("AcceleratedScaleTest_dst.png"));
124
} catch (IOException ex) {
125
ex.printStackTrace();
126
}
127
throw new RuntimeException("Test failed.");
128
}
129
}
130
}
131
System.out.println("Test Passed.");
132
}
133
134
}
135
136