Greg Daniel | 0576a45 | 2017-07-31 16:32:36 -0400 | [diff] [blame] | 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 | |
Greg Daniel | 0576a45 | 2017-07-31 16:32:36 -0400 | [diff] [blame] | 11 | #import <Metal/Metal.h> |
| 12 | |
Brian Salomon | a6a3df7 | 2018-03-23 16:32:22 -0400 | [diff] [blame] | 13 | #include "GrTypesPriv.h" |
Timothy Liang | e30739a | 2018-07-31 10:51:17 -0400 | [diff] [blame] | 14 | #include "ir/SkSLProgram.h" |
Brian Salomon | a6a3df7 | 2018-03-23 16:32:22 -0400 | [diff] [blame] | 15 | |
Timothy Liang | e30739a | 2018-07-31 10:51:17 -0400 | [diff] [blame] | 16 | class GrMtlGpu; |
| 17 | class GrSurface; |
Brian Salomon | a6a3df7 | 2018-03-23 16:32:22 -0400 | [diff] [blame] | 18 | |
Greg Daniel | 0576a45 | 2017-07-31 16:32:36 -0400 | [diff] [blame] | 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 | |
Timothy Liang | 4e85e80 | 2018-06-28 16:37:18 -0400 | [diff] [blame] | 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 | |
Timothy Liang | e886e80 | 2018-07-02 16:03:28 -0400 | [diff] [blame] | 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 | |
Timothy Liang | ff19c8f | 2018-07-11 13:27:21 -0400 | [diff] [blame] | 40 | /** |
Timothy Liang | 760dbc4 | 2018-07-17 13:28:20 -0400 | [diff] [blame] | 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 | /** |
Timothy Liang | ff19c8f | 2018-07-11 13:27:21 -0400 | [diff] [blame] | 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 | |
Timothy Liang | e30739a | 2018-07-31 10:51:17 -0400 | [diff] [blame] | 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 | |
Greg Daniel | 0576a45 | 2017-07-31 16:32:36 -0400 | [diff] [blame] | 65 | #endif |