Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Friends | List of all members
GrGpuResource Class Referenceabstract

#include <GrGpuResource.h>

Inheritance diagram for GrGpuResource:
GrIORef< GrGpuResource > SkNoncopyable BenchResource GrGpuBuffer GrSurface TestResource GrD3DBuffer GrGLBuffer GrMockBuffer GrMtlBuffer GrVkBuffer GrAttachment GrRenderTarget GrTexture

Classes

class  CacheAccess
 
class  ProxyAccess
 
class  ResourcePriv
 
class  UniqueID
 

Public Member Functions

bool wasDestroyed () const
 
const GrDirectContextgetContext () const
 
GrDirectContextgetContext ()
 
size_t gpuMemorySize () const
 
UniqueID uniqueID () const
 
const skgpu::UniqueKeygetUniqueKey () const
 
std::string getLabel () const
 
void setLabel (std::string_view label)
 
CacheAccess cacheAccess ()
 
const CacheAccess cacheAccess () const
 
ProxyAccess proxyAccess ()
 
ResourcePriv resourcePriv ()
 
const ResourcePriv resourcePriv () const
 
virtual void dumpMemoryStatistics (SkTraceMemoryDump *traceMemoryDump) const
 
virtual const char * getResourceType () const =0
 
- Public Member Functions inherited from GrIORef< GrGpuResource >
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
 

Static Public Member Functions

static uint32_t CreateUniqueID ()
 

Protected Member Functions

void registerWithCache (skgpu::Budgeted)
 
void registerWithCacheWrapped (GrWrapCacheable)
 
 GrGpuResource (GrGpu *, std::string_view label)
 
virtual ~GrGpuResource ()
 
GrGpugetGpu () const
 
virtual void onRelease ()
 
virtual void onAbandon ()
 
virtual void setMemoryBacking (SkTraceMemoryDump *, const SkString &) const
 
SkString getResourceName () const
 
void dumpMemoryStatisticsPriv (SkTraceMemoryDump *traceMemoryDump, const SkString &resourceName, const char *type, size_t size) const
 
- Protected Member Functions inherited from GrIORef< GrGpuResource >
 GrIORef ()
 
bool internalHasRef () const
 
bool internalHasNoCommandBufferUsages () const
 
void addInitialRef () const
 

Private Member Functions

virtual void computeScratchKey (skgpu::ScratchKey *) const
 
virtual size_t onGpuMemorySize () const =0
 
virtual void onSetLabel ()=0
 

Friends

class GrIORef< GrGpuResource >
 

Additional Inherited Members

- Public Types inherited from GrIORef< GrGpuResource >
enum  LastRemovedRef
 

Detailed Description

Base class for objects that can be kept in the GrResourceCache.

Definition at line 126 of file GrGpuResource.h.

Constructor & Destructor Documentation

◆ GrGpuResource()

GrGpuResource::GrGpuResource ( GrGpu gpu,
std::string_view  label 
)
protected

Definition at line 27 of file GrGpuResource.cpp.

28 : fGpu(gpu), fUniqueID(CreateUniqueID()), fLabel(label) {
29 SkDEBUGCODE(fCacheArrayIndex = -1);
30}
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
static uint32_t CreateUniqueID()

◆ ~GrGpuResource()

GrGpuResource::~GrGpuResource ( )
protectedvirtual

Definition at line 49 of file GrGpuResource.cpp.

49 {
50 // The cache should have released or destroyed this resource.
51 SkASSERT(this->wasDestroyed());
52}
#define SkASSERT(cond)
Definition: SkAssert.h:116
bool wasDestroyed() const

Member Function Documentation

◆ cacheAccess() [1/2]

GrGpuResource::CacheAccess GrGpuResource::cacheAccess ( )
inline

Definition at line 104 of file GrGpuResourceCacheAccess.h.

104{ return CacheAccess(this); }

◆ cacheAccess() [2/2]

const GrGpuResource::CacheAccess GrGpuResource::cacheAccess ( ) const
inline

Definition at line 106 of file GrGpuResourceCacheAccess.h.

106 { // NOLINT(readability-const-return-type)
107 return CacheAccess(const_cast<GrGpuResource*>(this));
108}

◆ computeScratchKey()

virtual void GrGpuResource::computeScratchKey ( skgpu::ScratchKey ) const
inlineprivatevirtual

Called by the registerWithCache if the resource is available to be used as scratch. Resource subclasses should override this if the instances should be recycled as scratch resources and populate the scratchKey with the key. By default resources are not recycled as scratch.

Reimplemented in GrTexture.

Definition at line 294 of file GrGpuResource.h.

294{}

◆ CreateUniqueID()

uint32_t GrGpuResource::CreateUniqueID ( )
static

Definition at line 210 of file GrGpuResource.cpp.

210 {
211 static std::atomic<uint32_t> nextID{1};
212 uint32_t id;
213 do {
214 id = nextID.fetch_add(1, std::memory_order_relaxed);
215 } while (id == SK_InvalidUniqueID);
216 return id;
217}
static constexpr uint32_t SK_InvalidUniqueID
Definition: SkTypes.h:196
const uintptr_t id

◆ dumpMemoryStatistics()

void GrGpuResource::dumpMemoryStatistics ( SkTraceMemoryDump traceMemoryDump) const
virtual

Dumps memory usage information for this GrGpuResource to traceMemoryDump. Typically, subclasses should not need to override this, and should only need to override setMemoryBacking.

Reimplemented in GrGLRenderTarget, GrGLTexture, and GrGLTextureRenderTarget.

Definition at line 73 of file GrGpuResource.cpp.

73 {
74 if (this->fRefsWrappedObjects && !traceMemoryDump->shouldDumpWrappedObjects()) {
75 return;
76 }
77
78 this->dumpMemoryStatisticsPriv(traceMemoryDump, this->getResourceName(),
79 this->getResourceType(), this->gpuMemorySize());
80}
size_t gpuMemorySize() const
void dumpMemoryStatisticsPriv(SkTraceMemoryDump *traceMemoryDump, const SkString &resourceName, const char *type, size_t size) const
SkString getResourceName() const
virtual const char * getResourceType() const =0
virtual bool shouldDumpWrappedObjects() const

◆ dumpMemoryStatisticsPriv()

void GrGpuResource::dumpMemoryStatisticsPriv ( SkTraceMemoryDump traceMemoryDump,
const SkString resourceName,
const char *  type,
size_t  size 
) const
protected

A helper for subclasses that override dumpMemoryStatistics(). This method using a format consistent with the default implementation of dumpMemoryStatistics() but allows the caller to customize various inputs.

Definition at line 82 of file GrGpuResource.cpp.

84 {
85 const char* tag = "Scratch";
86 if (fUniqueKey.isValid()) {
87 tag = (fUniqueKey.tag() != nullptr) ? fUniqueKey.tag() : "Other";
88 }
89
90 traceMemoryDump->dumpNumericValue(resourceName.c_str(), "size", "bytes", size);
91 traceMemoryDump->dumpStringValue(resourceName.c_str(), "type", type);
92 traceMemoryDump->dumpStringValue(resourceName.c_str(), "label", this->getLabel().c_str());
93 traceMemoryDump->dumpStringValue(resourceName.c_str(), "category", tag);
94 if (this->isPurgeable()) {
95 traceMemoryDump->dumpNumericValue(resourceName.c_str(), "purgeable_size", "bytes", size);
96 }
97 if (traceMemoryDump->shouldDumpWrappedObjects()) {
98 traceMemoryDump->dumpWrappedState(resourceName.c_str(), fRefsWrappedObjects);
99 }
100
101 this->setMemoryBacking(traceMemoryDump, resourceName);
102}
GLenum type
std::string getLabel() const
virtual void setMemoryBacking(SkTraceMemoryDump *, const SkString &) const
const char * c_str() const
Definition: SkString.h:133
virtual void dumpWrappedState(const char *, bool)
virtual void dumpStringValue(const char *, const char *, const char *)
virtual void dumpNumericValue(const char *dumpName, const char *valueName, const char *units, uint64_t value)=0
bool isValid() const
Definition: ResourceKey.h:55
const char * tag() const
Definition: ResourceKey.h:266
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259

◆ getContext() [1/2]

GrDirectContext * GrGpuResource::getContext ( )

Definition at line 133 of file GrGpuResource.cpp.

133 {
134 if (fGpu) {
135 return fGpu->getContext();
136 } else {
137 return nullptr;
138 }
139}
GrDirectContext * getContext()
Definition: GrGpu.h:67

◆ getContext() [2/2]

const GrDirectContext * GrGpuResource::getContext ( ) const

Retrieves the context that owns the object. Note that it is possible for this to return NULL. When objects have been release()ed or abandon()ed they no longer have an owning context. Destroying a GrDirectContext automatically releases all its resources.

Definition at line 125 of file GrGpuResource.cpp.

125 {
126 if (fGpu) {
127 return fGpu->getContext();
128 } else {
129 return nullptr;
130 }
131}

◆ getGpu()

GrGpu * GrGpuResource::getGpu ( ) const
inlineprotected

Definition at line 255 of file GrGpuResource.h.

255{ return fGpu; }

◆ getLabel()

std::string GrGpuResource::getLabel ( ) const
inline

Definition at line 193 of file GrGpuResource.h.

193{ return fLabel; }

◆ getResourceName()

SkString GrGpuResource::getResourceName ( ) const
protected

Returns a string that uniquely identifies this resource.

Definition at line 118 of file GrGpuResource.cpp.

118 {
119 // Dump resource as "skia/gpu_resources/resource_#".
120 SkString resourceName("skia/gpu_resources/resource_");
121 resourceName.appendU32(this->uniqueID().asUInt());
122 return resourceName;
123}
UniqueID uniqueID() const

◆ getResourceType()

virtual const char * GrGpuResource::getResourceType ( ) const
pure virtual

Describes the type of gpu resource that is represented by the implementing class (e.g. texture, buffer object, stencil). This data is used for diagnostic purposes by dumpMemoryStatistics().

The value returned is expected to be long lived and will not be copied by the caller.

◆ getUniqueKey()

const skgpu::UniqueKey & GrGpuResource::getUniqueKey ( ) const
inline

Returns the current unique key for the resource. It will be invalid if the resource has no associated unique key.

Definition at line 191 of file GrGpuResource.h.

191{ return fUniqueKey; }

◆ gpuMemorySize()

size_t GrGpuResource::gpuMemorySize ( ) const
inline

Retrieves the amount of GPU memory used by this resource in bytes. It is approximate since we aren't aware of additional padding or copies made by the driver.

Returns
the amount of GPU memory used in bytes

Definition at line 156 of file GrGpuResource.h.

156 {
157 if (kInvalidGpuMemorySize == fGpuMemorySize) {
158 fGpuMemorySize = this->onGpuMemorySize();
159 SkASSERT(kInvalidGpuMemorySize != fGpuMemorySize);
160 }
161 return fGpuMemorySize;
162 }
virtual size_t onGpuMemorySize() const =0

◆ onAbandon()

virtual void GrGpuResource::onAbandon ( )
inlineprotectedvirtual

Overridden to abandon any internal handles, ptrs, etc to backend API resources. This may be called when the underlying 3D context is no longer valid and so no backend API calls should be made.

Reimplemented in GrD3DAttachment, GrD3DBuffer, GrD3DRenderTarget, GrD3DTexture, GrD3DTextureRenderTarget, GrGLAttachment, GrGLBuffer, GrGLRenderTarget, GrGLTexture, GrGLTextureRenderTarget, GrRenderTarget, GrSurface, GrMockTexture, GrMtlAttachment, GrMtlBuffer, GrMtlRenderTarget, GrMtlTexture, GrMtlTextureRenderTarget, GrVkRenderTarget, GrVkTexture, and GrVkTextureRenderTarget.

Definition at line 262 of file GrGpuResource.h.

262{ }

◆ onGpuMemorySize()

virtual size_t GrGpuResource::onGpuMemorySize ( ) const
privatepure virtual

◆ onRelease()

virtual void GrGpuResource::onRelease ( )
inlineprotectedvirtual

◆ onSetLabel()

virtual void GrGpuResource::onSetLabel ( )
privatepure virtual

◆ proxyAccess()

GrGpuResource::ProxyAccess GrGpuResource::proxyAccess ( )
inline

Definition at line 367 of file GrGpuResource.h.

367{ return ProxyAccess(this); }

◆ registerWithCache()

void GrGpuResource::registerWithCache ( skgpu::Budgeted  budgeted)
protected

Definition at line 32 of file GrGpuResource.cpp.

32 {
34 fBudgetedType = budgeted == skgpu::Budgeted::kYes ? GrBudgetedType::kBudgeted
36 this->computeScratchKey(&fScratchKey);
37 get_resource_cache(fGpu)->resourceAccess().insertResource(this);
38}
static GrResourceCache * get_resource_cache(GrGpu *gpu)
virtual void computeScratchKey(skgpu::ScratchKey *) const
ResourceAccess resourceAccess()

◆ registerWithCacheWrapped()

void GrGpuResource::registerWithCacheWrapped ( GrWrapCacheable  wrapType)
protected

Definition at line 40 of file GrGpuResource.cpp.

40 {
42 // Resources referencing wrapped objects are never budgeted. They may be cached or uncached.
45 fRefsWrappedObjects = true;
46 get_resource_cache(fGpu)->resourceAccess().insertResource(this);
47}

◆ resourcePriv() [1/2]

GrGpuResource::ResourcePriv GrGpuResource::resourcePriv ( )
inline

Definition at line 91 of file GrGpuResourcePriv.h.

91{ return ResourcePriv(this); }

◆ resourcePriv() [2/2]

const GrGpuResource::ResourcePriv GrGpuResource::resourcePriv ( ) const
inline

Definition at line 93 of file GrGpuResourcePriv.h.

93 { // NOLINT(readability-const-return-type)
94 return ResourcePriv(const_cast<GrGpuResource*>(this));
95}

◆ setLabel()

void GrGpuResource::setLabel ( std::string_view  label)
inline

Definition at line 195 of file GrGpuResource.h.

195 {
196 fLabel = label;
197 this->onSetLabel();
198 }
virtual void onSetLabel()=0

◆ setMemoryBacking()

virtual void GrGpuResource::setMemoryBacking ( SkTraceMemoryDump ,
const SkString  
) const
inlineprotectedvirtual

Allows subclasses to add additional backing information to the SkTraceMemoryDump.

Reimplemented in GrGLAttachment, and GrGLBuffer.

Definition at line 267 of file GrGpuResource.h.

267{}

◆ uniqueID()

UniqueID GrGpuResource::uniqueID ( ) const
inline

Gets an id that is unique for this GrGpuResource object. It is static in that it does not change when the content of the GrGpuResource object changes. This will never return 0.

Definition at line 187 of file GrGpuResource.h.

187{ return fUniqueID; }

◆ wasDestroyed()

bool GrGpuResource::wasDestroyed ( ) const
inline

Tests whether a object has been abandoned or released. All objects will be in this state after their creating GrContext is destroyed or has contextLost called. It's up to the client to test wasDestroyed() before attempting to use an object if it holds refs on objects across ~GrContext, freeResources with the force flag, or contextLost.

Returns
true if the object has been released or abandoned, false otherwise.

Definition at line 138 of file GrGpuResource.h.

138{ return nullptr == fGpu; }

Friends And Related Function Documentation

◆ GrIORef< GrGpuResource >

friend class GrIORef< GrGpuResource >
friend

Definition at line 343 of file GrGpuResource.h.


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