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