| Flutter Impeller |

Public Types | Public Member Functions | Static Public Member Functions | List of all members
impeller::HostBuffer Class Referencefinal

`#include <host_buffer.h>`

Inheritance diagram for impeller::HostBuffer:

## Public Types
using | EmplaceProc = std::function< void(uint8_t *buffer)>

## Public Member Functions
virtual | ~HostBuffer ()
void | SetLabel (std::string label)
template<class UniformType , class = std::enable_if_t<std::is_standard_layout_v<UniformType>>>
BufferView | EmplaceUniform (const UniformType &uniform)
| Emplace uniform data onto the host buffer. Ensure that backend specific uniform alignment requirements are respected. More...
template<class StorageBufferType , class = std::enable_if_t<std::is_standard_layout_v<StorageBufferType>>>
BufferView | EmplaceStorageBuffer (const StorageBufferType &buffer)
| Emplace storage buffer data onto the host buffer. Ensure that backend specific uniform alignment requirements are respected. More...
template<class BufferType , class = std::enable_if_t<std::is_standard_layout_v<BufferType>>>
BufferView | Emplace (const BufferType &buffer)
| Emplace non-uniform data (like contiguous vertices) onto the host buffer. More...
BufferView | Emplace (const void *buffer, size_t length, size_t align)
BufferView | Emplace (size_t length, size_t align, const EmplaceProc &cb)
| Emplaces undefined data onto the managed buffer and gives the caller a chance to update it using the specified callback. The buffer is guaranteed to have enough space for length bytes. It is the responsibility of the caller to not exceed the bounds of the buffer returned in the EmplaceProc. More...
void | Reset ()
| Resets the contents of the HostBuffer to nothing so it can be reused. More...
size_t | GetSize () const
| Returns the size of the HostBuffer in memory in bytes. More...
Public Member Functions inherited from impeller::Allocation
| Allocation ()
| ~Allocation ()
uint8_t * | GetBuffer () const
size_t | GetLength () const
size_t | GetReservedLength () const
bool | Truncate (size_t length, bool npot=true)
Public Member Functions inherited from impeller::Buffer
virtual | ~Buffer ()

## Static Public Member Functions
static std::shared_ptr< HostBuffer > | Create ()
Static Public Member Functions inherited from impeller::Allocation
static uint32_t | NextPowerOfTwoSize (uint32_t x)

## Detailed Description

Definition at line 20 of file host_buffer.h.

## Member Typedef Documentation

## ◆ EmplaceProc

using impeller::HostBuffer::EmplaceProc = std::function<void(uint8_t* buffer)>

Definition at line 98 of file host_buffer.h.

## Constructor & Destructor Documentation

## ◆ ~HostBuffer()

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

## Member Function Documentation

## ◆ Create()

std::shared_ptr< HostBuffer > impeller::HostBuffer::Create | ( |  | ) |
| static

Definition at line 18 of file host_buffer.cc.

18 {
19 return std::shared_ptr<HostBuffer>(new HostBuffer());
20 }

Referenced by impeller::testing::TEST().

## ◆ Emplace() [1/3]

template<class BufferType , class = std::enable_if_t<std::is_standard_layout_v<BufferType>>>

BufferView impeller::HostBuffer::Emplace | ( | const BufferType & | buffer | ) |
| inline

Emplace non-uniform data (like contiguous vertices) onto the host buffer.

Parameters

  [in] | buffer | The buffer data.

Template Parameters

  BufferType | The type of the buffer data.

Returns
  The buffer view.

Definition at line 87 of file host_buffer.h.

87 {
88 return Emplace(reinterpret_cast<const void*>(&buffer), // buffer
89 sizeof(BufferType), // size
90 alignof(BufferType) // alignment
91 );
92 }

Referenced by Emplace(), EmplaceStorageBuffer(), EmplaceUniform(), impeller::RuntimeEffectContents::Render(), and impeller::TextContents::Render().

## ◆ Emplace() [2/3]

BufferView impeller::HostBuffer::Emplace | ( | const void * | buffer,
|  | size_t | length,
|  | size_t | align
| ) |  |

Definition at line 30 of file host_buffer.cc.

32 {
33 if (align == 0 || (GetLength() % align) == 0) {
34 return Emplace(buffer, length);
35 }
36
37 {
38 auto pad = Emplace(nullptr, align - (GetLength() % align));
39 if (!pad) {
40 return {};
41 }
42 }
43
44 return Emplace(buffer, length);
45 }

References Emplace(), and impeller::Allocation::GetLength().

## ◆ Emplace() [3/3]

BufferView impeller::HostBuffer::Emplace | ( | size_t | length,
|  | size_t | align,
|  | const EmplaceProc & | cb
| ) |  |

Emplaces undefined data onto the managed buffer and gives the caller a chance to update it using the specified callback. The buffer is guaranteed to have enough space for length bytes. It is the responsibility of the caller to not exceed the bounds of the buffer returned in the EmplaceProc.

Parameters

  [in] | cb | A callback that will be passed a ptr to the underlying host buffer.

Returns
  The buffer view.

Definition at line 59 of file host_buffer.cc.

61 {
62 if (!cb) {
63 return {};
64 }
65 auto old_length = GetLength();
66 if (!Truncate(old_length + length)) {
67 return {};
68 }
69 generation_++;
70 cb(GetBuffer() + old_length);
71
72 return BufferView{shared_from_this(), GetBuffer(), Range{old_length, length}};
73 }

References impeller::Allocation::GetBuffer(), impeller::Allocation::GetLength(), and impeller::Allocation::Truncate().

## ◆ EmplaceStorageBuffer()

template<class StorageBufferType , class = std::enable_if_t<std::is_standard_layout_v<StorageBufferType>>>

BufferView impeller::HostBuffer::EmplaceStorageBuffer | ( | const StorageBufferType & | buffer | ) |
| inline

Emplace storage buffer data onto the host buffer. Ensure that backend specific uniform alignment requirements are respected.

Parameters

  [in] | uniform | The storage buffer to emplace onto the buffer.

Template Parameters

  StorageBufferType | The type of the shader storage buffer.

Returns
  The buffer view.

Definition at line 65 of file host_buffer.h.

66 {
67 const auto alignment =
68 std::max(alignof(StorageBufferType), DefaultUniformAlignment());
69 return Emplace(&buffer, // buffer
70 sizeof(StorageBufferType), // size
71 alignment // alignment
72 );
73 }

References impeller::DefaultUniformAlignment(), and Emplace().

Referenced by impeller::testing::TEST_P().

## ◆ EmplaceUniform()

template<class UniformType , class = std::enable_if_t<std::is_standard_layout_v<UniformType>>>

BufferView impeller::HostBuffer::EmplaceUniform | ( | const UniformType & | uniform | ) |
| inline

Emplace uniform data onto the host buffer. Ensure that backend specific uniform alignment requirements are respected.

Parameters

  [in] | uniform | The uniform struct to emplace onto the buffer.

Template Parameters

  UniformType | The type of the uniform struct.

Returns
  The buffer view.

Definition at line 43 of file host_buffer.h.

43 {
44 const auto alignment =
45 std::max(alignof(UniformType), DefaultUniformAlignment());
46 return Emplace(reinterpret_cast<const void*>(&uniform), // buffer
47 sizeof(UniformType), // size
48 alignment // alignment
49 );
50 }

References impeller::DefaultUniformAlignment(), and Emplace().

Referenced by impeller::scene::CuboidGeometry::BindToCommand(), impeller::scene::UnlitMaterial::BindToCommand(), impeller::scene::UnskinnedVertexBufferGeometry::BindToCommand(), impeller::scene::SkinnedVertexBufferGeometry::BindToCommand(), ImGui_ImplImpeller_RenderDrawData(), impeller::RuntimeEffectContents::Render(), impeller::ClipContents::Render(), impeller::SolidRRectBlurContents::Render(), impeller::SolidColorContents::Render(), impeller::TextContents::Render(), impeller::ClipRestoreContents::Render(), and impeller::testing::TEST_P().

## ◆ GetSize()

size_t impeller::HostBuffer::GetSize | ( |  | ) | const

Returns the size of the HostBuffer in memory in bytes.

Definition at line 97 of file host_buffer.cc.

97 {
98 return GetReservedLength();
99 }

References impeller::Allocation::GetReservedLength().

## ◆ Reset()

void impeller::HostBuffer::Reset | ( |  | ) |

Resets the contents of the HostBuffer to nothing so it can be reused.

Definition at line 90 of file host_buffer.cc.

90 {
91 generation_ += 1;
92 device_buffer_ = nullptr;
93 bool did_truncate = Truncate(0);
94 FML_CHECK(did_truncate);
95 }

References impeller::Allocation::Truncate().

## ◆ SetLabel()

void impeller::HostBuffer::SetLabel | ( | std::string | label | ) |

Definition at line 26 of file host_buffer.cc.

26 {
27 label_ = std::move(label);
28 }

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

- impeller/core/host_buffer.h
- impeller/core/host_buffer.cc

impeller::DefaultUniformAlignment
constexpr size_t DefaultUniformAlignment()
Definition: platform.h:14
impeller::HostBuffer::Emplace
BufferView Emplace(const BufferType &buffer)
Emplace non-uniform data (like contiguous vertices) onto the host buffer.
Definition: host_buffer.h:87
impeller::Allocation::GetReservedLength
size_t GetReservedLength() const
Definition: allocation.cc:29
impeller::Allocation::GetLength
size_t GetLength() const
Definition: allocation.cc:25
impeller::Allocation::GetBuffer
uint8_t * GetBuffer() const
Definition: allocation.cc:21
impeller::Allocation::Truncate
bool Truncate(size_t length, bool npot=true)
Definition: allocation.cc:33