This repository has been archived by the owner on Aug 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
MTLContext.h
272 lines (235 loc) · 10.1 KB
/
MTLContext.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#ifndef MTLContext_h_Included
#define MTLContext_h_Included
#include "sun_java2d_pipe_BufferedContext.h"
#include "sun_java2d_metal_MTLContext.h"
#include "sun_java2d_metal_MTLContext_MTLContextCaps.h"
#import <Metal/Metal.h>
#include "MTLTexturePool.h"
#include "MTLPipelineStatesStorage.h"
#include "MTLTransform.h"
#include "MTLComposite.h"
#include "MTLPaints.h"
#include "MTLClip.h"
#include "EncoderManager.h"
#define MTLC_BLIT_TILE_SIZE 128
/**
* The MTLCommandBufferWrapper class contains command buffer and
* associated resources that will be released in completion handler
* */
@interface MTLCommandBufferWrapper : NSObject
- (id<MTLCommandBuffer>) getCommandBuffer;
- (void) onComplete; // invoked from completion handler in some pooled thread
- (void) registerPooledTexture:(MTLPooledTextureHandle *)handle;
@end
/**
* The MTLContext class contains cached state relevant to the native
* MTL context stored within the native ctxInfo field. Each Java-level
* MTLContext object is associated with a native-level MTLContext class.
* */
@interface MTLContext : NSObject
@property (readonly) MTLComposite * composite;
@property (readonly) MTLPaint * paint;
@property (readonly) MTLTransform * transform;
@property (readonly) MTLClip * clip;
@property jint textureFunction;
@property jboolean vertexCacheEnabled;
@property jboolean aaEnabled;
@property (readonly, strong) id<MTLDevice> device;
@property (strong) id<MTLLibrary> library;
@property (strong) id<MTLCommandQueue> commandQueue;
@property (strong) id<MTLCommandQueue> blitCommandQueue;
@property (strong) id<MTLBuffer> vertexBuffer;
@property (readonly) EncoderManager * encoderManager;
@property (strong)MTLPipelineStatesStorage* pipelineStateStorage;
@property (strong)MTLTexturePool* texturePool;
- (MTLCommandBufferWrapper *) getCommandBufferWrapper; // creates command buffer wrapper (when doesn't exist)
- (MTLCommandBufferWrapper *) pullCommandBufferWrapper; // returns current buffer wrapper with loosing object ownership
/**
* Fetches the MTLContext associated with the given destination surface,
* makes the context current for those surfaces, updates the destination
* viewport, and then returns a pointer to the MTLContext.
*/
+ (MTLContext*) setSurfacesEnv:(JNIEnv*)env src:(jlong)pSrc dst:(jlong)pDst;
- (id)initWithDevice:(id<MTLDevice>)d shadersLib:(NSString*)shadersLib;
- (void)dealloc;
/**
* Resets the current clip state (disables both scissor and depth tests).
*/
- (void)resetClip;
/**
* Sets the Metal scissor bounds to the provided rectangular clip bounds.
*/
- (void)setClipRectX1:(jint)x1 Y1:(jint)y1 X2:(jint)x2 Y2:(jint)y2;
- (const MTLScissorRect *)clipRect;
/**
* Sets up a complex (shape) clip using the Metal stencil buffer. This
* method prepares the stencil buffer so that the clip Region spans can
* be "rendered" into it. The stencil buffer is first cleared, then the
* stencil func is setup so that when we render the clip spans,
* nothing is rendered into the color buffer, but for each pixel that would
* be rendered, a 0xFF value is placed into that location in the stencil
* buffer. With stencil test enabled, pixels will only be rendered into the
* color buffer if the corresponding value at that (x,y) location in the
* stencil buffer is equal to 0xFF.
*/
- (void)beginShapeClip:(BMTLSDOps *)dstOps;
/**
* Finishes setting up the shape clip by resetting the stencil func
* so that future rendering operations will once again be encoded for the
* color buffer (while respecting the clip set up in the stencil buffer).
*/
- (void)endShapeClip:(BMTLSDOps *)dstOps;
/**
* Initializes the OpenGL state responsible for applying extra alpha. This
* step is only necessary for any operation that uses glDrawPixels() or
* glCopyPixels() with a non-1.0f extra alpha value. Since the source is
* always premultiplied, we apply the extra alpha value to both alpha and
* color components using GL_*_SCALE.
*/
- (void)setExtraAlpha:(jfloat)ea;
/**
* Resets all OpenGL compositing state (disables blending and logic
* operations).
*/
- (void)resetComposite;
/**
* Initializes the OpenGL blending state. XOR mode is disabled and the
* appropriate blend functions are setup based on the AlphaComposite rule
* constant.
*/
- (void)setAlphaCompositeRule:(jint)rule extraAlpha:(jfloat)extraAlpha
flags:(jint)flags;
/**
* Returns autorelease string with composite description (for debugging only)
*/
- (NSString*)getCompositeDescription;
/**
* Returns autorelease string with paint description (for debugging only)
*/
- (NSString*)getPaintDescription;
/**
* Initializes the OpenGL logic op state to XOR mode. Blending is disabled
* before enabling logic op mode. The XOR pixel value will be applied
* later in the MTLContext_SetColor() method.
*/
- (void)setXorComposite:(jint)xorPixel;
- (jboolean)isBlendingDisabled:(jboolean) isSrcOpaque;
- (jboolean)useXORComposite;
/**
* Resets the OpenGL transform state back to the identity matrix.
*/
- (void)resetTransform;
/**
* Initializes the OpenGL transform state by setting the modelview transform
* using the given matrix parameters.
*
* REMIND: it may be worthwhile to add serial id to AffineTransform, so we
* could do a quick check to see if the xform has changed since
* last time... a simple object compare won't suffice...
*/
- (void)setTransformM00:(jdouble) m00 M10:(jdouble) m10
M01:(jdouble) m01 M11:(jdouble) m11
M02:(jdouble) m02 M12:(jdouble) m12;
/**
* Initializes a small texture tile for use with tiled blit operations (see
* MTLBlitLoops.c and MTLMaskBlit.c for usage examples). The texture ID for
* the tile is stored in the given MTLContext. The tile is initially filled
* with garbage values, but the tile is updated as needed (via
* glTexSubImage2D()) with real RGBA values used in tiled blit situations.
* The internal format for the texture is GL_RGBA8, which should be sufficient
* for storing system memory surfaces of any known format (see PixelFormats
* for a list of compatible surface formats).
*/
- (jboolean)initBlitTileTexture;
/**
* Creates a 2D texture of the given format and dimensions and returns the
* texture object identifier. This method is typically used to create a
* temporary texture for intermediate work, such as in the
* MTLContext_InitBlitTileTexture() method below.
*/
- (jint)createBlitTextureFormat:(jint)internalFormat pixelFormat:(jint)pixelFormat
width:(jint)width height:(jint)height;
- (void)destroyContextResources;
- (void)resetPaint;
- (void)setColorPaint:(int)pixel;
- (void)setGradientPaintUseMask:(jboolean)useMask
cyclic:(jboolean)cyclic
p0:(jdouble)p0
p1:(jdouble)p1
p3:(jdouble)p3
pixel1:(jint)pixel1
pixel2:(jint) pixel2;
- (void)setLinearGradientPaint:(jboolean)useMask
linear:(jboolean)linear
cycleMethod:(jboolean)cycleMethod
numStops:(jint)numStops
p0:(jfloat)p0
p1:(jfloat)p1
p3:(jfloat)p3
fractions:(void *)fractions
pixels:(void *)pixels;
- (void)setRadialGradientPaint:(jboolean)useMask
linear:(jboolean)linear
cycleMethod:(jboolean)cycleMethod
numStops:(jint)numStops
m00:(jfloat)m00
m01:(jfloat)m01
m02:(jfloat)m02
m10:(jfloat)m10
m11:(jfloat)m11
m12:(jfloat)m12
focusX:(jfloat)focusX
fractions:(void *)fractions
pixels:(void *)pixels;
- (void)setTexturePaint:(jboolean)useMask
pSrcOps:(jlong)pSrcOps
filter:(jboolean)filter
xp0:(jdouble)xp0
xp1:(jdouble)xp1
xp3:(jdouble)xp3
yp0:(jdouble)yp0
yp1:(jdouble)yp1
yp3:(jdouble)yp3;
// Sets current image conversion operation (instance of MTLConvolveOp, MTLRescaleOp, MTLLookupOp).
// Used only in MTLIsoBlit (to blit image with some conversion). Pattern of usage: enableOp -> IsoBlit -> disableOp.
// TODO: Need to remove it from MTLContext and pass it as an argument for IsoBlit (because it's more
// simple and clear)
-(void)setBufImgOp:(NSObject*)bufImgOp;
-(NSObject*)getBufImgOp;
- (id<MTLCommandBuffer>)createCommandBuffer;
- (id<MTLCommandBuffer>)createBlitCommandBuffer;
@end
/**
* See BufferedContext.java for more on these flags...
*/
#define MTLC_NO_CONTEXT_FLAGS \
sun_java2d_pipe_BufferedContext_NO_CONTEXT_FLAGS
#define MTLC_SRC_IS_OPAQUE \
sun_java2d_pipe_BufferedContext_SRC_IS_OPAQUE
#define MTLC_USE_MASK \
sun_java2d_pipe_BufferedContext_USE_MASK
#endif /* MTLContext_h_Included */