Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrGLRenderTarget.h
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
8
9#ifndef GrGLRenderTarget_DEFINED
10#define GrGLRenderTarget_DEFINED
11
18
19class GrGLCaps;
20class GrGLGpu;
21class GrGLAttachment;
22
24public:
26 bool alwaysClearStencil() const override { return this->glRTFBOIDis0(); }
27
28 // set fSingleSampleFBOID to this value to indicate that it is multisampled but
29 // Gr doesn't know how to resolve it.
30 enum { kUnresolvableFBOID = 0 };
31
39
41 const SkISize&,
43 int sampleCount,
44 const IDs&,
45 int stencilBits,
47 std::string_view label);
48
49 bool isFBO0(bool multisample) const {
50 return (multisample ? fMultisampleFBOID : fSingleSampleFBOID) == 0;
51 }
52
54 return fMultisampleFBOID != 0 && fMultisampleFBOID == fSingleSampleFBOID;
55 }
56
58
59 GrBackendFormat backendFormat() const override;
60
61 bool canAttemptStencilAttachment(bool useMultisampleFBO) const override;
62
63 // GrGLRenderTarget overrides dumpMemoryStatistics so it can log its texture and renderbuffer
64 // components separately.
65 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override;
66
67 GrGLFormat format() const { return fRTFormat; }
68
69 bool hasDynamicMSAAAttachment() const { return SkToBool(fDynamicMSAAAttachment); }
71
72 // Binds the render target to GL_FRAMEBUFFER for rendering.
73 void bind(bool useMultisampleFBO) {
74 this->bindInternal(GR_GL_FRAMEBUFFER, useMultisampleFBO);
75 }
76
77 // Must be rebound even if this is already the currently bound render target.
78 bool mustRebind(bool useMultisampleFBO) const {
79 return fNeedsStencilAttachmentBind[useMultisampleFBO];
80 }
81
82 // Binds the render target for copying, reading, or clearing pixel values. If we are an MSAA
83 // render target with a separate resolve texture, we bind the multisampled FBO. Otherwise we
84 // bind the single sample FBO.
85 void bindForPixelOps(GrGLenum fboTarget) {
86 this->bindInternal(fboTarget,
87 this->numSamples() > 1 && !this->isMultisampledRenderToTexture());
88 }
89
90 enum class ResolveDirection : bool {
91 kSingleToMSAA, // glCaps.canResolveSingleToMSAA() must be true.
93 };
94
95 // Binds the multisampled and single sample FBOs, one to GL_DRAW_FRAMEBUFFER and the other to
96 // GL_READ_FRAMEBUFFER, depending on ResolveDirection.
98
99protected:
100 // Constructor for subclasses.
102 const SkISize&,
104 int sampleCount,
105 const IDs&,
107 std::string_view label);
108
109 void init(GrGLFormat, const IDs&);
110
111 // Binds the render target to the given target and ensures its stencil attachment is valid.
112 void bindInternal(GrGLenum fboTarget, bool useMultisampleFBO);
113
114 void onAbandon() override;
115 void onRelease() override;
116
117 int totalMemorySamplesPerPixel() const { return fTotalMemorySamplesPerPixel; }
118
119private:
120 // Constructor for instances wrapping backend objects.
122 const SkISize&,
124 int sampleCount,
125 const IDs&,
126 sk_sp<GrGLAttachment> stencil,
128 std::string_view label);
129
130 void setFlags(const GrGLCaps&, const IDs&);
131
132 GrGLGpu* getGLGpu() const;
133 bool completeStencilAttachment(GrAttachment* stencil, bool useMultisampleFBO) override;
134
135 size_t onGpuMemorySize() const override;
136
137 void onSetLabel() override;
138
139 sk_sp<GrGLAttachment> fDynamicMSAAAttachment;
140
141 GrGLuint fMultisampleFBOID;
142 GrGLuint fSingleSampleFBOID;
143 GrGLuint fMSColorRenderbufferID;
144 GrGLFormat fRTFormat;
145 bool fNeedsStencilAttachmentBind[2] = {false, false};
146 bool fDMSAARenderToTextureFBOIsMultisample = false;
147
148 GrBackendObjectOwnership fRTFBOOwnership;
149
150 // The RenderTarget needs to be able to report its VRAM footprint even after abandon and
151 // release have potentially zeroed out the IDs (e.g., so the cache can reset itself). Since
152 // the IDs are just required for the computation in totalSamples we cache that result here.
153 int fTotalMemorySamplesPerPixel;
154
155 using INHERITED = GrRenderTarget;
156};
157
158#endif
#define GR_GL_FRAMEBUFFER
GrGLFormat
Definition GrGLTypes.h:59
unsigned int GrGLuint
Definition GrGLTypes.h:113
unsigned int GrGLenum
Definition GrGLTypes.h:102
GrBackendObjectOwnership
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35
void bindForPixelOps(GrGLenum fboTarget)
bool glRTFBOIDis0() const
Definition GrSurface.h:117
bool alwaysClearStencil() const override
bool hasDynamicMSAAAttachment() const
bool canAttemptStencilAttachment(bool useMultisampleFBO) const override
void bindForResolve(ResolveDirection)
void onAbandon() override
bool completeStencilAttachment(GrAttachment *stencil, bool useMultisampleFBO) override
int totalMemorySamplesPerPixel() const
void bind(bool useMultisampleFBO)
bool isFBO0(bool multisample) const
static sk_sp< GrGLRenderTarget > MakeWrapped(GrGLGpu *, const SkISize &, GrGLFormat, int sampleCount, const IDs &, int stencilBits, skgpu::Protected, std::string_view label)
void bindInternal(GrGLenum fboTarget, bool useMultisampleFBO)
GrBackendRenderTarget getBackendRenderTarget() const override
size_t onGpuMemorySize() const override
void onSetLabel() override
GrBackendFormat backendFormat() const override
GrGLFormat format() const
void init(GrGLFormat, const IDs &)
bool mustRebind(bool useMultisampleFBO) const
void dumpMemoryStatistics(SkTraceMemoryDump *traceMemoryDump) const override
bool isMultisampledRenderToTexture() const
void onRelease() override
int numSamples() const
bool glRTFBOIDis0() const
Definition GrSurface.h:117
Protected
Definition GpuTypes.h:61
GrBackendObjectOwnership fRTFBOOwnership