1 /**
2  * @file lv_draw_vg_lite_fill.c
3  *
4  */
5 
6 /*********************
7  *      INCLUDES
8  *********************/
9 
10 #include "../../misc/lv_area_private.h"
11 #include "lv_draw_vg_lite.h"
12 
13 #if LV_USE_DRAW_VG_LITE
14 
15 #include "lv_draw_vg_lite_type.h"
16 #include "lv_vg_lite_path.h"
17 #include "lv_vg_lite_utils.h"
18 #include "lv_vg_lite_grad.h"
19 
20 /*********************
21  *      DEFINES
22  *********************/
23 
24 #if LV_GRADIENT_MAX_STOPS > VLC_MAX_GRADIENT_STOPS
25     #error "LV_GRADIENT_MAX_STOPS must be equal or less than VLC_MAX_GRADIENT_STOPS"
26 #endif
27 
28 /**********************
29  *      TYPEDEFS
30  **********************/
31 
32 /**********************
33  *  STATIC PROTOTYPES
34  **********************/
35 
36 /**********************
37  *  STATIC VARIABLES
38  **********************/
39 
40 /**********************
41  *      MACROS
42  **********************/
43 
44 /**********************
45  *   GLOBAL FUNCTIONS
46  **********************/
47 
lv_draw_vg_lite_fill(lv_draw_unit_t * draw_unit,const lv_draw_fill_dsc_t * dsc,const lv_area_t * coords)48 void lv_draw_vg_lite_fill(lv_draw_unit_t * draw_unit, const lv_draw_fill_dsc_t * dsc, const lv_area_t * coords)
49 {
50     lv_draw_vg_lite_unit_t * u = (lv_draw_vg_lite_unit_t *)draw_unit;
51 
52     lv_area_t clip_area;
53     if(!lv_area_intersect(&clip_area, coords, draw_unit->clip_area)) {
54         /*Fully clipped, nothing to do*/
55         return;
56     }
57 
58     LV_PROFILER_DRAW_BEGIN;
59 
60     vg_lite_matrix_t matrix = u->global_matrix;
61 
62     lv_vg_lite_path_t * path = lv_vg_lite_path_get(u, VG_LITE_FP32);
63     lv_vg_lite_path_set_quality(path, dsc->radius == 0 ? VG_LITE_LOW : VG_LITE_HIGH);
64     lv_vg_lite_path_set_bounding_box_area(path, &clip_area);
65     lv_vg_lite_path_append_rect(path,
66                                 coords->x1, coords->y1,
67                                 lv_area_get_width(coords), lv_area_get_height(coords),
68                                 dsc->radius);
69     lv_vg_lite_path_end(path);
70 
71     vg_lite_path_t * vg_lite_path = lv_vg_lite_path_get_path(path);
72 
73     LV_VG_LITE_ASSERT_DEST_BUFFER(&u->target_buffer);
74     LV_VG_LITE_ASSERT_PATH(vg_lite_path);
75     LV_VG_LITE_ASSERT_MATRIX(&matrix);
76 
77     if(dsc->grad.dir != LV_GRAD_DIR_NONE) {
78 #if LV_USE_VECTOR_GRAPHIC
79         lv_vg_lite_draw_grad_helper(
80             u,
81             &u->target_buffer,
82             vg_lite_path,
83             coords,
84             &dsc->grad,
85             &matrix,
86             VG_LITE_FILL_EVEN_ODD,
87             VG_LITE_BLEND_SRC_OVER);
88 #else
89         LV_LOG_WARN("Gradient fill is not supported without VECTOR_GRAPHIC");
90 #endif
91     }
92     else { /* normal fill */
93         vg_lite_color_t color = lv_vg_lite_color(dsc->color, dsc->opa, true);
94         LV_PROFILER_DRAW_BEGIN_TAG("vg_lite_draw");
95         LV_VG_LITE_CHECK_ERROR(vg_lite_draw(
96                                    &u->target_buffer,
97                                    vg_lite_path,
98                                    VG_LITE_FILL_EVEN_ODD,
99                                    &matrix,
100                                    VG_LITE_BLEND_SRC_OVER,
101                                    color));
102         LV_PROFILER_DRAW_END_TAG("vg_lite_draw");
103     }
104 
105     lv_vg_lite_path_drop(u, path);
106 
107     LV_PROFILER_DRAW_END;
108 }
109 
110 /**********************
111  *   STATIC FUNCTIONS
112  **********************/
113 
114 #endif /*LV_USE_DRAW_VG_LITE*/
115