mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
feat(image_cache): add dump info ability for image_cache
This commit is contained in:
parent
4d7f577c7c
commit
30f0d6c10a
7
src/misc/cache/lv_cache.c
vendored
7
src/misc/cache/lv_cache.c
vendored
@ -292,6 +292,13 @@ const char * lv_cache_get_name(lv_cache_t * cache)
|
||||
return cache->name;
|
||||
}
|
||||
|
||||
lv_iter_t * lv_cache_iter_create(lv_cache_t * cache)
|
||||
{
|
||||
LV_ASSERT_NULL(cache);
|
||||
if(cache == NULL || cache->clz->iter_create_cb == NULL) return NULL;
|
||||
return cache->clz->iter_create_cb(cache);
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
2
src/misc/cache/lv_cache.h
vendored
2
src/misc/cache/lv_cache.h
vendored
@ -215,6 +215,8 @@ void lv_cache_set_name(lv_cache_t * cache, const char * name);
|
||||
*/
|
||||
const char * lv_cache_get_name(lv_cache_t * cache);
|
||||
|
||||
lv_iter_t * lv_cache_iter_create(lv_cache_t * cache);
|
||||
|
||||
/*************************
|
||||
* GLOBAL VARIABLES
|
||||
*************************/
|
||||
|
37
src/misc/cache/lv_cache_lru_rb.c
vendored
37
src/misc/cache/lv_cache_lru_rb.c
vendored
@ -48,6 +48,8 @@
|
||||
#include "../../stdlib/lv_string.h"
|
||||
#include "../lv_ll.h"
|
||||
#include "../lv_rb_private.h"
|
||||
#include "../lv_rb.h"
|
||||
#include "../lv_iter.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
@ -91,6 +93,9 @@ inline static void ** get_lru_node(lv_lru_rb_t_ * lru, lv_rb_node_t * node);
|
||||
static uint32_t cnt_get_data_size_cb(const void * data);
|
||||
static uint32_t size_get_data_size_cb(const void * data);
|
||||
|
||||
static lv_iter_t * cache_iter_create_cb(lv_cache_t * cache);
|
||||
static lv_result_t cache_iter_next_cb(void * instance, void * context, void * elem);
|
||||
|
||||
/**********************
|
||||
* GLOBAL VARIABLES
|
||||
**********************/
|
||||
@ -105,7 +110,8 @@ const lv_cache_class_t lv_cache_class_lru_rb_count = {
|
||||
.drop_cb = drop_cb,
|
||||
.drop_all_cb = drop_all_cb,
|
||||
.get_victim_cb = get_victim_cb,
|
||||
.reserve_cond_cb = reserve_cond_cb
|
||||
.reserve_cond_cb = reserve_cond_cb,
|
||||
.iter_create_cb = cache_iter_create_cb,
|
||||
};
|
||||
|
||||
const lv_cache_class_t lv_cache_class_lru_rb_size = {
|
||||
@ -119,7 +125,8 @@ const lv_cache_class_t lv_cache_class_lru_rb_size = {
|
||||
.drop_cb = drop_cb,
|
||||
.drop_all_cb = drop_all_cb,
|
||||
.get_victim_cb = get_victim_cb,
|
||||
.reserve_cond_cb = reserve_cond_cb
|
||||
.reserve_cond_cb = reserve_cond_cb,
|
||||
.iter_create_cb = cache_iter_create_cb,
|
||||
};
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@ -460,3 +467,29 @@ static uint32_t size_get_data_size_cb(const void * data)
|
||||
lv_cache_slot_size_t * slot = (lv_cache_slot_size_t *)data;
|
||||
return slot->size;
|
||||
}
|
||||
|
||||
static lv_iter_t * cache_iter_create_cb(lv_cache_t * cache)
|
||||
{
|
||||
return lv_iter_create(cache, lv_cache_entry_get_size(cache->node_size), sizeof(void *), cache_iter_next_cb);
|
||||
}
|
||||
|
||||
static lv_result_t cache_iter_next_cb(void * instance, void * context, void * elem)
|
||||
{
|
||||
lv_lru_rb_t_ * lru = (lv_lru_rb_t_ *)instance;
|
||||
lv_rb_node_t *** ll_node = context;
|
||||
|
||||
LV_ASSERT_NULL(ll_node);
|
||||
|
||||
if(*ll_node == NULL) *ll_node = lv_ll_get_head(&lru->ll);
|
||||
else *ll_node = lv_ll_get_next(&lru->ll, *ll_node);
|
||||
|
||||
lv_rb_node_t ** node = *ll_node;
|
||||
|
||||
if(node == NULL) return LV_RESULT_INVALID;
|
||||
|
||||
uint32_t node_size = lru->cache.node_size;
|
||||
void * search_key = (*node)->data;
|
||||
lv_memcpy(elem, search_key, lv_cache_entry_get_size(node_size));
|
||||
|
||||
return LV_RESULT_OK;
|
||||
}
|
||||
|
4
src/misc/cache/lv_cache_private.h
vendored
4
src/misc/cache/lv_cache_private.h
vendored
@ -107,6 +107,8 @@ typedef lv_cache_entry_t * (*lv_cache_get_victim_cb)(lv_cache_t * cache, void *
|
||||
typedef lv_cache_reserve_cond_res_t (*lv_cache_reserve_cond_cb)(lv_cache_t * cache, const void * key, size_t size,
|
||||
void * user_data);
|
||||
|
||||
typedef lv_iter_t * (*lv_cache_iter_create_cb)(lv_cache_t * cache);
|
||||
|
||||
/**
|
||||
* The cache operations struct
|
||||
*/
|
||||
@ -155,6 +157,8 @@ struct lv_cache_class_t {
|
||||
lv_cache_drop_all_cb_t drop_all_cb; /**< The drop all function for cache entries */
|
||||
lv_cache_get_victim_cb get_victim_cb; /**< The get victim function for cache entries */
|
||||
lv_cache_reserve_cond_cb reserve_cond_cb; /**< The reserve condition function for cache entries */
|
||||
|
||||
lv_cache_iter_create_cb iter_create_cb; /**< The iterator creation function for cache entries */
|
||||
};
|
||||
|
||||
/*-----------------
|
||||
|
46
src/misc/cache/lv_image_cache.c
vendored
46
src/misc/cache/lv_image_cache.c
vendored
@ -10,6 +10,7 @@
|
||||
#include "../../draw/lv_image_decoder_private.h"
|
||||
#include "../lv_assert.h"
|
||||
#include "../../core/lv_global.h"
|
||||
#include "../../misc/lv_iter.h"
|
||||
|
||||
#include "lv_image_cache.h"
|
||||
#include "lv_image_header_cache.h"
|
||||
@ -34,6 +35,7 @@
|
||||
static lv_cache_compare_res_t image_cache_compare_cb(const lv_image_cache_data_t * lhs,
|
||||
const lv_image_cache_data_t * rhs);
|
||||
static void image_cache_free_cb(lv_image_cache_data_t * entry, void * user_data);
|
||||
static void iter_inspect_cb(void * elem);
|
||||
|
||||
/**********************
|
||||
* GLOBAL VARIABLES
|
||||
@ -99,6 +101,21 @@ bool lv_image_cache_is_enabled(void)
|
||||
return lv_cache_is_enabled(img_cache_p);
|
||||
}
|
||||
|
||||
lv_iter_t * lv_image_cache_iter_create(void)
|
||||
{
|
||||
return lv_cache_iter_create(img_cache_p);
|
||||
}
|
||||
|
||||
void lv_image_cache_dump(void)
|
||||
{
|
||||
lv_iter_t * iter = lv_image_cache_iter_create();
|
||||
if(iter == NULL) return;
|
||||
|
||||
LV_LOG_USER("Image cache dump:");
|
||||
LV_LOG_USER("\tsize\tdata_size\tcf\trc\ttype\tdecoded\t\t\tsrc");
|
||||
lv_iter_inspect(iter, iter_inspect_cb);
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
@ -143,3 +160,32 @@ static void image_cache_free_cb(lv_image_cache_data_t * entry, void * user_data)
|
||||
/*Free the duplicated file name*/
|
||||
if(entry->src_type == LV_IMAGE_SRC_FILE) lv_free((void *)entry->src);
|
||||
}
|
||||
|
||||
static void iter_inspect_cb(void * elem)
|
||||
{
|
||||
lv_image_cache_data_t * data = (lv_image_cache_data_t *)elem;
|
||||
lv_draw_buf_t * decoded = (lv_draw_buf_t *)data->decoded;
|
||||
lv_image_header_t * header = &decoded->header;
|
||||
lv_cache_entry_t * entry = lv_cache_entry_get_entry(data, img_cache_p->node_size);
|
||||
|
||||
LV_UNUSED(decoded);
|
||||
LV_UNUSED(header);
|
||||
LV_UNUSED(entry);
|
||||
|
||||
/* size data_size cf rc type decoded src*/
|
||||
#define IMAGE_CACHE_DUMP_FORMAT " %4dx%-4d %9d %d %d "
|
||||
switch(data->src_type) {
|
||||
case LV_IMAGE_SRC_FILE:
|
||||
LV_LOG_USER(IMAGE_CACHE_DUMP_FORMAT "file\t%-12p\t%s", header->w, header->h, decoded->data_size, header->cf,
|
||||
lv_cache_entry_get_ref(entry), (void *)data->decoded, (char *)data->src);
|
||||
break;
|
||||
case LV_IMAGE_SRC_VARIABLE:
|
||||
LV_LOG_USER(IMAGE_CACHE_DUMP_FORMAT "var \t%-12p\t%p", header->w, header->h, decoded->data_size, header->cf,
|
||||
lv_cache_entry_get_ref(entry), (void *)data->decoded, data->src);
|
||||
break;
|
||||
default:
|
||||
LV_LOG_USER(IMAGE_CACHE_DUMP_FORMAT "unkn\t%-12p\t%p", header->w, header->h, decoded->data_size, header->cf,
|
||||
lv_cache_entry_get_ref(entry), (void *)data->decoded, data->src);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
11
src/misc/cache/lv_image_cache.h
vendored
11
src/misc/cache/lv_image_cache.h
vendored
@ -56,6 +56,17 @@ void lv_image_cache_drop(const void * src);
|
||||
*/
|
||||
bool lv_image_cache_is_enabled(void);
|
||||
|
||||
/**
|
||||
* Create an iterator to iterate over the image cache.
|
||||
* @return an iterator to iterate over the image cache.
|
||||
*/
|
||||
lv_iter_t * lv_image_cache_iter_create(void);
|
||||
|
||||
/**
|
||||
* Dump the content of the image cache in a human-readable format with cache order.
|
||||
*/
|
||||
void lv_image_cache_dump(void);
|
||||
|
||||
/*************************
|
||||
* GLOBAL VARIABLES
|
||||
*************************/
|
||||
|
46
src/misc/cache/lv_image_header_cache.c
vendored
46
src/misc/cache/lv_image_header_cache.c
vendored
@ -12,6 +12,7 @@
|
||||
#include "../../core/lv_global.h"
|
||||
|
||||
#include "lv_image_header_cache.h"
|
||||
#include "../lv_iter.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
@ -32,6 +33,7 @@
|
||||
static lv_cache_compare_res_t image_header_cache_compare_cb(const lv_image_header_cache_data_t * lhs,
|
||||
const lv_image_header_cache_data_t * rhs);
|
||||
static void image_header_cache_free_cb(lv_image_header_cache_data_t * entry, void * user_data);
|
||||
static void iter_inspect_cb(void * elem);
|
||||
|
||||
/**********************
|
||||
* GLOBAL VARIABLES
|
||||
@ -94,6 +96,21 @@ bool lv_image_header_cache_is_enabled(void)
|
||||
return lv_cache_is_enabled(img_header_cache_p);
|
||||
}
|
||||
|
||||
lv_iter_t * lv_image_header_cache_iter_create(void)
|
||||
{
|
||||
return lv_cache_iter_create(img_header_cache_p);
|
||||
}
|
||||
|
||||
void lv_image_header_cache_dump(void)
|
||||
{
|
||||
lv_iter_t * iter = lv_image_cache_iter_create();
|
||||
if(iter == NULL) return;
|
||||
|
||||
LV_LOG_USER("Image cache dump:");
|
||||
LV_LOG_USER("\tsize\tdata_size\tcf\trc\ttype\tdecoded\t\t\tsrc");
|
||||
lv_iter_inspect(iter, iter_inspect_cb);
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
@ -131,3 +148,32 @@ static void image_header_cache_free_cb(lv_image_header_cache_data_t * entry, voi
|
||||
|
||||
if(entry->src_type == LV_IMAGE_SRC_FILE) lv_free((void *)entry->src);
|
||||
}
|
||||
|
||||
static void iter_inspect_cb(void * elem)
|
||||
{
|
||||
lv_image_cache_data_t * data = (lv_image_cache_data_t *)elem;
|
||||
lv_draw_buf_t * decoded = (lv_draw_buf_t *)data->decoded;
|
||||
lv_image_header_t * header = &decoded->header;
|
||||
lv_cache_entry_t * entry = lv_cache_entry_get_entry(data, img_header_cache_p->node_size);
|
||||
|
||||
LV_UNUSED(decoded);
|
||||
LV_UNUSED(header);
|
||||
LV_UNUSED(entry);
|
||||
|
||||
/* size data_size cf rc type decoded src*/
|
||||
#define IMAGE_CACHE_DUMP_FORMAT " %4dx%-4d %9d %d %d "
|
||||
switch(data->src_type) {
|
||||
case LV_IMAGE_SRC_FILE:
|
||||
LV_LOG_USER(IMAGE_CACHE_DUMP_FORMAT "file\t%-12p\t%s", header->w, header->h, decoded->data_size, header->cf,
|
||||
lv_cache_entry_get_ref(entry), (void *)data->decoded, (char *)data->src);
|
||||
break;
|
||||
case LV_IMAGE_SRC_VARIABLE:
|
||||
LV_LOG_USER(IMAGE_CACHE_DUMP_FORMAT "var \t%-12p\t%p", header->w, header->h, decoded->data_size, header->cf,
|
||||
lv_cache_entry_get_ref(entry), (void *)data->decoded, data->src);
|
||||
break;
|
||||
default:
|
||||
LV_LOG_USER(IMAGE_CACHE_DUMP_FORMAT "unkn\t%-12p\t%p", header->w, header->h, decoded->data_size, header->cf,
|
||||
lv_cache_entry_get_ref(entry), (void *)data->decoded, data->src);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
11
src/misc/cache/lv_image_header_cache.h
vendored
11
src/misc/cache/lv_image_header_cache.h
vendored
@ -57,6 +57,17 @@ void lv_image_header_cache_drop(const void * src);
|
||||
*/
|
||||
bool lv_image_header_cache_is_enabled(void);
|
||||
|
||||
/**
|
||||
* Create an iterator to iterate over the image header cache.
|
||||
* @return an iterator to iterate over the image header cache.
|
||||
*/
|
||||
lv_iter_t * lv_image_header_cache_iter_create(void);
|
||||
|
||||
/**
|
||||
* Dump the content of the image header cache in a human-readable format with cache order.
|
||||
*/
|
||||
void lv_image_header_cache_dump(void);
|
||||
|
||||
/*************************
|
||||
* GLOBAL VARIABLES
|
||||
*************************/
|
||||
|
Loading…
x
Reference in New Issue
Block a user