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