1 /* 2 * Copyright 2017 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef GrMtlUtil_DEFINED 9 #define GrMtlUtil_DEFINED 10 11 #import <Metal/Metal.h> 12 13 #include "GrTypesPriv.h" 14 #include "ir/SkSLProgram.h" 15 16 class GrMtlGpu; 17 class GrSurface; 18 19 /** 20 * Returns the Metal texture format for the given GrPixelConfig 21 */ 22 bool GrPixelConfigToMTLFormat(GrPixelConfig config, MTLPixelFormat* format); 23 24 /** 25 * Returns the GrPixelConfig for the given Metal texture format 26 */ 27 GrPixelConfig GrMTLFormatToPixelConfig(MTLPixelFormat format); 28 29 /** 30 * Returns a id<MTLTexture> to the MTLTexture pointed at by the const void*. Will use 31 * __bridge_transfer if we are adopting ownership. 32 */ 33 id<MTLTexture> GrGetMTLTexture(const void* mtlTexture, GrWrapOwnership); 34 35 /** 36 * Returns a const void* to whatever the id object is pointing to. Always uses __bridge. 37 */ 38 const void* GrGetPtrFromId(id idObject); 39 40 /** 41 * Returns a const void* to whatever the id object is pointing to. Always uses __bridge_retained. 42 */ 43 const void* GrReleaseId(id idObject); 44 45 /** 46 * Returns a MTLTextureDescriptor which describes the MTLTexture. Useful when creating a duplicate 47 * MTLTexture without the same storage allocation. 48 */ 49 MTLTextureDescriptor* GrGetMTLTextureDescriptor(id<MTLTexture> mtlTexture); 50 51 /** 52 * Returns a compiled MTLLibrary created from MSL code generated by SkSLC 53 */ 54 id<MTLLibrary> GrCompileMtlShaderLibrary(const GrMtlGpu* gpu, 55 const char* shaderString, 56 SkSL::Program::Kind kind, 57 const SkSL::Program::Settings& settings, 58 SkSL::Program::Inputs* outInputs); 59 60 /** 61 * Returns a MTLTexture corresponding to the GrSurface. Optionally can do a resolve. 62 */ 63 id<MTLTexture> GrGetMTLTextureFromSurface(GrSurface* surface, bool doResolve); 64 65 #endif 66