Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
image_lru.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_SHELL_PLATFORM_ANDROID_IMAGE_LRU_H_
6#define FLUTTER_SHELL_PLATFORM_ANDROID_IMAGE_LRU_H_
7
8#include <array>
9#include <cstddef>
10
12
13namespace flutter {
14
15// This value needs to be larger than the number of swapchain images
16// that a typical image reader will produce to ensure that we effectively
17// cache. If the value is too small, we will unnecessarily churn through
18// images, while if it is too large we may retain images longer than
19// necessary.
20static constexpr size_t kImageReaderSwapchainSize = 6u;
21
22using HardwareBufferKey = uint64_t;
23
24class ImageLRU {
25 public:
26 ImageLRU() = default;
27
28 ~ImageLRU() = default;
29
30 /// @brief Retrieve the image associated with the given [key], or nullptr.
31 sk_sp<flutter::DlImage> FindImage(std::optional<HardwareBufferKey> key);
32
33 /// @brief Add a new image to the cache with a key, returning the key of the
34 /// LRU entry that was removed.
35 ///
36 /// The value may be `0`, in which case nothing was removed.
39
40 /// @brief Remove all entires from the image cache.
41 void Clear();
42
43 private:
44 /// @brief Marks [key] as the most recently used.
45 void UpdateKey(const sk_sp<flutter::DlImage>& image, HardwareBufferKey key);
46
47 struct Data {
50 };
51
52 std::array<Data, kImageReaderSwapchainSize> images_;
53};
54
55} // namespace flutter
56
57#endif // FLUTTER_SHELL_PLATFORM_ANDROID_IMAGE_LRU_H_
HardwareBufferKey AddImage(const sk_sp< flutter::DlImage > &image, HardwareBufferKey key)
Add a new image to the cache with a key, returning the key of the LRU entry that was removed.
Definition image_lru.cc:42
~ImageLRU()=default
sk_sp< flutter::DlImage > FindImage(std::optional< HardwareBufferKey > key)
Retrieve the image associated with the given [key], or nullptr.
Definition image_lru.cc:9
ImageLRU()=default
void Clear()
Remove all entires from the image cache.
Definition image_lru.cc:60
sk_sp< SkImage > image
Definition examples.cpp:29
uint8_t value
static constexpr size_t kImageReaderSwapchainSize
Definition image_lru.h:20
struct PathData * Data(SkPath *path)
Definition path_ops.cc:52
uint64_t HardwareBufferKey
Definition image_lru.h:22