Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | List of all members
GrManagedResource Class Referenceabstract

#include <GrManagedResource.h>

Inheritance diagram for GrManagedResource:
SkNoncopyable GrD3DCommandSignature GrD3DPipeline GrD3DRootSignature GrMtlDepthStencil GrMtlEvent GrMtlRenderPipeline GrMtlSampler GrRecycledResource GrTextureResource GrVkManagedResource

Public Member Functions

 GrManagedResource ()
 
virtual ~GrManagedResource ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Private Member Functions

virtual void freeGPUData () const =0
 

Detailed Description

GrManagedResource is the base class for GPU resources that may be shared by multiple objects, in particular objects that are tracked by a command buffer. When an existing owner wants to share a reference, it calls ref(). When an owner wants to release its reference, it calls unref(). When the shared object's reference count goes to zero as the result of an unref() call, its (virtual) destructor is called. It is an error for the destructor to be called explicitly (or via the object going out of scope on the stack or calling delete) if getRefCnt() > 1.

This is nearly identical to SkRefCntBase. The exceptions are that unref() takes a GrGpu, and any derived classes must implement freeGPUData().

Definition at line 39 of file GrManagedResource.h.

Constructor & Destructor Documentation

◆ GrManagedResource()

GrManagedResource::GrManagedResource ( )
inline

Default construct, initializing the reference count to 1.

Definition at line 80 of file GrManagedResource.h.

80 : fRefCnt(1) {
81#ifdef SK_TRACE_MANAGED_RESOURCES
82 fKey = fKeyCounter.fetch_add(+1, std::memory_order_relaxed);
83 GetTrace()->add(this);
84#endif
85 }

◆ ~GrManagedResource()

virtual GrManagedResource::~GrManagedResource ( )
inlinevirtual

Destruct, asserting that the reference count is 1.

Definition at line 89 of file GrManagedResource.h.

89 {
90#ifdef SK_DEBUG
91 auto count = this->getRefCnt();
92 SkASSERTF(count == 1, "fRefCnt was %d", count);
93 fRefCnt.store(0); // illegal value, to catch us if we reuse after delete
94#endif
95 }
int count
#define SkASSERTF(cond, fmt,...)
Definition SkAssert.h:117

Member Function Documentation

◆ freeGPUData()

virtual void GrManagedResource::freeGPUData ( ) const
privatepure virtual

◆ ref()

void GrManagedResource::ref ( ) const
inline

Increment the reference count. Must be balanced by a call to unref() or unrefAndFreeResources().

Definition at line 115 of file GrManagedResource.h.

115 {
116 // No barrier required.
117 SkDEBUGCODE(int newRefCount = )fRefCnt.fetch_add(+1, std::memory_order_relaxed);
118 SkASSERT(newRefCount >= 1);
119 }
#define SkASSERT(cond)
Definition SkAssert.h:116
#define SkDEBUGCODE(...)
Definition SkDebug.h:23
Definition ref_ptr.h:256

◆ unique()

bool GrManagedResource::unique ( ) const
inline

May return true if the caller is the only owner. Ensures that all previous owner's actions are complete.

Definition at line 105 of file GrManagedResource.h.

105 {
106 // The acquire barrier is only really needed if we return true. It
107 // prevents code conditioned on the result of unique() from running
108 // until previous owners are all totally done calling unref().
109 return 1 == fRefCnt.load(std::memory_order_acquire);
110 }

◆ unref()

void GrManagedResource::unref ( ) const
inline

Decrement the reference count. If the reference count is 1 before the decrement, then delete the object. Note that if this is the case, then the object needs to have been allocated via new, and not on the stack. Any GPU data associated with this resource will be freed before it's deleted.

Definition at line 126 of file GrManagedResource.h.

126 {
127 // A release here acts in place of all releases we "should" have been doing in ref().
128 int newRefCount = fRefCnt.fetch_add(-1, std::memory_order_acq_rel);
129 SkASSERT(newRefCount >= 0);
130 if (newRefCount == 1) {
131 // Like unique(), the acquire is only needed on success, to make sure
132 // code in internal_dispose() doesn't happen before the decrement.
133 this->internal_dispose();
134 }
135 }

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