fix(draw_buf): use LV_ROUND_UP to align draw buffer address
From test config lv_test_conf.h: /*Use non power of 2 to avoid the case when `malloc` returns aligned pointer by default, and use a large value be sure any issues will cause crash*/ \#define LV_DRAW_BUF_ALIGN 852 We need to support non-power-of-2 draw buffer alignement. Introduce LV_ROUND_UP in lv_math.h and use it instead. Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "lv_draw_buf.h"
|
||||
#include "../stdlib/lv_string.h"
|
||||
#include "../core/lv_global.h"
|
||||
#include "../misc/lv_math.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
@@ -522,8 +523,7 @@ static void * buf_align(void * buf, lv_color_format_t color_format)
|
||||
|
||||
uint8_t * buf_u8 = buf;
|
||||
if(buf_u8) {
|
||||
buf_u8 += LV_DRAW_BUF_ALIGN - 1;
|
||||
buf_u8 = (uint8_t *)((lv_uintptr_t) buf_u8 & ~(LV_DRAW_BUF_ALIGN - 1));
|
||||
buf_u8 = (uint8_t *)LV_ROUND_UP((lv_uintptr_t)buf_u8, LV_DRAW_BUF_ALIGN);
|
||||
}
|
||||
return buf_u8;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,9 @@ extern "C" {
|
||||
/*Align up value x to align, align must be a power of two*/
|
||||
#define LV_ALIGN_UP(x, align) (((x) + ((align) - 1)) & ~((align) - 1))
|
||||
|
||||
/*Round up value x to round, round can be any integer number*/
|
||||
#define LV_ROUND_UP(x, round) ((((x) + ((round) - 1)) / (round)) * (round))
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
Reference in New Issue
Block a user