forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdl_storage.h
60 lines (42 loc) · 1.66 KB
/
dl_storage.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_DISPLAY_LIST_DL_STORAGE_H_
#define FLUTTER_DISPLAY_LIST_DL_STORAGE_H_
#include <memory>
#include "flutter/fml/logging.h"
namespace flutter {
// Manages a buffer allocated with malloc.
class DisplayListStorage {
public:
static const constexpr size_t kDLPageSize = 4096u;
DisplayListStorage() = default;
DisplayListStorage(DisplayListStorage&&);
/// Returns a pointer to the base of the storage.
uint8_t* base() { return ptr_.get(); }
const uint8_t* base() const { return ptr_.get(); }
/// Returns the currently allocated size
size_t size() const { return used_; }
/// Returns the maximum currently allocated space
size_t capacity() const { return allocated_; }
/// Ensures the indicated number of bytes are available and returns
/// a pointer to that memory within the storage while also invalidating
/// any other outstanding pointers into the storage.
uint8_t* allocate(size_t needed);
/// Trims the storage to the currently allocated size and invalidates
/// any outstanding pointers into the storage.
void trim() { realloc(used_); }
/// Resets the storage and allocation of the object to an empty state
void reset();
DisplayListStorage& operator=(DisplayListStorage&& other);
private:
void realloc(size_t count);
struct FreeDeleter {
void operator()(uint8_t* p) { std::free(p); }
};
std::unique_ptr<uint8_t, FreeDeleter> ptr_;
size_t used_ = 0u;
size_t allocated_ = 0u;
};
} // namespace flutter
#endif // FLUTTER_DISPLAY_LIST_DL_STORAGE_H_