Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | List of all members
GrIORef< DERIVED > Class Template Reference

#include <GrGpuResource.h>

Inheritance diagram for GrIORef< DERIVED >:
SkNoncopyable

Public Types

enum class  LastRemovedRef { kMainRef , kCommandBufferUsage }
 

Public Member Functions

bool unique () const
 
void ref () const
 
void unref () const
 
void refCommandBuffer () const
 
void unrefCommandBuffer () const
 
- Public Member Functions inherited from SkNoncopyable
 SkNoncopyable ()=default
 
 SkNoncopyable (SkNoncopyable &&)=default
 
SkNoncopyableoperator= (SkNoncopyable &&)=default
 

Protected Member Functions

 GrIORef ()
 
bool internalHasRef () const
 
bool internalHasNoCommandBufferUsages () const
 
void addInitialRef () const
 

Detailed Description

template<typename DERIVED>
class GrIORef< DERIVED >

Base class for GrGpuResource. Provides the hooks for resources to interact with the cache. Separated out as a base class to isolate the ref-cnting behavior and provide friendship without exposing all of GrGpuResource.

PRIOR to the last ref being removed DERIVED::notifyARefCntWillBeZero() will be called (static poly morphism using CRTP). It is legal for additional ref's to be added during this time. AFTER the ref count reaches zero DERIVED::notifyARefCntIsZero() will be called.

Definition at line 45 of file GrGpuResource.h.

Member Enumeration Documentation

◆ LastRemovedRef

template<typename DERIVED >
enum class GrIORef::LastRemovedRef
strong
Enumerator
kMainRef 
kCommandBufferUsage 

Definition at line 57 of file GrGpuResource.h.

57 {
58 kMainRef, // This refers to fRefCnt
59 kCommandBufferUsage, // This refers to fCommandBufferUsageCnt
60 };

Constructor & Destructor Documentation

◆ GrIORef()

template<typename DERIVED >
GrIORef< DERIVED >::GrIORef ( )
inlineprotected

Definition at line 86 of file GrGpuResource.h.

86: fRefCnt(1), fCommandBufferUsageCnt(0) {}

Member Function Documentation

◆ addInitialRef()

template<typename DERIVED >
void GrIORef< DERIVED >::addInitialRef ( ) const
inlineprotected

Definition at line 94 of file GrGpuResource.h.

94 {
95 SkASSERT(fRefCnt >= 0);
96 // No barrier required.
97 (void)fRefCnt.fetch_add(+1, std::memory_order_relaxed);
98 }
#define SkASSERT(cond)
Definition SkAssert.h:116

◆ internalHasNoCommandBufferUsages()

template<typename DERIVED >
bool GrIORef< DERIVED >::internalHasNoCommandBufferUsages ( ) const
inlineprotected

Definition at line 89 of file GrGpuResource.h.

89 {
90 return SkToBool(this->hasNoCommandBufferUsages());
91 }
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35

◆ internalHasRef()

template<typename DERIVED >
bool GrIORef< DERIVED >::internalHasRef ( ) const
inlineprotected

Definition at line 88 of file GrGpuResource.h.

88{ return SkToBool(this->getRefCnt()); }

◆ ref()

template<typename DERIVED >
void GrIORef< DERIVED >::ref ( ) const
inline

Definition at line 49 of file GrGpuResource.h.

49 {
50 // Only the cache should be able to add the first ref to a resource.
51 SkASSERT(this->getRefCnt() > 0);
52 // No barrier required.
53 (void)fRefCnt.fetch_add(+1, std::memory_order_relaxed);
54 }

◆ refCommandBuffer()

template<typename DERIVED >
void GrIORef< DERIVED >::refCommandBuffer ( ) const
inline

Definition at line 69 of file GrGpuResource.h.

69 {
70 // No barrier required.
71 (void)fCommandBufferUsageCnt.fetch_add(+1, std::memory_order_relaxed);
72 }

◆ unique()

template<typename DERIVED >
bool GrIORef< DERIVED >::unique ( ) const
inline

Definition at line 47 of file GrGpuResource.h.

47{ return fRefCnt == 1; }

◆ unref()

template<typename DERIVED >
void GrIORef< DERIVED >::unref ( ) const
inline

Definition at line 62 of file GrGpuResource.h.

62 {
63 SkASSERT(this->getRefCnt() > 0);
64 if (1 == fRefCnt.fetch_add(-1, std::memory_order_acq_rel)) {
65 this->notifyWillBeZero(LastRemovedRef::kMainRef);
66 }
67 }

◆ unrefCommandBuffer()

template<typename DERIVED >
void GrIORef< DERIVED >::unrefCommandBuffer ( ) const
inline

Definition at line 74 of file GrGpuResource.h.

74 {
75 SkASSERT(!this->hasNoCommandBufferUsages());
76 if (1 == fCommandBufferUsageCnt.fetch_add(-1, std::memory_order_acq_rel)) {
77 this->notifyWillBeZero(LastRemovedRef::kCommandBufferUsage);
78 }
79 }

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