Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
impeller
core
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
5
#include "
impeller/core/device_buffer.h
"
6
7
namespace
impeller
{
8
9
DeviceBuffer::DeviceBuffer
(
DeviceBufferDescriptor
desc) : desc_(desc) {}
10
11
DeviceBuffer::~DeviceBuffer
() =
default
;
12
13
void
DeviceBuffer::Flush
(std::optional<Range> range)
const
{}
14
15
void
DeviceBuffer::Invalidate
(std::optional<Range> range)
const
{}
16
17
// static
18
BufferView
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
25
std::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>(
34
OnGetContents
(),
desc_
.
size
))) {
35
return
nullptr
;
36
}
37
return
texture
;
38
}
39
40
const
DeviceBufferDescriptor
&
DeviceBuffer::GetDeviceBufferDescriptor
()
const
{
41
return
desc_
;
42
}
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
57
if
(
desc_
.
storage_mode
!=
StorageMode::kHostVisible
) {
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
impeller::Allocator
An object that allocates device memory.
Definition
allocator.h:22
impeller::Allocator::CreateTexture
std::shared_ptr< Texture > CreateTexture(const TextureDescriptor &desc)
Definition
allocator.cc:49
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::Flush
virtual void Flush(std::optional< Range > range=std::nullopt) const
Definition
device_buffer.cc:13
impeller::DeviceBuffer::desc_
const DeviceBufferDescriptor desc_
Definition
device_buffer.h:55
impeller::DeviceBuffer::Invalidate
virtual void Invalidate(std::optional< Range > range=std::nullopt) const
Definition
device_buffer.cc:15
impeller::DeviceBuffer::OnGetContents
virtual uint8_t * OnGetContents() const =0
impeller::DeviceBuffer::GetDeviceBufferDescriptor
const DeviceBufferDescriptor & GetDeviceBufferDescriptor() const
Definition
device_buffer.cc:40
impeller::DeviceBuffer::DeviceBuffer
DeviceBuffer(DeviceBufferDescriptor desc)
Definition
device_buffer.cc:9
impeller::DeviceBuffer::~DeviceBuffer
virtual ~DeviceBuffer()
impeller::DeviceBuffer::OnCopyHostBuffer
virtual bool OnCopyHostBuffer(const uint8_t *source, Range source_range, size_t offset)=0
impeller::DeviceBuffer::CopyHostBuffer
bool CopyHostBuffer(const uint8_t *source, Range source_range, size_t offset=0u)
Definition
device_buffer.cc:44
impeller::DeviceBuffer::AsTexture
virtual std::shared_ptr< Texture > AsTexture(Allocator &allocator, const TextureDescriptor &descriptor, uint16_t row_bytes) const
Definition
device_buffer.cc:25
source
SkBitmap source
Definition
examples.cpp:28
buffer
static const uint8_t buffer[]
Definition
fl_pixel_buffer_texture_test.cc:44
device_buffer.h
texture
FlTexture * texture
Definition
mock_texture_registrar.cc:24
impeller
Definition
texture.h:18
impeller::StorageMode::kHostVisible
@ kHostVisible
offset
Point offset
Definition
stroke_path_geometry.cc:256
impeller::BufferView
Definition
buffer_view.h:15
impeller::BufferView::range
Range range
Definition
buffer_view.h:17
impeller::BufferView::buffer
std::shared_ptr< const DeviceBuffer > buffer
Definition
buffer_view.h:16
impeller::DeviceBufferDescriptor
Definition
device_buffer_descriptor.h:14
impeller::DeviceBufferDescriptor::storage_mode
StorageMode storage_mode
Definition
device_buffer_descriptor.h:15
impeller::DeviceBufferDescriptor::size
size_t size
Definition
device_buffer_descriptor.h:16
impeller::Range
Definition
range.h:14
impeller::Range::length
size_t length
Definition
range.h:16
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
Generated on Fri Apr 26 2024 06:14:15 for Flutter Engine by
1.9.8