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