| Flutter Impeller |

device_buffer.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "impeller/core/device_buffer.h"
6
7 namespace impeller {
8
9 DeviceBuffer::DeviceBuffer(DeviceBufferDescriptor desc) : desc_(desc) {}
10
11 DeviceBuffer::~DeviceBuffer() = default;
12
13 // |Buffer|
14 std::shared_ptr<const DeviceBuffer> DeviceBuffer::GetDeviceBuffer(
15 Allocator& allocator) const {
16 return shared_from_this();
17 }
18
19 BufferView DeviceBuffer::AsBufferView() const {
20 BufferView view;
21 view.buffer = shared_from_this();
22 view.contents = OnGetContents();
23 view.range = {0u, desc_.size};
24 return view;
25 }
26
27 std::shared_ptr<Texture> DeviceBuffer::AsTexture(
28 Allocator& allocator,
29 const TextureDescriptor& descriptor,
30 uint16_t row_bytes) const {
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 }
41
42 const DeviceBufferDescriptor& DeviceBuffer::GetDeviceBufferDescriptor() const {
43 return desc_;
44 }
45
46 [[nodiscard]] bool DeviceBuffer::CopyHostBuffer(const uint8_t* source,
47 Range source_range,
48 size_t offset) {
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 }
71
72 } // namespace impeller
impeller::DeviceBuffer::OnGetContents
virtual uint8_t * OnGetContents() const =0
impeller::DeviceBuffer::DeviceBuffer
DeviceBuffer(DeviceBufferDescriptor desc)
Definition: device_buffer.cc:9
impeller::DeviceBufferDescriptor
Definition: device_buffer_descriptor.h:14
device_buffer.h
impeller::BufferView::contents
uint8_t * contents
Definition: buffer_view.h:15
impeller::DeviceBufferDescriptor::size
size_t size
Definition: device_buffer_descriptor.h:16
impeller::StorageMode::kHostVisible
@ kHostVisible
impeller::BufferView::range
Range range
Definition: buffer_view.h:16
impeller::Allocator::CreateTexture
std::shared_ptr< Texture > CreateTexture(const TextureDescriptor &desc)
Definition: allocator.cc:49
impeller::DeviceBuffer::~DeviceBuffer
virtual ~DeviceBuffer()
impeller::DeviceBuffer::AsTexture
virtual std::shared_ptr< Texture > AsTexture(Allocator &allocator, const TextureDescriptor &descriptor, uint16_t row_bytes) const
Definition: device_buffer.cc:27
impeller::BufferView::buffer
std::shared_ptr< const Buffer > buffer
Definition: buffer_view.h:14
impeller::DeviceBufferDescriptor::storage_mode
StorageMode storage_mode
Definition: device_buffer_descriptor.h:15
impeller::DeviceBuffer::CopyHostBuffer
bool CopyHostBuffer(const uint8_t *source, Range source_range, size_t offset=0u)
Definition: device_buffer.cc:46
impeller::Allocator
An object that allocates device memory.
Definition: allocator.h:22
impeller::DeviceBuffer::GetDeviceBufferDescriptor
const DeviceBufferDescriptor & GetDeviceBufferDescriptor() const
Definition: device_buffer.cc:42
impeller::BufferView
Definition: buffer_view.h:13
impeller::Range
Definition: range.h:14
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
impeller::TextureDescriptor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
Definition: texture_descriptor.h:37
impeller::DeviceBuffer::GetDeviceBuffer
std::shared_ptr< const DeviceBuffer > GetDeviceBuffer(Allocator &allocator) const
Definition: device_buffer.cc:14
impeller::Range::length
size_t length
Definition: range.h:16
impeller::DeviceBuffer::AsBufferView
BufferView AsBufferView() const
Definition: device_buffer.cc:19
impeller
Definition: aiks_context.cc:10