Flutter Engine
The Flutter Engine
GrMtlUtil.h
Go to the documentation of this file.
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
19
20class GrMtlGpu;
21class GrSurface;
23namespace SkSL {
24 enum class ProgramKind : int8_t;
25 struct ProgramSettings;
26}
27
28GR_NORETAIN_BEGIN
29
30/**
31 * Returns a id<MTLTexture> to the MTLTexture pointed at by the const void*.
32 *
33 * TODO: Remove this and the other bridging functions? It's better to cast on the calling
34 * side so ARC has more context, and they don't add much value.
35 */
36SK_ALWAYS_INLINE id<MTLTexture> GrGetMTLTexture(const void* mtlTexture) {
37#if __has_feature(objc_arc)
38 return (__bridge id<MTLTexture>)mtlTexture;
39#else
40 return (id<MTLTexture>)mtlTexture;
41#endif
42}
43
44/**
45 * Returns a const void* to whatever the id object is pointing to.
46 */
47SK_ALWAYS_INLINE const void* GrGetPtrFromId(id idObject) {
48#if __has_feature(objc_arc)
49 return (__bridge const void*)idObject;
50#else
51 return (const void*)idObject;
52#endif
53}
54
55/**
56 * Returns a const void* to whatever the id object is pointing to.
57 * Will call CFRetain on the object.
58 */
59SK_ALWAYS_INLINE CF_RETURNS_RETAINED const void* GrRetainPtrFromId(id idObject) {
60 return CFBridgingRetain(idObject);
61}
62
63enum class GrMtlErrorCode {
64 kTimeout = 1,
65};
66
67NSError* GrCreateMtlError(NSString* description, GrMtlErrorCode errorCode);
68
69/**
70 * Returns a MTLTextureDescriptor which describes the MTLTexture. Useful when creating a duplicate
71 * MTLTexture without the same storage allocation.
72 */
73MTLTextureDescriptor* GrGetMTLTextureDescriptor(id<MTLTexture> mtlTexture);
74
75/**
76 * Returns a compiled MTLLibrary created from MSL code
77 */
78id<MTLLibrary> GrCompileMtlShaderLibrary(const GrMtlGpu* gpu,
79 const std::string& msl,
81
82/**
83 * Attempts to compile an MSL shader asynchronously. We are not concerned about the result, which
84 * will be cached in the Apple shader cache.
85 */
87 const std::string& msl);
88
89/**
90 * Replacement for newLibraryWithSource:options:error that has a timeout.
91 */
92id<MTLLibrary> GrMtlNewLibraryWithSource(id<MTLDevice>, NSString* mslCode,
93 MTLCompileOptions*, NSError**);
94
95/**
96 * Replacement for newRenderPipelineStateWithDescriptor:error that has a timeout.
97 */
98id<MTLRenderPipelineState> GrMtlNewRenderPipelineStateWithDescriptor(
99 id<MTLDevice>, MTLRenderPipelineDescriptor*, NSError**);
100
101/**
102 * Returns a MTLTexture corresponding to the GrSurface.
103 */
105
106static inline MTLPixelFormat GrBackendFormatAsMTLPixelFormat(const GrBackendFormat& format) {
107 return static_cast<MTLPixelFormat>(GrBackendFormats::AsMtlFormat(format));
108}
109
110/**
111 * Maps a MTLPixelFormat into the CompressionType enum if applicable.
112 */
114
115int GrMtlFormatStencilBits(MTLPixelFormat);
116
117GrColorFormatDesc GrMtlFormatDesc(MTLPixelFormat);
118
119GR_NORETAIN_END
120
121#endif
MTLTextureDescriptor * GrGetMTLTextureDescriptor(id< MTLTexture > mtlTexture)
Definition: GrMtlUtil.mm:36
GrColorFormatDesc GrMtlFormatDesc(MTLPixelFormat)
Definition: GrMtlUtil.mm:233
id< MTLRenderPipelineState > GrMtlNewRenderPipelineStateWithDescriptor(id< MTLDevice >, MTLRenderPipelineDescriptor *, NSError **)
Definition: GrMtlUtil.mm:166
int GrMtlFormatStencilBits(MTLPixelFormat)
Definition: GrMtlUtil.mm:302
void GrPrecompileMtlShaderLibrary(const GrMtlGpu *gpu, const std::string &msl)
Definition: GrMtlUtil.mm:94
GrMtlErrorCode
Definition: GrMtlUtil.h:63
static MTLPixelFormat GrBackendFormatAsMTLPixelFormat(const GrBackendFormat &format)
Definition: GrMtlUtil.h:106
SK_ALWAYS_INLINE CF_RETURNS_RETAINED const void * GrRetainPtrFromId(id idObject)
Definition: GrMtlUtil.h:59
SkTextureCompressionType GrMtlFormatToCompressionType(MTLPixelFormat)
Definition: GrMtlUtil.mm:282
id< MTLLibrary > GrMtlNewLibraryWithSource(id< MTLDevice >, NSString *mslCode, MTLCompileOptions *, NSError **)
Definition: GrMtlUtil.mm:130
NSError * GrCreateMtlError(NSString *description, GrMtlErrorCode errorCode)
Definition: GrMtlUtil.mm:28
SK_ALWAYS_INLINE const void * GrGetPtrFromId(id idObject)
Definition: GrMtlUtil.h:47
id< MTLTexture > GrGetMTLTextureFromSurface(GrSurface *surface)
Definition: GrMtlUtil.mm:201
GR_NORETAIN_BEGIN SK_ALWAYS_INLINE id< MTLTexture > GrGetMTLTexture(const void *mtlTexture)
Definition: GrMtlUtil.h:36
id< MTLLibrary > GrCompileMtlShaderLibrary(const GrMtlGpu *gpu, const std::string &msl, GrContextOptions::ShaderErrorHandler *errorHandler)
Definition: GrMtlUtil.mm:52
#define SK_ALWAYS_INLINE
Definition: SkAttributes.h:30
SkTextureCompressionType
VkSurfaceKHR surface
Definition: main.cc:49
uint32_t uint32_t * format
SK_API GrMTLPixelFormat AsMtlFormat(const GrBackendFormat &)