Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GrBuffer Class Reference
Inheritance diagram for GrBuffer:
GrGpuResource GrIORef< GrGpuResource >

Public Member Functions

GrAccessPattern accessPattern () const
 
size_t sizeInBytes () const
 
bool isCPUBacked () const
 Returns true if the buffer is a wrapper around a CPU array. More...
 
size_t baseOffset () const
 
void * map ()
 Maps the buffer to be written by the CPU. More...
 
void unmap ()
 Unmaps the buffer. More...
 
void * mapPtr () const
 Returns the same ptr that map() returned at time of map or nullptr if the is not mapped. More...
 
bool isMapped () const
 Queries whether the buffer has been mapped. More...
 
bool updateData (const void *src, size_t srcSizeInBytes)
 Updates the buffer data. More...
 
- Public Member Functions inherited from GrGpuResource
bool wasDestroyed () const
 Tests whether a object has been abandoned or released. More...
 
const GrContextgetContext () const
 Retrieves the context that owns the object. More...
 
GrContextgetContext ()
 
size_t gpuMemorySize () const
 Retrieves the amount of GPU memory used by this resource in bytes. More...
 
uint32_t getUniqueID () const
 Gets an id that is unique for this GrGpuResource object. More...
 
const GrUniqueKeygetUniqueKey () const
 Returns the current unique key for the resource. More...
 
const SkDatasetCustomData (const SkData *data)
 Attach a custom data object to this resource. More...
 
const SkDatagetCustomData () const
 Returns the custom data object that was attached to this resource by calling setCustomData.
 
CacheAccess cacheAccess ()
 
const CacheAccess cacheAccess () const
 
ResourcePriv resourcePriv ()
 
const ResourcePriv resourcePriv () const
 
void abandon ()
 Removes references to objects in the underlying 3D API without freeing them. More...
 
virtual void dumpMemoryStatistics (SkTraceMemoryDump *traceMemoryDump) const
 Dumps memory usage information for this GrGpuResource to traceMemoryDump. More...
 
- Public Member Functions inherited from GrIORef< GrGpuResource >
void ref () const
 
void unref () const
 
void validate () const
 

Static Public Member Functions

static SK_WARN_UNUSED_RESULT
GrBuffer
CreateCPUBacked (GrGpu *, size_t sizeInBytes, GrBufferType, const void *data=nullptr)
 Creates a client-side buffer.
 
static void ComputeScratchKeyForDynamicVBO (size_t size, GrBufferType, GrScratchKey *)
 Computes a scratch key for a GPU-side buffer with a "dynamic" access pattern. More...
 

Protected Member Functions

 GrBuffer (GrGpu *, size_t sizeInBytes, GrBufferType, GrAccessPattern)
 
- Protected Member Functions inherited from GrGpuResource
void registerWithCache (SkBudgeted)
 
void registerWithCacheWrapped ()
 
 GrGpuResource (GrGpu *)
 
GrGpu * getGpu () const
 
virtual void onRelease ()
 Overridden to free GPU resources in the backend API. More...
 
virtual void onAbandon ()
 Overridden to abandon any internal handles, ptrs, etc to backend API resources. More...
 
void didChangeGpuMemorySize () const
 This entry point should be called whenever gpuMemorySize() should report a different size. More...
 
virtual void setMemoryBacking (SkTraceMemoryDump *, const SkString &) const
 Allows subclasses to add additional backing information to the SkTraceMemoryDump. More...
 
- Protected Member Functions inherited from GrIORef< GrGpuResource >
bool isPurgeable () const
 
bool internalHasPendingRead () const
 
bool internalHasPendingWrite () const
 
bool internalHasPendingIO () const
 
bool internalHasRef () const
 

Protected Attributes

void * fMapPtr
 

Private Types

typedef GrGpuResource INHERITED
 

Private Member Functions

 GrBuffer (GrGpu *, size_t sizeInBytes, GrBufferType, void *cpuData)
 Internal constructor to make a CPU-backed buffer.
 
virtual void onMap ()
 
virtual void onUnmap ()
 
virtual bool onUpdateData (const void *src, size_t srcSizeInBytes)
 
size_t onGpuMemorySize () const override
 
void computeScratchKey (GrScratchKey *key) const override
 Called by the registerWithCache if the resource is available to be used as scratch. More...
 

Private Attributes

size_t fSizeInBytes
 
GrAccessPattern fAccessPattern
 
void * fCPUData
 
GrBufferType fIntendedType
 

Additional Inherited Members

- Protected Types inherited from GrIORef< GrGpuResource >
enum  CntType
 

Member Function Documentation

void GrBuffer::computeScratchKey ( GrScratchKey ) const
overrideprivatevirtual

Called by the registerWithCache if the resource is available to be used as scratch.

Resource subclasses should override this if the instances should be recycled as scratch resources and populate the scratchKey with the key. By default resources are not recycled as scratch.

Reimplemented from GrGpuResource.

static void GrBuffer::ComputeScratchKeyForDynamicVBO ( size_t  size,
GrBufferType  ,
GrScratchKey  
)
static

Computes a scratch key for a GPU-side buffer with a "dynamic" access pattern.

(Buffers with "static" and "stream" patterns are disqualified by nature from being cached and reused.)

bool GrBuffer::isCPUBacked ( ) const
inline

Returns true if the buffer is a wrapper around a CPU array.

If true it indicates that map will always succeed and will be free.

bool GrBuffer::isMapped ( ) const
inline

Queries whether the buffer has been mapped.

Returns
true if the buffer is mapped, false otherwise.
void* GrBuffer::map ( )
inline

Maps the buffer to be written by the CPU.

The previous content of the buffer is invalidated. It is an error to draw from the buffer while it is mapped. It may fail if the backend doesn't support mapping the buffer. If the buffer is CPU backed then it will always succeed and is a free operation. Once a buffer is mapped, subsequent calls to map() are ignored.

Note that buffer mapping does not go through GrContext and therefore is not serialized with other operations.

Returns
a pointer to the data or nullptr if the map fails.
void* GrBuffer::mapPtr ( ) const
inline

Returns the same ptr that map() returned at time of map or nullptr if the is not mapped.

Returns
ptr to mapped buffer data or nullptr if buffer is not mapped.
void GrBuffer::unmap ( )
inline

Unmaps the buffer.

The pointer returned by the previous map call will no longer be valid.

bool GrBuffer::updateData ( const void *  src,
size_t  srcSizeInBytes 
)
inline

Updates the buffer data.

The size of the buffer will be preserved. The src data will be placed at the beginning of the buffer and any remaining contents will be undefined. srcSizeInBytes must be <= to the buffer size.

The buffer must not be mapped.

Note that buffer updates do not go through GrContext and therefore are not serialized with other operations.

Returns
returns true if the update succeeds, false otherwise.

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