Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | List of all members
GrGLBuffer Class Reference

#include <GrGLBuffer.h>

Inheritance diagram for GrGLBuffer:
GrGpuBuffer GrGpuResource GrBuffer GrIORef< GrGpuResource > SkNoncopyable

Public Member Functions

 ~GrGLBuffer () override
 
GrGLuint bufferID () const
 
void setHasAttachedToTexture ()
 
bool hasAttachedToTexture () const
 
- Public Member Functions inherited from GrGpuBuffer
GrAccessPattern accessPattern () const
 
size_t size () const final
 
void ref () const final
 
void unref () const final
 
void * map ()
 
void unmap ()
 
bool isMapped () const
 
bool isCpuBuffer () const final
 
bool clearToZero ()
 
bool updateData (const void *src, size_t offset, size_t size, bool preserve)
 
GrGpuBufferType intendedType () const
 
- Public Member Functions inherited from GrGpuResource
bool wasDestroyed () const
 
const GrDirectContextgetContext () const
 
GrDirectContextgetContext ()
 
size_t gpuMemorySize () const
 
UniqueID uniqueID () const
 
const skgpu::UniqueKeygetUniqueKey () const
 
std::string getLabel () const
 
void setLabel (std::string_view label)
 
CacheAccess cacheAccess ()
 
const CacheAccess cacheAccess () const
 
ProxyAccess proxyAccess ()
 
ResourcePriv resourcePriv ()
 
const ResourcePriv resourcePriv () const
 
virtual void dumpMemoryStatistics (SkTraceMemoryDump *traceMemoryDump) const
 
- Public Member Functions inherited from GrIORef< GrGpuResource >
bool unique () const
 
void ref () const
 
void unref () const
 
void refCommandBuffer () const
 
void unrefCommandBuffer () const
 
- Public Member Functions inherited from SkNoncopyable
 SkNoncopyable ()=default
 
 SkNoncopyable (SkNoncopyable &&)=default
 
SkNoncopyableoperator= (SkNoncopyable &&)=default
 
- Public Member Functions inherited from GrBuffer
 GrBuffer (const GrBuffer &)=delete
 
GrBufferoperator= (const GrBuffer &)=delete
 
virtual ~GrBuffer ()=default
 

Static Public Member Functions

static sk_sp< GrGLBufferMake (GrGLGpu *, size_t size, GrGpuBufferType intendedType, GrAccessPattern)
 
- Static Public Member Functions inherited from GrGpuBuffer
static void ComputeScratchKeyForDynamicBuffer (size_t size, GrGpuBufferType, skgpu::ScratchKey *)
 
- Static Public Member Functions inherited from GrGpuResource
static uint32_t CreateUniqueID ()
 

Protected Member Functions

 GrGLBuffer (GrGLGpu *, size_t size, GrGpuBufferType intendedType, GrAccessPattern, std::string_view label)
 
void onAbandon () override
 
void onRelease () override
 
void setMemoryBacking (SkTraceMemoryDump *traceMemoryDump, const SkString &dumpName) const override
 
- Protected Member Functions inherited from GrGpuBuffer
 GrGpuBuffer (GrGpu *, size_t sizeInBytes, GrGpuBufferType, GrAccessPattern, std::string_view label)
 
- Protected Member Functions inherited from GrGpuResource
void registerWithCache (skgpu::Budgeted)
 
void registerWithCacheWrapped (GrWrapCacheable)
 
 GrGpuResource (GrGpu *, std::string_view label)
 
virtual ~GrGpuResource ()
 
GrGpugetGpu () const
 
SkString getResourceName () const
 
void dumpMemoryStatisticsPriv (SkTraceMemoryDump *traceMemoryDump, const SkString &resourceName, const char *type, size_t size) const
 
- Protected Member Functions inherited from GrIORef< GrGpuResource >
 GrIORef ()
 
bool internalHasRef () const
 
bool internalHasNoCommandBufferUsages () const
 
void addInitialRef () const
 
- Protected Member Functions inherited from GrBuffer
 GrBuffer ()=default
 

Private Member Functions

void onMap (MapType) override
 
void onUnmap (MapType) override
 
bool onClearToZero () override
 
bool onUpdateData (const void *src, size_t offset, size_t size, bool preserve) override
 
void onSetLabel () override
 

Additional Inherited Members

- Public Types inherited from GrIORef< GrGpuResource >
enum  LastRemovedRef
 
- Protected Types inherited from GrGpuBuffer
enum class  MapType { kRead , kWriteDiscard }
 
- Protected Attributes inherited from GrGpuBuffer
void * fMapPtr
 

Detailed Description

Definition at line 17 of file GrGLBuffer.h.

Constructor & Destructor Documentation

◆ ~GrGLBuffer()

GrGLBuffer::~GrGLBuffer ( )
inlineoverride

Definition at line 24 of file GrGLBuffer.h.

24 {
25 // either release or abandon should have been called by the owner of this object.
26 SkASSERT(0 == fBufferID);
27 }
#define SkASSERT(cond)
Definition SkAssert.h:116

◆ GrGLBuffer()

GrGLBuffer::GrGLBuffer ( GrGLGpu gpu,
size_t  size,
GrGpuBufferType  intendedType,
GrAccessPattern  accessPattern,
std::string_view  label 
)
protected

Definition at line 103 of file GrGLBuffer.cpp.

108 : INHERITED(gpu, size, intendedType, accessPattern, label)
109 , fIntendedType(intendedType)
110 , fBufferID(0)
112 , fHasAttachedToTexture(false) {
113 GL_CALL(GenBuffers(1, &fBufferID));
114 if (fBufferID) {
115 GrGLenum target = gpu->bindBuffer(fIntendedType, this);
116 GrGLenum error = GL_ALLOC_CALL(this->glGpu(), BufferData(target,
118 nullptr,
119 fUsage));
120 if (error != GR_GL_NO_ERROR) {
121 GL_CALL(DeleteBuffers(1, &fBufferID));
122 fBufferID = 0;
123 }
124 }
126 if (!fBufferID) {
128 }
129}
#define GL_ALLOC_CALL(call)
static GrGLenum gr_to_gl_access_pattern(GrGpuBufferType bufferType, GrAccessPattern accessPattern, const GrGLCaps &caps)
#define GR_GL_NO_ERROR
#define GL_CALL(X)
unsigned int GrGLenum
Definition GrGLTypes.h:102
signed long int GrGLsizeiptr
Definition GrGLTypes.h:126
const GrGLCaps & glCaps() const
Definition GrGLGpu.h:108
GrGLenum bindBuffer(GrGpuBufferType type, const GrBuffer *)
Definition GrGLGpu.cpp:2143
size_t size() const final
Definition GrGpuBuffer.h:34
GrGpuBufferType intendedType() const
Definition GrGpuBuffer.h:99
GrAccessPattern accessPattern() const
Definition GrGpuBuffer.h:32
void registerWithCache(skgpu::Budgeted)
ResourcePriv resourcePriv()
const uint8_t uint32_t uint32_t GError ** error
uint32_t * target

Member Function Documentation

◆ bufferID()

GrGLuint GrGLBuffer::bufferID ( ) const
inline

Definition at line 29 of file GrGLBuffer.h.

29{ return fBufferID; }

◆ hasAttachedToTexture()

bool GrGLBuffer::hasAttachedToTexture ( ) const
inline

Definition at line 32 of file GrGLBuffer.h.

32{ return fHasAttachedToTexture; }

◆ Make()

sk_sp< GrGLBuffer > GrGLBuffer::Make ( GrGLGpu gpu,
size_t  size,
GrGpuBufferType  intendedType,
GrAccessPattern  accessPattern 
)
static

Definition at line 31 of file GrGLBuffer.cpp.

34 {
38 return nullptr;
39 }
40
42 /*label=*/"MakeGlBuffer"));
43 if (0 == buffer->bufferID()) {
44 return nullptr;
45 }
46 return buffer;
47}
TransferBufferType transferBufferType() const
What type of transfer buffer is supported?
Definition GrGLCaps.h:329
static const uint8_t buffer[]

◆ onAbandon()

void GrGLBuffer::onAbandon ( )
overrideprotectedvirtual

Overridden to abandon any internal handles, ptrs, etc to backend API resources. This may be called when the underlying 3D context is no longer valid and so no backend API calls should be made.

Reimplemented from GrGpuResource.

Definition at line 155 of file GrGLBuffer.cpp.

155 {
156 fBufferID = 0;
157 fMapPtr = nullptr;
159}
void * fMapPtr
virtual void onAbandon()

◆ onClearToZero()

bool GrGLBuffer::onClearToZero ( )
overrideprivatevirtual

Implements GrGpuBuffer.

Definition at line 246 of file GrGLBuffer.cpp.

246 {
247 SkASSERT(fBufferID);
248
249 // We could improve this on GL 4.3+ with glClearBufferData (also GL_ARB_clear_buffer_object).
251 if (fMapPtr) {
252 std::memset(fMapPtr, 0, this->size());
254 return true;
255 }
256
257 void* zeros = sk_calloc_throw(this->size());
258 bool result = this->updateData(zeros, 0, this->size(), /*preserve=*/false);
259 sk_free(zeros);
260 return result;
261}
static void * sk_calloc_throw(size_t size)
Definition SkMalloc.h:71
SK_API void sk_free(void *)
void onUnmap(MapType) override
void onMap(MapType) override
bool updateData(const void *src, size_t offset, size_t size, bool preserve)
GAsyncResult * result

◆ onMap()

void GrGLBuffer::onMap ( MapType  type)
overrideprivatevirtual

Implements GrGpuBuffer.

Definition at line 178 of file GrGLBuffer.cpp.

178 {
179 SkASSERT(fBufferID);
180 SkASSERT(!this->wasDestroyed());
181 SkASSERT(!this->isMapped());
182
183 // Handling dirty context is done in the bindBuffer call
184 switch (this->glCaps().mapBufferType()) {
186 return;
188 GrGLenum target = this->glGpu()->bindBuffer(fIntendedType, this);
190 GrGLenum error = invalidate_buffer(this->glGpu(),
191 target,
192 fUsage,
193 fBufferID,
194 this->size());
195 if (error != GR_GL_NO_ERROR) {
196 return;
197 }
198 }
200 GL_CALL_RET(fMapPtr, MapBuffer(target, access));
201 break;
202 }
204 GrGLenum target = this->glGpu()->bindBuffer(fIntendedType, this);
205 GrGLbitfield access;
206 switch (type) {
207 case MapType::kRead:
208 access = GR_GL_MAP_READ_BIT;
209 break;
212 break;
213 }
214 GL_CALL_RET(fMapPtr, MapBufferRange(target, 0, this->size(), access));
215 break;
216 }
218 GrGLenum target = this->glGpu()->bindBuffer(fIntendedType, this);
220 GL_CALL_RET(fMapPtr, MapBufferSubData(target, 0, this->size(), access));
221 break;
222 }
223 }
224}
static GrGLenum invalidate_buffer(GrGLGpu *gpu, GrGLenum target, GrGLenum usage, GrGLuint bufferID, size_t bufferSize)
#define GR_GL_MAP_INVALIDATE_BUFFER_BIT
#define GR_GL_MAP_WRITE_BIT
#define GR_GL_MAP_READ_BIT
#define GR_GL_WRITE_ONLY
#define GR_GL_READ_ONLY
#define GL_CALL_RET(R, X)
unsigned int GrGLbitfield
Definition GrGLTypes.h:104
@ kMapBufferRange_MapBufferType
Definition GrGLCaps.h:109
@ kMapBuffer_MapBufferType
Definition GrGLCaps.h:108
@ kNone_MapBufferType
Definition GrGLCaps.h:107
@ kChromium_MapBufferType
Definition GrGLCaps.h:110
bool isMapped() const
bool wasDestroyed() const

◆ onRelease()

void GrGLBuffer::onRelease ( )
overrideprotectedvirtual

Overridden to free GPU resources in the backend API.

Reimplemented from GrGpuResource.

Definition at line 140 of file GrGLBuffer.cpp.

140 {
141 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
142
143 if (!this->wasDestroyed()) {
144 // make sure we've not been abandoned or already released
145 if (fBufferID) {
146 GL_CALL(DeleteBuffers(1, &fBufferID));
147 fBufferID = 0;
148 }
149 fMapPtr = nullptr;
150 }
151
153}
#define TRACE_FUNC
virtual void onRelease()
#define TRACE_EVENT0(category_group, name)

◆ onSetLabel()

void GrGLBuffer::onSetLabel ( )
overrideprivatevirtual

Implements GrGpuResource.

Definition at line 278 of file GrGLBuffer.cpp.

278 {
279 SkASSERT(fBufferID);
280 if (!this->getLabel().empty()) {
281 const std::string label = "_Skia_" + this->getLabel();
282 if (this->glGpu()->glCaps().debugSupport()) {
283 GL_CALL(ObjectLabel(GR_GL_BUFFER, fBufferID, -1, label.c_str()));
284 }
285 }
286}
#define GR_GL_BUFFER
std::string getLabel() const
EMSCRIPTEN_KEEPALIVE void empty()

◆ onUnmap()

void GrGLBuffer::onUnmap ( MapType  )
overrideprivatevirtual

Implements GrGpuBuffer.

Definition at line 226 of file GrGLBuffer.cpp.

226 {
227 SkASSERT(fBufferID);
228 // bind buffer handles the dirty context
229 switch (this->glCaps().mapBufferType()) {
232 case GrGLCaps::kMapBuffer_MapBufferType: // fall through
234 GrGLenum target = this->glGpu()->bindBuffer(fIntendedType, this);
235 GL_CALL(UnmapBuffer(target));
236 break;
237 }
239 this->glGpu()->bindBuffer(fIntendedType, this); // TODO: Is this needed?
240 GL_CALL(UnmapBufferSubData(fMapPtr));
241 break;
242 }
243 fMapPtr = nullptr;
244}
#define SkUNREACHABLE
Definition SkAssert.h:135

◆ onUpdateData()

bool GrGLBuffer::onUpdateData ( const void *  src,
size_t  offset,
size_t  size,
bool  preserve 
)
overrideprivatevirtual

Implements GrGpuBuffer.

Definition at line 263 of file GrGLBuffer.cpp.

263 {
264 SkASSERT(fBufferID);
265
266 // bindbuffer handles dirty context
267 GrGLenum target = this->glGpu()->bindBuffer(fIntendedType, this);
268 if (!preserve) {
269 GrGLenum error = invalidate_buffer(this->glGpu(), target, fUsage, fBufferID, this->size());
270 if (error != GR_GL_NO_ERROR) {
271 return false;
272 }
273 }
274 GL_CALL(BufferSubData(target, offset, size, src));
275 return true;
276}
Point offset

◆ setHasAttachedToTexture()

void GrGLBuffer::setHasAttachedToTexture ( )
inline

Definition at line 31 of file GrGLBuffer.h.

31{ fHasAttachedToTexture = true; }

◆ setMemoryBacking()

void GrGLBuffer::setMemoryBacking ( SkTraceMemoryDump ,
const SkString  
) const
overrideprotectedvirtual

Allows subclasses to add additional backing information to the SkTraceMemoryDump.

Reimplemented from GrGpuResource.

Definition at line 288 of file GrGLBuffer.cpp.

289 {
290 SkString buffer_id;
291 buffer_id.appendU32(this->bufferID());
292 traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_buffer", buffer_id.c_str());
293}
GrGLuint bufferID() const
Definition GrGLBuffer.h:29
void appendU32(uint32_t value)
Definition SkString.h:210
const char * c_str() const
Definition SkString.h:133

The documentation for this class was generated from the following files: