| Flutter Impeller |

device_buffer.h
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 #ifndef FLUTTER_IMPELLER_CORE_DEVICE_BUFFER_H_
6 #define FLUTTER_IMPELLER_CORE_DEVICE_BUFFER_H_
7
8 #include <memory>
9 #include <string>
10
11 #include "impeller/core/allocator.h"
12 #include "impeller/core/buffer_view.h"
13 #include "impeller/core/device_buffer_descriptor.h"
14 #include "impeller/core/range.h"
15
16 namespace impeller {
17
18 class DeviceBuffer {
19 public:
20 virtual ~DeviceBuffer();
21
22 [[nodiscard]] bool CopyHostBuffer(const uint8_t* source,
23 Range source_range,
24 size_t offset = 0u);
25
26 virtual bool SetLabel(std::string_view label) = 0;
27
28 virtual bool SetLabel(std::string_view label, Range range) = 0;
29
30 /// @brief Create a buffer view of this entire buffer.
31 static BufferView AsBufferView(std::shared_ptr<DeviceBuffer> buffer);
32
33 const DeviceBufferDescriptor& GetDeviceBufferDescriptor() const;
34
35 virtual uint8_t* OnGetContents() const = 0;
36
37 /// Make any pending writes visible to the GPU.
38 ///
39 /// This method must be called if the device pointer provided by
40 /// [OnGetContents] is written to without using [CopyHostBuffer]. On Devices
41 /// with coherent host memory, this method will not perform extra work.
42 ///
43 /// If the range is not provided, the entire buffer is flushed.
44 virtual void Flush(std::optional<Range> range = std::nullopt) const;
45
46 virtual void Invalidate(std::optional<Range> range = std::nullopt) const;
47
48 protected:
49 const DeviceBufferDescriptor desc_;
50
51 explicit DeviceBuffer(DeviceBufferDescriptor desc);
52
53 virtual bool OnCopyHostBuffer(const uint8_t* source,
54 Range source_range,
55 size_t offset) = 0;
56
57 private:
58 DeviceBuffer(const DeviceBuffer&) = delete;
59
60 DeviceBuffer& operator=(const DeviceBuffer&) = delete;
61 };
62
63 } // namespace impeller
64
65 #endif // FLUTTER_IMPELLER_CORE_DEVICE_BUFFER_H_
allocator.h
buffer_view.h
impeller::DeviceBuffer
Definition: device_buffer.h:18
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::SetLabel
virtual bool SetLabel(std::string_view label, Range range)=0
impeller::DeviceBuffer::Invalidate
virtual void Invalidate(std::optional< Range > range=std::nullopt) const
Definition: device_buffer.cc:15
impeller::DeviceBuffer::OnGetContents
virtual uint8_t * OnGetContents() const =0
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::SetLabel
virtual bool SetLabel(std::string_view label)=0
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_descriptor.h
impeller
Definition: allocation.cc:12
range.h
impeller::BufferView
Definition: buffer_view.h:19
impeller::DeviceBufferDescriptor
Definition: device_buffer_descriptor.h:14
impeller::Range
Definition: range.h:13