Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
device_buffer.cc
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
6
7namespace impeller {
8
10
12
13void DeviceBuffer::Flush(std::optional<Range> range) const {}
14
15void DeviceBuffer::Invalidate(std::optional<Range> range) const {}
16
17// static
18BufferView DeviceBuffer::AsBufferView(std::shared_ptr<DeviceBuffer> buffer) {
19 BufferView view;
20 view.buffer = std::move(buffer);
21 view.range = {0u, view.buffer->desc_.size};
22 return view;
23}
24
25std::shared_ptr<Texture> DeviceBuffer::AsTexture(
26 Allocator& allocator,
27 const TextureDescriptor& descriptor,
28 uint16_t row_bytes) const {
29 auto texture = allocator.CreateTexture(descriptor);
30 if (!texture) {
31 return nullptr;
32 }
33 if (!texture->SetContents(std::make_shared<fml::NonOwnedMapping>(
35 return nullptr;
36 }
37 return texture;
38}
39
43
44[[nodiscard]] bool DeviceBuffer::CopyHostBuffer(const uint8_t* source,
45 Range source_range,
46 size_t offset) {
47 if (source_range.length == 0u) {
48 // Nothing to copy. Bail.
49 return true;
50 }
51
52 if (source == nullptr) {
53 // Attempted to copy data from a null buffer.
54 return false;
55 }
56
58 // One of the storage modes where a transfer queue must be used.
59 return false;
60 }
61
62 if (offset + source_range.length > desc_.size) {
63 // Out of bounds of this buffer.
64 return false;
65 }
66
67 return OnCopyHostBuffer(source, source_range, offset);
68}
69
70} // namespace impeller
An object that allocates device memory.
Definition allocator.h:22
std::shared_ptr< Texture > CreateTexture(const TextureDescriptor &desc)
Definition allocator.cc:49
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
const DeviceBufferDescriptor & GetDeviceBufferDescriptor() const
DeviceBuffer(DeviceBufferDescriptor desc)
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 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[]
FlTexture * texture
Point offset
std::shared_ptr< const DeviceBuffer > buffer
Definition buffer_view.h:16
size_t length
Definition range.h:16
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...