lv_cache.h
Typedefs
-
typedef struct _lv_cache_entry_t lv_cache_entry_t
-
typedef lv_cache_entry_t *(*lv_cache_add_cb)(size_t size)
Add a new entry to the cache with the given size. It won't allocate any buffers just free enough space to be a new entry with
size
bytes fits.- Param size:
the size of the new entry in bytes
- Return:
a handler for the new cache entry
-
typedef lv_cache_entry_t *(*lv_cache_find_cb)(const void *src_ptr, lv_cache_src_type_t src_type, uint32_t param1, uint32_t param2)
Find a cache entry
- Param src_ptr:
pointer to the source data
- Param src_type:
source type (
LV_CACHE_SRC_TYPE_PTR
orLV_CACHE_SRC_TYPE_STR
)- Param param1:
param1, which was set when the cache was added
- Param param2:
param2, which was set when the cache was added
- Return:
the cache entry with given source and parameters or NULL if not found
-
typedef void (*lv_cache_invalidate_cb)(lv_cache_entry_t *entry)
Invalidate (drop) a cache entry
- Param entry:
the entry to invalidate. (can be retrieved by
lv_cache_find()
)
-
typedef const void *(*lv_cache_get_data_cb)(lv_cache_entry_t *entry)
Get the data of a cache entry. It is considered a cached data access so the cache manager can count that this entry was used on more times, and therefore it's more relevant. It also increments entry->usage_count to indicate that the data is being used and cannot be dropped.
- Param entry:
the cache entry whose data should be retrieved
-
typedef void (*lv_cache_release_cb)(lv_cache_entry_t *entry)
Mark the cache entry as unused. It decrements entry->usage_count.
- Param entry:
the cache entry to invalidate
-
typedef void (*lv_cache_set_max_size_cb)(size_t size)
Set maximum cache size in bytes.
- Param size:
the max size in byes
-
typedef void (*lv_cache_empty_cb)(void)
Empty the cache.
Enums
Functions
-
void _lv_cache_init(void)
Initialize the cache module
-
void lv_cache_set_manager(lv_cache_manager_t *manager)
Set new cache manager
- Parameters:
manager -- the new cache manager with callback functions set
-
lv_cache_entry_t *lv_cache_add(size_t size)
Add a new entry to the cache with the given size. It won't allocate any buffers just free enough space to be a new entry with
size
bytes fits.- Parameters:
size -- the size of the new entry in bytes
- Returns:
a handler for the new cache entry
-
lv_cache_entry_t *lv_cache_find(const void *src, lv_cache_src_type_t src_type, uint32_t param1, uint32_t param2)
Find a cache entry with pointer source type
- Parameters:
src_ptr -- pointer to the source data
src_type -- source type (
LV_CACHE_SRC_TYPE_PTR
orLV_CACHE_SRC_TYPE_STR
)param1 -- param1, which was set when the cache was added
param2 -- param2, which was set when the cache was added
- Returns:
the cache entry with given source and parameters or NULL if not found
-
void lv_cache_invalidate(lv_cache_entry_t *entry)
Invalidate (drop) a cache entry
- Parameters:
entry -- the entry to invalidate. (can be retrieved by
lv_cache_find()
)
-
const void *lv_cache_get_data(lv_cache_entry_t *entry)
Get the data of a cache entry. It is considered a cached data access so the cache manager can count that this entry was used on more times, and therefore it's more relevant. It also increments entry->usage_count to indicate that the data is being used and cannot be dropped.
- Parameters:
entry -- the cache entry whose data should be retrieved
-
void lv_cache_release(lv_cache_entry_t *entry)
Mark the cache entry as unused. It decrements entry->usage_count.
- Parameters:
entry --
-
void lv_cache_set_max_size(size_t size)
Set maximum cache size in bytes.
- Parameters:
size -- the max size in byes
-
size_t lv_cache_get_max_size(void)
Get the max size of the cache
- Returns:
the max size in bytes
-
void lv_cache_lock(void)
Lock the mutex of the cache. Needs to be called manually before any cache operation,
-
void lv_cache_unlock(void)
Unlock the mutex of the cache. Needs to be called manually after any cache operation,
-
struct _lv_cache_entry_t
Public Members
-
const void *src
The image source or other source related to the cache content.
-
lv_cache_src_type_t src_type
-
uint32_t param1
Some extra parameters to describe the source. E.g. the current frame of an animation
-
uint32_t param2
-
uint32_t process_state
User processing tag
-
const void *data
The data to cache
-
uint32_t data_size
Size of data in bytes
-
uint32_t weight
On access to any cache entry,
life
of each cache entry will be incremented by their ownweight
to keep the entry alive longer
-
int32_t life
The current
life
. Entries with the smallest life will be purged from the cache if a new entry needs to be cached
-
uint32_t usage_count
Count how many times the cached data is being used. It will be incremented in lv_cache_get_data and decremented in lv_cache_release. A data will dropped from the cache only if its usage_count is zero
-
uint32_t free_src
Call
lv_free
onsrc
when the entry is removed from the cache
-
uint32_t free_data
Call
lv_draw_buf_free
ondata
when the entry is removed from the cache
-
uint32_t temporary
The cache entry was larger then the max cache size so only a temporary entry was allocated The entry will be closed and freed in
lv_cache_release
automatically
-
void *user_data
Any user data if needed
-
const void *src
-
struct lv_cache_manager_t
Public Members
-
lv_cache_add_cb add_cb
-
lv_cache_find_cb find_cb
-
lv_cache_invalidate_cb invalidate_cb
-
lv_cache_get_data_cb get_data_cb
-
lv_cache_release_cb release_cb
-
lv_cache_set_max_size_cb set_max_size_cb
-
lv_cache_empty_cb empty_cb
-
lv_mutex_t mutex
-
size_t max_size
-
uint32_t locked
Show the mutex state, used to log unlocked cache access
-
lv_cache_add_cb add_cb