5 #ifndef FLUTTER_IMPELLER_CORE_HOST_BUFFER_H_
6 #define FLUTTER_IMPELLER_CORE_HOST_BUFFER_H_
13 #include <type_traits>
30 static std::shared_ptr<HostBuffer>
Create(
31 const std::shared_ptr<Allocator>& allocator);
48 template <
class UniformType,
49 class = std::enable_if_t<std::is_standard_layout_v<UniformType>>>
51 const auto alignment =
53 return Emplace(
reinterpret_cast<const void*
>(&uniform),
70 class StorageBufferType,
71 class = std::enable_if_t<std::is_standard_layout_v<StorageBufferType>>>
73 const StorageBufferType& buffer) {
74 const auto alignment =
77 sizeof(StorageBufferType),
92 template <
class BufferType,
93 class = std::enable_if_t<std::is_standard_layout_v<BufferType>>>
95 return Emplace(
reinterpret_cast<const void*
>(&buffer),
137 [[nodiscard]] std::tuple<Range, std::shared_ptr<DeviceBuffer>>
138 EmplaceInternal(
const void* buffer,
size_t length);
140 std::tuple<Range, std::shared_ptr<DeviceBuffer>>
141 EmplaceInternal(
size_t length,
size_t align,
const EmplaceProc& cb);
143 std::tuple<Range, std::shared_ptr<DeviceBuffer>>
144 EmplaceInternal(
const void* buffer,
size_t length,
size_t align);
146 size_t GetLength()
const {
return offset_; }
148 void MaybeCreateNewBuffer();
150 std::shared_ptr<DeviceBuffer>& GetCurrentBuffer() {
151 return device_buffers_[frame_index_][current_buffer_];
154 [[nodiscard]] BufferView
Emplace(
const void* buffer,
size_t length);
156 explicit HostBuffer(
const std::shared_ptr<Allocator>& allocator);
158 HostBuffer(
const HostBuffer&) =
delete;
160 HostBuffer& operator=(
const HostBuffer&) =
delete;
162 std::shared_ptr<Allocator> allocator_;
165 size_t current_buffer_ = 0u;
167 size_t frame_index_ = 0u;
173 #endif // FLUTTER_IMPELLER_CORE_HOST_BUFFER_H_