Flutter Engine
The Flutter Engine
Public Member Functions | Private Member Functions | Friends | List of all members
SkRefCntBase Class Reference

#include <SkRefCnt.h>

Inheritance diagram for SkRefCntBase:
ClipTileRenderer SkRefCnt skiagm::ShapeRenderer DebugTileRenderer SolidColorRenderer TextureSetRenderer YUVTextureSetRenderer Benchmark GrColorSpaceXform GrContext_Base GrD3DAlloc GrD3DDescriptorTable GrD3DMemoryAllocator GrD3DResourceState GrGLInterface GrGLProgram GrMtlCommandBuffer GrMtlFramebuffer GrRenderTask GrThreadSafeCache::Trampoline GrThreadSafePipelineBuilder GrVkImageLayout GrVkSecondaryCBDrawContext MtlCompileResult Node PlacedRefCnt PromiseImageCallbackContext RefClass SKPAnimationBench::Animation SkBBoxHierarchy SkBidiFactory SkBlockMemoryRefCnt SkCapabilities SkColorPalette SkColorTable SkContourMeasure SkDataTable SkDevice SkDiscardableMemory::Factory SkDocument SkFlattenable SkFontConfigInterface SkFontMgr SkFontStyleSet SkFuchsiaFontDataCache SkIDChangeListener SkImage SkImageFilterCache SkMesh::IndexBuffer SkMesh::VertexBuffer SkNamedFactorySet SkPicture SkPixelRef SkPngChunkReader SkPtrSet SkRecord SkRuntimeEffect SkSL::DebugTrace SkSVGDOM SkSVGNode SkShapers::Factory SkSpecialImage SkStrikeClient::DiscardableHandleManager SkSurface SkTMaskGamma< R_LUM_BITS, G_LUM_BITS, B_LUM_BITS > SkTestFont SkUnicode SkWGLPbufferContext SkWeakRefCnt Slide SlideDir::Animator Surface ToolUtils::TopoTestNode UrlDataManager::UrlData flutter::DisplayList flutter::DisplayListBuilder flutter::DlImage flutter::DlImageColorSource flutter::DlRTree flutter::DlRuntimeEffect flutter::testing::DlPixelData flutter::testing::TestSkObject sk_gpu_test::FlushFinishTracker skgpu::MutableTextureState skgpu::Plot skgpu::VulkanInterface skgpu::VulkanMemoryAllocator skgpu::ganesh::PathRenderer skgpu::graphite::DrawContext skgpu::graphite::ImageProvider skgpu::graphite::PrecompileBase skgpu::graphite::ResourceCache skgpu::graphite::SharedContext skgpu::graphite::Task skgpu::graphite::TextureProxy skgpu::graphite::VulkanDescriptorPool skia::textlayout::FontCollection skif::Backend skottie::ExpressionEvaluator< T > skottie::ExpressionManager skottie::ExternalLayer skottie::GlyphDecorator skottie::Logger skottie::MarkerObserver skottie::PrecompInterceptor skottie::PropertyObserver skottie::SlotManager skottie::internal::Animator skottie::internal::CustomFont::GlyphCompMapper skresources::ExternalTrackAsset skresources::ImageAsset skresources::ResourceProvider sksg::Node sktext::StrikeForGPU sktext::gpu::Slug sktext::gpu::TextBlob skiagm::OffscreenShapeRenderer skiagm::PathRenderer skiagm::RectRenderer

Public Member Functions

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

Private Member Functions

virtual void internal_dispose () const
 

Friends

class SkWeakRefCnt
 

Detailed Description

SkRefCntBase is the base class for objects that may be shared by multiple objects. 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.

Definition at line 31 of file SkRefCnt.h.

Constructor & Destructor Documentation

◆ SkRefCntBase()

SkRefCntBase::SkRefCntBase ( )
inline

Default construct, initializing the reference count to 1.

Definition at line 35 of file SkRefCnt.h.

35: fRefCnt(1) {}

◆ ~SkRefCntBase()

virtual SkRefCntBase::~SkRefCntBase ( )
inlinevirtual

Destruct, asserting that the reference count is 1.

Definition at line 39 of file SkRefCnt.h.

39 {
40 #ifdef SK_DEBUG
41 SkASSERTF(this->getRefCnt() == 1, "fRefCnt was %d", this->getRefCnt());
42 // illegal value, to catch us if we reuse after delete
43 fRefCnt.store(0, std::memory_order_relaxed);
44 #endif
45 }
#define SkASSERTF(cond, fmt,...)
Definition: SkAssert.h:117

Member Function Documentation

◆ internal_dispose()

virtual void SkRefCntBase::internal_dispose ( ) const
inlineprivatevirtual

Called when the ref count goes to 0.

Definition at line 94 of file SkRefCnt.h.

94 {
95 #ifdef SK_DEBUG
96 SkASSERT(0 == this->getRefCnt());
97 fRefCnt.store(1, std::memory_order_relaxed);
98 #endif
99 delete this;
100 }
#define SkASSERT(cond)
Definition: SkAssert.h:116

◆ ref()

void SkRefCntBase::ref ( ) const
inline

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

Definition at line 62 of file SkRefCnt.h.

62 {
63 SkASSERT(this->getRefCnt() > 0);
64 // No barrier required.
65 (void)fRefCnt.fetch_add(+1, std::memory_order_relaxed);
66 }

◆ unique()

bool SkRefCntBase::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 50 of file SkRefCnt.h.

50 {
51 if (1 == fRefCnt.load(std::memory_order_acquire)) {
52 // The acquire barrier is only really needed if we return true. It
53 // prevents code conditioned on the result of unique() from running
54 // until previous owners are all totally done calling unref().
55 return true;
56 }
57 return false;
58 }

◆ unref()

void SkRefCntBase::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.

Definition at line 72 of file SkRefCnt.h.

72 {
73 SkASSERT(this->getRefCnt() > 0);
74 // A release here acts in place of all releases we "should" have been doing in ref().
75 if (1 == fRefCnt.fetch_add(-1, std::memory_order_acq_rel)) {
76 // Like unique(), the acquire is only needed on success, to make sure
77 // code in internal_dispose() doesn't happen before the decrement.
78 this->internal_dispose();
79 }
80 }
virtual void internal_dispose() const
Definition: SkRefCnt.h:94

Friends And Related Function Documentation

◆ SkWeakRefCnt

friend class SkWeakRefCnt
friend

Definition at line 104 of file SkRefCnt.h.


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