mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Patch buffer views.
This commit is contained in:
parent
47540e614e
commit
070e73868e
@ -12,25 +12,39 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
class HostBuffer;
|
||||
|
||||
class BufferBase {
|
||||
public:
|
||||
~BufferBase() = default;
|
||||
|
||||
virtual uint8_t* GetMapping() const = 0;
|
||||
|
||||
virtual size_t GetLength() const = 0;
|
||||
};
|
||||
|
||||
class BufferView : public BufferBase {
|
||||
class BufferView final : public BufferBase {
|
||||
public:
|
||||
uint8_t* GetMapping() const {
|
||||
// |BufferBase|
|
||||
~BufferView() = default;
|
||||
|
||||
// |BufferBase|
|
||||
uint8_t* GetMapping() const override {
|
||||
return parent_->GetMapping() + range_in_parent_.offset;
|
||||
}
|
||||
|
||||
size_t GetLength() const { return range_in_parent_.length; }
|
||||
// |BufferBase|
|
||||
size_t GetLength() const override { return range_in_parent_.length; }
|
||||
|
||||
private:
|
||||
friend HostBuffer;
|
||||
|
||||
std::shared_ptr<BufferBase> parent_;
|
||||
Range range_in_parent_;
|
||||
|
||||
BufferView(std::shared_ptr<BufferBase> parent, Range range_in_parent)
|
||||
: parent_(std::move(parent)), range_in_parent_(range_in_parent) {}
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(BufferView);
|
||||
};
|
||||
|
||||
@ -61,10 +75,12 @@ class HostBuffer : public std::enable_shared_from_this<HostBuffer>,
|
||||
|
||||
std::shared_ptr<BufferView> Emplace(size_t length);
|
||||
|
||||
~HostBuffer();
|
||||
virtual ~HostBuffer();
|
||||
|
||||
// |BufferBase|
|
||||
uint8_t* GetMapping() const override { return buffer_; }
|
||||
|
||||
// |BufferBase|
|
||||
size_t GetLength() const override { return length_; }
|
||||
|
||||
[[nodiscard]] bool Truncate(size_t length);
|
||||
|
||||
@ -27,9 +27,12 @@ HostBuffer::~HostBuffer() {
|
||||
}
|
||||
|
||||
std::shared_ptr<BufferView> HostBuffer::Emplace(size_t length) {
|
||||
auto old_length = length_;
|
||||
if (!Truncate(length_ + length)) {
|
||||
return nullptr;
|
||||
}
|
||||
return std::shared_ptr<BufferView>(
|
||||
new BufferView(shared_from_this(), Range{old_length, length}));
|
||||
}
|
||||
|
||||
bool HostBuffer::Truncate(size_t length) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user