| 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 return OnCreateTexture(desc);
59 }
60
61 void Allocator::DidAcquireSurfaceFrame() {}
62
63 uint16_t Allocator::MinimumBytesPerRow(PixelFormat format) const {
64 return BytesPerPixelForPixelFormat(format);
65 }
66
67 } // namespace impeller
impeller::Allocator::GetMaxTextureSizeSupported
virtual ISize GetMaxTextureSizeSupported() const =0
impeller::Allocator::OnCreateTexture
virtual std::shared_ptr< Texture > OnCreateTexture(const TextureDescriptor &desc)=0
impeller::DeviceBufferDescriptor
Definition: device_buffer_descriptor.h:14
device_buffer.h
formats.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:63
impeller::DeviceBufferDescriptor::size
size_t size
Definition: device_buffer_descriptor.h:16
impeller::Allocator::~Allocator
virtual ~Allocator()
impeller::StorageMode::kHostVisible
@ kHostVisible
impeller::Allocator::CreateTexture
std::shared_ptr< Texture > CreateTexture(const TextureDescriptor &desc)
Definition: allocator.cc:49
validation.h
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:94
impeller::Allocator::CreateBuffer
std::shared_ptr< DeviceBuffer > CreateBuffer(const DeviceBufferDescriptor &desc)
Definition: allocator.cc:44
impeller::BytesPerPixelForPixelFormat
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)
Definition: formats.h:442
impeller::DeviceBufferDescriptor::storage_mode
StorageMode storage_mode
Definition: device_buffer_descriptor.h:15
range.h
impeller::Allocator::CreateBufferWithCopy
std::shared_ptr< DeviceBuffer > CreateBufferWithCopy(const uint8_t *buffer, size_t length)
Definition: allocator.cc:18
impeller::TSize::width
Type width
Definition: size.h:22
impeller::TextureDescriptor::size
ISize size
Definition: texture_descriptor.h:41
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:67
allocator.h
impeller::Range
Definition: range.h:14
impeller::Allocator::Allocator
Allocator()
impeller::TSize::height
Type height
Definition: size.h:23
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::Allocator::DidAcquireSurfaceFrame
virtual void DidAcquireSurfaceFrame()
Increment an internal frame used to cycle through a ring buffer of allocation pools.
Definition: allocator.cc:61
impeller
Definition: aiks_context.cc:10
impeller::Allocator::OnCreateBuffer
virtual std::shared_ptr< DeviceBuffer > OnCreateBuffer(const DeviceBufferDescriptor &desc)=0