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