Flutter Engine
The Flutter Engine
GrGLBackendSurface.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 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
12#include "include/gpu/GrTypes.h"
22
23#include <algorithm>
24#include <cstddef>
25#include <cstdint>
26#include <string>
27
29public:
31
32 GrGLenum asEnum() const { return fGLFormat; }
33
34private:
35 SkTextureCompressionType compressionType() const override {
36 switch (GrGLFormatFromGLEnum(fGLFormat)) {
44 default:
46 }
47 }
48
49 size_t bytesPerBlock() const override {
51 }
52
53 int stencilBits() const override {
55 }
56
57 uint32_t channelMask() const override {
59 }
60
61 GrColorFormatDesc desc() const override {
62 return GrGLFormatDesc(GrGLFormatFromGLEnum(fGLFormat));
63 }
64
65 bool equal(const GrBackendFormatData* that) const override {
66 SkASSERT(!that || that->type() == GrBackendApi::kOpenGL);
67 if (auto otherGL = static_cast<const GrGLBackendFormatData*>(that)) {
68 return fGLFormat == otherGL->fGLFormat;
69 }
70 return false;
71 }
72
73 std::string toString() const override {
74#if defined(SK_DEBUG) || defined(GR_TEST_UTILS)
75 return GrGLFormatToStr(fGLFormat);
76#else
77 return "";
78#endif
79 }
80
81 void copyTo(AnyFormatData& formatData) const override {
82 formatData.emplace<GrGLBackendFormatData>(fGLFormat);
83 }
84
85#if defined(SK_DEBUG)
86 GrBackendApi type() const override { return GrBackendApi::kOpenGL; }
87#endif
88
89 GrGLenum fGLFormat; // the sized, internal format of the GL resource
90};
91
93 switch (target) {
97 return GrTextureType::k2D;
102 default:
104 }
105}
106
109 SkASSERT(!data || data->type() == GrBackendApi::kOpenGL);
110 return static_cast<const GrGLBackendFormatData*>(data);
111}
112
113namespace GrBackendFormats {
117}
118
120 if (format.isValid() && format.backend() == GrBackendApi::kOpenGL) {
122 SkASSERT(data);
123 return GrGLFormatFromGLEnum(data->asEnum());
124 }
126}
127
129 if (format.isValid() && format.backend() == GrBackendApi::kOpenGL) {
131 SkASSERT(data);
132 return data->asEnum();
133 }
134 return 0;
135}
136} // namespace GrBackendFormats
137
140 : fGLInfo(info, params) {}
141
142void GrGLBackendTextureData::copyTo(AnyTextureData& textureData) const {
143 textureData.emplace<GrGLBackendTextureData>(fGLInfo.info(), fGLInfo.refParameters());
144}
145
146bool GrGLBackendTextureData::isProtected() const { return fGLInfo.isProtected(); }
147
148bool GrGLBackendTextureData::equal(const GrBackendTextureData* that) const {
149 SkASSERT(!that || that->type() == GrBackendApi::kOpenGL);
150 if (auto otherGL = static_cast<const GrGLBackendTextureData*>(that)) {
151 return fGLInfo.info() == otherGL->fGLInfo.info();
152 }
153 return false;
154}
155
156bool GrGLBackendTextureData::isSameTexture(const GrBackendTextureData* that) const {
157 SkASSERT(!that || that->type() == GrBackendApi::kOpenGL);
158 if (auto otherGL = static_cast<const GrGLBackendTextureData*>(that)) {
159 return fGLInfo.info().fID == otherGL->fGLInfo.info().fID;
160 }
161 return false;
162}
163
164GrBackendFormat GrGLBackendTextureData::getBackendFormat() const {
165 return GrBackendFormats::MakeGL(fGLInfo.info().fFormat, fGLInfo.info().fTarget);
166}
167
170 SkASSERT(!data || data->type() == GrBackendApi::kOpenGL);
171 return static_cast<const GrGLBackendTextureData*>(data);
172}
173
176 SkASSERT(!data || data->type() == GrBackendApi::kOpenGL);
177 return static_cast<GrGLBackendTextureData*>(data);
178}
179
180namespace GrBackendTextures {
182 int height,
183 skgpu::Mipmapped mipped,
184 const GrGLTextureInfo& glInfo,
185 std::string_view label) {
187 width,
188 height,
189 label,
190 mipped,
193 GrGLBackendTextureData(glInfo, sk_make_sp<GrGLTextureParameters>()));
194 // Make no assumptions about client's texture's parameters.
196 return tex;
197}
198
200 int height,
201 skgpu::Mipmapped mipped,
202 const GrGLTextureInfo& glInfo,
204 std::string_view label) {
206 height,
207 label,
208 mipped,
212}
213
215 if (!tex.isValid() || tex.backend() != GrBackendApi::kOpenGL) {
216 return false;
217 }
219 SkASSERT(data);
220 *outInfo = data->info().info();
221 return true;
222}
223
225 if (tex && tex->isValid() && tex->backend() == GrBackendApi::kOpenGL) {
227 SkASSERT(data);
228 data->info().parameters()->invalidate();
229 }
230}
231} // namespace GrBackendTextures
232
234public:
236
237 GrGLFramebufferInfo info() const { return fGLInfo; }
238
239private:
240 GrBackendFormat getBackendFormat() const override {
242 }
243
244 bool isProtected() const override { return fGLInfo.isProtected(); }
245
246 bool equal(const GrBackendRenderTargetData* that) const override {
247 SkASSERT(!that || that->type() == GrBackendApi::kOpenGL);
248 if (auto otherGL = static_cast<const GrGLBackendRenderTargetData*>(that)) {
249 return fGLInfo == otherGL->fGLInfo;
250 }
251 return false;
252 }
253
254 void copyTo(AnyRenderTargetData& rtData) const override {
255 rtData.emplace<GrGLBackendRenderTargetData>(fGLInfo);
256 }
257
258#if defined(SK_DEBUG)
259 GrBackendApi type() const override { return GrBackendApi::kOpenGL; }
260#endif
261
262 GrGLFramebufferInfo fGLInfo;
263};
264
267 SkASSERT(!data || data->type() == GrBackendApi::kOpenGL);
268 return static_cast<const GrGLBackendRenderTargetData*>(data);
269}
270
271namespace GrBackendRenderTargets {
272// The GrGLTextureInfo must have a valid fFormat. If wrapping in an SkSurface we require the
273// stencil bits to be either 0, 8 or 16.
275 int width, int height, int sampleCnt, int stencilBits, const GrGLFramebufferInfo& glInfo) {
277 height,
278 std::max(1, sampleCnt),
279 stencilBits,
281 /*framebufferOnly=*/false,
283}
284
286 if (!rt.isValid() || rt.backend() != GrBackendApi::kOpenGL) {
287 return false;
288 }
290 SkASSERT(data);
291 *outInfo = data->info();
292 return true;
293}
294
295} // namespace GrBackendRenderTargets
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
static const GrGLBackendFormatData * get_and_cast_data(const GrBackendFormat &format)
static GrTextureType gl_target_to_gr_target(GrGLenum target)
#define GR_GL_TEXTURE_2D
Definition: GrGLDefines.h:152
#define GR_GL_TEXTURE_NONE
Definition: GrGLDefines.h:151
#define GR_GL_TEXTURE_RECTANGLE
Definition: GrGLDefines.h:1056
#define GR_GL_TEXTURE_EXTERNAL
Definition: GrGLDefines.h:1052
GrGLFormat
Definition: GrGLTypes.h:59
@ kCOMPRESSED_ETC1_RGB8
@ kCOMPRESSED_RGB8_BC1
@ kCOMPRESSED_RGB8_ETC2
@ kCOMPRESSED_RGBA8_BC1
unsigned int GrGLenum
Definition: GrGLTypes.h:102
static constexpr size_t GrGLFormatBytesPerBlock(GrGLFormat format)
Definition: GrGLUtil.h:479
static constexpr int GrGLFormatStencilBits(GrGLFormat format)
Definition: GrGLUtil.h:514
static constexpr GrGLFormat GrGLFormatFromGLEnum(GrGLenum glFormat)
Definition: GrGLUtil.h:409
static constexpr GrColorFormatDesc GrGLFormatDesc(GrGLFormat format)
Definition: GrGLUtil.h:75
static constexpr uint32_t GrGLFormatChannels(GrGLFormat format)
Definition: GrGLUtil.h:41
GrTextureType
Definition: GrTypesPriv.h:268
GrBackendApi
Definition: GrTypes.h:95
#define SkUNREACHABLE
Definition: SkAssert.h:135
#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)
bool isValid() const
GrBackendApi backend() const
GrGLBackendFormatData(GrGLenum format)
GrGLBackendRenderTargetData(GrGLFramebufferInfo info)
GrGLFramebufferInfo info() const
GrGLBackendTextureData(const GrGLTextureInfo &info, sk_sp< GrGLTextureParameters > params)
bool isProtected() const
Definition: GrGLTypesPriv.h:85
const GrGLTextureInfo & info() const
Definition: GrGLTypesPriv.h:81
sk_sp< GrGLTextureParameters > refParameters() const
Definition: GrGLTypesPriv.h:83
const EmbeddedViewParams * params
uint32_t uint32_t * format
uint32_t * target
static float max(float r, float g, float b)
Definition: hsl.cpp:49
FlTexture * texture
SK_API GrGLFormat AsGLFormat(const GrBackendFormat &)
SK_API GrGLenum AsGLFormatEnum(const GrBackendFormat &)
SK_API GrBackendFormat MakeGL(GrGLenum format, GrGLenum target)
SK_API GrBackendRenderTarget MakeGL(int width, int height, int sampleCnt, int stencilBits, const GrGLFramebufferInfo &glInfo)
SK_API bool GetGLFramebufferInfo(const GrBackendRenderTarget &, GrGLFramebufferInfo *)
SK_API GrBackendTexture MakeGL(int width, int height, skgpu::Mipmapped, const GrGLTextureInfo &glInfo, std::string_view label={})
SK_API void GLTextureParametersModified(GrBackendTexture *)
SK_API bool GetGLTextureInfo(const GrBackendTexture &, GrGLTextureInfo *)
Mipmapped
Definition: GpuTypes.h:53
int32_t height
int32_t width
bool isProtected() const
Definition: GrGLTypes.h:207
GrGLuint fID
Definition: GrGLTypes.h:182
GrGLenum fFormat
Definition: GrGLTypes.h:183
GrGLenum fTarget
Definition: GrGLTypes.h:181
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63