Skia
2DGraphicsLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GrGpuResource Class Referenceabstract

Base class for objects that can be kept in the GrResourceCache. More...

#include <GrGpuResource.h>

Inheritance diagram for GrGpuResource:
GrIORef< GrGpuResource > GrSurface GrRenderTarget GrTexture

Classes

class  UniqueID
 

Public Member Functions

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...
 
UniqueID uniqueID () const
 Gets an id that is unique for this GrGpuResource object. More...
 
const GrUniqueKeygetUniqueKey () const
 Returns the current unique key for the resource. More...
 
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 uint32_t CreateUniqueID ()
 

Protected Member Functions

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
 

Private Types

typedef GrIORef< GrGpuResourceINHERITED
 

Private Member Functions

virtual void computeScratchKey (GrScratchKey *) const
 Called by the registerWithCache if the resource is available to be used as scratch. More...
 
void release ()
 Frees the object in the underlying 3D API. More...
 
virtual size_t onGpuMemorySize () const =0
 
void setUniqueKey (const GrUniqueKey &)
 
void removeUniqueKey ()
 
void notifyAllCntsAreZero (CntType) const
 
bool notifyRefCountIsZero () const
 
void removeScratchKey ()
 
void makeBudgeted ()
 
void makeUnbudgeted ()
 

Private Attributes

int fCacheArrayIndex
 
uint32_t fTimestamp
 
uint32_t fExternalFlushCntWhenBecamePurgeable
 
GrStdSteadyClock::time_point fTimeWhenBecamePurgeable
 
GrScratchKey fScratchKey
 
GrUniqueKey fUniqueKey
 
GrGpu * fGpu
 
size_t fGpuMemorySize
 
SkBudgeted fBudgeted
 
bool fRefsWrappedObjects
 
const UniqueID fUniqueID
 

Static Private Attributes

static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0)
 

Friends

class GrIORef< GrGpuResource >
 

Additional Inherited Members

- Protected Types inherited from GrIORef< GrGpuResource >
enum  CntType
 

Detailed Description

Base class for objects that can be kept in the GrResourceCache.

Member Function Documentation

void GrGpuResource::abandon ( )

Removes references to objects in the underlying 3D API without freeing them.

Called by CacheAccess. In general this method should not be called outside of skia. It was made by public for a special case where it needs to be called in Blink when a texture becomes unsafe to use after having been shared through a texture mailbox.

virtual void GrGpuResource::computeScratchKey ( GrScratchKey ) const
inlineprivatevirtual

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 in GrTexture.

void GrGpuResource::didChangeGpuMemorySize ( ) const
protected

This entry point should be called whenever gpuMemorySize() should report a different size.

The cache will call gpuMemorySize() to update the current size of the resource.

virtual void GrGpuResource::dumpMemoryStatistics ( SkTraceMemoryDump traceMemoryDump) const
virtual

Dumps memory usage information for this GrGpuResource to traceMemoryDump.

Typically, subclasses should not need to override this, and should only need to override setMemoryBacking.

const GrContext* GrGpuResource::getContext ( ) const

Retrieves the context that owns the object.

Note that it is possible for this to return NULL. When objects have been release()ed or abandon()ed they no longer have an owning context. Destroying a GrContext automatically releases all its resources.

const GrUniqueKey& GrGpuResource::getUniqueKey ( ) const
inline

Returns the current unique key for the resource.

It will be invalid if the resource has no associated unique key.

size_t GrGpuResource::gpuMemorySize ( ) const
inline

Retrieves the amount of GPU memory used by this resource in bytes.

It is approximate since we aren't aware of additional padding or copies made by the driver.

Returns
the amount of GPU memory used in bytes
virtual void GrGpuResource::onAbandon ( )
inlineprotectedvirtual

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 in GrRenderTarget, and GrSurface.

virtual void GrGpuResource::onRelease ( )
inlineprotectedvirtual

Overridden to free GPU resources in the backend API.

Reimplemented in GrRenderTarget, and GrSurface.

void GrGpuResource::release ( )
private

Frees the object in the underlying 3D API.

Called by CacheAccess.

virtual void GrGpuResource::setMemoryBacking ( SkTraceMemoryDump ,
const SkString  
) const
inlineprotectedvirtual

Allows subclasses to add additional backing information to the SkTraceMemoryDump.

Called by onMemoryDump. The default implementation adds no backing information.

UniqueID GrGpuResource::uniqueID ( ) const
inline

Gets an id that is unique for this GrGpuResource object.

It is static in that it does not change when the content of the GrGpuResource object changes. This will never return 0.

bool GrGpuResource::wasDestroyed ( ) const
inline

Tests whether a object has been abandoned or released.

All objects will be in this state after their creating GrContext is destroyed or has contextLost called. It's up to the client to test wasDestroyed() before attempting to use an object if it holds refs on objects across ~GrContext, freeResources with the force flag, or contextLost.

Returns
true if the object has been released or abandoned, false otherwise.

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