Flutter Engine
 
Loading...
Searching...
No Matches
impeller::Allocator Class Referenceabstract

An object that allocates device memory. More...

#include <allocator.h>

Inheritance diagram for impeller::Allocator:
impeller::AllocatorGLES impeller::AllocatorMTL impeller::AllocatorVK impeller::TestImpellerAllocator impeller::testing::FailingAllocator impeller::testing::FlushTestAllocator impeller::testing::MockAllocator impeller::testing::TestAllocator

Public Member Functions

virtual ~Allocator ()
 
bool IsValid () const
 
std::shared_ptr< DeviceBufferCreateBuffer (const DeviceBufferDescriptor &desc)
 
std::shared_ptr< TextureCreateTexture (const TextureDescriptor &desc, bool threadsafe=false)
 Creates a new texture.
 
virtual uint16_t MinimumBytesPerRow (PixelFormat format) const
 Minimum value for row_bytes on a Texture. The row bytes parameter of that method must be aligned to this value.
 
std::shared_ptr< DeviceBufferCreateBufferWithCopy (const uint8_t *buffer, size_t length)
 
std::shared_ptr< DeviceBufferCreateBufferWithCopy (const fml::Mapping &mapping)
 
virtual ISize GetMaxTextureSizeSupported () const =0
 
virtual void DebugTraceMemoryStatistics () const
 Write debug memory usage information to the dart timeline in debug and profile modes.
 
virtual Bytes DebugGetHeapUsage () const
 

Protected Member Functions

 Allocator ()
 
virtual std::shared_ptr< DeviceBufferOnCreateBuffer (const DeviceBufferDescriptor &desc)=0
 
virtual std::shared_ptr< TextureOnCreateTexture (const TextureDescriptor &desc, bool threadsafe=false)=0
 

Detailed Description

An object that allocates device memory.

Definition at line 24 of file allocator.h.

Constructor & Destructor Documentation

◆ ~Allocator()

impeller::Allocator::~Allocator ( )
virtualdefault

◆ Allocator()

impeller::Allocator::Allocator ( )
protecteddefault

Member Function Documentation

◆ CreateBuffer()

std::shared_ptr< DeviceBuffer > impeller::Allocator::CreateBuffer ( const DeviceBufferDescriptor desc)

Definition at line 44 of file allocator.cc.

45 {
46 return OnCreateBuffer(desc);
47}
virtual std::shared_ptr< DeviceBuffer > OnCreateBuffer(const DeviceBufferDescriptor &desc)=0

References OnCreateBuffer().

Referenced by CreateBufferWithCopy().

◆ CreateBufferWithCopy() [1/2]

std::shared_ptr< DeviceBuffer > impeller::Allocator::CreateBufferWithCopy ( const fml::Mapping mapping)

Definition at line 39 of file allocator.cc.

40 {
41 return CreateBufferWithCopy(mapping.GetMapping(), mapping.GetSize());
42}
virtual const uint8_t * GetMapping() const =0
virtual size_t GetSize() const =0
std::shared_ptr< DeviceBuffer > CreateBufferWithCopy(const uint8_t *buffer, size_t length)
Definition allocator.cc:18

References CreateBufferWithCopy(), fml::Mapping::GetMapping(), and fml::Mapping::GetSize().

◆ CreateBufferWithCopy() [2/2]

std::shared_ptr< DeviceBuffer > impeller::Allocator::CreateBufferWithCopy ( const uint8_t *  buffer,
size_t  length 
)

Definition at line 18 of file allocator.cc.

20 {
21 DeviceBufferDescriptor desc;
22 desc.size = length;
23 desc.storage_mode = StorageMode::kHostVisible;
24 auto new_buffer = CreateBuffer(desc);
25
26 if (!new_buffer) {
27 return nullptr;
28 }
29
30 auto entire_range = Range{0, length};
31
32 if (!new_buffer->CopyHostBuffer(buffer, entire_range)) {
33 return nullptr;
34 }
35
36 return new_buffer;
37}
std::shared_ptr< DeviceBuffer > CreateBuffer(const DeviceBufferDescriptor &desc)
Definition allocator.cc:44
size_t length

References CreateBuffer(), impeller::kHostVisible, length, impeller::DeviceBufferDescriptor::size, and impeller::DeviceBufferDescriptor::storage_mode.

Referenced by CreateBufferWithCopy().

◆ CreateTexture()

std::shared_ptr< Texture > impeller::Allocator::CreateTexture ( const TextureDescriptor desc,
bool  threadsafe = false 
)

Creates a new texture.

Parameters
[in]descThe descriptor of the texture to create.
[in]threadsafeWhether mutations to this texture should be protected with a threadsafe barrier.

This parameter only affects the OpenGLES rendering backend.

If any interaction with this texture (including creation) will be done on a thread other than where the OpenGLES context resides, then threadsafe, must be set to true.

Definition at line 49 of file allocator.cc.

50 {
51 const auto max_size = GetMaxTextureSizeSupported();
52 if (desc.size.width > max_size.width || desc.size.height > max_size.height) {
53 VALIDATION_LOG << "Requested texture size " << desc.size
54 << " exceeds maximum supported size of " << max_size;
55 return nullptr;
56 }
57
58 if (desc.mip_count > desc.size.MipCount()) {
59 VALIDATION_LOG << "Requested mip_count " << desc.mip_count
60 << " exceeds maximum supported for size " << desc.size;
61 TextureDescriptor corrected_desc = desc;
62 corrected_desc.mip_count = desc.size.MipCount();
63 return OnCreateTexture(corrected_desc, threadsafe);
64 }
65
66 return OnCreateTexture(desc, threadsafe);
67}
virtual std::shared_ptr< Texture > OnCreateTexture(const TextureDescriptor &desc, bool threadsafe=false)=0
virtual ISize GetMaxTextureSizeSupported() const =0
#define VALIDATION_LOG
Definition validation.h:91

References GetMaxTextureSizeSupported(), impeller::TSize< T >::height, impeller::TextureDescriptor::mip_count, impeller::TSize< T >::MipCount(), OnCreateTexture(), impeller::TextureDescriptor::size, VALIDATION_LOG, and impeller::TSize< T >::width.

Referenced by impeller::RenderTarget::SetupDepthStencilAttachments().

◆ DebugGetHeapUsage()

virtual Bytes impeller::Allocator::DebugGetHeapUsage ( ) const
inlinevirtual

Reimplemented in impeller::AllocatorMTL, and impeller::AllocatorVK.

Definition at line 72 of file allocator.h.

72{ return Bytes{0}; }
AllocationSize< 1u > Bytes

◆ DebugTraceMemoryStatistics()

virtual void impeller::Allocator::DebugTraceMemoryStatistics ( ) const
inlinevirtual

Write debug memory usage information to the dart timeline in debug and profile modes.

This is supported on both the Metal and Vulkan backends.

Definition at line 69 of file allocator.h.

69{};

◆ GetMaxTextureSizeSupported()

virtual ISize impeller::Allocator::GetMaxTextureSizeSupported ( ) const
pure virtual

◆ IsValid()

bool impeller::Allocator::IsValid ( ) const

◆ MinimumBytesPerRow()

uint16_t impeller::Allocator::MinimumBytesPerRow ( PixelFormat  format) const
virtual

Minimum value for row_bytes on a Texture. The row bytes parameter of that method must be aligned to this value.

Definition at line 69 of file allocator.cc.

69 {
70 return BytesPerPixelForPixelFormat(format);
71}
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)
Definition formats.h:466

References impeller::BytesPerPixelForPixelFormat(), and format.

◆ OnCreateBuffer()

virtual std::shared_ptr< DeviceBuffer > impeller::Allocator::OnCreateBuffer ( const DeviceBufferDescriptor desc)
protectedpure virtual

◆ OnCreateTexture()

virtual std::shared_ptr< Texture > impeller::Allocator::OnCreateTexture ( const TextureDescriptor desc,
bool  threadsafe = false 
)
protectedpure virtual

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