Flutter Engine
The Flutter Engine
GrMtlBackendSurface.mm
Go to the documentation of this file.
1/*
2 * Copyright 2024 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 */
8
16
17#if !__has_feature(objc_arc)
18#error This file must be compiled with Arc. Use -fobjc-arc flag
19#endif
20
22public:
24
25 GrMTLPixelFormat asMtlFormat() const { return (GrMTLPixelFormat)fFormat; }
26
27private:
28 SkTextureCompressionType compressionType() const override {
29 return GrMtlFormatToCompressionType(fFormat);
30 }
31
32 size_t bytesPerBlock() const override { return skgpu::MtlFormatBytesPerBlock(fFormat); }
33
34 int stencilBits() const override { return GrMtlFormatStencilBits(fFormat); }
35
36 uint32_t channelMask() const override { return skgpu::MtlFormatChannels(fFormat); }
37
38 GrColorFormatDesc desc() const override { return GrMtlFormatDesc(fFormat); }
39
40 bool equal(const GrBackendFormatData* that) const override {
41 SkASSERT(!that || that->type() == GrBackendApi::kMetal);
42 if (auto otherMtl = static_cast<const GrMtlBackendFormatData*>(that)) {
43 return fFormat == otherMtl->fFormat;
44 }
45 return false;
46 }
47
48 std::string toString() const override {
49#if defined(SK_DEBUG) || GR_TEST_UTILS
50 return skgpu::MtlFormatToString(fFormat);
51#else
52 return "";
53#endif
54 }
55
56 void copyTo(AnyFormatData& formatData) const override {
57 formatData.emplace<GrMtlBackendFormatData>(fFormat);
58 }
59
60#if defined(SK_DEBUG)
61 GrBackendApi type() const override { return GrBackendApi::kMetal; }
62#endif
63
64 MTLPixelFormat fFormat;
65};
66
69 SkASSERT(!data || data->type() == GrBackendApi::kMetal);
70 return static_cast<const GrMtlBackendFormatData*>(data);
71}
72
73namespace GrBackendFormats {
74
78}
79
81 if (format.isValid() && format.backend() == GrBackendApi::kMetal) {
84 return data->asMtlFormat();
85 }
86 // MTLPixelFormatInvalid == 0
87 return GrMTLPixelFormat(0);
88}
89
90} // namespace GrBackendFormats
91
93public:
94 GrMtlBackendTextureData(const GrMtlTextureInfo& info) : fTexInfo(info) {}
95
96 const GrMtlTextureInfo& info() const { return fTexInfo; }
97
98private:
99 void copyTo(AnyTextureData& textureData) const override {
100 textureData.emplace<GrMtlBackendTextureData>(fTexInfo);
101 }
102
103 bool isProtected() const override { return false; }
104
105 bool equal(const GrBackendTextureData* that) const override {
106 return this->isSameTexture(that);
107 }
108
109 bool isSameTexture(const GrBackendTextureData* that) const override {
110 SkASSERT(!that || that->type() == GrBackendApi::kMetal);
111 if (auto otherMtl = static_cast<const GrMtlBackendTextureData*>(that)) {
112 return fTexInfo == otherMtl->fTexInfo;
113 }
114 return false;
115 }
116
117 GrBackendFormat getBackendFormat() const override {
119 }
120
121#if defined(SK_DEBUG)
122 GrBackendApi type() const override { return GrBackendApi::kMetal; }
123#endif
124
125 GrMtlTextureInfo fTexInfo;
126};
127
130 SkASSERT(!data || data->type() == GrBackendApi::kMetal);
131 return static_cast<const GrMtlBackendTextureData*>(data);
132}
133
134namespace GrBackendTextures {
135
137 int height,
138 skgpu::Mipmapped mipmapped,
139 const GrMtlTextureInfo& mtlInfo,
140 std::string_view label) {
142 height,
143 label,
144 mipmapped,
147 GrMtlBackendTextureData(mtlInfo));
148}
149
150bool GetMtlTextureInfo(const GrBackendTexture& tex, GrMtlTextureInfo* outInfo) {
151 if (!tex.isValid() || tex.backend() != GrBackendApi::kMetal) {
152 return false;
153 }
155 SkASSERT(data);
156 *outInfo = data->info();
157 return true;
158}
159
160} // namespace GrBackendTextures
161
163public:
164 GrMtlBackendRenderTargetData(const GrMtlTextureInfo& info) : fTexInfo(info) {}
165
166 const GrMtlTextureInfo& info() const { return fTexInfo; }
167
168private:
169 GrBackendFormat getBackendFormat() const override {
171 }
172
173 bool isProtected() const override { return false; }
174
175 bool equal(const GrBackendRenderTargetData* that) const override {
176 SkASSERT(!that || that->type() == GrBackendApi::kMetal);
177 if (auto otherMtl = static_cast<const GrMtlBackendRenderTargetData*>(that)) {
178 return fTexInfo == otherMtl->fTexInfo;
179 }
180 return false;
181 }
182
183 void copyTo(AnyRenderTargetData& rtData) const override {
184 rtData.emplace<GrMtlBackendRenderTargetData>(fTexInfo);
185 }
186
187#if defined(SK_DEBUG)
188 GrBackendApi type() const override { return GrBackendApi::kMetal; }
189#endif
190
191 GrMtlTextureInfo fTexInfo;
192};
193
196 SkASSERT(!data || data->type() == GrBackendApi::kMetal);
197 return static_cast<const GrMtlBackendRenderTargetData*>(data);
198}
199
200namespace GrBackendRenderTargets {
201
202GrBackendRenderTarget MakeMtl(int width, int height, const GrMtlTextureInfo& mtlInfo) {
204 width,
205 height,
207 /*stencilBits=*/0,
209 /*framebufferOnly=*/false, // TODO: set this from mtlInfo.fTexture->framebufferOnly
211}
212
213bool GetMtlTextureInfo(const GrBackendRenderTarget& rt, GrMtlTextureInfo* outInfo) {
214 if (!rt.isValid() || rt.backend() != GrBackendApi::kMetal) {
215 return false;
216 }
218 SkASSERT(data);
219 *outInfo = data->info();
220 return true;
221}
222
223} // namespace GrBackendRenderTargets
static const GrMtlBackendFormatData * get_and_cast_data(const GrBackendFormat &format)
GrMTLPixelFormat GrGetMTLPixelFormatFromMtlTextureInfo(const GrMtlTextureInfo &)
Definition: GrMtlUtil.mm:228
int GrMtlTextureInfoSampleCount(const GrMtlTextureInfo &)
Definition: GrMtlUtil.mm:294
unsigned int GrMTLPixelFormat
Definition: GrMtlTypes.h:17
GrColorFormatDesc GrMtlFormatDesc(MTLPixelFormat)
Definition: GrMtlUtil.mm:233
int GrMtlFormatStencilBits(MTLPixelFormat)
Definition: GrMtlUtil.mm:302
SkTextureCompressionType GrMtlFormatToCompressionType(MTLPixelFormat)
Definition: GrMtlUtil.mm:282
GrBackendApi
Definition: GrTypes.h:95
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkTextureCompressionType
GLenum type
GrBackendFormat::AnyFormatData AnyFormatData
GrBackendRenderTarget::AnyRenderTargetData AnyRenderTargetData
GrBackendApi backend() const
static GrBackendRenderTarget MakeGrBackendRenderTarget(int width, int height, int sampleCnt, int stencilBits, GrBackendApi backend, bool framebufferOnly, const RenderTargetData &data)
static GrBackendTexture MakeGrBackendTexture(int width, int height, std::string_view label, skgpu::Mipmapped mipped, GrBackendApi backend, GrTextureType texture, const TextureData &data)
static GrBackendFormat MakeGrBackendFormat(GrTextureType textureType, GrBackendApi api, const FormatData &data)
static const GrBackendFormatData * GetBackendData(const GrBackendFormat &format)
GrBackendTexture::AnyTextureData AnyTextureData
bool isValid() const
GrBackendApi backend() const
GrMTLPixelFormat asMtlFormat() const
GrMtlBackendFormatData(GrMTLPixelFormat format)
GrMtlBackendRenderTargetData(const GrMtlTextureInfo &info)
const GrMtlTextureInfo & info() const
GrMtlBackendTextureData(const GrMtlTextureInfo &info)
const GrMtlTextureInfo & info() const
uint32_t uint32_t * format
static float max(float r, float g, float b)
Definition: hsl.cpp:49
FlTexture * texture
SK_API GrBackendFormat MakeMtl(GrMTLPixelFormat format)
SK_API GrMTLPixelFormat AsMtlFormat(const GrBackendFormat &)
SK_API bool GetMtlTextureInfo(const GrBackendRenderTarget &, GrMtlTextureInfo *)
SK_API GrBackendRenderTarget MakeMtl(int width, int height, const GrMtlTextureInfo &mtlInfo)
SK_API GrBackendTexture MakeMtl(int width, int height, skgpu::Mipmapped, const GrMtlTextureInfo &mtlInfo, std::string_view label={})
SK_API bool GetMtlTextureInfo(const GrBackendTexture &, GrMtlTextureInfo *)
uint32_t MtlFormatChannels(MTLPixelFormat mtlFormat)
Definition: MtlUtils.mm:102
const char * MtlFormatToString(MTLPixelFormat mtlFormat)
Definition: MtlUtils.mm:73
Mipmapped
Definition: GpuTypes.h:53
size_t MtlFormatBytesPerBlock(MTLPixelFormat mtlFormat)
Definition: MtlUtils.mm:130
int32_t height
int32_t width
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63