Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
flutter::ImageLRU Class Reference

#include <image_lru.h>

Public Member Functions

 ImageLRU ()=default
 
 ~ImageLRU ()=default
 
sk_sp< flutter::DlImageFindImage (std::optional< HardwareBufferKey > key)
 Retrieve the image associated with the given [key], or nullptr. More...
 
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. More...
 
void Clear ()
 Remove all entires from the image cache. More...
 

Detailed Description

Definition at line 24 of file image_lru.h.

Constructor & Destructor Documentation

◆ ImageLRU()

flutter::ImageLRU::ImageLRU ( )
default

◆ ~ImageLRU()

flutter::ImageLRU::~ImageLRU ( )
default

Member Function Documentation

◆ AddImage()

HardwareBufferKey flutter::ImageLRU::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.

The value may be 0, in which case nothing was removed.

Definition at line 42 of file image_lru.cc.

43 {
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}
sk_sp< const SkImage > image
Definition: SkRecords.h:269
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

◆ Clear()

void flutter::ImageLRU::Clear ( )

Remove all entires from the image cache.

Definition at line 60 of file image_lru.cc.

60 {
61 for (size_t i = 0u; i < kImageReaderSwapchainSize; i++) {
62 images_[i] = Data{.key = 0u, .value = nullptr};
63 }
64}

◆ FindImage()

sk_sp< flutter::DlImage > flutter::ImageLRU::FindImage ( std::optional< HardwareBufferKey key)

Retrieve the image associated with the given [key], or nullptr.

Definition at line 9 of file image_lru.cc.

10 {
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}
GAsyncResult * result

The documentation for this class was generated from the following files: