feat(img_cache): add support for alternate img cache algorithm (#3798)

Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com>
Co-authored-by: pengyiqiang <pengyiqiang@xiaomi.com>
This commit is contained in:
_VIFEXTech
2022-11-19 16:26:17 +08:00
committed by GitHub
parent 1e07853533
commit ef62275ffb
6 changed files with 353 additions and 170 deletions

View File

@@ -316,6 +316,42 @@ Let's say you have loaded a PNG image into a `lv_img_dsc_t my_png` variable and
To do this, use `lv_img_cache_invalidate_src(&my_png)`. If `NULL` is passed as a parameter, the whole cache will be cleaned.
### Custom cache algorithm
If you want to implement your own cache algorithm, you can refer to the following code to replace the LVGL built-in image cache manager:
```c
static _lv_img_cache_entry_t * my_img_cache_open(const void * src, lv_color_t color, int32_t frame_id)
{
...
}
static void my_img_cache_set_size(uint16_t new_entry_cnt)
{
...
}
static void my_img_cache_invalidate_src(const void * src)
{
...
}
void my_img_cache_init(void)
{
/* Before replacing the image cache manager,
* you should ensure that all caches are cleared to prevent memory leaks.
*/
lv_img_cache_invalidate_src(NULL);
/*Initialize image cache manager.*/
lv_img_cache_manager_t manager;
lv_img_cache_manager_init(&manager);
manager.open_cb = my_img_cache_open;
manager.set_size_cb = my_img_cache_set_size;
manager.invalidate_src_cb = my_img_cache_invalidate_src;
/*Apply image cache manager to LVGL.*/
lv_img_cache_manager_apply(&manager);
}
```
## API