xref: /aosp_15_r20/external/skia/include/gpu/graphite/mtl/MtlGraphiteTypes.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2021 Google LLC
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 skgpu_graphite_MtlGraphiteTypes_DEFINED
9 #define skgpu_graphite_MtlGraphiteTypes_DEFINED
10 
11 #include "include/core/SkTypes.h"
12 
13 #if __OBJC__  // <Metal/Metal.h> only works when compiled for Objective C
14 #include "include/gpu/graphite/BackendTexture.h"
15 #include "include/gpu/graphite/GraphiteTypes.h"
16 #include "include/gpu/graphite/TextureInfo.h"
17 #include "include/ports/SkCFObject.h"
18 #include "include/private/base/SkAPI.h"
19 
20 #import <CoreFoundation/CoreFoundation.h>
21 #import <Metal/Metal.h>
22 #import <TargetConditionals.h>
23 
24 #if TARGET_OS_SIMULATOR
25 #define SK_API_AVAILABLE_CA_METAL_LAYER SK_API_AVAILABLE(macos(10.11), ios(13.0), tvos(13.0))
26 #else  // TARGET_OS_SIMULATOR
27 #define SK_API_AVAILABLE_CA_METAL_LAYER SK_API_AVAILABLE(macos(10.11), ios(8.0), tvos(9.0))
28 #endif  // TARGET_OS_SIMULATOR
29 
30 namespace skgpu::graphite {
31 
32 struct SK_API MtlTextureInfo {
33     uint32_t fSampleCount = 1;
34     skgpu::Mipmapped fMipmapped = skgpu::Mipmapped::kNo;
35 
36     MTLPixelFormat fFormat = MTLPixelFormatInvalid;
37     MTLTextureUsage fUsage = MTLTextureUsageUnknown;
38     MTLStorageMode fStorageMode = MTLStorageModeShared;
39     bool fFramebufferOnly = false;
40 
41     MtlTextureInfo() = default;
42     MtlTextureInfo(CFTypeRef mtlTexture);
MtlTextureInfoMtlTextureInfo43     MtlTextureInfo(uint32_t sampleCount,
44                    skgpu::Mipmapped mipmapped,
45                    MTLPixelFormat format,
46                    MTLTextureUsage usage,
47                    MTLStorageMode storageMode,
48                    bool framebufferOnly)
49             : fSampleCount(sampleCount)
50             , fMipmapped(mipmapped)
51             , fFormat(format)
52             , fUsage(usage)
53             , fStorageMode(storageMode)
54             , fFramebufferOnly(framebufferOnly) {}
55 };
56 
57 namespace TextureInfos {
58 SK_API TextureInfo MakeMetal(const MtlTextureInfo&);
59 SK_API TextureInfo MakeMetal(CFTypeRef mtlTexture);
60 
61 SK_API bool GetMtlTextureInfo(const TextureInfo&, MtlTextureInfo*);
62 }  // namespace TextureInfos
63 
64 namespace BackendTextures {
65 // The BackendTexture will not call retain or release on the passed in CFTypeRef. Thus the
66 // client must keep the CFTypeRef valid until they are no longer using the BackendTexture.
67 SK_API BackendTexture MakeMetal(SkISize dimensions, CFTypeRef mtlTexture);
68 
69 SK_API CFTypeRef GetMtlTexture(const BackendTexture&);
70 }  // namespace BackendTextures
71 
72 namespace BackendSemaphores {
73 // TODO(b/286088355) Determine creator's responsibility for setting refcnt.
74 SK_API BackendSemaphore MakeMetal(CFTypeRef mtlEvent, uint64_t value);
75 
76 SK_API CFTypeRef GetMtlEvent(const BackendSemaphore&);
77 SK_API uint64_t GetMtlValue(const BackendSemaphore&);
78 }  // namespace BackendSemaphores
79 
80 } // namespace skgpu::graphite
81 
82 #endif  // __OBJC__
83 
84 #endif // skgpu_graphite_MtlGraphiteTypes_DEFINED
85