Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
dl_storage.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_DISPLAY_LIST_DL_STORAGE_H_
6#define FLUTTER_DISPLAY_LIST_DL_STORAGE_H_
7
8#include <cstdint>
9#include <memory>
10
11#include "flutter/fml/logging.h"
12
13namespace flutter {
14
15// Manages a buffer allocated with malloc.
17 public:
18 static const constexpr size_t kDLPageSize = 4096u;
19
20 DisplayListStorage() = default;
22
23 /// Returns a pointer to the base of the storage.
24 uint8_t* base() { return ptr_.get(); }
25 const uint8_t* base() const { return ptr_.get(); }
26
27 /// Returns the currently allocated size
28 size_t size() const { return used_; }
29
30 /// Returns the maximum currently allocated space
31 size_t capacity() const { return allocated_; }
32
33 /// Ensures the indicated number of bytes are available and returns
34 /// a pointer to that memory within the storage while also invalidating
35 /// any other outstanding pointers into the storage.
36 uint8_t* allocate(size_t needed);
37
38 /// Trims the storage to the currently allocated size and invalidates
39 /// any outstanding pointers into the storage.
40 void trim() { realloc(used_); }
41
42 /// Resets the storage and allocation of the object to an empty state
43 void reset();
44
46
47 /// @brief Compute the next power of two from [x].
48 static size_t NextPowerOfTwoSize(size_t x);
49
50 private:
51 void realloc(size_t count);
52
53 struct FreeDeleter {
54 void operator()(uint8_t* p) { std::free(p); }
55 };
56 std::unique_ptr<uint8_t, FreeDeleter> ptr_;
57
58 size_t used_ = 0u;
59 size_t allocated_ = 0u;
60};
61
62} // namespace flutter
63
64#endif // FLUTTER_DISPLAY_LIST_DL_STORAGE_H_
void reset()
Resets the storage and allocation of the object to an empty state.
Definition dl_storage.cc:68
const uint8_t * base() const
Definition dl_storage.h:25
DisplayListStorage & operator=(DisplayListStorage &&other)
Definition dl_storage.cc:74
uint8_t * base()
Returns a pointer to the base of the storage.
Definition dl_storage.h:24
static size_t NextPowerOfTwoSize(size_t x)
Compute the next power of two from [x].
Definition dl_storage.cc:14
size_t size() const
Returns the currently allocated size.
Definition dl_storage.h:28
uint8_t * allocate(size_t needed)
Definition dl_storage.cc:39
size_t capacity() const
Returns the maximum currently allocated space.
Definition dl_storage.h:31
static const constexpr size_t kDLPageSize
Definition dl_storage.h:18
int32_t x