Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
image_lru.cc
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#include "flutter/shell/platform/android/image_lru.h"
6
7namespace flutter {
8
10 std::optional<HardwareBufferKey> key) {
11 if (!key.has_value()) {
12 return nullptr;
13 }
14 auto key_value = key.value();
15 for (size_t i = 0u; i < kImageReaderSwapchainSize; i++) {
16 if (images_[i].key == key_value) {
17 auto result = images_[i].value;
18 UpdateKey(result, key_value);
19 return result;
20 }
21 }
22 return nullptr;
23}
24
25void ImageLRU::UpdateKey(const sk_sp<flutter::DlImage>& image,
27 if (images_[0].key == key) {
28 return;
29 }
30 size_t i = 1u;
31 for (; i < kImageReaderSwapchainSize; i++) {
32 if (images_[i].key == key) {
33 break;
34 }
35 }
36 for (auto j = i; j > 0; j--) {
37 images_[j] = images_[j - 1];
38 }
39 images_[0] = Data{.key = key, .value = image};
40}
41
44 HardwareBufferKey lru_key = images_[kImageReaderSwapchainSize - 1].key;
45 bool updated_image = false;
46 for (size_t i = 0u; i < kImageReaderSwapchainSize; i++) {
47 if (images_[i].key == lru_key) {
48 updated_image = true;
49 images_[i] = Data{.key = key, .value = image};
50 break;
51 }
52 }
53 if (!updated_image) {
54 images_[0] = Data{.key = key, .value = image};
55 }
56 UpdateKey(image, key);
57 return lru_key;
58}
59
61 for (size_t i = 0u; i < kImageReaderSwapchainSize; i++) {
62 images_[i] = Data{.key = 0u, .value = nullptr};
63 }
64}
65
66} // namespace flutter
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
sk_sp< flutter::DlImage > FindImage(std::optional< HardwareBufferKey > key)
Retrieve the image associated with the given [key], or nullptr.
Definition image_lru.cc:9
void Clear()
Remove all entires from the image cache.
Definition image_lru.cc:60
sk_sp< SkImage > image
Definition examples.cpp:29
GAsyncResult * result
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