From deb43a233366de6edfe1a817ca72ab12f5c36533 Mon Sep 17 00:00:00 2001 From: Neo Xu Date: Wed, 20 Dec 2023 17:07:27 +0800 Subject: [PATCH] feat(math): add LV_ALIGN_UP macro (#5053) Signed-off-by: Xu Xingliang --- src/draw/lv_draw_label.c | 4 ++-- src/misc/lv_math.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/draw/lv_draw_label.c b/src/draw/lv_draw_label.c index 6d2eba326..224c03786 100644 --- a/src/draw/lv_draw_label.c +++ b/src/draw/lv_draw_label.c @@ -399,8 +399,8 @@ static void draw_letter(lv_draw_unit_t * draw_unit, lv_draw_glyph_dsc_t * dsc, } uint32_t bitmap_size = lv_draw_buf_width_to_stride(g.box_w, LV_COLOR_FORMAT_A8) * g.box_h; - bitmap_size = (bitmap_size + 63) & - (~63); /*Round up to avoid many allocations if the next buffer is just slightly larger*/ + /*Round up to avoid many allocations if the next buffer is just slightly larger*/ + bitmap_size = LV_ALIGN_UP(bitmap_size, 64); if(dsc->_bitmap_buf_size < bitmap_size) { lv_draw_buf_free(dsc->_bitmap_buf_unaligned); dsc->_bitmap_buf_unaligned = lv_draw_buf_malloc(bitmap_size, LV_COLOR_FORMAT_A8); diff --git a/src/misc/lv_math.h b/src/misc/lv_math.h index 9d889d655..904b44718 100644 --- a/src/misc/lv_math.h +++ b/src/misc/lv_math.h @@ -27,6 +27,9 @@ extern "C" { #define LV_BEZIER_VAL_MAX (1L << LV_BEZIER_VAL_SHIFT) /**< Max time in Bezier functions (not [0..1] to use integers)*/ #define LV_BEZIER_VAL_FLOAT(f) ((int32_t)((f) * LV_BEZIER_VAL_MAX)) /**< Convert const float number cubic-bezier values to fix-point value*/ +/*Align up value x to align, align must be a power of two*/ +#define LV_ALIGN_UP(x, align) (((x) + ((align) - 1)) & ~((align) - 1)) + /********************** * TYPEDEFS **********************/