1 #ifndef EncoderManager_h_Included
 2 #define EncoderManager_h_Included
 3 
 4 #import <Metal/Metal.h>
 5 
 6 #include <jni.h>
 7 #include "MTLSurfaceDataBase.h"
 8 
 9 @class MTLContex;
10 
11 /**
12  * The EncoderManager class used to obtain MTLRenderCommandEncoder (or MTLBlitCommandEncoder) corresponding
13  * to the current state of MTLContext.
14  *
15  * Due to performance issues (creation of MTLRenderCommandEncoder isn't cheap), each getXXXEncoder invocation
16  * updates properties of common (cached) encoder and returns this encoder.
17  *
18  * Base method getEncoder does the following:
19  *  1. Checks whether common encoder must be closed and recreated (some of encoder properties is 'persistent',
20  *  for example destination, stencil, or any other property of MTLRenderPassDescriptor)
21  *  2. Updates 'mutable' properties encoder: pipelineState (with corresponding buffers), clip, transform, e.t.c. To avoid
22  *  unnecessary calls of [encoder setXXX] this manager compares requested state with cached one.
23  * */
24 @interface EncoderManager : NSObject
25 - (id _Nonnull)init;
26 - (void)dealloc;
27 
28 - (void)setContext:(MTLContex * _Nonnull)mtlc;
29 
30 // returns encoder that renders/fills geometry with current paint and composite
31 - (id<MTLRenderCommandEncoder> _Nonnull)getRenderEncoder:(const BMTLSDOps * _Nonnull)dstOps;
32 
33 - (id<MTLRenderCommandEncoder> _Nonnull)getAARenderEncoder:(const BMTLSDOps * _Nonnull)dstOps;
34 
35 - (id<MTLRenderCommandEncoder> _Nonnull)getRenderEncoder:(id<MTLTexture> _Nonnull)dest
36                                              isDstOpaque:(bool)isOpaque;
37 
38 // returns encoder that renders/fills geometry with current composite and with given texture
39 // (user must call [encoder setFragmentTexture] before any rendering)
40 - (id<MTLRenderCommandEncoder> _Nonnull)getTextureEncoder:(const BMTLSDOps * _Nonnull)dstOps
41                                       isSrcOpaque:(bool)isSrcOpaque;
42 
43 - (id<MTLRenderCommandEncoder> _Nonnull) getTextureEncoder:(id<MTLTexture> _Nonnull)dest
44                                                isSrcOpaque:(bool)isSrcOpaque
45                                                isDstOpaque:(bool)isDstOpaque;
46 
47 - (id<MTLRenderCommandEncoder> _Nonnull)getTextureEncoder:(id<MTLTexture> _Nonnull)dest
48                                       isSrcOpaque:(bool)isSrcOpaque
49                                       isDstOpaque:(bool)isDstOpaque
50                                     interpolation:(int)interpolation;
51 
52 - (id<MTLRenderCommandEncoder> _Nonnull)getTextureEncoder:(id<MTLTexture> _Nonnull)dest
53                                               isSrcOpaque:(bool)isSrcOpaque
54                                               isDstOpaque:(bool)isDstOpaque
55                                             interpolation:(int)interpolation
56                                                      isAA:(jboolean)isAA;
57 
58 // Base method to obtain any MTLRenderCommandEncoder
59 - (id<MTLRenderCommandEncoder> _Nonnull)
60     getEncoder:(id<MTLTexture> _Nonnull)dest
61       isOpaque:(jboolean)isOpaque
62      isTexture:(jboolean)isTexture
63  interpolation:(int)interpolation
64           isAA:(jboolean)isAA
65       srcFlags:(const SurfaceRasterFlags *_Nullable)srcFlags;
66 
67 - (id<MTLBlitCommandEncoder> _Nonnull)createBlitEncoder;
68 
69 - (void)endEncoder;
70 @end
71 
72 #endif // EncoderManager_h_Included