Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GrGpuResourceRef Class Reference

This class is intended only for internal use in core Gr code. More...

#include <GrGpuResourceRef.h>

Inheritance diagram for GrGpuResourceRef:
GrTGpuResourceRef< T > GrTGpuResourceRef< GrBuffer > GrTGpuResourceRef< GrRenderTarget > GrTGpuResourceRef< GrTexture >

Public Member Functions

GrGpuResourcegetResource () const
 
bool ownsPendingIO () const
 Does this object own a pending read or write on the resource it is wrapping. More...
 
void reset ()
 Shortcut for calling setResource() with NULL. More...
 

Protected Member Functions

 GrGpuResourceRef (GrGpuResource *, GrIOType)
 Adopts a ref from the caller. More...
 
void setResource (GrGpuResource *, GrIOType)
 Adopts a ref from the caller. More...
 

Private Types

typedef SkNoncopyable INHERITED
 

Private Member Functions

void markPendingIO () const
 Called by owning GrProgramElement when the program element is first scheduled for execution. More...
 
void removeRef () const
 Called when the program element/draw state is no longer owned by GrDrawTarget-client code. More...
 
void pendingIOComplete () const
 Called to indicate that the previous pending IO is complete. More...
 

Private Attributes

GrGpuResourcefResource
 
bool fOwnRef
 
bool fPendingIO
 
GrIOType fIOType
 

Friends

class GrProgramElement
 

Detailed Description

This class is intended only for internal use in core Gr code.

Class that wraps a resource referenced by a GrProgramElement or GrDrawState. It manages converting refs to pending IO operations. It allows a resource ownership to be in three states:

  1. Owns a single ref
  2. Owns a single ref and a pending IO operation (read, write, or read-write)
  3. Owns a single pending IO operation.

It is legal to destroy the GrGpuResourceRef in any of these states. It starts in state

  1. Calling markPendingIO() converts it from state 1 to state 2. Calling removeRef() goes from state 2 to state 3. Calling pendingIOComplete() moves from state 2 to state 1. There is no valid way of going from state 3 back to 2 or 1.

Like SkAutoTUnref, its constructor and setter adopt a ref from their caller.

TODO: Once GrDODrawState no longer exists and therefore GrDrawState and GrOptDrawState no longer share an instance of this class, attempt to make the resource owned by GrGpuResourceRef only settable via the constructor.

Constructor & Destructor Documentation

GrGpuResourceRef::GrGpuResourceRef ( GrGpuResource ,
GrIOType   
)
protected

Adopts a ref from the caller.

ioType expresses what type of IO operations will be marked as pending on the resource when markPendingIO is called.

Member Function Documentation

void GrGpuResourceRef::markPendingIO ( ) const
private

Called by owning GrProgramElement when the program element is first scheduled for execution.

It can only be called once.

bool GrGpuResourceRef::ownsPendingIO ( ) const
inline

Does this object own a pending read or write on the resource it is wrapping.

void GrGpuResourceRef::pendingIOComplete ( ) const
private

Called to indicate that the previous pending IO is complete.

Useful when the owning object still has refs, so it is not about to destroy this GrGpuResourceRef, but its previously pending executions have been complete. Can only be called if removeRef() was not previously called.

void GrGpuResourceRef::removeRef ( ) const
private

Called when the program element/draw state is no longer owned by GrDrawTarget-client code.

This lets the cache know that the drawing code will no longer schedule additional reads or writes to the resource using the program element or draw state. It can only be called once.

void GrGpuResourceRef::reset ( )

Shortcut for calling setResource() with NULL.

It cannot be called after markingPendingIO is called.

void GrGpuResourceRef::setResource ( GrGpuResource ,
GrIOType   
)
protected

Adopts a ref from the caller.

ioType expresses what type of IO operations will be marked as pending on the resource when markPendingIO is called.


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