add LV_DRAW_COMPLEX

This commit is contained in:
Gabor Kiss-Vamosi
2021-01-26 16:38:21 +01:00
parent 1f4c5adc30
commit e02c7bd415
21 changed files with 224 additions and 107 deletions

View File

@@ -420,15 +420,6 @@
# endif
#endif
/* 1: Use other blend modes than normal (`LV_BLEND_MODE_...`)*/
#ifndef LV_USE_BLEND_MODES
# ifdef CONFIG_LV_USE_BLEND_MODES
# define LV_USE_BLEND_MODES CONFIG_LV_USE_BLEND_MODES
# else
# define LV_USE_BLEND_MODES 1
# endif
#endif
/* 1: Use the `opa_scale` style property to set the opacity of an object and its children at once*/
#ifndef LV_USE_OPA_SCALE
# ifdef CONFIG_LV_USE_OPA_SCALE

View File

@@ -249,12 +249,18 @@ lv_res_t lv_event_send(lv_obj_t * obj, lv_event_t event, void * data)
return res;
}
void * lv_event_get_data(void)
{
return event_act_data;
}
uint32_t lv_event_register_id(void)
{
static uint32_t last_id = _LV_EVENT_LAST;
last_id ++;
return last_id;
}
/**
* Nested events can be called and one of them might belong to an object that is being deleted.
* Mark this object's `event_temp_data` deleted to know that it's `lv_event_send` should return `LV_RES_INV`
@@ -689,7 +695,7 @@ static lv_draw_res_t lv_obj_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv
if(lv_obj_get_style_bg_opa(obj, LV_PART_MAIN) < LV_OPA_MAX) return LV_DRAW_RES_NOT_COVER;
#if LV_USE_BLEND_MODES
#if LV_DRAW_COMPLEX
if(lv_obj_get_style_blend_mode(obj, LV_PART_MAIN) != LV_BLEND_MODE_NORMAL) return LV_DRAW_RES_NOT_COVER;
#endif
if(lv_obj_get_style_opa(obj, LV_PART_MAIN) < LV_OPA_MAX) return LV_DRAW_RES_NOT_COVER;
@@ -718,6 +724,7 @@ static lv_draw_res_t lv_obj_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv
lv_draw_rect(&coords, clip_area, &draw_dsc);
#if LV_DRAW_COMPLEX
if(lv_obj_get_style_clip_corner(obj, LV_PART_MAIN)) {
lv_draw_mask_radius_param_t * mp = lv_mem_buf_get(sizeof(lv_draw_mask_radius_param_t));
lv_coord_t r = lv_obj_get_style_radius(obj, LV_PART_MAIN);
@@ -725,14 +732,17 @@ static lv_draw_res_t lv_obj_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv
/*Add the mask and use `obj+8` as custom id. Don't use `obj` directly because it might be used by the user*/
lv_draw_mask_add(mp, obj + 8);
}
#endif
}
else if(mode == LV_DRAW_MODE_POST_DRAW) {
draw_scrollbar(obj, clip_area);
#if LV_DRAW_COMPLEX
if(lv_obj_get_style_clip_corner(obj, LV_PART_MAIN)) {
lv_draw_mask_radius_param_t * param = lv_draw_mask_remove_custom(obj + 8);
lv_mem_buf_release(param);
}
#endif
/*If the border is drawn later disable loading other properties*/
if(lv_obj_get_style_border_post(obj, LV_PART_MAIN)) {
@@ -916,6 +926,7 @@ static lv_res_t scrollbar_init_draw_dsc(lv_obj_t * obj, lv_draw_rect_dsc_t * dsc
}
}
#if LV_DRAW_COMPLEX
lv_opa_t opa = lv_obj_get_style_opa(obj, LV_PART_SCROLLBAR);
if(opa < LV_OPA_MAX) {
dsc->bg_opa = (dsc->bg_opa * opa) >> 8;
@@ -928,6 +939,10 @@ static lv_res_t scrollbar_init_draw_dsc(lv_obj_t * obj, lv_draw_rect_dsc_t * dsc
} else {
return LV_RES_INV;
}
#else
if(dsc->bg_opa != LV_OPA_TRANSP || dsc->border_opa != LV_OPA_TRANSP) return LV_RES_OK;
else return LV_RES_INV;
#endif
}

View File

@@ -356,6 +356,19 @@ lv_res_t lv_event_send(lv_obj_t * obj, lv_event_t event, void * data);
*/
void * lv_event_get_data(void);
/**
* Register a new, custom event ID.
* It can be used the same way as e.g. `LV_EVENT_CLICKED` to send custom events
* @return the new event id
* @example
* uint32_t LV_EVENT_MINE = 0;
* ...
* e = lv_event_register_id();
* ...
* lv_event_send(obj, LV_EVENT_MINE, &some_data);
*/
uint32_t lv_event_register_id(void);
/**
* Send an event to the object
* @param obj pointer to an object

View File

@@ -38,9 +38,10 @@
void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t part, lv_draw_rect_dsc_t * draw_dsc)
{
#if LV_DRAW_COMPLEX
draw_dsc->radius = lv_obj_get_style_radius(obj, part);
#if LV_USE_OPA_SCALE
lv_opa_t main_opa = part != LV_PART_MAIN ? lv_obj_get_style_opa(obj, part) : LV_OPA_COVER;
lv_opa_t opa = lv_obj_get_style_opa(obj, part);
if(opa <= LV_OPA_MIN || main_opa <= LV_OPA_MIN) {
@@ -50,11 +51,8 @@ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t part, lv_draw_rect_dsc_t
draw_dsc->outline_opa = LV_OPA_TRANSP;
return;
}
#endif
#if LV_USE_BLEND_MODES
draw_dsc->blend_mode = lv_obj_get_style_blend_mode(obj, part);
#endif
if(draw_dsc->bg_opa != LV_OPA_TRANSP) {
draw_dsc->bg_opa = lv_obj_get_style_bg_opa(obj, part);
@@ -135,7 +133,6 @@ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t part, lv_draw_rect_dsc_t
}
}
#if LV_USE_OPA_SCALE
if(main_opa < LV_OPA_MAX) {
opa = (uint16_t)((uint16_t) main_opa * opa) >> 8;
}
@@ -147,6 +144,55 @@ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t part, lv_draw_rect_dsc_t
draw_dsc->content_opa = (uint16_t)((uint16_t)draw_dsc->content_opa * opa) >> 8;
draw_dsc->outline_opa = (uint16_t)((uint16_t)draw_dsc->outline_opa * opa) >> 8;
}
#else /*LV_DRAW_COMPLEX*/
if(draw_dsc->bg_opa != LV_OPA_TRANSP) {
draw_dsc->bg_opa = lv_obj_get_style_bg_opa(obj, part);
if(draw_dsc->bg_opa > LV_OPA_MIN) {
draw_dsc->bg_color = lv_obj_get_style_bg_color_filtered(obj, part);
}
}
draw_dsc->border_width = lv_obj_get_style_border_width(obj, part);
if(draw_dsc->border_width) {
if(draw_dsc->border_opa != LV_OPA_TRANSP) {
draw_dsc->border_opa = lv_obj_get_style_border_opa(obj, part);
if(draw_dsc->border_opa > LV_OPA_MIN) {
draw_dsc->border_color = lv_obj_get_style_border_color_filtered(obj, part);
}
}
}
draw_dsc->outline_width = lv_obj_get_style_outline_width(obj, part);
if(draw_dsc->outline_width) {
if(draw_dsc->outline_opa != LV_OPA_TRANSP) {
draw_dsc->outline_opa = lv_obj_get_style_outline_opa(obj, part);
if(draw_dsc->outline_opa > LV_OPA_MIN) {
draw_dsc->outline_pad = lv_obj_get_style_outline_pad(obj, part);
draw_dsc->outline_color = lv_obj_get_style_outline_color(obj, part);
}
}
}
if(draw_dsc->bg_img_opa != LV_OPA_TRANSP) {
draw_dsc->bg_img_src = lv_obj_get_style_bg_img_src(obj, part);
if(draw_dsc->bg_img_src) {
draw_dsc->bg_img_opa = lv_obj_get_style_bg_img_opa(obj, part);
if(draw_dsc->bg_img_opa > LV_OPA_MIN) {
draw_dsc->bg_img_tiled = lv_obj_get_style_bg_img_tiled(obj, part);
}
}
}
draw_dsc->content_text = lv_obj_get_style_content_text(obj, part);
if(draw_dsc->content_text) {
draw_dsc->content_ofs_y = lv_obj_get_style_content_ofs_y(obj, part);
draw_dsc->content_ofs_x = lv_obj_get_style_content_ofs_x(obj, part);
draw_dsc->content_align = lv_obj_get_style_content_align(obj, part);
draw_dsc->content_font = lv_obj_get_style_content_font(obj, part);
draw_dsc->content_color = lv_obj_get_style_content_color_filtered(obj, part);
draw_dsc->content_letter_space = lv_obj_get_style_content_letter_space(obj, part);
draw_dsc->content_line_space = lv_obj_get_style_content_line_space(obj, part);
}
#endif
}
@@ -167,7 +213,7 @@ void lv_obj_init_draw_label_dsc(lv_obj_t * obj, uint8_t part, lv_draw_label_dsc_
draw_dsc->letter_space = lv_obj_get_style_text_letter_space(obj, part);
draw_dsc->line_space = lv_obj_get_style_text_line_space(obj, part);
draw_dsc->decor = lv_obj_get_style_text_decor(obj, part);
#if LV_USE_BLEND_MODES
#if LV_DRAW_COMPLEX
draw_dsc->blend_mode = lv_obj_get_style_blend_mode(obj, part);
#endif
@@ -213,7 +259,7 @@ void lv_obj_init_draw_img_dsc(lv_obj_t * obj, uint8_t part, lv_draw_img_dsc_t *
if(draw_dsc->recolor_opa > 0) {
draw_dsc->recolor = lv_obj_get_style_img_recolor(obj, part);
}
#if LV_USE_BLEND_MODES
#if LV_DRAW_COMPLEX
draw_dsc->blend_mode = lv_obj_get_style_blend_mode(obj, part);
#endif
}
@@ -244,7 +290,7 @@ void lv_obj_init_draw_line_dsc(lv_obj_t * obj, uint8_t part, lv_draw_line_dsc_t
draw_dsc->round_start = lv_obj_get_style_line_rounded(obj, part);
draw_dsc->round_end = draw_dsc->round_start;
#if LV_USE_BLEND_MODES
#if LV_DRAW_COMPLEX
draw_dsc->blend_mode = lv_obj_get_style_blend_mode(obj, part);
#endif
}
@@ -270,7 +316,7 @@ void lv_obj_init_draw_arc_dsc(lv_obj_t * obj, uint8_t part, lv_draw_arc_dsc_t *
draw_dsc->rounded = lv_obj_get_style_line_rounded(obj, part);
#if LV_USE_BLEND_MODES
#if LV_DRAW_COMPLEX
draw_dsc->blend_mode = lv_obj_get_style_blend_mode(obj, part);
#endif
}

View File

@@ -10,6 +10,7 @@
#include "lv_draw_rect.h"
#include "lv_draw_mask.h"
#include "../lv_misc/lv_math.h"
#include "../lv_misc/lv_log.h"
/*********************
* DEFINES
@@ -37,11 +38,13 @@ typedef struct {
/**********************
* STATIC PROTOTYPES
**********************/
#if LV_DRAW_COMPLEX
static void draw_quarter_0(quarter_draw_dsc_t * q);
static void draw_quarter_1(quarter_draw_dsc_t * q);
static void draw_quarter_2(quarter_draw_dsc_t * q);
static void draw_quarter_3(quarter_draw_dsc_t * q);
static void get_rounded_area(int16_t angle, lv_coord_t radius, uint8_t thickness, lv_area_t * res_area);
#endif /*LV_DRAW_COMPLEX*/
/**********************
* STATIC VARIABLES
@@ -77,6 +80,7 @@ LV_ATTRIBUTE_FAST_MEM void lv_draw_arc_dsc_init(lv_draw_arc_dsc_t * dsc)
void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uint16_t start_angle, uint16_t end_angle,
const lv_area_t * clip_area, const lv_draw_arc_dsc_t * dsc)
{
#if LV_DRAW_COMPLEX
if(dsc->opa <= LV_OPA_MIN) return;
if(dsc->width == 0) return;
if(start_angle == end_angle) return;
@@ -197,12 +201,16 @@ void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uin
lv_draw_mask_remove_id(mask_end_id);
}
}
#else
LV_LOG_WARN("Can't draw arc with LV_DRAW_COMPLEX == 0");
#endif /*LV_DRAW_COMPLEX*/
}
/**********************
* STATIC FUNCTIONS
**********************/
#if LV_DRAW_COMPLEX
static void draw_quarter_0(quarter_draw_dsc_t * q)
{
lv_area_t quarter_area;
@@ -452,3 +460,5 @@ static void get_rounded_area(int16_t angle, lv_coord_t radius, uint8_t thickness
res_area->y2 = cir_y + thick_half - thick_corr;
}
}
#endif /*LV_DRAW_COMPLEX*/

View File

@@ -42,7 +42,7 @@ LV_ATTRIBUTE_FAST_MEM static void fill_normal(const lv_area_t * disp_area, lv_co
lv_color_t color, lv_opa_t opa,
const lv_opa_t * mask, lv_draw_mask_res_t mask_res);
#if LV_USE_BLEND_MODES
#if LV_DRAW_COMPLEX
static void fill_blended(const lv_area_t * disp_area, lv_color_t * disp_buf, const lv_area_t * draw_area,
lv_color_t color, lv_opa_t opa,
const lv_opa_t * mask, lv_draw_mask_res_t mask_res, lv_blend_mode_t mode);
@@ -57,7 +57,7 @@ LV_ATTRIBUTE_FAST_MEM static void map_normal(const lv_area_t * disp_area, lv_col
const lv_area_t * map_area, const lv_color_t * map_buf, lv_opa_t opa,
const lv_opa_t * mask, lv_draw_mask_res_t mask_res);
#if LV_USE_BLEND_MODES
#if LV_DRAW_COMPLEX
static void map_blended(const lv_area_t * disp_area, lv_color_t * disp_buf, const lv_area_t * draw_area,
const lv_area_t * map_area, const lv_color_t * map_buf, lv_opa_t opa,
const lv_opa_t * mask, lv_draw_mask_res_t mask_res, lv_blend_mode_t mode);
@@ -174,7 +174,7 @@ LV_ATTRIBUTE_FAST_MEM void _lv_blend_fill(const lv_area_t * clip_area, const lv_
else if(mode == LV_BLEND_MODE_NORMAL) {
fill_normal(disp_area, disp_buf, &draw_area, color, opa, mask, mask_res);
}
#if LV_USE_BLEND_MODES
#if LV_DRAW_COMPLEX
else {
fill_blended(disp_area, disp_buf, &draw_area, color, opa, mask, mask_res, mode);
}
@@ -241,7 +241,7 @@ LV_ATTRIBUTE_FAST_MEM void _lv_blend_map(const lv_area_t * clip_area, const lv_a
else if(mode == LV_BLEND_MODE_NORMAL) {
map_normal(disp_area, disp_buf, &draw_area, map_area, map_buf, opa, mask, mask_res);
}
#if LV_USE_BLEND_MODES
#if LV_DRAW_COMPLEX
else {
map_blended(disp_area, disp_buf, &draw_area, map_area, map_buf, opa, mask, mask_res, mode);
}
@@ -362,7 +362,6 @@ LV_ATTRIBUTE_FAST_MEM static void fill_normal(const lv_area_t * disp_area, lv_co
}
/*No mask with opacity*/
else {
#if LV_USE_GPU_NXP_PXP
if(lv_area_get_size(draw_area) >= LV_GPU_NXP_PXP_FILL_OPA_SIZE_LIMIT) {
lv_gpu_nxp_pxp_fill(disp_buf, disp_w, draw_area, color, opa);
@@ -549,7 +548,7 @@ LV_ATTRIBUTE_FAST_MEM static void fill_normal(const lv_area_t * disp_area, lv_co
}
}
#if LV_USE_BLEND_MODES
#if LV_DRAW_COMPLEX
/**
* Fill an area with a color but apply blending algorithms
* @param disp_area the current display area (destination area)
@@ -949,7 +948,7 @@ LV_ATTRIBUTE_FAST_MEM static void map_normal(const lv_area_t * disp_area, lv_col
}
}
}
#if LV_USE_BLEND_MODES
#if LV_DRAW_COMPLEX
static void map_blended(const lv_area_t * disp_area, lv_color_t * disp_buf, const lv_area_t * draw_area,
const lv_area_t * map_area, const lv_color_t * map_buf, lv_opa_t opa,
const lv_opa_t * mask, lv_draw_mask_res_t mask_res, lv_blend_mode_t mode)

View File

@@ -362,6 +362,8 @@ LV_ATTRIBUTE_FAST_MEM static void lv_draw_map(const lv_area_t * map_area, const
_lv_blend_map(clip_area, map_area, (lv_color_t *)map_p, NULL, LV_DRAW_MASK_RES_FULL_COVER, draw_dsc->opa,
draw_dsc->blend_mode);
}
#if LV_DRAW_COMPLEX
#if LV_USE_GPU_NXP_PXP
/* Simple case without masking and transformations */
else if(other_mask_cnt == 0 && draw_dsc->angle == 0 && draw_dsc->zoom == LV_IMG_ZOOM_NONE && alpha_byte == false &&
@@ -637,6 +639,7 @@ LV_ATTRIBUTE_FAST_MEM static void lv_draw_map(const lv_area_t * map_area, const
lv_mem_buf_release(map2);
}
}
#endif
}
static void show_error(const lv_area_t * coords, const lv_area_t * clip_area, const char * msg)

View File

@@ -38,6 +38,7 @@ LV_ATTRIBUTE_FAST_MEM static void lv_draw_letter(const lv_point_t * pos_p, const
LV_ATTRIBUTE_FAST_MEM static void draw_letter_normal(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_dsc_t * g,
const lv_area_t * clip_area,
const uint8_t * map_p, lv_color_t color, lv_opa_t opa, lv_blend_mode_t blend_mode);
static void draw_letter_subpx(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_dsc_t * g, const lv_area_t * clip_area,
const uint8_t * map_p, lv_color_t color, lv_opa_t opa, lv_blend_mode_t blend_mode);
@@ -63,6 +64,7 @@ const uint8_t _lv_bpp4_opa_table[16] = {0, 17, 34, 51, /*Opacity mapping with
136, 153, 170, 187,
204, 221, 238, 255
};
const uint8_t _lv_bpp8_opa_table[256] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
@@ -439,12 +441,8 @@ LV_ATTRIBUTE_FAST_MEM static void lv_draw_letter(const lv_point_t * pos_p, const
return;
}
if(font_p->subpx) {
draw_letter_subpx(pos_x, pos_y, &g, clip_area, map_p, color, opa, blend_mode);
}
else {
draw_letter_normal(pos_x, pos_y, &g, clip_area, map_p, color, opa, blend_mode);
}
if(font_p->subpx) draw_letter_subpx(pos_x, pos_y, &g, clip_area, map_p, color, opa, blend_mode);
else draw_letter_normal(pos_x, pos_y, &g, clip_area, map_p, color, opa, blend_mode);
}
LV_ATTRIBUTE_FAST_MEM static void draw_letter_normal(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_dsc_t * g,
@@ -563,6 +561,7 @@ LV_ATTRIBUTE_FAST_MEM static void draw_letter_normal(lv_coord_t pos_x, lv_coord_
mask_p++;
}
#if LV_DRAW_COMPLEX
/*Apply masks if any*/
if(other_mask_cnt) {
lv_draw_mask_res_t mask_res = lv_draw_mask_apply(mask_buf + mask_p_start, fill_area.x1, fill_area.y2,
@@ -571,6 +570,7 @@ LV_ATTRIBUTE_FAST_MEM static void draw_letter_normal(lv_coord_t pos_x, lv_coord_
lv_memset_00(mask_buf + mask_p_start, lv_area_get_width(&fill_area));
}
}
#endif
if((uint32_t) mask_p + (col_end - col_start) < mask_buf_size) {
fill_area.y2 ++;
@@ -605,7 +605,7 @@ LV_ATTRIBUTE_FAST_MEM static void draw_letter_normal(lv_coord_t pos_x, lv_coord_
static void draw_letter_subpx(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_dsc_t * g, const lv_area_t * clip_area,
const uint8_t * map_p, lv_color_t color, lv_opa_t opa, lv_blend_mode_t blend_mode)
{
#if LV_USE_FONT_SUBPX
#if LV_DRAW_COMPLEX
const uint8_t * bpp_opa_table;
uint32_t bitmask_init;
uint32_t bitmask;

View File

@@ -24,9 +24,11 @@
/**********************
* STATIC PROTOTYPES
**********************/
LV_ATTRIBUTE_FAST_MEM static void draw_line_skew(const lv_point_t * point1, const lv_point_t * point2,
const lv_area_t * clip,
const lv_draw_line_dsc_t * dsc);
LV_ATTRIBUTE_FAST_MEM static void draw_line_hor(const lv_point_t * point1, const lv_point_t * point2,
const lv_area_t * clip,
const lv_draw_line_dsc_t * dsc);
@@ -149,6 +151,7 @@ LV_ATTRIBUTE_FAST_MEM static void draw_line_hor(const lv_point_t * point1, const
dsc->color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa,
dsc->blend_mode);
}
#if LV_DRAW_COMPLEX
/*If there other mask apply it*/
else {
/* Get clipped fill area which is the real draw area.
@@ -214,6 +217,7 @@ LV_ATTRIBUTE_FAST_MEM static void draw_line_hor(const lv_point_t * point1, const
}
lv_mem_buf_release(mask_buf);
}
#endif /*LV_DRAW_COMPLEX*/
}
LV_ATTRIBUTE_FAST_MEM static void draw_line_ver(const lv_point_t * point1, const lv_point_t * point2,
@@ -249,6 +253,8 @@ LV_ATTRIBUTE_FAST_MEM static void draw_line_ver(const lv_point_t * point1, const
dsc->color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa,
dsc->blend_mode);
}
#if LV_DRAW_COMPLEX
/*If there other mask apply it*/
else {
/* Get clipped fill area which is the real draw area.
@@ -308,12 +314,14 @@ LV_ATTRIBUTE_FAST_MEM static void draw_line_ver(const lv_point_t * point1, const
}
lv_mem_buf_release(mask_buf);
}
#endif /*LV_DRAW_COMPLEX*/
}
LV_ATTRIBUTE_FAST_MEM static void draw_line_skew(const lv_point_t * point1, const lv_point_t * point2,
const lv_area_t * clip,
const lv_draw_line_dsc_t * dsc)
{
#if LV_DRAW_COMPLEX
/*Keep the great y in p1*/
lv_point_t p1;
lv_point_t p2;
@@ -475,4 +483,8 @@ LV_ATTRIBUTE_FAST_MEM static void draw_line_skew(const lv_point_t * point1, cons
lv_draw_mask_remove_id(mask_right_id);
lv_draw_mask_remove_id(mask_top_id);
lv_draw_mask_remove_id(mask_bottom_id);
#else
LV_LOG_WARN("Can't draw skewed line with LV_DRAW_COMPLEX == 0");
#endif /*LV_DRAW_COMPLEX*/
}

View File

@@ -6,6 +6,9 @@
/*********************
* INCLUDES
*********************/
#if LV_DRAW_COMPLEX
#include "lv_draw_mask.h"
#include "../lv_misc/lv_math.h"
#include "../lv_misc/lv_log.h"
@@ -1230,3 +1233,5 @@ LV_ATTRIBUTE_FAST_MEM static inline void sqrt_approx(lv_sqrt_res_t * q, lv_sqrt_
q->i = d >> 4;
q->f = (d & 0xF) << 4;
}
#endif /*LV_DRAW_COMPLEX*/

View File

@@ -1,15 +1,16 @@
/**
* @file lv_mask.h
* @file lv_draw_mask.h
*
*/
#ifndef LV_MASK_H
#define LV_MASK_H
#ifndef LV_DRAW_MASK_H
#define LV_DRAW_MASK_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
@@ -22,7 +23,11 @@ extern "C" {
* DEFINES
*********************/
#define LV_MASK_ID_INV (-1)
#if LV_DRAW_COMPLEX
#define _LV_MASK_MAX_NUM 16
#else
#define _LV_MASK_MAX_NUM 1
#endif
/**********************
* TYPEDEFS
@@ -37,6 +42,23 @@ enum {
typedef uint8_t lv_draw_mask_res_t;
typedef struct {
void * param;
void * custom_id;
} _lv_draw_mask_saved_t;
typedef _lv_draw_mask_saved_t _lv_draw_mask_saved_arr_t[_LV_MASK_MAX_NUM];
#if LV_DRAW_COMPLEX == 0
static inline uint8_t lv_draw_mask_get_cnt(void) {
return 0;
}
#endif
#if LV_DRAW_COMPLEX
enum {
LV_DRAW_MASK_TYPE_LINE,
LV_DRAW_MASK_TYPE_ANGLE,
@@ -161,12 +183,6 @@ typedef struct _lv_draw_mask_map_param_t {
} cfg;
} lv_draw_mask_map_param_t;
typedef struct {
void * param;
void * custom_id;
} _lv_draw_mask_saved_t;
typedef _lv_draw_mask_saved_t _lv_draw_mask_saved_arr_t[_LV_MASK_MAX_NUM];
/**********************
* GLOBAL PROTOTYPES
@@ -292,6 +308,8 @@ void lv_draw_mask_fade_init(lv_draw_mask_fade_param_t * param, const lv_area_t *
*/
void lv_draw_mask_map_init(lv_draw_mask_map_param_t * param, const lv_area_t * coords, const lv_opa_t * map);
#endif /*LV_DRAW_COMPLEX*/
/**********************
* MACROS
**********************/
@@ -300,4 +318,4 @@ void lv_draw_mask_map_init(lv_draw_mask_map_param_t * param, const lv_area_t * c
} /* extern "C" */
#endif
#endif /*LV_MASK_H*/
#endif /*LV_DRAW_MASK_H*/

View File

@@ -35,10 +35,9 @@ LV_ATTRIBUTE_FAST_MEM static void draw_bg_img(const lv_area_t * coords, const lv
LV_ATTRIBUTE_FAST_MEM static void draw_border(const lv_area_t * coords, const lv_area_t * clip,
const lv_draw_rect_dsc_t * dsc);
#if LV_USE_OUTLINE
static void draw_outline(const lv_area_t * coords, const lv_area_t * clip, const lv_draw_rect_dsc_t * dsc);
#endif
#if LV_USE_SHADOW
static void draw_outline(const lv_area_t * coords, const lv_area_t * clip, const lv_draw_rect_dsc_t * dsc);
#if LV_USE_COMPLEX
LV_ATTRIBUTE_FAST_MEM static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip,
const lv_draw_rect_dsc_t * dsc);
LV_ATTRIBUTE_FAST_MEM static void shadow_draw_corner_buf(const lv_area_t * coords, uint16_t * sh_buf, lv_coord_t s,
@@ -46,13 +45,13 @@ LV_ATTRIBUTE_FAST_MEM static void shadow_draw_corner_buf(const lv_area_t * coord
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_content(const lv_area_t * coords, const lv_area_t * clip, const lv_draw_rect_dsc_t * dsc);
#endif
static void draw_content(const lv_area_t * coords, const lv_area_t * clip, const lv_draw_rect_dsc_t * dsc);
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, bool radius_is_in, lv_color_t color, lv_opa_t opa, lv_blend_mode_t blend_mode);
#if LV_USE_COMPLEX
LV_ATTRIBUTE_FAST_MEM static inline lv_color_t grad_get(const lv_draw_rect_dsc_t * dsc, lv_coord_t s, lv_coord_t i);
#endif
/**********************
* STATIC VARIABLES
@@ -100,7 +99,7 @@ LV_ATTRIBUTE_FAST_MEM void lv_draw_rect_dsc_init(lv_draw_rect_dsc_t * dsc)
void lv_draw_rect(const lv_area_t * coords, const lv_area_t * clip, const lv_draw_rect_dsc_t * dsc)
{
if(lv_area_get_height(coords) < 1 || lv_area_get_width(coords) < 1) return;
#if LV_USE_SHADOW
#if LV_DRAW_COMPLEX
draw_shadow(coords, clip, dsc);
#endif
@@ -163,10 +162,6 @@ LV_ATTRIBUTE_FAST_MEM static void draw_bg(const lv_area_t * coords, const lv_are
draw_area.x2 -= disp_area->x1;
draw_area.y2 -= disp_area->y1;
int32_t draw_area_w = lv_area_get_width(&draw_area);
/*Create a mask if there is a radius*/
lv_opa_t * mask_buf = lv_mem_buf_get(draw_area_w);
lv_grad_dir_t grad_dir = dsc->bg_grad_dir;
if(dsc->bg_color.full == dsc->bg_grad_color.full) grad_dir = LV_GRAD_DIR_NONE;
@@ -176,7 +171,6 @@ LV_ATTRIBUTE_FAST_MEM static void draw_bg(const lv_area_t * coords, const lv_are
if(other_mask_cnt) simple_mode = false;
else if(grad_dir == LV_GRAD_DIR_HOR) simple_mode = false;
int16_t mask_rout_id = LV_MASK_ID_INV;
int32_t coords_w = lv_area_get_width(&coords_bg);
int32_t coords_h = lv_area_get_height(&coords_bg);
@@ -192,10 +186,16 @@ LV_ATTRIBUTE_FAST_MEM static void draw_bg(const lv_area_t * coords, const lv_are
dsc->bg_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa,
dsc->blend_mode);
}
#if LV_DRAW_COMPLEX
/*More complex case: there is a radius, gradient or other mask.*/
else {
int32_t draw_area_w = lv_area_get_width(&draw_area);
int16_t mask_rout_id = LV_MASK_ID_INV;
lv_opa_t * mask_buf = NULL;
lv_draw_mask_radius_param_t mask_rout_param;
if(rout > 0) {
mask_buf = lv_mem_buf_get(draw_area_w);
lv_draw_mask_radius_init(&mask_rout_param, &coords_bg, rout, false);
mask_rout_id = lv_draw_mask_add(&mask_rout_param, NULL);
}
@@ -205,8 +205,8 @@ LV_ATTRIBUTE_FAST_MEM static void draw_bg(const lv_area_t * coords, const lv_are
lv_draw_mask_res_t mask_res = LV_DRAW_MASK_RES_FULL_COVER;
lv_color_t grad_color = dsc->bg_color;
lv_color_t * grad_map = NULL;
/*In case of horizontal gradient pre-compute a line with a gradient*/
lv_color_t * grad_map = NULL;
if(grad_dir == LV_GRAD_DIR_HOR) {
grad_map = lv_mem_buf_get(coords_w * sizeof(lv_color_t));
@@ -335,12 +335,11 @@ LV_ATTRIBUTE_FAST_MEM static void draw_bg(const lv_area_t * coords, const lv_are
}
if(grad_map) lv_mem_buf_release(grad_map);
if(mask_buf) lv_mem_buf_release(mask_buf);
lv_draw_mask_remove_id(mask_rout_id);
}
lv_draw_mask_remove_id(mask_rout_id);
lv_mem_buf_release(mask_buf);
#endif
}
LV_ATTRIBUTE_FAST_MEM static void draw_bg_img(const lv_area_t * coords, const lv_area_t * clip,
@@ -416,6 +415,7 @@ LV_ATTRIBUTE_FAST_MEM static void draw_border(const lv_area_t * coords, const lv
draw_full_border(&area_inner, coords, clip, dsc->radius, false, dsc->border_color, dsc->border_opa,
dsc->blend_mode);
}
#if LV_DRAW_COMPLEX
else {
lv_opa_t opa = dsc->border_opa;
if(opa > LV_OPA_MAX) opa = LV_OPA_COVER;
@@ -507,8 +507,10 @@ LV_ATTRIBUTE_FAST_MEM static void draw_border(const lv_area_t * coords, const lv
lv_draw_mask_remove_id(mask_rout_id);
lv_mem_buf_release(mask_buf);
}
#endif /*LV_DRAW_COMPLEX*/
}
#if LV_DRAW_COMPLEX
LV_ATTRIBUTE_FAST_MEM static inline lv_color_t grad_get(const lv_draw_rect_dsc_t * dsc, lv_coord_t s, lv_coord_t i)
{
int32_t min = (dsc->bg_main_color_stop * s) >> 8;
@@ -524,7 +526,6 @@ LV_ATTRIBUTE_FAST_MEM static inline lv_color_t grad_get(const lv_draw_rect_dsc_t
return lv_color_mix(dsc->bg_grad_color, dsc->bg_color, mix);
}
#if LV_USE_SHADOW
LV_ATTRIBUTE_FAST_MEM static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip,
const lv_draw_rect_dsc_t * dsc)
{
@@ -1152,7 +1153,6 @@ 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, const lv_draw_rect_dsc_t * dsc)
{
if(dsc->outline_opa <= LV_OPA_MIN) return;
@@ -1181,9 +1181,7 @@ static void draw_outline(const lv_area_t * coords, const lv_area_t * clip, const
draw_full_border(&area_inner, &area_outer, clip, dsc->radius, true, dsc->outline_color, dsc->outline_opa,
dsc->blend_mode);
}
#endif
#if LV_USE_PATTERN
static void draw_content(const lv_area_t * coords, const lv_area_t * clip, const lv_draw_rect_dsc_t * dsc)
{
if(dsc->content_text == NULL) return;
@@ -1191,6 +1189,14 @@ static void draw_content(const lv_area_t * coords, const lv_area_t * clip, const
lv_draw_label_dsc_t label_dsc;
#if LV_USE_ARABIC_PERSIAN_CHARS
size_t len = _lv_txt_ap_calc_bytes_cnt(dsc->content_text) + 1;
const char * txt = txt = lv_mem_buf_get(len);
_lv_txt_ap_proc(dsc->content_text, txt);
#else
const char * txt = dsc->content_text;
#endif
lv_draw_label_dsc_init(&label_dsc);
label_dsc.color = dsc->content_color;
label_dsc.font = dsc->content_font;
@@ -1204,7 +1210,6 @@ static void draw_content(const lv_area_t * coords, const lv_area_t * clip, const
if(s.x == 0 || s.y == 0) return;
lv_area_t coords_tmp;
lv_draw_mask_radius_param_t radius_mask_param;
coords_tmp.x1 = 0;
coords_tmp.y1 = 0;
@@ -1222,15 +1227,16 @@ static void draw_content(const lv_area_t * coords, const lv_area_t * clip, const
lv_draw_label(&coords_tmp, clip, &label_dsc, dsc->content_text, NULL);
#if LV_USE_ARABIC_PERSIAN_CHARS
lv_mem_buf_release(str);
lv_mem_buf_release(txt);
#endif
}
#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, bool radius_is_in, lv_color_t color, lv_opa_t opa, lv_blend_mode_t blend_mode)
{
#if LV_DRAW_COMPLEX
uint8_t other_mask_cnt = lv_draw_mask_get_cnt();
bool simple_mode = true;
if(other_mask_cnt) simple_mode = false;
@@ -1411,4 +1417,5 @@ static void draw_full_border(const lv_area_t * area_inner, const lv_area_t * are
lv_draw_mask_remove_id(mask_rin_id);
lv_draw_mask_remove_id(mask_rout_id);
lv_mem_buf_release(mask_buf);
#endif /*LV_DRAW_COMPLEX*/
}

View File

@@ -42,7 +42,11 @@
*/
void lv_draw_triangle(const lv_point_t points[], const lv_area_t * clip_area, const lv_draw_rect_dsc_t * draw_dsc)
{
#if LV_DRAW_COMPLEX
lv_draw_polygon(points, 3, clip_area, draw_dsc);
#else
LV_LOG_WARN("Can't draw triangle with LV_DRAW_COMPLEX == 0");
#endif /*LV_DRAW_COMPLEX*/
}
/**
@@ -55,6 +59,7 @@ void lv_draw_triangle(const lv_point_t points[], const lv_area_t * clip_area, co
void lv_draw_polygon(const lv_point_t points[], uint16_t point_cnt, const lv_area_t * clip_area,
const lv_draw_rect_dsc_t * draw_dsc)
{
#if LV_DRAW_COMPLEX
if(point_cnt < 3) return;
if(points == NULL) return;
@@ -193,7 +198,9 @@ void lv_draw_polygon(const lv_point_t points[], uint16_t point_cnt, const lv_are
lv_mem_buf_release(mp);
lv_mem_buf_release(p);
#else
LV_LOG_WARN("Can't draw polygon with LV_DRAW_COMPLEX == 0");
#endif /*LV_DRAW_COMPLEX*/
}
/**********************

View File

@@ -410,7 +410,7 @@ uint32_t lv_img_buf_get_img_size(lv_coord_t w, lv_coord_t h, lv_img_cf_t cf)
}
}
#if LV_USE_IMG_TRANSFORM
#if LV_DRAW_COMPLEX
/**
* Initialize a descriptor to transform an image
* @param dsc pointer to an `lv_img_transform_dsc_t` variable whose `cfg` field is initialized
@@ -474,7 +474,7 @@ void _lv_img_buf_transform_init(lv_img_transform_dsc_t * dsc)
void _lv_img_buf_get_transformed_area(lv_area_t * res, lv_coord_t w, lv_coord_t h, int16_t angle, uint16_t zoom,
const lv_point_t * pivot)
{
#if LV_USE_IMG_TRANSFORM
#if LV_DRAW_COMPLEX
if(angle == 0 && zoom == LV_IMG_ZOOM_NONE) {
res->x1 = 0;
res->y1 = 0;
@@ -556,7 +556,8 @@ void _lv_img_buf_get_transformed_area(lv_area_t * res, lv_coord_t w, lv_coord_t
#endif
}
#if LV_USE_IMG_TRANSFORM
#if LV_DRAW_COMPLEX
/**
* Get which color and opa would come to a pixel if it were rotated
* @param dsc a descriptor initialized by `lv_img_buf_rotate_init`

View File

@@ -263,7 +263,7 @@ void lv_img_buf_free(lv_img_dsc_t * dsc);
*/
uint32_t lv_img_buf_get_img_size(lv_coord_t w, lv_coord_t h, lv_img_cf_t cf);
#if LV_USE_IMG_TRANSFORM
#if LV_DRAW_COMPLEX
/**
* Initialize a descriptor to rotate an image
* @param dsc pointer to an `lv_img_transform_dsc_t` variable whose `cfg` field is initialized

View File

@@ -153,17 +153,11 @@ void lv_mem_deinit(void)
*/
void * lv_mem_alloc(size_t size)
{
if(size == 0) {
printf("alloc: 0\n");
return &zero_mem;
}
if(size == 0) return &zero_mem;
/*Round the size up to ALIGN_MASK*/
size = (size + ALIGN_MASK) & (~ALIGN_MASK);
void * alloc = NULL;
printf("alloc: %d\n", size);
#if LV_MEM_CUSTOM == 0
alloc = alloc_core(size);
@@ -221,17 +215,13 @@ void * lv_mem_alloc(size_t size)
*/
void lv_mem_free(const void * data)
{
if(data == &zero_mem) {
printf("free: %d\n", 0);
return;
}
if(data == &zero_mem) return;
if(data == NULL) return;
#if LV_ENABLE_GC == 0
/*e points to the header*/
lv_mem_ent_t * e = (lv_mem_ent_t *)((uint8_t *)data - sizeof(lv_mem_header_t));
printf("free: %d\n", e->header.s.d_size);
# if LV_MEM_ADD_JUNK
lv_memset((void *)data, 0xbb, lv_mem_get_size(data));
# endif
@@ -793,21 +783,12 @@ static lv_mem_ent_t * ent_get_next(lv_mem_ent_t * act_e)
*/
static inline void * ent_alloc(lv_mem_ent_t * e, size_t size)
{
// static uint32_t cnt = 0;
//
//// if((cnt & 0xFFFF) == 0)
// printf("alloc: %d\n", cnt);
// cnt++;
//
/*Truncate the entry to the desired size */
ent_trunc(e, size);
e->header.s.used = 1;
/*Save the allocated data*/
return &e->first_data;
}
/**

View File

@@ -51,7 +51,7 @@ LV_EXPORT_CONST_INT(LV_IMG_ZOOM_NONE);
*/
enum {
LV_BLEND_MODE_NORMAL, /**< Simply mix according to the opacity value*/
#if LV_USE_BLEND_MODES
#if LV_DRAW_COMPLEX
LV_BLEND_MODE_ADDITIVE, /**< Add the respective color channels*/
LV_BLEND_MODE_SUBTRACTIVE,/**< Subtract the foreground from the background*/
#endif

View File

@@ -44,7 +44,7 @@ typedef struct {
/**********************
* GLOBAL PROTOTYPES
**********************/
uint32_t _lv_txt_ap_proc(const char * txt);
uint32_t _lv_txt_ap_calc_bytes_cnt(const char * txt);
void _lv_txt_ap_proc(const char * txt, char * txt_out);
/**********************

View File

@@ -477,9 +477,11 @@ static void draw_indic(lv_obj_t * obj, const lv_area_t * clip_area)
draw_indic_dsc.content_opa = content_opa;
}
#if LV_DRAW_COMPLEX
lv_draw_mask_radius_param_t mask_bg_param;
lv_draw_mask_radius_init(&mask_bg_param, &bar_coords, bg_radius, false);
int16_t mask_bg_id = lv_draw_mask_add(&mask_bg_param, NULL);
#endif
/*Draw_only the background and the pattern*/
lv_opa_t shadow_opa = draw_indic_dsc.shadow_opa;
@@ -505,11 +507,12 @@ static void draw_indic(lv_obj_t * obj, const lv_area_t * clip_area)
mask_indic_max_area.x2 = mask_indic_max_area.x1 + LV_BAR_SIZE_MIN;
}
#if LV_DRAW_COMPLEX
/*Create a mask to the current indicator area to see only this part from the whole gradient.*/
lv_draw_mask_radius_param_t mask_indic_param;
lv_draw_mask_radius_init(&mask_indic_param, &bar->indic_area, draw_indic_dsc.radius, false);
int16_t mask_indic_id = lv_draw_mask_add(&mask_indic_param, NULL);
#endif
lv_draw_rect(&mask_indic_max_area, clip_area, &draw_indic_dsc);
draw_indic_dsc.border_opa = border_opa;
draw_indic_dsc.shadow_opa = shadow_opa;
@@ -521,8 +524,10 @@ static void draw_indic(lv_obj_t * obj, const lv_area_t * clip_area)
draw_indic_dsc.content_opa = LV_OPA_TRANSP;
lv_draw_rect(&bar->indic_area, clip_area, &draw_indic_dsc);
#if LV_DRAW_COMPLEX
lv_draw_mask_remove_id(mask_indic_id);
lv_draw_mask_remove_id(mask_bg_id);
#endif
/*When not masks draw the value*/
draw_indic_dsc.content_opa = content_opa;

View File

@@ -243,7 +243,7 @@ void lv_canvas_transform(lv_obj_t * obj, lv_img_dsc_t * img, int16_t angle, uint
lv_coord_t offset_y,
int32_t pivot_x, int32_t pivot_y, bool antialias)
{
#if LV_USE_IMG_TRANSFORM
#if LV_DRAW_COMPLEX
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
LV_ASSERT_NULL(img);
@@ -329,7 +329,7 @@ void lv_canvas_transform(lv_obj_t * obj, lv_img_dsc_t * img, int16_t angle, uint
lv_obj_invalidate(obj);
#else
LV_UNUSED(canvas);
LV_UNUSED(obj);
LV_UNUSED(img);
LV_UNUSED(angle);
LV_UNUSED(zoom);
@@ -338,7 +338,7 @@ void lv_canvas_transform(lv_obj_t * obj, lv_img_dsc_t * img, int16_t angle, uint
LV_UNUSED(pivot_x);
LV_UNUSED(pivot_y);
LV_UNUSED(antialias);
LV_LOG_WARN("LV_USE_IMG_TRANSFORM is disabled in lv_conf.h");
LV_LOG_WARN("Can't transform canvas with LV_DRAW_COMPLEX == 0");
#endif
}
@@ -981,6 +981,7 @@ void lv_canvas_draw_polygon(lv_obj_t * canvas, const lv_point_t points[], uint32
void lv_canvas_draw_arc(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord_t r, int32_t start_angle,
int32_t end_angle, const lv_draw_line_dsc_t * arc_draw_dsc)
{
#if LV_DRAW_COMPLEX
LV_ASSERT_OBJ(canvas, LV_OBJX_NAME);
lv_img_dsc_t * dsc = lv_canvas_get_img(canvas);
@@ -1030,6 +1031,9 @@ void lv_canvas_draw_arc(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord_
_lv_refr_set_disp_refreshing(refr_ori);
lv_obj_invalidate(canvas);
#else
LV_LOG_WARN("Can't draw arc with LV_DRAW_COMPLEX == 0");
#endif
}
/**********************

View File

@@ -543,7 +543,7 @@ static lv_draw_res_t lv_img_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv
if(_lv_area_is_in(clip_area, &a, 0) == false) return LV_DRAW_RES_NOT_COVER;
}
#if LV_USE_BLEND_MODES
#if LV_DRAW_COMPLEX
if(lv_obj_get_style_blend_mode(obj, LV_PART_MAIN) != LV_BLEND_MODE_NORMAL) return LV_DRAW_RES_NOT_COVER;
#endif