Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
image_lru_unittests.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
7#include "gtest/gtest.h"
8
9namespace flutter {
10namespace testing {
11
12TEST(ImageLRU, CanStoreSingleImage) {
13 auto image = DlImageSkia::Make(nullptr);
14 ImageLRU image_lru;
15
16 EXPECT_EQ(image_lru.FindImage(1), nullptr);
17
18 image_lru.AddImage(image, 1);
19
20 EXPECT_EQ(image_lru.FindImage(1), image);
21}
22
23TEST(ImageLRU, EvictsLRU) {
24 auto image = DlImageSkia::Make(nullptr);
25 ImageLRU image_lru;
26
27 // Fill up the cache, nothing is removed
28 for (auto i = 0u; i < kImageReaderSwapchainSize; i++) {
29 EXPECT_EQ(image_lru.AddImage(image, i + 1), 0u);
30 }
31 // Confirm each image is in the cache. This should keep the LRU
32 // order the same.
33 for (auto i = 0u; i < kImageReaderSwapchainSize; i++) {
34 EXPECT_EQ(image_lru.FindImage(i + 1), image);
35 }
36
37 // Insert new image and verify least recently used was removed.
38 EXPECT_EQ(image_lru.AddImage(image, 100), 1u);
39}
40
41TEST(ImageLRU, CanClear) {
42 auto image = DlImageSkia::Make(nullptr);
43 ImageLRU image_lru;
44
45 // Fill up the cache, nothing is removed
46 for (auto i = 0u; i < kImageReaderSwapchainSize; i++) {
47 EXPECT_EQ(image_lru.AddImage(image, i + 1), 0u);
48 }
49 image_lru.Clear();
50
51 // Expect no cache entries.
52 for (auto i = 0u; i < kImageReaderSwapchainSize; i++) {
53 EXPECT_EQ(image_lru.FindImage(i + 1), nullptr);
54 }
55}
56
57} // namespace testing
58} // namespace flutter
static sk_sp< DlImage > Make(const SkImage *image)
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
FlutterVulkanImage * image
TEST(NativeAssetsManagerTest, NoAvailableAssets)
static constexpr size_t kImageReaderSwapchainSize
Definition image_lru.h:20