| 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 void DeviceBuffer::Flush(std::optional<Range> range) const {}
14
15 void DeviceBuffer::Invalidate(std::optional<Range> range) const {}
16
17 // static
18 BufferView DeviceBuffer::AsBufferView(std::shared_ptr<DeviceBuffer> buffer) {
19 Range range = {0u, buffer->desc_.size};
20 return BufferView(std::move(buffer), range);
21 }
22
23 const DeviceBufferDescriptor& DeviceBuffer::GetDeviceBufferDescriptor() const {
24 return desc_;
25 }
26
27 [[nodiscard]] bool DeviceBuffer::CopyHostBuffer(const uint8_t* source,
28 Range source_range,
29 size_t offset) {
30 if (source_range.length == 0u) {
31 // Nothing to copy. Bail.
32 return true;
33 }
34
35 if (source == nullptr) {
36 // Attempted to copy data from a null buffer.
37 return false;
38 }
39
40 if (desc_.storage_mode != StorageMode::kHostVisible) {
41 // One of the storage modes where a transfer queue must be used.
42 return false;
43 }
44
45 if (offset + source_range.length > desc_.size) {
46 // Out of bounds of this buffer.
47 return false;
48 }
49
50 return OnCopyHostBuffer(source, source_range, offset);
51 }
52
53 } // namespace impeller
impeller::DeviceBuffer::AsBufferView
static BufferView AsBufferView(std::shared_ptr< DeviceBuffer > buffer)
Create a buffer view of this entire buffer.
Definition: device_buffer.cc:18
impeller::DeviceBuffer::Flush
virtual void Flush(std::optional< Range > range=std::nullopt) const
Definition: device_buffer.cc:13
impeller::DeviceBuffer::desc_
const DeviceBufferDescriptor desc_
Definition: device_buffer.h:49
impeller::DeviceBuffer::Invalidate
virtual void Invalidate(std::optional< Range > range=std::nullopt) const
Definition: device_buffer.cc:15
impeller::DeviceBuffer::GetDeviceBufferDescriptor
const DeviceBufferDescriptor & GetDeviceBufferDescriptor() const
Definition: device_buffer.cc:23
impeller::DeviceBuffer::DeviceBuffer
DeviceBuffer(DeviceBufferDescriptor desc)
Definition: device_buffer.cc:9
impeller::DeviceBuffer::~DeviceBuffer
virtual ~DeviceBuffer()
impeller::DeviceBuffer::OnCopyHostBuffer
virtual bool OnCopyHostBuffer(const uint8_t *source, Range source_range, size_t offset)=0
impeller::DeviceBuffer::CopyHostBuffer
bool CopyHostBuffer(const uint8_t *source, Range source_range, size_t offset=0u)
Definition: device_buffer.cc:27
device_buffer.h
impeller
Definition: allocation.cc:12
impeller::StorageMode::kHostVisible
@ kHostVisible
offset
SeparatedVector2 offset
Definition: stroke_path_geometry.cc:319
impeller::BufferView
Definition: buffer_view.h:19
impeller::DeviceBufferDescriptor
Definition: device_buffer_descriptor.h:14
impeller::DeviceBufferDescriptor::storage_mode
StorageMode storage_mode
Definition: device_buffer_descriptor.h:15
impeller::DeviceBufferDescriptor::size
size_t size
Definition: device_buffer_descriptor.h:16
impeller::Range
Definition: range.h:13
impeller::Range::length
size_t length
Definition: range.h:15