Flutter Engine
The Flutter Engine
TextureInfo.h
Go to the documentation of this file.
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_TextureInfo_DEFINED
9#define skgpu_graphite_TextureInfo_DEFINED
10
14
15#ifdef SK_DAWN
17#endif
18
19#ifdef SK_METAL
21#endif
22
23#ifdef SK_VULKAN
25#endif
26
27struct SkISize;
28
29namespace skgpu::graphite {
30
32public:
34#ifdef SK_DAWN
35 TextureInfo(const DawnTextureInfo& dawnInfo)
36 : fBackend(BackendApi::kDawn)
37 , fValid(true)
38 , fSampleCount(dawnInfo.fSampleCount)
39 , fMipmapped(dawnInfo.fMipmapped)
40 , fProtected(Protected::kNo)
41 , fDawnSpec(dawnInfo) {}
42#endif
43
44#ifdef SK_METAL
45 TextureInfo(const MtlTextureInfo& mtlInfo)
46 : fBackend(BackendApi::kMetal)
47 , fValid(true)
48 , fSampleCount(mtlInfo.fSampleCount)
49 , fMipmapped(mtlInfo.fMipmapped)
50 , fProtected(Protected::kNo)
51 , fMtlSpec(mtlInfo) {}
52#endif
53
54#ifdef SK_VULKAN
55 TextureInfo(const VulkanTextureInfo& vkInfo)
56 : fBackend(BackendApi::kVulkan)
57 , fValid(true)
58 , fSampleCount(vkInfo.fSampleCount)
59 , fMipmapped(vkInfo.fMipmapped)
60 , fProtected(Protected::kNo)
61 , fVkSpec(vkInfo) {
62 if (vkInfo.fFlags & VK_IMAGE_CREATE_PROTECTED_BIT) {
63 fProtected = Protected::kYes;
64 }
65 }
66#endif
67
69 TextureInfo(const TextureInfo&) = default;
70 TextureInfo& operator=(const TextureInfo&);
71
72 bool operator==(const TextureInfo&) const;
73 bool operator!=(const TextureInfo& that) const { return !(*this == that); }
74
75 bool isValid() const { return fValid; }
76 BackendApi backend() const { return fBackend; }
77
78 uint32_t numSamples() const { return fSampleCount; }
79 Mipmapped mipmapped() const { return fMipmapped; }
80 Protected isProtected() const { return fProtected; }
81 SkTextureCompressionType compressionType() const;
82
83#ifdef SK_DAWN
84 bool getDawnTextureInfo(DawnTextureInfo* info) const;
85#endif
86
87#ifdef SK_METAL
88 bool getMtlTextureInfo(MtlTextureInfo* info) const {
89 if (!this->isValid() || fBackend != BackendApi::kMetal) {
90 return false;
91 }
92 *info = MtlTextureSpecToTextureInfo(fMtlSpec, fSampleCount, fMipmapped);
93 return true;
94 }
95#endif
96
97#ifdef SK_VULKAN
98 bool getVulkanTextureInfo(VulkanTextureInfo* info) const {
99 if (!this->isValid() || fBackend != BackendApi::kVulkan) {
100 return false;
101 }
102 *info = VulkanTextureSpecToTextureInfo(fVkSpec, fSampleCount, fMipmapped);
103 return true;
104 }
105#endif
106
107 bool isCompatible(const TextureInfo& that) const;
108 // Return a string containing the full description of this TextureInfo.
109 SkString toString() const;
110 // Return a string containing only the info relevant for its use as a RenderPass attachment.
111 SkString toRPAttachmentString() const;
112
113private:
114 friend size_t ComputeSize(SkISize dimensions, const TextureInfo&); // for bytesPerPixel
115
116 size_t bytesPerPixel() const;
117
118#ifdef SK_DAWN
119 friend class DawnCaps;
120 friend class DawnCommandBuffer;
121 friend class DawnComputePipeline;
122 friend class DawnGraphicsPipeline;
123 friend class DawnResourceProvider;
124 friend class DawnTexture;
125 const DawnTextureSpec& dawnTextureSpec() const {
126 SkASSERT(fValid && fBackend == BackendApi::kDawn);
127 return fDawnSpec;
128 }
129#endif
130
131#ifdef SK_METAL
132 friend class MtlCaps;
133 friend class MtlGraphicsPipeline;
134 friend class MtlTexture;
135 const MtlTextureSpec& mtlTextureSpec() const {
136 SkASSERT(fValid && fBackend == BackendApi::kMetal);
137 return fMtlSpec;
138 }
139#endif
140
141#ifdef SK_VULKAN
142 friend class VulkanCaps;
143 friend class VulkanResourceProvider;
144 friend class VulkanTexture;
145 // For querying texture for YCbCr information when generating a PaintParamsKey
146 friend class PaintParamsKey;
147
148 const VulkanTextureSpec& vulkanTextureSpec() const {
149 SkASSERT(fValid && fBackend == BackendApi::kVulkan);
150 return fVkSpec;
151 }
152#endif
153
154 BackendApi fBackend = BackendApi::kMock;
155 bool fValid = false;
156
157 uint32_t fSampleCount = 1;
158 Mipmapped fMipmapped = Mipmapped::kNo;
159 Protected fProtected = Protected::kNo;
160
161 union {
162#ifdef SK_DAWN
163 DawnTextureSpec fDawnSpec;
164#endif
165#ifdef SK_METAL
166 MtlTextureSpec fMtlSpec;
167#endif
168#ifdef SK_VULKAN
169 VulkanTextureSpec fVkSpec;
170#endif
172 };
173};
174
175} // namespace skgpu::graphite
176
177#endif //skgpu_graphite_TextureInfo_DEFINED
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
#define SK_API
Definition: SkAPI.h:35
#define SkASSERT(cond)
Definition: SkAssert.h:116
@ kNo
Don't pre-clip the geometry before applying the (perspective) matrix.
SkTextureCompressionType
Mipmapped mipmapped() const
Definition: TextureInfo.h:79
TextureInfo(const TextureInfo &)=default
bool operator!=(const TextureInfo &that) const
Definition: TextureInfo.h:73
uint32_t numSamples() const
Definition: TextureInfo.h:78
BackendApi backend() const
Definition: TextureInfo.h:76
Protected isProtected() const
Definition: TextureInfo.h:80
@ kVulkan
Definition: embedder.h:86
@ kMetal
Definition: embedder.h:85
bool operator==(C p1, const scoped_nsprotocol< C > &p2)
VulkanTextureInfo VulkanTextureSpecToTextureInfo(const VulkanTextureSpec &vkSpec, uint32_t sampleCount, Mipmapped mipmapped)
size_t ComputeSize(SkISize dimensions, const TextureInfo &info)
MtlTextureInfo MtlTextureSpecToTextureInfo(const MtlTextureSpec &mtlSpec, uint32_t sampleCount, Mipmapped mipmapped)
BackendApi
Definition: GpuTypes.h:22
Mipmapped
Definition: GpuTypes.h:53
Protected
Definition: GpuTypes.h:61
Definition: SkSize.h:16
@ VK_IMAGE_CREATE_PROTECTED_BIT
Definition: vulkan_core.h:2320