Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/share/classes/sun/java2d/pipe/SpanShapeRenderer.java
41159 views
1
/*
2
* Copyright (c) 1998, 2021, 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. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package sun.java2d.pipe;
27
28
import sun.java2d.SunGraphics2D;
29
import sun.java2d.SurfaceData;
30
import java.awt.Rectangle;
31
import java.awt.Shape;
32
import java.awt.BasicStroke;
33
import java.awt.geom.PathIterator;
34
import java.awt.geom.AffineTransform;
35
import java.awt.geom.Rectangle2D;
36
import sun.awt.SunHints;
37
38
/**
39
* This class is used to convert raw geometry into a span iterator
40
* object using a simple flattening polygon scan converter.
41
* The iterator can be passed on to special SpanFiller loops to
42
* perform the actual rendering.
43
*/
44
public abstract class SpanShapeRenderer implements ShapeDrawPipe {
45
46
public static class Composite extends SpanShapeRenderer {
47
CompositePipe comppipe;
48
49
public Composite(CompositePipe pipe) {
50
comppipe = pipe;
51
}
52
53
public Object startSequence(SunGraphics2D sg, Shape s,
54
Rectangle devR, int[] bbox) {
55
return comppipe.startSequence(sg, s, devR, bbox);
56
}
57
58
public void renderBox(Object ctx, int x, int y, int w, int h) {
59
comppipe.renderPathTile(ctx, null, 0, w, x, y, w, h);
60
}
61
62
public void endSequence(Object ctx) {
63
comppipe.endSequence(ctx);
64
}
65
}
66
67
public static class Simple extends SpanShapeRenderer
68
implements LoopBasedPipe
69
{
70
public Object startSequence(SunGraphics2D sg, Shape s,
71
Rectangle devR, int[] bbox) {
72
return sg;
73
}
74
75
public void renderBox(Object ctx, int x, int y, int w, int h) {
76
SunGraphics2D sg2d = (SunGraphics2D) ctx;
77
SurfaceData sd = sg2d.getSurfaceData();
78
sg2d.loops.fillRectLoop.FillRect(sg2d, sd, x, y, w, h);
79
}
80
81
public void endSequence(Object ctx) {
82
}
83
}
84
85
public void draw(SunGraphics2D sg, Shape s) {
86
if (sg.stroke instanceof BasicStroke) {
87
ShapeSpanIterator sr = LoopPipe.getStrokeSpans(sg, s);
88
try {
89
renderSpans(sg, sg.getCompClip(), s, sr);
90
} finally {
91
sr.dispose();
92
}
93
} else {
94
fill(sg, sg.stroke.createStrokedShape(s));
95
}
96
}
97
98
public static final int NON_RECTILINEAR_TRANSFORM_MASK =
99
(AffineTransform.TYPE_GENERAL_TRANSFORM |
100
AffineTransform.TYPE_GENERAL_ROTATION);
101
102
public void fill(SunGraphics2D sg, Shape s) {
103
if (s instanceof Rectangle2D &&
104
(sg.transform.getType() & NON_RECTILINEAR_TRANSFORM_MASK) == 0)
105
{
106
renderRect(sg, (Rectangle2D) s);
107
return;
108
}
109
110
Region clipRegion = sg.getCompClip();
111
ShapeSpanIterator sr = LoopPipe.getFillSSI(sg);
112
try {
113
sr.setOutputArea(clipRegion);
114
sr.appendPath(s.getPathIterator(sg.transform));
115
renderSpans(sg, clipRegion, s, sr);
116
} finally {
117
sr.dispose();
118
}
119
}
120
121
public abstract Object startSequence(SunGraphics2D sg, Shape s,
122
Rectangle devR, int[] bbox);
123
124
public abstract void renderBox(Object ctx, int x, int y, int w, int h);
125
126
public abstract void endSequence(Object ctx);
127
128
public void renderRect(SunGraphics2D sg, Rectangle2D r) {
129
double[] corners = {
130
r.getX(), r.getY(), r.getWidth(), r.getHeight(),
131
};
132
corners[2] += corners[0];
133
corners[3] += corners[1];
134
if (corners[2] <= corners[0] || corners[3] <= corners[1]) {
135
return;
136
}
137
sg.transform.transform(corners, 0, corners, 0, 2);
138
if (corners[2] < corners[0]) {
139
double t = corners[2];
140
corners[2] = corners[0];
141
corners[0] = t;
142
}
143
if (corners[3] < corners[1]) {
144
double t = corners[3];
145
corners[3] = corners[1];
146
corners[1] = t;
147
}
148
int[] abox = {
149
(int) corners[0],
150
(int) corners[1],
151
(int) corners[2],
152
(int) corners[3],
153
};
154
Rectangle devR = new Rectangle(abox[0], abox[1],
155
abox[2] - abox[0],
156
abox[3] - abox[1]);
157
Region clipRegion = sg.getCompClip();
158
clipRegion.clipBoxToBounds(abox);
159
if (abox[0] >= abox[2] || abox[1] >= abox[3]) {
160
return;
161
}
162
Object context = startSequence(sg, r, devR, abox);
163
if (clipRegion.isRectangular()) {
164
renderBox(context, abox[0], abox[1],
165
abox[2] - abox[0],
166
abox[3] - abox[1]);
167
} else {
168
SpanIterator sr = clipRegion.getSpanIterator(abox);
169
while (sr.nextSpan(abox)) {
170
renderBox(context, abox[0], abox[1],
171
abox[2] - abox[0],
172
abox[3] - abox[1]);
173
}
174
}
175
endSequence(context);
176
}
177
178
public void renderSpans(SunGraphics2D sg, Region clipRegion, Shape s,
179
ShapeSpanIterator sr)
180
{
181
Object context = null;
182
int[] abox = new int[4];
183
try {
184
sr.getPathBox(abox);
185
Rectangle devR = new Rectangle(abox[0], abox[1],
186
abox[2] - abox[0],
187
abox[3] - abox[1]);
188
clipRegion.clipBoxToBounds(abox);
189
if (abox[0] >= abox[2] || abox[1] >= abox[3]) {
190
return;
191
}
192
sr.intersectClipBox(abox[0], abox[1], abox[2], abox[3]);
193
context = startSequence(sg, s, devR, abox);
194
195
spanClipLoop(context, sr, clipRegion, abox);
196
197
} finally {
198
if (context != null) {
199
endSequence(context);
200
}
201
}
202
}
203
204
public void spanClipLoop(Object ctx, SpanIterator sr,
205
Region r, int[] abox) {
206
if (!r.isRectangular()) {
207
sr = r.filter(sr);
208
}
209
while (sr.nextSpan(abox)) {
210
int x = abox[0];
211
int y = abox[1];
212
renderBox(ctx, x, y, abox[2] - x, abox[3] - y);
213
}
214
}
215
}
216
217