Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
TextureInfo.cpp
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
9
10#ifdef SK_DAWN
12#endif
13
14#ifdef SK_METAL
15namespace skgpu::graphite {
16 // Including Metal types/headers here is tricky. This is defined in MtlGraphiteUtils.mm
19}
20#endif
21
22#ifdef SK_VULKAN
24#endif
25
26namespace skgpu::graphite {
27
29 if (!that.isValid()) {
30 fValid = false;
31 return *this;
32 }
33 fBackend = that.fBackend;
34 fSampleCount = that.fSampleCount;
35 fMipmapped = that.fMipmapped;
36 fProtected = that.fProtected;
37
38 switch (that.backend()) {
39#ifdef SK_DAWN
41 fDawnSpec = that.fDawnSpec;
42 break;
43#endif
44#ifdef SK_METAL
46 fMtlSpec = that.fMtlSpec;
47 break;
48#endif
49#ifdef SK_VULKAN
51 fVkSpec = that.fVkSpec;
52 break;
53#endif
54 default:
55 SK_ABORT("Unsupport Backend");
56 }
57
58 fValid = true;
59 return *this;
60}
61
62bool TextureInfo::operator==(const TextureInfo& that) const {
63 if (!this->isValid() && !that.isValid()) {
64 return true;
65 }
66 if (!this->isValid() || !that.isValid()) {
67 return false;
68 }
69
70 if (fBackend != that.fBackend) {
71 return false;
72 }
73
74 if (fSampleCount != that.fSampleCount ||
75 fMipmapped != that.fMipmapped ||
76 fProtected != that.fProtected) {
77 return false;
78 }
79
80 switch (fBackend) {
81#ifdef SK_DAWN
83 return fDawnSpec == that.fDawnSpec;
84#endif
85#ifdef SK_METAL
87 return fMtlSpec == that.fMtlSpec;
88#endif
89#ifdef SK_VULKAN
91 return fVkSpec == that.fVkSpec;
92#endif
93 default:
94 return false;
95 }
96}
97
98bool TextureInfo::isCompatible(const TextureInfo& that) const {
99 if (!this->isValid() || !that.isValid()) {
100 return false;
101 }
102
103 if (fSampleCount != that.fSampleCount ||
104 fMipmapped != that.fMipmapped ||
105 fProtected != that.fProtected) {
106 return false;
107 }
108
109 if (fBackend != that.fBackend) {
110 return false;
111 }
112
113 switch (fBackend) {
114#ifdef SK_DAWN
116 return fDawnSpec.isCompatible(that.fDawnSpec);
117#endif
118#ifdef SK_METAL
120 return fMtlSpec.isCompatible(that.fMtlSpec);
121#endif
122#ifdef SK_VULKAN
124 return fVkSpec.isCompatible(that.fVkSpec);
125#endif
126 default:
127 return false;
128 }
129}
130
131#ifdef SK_DAWN
132bool TextureInfo::getDawnTextureInfo(DawnTextureInfo* info) const {
133 if (!this->isValid() || fBackend != BackendApi::kDawn) {
134 return false;
135 }
136 *info = DawnTextureSpecToTextureInfo(fDawnSpec, fSampleCount, fMipmapped);
137 return true;
138}
139#endif
140
142 SkString ret;
143 switch (fBackend) {
144#ifdef SK_DAWN
146 ret.appendf("Dawn(%s,", fDawnSpec.toString().c_str());
147 break;
148#endif
149#ifdef SK_METAL
151 ret.appendf("Metal(%s,", fMtlSpec.toString().c_str());
152 break;
153#endif
154#ifdef SK_VULKAN
156 ret.appendf("Vulkan(%s,", fVkSpec.toString().c_str());
157 break;
158#endif
160 ret += "Mock(";
161 break;
162 default:
163 ret += "Invalid(";
164 break;
165 }
166 ret.appendf("bytesPerPixel=%zu,sampleCount=%u,mipmapped=%d,protected=%d)",
167 bytesPerPixel(),
168 fSampleCount,
169 static_cast<int>(fMipmapped),
170 static_cast<int>(fProtected));
171 return ret;
172}
173
174size_t TextureInfo::bytesPerPixel() const {
175 if (!this->isValid()) {
176 return 0;
177 }
178
179 switch (fBackend) {
180#ifdef SK_DAWN
182 return DawnFormatBytesPerBlock(this->dawnTextureSpec().getViewFormat());
183#endif
184#ifdef SK_METAL
186 return MtlFormatBytesPerBlock(this->mtlTextureSpec().fFormat);
187#endif
188#ifdef SK_VULKAN
190 return VkFormatBytesPerBlock(this->vulkanTextureSpec().fFormat);
191#endif
192 default:
193 return 0;
194 }
195}
196
198 if (!this->isValid()) {
200 }
201
202 switch (fBackend) {
203#ifdef SK_DAWN
205 return DawnFormatToCompressionType(this->dawnTextureSpec().getViewFormat());
206#endif
207#ifdef SK_METAL
209 return MtlFormatToCompressionType(this->mtlTextureSpec().fFormat);
210#endif
211#ifdef SK_VULKAN
213 return VkFormatToCompressionType(this->vulkanTextureSpec().fFormat);
214#endif
215 default:
217 }
218}
219
220} // namespace skgpu::graphite
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
#define SK_ABORT(message,...)
Definition SkAssert.h:70
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:550
SkTextureCompressionType compressionType() const
TextureInfo & operator=(const TextureInfo &)
bool isCompatible(const TextureInfo &that) const
BackendApi backend() const
Definition TextureInfo.h:76
bool operator==(const TextureInfo &) const
unsigned int MtlPixelFormat
SkTextureCompressionType DawnFormatToCompressionType(wgpu::TextureFormat format)
Definition DawnUtils.cpp:49
DawnTextureInfo DawnTextureSpecToTextureInfo(const DawnTextureSpec &dawnSpec, uint32_t sampleCount, Mipmapped mipmapped)
size_t MtlFormatBytesPerBlock(MtlPixelFormat format)
size_t DawnFormatBytesPerBlock(wgpu::TextureFormat format)
Definition DawnUtils.cpp:21
SkTextureCompressionType MtlFormatToCompressionType(MtlPixelFormat format)
static constexpr size_t VkFormatBytesPerBlock(VkFormat vkFormat)
static constexpr SkTextureCompressionType VkFormatToCompressionType(VkFormat vkFormat)