| 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(const std::string& label) = 0;
27
28 virtual bool SetLabel(const std::string& 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_
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::OnGetContents
virtual uint8_t * OnGetContents() const =0
impeller::DeviceBuffer::DeviceBuffer
DeviceBuffer(DeviceBufferDescriptor desc)
Definition: device_buffer.cc:9
impeller::DeviceBuffer
Definition: device_buffer.h:18
impeller::DeviceBufferDescriptor
Definition: device_buffer_descriptor.h:14
offset
SeparatedVector2 offset
Definition: stroke_path_geometry.cc:311
impeller::DeviceBuffer::~DeviceBuffer
virtual ~DeviceBuffer()
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
range.h
impeller::DeviceBuffer::Flush
virtual void Flush(std::optional< Range > range=std::nullopt) const
Definition: device_buffer.cc:13
impeller::DeviceBuffer::SetLabel
virtual bool SetLabel(const std::string &label)=0
allocator.h
impeller::BufferView
Definition: buffer_view.h:15
impeller::Range
Definition: range.h:12
buffer_view.h
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
device_buffer_descriptor.h
impeller::DeviceBuffer::Invalidate
virtual void Invalidate(std::optional< Range > range=std::nullopt) const
Definition: device_buffer.cc:15
impeller
Definition: aiks_blend_unittests.cc:18