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