8 #ifndef GrBuffer_DEFINED
9 #define GrBuffer_DEFINED
11 #include "GrGpuResource.h"
21 const void* data =
nullptr);
29 GrAccessPattern accessPattern()
const {
return fAccessPattern; }
30 size_t sizeInBytes()
const {
return fSizeInBytes; }
37 size_t baseOffset()
const {
return reinterpret_cast<size_t>(fCPUData); }
77 void*
mapPtr()
const {
return fMapPtr; }
102 SkASSERT(srcSizeInBytes <= fSizeInBytes);
103 return this->onUpdateData(src, srcSizeInBytes);
111 GrBuffer(GrGpu*,
size_t sizeInBytes, GrBufferType, GrAccessPattern);
119 GrBuffer(GrGpu*,
size_t sizeInBytes, GrBufferType,
void* cpuData);
121 virtual void onMap() { SkASSERT(this->
isCPUBacked()); fMapPtr = fCPUData; }
122 virtual void onUnmap() { SkASSERT(this->
isCPUBacked()); }
123 virtual bool onUpdateData(
const void* src,
size_t srcSizeInBytes);
125 size_t onGpuMemorySize()
const override {
return fSizeInBytes; }
129 GrAccessPattern fAccessPattern;
131 GrBufferType fIntendedType;
Base class for objects that can be kept in the GrResourceCache.
Definition: GrGpuResource.h:140
static SK_WARN_UNUSED_RESULT GrBuffer * CreateCPUBacked(GrGpu *, size_t sizeInBytes, GrBufferType, const void *data=nullptr)
Creates a client-side buffer.
SK_API void sk_free(void *)
Free memory returned by sk_malloc().
#define SkToBool(cond)
Returns 0 or 1 based on the condition.
Definition: SkTypes.h:287
bool updateData(const void *src, size_t srcSizeInBytes)
Updates the buffer data.
Definition: GrBuffer.h:100
void computeScratchKey(GrScratchKey *key) const override
Called by the registerWithCache if the resource is available to be used as scratch.
Definition: GrBuffer.h:15
void * mapPtr() const
Returns the same ptr that map() returned at time of map or nullptr if the is not mapped.
Definition: GrBuffer.h:77
void * map()
Maps the buffer to be written by the CPU.
Definition: GrBuffer.h:53
A key used for scratch resources.
Definition: GrResourceKey.h:166
bool isMapped() const
Queries whether the buffer has been mapped.
Definition: GrBuffer.h:84
void unmap()
Unmaps the buffer.
Definition: GrBuffer.h:65
bool isCPUBacked() const
Returns true if the buffer is a wrapper around a CPU array.
Definition: GrBuffer.h:36
static void ComputeScratchKeyForDynamicVBO(size_t size, GrBufferType, GrScratchKey *)
Computes a scratch key for a GPU-side buffer with a "dynamic" access pattern.