1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-21 06:53:01 +08:00
lvgl/src/lv_draw/lv_img_cache.h

79 lines
2.2 KiB
C
Raw Normal View History

2019-06-20 18:43:03 +02:00
/**
* @file lv_img_cache.h
*
*/
2019-06-20 23:14:17 +02:00
#ifndef LV_IMG_CACHE_H
#define LV_IMG_CACHE_H
2019-06-20 18:43:03 +02:00
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lv_img_decoder.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
2019-06-27 18:07:26 -04:00
/**
* When loading images from the network it can take a long time to download and decode the image.
*
* To avoid repeating this heavy load images can be cached.
*/
2019-06-20 18:43:03 +02:00
typedef struct
{
2019-06-27 18:07:26 -04:00
lv_img_decoder_dsc_t dec_dsc; /**< Image information */
2019-06-20 18:43:03 +02:00
2019-06-27 18:07:26 -04:00
/** Count the cache entries's life. Add `time_tio_open` to `life` when the entry is used.
* Decrement all lifes by one every in every ::lv_img_cache_open.
* If life == 0 the entry can be reused */
2019-06-20 23:14:17 +02:00
int32_t life;
2019-06-27 07:16:15 +02:00
} lv_img_cache_entry_t;
2019-06-20 18:43:03 +02:00
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Open an image using the image decoder interface and cache it.
* The image will be left open meaning if the image decoder open callback allocated memory then it will remain.
* The image is closed if a new image is opened and the new image takes its place in the cache.
* @param src source of the image. Path to file or pointer to an `lv_img_dsc_t` variable
* @param style style of the image
* @return pointer to the cache entry or NULL if can open the image
*/
2019-06-20 23:14:17 +02:00
lv_img_cache_entry_t * lv_img_cache_open(const void * src, const lv_style_t * style);
2019-06-20 18:43:03 +02:00
/**
* Set the number of images to be cached.
* More cached images mean more opened image at same time which might mean more memory usage.
* E.g. if 20 PNG or JPG images are open in the RAM they consume memory while opened in the cache.
2019-06-25 17:14:11 +02:00
* @param new_entry_cnt number of image to cache
2019-06-20 18:43:03 +02:00
*/
void lv_img_cache_set_size(uint16_t new_slot_num);
/**
* Invalidate an image source in the cache.
* Useful if the image source is updated therefore it needs to be cached again.
* @param src an image source path to a file or pointer to an `lv_img_dsc_t` variable.
*/
void lv_img_cache_invalidate_src(const void * src);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
2019-06-20 23:14:17 +02:00
#endif /*LV_IMG_CACHE_H*/