Flutter Impeller
allocation.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_BASE_ALLOCATION_H_
6 #define FLUTTER_IMPELLER_BASE_ALLOCATION_H_
7 
8 #include <cstdint>
9 #include <limits>
10 #include <memory>
11 
12 #include "flutter/fml/mapping.h"
13 
14 namespace impeller {
15 
16 class Allocation {
17  public:
18  Allocation();
19 
20  ~Allocation();
21 
22  uint8_t* GetBuffer() const;
23 
24  size_t GetLength() const;
25 
26  size_t GetReservedLength() const;
27 
28  [[nodiscard]] bool Truncate(size_t length, bool npot = true);
29 
30  static uint32_t NextPowerOfTwoSize(uint32_t x);
31 
32  private:
33  uint8_t* buffer_ = nullptr;
34  size_t length_ = 0;
35  size_t reserved_ = 0;
36 
37  [[nodiscard]] bool Reserve(size_t reserved);
38 
39  [[nodiscard]] bool ReserveNPOT(size_t reserved);
40 
41  Allocation(const Allocation&) = delete;
42 
43  Allocation& operator=(const Allocation&) = delete;
44 };
45 
46 std::shared_ptr<fml::Mapping> CreateMappingWithCopy(const uint8_t* contents,
47  size_t length);
48 
49 std::shared_ptr<fml::Mapping> CreateMappingFromAllocation(
50  const std::shared_ptr<Allocation>& allocation);
51 
52 std::shared_ptr<fml::Mapping> CreateMappingWithString(
53  std::shared_ptr<const std::string> string);
54 
55 std::shared_ptr<fml::Mapping> CreateMappingWithString(std::string string);
56 
57 } // namespace impeller
58 
59 #endif // FLUTTER_IMPELLER_BASE_ALLOCATION_H_
impeller::Allocation::~Allocation
~Allocation()
Definition: allocation.cc:16
impeller::Allocation::NextPowerOfTwoSize
static uint32_t NextPowerOfTwoSize(uint32_t x)
Definition: allocation.cc:41
impeller::CreateMappingFromAllocation
std::shared_ptr< fml::Mapping > CreateMappingFromAllocation(const std::shared_ptr< Allocation > &allocation)
Definition: allocation.cc:99
impeller::Allocation::Allocation
Allocation()
impeller::Allocation::GetReservedLength
size_t GetReservedLength() const
Definition: allocation.cc:28
impeller::Allocation::GetLength
size_t GetLength() const
Definition: allocation.cc:24
impeller::Allocation::GetBuffer
uint8_t * GetBuffer() const
Definition: allocation.cc:20
impeller::Allocation
Definition: allocation.h:16
impeller::CreateMappingWithString
std::shared_ptr< fml::Mapping > CreateMappingWithString(std::string string)
Definition: allocation.cc:111
impeller::CreateMappingWithCopy
std::shared_ptr< fml::Mapping > CreateMappingWithCopy(const uint8_t *contents, size_t length)
Definition: allocation.cc:83
impeller
Definition: aiks_context.cc:10
impeller::Allocation::Truncate
bool Truncate(size_t length, bool npot=true)
Definition: allocation.cc:32