Skia
2DGraphicsLibrary
|
Base class for GrGpuResource. More...
#include <GrGpuResource.h>
Public Member Functions | |
void | ref () const |
void | unref () const |
void | validate () const |
Protected Types | |
enum | CntType { kRef_CntType, kPendingRead_CntType, kPendingWrite_CntType } |
Protected Member Functions | |
bool | isPurgeable () const |
bool | internalHasPendingRead () const |
bool | internalHasPendingWrite () const |
bool | internalHasPendingIO () const |
bool | internalHasRef () const |
Private Attributes | |
int32_t | fRefCnt |
int32_t | fPendingReads |
int32_t | fPendingWrites |
Base class for GrGpuResource.
Handles the various types of refs we need. Separated out as a base class to isolate the ref-cnting behavior and provide friendship without exposing all of GrGpuResource.
Gpu resources can have three types of refs: 1) Normal ref (+ by ref(), - by unref()): These are used by code that is issuing draw calls that read and write the resource via GrOpList and by any object that must own a GrGpuResource and is itself owned (directly or indirectly) by Skia-client code. 2) Pending read (+ by addPendingRead(), - by completedRead()): GrContext has scheduled a read of the resource by the GPU as a result of a skia API call but hasn't executed it yet. 3) Pending write (+ by addPendingWrite(), - by completedWrite()): GrContext has scheduled a write to the resource by the GPU as a result of a skia API call but hasn't executed it yet.
The latter two ref types are private and intended only for Gr core code.
When all the ref/io counts reach zero DERIVED::notifyAllCntsAreZero() will be called (static poly morphism using CRTP). Similarly when the ref (but not necessarily pending read/write) count reaches 0 DERIVED::notifyRefCountIsZero() will be called. In the case when an unref() causes both the ref cnt to reach zero and the other counts are zero, notifyRefCountIsZero() will be called before notifyIsPurgeable(). Moreover, if notifyRefCountIsZero() returns false then notifyAllRefCntsAreZero() won't be called at all. notifyRefCountIsZero() must return false if the object may be deleted after notifyRefCntIsZero() returns.
GrIORef and GrGpuResource are separate classes for organizational reasons and to be able to give access via friendship to only the functions related to pending IO operations.