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 isAA:(jboolean)isAA; 51 52 // Base method to obtain any MTLRenderCommandEncoder 53 - (id<MTLRenderCommandEncoder> _Nonnull) 54 getEncoder:(id<MTLTexture> _Nonnull)dest 55 isOpaque:(jboolean)isOpaque 56 isTexture:(jboolean)isTexture 57 isAA:(jboolean)isAA 58 srcFlags:(const SurfaceRasterFlags *_Nullable)srcFlags; 59 60 - (id<MTLBlitCommandEncoder> _Nonnull)createBlitEncoder; 61 62 - (void)endEncoder; 63 @end 64 65 #endif // EncoderManager_h_Included