| Flutter Impeller |

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
BufferView | AsBufferView () const
virtual std::shared_ptr< Texture > | AsTexture (Allocator &allocator, const TextureDescriptor &descriptor, uint16_t row_bytes) const
std::shared_ptr< const DeviceBuffer > | GetDeviceBuffer (Allocator &allocator) const
const DeviceBufferDescriptor & | GetDeviceBufferDescriptor () const
virtual uint8_t * | OnGetContents () const =0
Public Member Functions inherited from impeller::Buffer
virtual | ~Buffer ()

## 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 20 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 | ( |  | ) | const

Definition at line 19 of file device_buffer.cc.

19 {
20 BufferView view;
21 view.buffer = shared_from_this();
22 view.contents = OnGetContents();
23 view.range = {0u, desc_.size};
24 return view;
25 }

References impeller::BufferView::buffer, impeller::BufferView::contents, desc_, OnGetContents(), impeller::BufferView::range, and impeller::DeviceBufferDescriptor::size.

## ◆ AsTexture()

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

Definition at line 27 of file device_buffer.cc.

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

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 46 of file device_buffer.cc.

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

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

## ◆ GetDeviceBuffer()

std::shared_ptr< const DeviceBuffer > impeller::DeviceBuffer::GetDeviceBuffer | ( | Allocator & | allocator | ) | const
| virtual

Implements impeller::Buffer.

Definition at line 14 of file device_buffer.cc.

15 {
16 return shared_from_this();
17 }

## ◆ GetDeviceBufferDescriptor()

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

Definition at line 42 of file device_buffer.cc.

42 {
43 return desc_;
44 }

References desc_.

## ◆ 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 AsBufferView(), and 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 49 of file device_buffer.h.

Referenced by AsBufferView(), 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:49
impeller::DeviceBuffer::OnCopyHostBuffer
virtual bool OnCopyHostBuffer(const uint8_t *source, Range source_range, size_t offset)=0