Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
impeller
core
allocator.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/allocator.h
"
6
7
#include "
impeller/base/validation.h
"
8
#include "
impeller/core/device_buffer.h
"
9
#include "
impeller/core/formats.h
"
10
#include "
impeller/core/range.h
"
11
12
namespace
impeller
{
13
14
Allocator::Allocator
() =
default
;
15
16
Allocator::~Allocator
() =
default
;
17
18
std::shared_ptr<DeviceBuffer>
Allocator::CreateBufferWithCopy
(
19
const
uint8_t*
buffer
,
20
size_t
length
) {
21
DeviceBufferDescriptor
desc;
22
desc.size =
length
;
23
desc.storage_mode =
StorageMode::kHostVisible
;
24
auto
new_buffer =
CreateBuffer
(desc);
25
26
if
(!new_buffer) {
27
return
nullptr
;
28
}
29
30
auto
entire_range =
Range
{0,
length
};
31
32
if
(!new_buffer->CopyHostBuffer(
buffer
, entire_range)) {
33
return
nullptr
;
34
}
35
36
return
new_buffer;
37
}
38
39
std::shared_ptr<DeviceBuffer>
Allocator::CreateBufferWithCopy
(
40
const
fml::Mapping
& mapping) {
41
return
CreateBufferWithCopy
(mapping.
GetMapping
(), mapping.
GetSize
());
42
}
43
44
std::shared_ptr<DeviceBuffer>
Allocator::CreateBuffer
(
45
const
DeviceBufferDescriptor
& desc) {
46
return
OnCreateBuffer
(desc);
47
}
48
49
std::shared_ptr<Texture>
Allocator::CreateTexture
(
50
const
TextureDescriptor
& desc) {
51
const
auto
max_size =
GetMaxTextureSizeSupported
();
52
if
(desc.size.width > max_size.width || desc.size.height > max_size.height) {
53
VALIDATION_LOG
<<
"Requested texture size "
<< desc.size
54
<<
" exceeds maximum supported size of "
<< max_size;
55
return
nullptr
;
56
}
57
58
if
(desc.mip_count > desc.size.MipCount()) {
59
VALIDATION_LOG
<<
"Requested mip_count "
<< desc.mip_count
60
<<
" exceeds maximum supported for size "
<< desc.size;
61
TextureDescriptor
corrected_desc = desc;
62
corrected_desc.
mip_count
= desc.size.MipCount();
63
return
OnCreateTexture
(corrected_desc);
64
}
65
66
return
OnCreateTexture
(desc);
67
}
68
69
uint16_t
Allocator::MinimumBytesPerRow
(
PixelFormat
format
)
const
{
70
return
BytesPerPixelForPixelFormat
(
format
);
71
}
72
73
}
// namespace impeller
allocator.h
fml::Mapping
Definition
mapping.h:21
fml::Mapping::GetMapping
virtual const uint8_t * GetMapping() const =0
fml::Mapping::GetSize
virtual size_t GetSize() const =0
impeller::Allocator::MinimumBytesPerRow
virtual uint16_t MinimumBytesPerRow(PixelFormat format) const
Minimum value for row_bytes on a Texture. The row bytes parameter of that method must be aligned to t...
Definition
allocator.cc:69
impeller::Allocator::Allocator
Allocator()
impeller::Allocator::GetMaxTextureSizeSupported
virtual ISize GetMaxTextureSizeSupported() const =0
impeller::Allocator::CreateBufferWithCopy
std::shared_ptr< DeviceBuffer > CreateBufferWithCopy(const uint8_t *buffer, size_t length)
Definition
allocator.cc:18
impeller::Allocator::OnCreateTexture
virtual std::shared_ptr< Texture > OnCreateTexture(const TextureDescriptor &desc)=0
impeller::Allocator::CreateBuffer
std::shared_ptr< DeviceBuffer > CreateBuffer(const DeviceBufferDescriptor &desc)
Definition
allocator.cc:44
impeller::Allocator::~Allocator
virtual ~Allocator()
impeller::Allocator::CreateTexture
std::shared_ptr< Texture > CreateTexture(const TextureDescriptor &desc)
Definition
allocator.cc:49
impeller::Allocator::OnCreateBuffer
virtual std::shared_ptr< DeviceBuffer > OnCreateBuffer(const DeviceBufferDescriptor &desc)=0
buffer
static const uint8_t buffer[]
Definition
fl_pixel_buffer_texture_test.cc:44
format
uint32_t uint32_t * format
Definition
fl_texture_registrar_test.cc:41
device_buffer.h
formats.h
range.h
length
size_t length
Definition
key_event_handler.cc:41
impeller
Definition
texture.h:18
impeller::BytesPerPixelForPixelFormat
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)
Definition
formats.h:448
impeller::StorageMode::kHostVisible
@ kHostVisible
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition
formats.h:100
impeller::DeviceBufferDescriptor
Definition
device_buffer_descriptor.h:14
impeller::Range
Definition
range.h:14
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
impeller::TextureDescriptor::mip_count
size_t mip_count
Definition
texture_descriptor.h:42
validation.h
VALIDATION_LOG
#define VALIDATION_LOG
Definition
validation.h:73
Generated on Fri Apr 26 2024 06:14:08 for Flutter Engine by
1.9.8