Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
GrMtlBuffer Class Reference

#include <GrMtlBuffer.h>

Inheritance diagram for GrMtlBuffer:
GrGpuBuffer GrGpuResource GrBuffer GrIORef< GrGpuResource > SkNoncopyable

Public Member Functions

 ~GrMtlBuffer () override
 
id< MTLBuffer > mtlBuffer () const
 
- Public Member Functions inherited from GrGpuBuffer
GrAccessPattern accessPattern () const
 
size_t size () const final
 
void ref () const final
 
void unref () const final
 
void * map ()
 
void unmap ()
 
bool isMapped () const
 
bool isCpuBuffer () const final
 
bool clearToZero ()
 
bool updateData (const void *src, size_t offset, size_t size, bool preserve)
 
GrGpuBufferType intendedType () const
 
- Public Member Functions inherited from GrGpuResource
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
 
- Public Member Functions inherited from GrBuffer
 GrBuffer (const GrBuffer &)=delete
 
GrBufferoperator= (const GrBuffer &)=delete
 
virtual ~GrBuffer ()=default
 
virtual void ref () const =0
 
virtual void unref () const =0
 
virtual size_t size () const =0
 
virtual bool isCpuBuffer () const =0
 

Static Public Member Functions

static sk_sp< GrMtlBufferMake (GrMtlGpu *, size_t size, GrGpuBufferType intendedType, GrAccessPattern)
 
- Static Public Member Functions inherited from GrGpuBuffer
static void ComputeScratchKeyForDynamicBuffer (size_t size, GrGpuBufferType, skgpu::ScratchKey *)
 
- Static Public Member Functions inherited from GrGpuResource
static uint32_t CreateUniqueID ()
 

Protected Member Functions

 GrMtlBuffer (GrMtlGpu *, size_t size, GrGpuBufferType intendedType, GrAccessPattern, std::string_view label)
 
void onAbandon () override
 
void onRelease () override
 
- Protected Member Functions inherited from GrGpuBuffer
 GrGpuBuffer (GrGpu *, size_t sizeInBytes, GrGpuBufferType, GrAccessPattern, std::string_view label)
 
- Protected Member Functions inherited from GrGpuResource
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
 
- Protected Member Functions inherited from GrBuffer
 GrBuffer ()=default
 

Additional Inherited Members

- Public Types inherited from GrIORef< GrGpuResource >
enum  LastRemovedRef
 
- Protected Types inherited from GrGpuBuffer
enum class  MapType { kRead , kWriteDiscard }
 
- Protected Attributes inherited from GrGpuBuffer
void * fMapPtr
 

Detailed Description

Definition at line 19 of file GrMtlBuffer.h.

Constructor & Destructor Documentation

◆ ~GrMtlBuffer()

GrMtlBuffer::~GrMtlBuffer ( )
override

Definition at line 81 of file GrMtlBuffer.mm.

81 {
82 SkASSERT(!fMtlBuffer);
84}
#define SkASSERT(cond)
Definition: SkAssert.h:116
void * fMapPtr
Definition: GrGpuBuffer.h:119

◆ GrMtlBuffer()

GrMtlBuffer::GrMtlBuffer ( GrMtlGpu gpu,
size_t  size,
GrGpuBufferType  intendedType,
GrAccessPattern  accessPattern,
std::string_view  label 
)
protected

Definition at line 49 of file GrMtlBuffer.mm.

51 : INHERITED(gpu, size, intendedType, accessPattern, label)
52 , fIsDynamic(accessPattern != kStatic_GrAccessPattern) {
53 NSUInteger options = 0;
54 if (@available(macOS 10.11, iOS 9.0, tvOS 9.0, *)) {
55 if (fIsDynamic) {
56#ifdef SK_BUILD_FOR_MAC
57 if (gpu->mtlCaps().isMac()) {
58 options |= MTLResourceStorageModeManaged;
59 } else {
60 options |= MTLResourceStorageModeShared;
61 }
62#else
63 options |= MTLResourceStorageModeShared;
64#endif
65 } else {
66 options |= MTLResourceStorageModePrivate;
67 }
68 }
69
71 fMtlBuffer = size == 0 ? nil :
72 [gpu->device() newBufferWithLength: size
74#ifdef SK_ENABLE_MTL_DEBUG_INFO
75 fMtlBuffer.label = kBufferTypeNames[(int)intendedType];
76#endif
78 VALIDATE();
79}
const char * options
#define VALIDATE()
Definition: GrMtlBuffer.mm:22
@ kStatic_GrAccessPattern
Definition: GrTypesPriv.h:428
static constexpr size_t SkAlignTo(size_t x, size_t alignment)
Definition: SkAlign.h:33
size_t size() const final
Definition: GrGpuBuffer.h:34
GrGpuBufferType intendedType() const
Definition: GrGpuBuffer.h:99
GrAccessPattern accessPattern() const
Definition: GrGpuBuffer.h:32
void registerWithCache(skgpu::Budgeted)
bool isMac() const
Definition: GrMtlCaps.h:89
size_t getMinBufferAlignment() const
Definition: GrMtlCaps.h:92
const GrMtlCaps & mtlCaps() const
Definition: GrMtlGpu.h:47
id< MTLDevice > device() const
Definition: GrMtlGpu.h:49

Member Function Documentation

◆ Make()

GR_NORETAIN_BEGIN sk_sp< GrMtlBuffer > GrMtlBuffer::Make ( GrMtlGpu gpu,
size_t  size,
GrGpuBufferType  intendedType,
GrAccessPattern  accessPattern 
)
static

Definition at line 38 of file GrMtlBuffer.mm.

41 {
42 return sk_sp<GrMtlBuffer>(new GrMtlBuffer(gpu,
43 size,
46 /*label=*/"MakeMtlBuffer"));
47}
GrMtlBuffer(GrMtlGpu *, size_t size, GrGpuBufferType intendedType, GrAccessPattern, std::string_view label)
Definition: GrMtlBuffer.mm:49

◆ mtlBuffer()

id< MTLBuffer > GrMtlBuffer::mtlBuffer ( ) const
inline

Definition at line 28 of file GrMtlBuffer.h.

28{ return fMtlBuffer; }

◆ onAbandon()

void GrMtlBuffer::onAbandon ( )
overrideprotectedvirtual

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 from GrGpuResource.

Definition at line 135 of file GrMtlBuffer.mm.

135 {
136 fMtlBuffer = nil;
137 fMapPtr = nullptr;
138 VALIDATE();
140}
virtual void onAbandon()

◆ onRelease()

void GrMtlBuffer::onRelease ( )
overrideprotectedvirtual

Overridden to free GPU resources in the backend API.

Reimplemented from GrGpuResource.

Definition at line 142 of file GrMtlBuffer.mm.

142 {
143 if (!this->wasDestroyed()) {
144 VALIDATE();
145 fMtlBuffer = nil;
146 fMapPtr = nullptr;
147 VALIDATE();
148 }
150}
bool wasDestroyed() const
virtual void onRelease()

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