Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
14#include "impeller/core/range.h"
16
17namespace impeller {
18
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
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:
56
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_
An object that allocates device memory.
Definition allocator.h:22
static BufferView AsBufferView(std::shared_ptr< DeviceBuffer > buffer)
Create a buffer view of this entire buffer.
virtual void Flush(std::optional< Range > range=std::nullopt) const
const DeviceBufferDescriptor desc_
virtual void Invalidate(std::optional< Range > range=std::nullopt) const
virtual uint8_t * OnGetContents() const =0
virtual bool SetLabel(const std::string &label)=0
const DeviceBufferDescriptor & GetDeviceBufferDescriptor() const
virtual bool OnCopyHostBuffer(const uint8_t *source, Range source_range, size_t offset)=0
bool CopyHostBuffer(const uint8_t *source, Range source_range, size_t offset=0u)
virtual bool SetLabel(const std::string &label, Range range)=0
virtual std::shared_ptr< Texture > AsTexture(Allocator &allocator, const TextureDescriptor &descriptor, uint16_t row_bytes) const
SkBitmap source
Definition examples.cpp:28
static const uint8_t buffer[]
Point offset
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...