Update lvgl to v8.4.0

This commit is contained in:
lewisxhe
2024-09-13 11:35:47 +08:00
parent 1a57bfcf2b
commit f285d52d61
641 changed files with 25425 additions and 30726 deletions
+7 -1
View File
@@ -49,7 +49,6 @@ static lv_timer_t * _lv_anim_tmr;
#define TRACE_ANIM(...)
#endif
/**********************
* GLOBAL FUNCTIONS
**********************/
@@ -147,6 +146,7 @@ bool lv_anim_del(void * var, lv_anim_exec_xcb_t exec_cb)
if((a->var == var || var == NULL) && (a->exec_cb == exec_cb || exec_cb == NULL)) {
_lv_ll_remove(&LV_GC_ROOT(_lv_anim_ll), a);
if(a->deleted_cb != NULL) a->deleted_cb(a);
lv_mem_free(a);
anim_mark_list_change(); /*Read by `anim_timer`. It need to know if a delete occurred in
the linked list*/
@@ -177,6 +177,11 @@ lv_anim_t * lv_anim_get(void * var, lv_anim_exec_xcb_t exec_cb)
return NULL;
}
struct _lv_timer_t * lv_anim_get_timer(void)
{
return _lv_anim_tmr;
}
uint16_t lv_anim_count_running(void)
{
uint16_t cnt = 0;
@@ -429,6 +434,7 @@ static void anim_ready_handler(lv_anim_t * a)
/*Call the callback function at the end*/
if(a->ready_cb != NULL) a->ready_cb(a);
if(a->deleted_cb != NULL) a->deleted_cb(a);
lv_mem_free(a);
}
/*If the animation is not deleted then restart it*/
+21
View File
@@ -40,6 +40,7 @@ typedef enum {
} lv_anim_enable_t;
struct _lv_anim_t;
struct _lv_timer_t;
/** Get the current value during an animation*/
typedef int32_t (*lv_anim_path_cb_t)(const struct _lv_anim_t *);
@@ -65,12 +66,16 @@ typedef void (*lv_anim_start_cb_t)(struct _lv_anim_t *);
/** Callback used when the animation values are relative to get the current value*/
typedef int32_t (*lv_anim_get_value_cb_t)(struct _lv_anim_t *);
/** Callback used when the animation is deleted*/
typedef void (*lv_anim_deleted_cb_t)(struct _lv_anim_t *);
/** Describes an animation*/
typedef struct _lv_anim_t {
void * var; /**<Variable to animate*/
lv_anim_exec_xcb_t exec_cb; /**< Function to execute to animate*/
lv_anim_start_cb_t start_cb; /**< Call it when the animation is starts (considering `delay`)*/
lv_anim_ready_cb_t ready_cb; /**< Call it when the animation is ready*/
lv_anim_deleted_cb_t deleted_cb; /**< Call it when the animation is deleted*/
lv_anim_get_value_cb_t get_value_cb; /**< Get the current value in relative mode*/
#if LV_USE_USER_DATA
void * user_data; /**< Custom user data*/
@@ -224,6 +229,16 @@ static inline void lv_anim_set_ready_cb(lv_anim_t * a, lv_anim_ready_cb_t ready_
a->ready_cb = ready_cb;
}
/**
* Set a function call when the animation is deleted.
* @param a pointer to an initialized `lv_anim_t` variable
* @param deleted_cb a function call when the animation is deleted
*/
static inline void lv_anim_set_deleted_cb(lv_anim_t * a, lv_anim_deleted_cb_t deleted_cb)
{
a->deleted_cb = deleted_cb;
}
/**
* Make the animation to play back to when the forward direction is ready
* @param a pointer to an initialized `lv_anim_t` variable
@@ -345,6 +360,12 @@ void lv_anim_del_all(void);
*/
lv_anim_t * lv_anim_get(void * var, lv_anim_exec_xcb_t exec_cb);
/**
* Get global animation refresher timer.
* @return pointer to the animation refresher timer.
*/
struct _lv_timer_t * lv_anim_get_timer(void);
/**
* Delete an animation by getting the animated variable from `a`.
* Only animations with `exec_cb` will be deleted.
+124
View File
@@ -143,6 +143,78 @@ bool _lv_area_intersect(lv_area_t * res_p, const lv_area_t * a1_p, const lv_area
return union_ok;
}
/**
* Get resulting sub areas after removing the common parts of two areas from the first area
* @param res_p pointer to an array of areas with a count of 4, the resulting areas will be stored here
* @param a1_p pointer to the first area
* @param a2_p pointer to the second area
* @return number of results or -1 if no intersect
*/
int8_t _lv_area_diff(lv_area_t * res_p, const lv_area_t * a1_p, const lv_area_t * a2_p)
{
/*Areas have no common parts*/
if(!_lv_area_is_on(a1_p, a2_p)) return -1;
/*No remaining areas after removing common parts*/
if(_lv_area_is_in(a1_p, a2_p, 0)) return 0;
/*Result counter*/
int8_t res_c = 0;
/*Get required information*/
lv_area_t n;
lv_coord_t a1_w = lv_area_get_width(a1_p) - 1;
lv_coord_t a1_h = lv_area_get_height(a1_p) - 1;
/*Compute top rectangle*/
lv_coord_t th = a2_p->y1 - a1_p->y1;
if(th > 0) {
n.x1 = a1_p->x1;
n.y1 = a1_p->y1;
n.x2 = a1_p->x2;
n.y2 = a1_p->y1 + th;
res_p[res_c++] = n;
}
/*Compute the bottom rectangle*/
lv_coord_t bh = a1_h - (a2_p->y2 - a1_p->y1);
if(bh > 0 && a2_p->y2 < a1_p->y2) {
n.x1 = a1_p->x1;
n.y1 = a2_p->y2;
n.x2 = a1_p->x2;
n.y2 = a2_p->y2 + bh;
res_p[res_c++] = n;
}
/*Compute side height*/
lv_coord_t y1 = a2_p->y1 > a1_p->y1 ? a2_p->y1 : a1_p->y1;
lv_coord_t y2 = a2_p->y2 < a1_p->y2 ? a2_p->y2 : a1_p->y2;
lv_coord_t sh = y2 - y1;
/*Compute the left rectangle*/
lv_coord_t lw = a2_p->x1 - a1_p->x1;
if(lw > 0 && sh > 0) {
n.x1 = a1_p->x1;
n.y1 = y1;
n.x2 = a1_p->x1 + lw;
n.y2 = y1 + sh;
res_p[res_c++] = n;
}
/*Compute the right rectangle*/
lv_coord_t rw = a1_w - (a2_p->x2 - a1_p->x1);
if(rw > 0) {
n.x1 = a2_p->x2;
n.y1 = y1;
n.x2 = a2_p->x2 + rw;
n.y2 = y1 + sh;
res_p[res_c++] = n;
}
//Return number of results
return res_c;
}
/**
* Join two areas into a third which involves the other two
* @param res_p pointer to an area, the result will be stored here
@@ -456,6 +528,58 @@ void lv_area_align(const lv_area_t * base, lv_area_t * to_align, lv_align_t alig
to_align->y2 = to_align->y1 + h - 1;
}
#define _LV_TRANSFORM_TRIGO_SHIFT 10
void lv_point_transform(lv_point_t * p, int32_t angle, int32_t zoom, const lv_point_t * pivot)
{
if(angle == 0 && zoom == 256) {
return;
}
p->x -= pivot->x;
p->y -= pivot->y;
if(angle == 0) {
p->x = (((int32_t)(p->x) * zoom) >> 8) + pivot->x;
p->y = (((int32_t)(p->y) * zoom) >> 8) + pivot->y;
return;
}
static int32_t angle_prev = INT32_MIN;
static int32_t sinma;
static int32_t cosma;
if(angle_prev != angle) {
int32_t angle_limited = angle;
if(angle_limited > 3600) angle_limited -= 3600;
if(angle_limited < 0) angle_limited += 3600;
int32_t angle_low = angle_limited / 10;
int32_t angle_high = angle_low + 1;
int32_t angle_rem = angle_limited - (angle_low * 10);
int32_t s1 = lv_trigo_sin(angle_low);
int32_t s2 = lv_trigo_sin(angle_high);
int32_t c1 = lv_trigo_sin(angle_low + 90);
int32_t c2 = lv_trigo_sin(angle_high + 90);
sinma = (s1 * (10 - angle_rem) + s2 * angle_rem) / 10;
cosma = (c1 * (10 - angle_rem) + c2 * angle_rem) / 10;
sinma = sinma >> (LV_TRIGO_SHIFT - _LV_TRANSFORM_TRIGO_SHIFT);
cosma = cosma >> (LV_TRIGO_SHIFT - _LV_TRANSFORM_TRIGO_SHIFT);
angle_prev = angle;
}
int32_t x = p->x;
int32_t y = p->y;
if(zoom == 256) {
p->x = ((cosma * x - sinma * y) >> _LV_TRANSFORM_TRIGO_SHIFT) + pivot->x;
p->y = ((sinma * x + cosma * y) >> _LV_TRANSFORM_TRIGO_SHIFT) + pivot->y;
}
else {
p->x = (((cosma * x - sinma * y) * zoom) >> (_LV_TRANSFORM_TRIGO_SHIFT + 8)) + pivot->x;
p->y = (((sinma * x + cosma * y) * zoom) >> (_LV_TRANSFORM_TRIGO_SHIFT + 8)) + pivot->y;
}
}
/**********************
* STATIC FUNCTIONS
**********************/
+11 -1
View File
@@ -177,6 +177,15 @@ void lv_area_move(lv_area_t * area, lv_coord_t x_ofs, lv_coord_t y_ofs);
*/
bool _lv_area_intersect(lv_area_t * res_p, const lv_area_t * a1_p, const lv_area_t * a2_p);
/**
* Get resulting sub areas after removing the common parts of two areas from the first area
* @param res_p pointer to an array of areas with a count of 4, the resulting areas will be stored here
* @param a1_p pointer to the first area
* @param a2_p pointer to the second area
* @return number of results (max 4) or -1 if no intersect
*/
int8_t _lv_area_diff(lv_area_t * res_p, const lv_area_t * a1_p, const lv_area_t * a2_p);
/**
* Join two areas into a third which involves the other two
* @param res_p pointer to an area, the result will be stored here
@@ -211,7 +220,6 @@ bool _lv_area_is_on(const lv_area_t * a1_p, const lv_area_t * a2_p);
*/
bool _lv_area_is_in(const lv_area_t * ain_p, const lv_area_t * aholder_p, lv_coord_t radius);
/**
* Check if an area is fully out of an other
* @param aout_p pointer to an area which could be in 'aholder_p'
@@ -236,6 +244,8 @@ bool _lv_area_is_equal(const lv_area_t * a, const lv_area_t * b);
*/
void lv_area_align(const lv_area_t * base, lv_area_t * to_align, lv_align_t align, lv_coord_t ofs_x, lv_coord_t ofs_y);
void lv_point_transform(lv_point_t * p, int32_t angle, int32_t zoom, const lv_point_t * pivot);
/**********************
* MACROS
**********************/
+27
View File
@@ -65,6 +65,33 @@ lv_res_t lv_async_call(lv_async_cb_t async_xcb, void * user_data)
return LV_RES_OK;
}
lv_res_t lv_async_call_cancel(lv_async_cb_t async_xcb, void * user_data)
{
lv_timer_t * timer = lv_timer_get_next(NULL);
lv_res_t res = LV_RES_INV;
while(timer != NULL) {
/*Find the next timer node*/
lv_timer_t * timer_next = lv_timer_get_next(timer);
/*Find async timer callback*/
if(timer->timer_cb == lv_async_timer_cb) {
lv_async_info_t * info = (lv_async_info_t *)timer->user_data;
/*Match user function callback and user data*/
if(info->cb == async_xcb && info->user_data == user_data) {
lv_timer_del(timer);
lv_mem_free(info);
res = LV_RES_OK;
}
}
timer = timer_next;
}
return res;
}
/**********************
* STATIC FUNCTIONS
**********************/
+7
View File
@@ -43,6 +43,13 @@ typedef void (*lv_async_cb_t)(void *);
*/
lv_res_t lv_async_call(lv_async_cb_t async_xcb, void * user_data);
/**
* Cancel an asynchronous function call
* @param async_xcb a callback which is the task itself.
* @param user_data custom parameter
*/
lv_res_t lv_async_call_cancel(lv_async_cb_t async_xcb, void * user_data);
/**********************
* MACROS
**********************/
+4 -1
View File
@@ -376,7 +376,6 @@ static bool lv_bidi_letter_is_weak(uint32_t letter)
*/
static bool lv_bidi_letter_is_rtl(uint32_t letter)
{
if(letter >= 0x5d0 && letter <= 0x5ea) return true;
if(letter == 0x202E) return true; /*Unicode of LV_BIDI_RLO*/
/*Check for Persian and Arabic characters [https://en.wikipedia.org/wiki/Arabic_script_in_Unicode]*/
@@ -384,6 +383,10 @@ static bool lv_bidi_letter_is_rtl(uint32_t letter)
if(letter >= 0xFB50 && letter <= 0xFDFF) return true;
if(letter >= 0xFE70 && letter <= 0xFEFF) return true;
/*Check for Hebrew characters [https://en.wikipedia.org/wiki/Unicode_and_HTML_for_the_Hebrew_alphabet]*/
if(letter >= 0x590 && letter <= 0x5FF) return true;
if(letter >= 0xFB1D && letter <= 0xFB4F) return true;
return false;
}
-1
View File
@@ -113,7 +113,6 @@ void _lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t le
*/
void lv_bidi_calculate_align(lv_text_align_t * align, lv_base_dir_t * base_dir, const char * txt);
/**********************
* MACROS
**********************/
+1 -1
View File
@@ -33,7 +33,7 @@
* GLOBAL FUNCTIONS
**********************/
LV_ATTRIBUTE_FAST_MEM void lv_color_fill(lv_color_t * buf, lv_color_t color, uint32_t px_num)
void LV_ATTRIBUTE_FAST_MEM lv_color_fill(lv_color_t * buf, lv_color_t color, uint32_t px_num)
{
#if LV_COLOR_DEPTH == 16
uintptr_t buf_int = (uintptr_t)buf;
+14 -12
View File
@@ -23,10 +23,6 @@ extern "C" {
#error "LV_COLOR_DEPTH 24 is deprecated. Use LV_COLOR_DEPTH 32 instead (lv_conf.h)"
#endif
#if LV_COLOR_DEPTH != 32 && LV_COLOR_SCREEN_TRANSP != 0
#error "LV_COLOR_SCREEN_TRANSP requires LV_COLOR_DEPTH == 32. Set it in lv_conf.h"
#endif
#if LV_COLOR_DEPTH != 16 && LV_COLOR_16_SWAP != 0
#error "LV_COLOR_16_SWAP requires LV_COLOR_DEPTH == 16. Set it in lv_conf.h"
#endif
@@ -258,7 +254,6 @@ typedef struct _lv_color_filter_dsc_t {
void * user_data;
} lv_color_filter_dsc_t;
typedef enum {
LV_PALETTE_RED,
LV_PALETTE_PINK,
@@ -440,18 +435,25 @@ static inline uint32_t lv_color_to32(lv_color_t color)
* @param mix The ratio of the colors. 0: full `c2`, 255: full `c1`, 127: half `c1` and half`c2`
* @return the mixed color
*/
LV_ATTRIBUTE_FAST_MEM static inline lv_color_t lv_color_mix(lv_color_t c1, lv_color_t c2, uint8_t mix)
static inline lv_color_t LV_ATTRIBUTE_FAST_MEM lv_color_mix(lv_color_t c1, lv_color_t c2, uint8_t mix)
{
lv_color_t ret;
#if LV_COLOR_DEPTH == 16 && LV_COLOR_16_SWAP == 0
#if LV_COLOR_DEPTH == 16 && LV_COLOR_MIX_ROUND_OFS == 0
#if LV_COLOR_16_SWAP == 1
c1.full = c1.full << 8 | c1.full >> 8;
c2.full = c2.full << 8 | c2.full >> 8;
#endif
/*Source: https://stackoverflow.com/a/50012418/1999969*/
mix = (mix + 4) >> 3;
mix = (uint32_t)((uint32_t)mix + 4) >> 3;
uint32_t bg = (uint32_t)((uint32_t)c2.full | ((uint32_t)c2.full << 16)) &
0x7E0F81F; /*0b00000111111000001111100000011111*/
uint32_t fg = (uint32_t)((uint32_t)c1.full | ((uint32_t)c1.full << 16)) & 0x7E0F81F;
uint32_t result = ((((fg - bg) * mix) >> 5) + bg) & 0x7E0F81F;
ret.full = (uint16_t)((result >> 16) | result);
#if LV_COLOR_16_SWAP == 1
ret.full = ret.full << 8 | ret.full >> 8;
#endif
#elif LV_COLOR_DEPTH != 1
/*LV_COLOR_DEPTH == 8, 16 or 32*/
LV_COLOR_SET_R(ret, LV_UDIV255((uint16_t)LV_COLOR_GET_R(c1) * mix + LV_COLOR_GET_R(c2) *
@@ -469,7 +471,7 @@ LV_ATTRIBUTE_FAST_MEM static inline lv_color_t lv_color_mix(lv_color_t c1, lv_co
return ret;
}
LV_ATTRIBUTE_FAST_MEM static inline void lv_color_premult(lv_color_t c, uint8_t mix, uint16_t * out)
static inline void LV_ATTRIBUTE_FAST_MEM lv_color_premult(lv_color_t c, uint8_t mix, uint16_t * out)
{
#if LV_COLOR_DEPTH != 1
out[0] = (uint16_t)LV_COLOR_GET_R(c) * mix;
@@ -494,7 +496,7 @@ LV_ATTRIBUTE_FAST_MEM static inline void lv_color_premult(lv_color_t c, uint8_t
* @return the mixed color
* @note 255 won't give clearly `c1`.
*/
LV_ATTRIBUTE_FAST_MEM static inline lv_color_t lv_color_mix_premult(uint16_t * premult_c1, lv_color_t c2, uint8_t mix)
static inline lv_color_t LV_ATTRIBUTE_FAST_MEM lv_color_mix_premult(uint16_t * premult_c1, lv_color_t c2, uint8_t mix)
{
lv_color_t ret;
#if LV_COLOR_DEPTH != 1
@@ -525,7 +527,7 @@ LV_ATTRIBUTE_FAST_MEM static inline lv_color_t lv_color_mix_premult(uint16_t * p
* @param res_color the result color
* @param res_opa the result opacity
*/
LV_ATTRIBUTE_FAST_MEM static inline void lv_color_mix_with_alpha(lv_color_t bg_color, lv_opa_t bg_opa,
static inline void LV_ATTRIBUTE_FAST_MEM lv_color_mix_with_alpha(lv_color_t bg_color, lv_opa_t bg_opa,
lv_color_t fg_color, lv_opa_t fg_opa,
lv_color_t * res_color, lv_opa_t * res_opa)
{
@@ -641,7 +643,7 @@ static inline void lv_color_filter_dsc_init(lv_color_filter_dsc_t * dsc, lv_colo
//! @cond Doxygen_Suppress
//!
LV_ATTRIBUTE_FAST_MEM void lv_color_fill(lv_color_t * buf, lv_color_t color, uint32_t px_num);
void /* LV_ATTRIBUTE_FAST_MEM */ lv_color_fill(lv_color_t * buf, lv_color_t color, uint32_t px_num);
//! @endcond
lv_color_t lv_color_lighten(lv_color_t c, lv_opa_t lvl);
-1
View File
@@ -57,7 +57,6 @@ enum {
};
typedef uint8_t lv_fs_mode_t;
/**
* Seek modes.
*/
+42 -47
View File
@@ -48,13 +48,6 @@ static int lv_lru_cmp_keys(lv_lru_item_t * item, const void * key, uint32_t key_
/** remove an item and push it to the free items queue */
static void lv_lru_remove_item(lv_lru_t * cache, lv_lru_item_t * prev, lv_lru_item_t * item, uint32_t hash_index);
/**
* remove the least recently used item
*
* @todo we can optimise this by finding the n lru items, where n = required_space / average_length
*/
static void lv_lru_remove_lru_item(lv_lru_t * cache);
/** pop an existing item off the free queue, or create a new one */
static lv_lru_item_t * lv_lru_pop_or_create_item(lv_lru_t * cache);
@@ -106,13 +99,12 @@ lv_lru_t * lv_lru_create(size_t cache_size, size_t average_length, lv_lru_free_t
return cache;
}
void lv_lru_del(lv_lru_t * cache)
{
LV_ASSERT_NULL(cache);
// free each of the cached items, and the hash table
lv_lru_item_t * item = NULL, *next = NULL;
lv_lru_item_t * item = NULL, * next = NULL;
uint32_t i = 0;
if(cache->items) {
for(; i < cache->hash_table_size; i++) {
@@ -142,7 +134,6 @@ void lv_lru_del(lv_lru_t * cache)
lv_mem_free(cache);
}
lv_lru_res_t lv_lru_set(lv_lru_t * cache, const void * key, size_t key_length, void * value, size_t value_length)
{
test_for_missing_cache();
@@ -152,8 +143,8 @@ lv_lru_res_t lv_lru_set(lv_lru_t * cache, const void * key, size_t key_length, v
// see if the key already exists
uint32_t hash_index = lv_lru_hash(cache, key, key_length);
size_t required = 0;
lv_lru_item_t * item = NULL, *prev = NULL;
int required = 0;
lv_lru_item_t * item = NULL, * prev = NULL;
item = cache->items[hash_index];
while(item && lv_lru_cmp_keys(item, key, key_length)) {
@@ -163,7 +154,7 @@ lv_lru_res_t lv_lru_set(lv_lru_t * cache, const void * key, size_t key_length, v
if(item) {
// update the value and value_lengths
required = (size_t)(value_length - item->value_length);
required = (int)(value_length - item->value_length);
cache->value_free(item->value);
item->value = value;
item->value_length = value_length;
@@ -177,7 +168,7 @@ lv_lru_res_t lv_lru_set(lv_lru_t * cache, const void * key, size_t key_length, v
memcpy(item->key, key, key_length);
item->value_length = value_length;
item->key_length = key_length;
required = (size_t) value_length;
required = (int) value_length;
if(prev)
prev->next = item;
@@ -195,7 +186,6 @@ lv_lru_res_t lv_lru_set(lv_lru_t * cache, const void * key, size_t key_length, v
return LV_LRU_OK;
}
lv_lru_res_t lv_lru_get(lv_lru_t * cache, const void * key, size_t key_size, void ** value)
{
test_for_missing_cache();
@@ -225,7 +215,7 @@ lv_lru_res_t lv_lru_remove(lv_lru_t * cache, const void * key, size_t key_size)
test_for_missing_key();
// loop until we find the item, or hit the end of a chain
lv_lru_item_t * item = NULL, *prev = NULL;
lv_lru_item_t * item = NULL, * prev = NULL;
uint32_t hash_index = lv_lru_hash(cache, key, key_size);
item = cache->items[hash_index];
@@ -241,6 +231,34 @@ lv_lru_res_t lv_lru_remove(lv_lru_t * cache, const void * key, size_t key_size)
return LV_LRU_OK;
}
void lv_lru_remove_lru_item(lv_lru_t * cache)
{
lv_lru_item_t * min_item = NULL, * min_prev = NULL;
lv_lru_item_t * item = NULL, * prev = NULL;
uint32_t i = 0, min_index = -1;
uint64_t min_access_count = -1;
for(; i < cache->hash_table_size; i++) {
item = cache->items[i];
prev = NULL;
while(item) {
if(item->access_count < min_access_count || (int64_t) min_access_count == -1) {
min_access_count = item->access_count;
min_item = item;
min_prev = prev;
min_index = i;
}
prev = item;
item = item->next;
}
}
if(min_item) {
lv_lru_remove_item(cache, min_prev, min_item, min_index);
}
}
/**********************
* STATIC FUNCTIONS
**********************/
@@ -282,18 +300,22 @@ static uint32_t lv_lru_hash(lv_lru_t * cache, const void * key, uint32_t key_len
static int lv_lru_cmp_keys(lv_lru_item_t * item, const void * key, uint32_t key_length)
{
if(key_length != item->key_length)
if(key_length != item->key_length) {
return 1;
else
}
else {
return memcmp(key, item->key, key_length);
}
}
static void lv_lru_remove_item(lv_lru_t * cache, lv_lru_item_t * prev, lv_lru_item_t * item, uint32_t hash_index)
{
if(prev)
if(prev) {
prev->next = item->next;
else
}
else {
cache->items[hash_index] = (lv_lru_item_t *) item->next;
}
// free memory and update the free memory counter
cache->free_memory += item->value_length;
@@ -306,33 +328,6 @@ static void lv_lru_remove_item(lv_lru_t * cache, lv_lru_item_t * prev, lv_lru_it
cache->free_items = item;
}
static void lv_lru_remove_lru_item(lv_lru_t * cache)
{
lv_lru_item_t * min_item = NULL, *min_prev = NULL;
lv_lru_item_t * item = NULL, *prev = NULL;
uint32_t i = 0, min_index = -1;
uint64_t min_access_count = -1;
for(; i < cache->hash_table_size; i++) {
item = cache->items[i];
prev = NULL;
while(item) {
if(item->access_count < min_access_count || (int64_t) min_access_count == -1) {
min_access_count = item->access_count;
min_item = item;
min_prev = prev;
min_index = i;
}
prev = item;
item = item->next;
}
}
if(min_item)
lv_lru_remove_item(cache, min_prev, min_item, min_index);
}
static lv_lru_item_t * lv_lru_pop_or_create_item(lv_lru_t * cache)
{
lv_lru_item_t * item = NULL;
+6 -2
View File
@@ -21,7 +21,6 @@ extern "C" {
#include <stdint.h>
#include <stddef.h>
/*********************
* DEFINES
*********************/
@@ -55,7 +54,6 @@ typedef struct lv_lru_t {
lv_lru_item_t * free_items;
} lv_lru_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
@@ -71,6 +69,12 @@ lv_lru_res_t lv_lru_get(lv_lru_t * cache, const void * key, size_t key_size, voi
lv_lru_res_t lv_lru_remove(lv_lru_t * cache, const void * key, size_t key_size);
/**
* remove the least recently used item
*
* @todo we can optimise this by finding the n lru items, where n = required_space / average_length
*/
void lv_lru_remove_lru_item(lv_lru_t * cache);
/**********************
* MACROS
**********************/
+2 -2
View File
@@ -45,7 +45,7 @@ static const int16_t sin0_90_table[] = {
* @param angle
* @return sinus of 'angle'. sin(-90) = -32767, sin(90) = 32767
*/
LV_ATTRIBUTE_FAST_MEM int16_t lv_trigo_sin(int16_t angle)
int16_t LV_ATTRIBUTE_FAST_MEM lv_trigo_sin(int16_t angle)
{
int16_t ret = 0;
angle = angle % 360;
@@ -106,7 +106,7 @@ uint32_t lv_bezier3(uint32_t t, uint32_t u0, uint32_t u1, uint32_t u2, uint32_t
* If root < 256: mask = 0x800
* Else: mask = 0x8000
*/
LV_ATTRIBUTE_FAST_MEM void lv_sqrt(uint32_t x, lv_sqrt_res_t * q, uint32_t mask)
void LV_ATTRIBUTE_FAST_MEM lv_sqrt(uint32_t x, lv_sqrt_res_t * q, uint32_t mask)
{
x = x << 8; /*To get 4 bit precision. (sqrt(256) = 16 = 4 bit)*/
+3 -3
View File
@@ -44,9 +44,9 @@ typedef struct {
* @param angle
* @return sinus of 'angle'. sin(-90) = -32767, sin(90) = 32767
*/
LV_ATTRIBUTE_FAST_MEM int16_t lv_trigo_sin(int16_t angle);
int16_t /* LV_ATTRIBUTE_FAST_MEM */ lv_trigo_sin(int16_t angle);
static inline LV_ATTRIBUTE_FAST_MEM int16_t lv_trigo_cos(int16_t angle)
static inline int16_t LV_ATTRIBUTE_FAST_MEM lv_trigo_cos(int16_t angle)
{
return lv_trigo_sin(angle + 90);
}
@@ -84,7 +84,7 @@ uint16_t lv_atan2(int x, int y);
* If root < 256: mask = 0x800
* Else: mask = 0x8000
*/
LV_ATTRIBUTE_FAST_MEM void lv_sqrt(uint32_t x, lv_sqrt_res_t * q, uint32_t mask);
void /* LV_ATTRIBUTE_FAST_MEM */ lv_sqrt(uint32_t x, lv_sqrt_res_t * q, uint32_t mask);
//! @endcond
+24 -11
View File
@@ -55,6 +55,8 @@
**********************/
#if LV_MEM_CUSTOM == 0
static lv_tlsf_t tlsf;
static uint32_t cur_used;
static uint32_t max_used;
#endif
static uint32_t zero_mem = ZERO_MEM_SENTINEL; /*Give the address of this variable if 0 byte should be allocated*/
@@ -135,12 +137,14 @@ void * lv_mem_alloc(size_t size)
#endif
if(alloc == NULL) {
LV_LOG_ERROR("couldn't allocate memory (%lu bytes)", (unsigned long)size);
LV_LOG_INFO("couldn't allocate memory (%lu bytes)", (unsigned long)size);
#if LV_LOG_LEVEL <= LV_LOG_LEVEL_INFO
lv_mem_monitor_t mon;
lv_mem_monitor(&mon);
LV_LOG_ERROR("used: %6d (%3d %%), frag: %3d %%, biggest free: %6d",
(int)(mon.total_size - mon.free_size), mon.used_pct, mon.frag_pct,
(int)mon.free_biggest_size);
LV_LOG_INFO("used: %6d (%3d %%), frag: %3d %%, biggest free: %6d",
(int)(mon.total_size - mon.free_size), mon.used_pct, mon.frag_pct,
(int)mon.free_biggest_size);
#endif
}
#if LV_MEM_ADD_JUNK
else {
@@ -148,7 +152,13 @@ void * lv_mem_alloc(size_t size)
}
#endif
MEM_TRACE("allocated at %p", alloc);
if(alloc) {
#if LV_MEM_CUSTOM == 0
cur_used += size;
max_used = LV_MAX(cur_used, max_used);
#endif
MEM_TRACE("allocated at %p", alloc);
}
return alloc;
}
@@ -166,7 +176,9 @@ void lv_mem_free(void * data)
# if LV_MEM_ADD_JUNK
lv_memset(data, 0xbb, lv_tlsf_block_size(data));
# endif
lv_tlsf_free(tlsf, data);
size_t size = lv_tlsf_free(tlsf, data);
if(cur_used > size) cur_used -= size;
else cur_used = 0;
#else
LV_MEM_CUSTOM_FREE(data);
#endif
@@ -250,11 +262,12 @@ void lv_mem_monitor(lv_mem_monitor_t * mon_p)
mon_p->frag_pct = 0; /*no fragmentation if all the RAM is used*/
}
mon_p->max_used = max_used;
MEM_TRACE("finished");
#endif
}
/**
* Get a temporal buffer with the given size.
* @param size the required size
@@ -351,7 +364,7 @@ void lv_mem_buf_free_all(void)
* @param src pointer to the source buffer
* @param len number of byte to copy
*/
LV_ATTRIBUTE_FAST_MEM void * lv_memcpy(void * dst, const void * src, size_t len)
void * LV_ATTRIBUTE_FAST_MEM lv_memcpy(void * dst, const void * src, size_t len)
{
uint8_t * d8 = dst;
const uint8_t * s8 = src;
@@ -413,7 +426,7 @@ LV_ATTRIBUTE_FAST_MEM void * lv_memcpy(void * dst, const void * src, size_t len)
* @param v value to set [0..255]
* @param len number of byte to set
*/
LV_ATTRIBUTE_FAST_MEM void lv_memset(void * dst, uint8_t v, size_t len)
void LV_ATTRIBUTE_FAST_MEM lv_memset(void * dst, uint8_t v, size_t len)
{
uint8_t * d8 = (uint8_t *)dst;
@@ -456,7 +469,7 @@ LV_ATTRIBUTE_FAST_MEM void lv_memset(void * dst, uint8_t v, size_t len)
* @param dst pointer to the destination buffer
* @param len number of byte to set
*/
LV_ATTRIBUTE_FAST_MEM void lv_memset_00(void * dst, size_t len)
void LV_ATTRIBUTE_FAST_MEM lv_memset_00(void * dst, size_t len)
{
uint8_t * d8 = (uint8_t *)dst;
uintptr_t d_align = (lv_uintptr_t) d8 & ALIGN_MASK;
@@ -494,7 +507,7 @@ LV_ATTRIBUTE_FAST_MEM void lv_memset_00(void * dst, size_t len)
* @param dst pointer to the destination buffer
* @param len number of byte to set
*/
LV_ATTRIBUTE_FAST_MEM void lv_memset_ff(void * dst, size_t len)
void LV_ATTRIBUTE_FAST_MEM lv_memset_ff(void * dst, size_t len)
{
uint8_t * d8 = (uint8_t *)dst;
uintptr_t d_align = (lv_uintptr_t) d8 & ALIGN_MASK;
+5 -6
View File
@@ -101,7 +101,6 @@ lv_res_t lv_mem_test(void);
*/
void lv_mem_monitor(lv_mem_monitor_t * mon_p);
/**
* Get a temporal buffer with the given size.
* @param size the required size
@@ -183,7 +182,7 @@ static inline void lv_memset_ff(void * dst, size_t len)
* @param src pointer to the source buffer
* @param len number of byte to copy
*/
LV_ATTRIBUTE_FAST_MEM void * lv_memcpy(void * dst, const void * src, size_t len);
void * /* LV_ATTRIBUTE_FAST_MEM */ lv_memcpy(void * dst, const void * src, size_t len);
/**
* Same as `memcpy` but optimized to copy only a few bytes.
@@ -191,7 +190,7 @@ LV_ATTRIBUTE_FAST_MEM void * lv_memcpy(void * dst, const void * src, size_t len)
* @param src pointer to the source buffer
* @param len number of byte to copy
*/
LV_ATTRIBUTE_FAST_MEM static inline void * lv_memcpy_small(void * dst, const void * src, size_t len)
static inline void * LV_ATTRIBUTE_FAST_MEM lv_memcpy_small(void * dst, const void * src, size_t len)
{
uint8_t * d8 = (uint8_t *)dst;
const uint8_t * s8 = (const uint8_t *)src;
@@ -212,21 +211,21 @@ LV_ATTRIBUTE_FAST_MEM static inline void * lv_memcpy_small(void * dst, const voi
* @param v value to set [0..255]
* @param len number of byte to set
*/
LV_ATTRIBUTE_FAST_MEM void lv_memset(void * dst, uint8_t v, size_t len);
void /* LV_ATTRIBUTE_FAST_MEM */ lv_memset(void * dst, uint8_t v, size_t len);
/**
* Same as `memset(dst, 0x00, len)` but optimized for 4 byte operation.
* @param dst pointer to the destination buffer
* @param len number of byte to set
*/
LV_ATTRIBUTE_FAST_MEM void lv_memset_00(void * dst, size_t len);
void /* LV_ATTRIBUTE_FAST_MEM */ lv_memset_00(void * dst, size_t len);
/**
* Same as `memset(dst, 0xFF, len)` but optimized for 4 byte operation.
* @param dst pointer to the destination buffer
* @param len number of byte to set
*/
LV_ATTRIBUTE_FAST_MEM void lv_memset_ff(void * dst, size_t len);
void /* LV_ATTRIBUTE_FAST_MEM */ lv_memset_ff(void * dst, size_t len);
//! @endcond
+6
View File
@@ -40,14 +40,20 @@
/* platform-specific printf format for int32_t, usually "d" or "ld" */
#define LV_PRId32 PRId32
#define LV_PRIu32 PRIu32
#define LV_PRIx32 PRIx32
#define LV_PRIX32 PRIX32
#else
#define LV_PRId32 "d"
#define LV_PRIu32 "u"
#define LV_PRIx32 "x"
#define LV_PRIX32 "X"
#endif
#else
/* hope this is correct for ports without __has_include or without inttypes.h */
#define LV_PRId32 "d"
#define LV_PRIu32 "u"
#define LV_PRIx32 "x"
#define LV_PRIX32 "X"
#endif
#ifdef __cplusplus
+128 -79
View File
@@ -9,6 +9,8 @@
#include "lv_style.h"
#include "../misc/lv_gc.h"
#include "../misc/lv_mem.h"
#include "lv_assert.h"
#include "lv_types.h"
/*********************
* DEFINES
@@ -22,6 +24,13 @@
* STATIC PROTOTYPES
**********************/
static void lv_style_set_prop_internal(lv_style_t * style, lv_style_prop_t prop_and_meta, lv_style_value_t value,
void (*value_adjustment_helper)(lv_style_prop_t, lv_style_value_t, uint16_t *, lv_style_value_t *));
static void lv_style_set_prop_helper(lv_style_prop_t prop, lv_style_value_t value, uint16_t * prop_storage,
lv_style_value_t * value_storage);
static void lv_style_set_prop_meta_helper(lv_style_prop_t prop, lv_style_value_t value, uint16_t * prop_storage,
lv_style_value_t * value_storage);
/**********************
* GLOBAL VARIABLES
**********************/
@@ -40,8 +49,8 @@ const uint8_t _lv_style_builtin_prop_flag_lookup_table[_LV_STYLE_NUM_BUILT_IN_PR
[LV_STYLE_TRANSFORM_HEIGHT] = LV_STYLE_PROP_EXT_DRAW,
[LV_STYLE_TRANSLATE_X] = LV_STYLE_PROP_LAYOUT_REFR | LV_STYLE_PROP_PARENT_LAYOUT_REFR,
[LV_STYLE_TRANSLATE_Y] = LV_STYLE_PROP_LAYOUT_REFR | LV_STYLE_PROP_PARENT_LAYOUT_REFR,
[LV_STYLE_TRANSFORM_ZOOM] = LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_LAYOUT_REFR | LV_STYLE_PROP_PARENT_LAYOUT_REFR,
[LV_STYLE_TRANSFORM_ANGLE] = LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_LAYOUT_REFR | LV_STYLE_PROP_PARENT_LAYOUT_REFR,
[LV_STYLE_TRANSFORM_ZOOM] = LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_LAYER_REFR,
[LV_STYLE_TRANSFORM_ANGLE] = LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_LAYER_REFR,
[LV_STYLE_PAD_TOP] = LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_LAYOUT_REFR,
[LV_STYLE_PAD_BOTTOM] = LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_LAYOUT_REFR,
@@ -110,13 +119,14 @@ const uint8_t _lv_style_builtin_prop_flag_lookup_table[_LV_STYLE_NUM_BUILT_IN_PR
[LV_STYLE_RADIUS] = 0,
[LV_STYLE_CLIP_CORNER] = 0,
[LV_STYLE_OPA] = LV_STYLE_PROP_INHERIT,
[LV_STYLE_OPA] = 0,
[LV_STYLE_OPA_LAYERED] = LV_STYLE_PROP_LAYER_REFR,
[LV_STYLE_COLOR_FILTER_DSC] = LV_STYLE_PROP_INHERIT,
[LV_STYLE_COLOR_FILTER_OPA] = LV_STYLE_PROP_INHERIT,
[LV_STYLE_ANIM_TIME] = 0,
[LV_STYLE_ANIM_SPEED] = 0,
[LV_STYLE_TRANSITION] = 0,
[LV_STYLE_BLEND_MODE] = 0,
[LV_STYLE_BLEND_MODE] = LV_STYLE_PROP_LAYER_REFR,
[LV_STYLE_LAYOUT] = LV_STYLE_PROP_LAYOUT_REFR,
[LV_STYLE_BASE_DIR] = LV_STYLE_PROP_INHERIT | LV_STYLE_PROP_LAYOUT_REFR,
};
@@ -128,6 +138,7 @@ uint32_t _lv_style_custom_prop_flag_lookup_table_size = 0;
**********************/
static uint16_t last_custom_prop_id = (uint16_t)_LV_STYLE_LAST_BUILT_IN_PROP;
static const lv_style_value_t null_style_value = { .num = 0 };
/**********************
* MACROS
@@ -155,7 +166,7 @@ void lv_style_reset(lv_style_t * style)
{
LV_ASSERT_STYLE(style);
if(style->is_const) {
if(style->prop1 == LV_STYLE_PROP_ANY) {
LV_LOG_ERROR("Cannot reset const style");
return;
}
@@ -169,13 +180,24 @@ void lv_style_reset(lv_style_t * style)
lv_style_prop_t lv_style_register_prop(uint8_t flag)
{
if(LV_GC_ROOT(_lv_style_custom_prop_flag_lookup_table) == NULL) {
_lv_style_custom_prop_flag_lookup_table_size = 0;
last_custom_prop_id = (uint16_t)_LV_STYLE_LAST_BUILT_IN_PROP;
}
if(((last_custom_prop_id + 1) & LV_STYLE_PROP_META_MASK) != 0) {
LV_LOG_ERROR("No more custom property IDs available");
return LV_STYLE_PROP_INV;
}
/*
* Allocate the lookup table if it's not yet available.
*/
uint8_t required_size = (last_custom_prop_id + 1 - _LV_STYLE_LAST_BUILT_IN_PROP);
size_t required_size = (last_custom_prop_id + 1 - _LV_STYLE_LAST_BUILT_IN_PROP);
if(_lv_style_custom_prop_flag_lookup_table_size < required_size) {
/* Round required_size up to the nearest 32-byte value */
required_size = (required_size + 31) & ~31;
LV_ASSERT_MSG(required_size > 0, "required size has become 0?");
uint8_t * old_p = LV_GC_ROOT(_lv_style_custom_prop_flag_lookup_table);
uint8_t * new_p = lv_mem_realloc(old_p, required_size * sizeof(uint8_t));
if(new_p == NULL) {
@@ -201,7 +223,7 @@ bool lv_style_remove_prop(lv_style_t * style, lv_style_prop_t prop)
{
LV_ASSERT_STYLE(style);
if(style->is_const) {
if(style->prop1 == LV_STYLE_PROP_ANY) {
LV_LOG_ERROR("Cannot remove prop from const style");
return false;
}
@@ -209,7 +231,7 @@ bool lv_style_remove_prop(lv_style_t * style, lv_style_prop_t prop)
if(style->prop_cnt == 0) return false;
if(style->prop_cnt == 1) {
if(style->prop1 == prop) {
if(LV_STYLE_PROP_ID_MASK(style->prop1) == prop) {
style->prop1 = LV_STYLE_PROP_INV;
style->prop_cnt = 0;
return true;
@@ -221,7 +243,7 @@ bool lv_style_remove_prop(lv_style_t * style, lv_style_prop_t prop)
uint16_t * old_props = (uint16_t *)tmp;
uint32_t i;
for(i = 0; i < style->prop_cnt; i++) {
if(old_props[i] == prop) {
if(LV_STYLE_PROP_ID_MASK(old_props[i]) == prop) {
lv_style_value_t * old_values = (lv_style_value_t *)style->v_p.values_and_props;
if(style->prop_cnt == 2) {
@@ -260,78 +282,15 @@ bool lv_style_remove_prop(lv_style_t * style, lv_style_prop_t prop)
void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t value)
{
LV_ASSERT_STYLE(style);
if(style->is_const) {
LV_LOG_ERROR("Cannot set property of constant style");
return;
}
if(style->prop_cnt > 1) {
uint8_t * tmp = style->v_p.values_and_props + style->prop_cnt * sizeof(lv_style_value_t);
uint16_t * props = (uint16_t *)tmp;
int32_t i;
for(i = style->prop_cnt - 1; i >= 0; i--) {
if(props[i] == prop) {
lv_style_value_t * values = (lv_style_value_t *)style->v_p.values_and_props;
values[i] = value;
return;
}
}
size_t size = (style->prop_cnt + 1) * (sizeof(lv_style_value_t) + sizeof(uint16_t));
uint8_t * values_and_props = lv_mem_realloc(style->v_p.values_and_props, size);
if(values_and_props == NULL) return;
style->v_p.values_and_props = values_and_props;
tmp = values_and_props + style->prop_cnt * sizeof(lv_style_value_t);
props = (uint16_t *)tmp;
/*Shift all props to make place for the value before them*/
for(i = style->prop_cnt - 1; i >= 0; i--) {
props[i + sizeof(lv_style_value_t) / sizeof(uint16_t)] = props[i];
}
style->prop_cnt++;
/*Go to the new position wit the props*/
tmp = values_and_props + style->prop_cnt * sizeof(lv_style_value_t);
props = (uint16_t *)tmp;
lv_style_value_t * values = (lv_style_value_t *)values_and_props;
/*Set the new property and value*/
props[style->prop_cnt - 1] = prop;
values[style->prop_cnt - 1] = value;
}
else if(style->prop_cnt == 1) {
if(style->prop1 == prop) {
style->v_p.value1 = value;
return;
}
size_t size = (style->prop_cnt + 1) * (sizeof(lv_style_value_t) + sizeof(uint16_t));
uint8_t * values_and_props = lv_mem_alloc(size);
if(values_and_props == NULL) return;
lv_style_value_t value_tmp = style->v_p.value1;
style->v_p.values_and_props = values_and_props;
style->prop_cnt++;
uint8_t * tmp = values_and_props + style->prop_cnt * sizeof(lv_style_value_t);
uint16_t * props = (uint16_t *)tmp;
lv_style_value_t * values = (lv_style_value_t *)values_and_props;
props[0] = style->prop1;
props[1] = prop;
values[0] = value_tmp;
values[1] = value;
}
else {
style->prop_cnt = 1;
style->prop1 = prop;
style->v_p.value1 = value;
}
uint8_t group = _lv_style_get_prop_group(prop);
style->has_group |= 1 << group;
lv_style_set_prop_internal(style, prop, value, lv_style_set_prop_helper);
}
lv_res_t lv_style_get_prop(const lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value)
void lv_style_set_prop_meta(lv_style_t * style, lv_style_prop_t prop, uint16_t meta)
{
lv_style_set_prop_internal(style, prop | meta, null_style_value, lv_style_set_prop_meta_helper);
}
lv_style_res_t lv_style_get_prop(const lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value)
{
return lv_style_get_prop_inlined(style, prop, value);
}
@@ -372,6 +331,7 @@ lv_style_value_t lv_style_prop_get_default(lv_style_prop_t prop)
value.color = lv_color_black();
break;
case LV_STYLE_OPA:
case LV_STYLE_OPA_LAYERED:
case LV_STYLE_BORDER_OPA:
case LV_STYLE_TEXT_OPA:
case LV_STYLE_IMG_OPA:
@@ -436,3 +396,92 @@ uint8_t _lv_style_prop_lookup_flags(lv_style_prop_t prop)
/**********************
* STATIC FUNCTIONS
**********************/
static void lv_style_set_prop_helper(lv_style_prop_t prop, lv_style_value_t value, uint16_t * prop_storage,
lv_style_value_t * value_storage)
{
*prop_storage = prop;
*value_storage = value;
}
static void lv_style_set_prop_meta_helper(lv_style_prop_t prop, lv_style_value_t value, uint16_t * prop_storage,
lv_style_value_t * value_storage)
{
LV_UNUSED(value);
LV_UNUSED(value_storage);
*prop_storage = prop; /* meta is OR-ed into the prop ID already */
}
static void lv_style_set_prop_internal(lv_style_t * style, lv_style_prop_t prop_and_meta, lv_style_value_t value,
void (*value_adjustment_helper)(lv_style_prop_t, lv_style_value_t, uint16_t *, lv_style_value_t *))
{
LV_ASSERT_STYLE(style);
if(style->prop1 == LV_STYLE_PROP_ANY) {
LV_LOG_ERROR("Cannot set property of constant style");
return;
}
lv_style_prop_t prop_id = LV_STYLE_PROP_ID_MASK(prop_and_meta);
if(style->prop_cnt > 1) {
uint8_t * tmp = style->v_p.values_and_props + style->prop_cnt * sizeof(lv_style_value_t);
uint16_t * props = (uint16_t *)tmp;
int32_t i;
for(i = style->prop_cnt - 1; i >= 0; i--) {
if(LV_STYLE_PROP_ID_MASK(props[i]) == prop_id) {
lv_style_value_t * values = (lv_style_value_t *)style->v_p.values_and_props;
value_adjustment_helper(prop_and_meta, value, &props[i], &values[i]);
return;
}
}
size_t size = (style->prop_cnt + 1) * (sizeof(lv_style_value_t) + sizeof(uint16_t));
uint8_t * values_and_props = lv_mem_realloc(style->v_p.values_and_props, size);
if(values_and_props == NULL) return;
style->v_p.values_and_props = values_and_props;
tmp = values_and_props + style->prop_cnt * sizeof(lv_style_value_t);
props = (uint16_t *)tmp;
/*Shift all props to make place for the value before them*/
for(i = style->prop_cnt - 1; i >= 0; i--) {
props[i + sizeof(lv_style_value_t) / sizeof(uint16_t)] = props[i];
}
style->prop_cnt++;
/*Go to the new position wit the props*/
tmp = values_and_props + style->prop_cnt * sizeof(lv_style_value_t);
props = (uint16_t *)tmp;
lv_style_value_t * values = (lv_style_value_t *)values_and_props;
/*Set the new property and value*/
value_adjustment_helper(prop_and_meta, value, &props[style->prop_cnt - 1], &values[style->prop_cnt - 1]);
}
else if(style->prop_cnt == 1) {
if(LV_STYLE_PROP_ID_MASK(style->prop1) == prop_id) {
value_adjustment_helper(prop_and_meta, value, &style->prop1, &style->v_p.value1);
return;
}
size_t size = (style->prop_cnt + 1) * (sizeof(lv_style_value_t) + sizeof(uint16_t));
uint8_t * values_and_props = lv_mem_alloc(size);
if(values_and_props == NULL) return;
lv_style_value_t value_tmp = style->v_p.value1;
style->v_p.values_and_props = values_and_props;
style->prop_cnt++;
uint8_t * tmp = values_and_props + style->prop_cnt * sizeof(lv_style_value_t);
uint16_t * props = (uint16_t *)tmp;
lv_style_value_t * values = (lv_style_value_t *)values_and_props;
props[0] = style->prop1;
values[0] = value_tmp;
value_adjustment_helper(prop_and_meta, value, &props[1], &values[1]);
}
else {
style->prop_cnt = 1;
value_adjustment_helper(prop_and_meta, value, &style->prop1, &style->v_p.value1);
}
uint8_t group = _lv_style_get_prop_group(prop_id);
style->has_group |= 1 << group;
}
+124 -75
View File
@@ -40,7 +40,8 @@ extern "C" {
#define LV_STYLE_PROP_EXT_DRAW (1 << 1) /*Requires ext. draw size update when changed*/
#define LV_STYLE_PROP_LAYOUT_REFR (1 << 2) /*Requires layout update when changed*/
#define LV_STYLE_PROP_PARENT_LAYOUT_REFR (1 << 3) /*Requires layout update on parent when changed*/
#define LV_STYLE_PROP_ALL (0xf) /*Indicating all flags*/
#define LV_STYLE_PROP_LAYER_REFR (1 << 4) /*Affects layer handling*/
#define LV_STYLE_PROP_ALL (0x1F) /*Indicating all flags*/
/**
* Other constants
@@ -48,17 +49,32 @@ extern "C" {
#define LV_IMG_ZOOM_NONE 256 /*Value for not zooming the image*/
LV_EXPORT_CONST_INT(LV_IMG_ZOOM_NONE);
// *INDENT-OFF*
#if LV_USE_ASSERT_STYLE
#define LV_STYLE_CONST_INIT(var_name, prop_array) const lv_style_t var_name = { .sentinel = LV_STYLE_SENTINEL_VALUE, .v_p = { .const_props = prop_array }, .has_group = 0xFF, .is_const = 1 }
#define LV_STYLE_CONST_INIT(var_name, prop_array) \
const lv_style_t var_name = { \
.sentinel = LV_STYLE_SENTINEL_VALUE, \
.v_p = { .const_props = prop_array }, \
.has_group = 0xFF, \
.prop1 = LV_STYLE_PROP_ANY, \
.prop_cnt = (sizeof(prop_array) / sizeof((prop_array)[0])), \
}
#else
#define LV_STYLE_CONST_INIT(var_name, prop_array) const lv_style_t var_name = { .v_p = { .const_props = prop_array }, .has_group = 0xFF, .is_const = 1 }
#define LV_STYLE_CONST_INIT(var_name, prop_array) \
const lv_style_t var_name = { \
.v_p = { .const_props = prop_array }, \
.has_group = 0xFF, \
.prop1 = LV_STYLE_PROP_ANY, \
.prop_cnt = (sizeof(prop_array) / sizeof((prop_array)[0])), \
}
#endif
// *INDENT-ON*
/** On simple system, don't waste resources on gradients */
#if !defined(LV_DRAW_COMPLEX) || !defined(LV_GRADIENT_MAX_STOPS)
#define LV_GRADIENT_MAX_STOPS 2
#endif
#define LV_STYLE_PROP_META_INHERIT 0x8000
#define LV_STYLE_PROP_META_INITIAL 0x4000
#define LV_STYLE_PROP_META_MASK (LV_STYLE_PROP_META_INHERIT | LV_STYLE_PROP_META_INITIAL)
#define LV_STYLE_PROP_ID_MASK(prop) ((lv_style_prop_t)((prop) & ~LV_STYLE_PROP_META_MASK))
/**********************
* TYPEDEFS
@@ -160,7 +176,7 @@ typedef union {
* Props are split into groups of 16. When adding a new prop to a group, ensure it does not overflow into the next one.
*/
typedef enum {
LV_STYLE_PROP_INV,
LV_STYLE_PROP_INV = 0,
/*Group 0*/
LV_STYLE_WIDTH = 1,
@@ -172,12 +188,8 @@ typedef enum {
LV_STYLE_X = 7,
LV_STYLE_Y = 8,
LV_STYLE_ALIGN = 9,
LV_STYLE_TRANSFORM_WIDTH = 10,
LV_STYLE_TRANSFORM_HEIGHT = 11,
LV_STYLE_TRANSLATE_X = 12,
LV_STYLE_TRANSLATE_Y = 13,
LV_STYLE_TRANSFORM_ZOOM = 14,
LV_STYLE_TRANSFORM_ANGLE = 15,
LV_STYLE_LAYOUT = 10,
LV_STYLE_RADIUS = 11,
/*Group 1*/
LV_STYLE_PAD_TOP = 16,
@@ -186,6 +198,8 @@ typedef enum {
LV_STYLE_PAD_RIGHT = 19,
LV_STYLE_PAD_ROW = 20,
LV_STYLE_PAD_COLUMN = 21,
LV_STYLE_BASE_DIR = 22,
LV_STYLE_CLIP_CORNER = 23,
/*Group 2*/
LV_STYLE_BG_COLOR = 32,
@@ -245,25 +259,39 @@ typedef enum {
LV_STYLE_TEXT_ALIGN = 91,
/*Group 6*/
LV_STYLE_RADIUS = 96,
LV_STYLE_CLIP_CORNER = 97,
LV_STYLE_OPA = 98,
LV_STYLE_COLOR_FILTER_DSC = 99,
LV_STYLE_COLOR_FILTER_OPA = 100,
LV_STYLE_ANIM = 101,
LV_STYLE_ANIM_TIME = 102,
LV_STYLE_ANIM_SPEED = 103,
LV_STYLE_TRANSITION = 104,
LV_STYLE_BLEND_MODE = 105,
LV_STYLE_LAYOUT = 106,
LV_STYLE_BASE_DIR = 107,
LV_STYLE_OPA = 96,
LV_STYLE_OPA_LAYERED = 97,
LV_STYLE_COLOR_FILTER_DSC = 98,
LV_STYLE_COLOR_FILTER_OPA = 99,
LV_STYLE_ANIM = 100,
LV_STYLE_ANIM_TIME = 101,
LV_STYLE_ANIM_SPEED = 102,
LV_STYLE_TRANSITION = 103,
LV_STYLE_BLEND_MODE = 104,
LV_STYLE_TRANSFORM_WIDTH = 105,
LV_STYLE_TRANSFORM_HEIGHT = 106,
LV_STYLE_TRANSLATE_X = 107,
LV_STYLE_TRANSLATE_Y = 108,
LV_STYLE_TRANSFORM_ZOOM = 109,
LV_STYLE_TRANSFORM_ANGLE = 110,
LV_STYLE_TRANSFORM_PIVOT_X = 111,
LV_STYLE_TRANSFORM_PIVOT_Y = 112,
_LV_STYLE_LAST_BUILT_IN_PROP = 111,
_LV_STYLE_LAST_BUILT_IN_PROP = 112,
_LV_STYLE_NUM_BUILT_IN_PROPS = _LV_STYLE_LAST_BUILT_IN_PROP + 1,
LV_STYLE_PROP_ANY = 0xFFFF
LV_STYLE_PROP_ANY = 0xFFFF,
_LV_STYLE_PROP_CONST = 0xFFFF /* magic value for const styles */
} lv_style_prop_t;
enum {
LV_STYLE_RES_NOT_FOUND,
LV_STYLE_RES_FOUND,
LV_STYLE_RES_INHERIT
};
typedef uint8_t lv_style_res_t;
/**
* Descriptor for style transitions
*/
@@ -302,8 +330,7 @@ typedef struct {
const lv_style_const_prop_t * const_props;
} v_p;
uint16_t prop1 : 15;
uint16_t is_const : 1;
uint16_t prop1;
uint8_t has_group;
uint8_t prop_cnt;
} lv_style_t;
@@ -312,7 +339,6 @@ typedef struct {
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize a style
* @param style pointer to a style to initialize
@@ -367,16 +393,13 @@ bool lv_style_remove_prop(lv_style_t * style, lv_style_prop_t prop);
void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t value);
/**
* Get the value of a property
* @param style pointer to a style
* @param prop the ID of a property
* @param value pointer to a `lv_style_value_t` variable to store the value
* @return LV_RES_INV: the property wasn't found in the style (`value` is unchanged)
* LV_RES_OK: the property was fond, and `value` is set accordingly
* @note For performance reasons there are no sanity check on `style`
* Set a special meta state for a property in a style.
* This function shouldn't be used directly by the user.
* @param style pointer to style
* @param prop the ID of a property (e.g. `LV_STYLE_BG_COLOR`)
* @param meta the meta value to attach to the property in the style
*/
lv_res_t lv_style_get_prop(const lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value);
void lv_style_set_prop_meta(lv_style_t * style, lv_style_prop_t prop, uint16_t meta);
/**
* Get the value of a property
@@ -386,42 +409,8 @@ lv_res_t lv_style_get_prop(const lv_style_t * style, lv_style_prop_t prop, lv_st
* @return LV_RES_INV: the property wasn't found in the style (`value` is unchanged)
* LV_RES_OK: the property was fond, and `value` is set accordingly
* @note For performance reasons there are no sanity check on `style`
* @note This function is the same as ::lv_style_get_prop but inlined. Use it only on performance critical places
*/
static inline lv_res_t lv_style_get_prop_inlined(const lv_style_t * style, lv_style_prop_t prop,
lv_style_value_t * value)
{
if(style->is_const) {
const lv_style_const_prop_t * const_prop;
for(const_prop = style->v_p.const_props; const_prop->prop != LV_STYLE_PROP_INV; const_prop++) {
if(const_prop->prop == prop) {
*value = const_prop->value;
return LV_RES_OK;
}
}
return LV_RES_INV;
}
if(style->prop_cnt == 0) return LV_RES_INV;
if(style->prop_cnt > 1) {
uint8_t * tmp = style->v_p.values_and_props + style->prop_cnt * sizeof(lv_style_value_t);
uint16_t * props = (uint16_t *)tmp;
uint32_t i;
for(i = 0; i < style->prop_cnt; i++) {
if(props[i] == prop) {
lv_style_value_t * values = (lv_style_value_t *)style->v_p.values_and_props;
*value = values[i];
return LV_RES_OK;
}
}
}
else if(style->prop1 == prop) {
*value = style->v_p.value1;
return LV_RES_OK;
}
return LV_RES_INV;
}
lv_style_res_t lv_style_get_prop(const lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value);
/**
* Initialize a transition descriptor.
@@ -446,6 +435,66 @@ void lv_style_transition_dsc_init(lv_style_transition_dsc_t * tr, const lv_style
*/
lv_style_value_t lv_style_prop_get_default(lv_style_prop_t prop);
/**
* Get the value of a property
* @param style pointer to a style
* @param prop the ID of a property
* @param value pointer to a `lv_style_value_t` variable to store the value
* @return LV_RES_INV: the property wasn't found in the style (`value` is unchanged)
* LV_RES_OK: the property was fond, and `value` is set accordingly
* @note For performance reasons there are no sanity check on `style`
* @note This function is the same as ::lv_style_get_prop but inlined. Use it only on performance critical places
*/
static inline lv_style_res_t lv_style_get_prop_inlined(const lv_style_t * style, lv_style_prop_t prop,
lv_style_value_t * value)
{
if(style->prop1 == LV_STYLE_PROP_ANY) {
const lv_style_const_prop_t * const_prop;
uint32_t i;
for(i = 0; i < style->prop_cnt; i++) {
const_prop = style->v_p.const_props + i;
lv_style_prop_t prop_id = LV_STYLE_PROP_ID_MASK(const_prop->prop);
if(prop_id == prop) {
if(const_prop->prop & LV_STYLE_PROP_META_INHERIT)
return LV_STYLE_RES_INHERIT;
*value = (const_prop->prop & LV_STYLE_PROP_META_INITIAL) ? lv_style_prop_get_default(prop_id) : const_prop->value;
return LV_STYLE_RES_FOUND;
}
}
return LV_STYLE_RES_NOT_FOUND;
}
if(style->prop_cnt == 0) return LV_STYLE_RES_NOT_FOUND;
if(style->prop_cnt > 1) {
uint8_t * tmp = style->v_p.values_and_props + style->prop_cnt * sizeof(lv_style_value_t);
uint16_t * props = (uint16_t *)tmp;
uint32_t i;
for(i = 0; i < style->prop_cnt; i++) {
lv_style_prop_t prop_id = LV_STYLE_PROP_ID_MASK(props[i]);
if(prop_id == prop) {
if(props[i] & LV_STYLE_PROP_META_INHERIT)
return LV_STYLE_RES_INHERIT;
if(props[i] & LV_STYLE_PROP_META_INITIAL)
*value = lv_style_prop_get_default(prop_id);
else {
lv_style_value_t * values = (lv_style_value_t *)style->v_p.values_and_props;
*value = values[i];
}
return LV_STYLE_RES_FOUND;
}
}
}
else if(LV_STYLE_PROP_ID_MASK(style->prop1) == prop) {
if(style->prop1 & LV_STYLE_PROP_META_INHERIT)
return LV_STYLE_RES_INHERIT;
*value = (style->prop1 & LV_STYLE_PROP_META_INITIAL) ? lv_style_prop_get_default(LV_STYLE_PROP_ID_MASK(
style->prop1)) : style->v_p.value1;
return LV_STYLE_RES_FOUND;
}
return LV_STYLE_RES_NOT_FOUND;
}
/**
* Checks if a style is empty (has no properties)
* @param style pointer to a style
+24
View File
@@ -120,6 +120,22 @@ void lv_style_set_transform_angle(lv_style_t * style, lv_coord_t value)
lv_style_set_prop(style, LV_STYLE_TRANSFORM_ANGLE, v);
}
void lv_style_set_transform_pivot_x(lv_style_t * style, lv_coord_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_TRANSFORM_PIVOT_X, v);
}
void lv_style_set_transform_pivot_y(lv_style_t * style, lv_coord_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_TRANSFORM_PIVOT_Y, v);
}
void lv_style_set_pad_top(lv_style_t * style, lv_coord_t value)
{
lv_style_value_t v = {
@@ -584,6 +600,14 @@ void lv_style_set_opa(lv_style_t * style, lv_opa_t value)
lv_style_set_prop(style, LV_STYLE_OPA, v);
}
void lv_style_set_opa_layered(lv_style_t * style, lv_opa_t value)
{
lv_style_value_t v = {
.num = (int32_t)value
};
lv_style_set_prop(style, LV_STYLE_OPA_LAYERED, v);
}
void lv_style_set_color_filter_dsc(lv_style_t * style, const lv_color_filter_dsc_t * value)
{
lv_style_value_t v = {
+18
View File
@@ -13,6 +13,8 @@ void lv_style_set_translate_x(lv_style_t * style, lv_coord_t value);
void lv_style_set_translate_y(lv_style_t * style, lv_coord_t value);
void lv_style_set_transform_zoom(lv_style_t * style, lv_coord_t value);
void lv_style_set_transform_angle(lv_style_t * style, lv_coord_t value);
void lv_style_set_transform_pivot_x(lv_style_t * style, lv_coord_t value);
void lv_style_set_transform_pivot_y(lv_style_t * style, lv_coord_t value);
void lv_style_set_pad_top(lv_style_t * style, lv_coord_t value);
void lv_style_set_pad_bottom(lv_style_t * style, lv_coord_t value);
void lv_style_set_pad_left(lv_style_t * style, lv_coord_t value);
@@ -71,6 +73,7 @@ void lv_style_set_text_align(lv_style_t * style, lv_text_align_t value);
void lv_style_set_radius(lv_style_t * style, lv_coord_t value);
void lv_style_set_clip_corner(lv_style_t * style, bool value);
void lv_style_set_opa(lv_style_t * style, lv_opa_t value);
void lv_style_set_opa_layered(lv_style_t * style, lv_opa_t value);
void lv_style_set_color_filter_dsc(lv_style_t * style, const lv_color_filter_dsc_t * value);
void lv_style_set_color_filter_opa(lv_style_t * style, lv_opa_t value);
void lv_style_set_anim(lv_style_t * style, const lv_anim_t * value);
@@ -156,6 +159,16 @@ void lv_style_set_base_dir(lv_style_t * style, lv_base_dir_t value);
.prop = LV_STYLE_TRANSFORM_ANGLE, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TRANSFORM_PIVOT_X(val) \
{ \
.prop = LV_STYLE_TRANSFORM_PIVOT_X, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_TRANSFORM_PIVOT_Y(val) \
{ \
.prop = LV_STYLE_TRANSFORM_PIVOT_Y, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_PAD_TOP(val) \
{ \
.prop = LV_STYLE_PAD_TOP, .value = { .num = (int32_t)val } \
@@ -446,6 +459,11 @@ void lv_style_set_base_dir(lv_style_t * style, lv_base_dir_t value);
.prop = LV_STYLE_OPA, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_OPA_LAYERED(val) \
{ \
.prop = LV_STYLE_OPA_LAYERED, .value = { .num = (int32_t)val } \
}
#define LV_STYLE_CONST_COLOR_FILTER_DSC(val) \
{ \
.prop = LV_STYLE_COLOR_FILTER_DSC, .value = { .ptr = val } \
+1 -1
View File
@@ -64,7 +64,7 @@ void _lv_timer_core_init(void)
* Call it periodically to handle lv_timers.
* @return the time after which it must be called again
*/
LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler(void)
uint32_t LV_ATTRIBUTE_TIMER_HANDLER lv_timer_handler(void)
{
TIMER_TRACE("begin");
+2 -2
View File
@@ -65,7 +65,7 @@ void _lv_timer_core_init(void);
* Call it periodically to handle lv_timers.
* @return time till it needs to be run next (in ms)
*/
LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler(void);
uint32_t /* LV_ATTRIBUTE_TIMER_HANDLER */ lv_timer_handler(void);
//! @endcond
@@ -75,7 +75,7 @@ LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler(void);
* This function is used to simplify the porting.
* @param __ms the period for running lv_timer_handler()
*/
static inline LV_ATTRIBUTE_TIMER_HANDLER uint32_t lv_timer_handler_run_in_period(uint32_t ms)
static inline uint32_t LV_ATTRIBUTE_TIMER_HANDLER lv_timer_handler_run_in_period(uint32_t ms)
{
static uint32_t last_tick = 0;
uint32_t curr_tick = lv_tick_get();
+9 -2
View File
@@ -358,7 +358,6 @@ static const size_t block_size_min =
sizeof(block_header_t) - sizeof(block_header_t *);
static const size_t block_size_max = tlsf_cast(size_t, 1) << FL_INDEX_MAX;
/* The TLSF control structure. */
typedef struct control_t {
/* Empty lists point at this block to indicate they are free. */
@@ -1157,18 +1156,22 @@ void * lv_tlsf_memalign(lv_tlsf_t tlsf, size_t align, size_t size)
return block_prepare_used(control, block, adjust);
}
void lv_tlsf_free(lv_tlsf_t tlsf, const void * ptr)
size_t lv_tlsf_free(lv_tlsf_t tlsf, const void * ptr)
{
size_t size = 0;
/* Don't attempt to free a NULL pointer. */
if(ptr) {
control_t * control = tlsf_cast(control_t *, tlsf);
block_header_t * block = block_from_ptr(ptr);
tlsf_assert(!block_is_free(block) && "block already marked as free");
size = block->size;
block_mark_as_free(block);
block = block_merge_prev(control, block);
block = block_merge_next(control, block);
block_insert(control, block);
}
return size;
}
/*
@@ -1204,6 +1207,10 @@ void * lv_tlsf_realloc(lv_tlsf_t tlsf, void * ptr, size_t size)
const size_t cursize = block_size(block);
const size_t combined = cursize + block_size(next) + block_header_overhead;
const size_t adjust = adjust_request_size(size, ALIGN_SIZE);
if(size > cursize && adjust == 0) {
/* The request is probably too large, fail */
return NULL;
}
tlsf_assert(!block_is_free(block) && "block already marked as free");
+1 -1
View File
@@ -66,7 +66,7 @@ void lv_tlsf_remove_pool(lv_tlsf_t tlsf, lv_pool_t pool);
void * lv_tlsf_malloc(lv_tlsf_t tlsf, size_t bytes);
void * lv_tlsf_memalign(lv_tlsf_t tlsf, size_t align, size_t bytes);
void * lv_tlsf_realloc(lv_tlsf_t tlsf, void * ptr, size_t size);
void lv_tlsf_free(lv_tlsf_t tlsf, const void * ptr);
size_t lv_tlsf_free(lv_tlsf_t tlsf, const void * ptr);
/* Returns internal block size, not original request size */
size_t lv_tlsf_block_size(void * ptr);
+1 -1
View File
@@ -798,7 +798,7 @@ static uint32_t lv_txt_iso8859_1_conv_wc(uint32_t c)
*/
static uint32_t lv_txt_iso8859_1_next(const char * txt, uint32_t * i)
{
if(i == NULL) return txt[1]; /*Get the next char*/
if(i == NULL) return txt[0]; /*Get the next char*/
uint8_t letter = txt[*i];
(*i)++;