Flutter Impeller
allocator.h
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 #ifndef FLUTTER_IMPELLER_CORE_ALLOCATOR_H_
6 #define FLUTTER_IMPELLER_CORE_ALLOCATOR_H_
7 
8 #include "flutter/fml/mapping.h"
11 #include "impeller/core/texture.h"
13 #include "impeller/geometry/size.h"
14 
15 namespace impeller {
16 
17 class Context;
18 class DeviceBuffer;
19 
20 //------------------------------------------------------------------------------
21 /// @brief An object that allocates device memory.
22 ///
23 class Allocator {
24  public:
25  virtual ~Allocator();
26 
27  bool IsValid() const;
28 
29  std::shared_ptr<DeviceBuffer> CreateBuffer(
30  const DeviceBufferDescriptor& desc);
31 
32  std::shared_ptr<Texture> CreateTexture(const TextureDescriptor& desc);
33 
34  //------------------------------------------------------------------------------
35  /// @brief Minimum value for `row_bytes` on a Texture. The row
36  /// bytes parameter of that method must be aligned to this value.
37  ///
38  virtual uint16_t MinimumBytesPerRow(PixelFormat format) const;
39 
40  std::shared_ptr<DeviceBuffer> CreateBufferWithCopy(const uint8_t* buffer,
41  size_t length);
42 
43  std::shared_ptr<DeviceBuffer> CreateBufferWithCopy(
44  const fml::Mapping& mapping);
45 
46  virtual ISize GetMaxTextureSizeSupported() const = 0;
47 
48  /// @brief Write debug memory usage information to the dart timeline in debug
49  /// and profile modes.
50  ///
51  /// This is supported on both the Metal and Vulkan backends.
52  virtual void DebugTraceMemoryStatistics() const {};
53 
54  // Visible for testing.
55  virtual Bytes DebugGetHeapUsage() const { return Bytes{0}; }
56 
57  protected:
58  Allocator();
59 
60  virtual std::shared_ptr<DeviceBuffer> OnCreateBuffer(
61  const DeviceBufferDescriptor& desc) = 0;
62 
63  virtual std::shared_ptr<Texture> OnCreateTexture(
64  const TextureDescriptor& desc) = 0;
65 
66  private:
67  Allocator(const Allocator&) = delete;
68 
69  Allocator& operator=(const Allocator&) = delete;
70 };
71 
72 } // namespace impeller
73 
74 #endif // FLUTTER_IMPELLER_CORE_ALLOCATOR_H_
impeller::Allocator::IsValid
bool IsValid() const
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
texture_descriptor.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
virtual ~Allocator()
impeller::Allocator::CreateTexture
std::shared_ptr< Texture > CreateTexture(const TextureDescriptor &desc)
Definition: allocator.cc:49
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:99
impeller::TSize
Definition: size.h:19
impeller::Allocator::CreateBuffer
std::shared_ptr< DeviceBuffer > CreateBuffer(const DeviceBufferDescriptor &desc)
Definition: allocator.cc:44
impeller::Allocator::DebugGetHeapUsage
virtual Bytes DebugGetHeapUsage() const
Definition: allocator.h:55
impeller::Allocator
An object that allocates device memory.
Definition: allocator.h:23
impeller::AllocationSize< 1u >
impeller::Allocator::CreateBufferWithCopy
std::shared_ptr< DeviceBuffer > CreateBufferWithCopy(const uint8_t *buffer, size_t length)
Definition: allocator.cc:18
impeller::Allocator::Allocator
Allocator()
texture.h
device_buffer_descriptor.h
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
allocation_size.h
impeller
Definition: allocation.cc:12
impeller::Allocator::DebugTraceMemoryStatistics
virtual void DebugTraceMemoryStatistics() const
Write debug memory usage information to the dart timeline in debug and profile modes.
Definition: allocator.h:52
size.h
impeller::Allocator::OnCreateBuffer
virtual std::shared_ptr< DeviceBuffer > OnCreateBuffer(const DeviceBufferDescriptor &desc)=0