Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/macosx/classes/sun/java2d/metal/MTLRenderer.java
41159 views
1
/*
2
* Copyright (c) 2019, 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.metal;
27
28
import sun.java2d.InvalidPipeException;
29
import sun.java2d.SunGraphics2D;
30
import sun.java2d.loops.GraphicsPrimitive;
31
import sun.java2d.pipe.BufferedRenderPipe;
32
import sun.java2d.pipe.ParallelogramPipe;
33
import sun.java2d.pipe.RenderQueue;
34
import sun.java2d.pipe.SpanIterator;
35
36
import java.awt.Transparency;
37
import java.awt.geom.Path2D;
38
39
import static sun.java2d.pipe.BufferedOpCodes.COPY_AREA;
40
41
class MTLRenderer extends BufferedRenderPipe {
42
43
MTLRenderer(RenderQueue rq) {
44
super(rq);
45
}
46
47
@Override
48
protected void validateContext(SunGraphics2D sg2d) {
49
int ctxflags =
50
sg2d.paint.getTransparency() == Transparency.OPAQUE ?
51
MTLContext.SRC_IS_OPAQUE : MTLContext.NO_CONTEXT_FLAGS;
52
MTLSurfaceData dstData;
53
try {
54
dstData = (MTLSurfaceData)sg2d.surfaceData;
55
} catch (ClassCastException e) {
56
throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
57
}
58
MTLContext.validateContext(dstData, dstData,
59
sg2d.getCompClip(), sg2d.composite,
60
null, sg2d.paint, sg2d, ctxflags);
61
}
62
63
@Override
64
protected void validateContextAA(SunGraphics2D sg2d) {
65
int ctxflags = MTLContext.NO_CONTEXT_FLAGS;
66
MTLSurfaceData dstData;
67
try {
68
dstData = (MTLSurfaceData)sg2d.surfaceData;
69
} catch (ClassCastException e) {
70
throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
71
}
72
MTLContext.validateContext(dstData, dstData,
73
sg2d.getCompClip(), sg2d.composite,
74
null, sg2d.paint, sg2d, ctxflags);
75
}
76
77
void copyArea(SunGraphics2D sg2d,
78
int x, int y, int w, int h, int dx, int dy)
79
{
80
rq.lock();
81
try {
82
int ctxflags =
83
sg2d.surfaceData.getTransparency() == Transparency.OPAQUE ?
84
MTLContext.SRC_IS_OPAQUE : MTLContext.NO_CONTEXT_FLAGS;
85
MTLSurfaceData dstData;
86
try {
87
dstData = (MTLSurfaceData)sg2d.surfaceData;
88
} catch (ClassCastException e) {
89
throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
90
}
91
MTLContext.validateContext(dstData, dstData,
92
sg2d.getCompClip(), sg2d.composite,
93
null, null, null, ctxflags);
94
95
rq.ensureCapacity(28);
96
buf.putInt(COPY_AREA);
97
buf.putInt(x).putInt(y).putInt(w).putInt(h);
98
buf.putInt(dx).putInt(dy);
99
} finally {
100
rq.unlock();
101
}
102
}
103
104
@Override
105
protected native void drawPoly(int[] xPoints, int[] yPoints,
106
int nPoints, boolean isClosed,
107
int transX, int transY);
108
109
MTLRenderer traceWrap() {
110
return new Tracer(this);
111
}
112
113
private class Tracer extends MTLRenderer {
114
private MTLRenderer mtlr;
115
Tracer(MTLRenderer mtlr) {
116
super(mtlr.rq);
117
this.mtlr = mtlr;
118
}
119
public ParallelogramPipe getAAParallelogramPipe() {
120
final ParallelogramPipe realpipe = mtlr.getAAParallelogramPipe();
121
return new ParallelogramPipe() {
122
public void fillParallelogram(SunGraphics2D sg2d,
123
double ux1, double uy1,
124
double ux2, double uy2,
125
double x, double y,
126
double dx1, double dy1,
127
double dx2, double dy2)
128
{
129
GraphicsPrimitive.tracePrimitive("MTLFillAAParallelogram");
130
realpipe.fillParallelogram(sg2d,
131
ux1, uy1, ux2, uy2,
132
x, y, dx1, dy1, dx2, dy2);
133
}
134
public void drawParallelogram(SunGraphics2D sg2d,
135
double ux1, double uy1,
136
double ux2, double uy2,
137
double x, double y,
138
double dx1, double dy1,
139
double dx2, double dy2,
140
double lw1, double lw2)
141
{
142
GraphicsPrimitive.tracePrimitive("MTLDrawAAParallelogram");
143
realpipe.drawParallelogram(sg2d,
144
ux1, uy1, ux2, uy2,
145
x, y, dx1, dy1, dx2, dy2,
146
lw1, lw2);
147
}
148
};
149
}
150
protected void validateContext(SunGraphics2D sg2d) {
151
mtlr.validateContext(sg2d);
152
}
153
public void drawLine(SunGraphics2D sg2d,
154
int x1, int y1, int x2, int y2)
155
{
156
GraphicsPrimitive.tracePrimitive("MTLDrawLine");
157
mtlr.drawLine(sg2d, x1, y1, x2, y2);
158
}
159
public void drawRect(SunGraphics2D sg2d, int x, int y, int w, int h) {
160
GraphicsPrimitive.tracePrimitive("MTLDrawRect");
161
mtlr.drawRect(sg2d, x, y, w, h);
162
}
163
protected void drawPoly(SunGraphics2D sg2d,
164
int[] xPoints, int[] yPoints,
165
int nPoints, boolean isClosed)
166
{
167
GraphicsPrimitive.tracePrimitive("MTLDrawPoly");
168
mtlr.drawPoly(sg2d, xPoints, yPoints, nPoints, isClosed);
169
}
170
public void fillRect(SunGraphics2D sg2d, int x, int y, int w, int h) {
171
GraphicsPrimitive.tracePrimitive("MTLFillRect");
172
mtlr.fillRect(sg2d, x, y, w, h);
173
}
174
protected void drawPath(SunGraphics2D sg2d,
175
Path2D.Float p2df, int transx, int transy)
176
{
177
GraphicsPrimitive.tracePrimitive("MTLDrawPath");
178
mtlr.drawPath(sg2d, p2df, transx, transy);
179
}
180
protected void fillPath(SunGraphics2D sg2d,
181
Path2D.Float p2df, int transx, int transy)
182
{
183
GraphicsPrimitive.tracePrimitive("MTLFillPath");
184
mtlr.fillPath(sg2d, p2df, transx, transy);
185
}
186
protected void fillSpans(SunGraphics2D sg2d, SpanIterator si,
187
int transx, int transy)
188
{
189
GraphicsPrimitive.tracePrimitive("MTLFillSpans");
190
mtlr.fillSpans(sg2d, si, transx, transy);
191
}
192
public void fillParallelogram(SunGraphics2D sg2d,
193
double ux1, double uy1,
194
double ux2, double uy2,
195
double x, double y,
196
double dx1, double dy1,
197
double dx2, double dy2)
198
{
199
GraphicsPrimitive.tracePrimitive("MTLFillParallelogram");
200
mtlr.fillParallelogram(sg2d,
201
ux1, uy1, ux2, uy2,
202
x, y, dx1, dy1, dx2, dy2);
203
}
204
public void drawParallelogram(SunGraphics2D sg2d,
205
double ux1, double uy1,
206
double ux2, double uy2,
207
double x, double y,
208
double dx1, double dy1,
209
double dx2, double dy2,
210
double lw1, double lw2)
211
{
212
GraphicsPrimitive.tracePrimitive("MTLDrawParallelogram");
213
mtlr.drawParallelogram(sg2d,
214
ux1, uy1, ux2, uy2,
215
x, y, dx1, dy1, dx2, dy2, lw1, lw2);
216
}
217
public void copyArea(SunGraphics2D sg2d,
218
int x, int y, int w, int h, int dx, int dy)
219
{
220
GraphicsPrimitive.tracePrimitive("MTLCopyArea");
221
mtlr.copyArea(sg2d, x, y, w, h, dx, dy);
222
}
223
}
224
}
225
226