From b58f9c602179877222130221646ff7d3f40f445f Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Tue, 4 Aug 2020 09:19:25 +0200 Subject: [PATCH] Add LV_USE_OUTLINE/PATTERN/VALUE_STR and LV_MEMCPY_MEMSET_STD --- CHANGELOG.md | 3 +- lv_conf_template.h | 15 ++++++++- src/lv_conf_internal.h | 28 ++++++++++++++-- src/lv_core/lv_obj.c | 8 ++++- src/lv_draw/lv_draw_rect.c | 33 ++++++++++++++++--- src/lv_misc/lv_mem.c | 5 ++- src/lv_misc/lv_mem.h | 66 ++++++++++++++++++++++++++++++++++++-- 7 files changed, 143 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4afdd3327..7960f5497 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,8 @@ - Add `lv_event_send_refresh`, `lv_event_send_refresh_recursive` to easily send `LV_EVENT_REFRESH` to object - Add `lv_tabview_set_tab_name()` function - used to change a tab's name - Add `LV_THEME_MATERIAL_FLAG_NO_TRANSITION` and `LV_THEME_MATERIAL_FLAG_NO_FOCUS` flags -- Reduce code size by adding: `LV_USE_FONT_COMPRESSED` and `LV_FONT_USE_SUBPX` and applying some optimization +- Reduce code size by adding: `LV_USE_FONT_COMPRESSED`, `LV_FONT_USE_SUBPX`, `LV_USE_OUTLINE`, `LV_USE_PATTERN`, `LV_USE_VALUE_STR` and applying some optimization +- Add `LV_MEMCPY_MEMSET_STD` to use standard `memcpy` and `memset` ### Bugfixes diff --git a/lv_conf_template.h b/lv_conf_template.h index aab9f497f..d8b5f8870 100644 --- a/lv_conf_template.h +++ b/lv_conf_template.h @@ -97,6 +97,10 @@ typedef int16_t lv_coord_t; # define LV_MEM_CUSTOM_FREE free /*Wrapper to free*/ #endif /*LV_MEM_CUSTOM*/ +/* Use the standard memcpy and memset instead of LVGL's own functions. + * The standard functions might or might not be faster depending on their implementation. */ +#define LV_MEMCPY_MEMSET_STD 0 + /* Garbage Collector settings * Used if lvgl is binded to higher level language and the memory is managed by that language */ #define LV_ENABLE_GC 0 @@ -150,7 +154,7 @@ typedef void * lv_anim_user_data_t; #endif -/* 1: Enable shadow drawing*/ +/* 1: Enable shadow drawing on rectangles*/ #define LV_USE_SHADOW 1 #if LV_USE_SHADOW /* Allow buffering some shadow calculation @@ -160,6 +164,15 @@ typedef void * lv_anim_user_data_t; #define LV_SHADOW_CACHE_SIZE 0 #endif +/*1: enable outline drawing on rectangles*/ +#define LV_USE_OUTLINE 1 + +/*1: enable pattern drawing on rectangles*/ +#define LV_USE_PATTERN 1 + +/*1: enable value string drawing on rectangles*/ +#define LV_USE_VALUE_STR 1 + /* 1: Use other blend modes than normal (`LV_BLEND_MODE_...`)*/ #define LV_USE_BLEND_MODES 1 diff --git a/src/lv_conf_internal.h b/src/lv_conf_internal.h index 7f86b0eae..d43134241 100644 --- a/src/lv_conf_internal.h +++ b/src/lv_conf_internal.h @@ -147,6 +147,12 @@ #endif #endif /*LV_MEM_CUSTOM*/ +/* Use the standard memcpy and memset instead of LVGL's own functions. + * The standard functions might or might not be faster depending on their implementation. */ +#ifndef LV_MEMCPY_MEMSET_STD +#define LV_MEMCPY_MEMSET_STD 0 +#endif + /* Garbage Collector settings * Used if lvgl is binded to higher level language and the memory is managed by that language */ #ifndef LV_ENABLE_GC @@ -223,7 +229,7 @@ #endif -/* 1: Enable shadow drawing*/ +/* 1: Enable shadow drawing on rectangles*/ #ifndef LV_USE_SHADOW #define LV_USE_SHADOW 1 #endif @@ -237,6 +243,21 @@ #endif #endif +/*1: enable outline drawing on rectangles*/ +#ifndef LV_USE_OUTLINE +#define LV_USE_OUTLINE 1 +#endif + +/*1: enable pattern drawing on rectangles*/ +#ifndef LV_USE_PATTERN +#define LV_USE_PATTERN 1 +#endif + +/*1: enable value string drawing on rectangles*/ +#ifndef LV_USE_VALUE_STR +#define LV_USE_VALUE_STR 1 +#endif + /* 1: Use other blend modes than normal (`LV_BLEND_MODE_...`)*/ #ifndef LV_USE_BLEND_MODES #define LV_USE_BLEND_MODES 1 @@ -633,7 +654,10 @@ e.g. "stm32f769xx.h" or "stm32f429xx.h" */ /* A fast and impressive theme. * Flags: * LV_THEME_MATERIAL_FLAG_LIGHT: light theme - * LV_THEME_MATERIAL_FLAG_DARK: dark theme*/ + * LV_THEME_MATERIAL_FLAG_DARK: dark theme + * LV_THEME_MATERIAL_FLAG_NO_TRANSITION: disable transitions (state change animations) + * LV_THEME_MATERIAL_FLAG_NO_FOCUS: disable indication of focused state) + * */ #ifndef LV_USE_THEME_MATERIAL #define LV_USE_THEME_MATERIAL 1 #endif diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index 8eedc3da0..3a5d05e46 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -3157,7 +3157,7 @@ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t part, lv_draw_rect_dsc_t } } - +#if LV_USE_OUTLINE if(draw_dsc->outline_opa != LV_OPA_TRANSP) { draw_dsc->outline_width = lv_obj_get_style_outline_width(obj, part); if(draw_dsc->outline_width) { @@ -3171,7 +3171,9 @@ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t part, lv_draw_rect_dsc_t #endif } } +#endif +#if LV_USE_PATTERN if(draw_dsc->pattern_opa != LV_OPA_TRANSP) { draw_dsc->pattern_image = lv_obj_get_style_pattern_image(obj, part); if(draw_dsc->pattern_image) { @@ -3192,6 +3194,8 @@ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t part, lv_draw_rect_dsc_t } } } +#endif + #if LV_USE_SHADOW if(draw_dsc->shadow_opa > LV_OPA_MIN) { draw_dsc->shadow_width = lv_obj_get_style_shadow_width(obj, part); @@ -3210,6 +3214,7 @@ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t part, lv_draw_rect_dsc_t } #endif +#if LV_USE_VALUE_STR if(draw_dsc->value_opa > LV_OPA_MIN) { draw_dsc->value_str = lv_obj_get_style_value_str(obj, part); if(draw_dsc->value_str) { @@ -3228,6 +3233,7 @@ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t part, lv_draw_rect_dsc_t } } } +#endif #if LV_USE_OPA_SCALE if(opa_scale < LV_OPA_MAX) { diff --git a/src/lv_draw/lv_draw_rect.c b/src/lv_draw/lv_draw_rect.c index f624d99e8..b83963966 100644 --- a/src/lv_draw/lv_draw_rect.c +++ b/src/lv_draw/lv_draw_rect.c @@ -30,8 +30,10 @@ LV_ATTRIBUTE_FAST_MEM static void draw_bg(const lv_area_t * coords, const lv_area_t * clip, lv_draw_rect_dsc_t * dsc); LV_ATTRIBUTE_FAST_MEM static void draw_border(const lv_area_t * coords, const lv_area_t * clip, lv_draw_rect_dsc_t * dsc); + +#if LV_USE_OUTLINE static void draw_outline(const lv_area_t * coords, const lv_area_t * clip, lv_draw_rect_dsc_t * dsc); -LV_ATTRIBUTE_FAST_MEM static inline lv_color_t grad_get(lv_draw_rect_dsc_t * dsc, lv_coord_t s, lv_coord_t i); +#endif #if LV_USE_SHADOW LV_ATTRIBUTE_FAST_MEM static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip, lv_draw_rect_dsc_t * dsc); @@ -39,9 +41,16 @@ LV_ATTRIBUTE_FAST_MEM static void shadow_draw_corner_buf(const lv_area_t * coord lv_coord_t r); LV_ATTRIBUTE_FAST_MEM static void shadow_blur_corner(lv_coord_t size, lv_coord_t sw, uint16_t * sh_ups_buf); #endif + +#if LV_USE_PATTERN static void draw_pattern(const lv_area_t * coords, const lv_area_t * clip, lv_draw_rect_dsc_t * dsc); -static void draw_value(const lv_area_t * coords, const lv_area_t * clip, lv_draw_rect_dsc_t * dsc); +#endif + +#if LV_USE_VALUE_STR +static void draw_value_str(const lv_area_t * coords, const lv_area_t * clip, lv_draw_rect_dsc_t * dsc); +#endif static void draw_full_border(const lv_area_t * area_inner, const lv_area_t * area_outer, const lv_area_t * clip, lv_coord_t radius, lv_color_t color, lv_opa_t opa, lv_blend_mode_t blend_mode); +LV_ATTRIBUTE_FAST_MEM static inline lv_color_t grad_get(lv_draw_rect_dsc_t * dsc, lv_coord_t s, lv_coord_t i); /********************** * STATIC VARIABLES @@ -96,10 +105,19 @@ void lv_draw_rect(const lv_area_t * coords, const lv_area_t * clip, lv_draw_rect #endif draw_bg(coords, clip, dsc); + +#if LV_USE_PATTERN draw_pattern(coords, clip, dsc); +#endif draw_border(coords, clip, dsc); - draw_value(coords, clip, dsc); + +#if LV_USE_VALUE_STR + draw_value_str(coords, clip, dsc); +#endif + +#if LV_USE_OUTLINE draw_outline(coords, clip, dsc); +#endif LV_ASSERT_MEM_INTEGRITY(); } @@ -1128,6 +1146,7 @@ LV_ATTRIBUTE_FAST_MEM static void shadow_blur_corner(lv_coord_t size, lv_coord_t #endif +#if LV_USE_OUTLINE static void draw_outline(const lv_area_t * coords, const lv_area_t * clip, lv_draw_rect_dsc_t * dsc) { if(dsc->outline_opa <= LV_OPA_MIN) return; @@ -1155,7 +1174,10 @@ static void draw_outline(const lv_area_t * coords, const lv_area_t * clip, lv_dr draw_full_border(&area_inner, &area_outer, clip, dsc->radius, dsc->outline_color, dsc->outline_opa, dsc->outline_blend_mode); } +#endif + +#if LV_USE_PATTERN static void draw_pattern(const lv_area_t * coords, const lv_area_t * clip, lv_draw_rect_dsc_t * dsc) { if(dsc->pattern_image == NULL) return; @@ -1256,9 +1278,11 @@ static void draw_pattern(const lv_area_t * coords, const lv_area_t * clip, lv_dr lv_draw_mask_remove_id(radius_mask_id); } } +#endif -static void draw_value(const lv_area_t * coords, const lv_area_t * clip, lv_draw_rect_dsc_t * dsc) +#if LV_USE_VALUE_STR +static void draw_value_str(const lv_area_t * coords, const lv_area_t * clip, lv_draw_rect_dsc_t * dsc) { if(dsc->value_str == NULL) return; if(dsc->value_opa <= LV_OPA_MIN) return; @@ -1291,6 +1315,7 @@ static void draw_value(const lv_area_t * coords, const lv_area_t * clip, lv_draw lv_draw_label(&value_area, clip, &label_dsc, dsc->value_str, NULL); } +#endif static void draw_full_border(const lv_area_t * area_inner, const lv_area_t * area_outer, const lv_area_t * clip, lv_coord_t radius, lv_color_t color, lv_opa_t opa, lv_blend_mode_t blend_mode) { diff --git a/src/lv_misc/lv_mem.c b/src/lv_misc/lv_mem.c index 8775f39da..7fa3146f8 100644 --- a/src/lv_misc/lv_mem.c +++ b/src/lv_misc/lv_mem.c @@ -586,6 +586,7 @@ void _lv_mem_buf_free_all(void) } } +#if LV_MEMCPY_MEMSET_STD == 0 /** * Same as `memcpy` but optimized for 4 byte operation. * @param dst pointer to the destination buffer @@ -652,7 +653,6 @@ LV_ATTRIBUTE_FAST_MEM void * _lv_memcpy(void * dst, const void * src, size_t len /** * Same as `memset` but optimized for 4 byte operation. - * `dst` should be word aligned else normal `memcpy` will be used * @param dst pointer to the destination buffer * @param v value to set [0..255] * @param len number of byte to set @@ -707,7 +707,6 @@ LV_ATTRIBUTE_FAST_MEM void _lv_memset(void * dst, uint8_t v, size_t len) /** * Same as `memset(dst, 0x00, len)` but optimized for 4 byte operation. - * `dst` should be word aligned else normal `memcpy` will be used * @param dst pointer to the destination buffer * @param len number of byte to set */ @@ -757,7 +756,6 @@ LV_ATTRIBUTE_FAST_MEM void _lv_memset_00(void * dst, size_t len) /** * Same as `memset(dst, 0xFF, len)` but optimized for 4 byte operation. - * `dst` should be word aligned else normal `memcpy` will be used * @param dst pointer to the destination buffer * @param len number of byte to set */ @@ -805,6 +803,7 @@ LV_ATTRIBUTE_FAST_MEM void _lv_memset_ff(void * dst, size_t len) } } +#endif /*LV_MEMCPY_MEMSET_STD*/ /********************** * STATIC FUNCTIONS diff --git a/src/lv_misc/lv_mem.h b/src/lv_misc/lv_mem.h index 91774133a..f3ca9c6f2 100644 --- a/src/lv_misc/lv_mem.h +++ b/src/lv_misc/lv_mem.h @@ -20,6 +20,10 @@ extern "C" { #include "lv_log.h" #include "lv_types.h" +#if LV_MEMCPY_MEMSET_STD +#include +#endif + /********************* * DEFINES *********************/ @@ -137,6 +141,62 @@ void _lv_mem_buf_free_all(void); //! @cond Doxygen_Suppress +#if LV_MEMCPY_MEMSET_STD + +/** + * Wrapper for the standard memcpy + * @param dst pointer to the destination buffer + * @param src pointer to the source buffer + * @param len number of byte to copy + */ +static inline void * _lv_memcpy(void * dst, const void * src, size_t len) +{ + return memcpy(dst, src, len); +} + +/** + * Wrapper for the standard memcpy + * @param dst pointer to the destination buffer + * @param src pointer to the source buffer + * @param len number of byte to copy + */ +static inline void * _lv_memcpy_small(void * dst, const void * src, size_t len) +{ + return memcpy(dst, src, len); +} + +/** + * Wrapper for the standard memset + * @param dst pointer to the destination buffer + * @param v value to set [0..255] + * @param len number of byte to set + */ +static inline void _lv_memset(void * dst, uint8_t v, size_t len) +{ + memset(dst, v, len); +} + +/** + * Wrapper for the standard memset with fixed 0x00 value + * @param dst pointer to the destination buffer + * @param len number of byte to set + */ +static inline void _lv_memset_00(void * dst, size_t len) +{ + memset(dst, 0x00, len); +} + +/** + * Wrapper for the standard memset with fixed 0xFF value + * @param dst pointer to the destination buffer + * @param len number of byte to set + */ +static inline void _lv_memset_ff(void * dst, size_t len) +{ + memset(dst, 0xFF, len); +} + +#else /** * Same as `memcpy` but optimized for 4 byte operation. * @param dst pointer to the destination buffer @@ -168,7 +228,6 @@ LV_ATTRIBUTE_FAST_MEM static inline void * _lv_memcpy_small(void * dst, const vo /** * Same as `memset` but optimized for 4 byte operation. - * `dst` should be word aligned else normal `memcpy` will be used * @param dst pointer to the destination buffer * @param v value to set [0..255] * @param len number of byte to set @@ -177,7 +236,6 @@ LV_ATTRIBUTE_FAST_MEM void _lv_memset(void * dst, uint8_t v, size_t len); /** * Same as `memset(dst, 0x00, len)` but optimized for 4 byte operation. - * `dst` should be word aligned else normal `memcpy` will be used * @param dst pointer to the destination buffer * @param len number of byte to set */ @@ -185,7 +243,6 @@ LV_ATTRIBUTE_FAST_MEM void _lv_memset_00(void * dst, size_t len); /** * Same as `memset(dst, 0xFF, len)` but optimized for 4 byte operation. - * `dst` should be word aligned else normal `memcpy` will be used * @param dst pointer to the destination buffer * @param len number of byte to set */ @@ -193,6 +250,9 @@ LV_ATTRIBUTE_FAST_MEM void _lv_memset_ff(void * dst, size_t len); //! @endcond +#endif + + /********************** * MACROS **********************/