| Flutter Impeller |

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
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::CreateBuffer
std::shared_ptr< DeviceBuffer > CreateBuffer(const DeviceBufferDescriptor &desc)
Definition: allocator.cc:44
impeller::Allocator::OnCreateBuffer
virtual std::shared_ptr< DeviceBuffer > OnCreateBuffer(const DeviceBufferDescriptor &desc)=0
impeller::Allocator::~Allocator
virtual ~Allocator()
impeller::Allocator::OnCreateTexture
virtual std::shared_ptr< Texture > OnCreateTexture(const TextureDescriptor &desc)=0
impeller::Allocator::CreateTexture
std::shared_ptr< Texture > CreateTexture(const TextureDescriptor &desc)
Definition: allocator.cc:49
formats.h
device_buffer.h
impeller
Definition: allocation.cc:12
impeller::BytesPerPixelForPixelFormat
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)
Definition: formats.h:466
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:99
range.h
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:13
impeller::TSize::height
Type height
Definition: size.h:29
impeller::TSize::width
Type width
Definition: size.h:28
impeller::TSize::MipCount
constexpr size_t MipCount() const
Definition: size.h:140
impeller::TextureDescriptor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
Definition: texture_descriptor.h:38
impeller::TextureDescriptor::size
ISize size
Definition: texture_descriptor.h:42
impeller::TextureDescriptor::mip_count
size_t mip_count
Definition: texture_descriptor.h:43
validation.h
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91