Flutter Engine
 
Loading...
Searching...
No Matches
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
6
10#include "impeller/core/range.h"
11
12namespace impeller {
13
14Allocator::Allocator() = default;
15
16Allocator::~Allocator() = default;
17
18std::shared_ptr<DeviceBuffer> Allocator::CreateBufferWithCopy(
19 const uint8_t* buffer,
20 size_t length) {
22 desc.size = length;
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
39std::shared_ptr<DeviceBuffer> Allocator::CreateBufferWithCopy(
40 const fml::Mapping& mapping) {
41 return CreateBufferWithCopy(mapping.GetMapping(), mapping.GetSize());
42}
43
44std::shared_ptr<DeviceBuffer> Allocator::CreateBuffer(
45 const DeviceBufferDescriptor& desc) {
46 return OnCreateBuffer(desc);
47}
48
49std::shared_ptr<Texture> Allocator::CreateTexture(const TextureDescriptor& desc,
50 bool threadsafe) {
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, threadsafe);
64 }
65
66 return OnCreateTexture(desc, threadsafe);
67}
68
72
73} // namespace impeller
virtual const uint8_t * GetMapping() const =0
virtual size_t GetSize() const =0
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
virtual std::shared_ptr< Texture > OnCreateTexture(const TextureDescriptor &desc, bool threadsafe=false)=0
virtual ISize GetMaxTextureSizeSupported() const =0
std::shared_ptr< DeviceBuffer > CreateBufferWithCopy(const uint8_t *buffer, size_t length)
Definition allocator.cc:18
std::shared_ptr< DeviceBuffer > CreateBuffer(const DeviceBufferDescriptor &desc)
Definition allocator.cc:44
virtual std::shared_ptr< DeviceBuffer > OnCreateBuffer(const DeviceBufferDescriptor &desc)=0
std::shared_ptr< Texture > CreateTexture(const TextureDescriptor &desc, bool threadsafe=false)
Creates a new texture.
Definition allocator.cc:49
uint32_t uint32_t * format
size_t length
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)
Definition formats.h:466
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition formats.h:99
Type height
Definition size.h:29
Type width
Definition size.h:28
constexpr size_t MipCount() const
Return the mip count of the texture.
Definition size.h:137
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
#define VALIDATION_LOG
Definition validation.h:91