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 
6 
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) {
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 
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 
70  return BytesPerPixelForPixelFormat(format);
71 }
72 
73 } // namespace impeller
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 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
virtual std::shared_ptr< Texture > OnCreateTexture(const TextureDescriptor &desc)=0
std::shared_ptr< Texture > CreateTexture(const TextureDescriptor &desc)
Definition: allocator.cc:49
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