Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLContext.h
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
#ifndef MTLContext_h_Included
27
#define MTLContext_h_Included
28
29
#include "sun_java2d_pipe_BufferedContext.h"
30
#include "sun_java2d_metal_MTLContext_MTLContextCaps.h"
31
32
#import <Metal/Metal.h>
33
34
#include "MTLTexturePool.h"
35
#include "MTLPipelineStatesStorage.h"
36
#include "MTLTransform.h"
37
#include "MTLComposite.h"
38
#include "MTLPaints.h"
39
#include "MTLClip.h"
40
#include "EncoderManager.h"
41
#include "MTLSamplerManager.h"
42
43
@class MTLStencilManager;
44
45
// Constant from
46
// https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf
47
#define MTL_GPU_FAMILY_MAC_TXT_SIZE 16384
48
49
/**
50
* The MTLCommandBufferWrapper class contains command buffer and
51
* associated resources that will be released in completion handler
52
* */
53
@interface MTLCommandBufferWrapper : NSObject
54
- (id<MTLCommandBuffer>) getCommandBuffer;
55
- (void) onComplete; // invoked from completion handler in some pooled thread
56
- (void) registerPooledTexture:(MTLPooledTextureHandle *)handle;
57
@end
58
59
/**
60
* The MTLContext class contains cached state relevant to the native
61
* MTL context stored within the native ctxInfo field. Each Java-level
62
* MTLContext object is associated with a native-level MTLContext class.
63
* */
64
@interface MTLContext : NSObject
65
@property (readonly) MTLComposite * composite;
66
@property (readwrite, retain) MTLPaint * paint;
67
@property (readonly) MTLTransform * transform;
68
@property (readonly) MTLClip * clip;
69
70
@property jint textureFunction;
71
@property jboolean vertexCacheEnabled;
72
@property jboolean aaEnabled;
73
74
@property (readonly, strong) id<MTLDevice> device;
75
@property (strong) id<MTLCommandQueue> commandQueue;
76
@property (strong) id<MTLCommandQueue> blitCommandQueue;
77
@property (strong) id<MTLBuffer> vertexBuffer;
78
79
@property (readonly) EncoderManager * encoderManager;
80
@property (readonly) MTLSamplerManager * samplerManager;
81
@property (readonly) MTLStencilManager * stencilManager;
82
83
@property (strong)MTLPipelineStatesStorage* pipelineStateStorage;
84
@property (strong)MTLTexturePool* texturePool;
85
86
- (MTLCommandBufferWrapper *) getCommandBufferWrapper; // creates command buffer wrapper (when doesn't exist)
87
- (MTLCommandBufferWrapper *) pullCommandBufferWrapper; // returns current buffer wrapper with loosing object ownership
88
89
/**
90
* Fetches the MTLContext associated with the given destination surface,
91
* makes the context current for those surfaces, updates the destination
92
* viewport, and then returns a pointer to the MTLContext.
93
*/
94
+ (MTLContext*) setSurfacesEnv:(JNIEnv*)env src:(jlong)pSrc dst:(jlong)pDst;
95
96
- (id)initWithDevice:(id<MTLDevice>)d shadersLib:(NSString*)shadersLib;
97
- (void)dealloc;
98
99
/**
100
* Resets the current clip state (disables both scissor and depth tests).
101
*/
102
- (void)resetClip;
103
104
/**
105
* Sets the Metal scissor bounds to the provided rectangular clip bounds.
106
*/
107
- (void)setClipRectX1:(jint)x1 Y1:(jint)y1 X2:(jint)x2 Y2:(jint)y2;
108
109
- (const MTLScissorRect *)clipRect;
110
111
/**
112
* Sets up a complex (shape) clip using the Metal stencil buffer. This
113
* method prepares the stencil buffer so that the clip Region spans can
114
* be "rendered" into it. The stencil buffer is first cleared, then the
115
* stencil func is setup so that when we render the clip spans,
116
* nothing is rendered into the color buffer, but for each pixel that would
117
* be rendered, a 0xFF value is placed into that location in the stencil
118
* buffer. With stencil test enabled, pixels will only be rendered into the
119
* color buffer if the corresponding value at that (x,y) location in the
120
* stencil buffer is equal to 0xFF.
121
*/
122
- (void)beginShapeClip:(BMTLSDOps *)dstOps;
123
124
/**
125
* Finishes setting up the shape clip by resetting the stencil func
126
* so that future rendering operations will once again be encoded for the
127
* color buffer (while respecting the clip set up in the stencil buffer).
128
*/
129
- (void)endShapeClip:(BMTLSDOps *)dstOps;
130
131
/**
132
* Resets all Metal compositing state (disables blending and logic
133
* operations).
134
*/
135
- (void)resetComposite;
136
137
/**
138
* Initializes the Metal blending state. XOR mode is disabled and the
139
* appropriate blend functions are setup based on the AlphaComposite rule
140
* constant.
141
*/
142
- (void)setAlphaCompositeRule:(jint)rule extraAlpha:(jfloat)extraAlpha
143
flags:(jint)flags;
144
145
/**
146
* Returns autorelease string with composite description (for debugging only)
147
*/
148
- (NSString*)getCompositeDescription;
149
150
/**
151
* Returns autorelease string with paint description (for debugging only)
152
*/
153
- (NSString*)getPaintDescription;
154
155
/**
156
* Initializes the Metal logic op state to XOR mode. Blending is disabled
157
* before enabling logic op mode. The XOR pixel value will be applied
158
* later in the MTLContext_SetColor() method.
159
*/
160
- (void)setXorComposite:(jint)xorPixel;
161
- (jboolean)useXORComposite;
162
163
/**
164
* Resets the Metal transform state back to the identity matrix.
165
*/
166
- (void)resetTransform;
167
168
/**
169
* Initializes the Metal transform state by setting the modelview transform
170
* using the given matrix parameters.
171
*
172
* REMIND: it may be worthwhile to add serial id to AffineTransform, so we
173
* could do a quick check to see if the xform has changed since
174
* last time... a simple object compare won't suffice...
175
*/
176
- (void)setTransformM00:(jdouble) m00 M10:(jdouble) m10
177
M01:(jdouble) m01 M11:(jdouble) m11
178
M02:(jdouble) m02 M12:(jdouble) m12;
179
180
- (void)reset;
181
- (void)resetPaint;
182
- (void)setColorPaint:(int)pixel;
183
- (void)setGradientPaintUseMask:(jboolean)useMask
184
cyclic:(jboolean)cyclic
185
p0:(jdouble)p0
186
p1:(jdouble)p1
187
p3:(jdouble)p3
188
pixel1:(jint)pixel1
189
pixel2:(jint) pixel2;
190
- (void)setLinearGradientPaint:(jboolean)useMask
191
linear:(jboolean)linear
192
cycleMethod:(jint)cycleMethod
193
numStops:(jint)numStops
194
p0:(jfloat)p0
195
p1:(jfloat)p1
196
p3:(jfloat)p3
197
fractions:(jfloat *)fractions
198
pixels:(jint *)pixels;
199
- (void)setRadialGradientPaint:(jboolean)useMask
200
linear:(jboolean)linear
201
cycleMethod:(jboolean)cycleMethod
202
numStops:(jint)numStops
203
m00:(jfloat)m00
204
m01:(jfloat)m01
205
m02:(jfloat)m02
206
m10:(jfloat)m10
207
m11:(jfloat)m11
208
m12:(jfloat)m12
209
focusX:(jfloat)focusX
210
fractions:(void *)fractions
211
pixels:(void *)pixels;
212
- (void)setTexturePaint:(jboolean)useMask
213
pSrcOps:(jlong)pSrcOps
214
filter:(jboolean)filter
215
xp0:(jdouble)xp0
216
xp1:(jdouble)xp1
217
xp3:(jdouble)xp3
218
yp0:(jdouble)yp0
219
yp1:(jdouble)yp1
220
yp3:(jdouble)yp3;
221
222
// Sets current image conversion operation (instance of MTLConvolveOp, MTLRescaleOp, MTLLookupOp).
223
// Used only in MTLIsoBlit (to blit image with some conversion). Pattern of usage: enableOp -> IsoBlit -> disableOp.
224
// TODO: Need to remove it from MTLContext and pass it as an argument for IsoBlit (because it's more
225
// simple and clear)
226
-(void)setBufImgOp:(NSObject*)bufImgOp;
227
228
-(NSObject*)getBufImgOp;
229
230
- (id<MTLCommandBuffer>)createCommandBuffer;
231
- (id<MTLCommandBuffer>)createBlitCommandBuffer;
232
@end
233
234
/**
235
* See BufferedContext.java for more on these flags...
236
*/
237
#define MTLC_NO_CONTEXT_FLAGS \
238
sun_java2d_pipe_BufferedContext_NO_CONTEXT_FLAGS
239
#define MTLC_SRC_IS_OPAQUE \
240
sun_java2d_pipe_BufferedContext_SRC_IS_OPAQUE
241
#define MTLC_USE_MASK \
242
sun_java2d_pipe_BufferedContext_USE_MASK
243
244
#endif /* MTLContext_h_Included */
245
246