Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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"
21
22#include <algorithm>
23#include <cstddef>
24#include <cstdint>
25#include <string>
26
28public:
30
31 GrGLenum asEnum() const { return fGLFormat; }
32
33private:
47
48 size_t bytesPerBlock() const override {
50 }
51
52 int stencilBits() const override {
54 }
55
56 uint32_t channelMask() const override {
58 }
59
60 GrColorFormatDesc desc() const override {
61 return GrGLFormatDesc(GrGLFormatFromGLEnum(fGLFormat));
62 }
63
64 bool equal(const GrBackendFormatData* that) const override {
65 SkASSERT(!that || that->type() == GrBackendApi::kOpenGL);
66 if (auto otherGL = static_cast<const GrGLBackendFormatData*>(that)) {
67 return fGLFormat == otherGL->fGLFormat;
68 }
69 return false;
70 }
71
72 std::string toString() const override {
73#if defined(SK_DEBUG) || defined(GR_TEST_UTILS)
74 return GrGLFormatToStr(fGLFormat);
75#else
76 return "";
77#endif
78 }
79
80 void copyTo(AnyFormatData& formatData) const override {
81 formatData.emplace<GrGLBackendFormatData>(fGLFormat);
82 }
83
84#if defined(SK_DEBUG)
85 GrBackendApi type() const override { return GrBackendApi::kOpenGL; }
86#endif
87
88 GrGLenum fGLFormat; // the sized, internal format of the GL resource
89};
90
105
108 SkASSERT(!data || data->type() == GrBackendApi::kOpenGL);
109 return static_cast<const GrGLBackendFormatData*>(data);
110}
111
112namespace GrBackendFormats {
117
119 if (format.isValid() && format.backend() == GrBackendApi::kOpenGL) {
121 SkASSERT(data);
122 return GrGLFormatFromGLEnum(data->asEnum());
123 }
125}
126
128 if (format.isValid() && format.backend() == GrBackendApi::kOpenGL) {
130 SkASSERT(data);
131 return data->asEnum();
132 }
133 return 0;
134}
135} // namespace GrBackendFormats
136
140
142 textureData.emplace<GrGLBackendTextureData>(fGLInfo.info(), fGLInfo.refParameters());
143}
144
145bool GrGLBackendTextureData::isProtected() const { return fGLInfo.isProtected(); }
146
148 SkASSERT(!that || that->type() == GrBackendApi::kOpenGL);
149 if (auto otherGL = static_cast<const GrGLBackendTextureData*>(that)) {
150 return fGLInfo.info() == otherGL->fGLInfo.info();
151 }
152 return false;
153}
154
156 SkASSERT(!that || that->type() == GrBackendApi::kOpenGL);
157 if (auto otherGL = static_cast<const GrGLBackendTextureData*>(that)) {
158 return fGLInfo.info().fID == otherGL->fGLInfo.info().fID;
159 }
160 return false;
161}
162
166
169 SkASSERT(!data || data->type() == GrBackendApi::kOpenGL);
170 return static_cast<const GrGLBackendTextureData*>(data);
171}
172
175 SkASSERT(!data || data->type() == GrBackendApi::kOpenGL);
176 return static_cast<GrGLBackendTextureData*>(data);
177}
178
179namespace GrBackendTextures {
181 int height,
182 skgpu::Mipmapped mipped,
183 const GrGLTextureInfo& glInfo,
184 std::string_view label) {
186 width,
187 height,
188 label,
189 mipped,
192 GrGLBackendTextureData(glInfo, sk_make_sp<GrGLTextureParameters>()));
193 // Make no assumptions about client's texture's parameters.
195 return tex;
196}
197
199 int height,
200 skgpu::Mipmapped mipped,
201 const GrGLTextureInfo& glInfo,
203 std::string_view label) {
205 height,
206 label,
207 mipped,
211}
212
214 if (!tex.isValid() || tex.backend() != GrBackendApi::kOpenGL) {
215 return false;
216 }
217 const GrGLBackendTextureData* data = get_and_cast_data(tex);
218 SkASSERT(data);
219 *outInfo = data->info().info();
220 return true;
221}
222
224 if (tex && tex->isValid() && tex->backend() == GrBackendApi::kOpenGL) {
226 SkASSERT(data);
227 data->info().parameters()->invalidate();
228 }
229}
230} // namespace GrBackendTextures
231
233public:
235
236 GrGLFramebufferInfo info() const { return fGLInfo; }
237
238private:
242
243 bool isProtected() const override { return fGLInfo.isProtected(); }
244
245 bool equal(const GrBackendRenderTargetData* that) const override {
246 SkASSERT(!that || that->type() == GrBackendApi::kOpenGL);
247 if (auto otherGL = static_cast<const GrGLBackendRenderTargetData*>(that)) {
248 return fGLInfo == otherGL->fGLInfo;
249 }
250 return false;
251 }
252
253 void copyTo(AnyRenderTargetData& rtData) const override {
254 rtData.emplace<GrGLBackendRenderTargetData>(fGLInfo);
255 }
256
257#if defined(SK_DEBUG)
258 GrBackendApi type() const override { return GrBackendApi::kOpenGL; }
259#endif
260
261 GrGLFramebufferInfo fGLInfo;
262};
263
266 SkASSERT(!data || data->type() == GrBackendApi::kOpenGL);
267 return static_cast<const GrGLBackendRenderTargetData*>(data);
268}
269
270namespace GrBackendRenderTargets {
271// The GrGLTextureInfo must have a valid fFormat. If wrapping in an SkSurface we require the
272// stencil bits to be either 0, 8 or 16.
274 int width, int height, int sampleCnt, int stencilBits, const GrGLFramebufferInfo& glInfo) {
276 height,
277 std::max(1, sampleCnt),
278 stencilBits,
280 /*framebufferOnly=*/false,
282}
283
285 if (!rt.isValid() || rt.backend() != GrBackendApi::kOpenGL) {
286 return false;
287 }
289 SkASSERT(data);
290 *outInfo = data->info();
291 return true;
292}
293
294} // 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
#define GR_GL_TEXTURE_NONE
#define GR_GL_TEXTURE_RECTANGLE
#define GR_GL_TEXTURE_EXTERNAL
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
GrBackendApi
Definition GrTypes.h:95
#define SkUNREACHABLE
Definition SkAssert.h:135
#define SkASSERT(cond)
Definition SkAssert.h:116
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)
GrBackendApi backend() const
uint32_t channelMask() const override
SkTextureCompressionType compressionType() const override
GrColorFormatDesc desc() const override
int stencilBits() const override
bool equal(const GrBackendFormatData *that) const override
void copyTo(AnyFormatData &formatData) const override
std::string toString() const override
GrGLBackendFormatData(GrGLenum format)
size_t bytesPerBlock() const override
bool equal(const GrBackendRenderTargetData *that) const override
GrGLBackendRenderTargetData(GrGLFramebufferInfo info)
void copyTo(AnyRenderTargetData &rtData) const override
GrGLFramebufferInfo info() const
bool isProtected() const override
GrBackendFormat getBackendFormat() const override
bool isSameTexture(const GrBackendTextureData *that) const override
GrGLBackendTextureData(const GrGLTextureInfo &info, sk_sp< GrGLTextureParameters > params)
bool isProtected() const override
bool equal(const GrBackendTextureData *that) const override
void copyTo(AnyTextureData &) const override
GrBackendFormat getBackendFormat() const override
const GrGLTextureInfo & info() const
sk_sp< GrGLTextureParameters > refParameters() const
void emplace(Args &&... args)
const EmbeddedViewParams * params
uint32_t uint32_t * format
uint32_t * target
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
GrGLenum fFormat
Definition GrGLTypes.h:183
GrGLenum fTarget
Definition GrGLTypes.h:181