Flutter Engine
The Flutter Engine
GrGLAttachment.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 Google Inc.
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
13
14#define GL_CALL(X) GR_GL_CALL(gpu->glInterface(), X)
15
16#define GL_ALLOC_CALL(call) \
17 [&] { \
18 if (gpu->glCaps().skipErrorChecks()) { \
19 GR_GL_CALL(gpu->glInterface(), call); \
20 return static_cast<GrGLenum>(GR_GL_NO_ERROR); \
21 } else { \
22 gpu->clearErrorsAndCheckForOOM(); \
23 GR_GL_CALL_NOERRCHECK(gpu->glInterface(), call); \
24 return gpu->getErrorAndCheckForOOM(); \
25 } \
26 }()
27
29 int sampleCount,
31 int width,
32 int height) {
35 switch (gpu->glCaps().msFBOType()) {
37 error = GL_ALLOC_CALL(RenderbufferStorageMultisample(
38 GR_GL_RENDERBUFFER, sampleCount, format, width, height));
39 break;
41 error = GL_ALLOC_CALL(RenderbufferStorageMultisampleES2APPLE(
42 GR_GL_RENDERBUFFER, sampleCount, format, width, height));
43 break;
46 error = GL_ALLOC_CALL(RenderbufferStorageMultisampleES2EXT(
47 GR_GL_RENDERBUFFER, sampleCount, format, width, height));
48 break;
51 }
52 return error == GR_GL_NO_ERROR;
53}
54
56 SkISize dimensions,
57 int sampleCnt,
59 GrGLuint rbID = 0;
60
61 GL_CALL(GenRenderbuffers(1, &rbID));
62 if (!rbID) {
63 return nullptr;
64 }
65 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, rbID));
67 // we do this "if" so that we don't call the multisample
68 // version on a GL that doesn't have an MSAA extension.
69 if (sampleCnt > 1) {
70 if (!renderbuffer_storage_msaa(gpu, sampleCnt, glFmt, dimensions.width(),
71 dimensions.height())) {
72 GL_CALL(DeleteRenderbuffers(1, &rbID));
73 return nullptr;
74 }
75 } else {
76 GrGLenum error = GL_ALLOC_CALL(RenderbufferStorage(
78 if (error != GR_GL_NO_ERROR) {
79 GL_CALL(DeleteRenderbuffers(1, &rbID));
80 return nullptr;
81 }
82 }
83
85 rbID,
88 sampleCnt,
89 format,
90 /*label=*/"GLAttachmentMakeStencil"));
91}
92
94 SkISize dimensions,
95 int sampleCnt,
97 GrGLuint rbID = 0;
98
99 GL_CALL(GenRenderbuffers(1, &rbID));
100 if (!rbID) {
101 return nullptr;
102 }
103 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, rbID));
106 gpu, sampleCnt, glFmt, dimensions.width(), dimensions.height())) {
107 GL_CALL(DeleteRenderbuffers(1, &rbID));
108 return nullptr;
109 }
110
112 rbID,
115 sampleCnt,
116 format,
117 /*label=*/"GLAttachmentMakeMSAA"));
118}
119
120
122 if (0 != fRenderbufferID) {
123 GrGLGpu* gpuGL = (GrGLGpu*)this->getGpu();
124 const GrGLInterface* gl = gpuGL->glInterface();
125 GR_GL_CALL(gl, DeleteRenderbuffers(1, &fRenderbufferID));
126 fRenderbufferID = 0;
127 }
128
130}
131
133 fRenderbufferID = 0;
134
136}
137
140}
141
143 const SkString& dumpName) const {
144 SkString renderbuffer_id;
145 renderbuffer_id.appendU32(this->renderbufferID());
146 traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_renderbuffer", renderbuffer_id.c_str());
147}
148
149void GrGLAttachment::onSetLabel() {
150 SkASSERT(fRenderbufferID);
151 if (!this->getLabel().empty()) {
152 const std::string label = "_Skia_" + this->getLabel();
153 GrGLGpu* glGpu = static_cast<GrGLGpu*>(this->getGpu());
154 if (glGpu->glCaps().debugSupport()) {
155 GR_GL_CALL(glGpu->glInterface(),
156 ObjectLabel(GR_GL_TEXTURE, fRenderbufferID, -1, label.c_str()));
157 }
158 }
159}
static bool renderbuffer_storage_msaa(GrGLGpu *gpu, int sampleCount, GrGLenum format, int width, int height)
#define GL_CALL(X)
#define GL_ALLOC_CALL(call)
#define GR_GL_RENDERBUFFER
Definition: GrGLDefines.h:903
#define GR_GL_TEXTURE
Definition: GrGLDefines.h:639
#define GR_GL_NO_ERROR
Definition: GrGLDefines.h:175
#define GR_GL_TEXTURE_NONE
Definition: GrGLDefines.h:151
GrGLFormat
Definition: GrGLTypes.h:59
unsigned int GrGLuint
Definition: GrGLTypes.h:113
unsigned int GrGLenum
Definition: GrGLTypes.h:102
#define GR_GL_CALL(IFACE, X)
Definition: GrGLUtil.h:381
static constexpr GrGLenum GrGLFormatToEnum(GrGLFormat format)
Definition: GrGLUtil.h:445
#define SkUNREACHABLE
Definition: SkAssert.h:135
#define SkASSERT(cond)
Definition: SkAssert.h:116
void setMemoryBacking(SkTraceMemoryDump *traceMemoryDump, const SkString &dumpName) const override
GrGLuint renderbufferID() const
static sk_sp< GrGLAttachment > MakeStencil(GrGLGpu *gpu, SkISize dimensions, int sampleCnt, GrGLFormat format)
static sk_sp< GrGLAttachment > MakeMSAA(GrGLGpu *gpu, SkISize dimensions, int sampleCnt, GrGLFormat format)
GrGLFormat format() const
GrBackendFormat backendFormat() const override
void onRelease() override
void onAbandon() override
GrGLenum getRenderbufferInternalFormat(GrGLFormat format) const
Definition: GrGLCaps.h:247
@ kES_Apple_MSFBOType
Definition: GrGLCaps.h:69
@ kES_EXT_MsToTexture_MSFBOType
Definition: GrGLCaps.h:81
@ kNone_MSFBOType
Definition: GrGLCaps.h:59
@ kES_IMG_MsToTexture_MSFBOType
Definition: GrGLCaps.h:76
@ kStandard_MSFBOType
Definition: GrGLCaps.h:65
MSFBOType msFBOType() const
Definition: GrGLCaps.h:285
bool debugSupport() const
Is there support for GL_KHR_debug?
Definition: GrGLCaps.h:359
const GrGLCaps & glCaps() const
Definition: GrGLGpu.h:108
const GrGLInterface * glInterface() const
Definition: GrGLGpu.h:103
std::string getLabel() const
GrGpu * getGpu() const
SkISize dimensions() const
Definition: GrSurface.h:27
void onAbandon() override
Definition: GrSurface.cpp:86
void onRelease() override
Definition: GrSurface.cpp:81
void appendU32(uint32_t value)
Definition: SkString.h:210
const char * c_str() const
Definition: SkString.h:133
virtual void setMemoryBacking(const char *dumpName, const char *backingType, const char *backingObjectId)=0
EMSCRIPTEN_KEEPALIVE void empty()
const uint8_t uint32_t uint32_t GError ** error
uint32_t uint32_t * format
SK_API GrBackendFormat MakeGL(GrGLenum format, GrGLenum target)
gl
Definition: malisc.py:41
int32_t height
int32_t width
Definition: SkSize.h:16
constexpr int32_t width() const
Definition: SkSize.h:36
constexpr int32_t height() const
Definition: SkSize.h:37