Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/java2d/DrawXORModeTest.java
38833 views
1
/*
2
* Copyright (c) 2014, 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 8036022
27
* @summary Test verifies that drawing shapes with XOR composite
28
* does not trigger an InternalError in GDI surface data.
29
* @run main/othervm -Dsun.java2d.d3d=True DrawXORModeTest
30
*/
31
import java.awt.BasicStroke;
32
import java.awt.Color;
33
import java.awt.Component;
34
import java.awt.Dimension;
35
import java.awt.Frame;
36
import java.awt.Graphics;
37
import java.awt.Graphics2D;
38
import java.awt.Stroke;
39
import java.awt.geom.Line2D;
40
import java.util.concurrent.CountDownLatch;
41
42
public class DrawXORModeTest extends Component {
43
44
public static void main(String[] args) {
45
final DrawXORModeTest c = new DrawXORModeTest();
46
47
final Frame f = new Frame("XOR mode test");
48
f.add(c);
49
f.pack();
50
51
f.setVisible(true);
52
53
try {
54
c.checkResult();
55
} finally {
56
f.dispose();
57
}
58
}
59
60
@Override
61
public void paint(Graphics g) {
62
if (g == null || !(g instanceof Graphics2D)) {
63
return;
64
}
65
g.setColor(Color.white);
66
g.setXORMode(Color.black);
67
Graphics2D dg = (Graphics2D) g;
68
Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT,
69
BasicStroke.JOIN_MITER,
70
10.0f,
71
new float[]{1.0f, 1.0f},
72
0.0f);
73
dg.setStroke(stroke);
74
try {
75
dg.draw(new Line2D.Float(10, 10, 20, 20));
76
} catch (Throwable e) {
77
synchronized (this) {
78
theError = e;
79
}
80
} finally {
81
didDraw.countDown();
82
}
83
}
84
85
@Override
86
public Dimension getPreferredSize() {
87
return new Dimension(400, 100);
88
}
89
90
public void checkResult() {
91
try {
92
didDraw.await();
93
} catch (InterruptedException e) {
94
}
95
96
synchronized (this) {
97
if (theError != null) {
98
System.out.println("Error: " + theError);
99
100
throw new RuntimeException("Test FAILED.");
101
}
102
}
103
System.out.println("Test PASSED.");
104
105
}
106
107
private Throwable theError = null;
108
109
private final CountDownLatch didDraw = new CountDownLatch(1);
110
}
111
112