| Flutter Impeller |

Public Member Functions | Protected Member Functions | List of all members
impeller::Allocator Class Referenceabstract

An object that allocates device memory. More...

`#include <allocator.h>`

Inheritance diagram for impeller::Allocator:

## Public Member Functions
virtual | ~Allocator ()
bool | IsValid () const
std::shared_ptr< DeviceBuffer > | CreateBuffer (const DeviceBufferDescriptor &desc)
std::shared_ptr< Texture > | CreateTexture (const TextureDescriptor &desc)
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. More...
std::shared_ptr< DeviceBuffer > | CreateBufferWithCopy (const uint8_t *buffer, size_t length)
std::shared_ptr< DeviceBuffer > | CreateBufferWithCopy (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. More...
virtual Bytes | DebugGetHeapUsage () const

## Protected Member Functions
| Allocator ()
virtual std::shared_ptr< DeviceBuffer > | OnCreateBuffer (const DeviceBufferDescriptor &desc)=0
virtual std::shared_ptr< Texture > | OnCreateTexture (const TextureDescriptor &desc)=0

## Detailed Description

An object that allocates device memory.

Definition at line 24 of file allocator.h.

## Constructor & Destructor Documentation

## ◆ ~Allocator()

impeller::Allocator::~Allocator | ( |  | ) |
| virtual default

## ◆ Allocator()

impeller::Allocator::Allocator | ( |  | ) |
| protected default

## 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 }
impeller::Allocator::OnCreateBuffer
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 }
impeller::Allocator::CreateBufferWithCopy
std::shared_ptr< DeviceBuffer > CreateBufferWithCopy(const uint8_t *buffer, size_t length)
Definition: allocator.cc:18

References CreateBufferWithCopy().

## ◆ 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 }
impeller::Allocator::CreateBuffer
std::shared_ptr< DeviceBuffer > CreateBuffer(const DeviceBufferDescriptor &desc)
Definition: allocator.cc:44
impeller::StorageMode::kHostVisible
@ kHostVisible

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

Referenced by CreateBufferWithCopy().

## ◆ CreateTexture()

std::shared_ptr< Texture > impeller::Allocator::CreateTexture | ( | const TextureDescriptor & | desc | ) |

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);
64 }
65
66 return OnCreateTexture(desc);
67 }
impeller::Allocator::GetMaxTextureSizeSupported
virtual ISize GetMaxTextureSizeSupported() const =0
impeller::Allocator::OnCreateTexture
virtual std::shared_ptr< Texture > OnCreateTexture(const TextureDescriptor &desc)=0
VALIDATION_LOG
#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
| inline virtual

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

Definition at line 56 of file allocator.h.

56 { return Bytes{0}; }
impeller::Bytes
AllocationSize< 1u > Bytes
Definition: allocation_size.h:151

## ◆ DebugTraceMemoryStatistics()

virtual void impeller::Allocator::DebugTraceMemoryStatistics | ( |  | ) | const
| inline virtual

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 53 of file allocator.h.

53 {};

## ◆ GetMaxTextureSizeSupported()

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

Implemented in impeller::testing::TestAllocator, impeller::testing::FlushTestAllocator, and impeller::testing::FailingAllocator.

Referenced by CreateTexture().

## ◆ 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 }
impeller::BytesPerPixelForPixelFormat
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)
Definition: formats.h:466

References impeller::BytesPerPixelForPixelFormat().

## ◆ OnCreateBuffer()

virtual std::shared_ptr<DeviceBuffer> impeller::Allocator::OnCreateBuffer | ( | const DeviceBufferDescriptor & | desc | ) |
| protected pure virtual

Implemented in impeller::testing::TestAllocator, impeller::testing::FlushTestAllocator, and impeller::testing::FailingAllocator.

Referenced by CreateBuffer().

## ◆ OnCreateTexture()

virtual std::shared_ptr<Texture> impeller::Allocator::OnCreateTexture | ( | const TextureDescriptor & | desc | ) |
| protected pure virtual

Implemented in impeller::testing::TestAllocator, impeller::testing::FlushTestAllocator, and impeller::testing::FailingAllocator.

Referenced by CreateTexture().

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

- impeller/core/allocator.h
- impeller/core/allocator.cc