| Flutter Impeller |

Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
impeller::DeviceBuffer Class Referenceabstract

`#include <device_buffer.h>`

Inheritance diagram for impeller::DeviceBuffer:

## Public Member Functions
virtual | ~DeviceBuffer ()
bool | CopyHostBuffer (const uint8_t *source, Range source_range, size_t offset=0u)
virtual bool | SetLabel (const std::string &label)=0
virtual bool | SetLabel (const std::string &label, Range range)=0
virtual std::shared_ptr< Texture > | AsTexture (Allocator &allocator, const TextureDescriptor &descriptor, uint16_t row_bytes) const
const DeviceBufferDescriptor & | GetDeviceBufferDescriptor () const
virtual uint8_t * | OnGetContents () const =0
virtual void | Flush (std::optional< Range > range=std::nullopt) const
virtual void | Invalidate (std::optional< Range > range=std::nullopt) const

## Static Public Member Functions
static BufferView | AsBufferView (std::shared_ptr< DeviceBuffer > buffer)
| Create a buffer view of this entire buffer. More...

## Protected Member Functions
| DeviceBuffer (DeviceBufferDescriptor desc)
virtual bool | OnCopyHostBuffer (const uint8_t *source, Range source_range, size_t offset)=0

## Protected Attributes
const DeviceBufferDescriptor | desc_

## Detailed Description

Definition at line 19 of file device_buffer.h.

## Constructor & Destructor Documentation

## ◆ ~DeviceBuffer()

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

## ◆ DeviceBuffer()

impeller::DeviceBuffer::DeviceBuffer | ( | DeviceBufferDescriptor | desc | ) |
| explicit protected

Definition at line 9 of file device_buffer.cc.

9 : desc_(desc) {}

## Member Function Documentation

## ◆ AsBufferView()

BufferView impeller::DeviceBuffer::AsBufferView | ( | std::shared_ptr< DeviceBuffer > | buffer | ) |
| static

Create a buffer view of this entire buffer.

Definition at line 18 of file device_buffer.cc.

18 {
19 BufferView view;
20 view.buffer = std::move(buffer);
21 view.range = {0u, view.buffer->desc_.size};
22 return view;
23 }

References impeller::BufferView::buffer, and impeller::BufferView::range.

Referenced by impeller::ComputeTessellator::Tessellate(), impeller::testing::TEST(), and impeller::testing::TEST_P().

## ◆ AsTexture()

std::shared_ptr< Texture > impeller::DeviceBuffer::AsTexture | ( | Allocator & | allocator,
|  | const TextureDescriptor & | descriptor,
|  | uint16_t | row_bytes
| ) |  | const
| virtual

Definition at line 25 of file device_buffer.cc.

28 {
29 auto texture = allocator.CreateTexture(descriptor);
30 if (!texture) {
31 return nullptr;
32 }
33 if (!texture->SetContents(std::make_shared<fml::NonOwnedMapping>(
34 OnGetContents(), desc_.size))) {
35 return nullptr;
36 }
37 return texture;
38 }

References impeller::Allocator::CreateTexture(), desc_, OnGetContents(), and impeller::DeviceBufferDescriptor::size.

## ◆ CopyHostBuffer()

bool impeller::DeviceBuffer::CopyHostBuffer | ( | const uint8_t * | source,
|  | Range | source_range,
|  | size_t | offset = `0u`
| ) |  |

Definition at line 44 of file device_buffer.cc.

46 {
47 if (source_range.length == 0u) {
48 // Nothing to copy. Bail.
49 return true;
50 }
51
52 if (source == nullptr) {
53 // Attempted to copy data from a null buffer.
54 return false;
55 }
56
57 if (desc_.storage_mode != StorageMode::kHostVisible) {
58 // One of the storage modes where a transfer queue must be used.
59 return false;
60 }
61
62 if (offset + source_range.length > desc_.size) {
63 // Out of bounds of this buffer.
64 return false;
65 }
66
67 return OnCopyHostBuffer(source, source_range, offset);
68 }

References desc_, impeller::kHostVisible, impeller::Range::length, offset, OnCopyHostBuffer(), impeller::DeviceBufferDescriptor::size, and impeller::DeviceBufferDescriptor::storage_mode.

## ◆ Flush()

void impeller::DeviceBuffer::Flush | ( | std::optional< Range > | range = `std::nullopt` | ) | const
| virtual

Make any pending writes visible to the GPU.

This method must be called if the device pointer provided by [OnGetContents] is written to without using [CopyHostBuffer]. On Devices with coherent host memory, this method will not perform extra work.

If the range is not provided, the entire buffer is flushed.

Reimplemented in impeller::DeviceBufferGLES.

Definition at line 13 of file device_buffer.cc.

13 {}

## ◆ GetDeviceBufferDescriptor()

const DeviceBufferDescriptor & impeller::DeviceBuffer::GetDeviceBufferDescriptor | ( |  | ) | const

Definition at line 40 of file device_buffer.cc.

40 {
41 return desc_;
42 }

References desc_.

## ◆ Invalidate()

void impeller::DeviceBuffer::Invalidate | ( | std::optional< Range > | range = `std::nullopt` | ) | const
| virtual

Definition at line 15 of file device_buffer.cc.

15 {}

## ◆ OnCopyHostBuffer()

virtual bool impeller::DeviceBuffer::OnCopyHostBuffer | ( | const uint8_t * | source,
|  | Range | source_range,
|  | size_t | offset
| ) |  |
| protected pure virtual

Referenced by CopyHostBuffer().

## ◆ OnGetContents()

virtual uint8_t* impeller::DeviceBuffer::OnGetContents | ( |  | ) | const
| pure virtual

Referenced by AsTexture().

## ◆ SetLabel() [1/2]

virtual bool impeller::DeviceBuffer::SetLabel | ( | const std::string & | label | ) |
| pure virtual

## ◆ SetLabel() [2/2]

virtual bool impeller::DeviceBuffer::SetLabel | ( | const std::string & | label,
|  | Range | range
| ) |  |
| pure virtual

## Member Data Documentation

## ◆ desc_

const DeviceBufferDescriptor impeller::DeviceBuffer::desc_
| protected

Definition at line 55 of file device_buffer.h.

Referenced by AsTexture(), CopyHostBuffer(), and GetDeviceBufferDescriptor().

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

- impeller/core/device_buffer.h
- impeller/core/device_buffer.cc

impeller::DeviceBuffer::OnGetContents
virtual uint8_t * OnGetContents() const =0
impeller::DeviceBufferDescriptor::size
size_t size
Definition: device_buffer_descriptor.h:16
impeller::StorageMode::kHostVisible
@ kHostVisible
impeller::DeviceBufferDescriptor::storage_mode
StorageMode storage_mode
Definition: device_buffer_descriptor.h:15
impeller::DeviceBuffer::desc_
const DeviceBufferDescriptor desc_
Definition: device_buffer.h:55
impeller::DeviceBuffer::OnCopyHostBuffer
virtual bool OnCopyHostBuffer(const uint8_t *source, Range source_range, size_t offset)=0
offset
Point offset
Definition: stroke_path_geometry.cc:300