Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/java2d/GdiRendering/InsetClipping.java
41149 views
1
/*
2
* Copyright (c) 2003, 2020, 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
* @key headful
27
* @bug 4873505 6588884
28
* @author cheth
29
* @summary verifies that drawImage behaves the bounds of a complex
30
* clip shape. This was a problem with our GDI renderer on Windows, where
31
* we would ignore the window insets.
32
* @run main InsetClipping
33
*/
34
35
/**
36
* This test works by setting up a clip area that equals the visible area
37
* of the Frame. When we perform any rendering operation to that window,
38
* we should not see the results of the operation because they should be
39
* clipped out. We create an Image with one color (red) and use a
40
* different background fill color (blue). We fill the area with the
41
* background color, then set the clip, then draw the image; if we detect
42
* the image color at pixel (0, 0) then we did not clip correctly and the
43
* test fails.
44
*/
45
46
import java.awt.Color;
47
import java.awt.Frame;
48
import java.awt.Graphics;
49
import java.awt.Insets;
50
import java.awt.Point;
51
import java.awt.Rectangle;
52
import java.awt.Robot;
53
import java.awt.geom.Area;
54
import java.awt.image.BufferedImage;
55
56
public class InsetClipping extends Frame {
57
BufferedImage image;
58
Area area;
59
static boolean painted = false;
60
static Color imageColor = Color.red;
61
static Color fillColor = Color.blue;
62
63
public InsetClipping() {
64
65
image = new BufferedImage( 300, 300,BufferedImage.TYPE_INT_RGB);
66
Graphics g2 = image.createGraphics();
67
g2.setColor(imageColor);
68
g2.fillRect(0,0, 300,300);
69
}
70
71
public void paint(Graphics g) {
72
Insets insets = getInsets();
73
area = new Area( new Rectangle(0,0, getWidth(), getHeight()));
74
area.subtract(new Area(new Rectangle(insets.left, insets.top,
75
getWidth() - insets.right,
76
getHeight() - insets.bottom)));
77
g.setColor(fillColor);
78
g.fillRect(0, 0, getWidth(), getHeight());
79
g.setClip(area);
80
g.drawImage(image, 0, 0, null);
81
painted = true;
82
}
83
84
public static void main(String args[]) {
85
InsetClipping clipTest = new InsetClipping();
86
clipTest.setSize(300, 300);
87
clipTest.setLocationRelativeTo(null);
88
clipTest.setVisible(true);
89
while (!painted) {
90
try {
91
Thread.sleep(100);
92
} catch (Exception e) {}
93
}
94
try {
95
Thread.sleep(2000);
96
} catch (InterruptedException ex) {}
97
try {
98
Robot robot = new Robot();
99
Point clientLoc = clipTest.getLocationOnScreen();
100
Insets insets = clipTest.getInsets();
101
clientLoc.x += insets.left;
102
clientLoc.y += insets.top;
103
BufferedImage clientPixels =
104
robot.createScreenCapture(new Rectangle(clientLoc.x,
105
clientLoc.y,
106
clientLoc.x + 2,
107
clientLoc.y + 2));
108
try {
109
Thread.sleep(2000);
110
} catch (Exception e) {}
111
int pixelVal = clientPixels.getRGB(2, 2);
112
clipTest.dispose();
113
if ((new Color(pixelVal)).equals(fillColor)) {
114
System.out.println("Passed");
115
} else {
116
throw new Error("Failed: incorrect color in pixel (2, 2)");
117
}
118
} catch (Exception e) {
119
System.out.println("Problems creating Robot");
120
}
121
}
122
}
123
124