• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 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 skgpu_graphite_MtlGraphiteTypesPriv_DEFINED
9 #define skgpu_graphite_MtlGraphiteTypesPriv_DEFINED
10 
11 #include "include/core/SkString.h"
12 #include "include/gpu/graphite/GraphiteTypes.h"
13 #include "include/gpu/graphite/mtl/MtlGraphiteTypes.h"
14 
15 ///////////////////////////////////////////////////////////////////////////////
16 
17 #ifdef __APPLE__
18 
19 #include <TargetConditionals.h>
20 
21 // We're using the MSL version as shorthand for the Metal SDK version here
22 #if defined(SK_BUILD_FOR_MAC)
23 #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 130000
24 #define SKGPU_GRAPHITE_METAL_SDK_VERSION 300
25 #elif __MAC_OS_X_VERSION_MAX_ALLOWED >= 120000
26 #define SKGPU_GRAPHITE_METAL_SDK_VERSION 240
27 #elif __MAC_OS_X_VERSION_MAX_ALLOWED >= 110000
28 #define SKGPU_GRAPHITE_METAL_SDK_VERSION 230
29 #else
30 #error Must use at least 11.00 SDK to build Metal backend for MacOS
31 #endif
32 #else
33 #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 160000 || __TV_OS_VERSION_MAX_ALLOWED >= 160000
34 #define SKGPU_GRAPHITE_METAL_SDK_VERSION 300
35 #elif __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 || __TV_OS_VERSION_MAX_ALLOWED >= 150000
36 #define SKGPU_GRAPHITE_METAL_SDK_VERSION 240
37 #elif __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000 || __TV_OS_VERSION_MAX_ALLOWED >= 140000
38 #define SKGPU_GRAPHITE_METAL_SDK_VERSION 230
39 #else
40 #error Must use at least 14.00 SDK to build Metal backend for iOS
41 #endif
42 #endif
43 
44 #endif  // __APPLE__
45 
46 namespace skgpu::graphite {
47 
48 struct MtlTextureSpec {
MtlTextureSpecMtlTextureSpec49     MtlTextureSpec()
50             : fFormat(0)
51             , fUsage(0)
52             , fStorageMode(0)
53             , fFramebufferOnly(false) {}
MtlTextureSpecMtlTextureSpec54     MtlTextureSpec(const MtlTextureInfo& info)
55             : fFormat(info.fFormat)
56             , fUsage(info.fUsage)
57             , fStorageMode(info.fStorageMode)
58             , fFramebufferOnly(info.fFramebufferOnly) {}
59 
60     bool operator==(const MtlTextureSpec& that) const {
61         return fFormat == that.fFormat &&
62                fUsage == that.fUsage &&
63                fStorageMode == that.fStorageMode &&
64                fFramebufferOnly == that.fFramebufferOnly;
65     }
66 
isCompatibleMtlTextureSpec67     bool isCompatible(const MtlTextureSpec& that) const {
68         // The usages may match or the usage passed in may be a superset of the usage stored within.
69         return fFormat == that.fFormat &&
70                fStorageMode == that.fStorageMode &&
71                fFramebufferOnly == that.fFramebufferOnly &&
72                (fUsage & that.fUsage) == fUsage;
73     }
74 
toStringMtlTextureSpec75     SkString toString() const {
76         return SkStringPrintf("format=%u,usage=0x%04X,storageMode=%u,framebufferOnly=%d",
77                               fFormat,
78                               fUsage,
79                               fStorageMode,
80                               fFramebufferOnly);
81     }
82 
83     MtlPixelFormat fFormat;
84     MtlTextureUsage fUsage;
85     MtlStorageMode fStorageMode;
86     bool fFramebufferOnly;
87 };
88 
89 MtlTextureInfo MtlTextureSpecToTextureInfo(const MtlTextureSpec& mtlSpec,
90                                            uint32_t sampleCount,
91                                            Mipmapped mipmapped);
92 
93 }  // namespace skgpu::graphite
94 
95 #endif  // skgpu_graphite_MtlGraphiteTypesPriv_DEFINED
96