Home | History | Annotate | Download | only in mtl
      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 a id<MTLTexture> to the MTLTexture pointed at by the const void*. Will use
     26  * __bridge_transfer if we are adopting ownership.
     27  */
     28 id<MTLTexture> GrGetMTLTexture(const void* mtlTexture, GrWrapOwnership);
     29 
     30 /**
     31  * Returns a const void* to whatever the id object is pointing to. Always uses __bridge.
     32  */
     33 const void* GrGetPtrFromId(id idObject);
     34 
     35 /**
     36  * Returns a const void* to whatever the id object is pointing to. Always uses __bridge_retained.
     37  */
     38 const void* GrReleaseId(id idObject);
     39 
     40 /**
     41  * Returns a MTLTextureDescriptor which describes the MTLTexture. Useful when creating a duplicate
     42  * MTLTexture without the same storage allocation.
     43  */
     44 MTLTextureDescriptor* GrGetMTLTextureDescriptor(id<MTLTexture> mtlTexture);
     45 
     46 /**
     47  * Returns a compiled MTLLibrary created from MSL code generated by SkSLC
     48  */
     49 id<MTLLibrary> GrCompileMtlShaderLibrary(const GrMtlGpu* gpu,
     50                                          const char* shaderString,
     51                                          SkSL::Program::Kind kind,
     52                                          const SkSL::Program::Settings& settings,
     53                                          SkSL::Program::Inputs* outInputs);
     54 
     55 /**
     56  * Returns a MTLTexture corresponding to the GrSurface. Optionally can do a resolve.
     57  */
     58 id<MTLTexture> GrGetMTLTextureFromSurface(GrSurface* surface, bool doResolve);
     59 
     60 #endif
     61