Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/java2d/DirectX/NonOpaqueDestLCDAATest/NonOpaqueDestLCDAATest.java
41153 views
1
/*
2
* Copyright (c) 2008, 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
/*
25
* @test
26
* @bug 6728834 6749060 8198613
27
* @summary Tests that LCD AA text rendering works properly with destinations
28
* being VolatileImage of all transparency types
29
* @author Dmitri.Trembovetski: area=Graphics
30
* @run main/manual/othervm -Dsun.java2d.d3d=false NonOpaqueDestLCDAATest
31
* @run main/manual/othervm NonOpaqueDestLCDAATest
32
*/
33
34
import java.awt.AlphaComposite;
35
import java.awt.Color;
36
import java.awt.Dimension;
37
import java.awt.EventQueue;
38
import java.awt.Font;
39
import java.awt.Graphics;
40
import java.awt.Graphics2D;
41
import java.awt.GraphicsConfiguration;
42
import java.awt.Image;
43
import java.awt.RenderingHints;
44
import java.awt.event.ActionEvent;
45
import java.awt.event.ActionListener;
46
import java.awt.event.ComponentAdapter;
47
import java.awt.event.ComponentEvent;
48
import java.awt.event.WindowAdapter;
49
import java.awt.event.WindowEvent;
50
import java.awt.image.BufferedImage;
51
import java.awt.image.VolatileImage;
52
import java.io.File;
53
import java.util.concurrent.CountDownLatch;
54
import javax.imageio.ImageIO;
55
import javax.swing.JButton;
56
import javax.swing.JFrame;
57
import javax.swing.JPanel;
58
import javax.swing.JTextArea;
59
import static java.awt.Transparency.*;
60
61
public class NonOpaqueDestLCDAATest extends JFrame implements ActionListener {
62
private static volatile boolean passed = true;
63
private static CountDownLatch complete = new CountDownLatch(1);
64
65
public NonOpaqueDestLCDAATest() {
66
JTextArea desc = new JTextArea();
67
desc.setText(
68
"\n Instructions: the three text strings below should appear" +
69
" readable, without smudges or misshapen bold glyphs.\n" +
70
" You may need a magnifier to notice some bad colorfringing in "+
71
" in SW Translucent case, especially in vertical stems.\n\n"+
72
" Basically text rendered to TRANSLUCENT destination should look"+
73
" similar to one rendered to OPAQUE - it may differ in whether or" +
74
" not it's LCD, but it should look 'correct'\n\n"+
75
"If the text looks fine the test PASSED otherwise it FAILED.\n");
76
desc.setEditable(false);
77
desc.setBackground(Color.black);
78
desc.setForeground(Color.green);
79
add("North", desc);
80
JPanel renderPanel = new JPanel() {
81
@Override
82
public void paintComponent(Graphics g) {
83
render(g, getWidth(), getHeight());
84
}
85
};
86
renderPanel.setPreferredSize(new Dimension(1024, 650));
87
renderPanel.addComponentListener(new ComponentAdapter() {
88
@Override
89
public void componentResized(ComponentEvent e) {
90
images = null;
91
}
92
});
93
add("Center", renderPanel);
94
95
JButton passedBtn = new JButton("Passed");
96
JButton failedBtn = new JButton("Failed");
97
passedBtn.addActionListener(this);
98
failedBtn.addActionListener(this);
99
JPanel p = new JPanel();
100
p.add(passedBtn);
101
p.add(failedBtn);
102
add("South", p);
103
addWindowListener(new WindowAdapter() {
104
@Override
105
public void windowClosing(WindowEvent e) {
106
complete.countDown();
107
}
108
});
109
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
110
}
111
112
public void render(Graphics g, int w, int h) {
113
initImages(w, h);
114
115
g.setColor(new Color(0xAD, 0xD8, 0xE6));
116
g.fillRect(0, 0, w, h);
117
118
Graphics2D g2d = (Graphics2D) g.create();
119
for (Image im : images) {
120
g2d.drawImage(im, 0, 0, null);
121
g2d.translate(0, im.getHeight(null));
122
}
123
}
124
125
String tr[] = { "OPAQUE", "BITMASK", "TRANSLUCENT" };
126
@Override
127
public void actionPerformed(ActionEvent e) {
128
if (e.getActionCommand().equals("Passed")) {
129
passed = true;
130
System.out.println("Test Passed");
131
} else if (e.getActionCommand().equals("Failed")) {
132
System.out.println("Test Failed");
133
for (int i = 0; i < images.length; i++) {
134
String f = "NonOpaqueDestLCDAATest_"+tr[i];
135
try {
136
if (images[i] instanceof VolatileImage) {
137
f += "_vi.png";
138
ImageIO.write(((VolatileImage)images[i]).
139
getSnapshot(), "png", new File(f));
140
} else {
141
f += "_bi.png";
142
ImageIO.write((BufferedImage)images[i],
143
"png", new File(f));
144
}
145
System.out.printf("Dumped %s image to %s\n", tr[i], f);
146
} catch (Throwable t) {}
147
}
148
passed = false;
149
}
150
dispose();
151
complete.countDown();
152
}
153
154
static void clear(Graphics2D g, int type, int w, int h) {
155
Graphics2D gg = (Graphics2D) g.create();
156
if (type > OPAQUE) {
157
gg.setColor(new Color(0, 0, 0, 0));
158
gg.setComposite(AlphaComposite.Src);
159
} else {
160
gg.setColor(new Color(0xAD, 0xD8, 0xE6));
161
}
162
gg.fillRect(0, 0, w, h);
163
}
164
165
private void render(Image im, int type, String s) {
166
Graphics2D g2d = (Graphics2D) im.getGraphics();
167
clear(g2d, type, im.getWidth(null), im.getHeight(null));
168
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
169
RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
170
Font f = new Font("Dialog", Font.BOLD, 40);// g2d.getFont().deriveFont(32.0f);
171
g2d.setColor(Color.white);
172
g2d.setFont(g2d.getFont().deriveFont(36.0f));
173
g2d.drawString(s, 10, im.getHeight(null) / 2);
174
}
175
176
Image images[];
177
private void initImages(int w, int h) {
178
if (images == null) {
179
images = new Image[6];
180
GraphicsConfiguration gc = getGraphicsConfiguration();
181
for (int i = OPAQUE; i <= TRANSLUCENT; i++) {
182
VolatileImage vi =
183
gc.createCompatibleVolatileImage(w,h/images.length,i);
184
images[i-1] = vi;
185
vi.validate(gc);
186
String s = "LCD AA Text rendered to " + tr[i - 1] + " HW destination";
187
render(vi, i, s);
188
189
s = "LCD AA Text rendered to " + tr[i - 1] + " SW destination";
190
images[i-1+3] = gc.createCompatibleImage(w, h/images.length, i);
191
render(images[i-1+3], i, s);
192
}
193
}
194
}
195
196
public static void main(String[] args) throws InterruptedException {
197
EventQueue.invokeLater(new Runnable() {
198
@Override
199
public void run() {
200
NonOpaqueDestLCDAATest t = new NonOpaqueDestLCDAATest();
201
t.pack();
202
t.setVisible(true);
203
}
204
});
205
206
complete.await();
207
if (!passed) {
208
throw new RuntimeException("Test Failed!");
209
}
210
}
211
}
212
213