| Flutter Impeller |

Classes | 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 capacity of the HostBuffer in memory in bytes. More...
size_t | GetLength () const
| Returns the size of the currently allocated HostBuffer memory in bytes. More...
Public Member Functions inherited from impeller::Buffer
virtual | ~Buffer ()

## Static Public Member Functions
static std::shared_ptr< HostBuffer > | Create ()

## 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 96 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 85 of file host_buffer.h.

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

Referenced by impeller::Geometry::ComputePositionGeometry(), impeller::Geometry::ComputePositionUVGeometry(), 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 auto [device_buffer, range] = state_->Emplace(buffer, length, align);
34 if (!device_buffer) {
35 return {};
36 }
37 return BufferView{state_, device_buffer, range};
38 }

## ◆ 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 48 of file host_buffer.cc.

50 {
51 auto [buffer, range] = state_->Emplace(length, align, cb);
52 if (!buffer) {
53 return {};
54 }
55 return BufferView{state_, buffer, range};
56 }

## ◆ 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 63 of file host_buffer.h.

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

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 41 of file host_buffer.h.

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

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().

## ◆ GetLength()

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

Returns the size of the currently allocated HostBuffer memory in bytes.

Definition at line 71 of file host_buffer.cc.

71 {
72 return state_->GetLength();
73 }

## ◆ GetSize()

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

Returns the capacity of the HostBuffer in memory in bytes.

Definition at line 67 of file host_buffer.cc.

67 {
68 return state_->GetReservedLength();
69 }

## ◆ Reset()

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

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

Definition at line 63 of file host_buffer.cc.

63 {
64 state_->Reset();
65 }

## ◆ SetLabel()

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

Definition at line 26 of file host_buffer.cc.

26 {
27 state_->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:15
impeller::HostBuffer::Emplace
BufferView Emplace(const BufferType &buffer)
Emplace non-uniform data (like contiguous vertices) onto the host buffer.
Definition: host_buffer.h:85