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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user