1 /**
2  * MIT License
3  *
4  * -----------------------------------------------------------------------------
5  * Copyright (c) 2008-24 Think Silicon Single Member PC
6  * -----------------------------------------------------------------------------
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights to
11  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
12  * the Software, and to permit persons to whom the Software is furnished to do so,
13  * subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice (including the next paragraph)
16  * shall be included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
19  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
20  * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
22  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
23  * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  *
25  */
26 
27 /**
28  * @file lv_draw_nema_gfx_fill.c
29  *
30  */
31 
32 /*********************
33  *      INCLUDES
34  *********************/
35 #include "lv_draw_nema_gfx.h"
36 
37 #if LV_USE_NEMA_GFX
38 
39 /**********************
40  *   GLOBAL FUNCTIONS
41  **********************/
lv_draw_nema_gfx_line(lv_draw_unit_t * draw_unit,const lv_draw_line_dsc_t * dsc)42 void lv_draw_nema_gfx_line(lv_draw_unit_t * draw_unit, const lv_draw_line_dsc_t * dsc)
43 {
44     if(dsc->width == 0)
45         return;
46     if(dsc->opa <= (lv_opa_t)LV_OPA_MIN)
47         return;
48     if(dsc->p1.x == dsc->p2.x && dsc->p1.y == dsc->p2.y)
49         return;
50 
51     lv_draw_nema_gfx_unit_t * draw_nema_gfx_unit = (lv_draw_nema_gfx_unit_t *)draw_unit;
52 
53     lv_layer_t * layer = draw_unit->target_layer;
54     lv_area_t clip_area;
55     clip_area.x1 = LV_MIN(dsc->p1.x, dsc->p2.x) - dsc->width / 2;
56     clip_area.x2 = LV_MAX(dsc->p1.x, dsc->p2.x) + dsc->width / 2;
57     clip_area.y1 = LV_MIN(dsc->p1.y, dsc->p2.y) - dsc->width / 2;
58     clip_area.y2 = LV_MAX(dsc->p1.y, dsc->p2.y) + dsc->width / 2;
59 
60     if(!lv_area_intersect(&clip_area, &clip_area, draw_unit->clip_area))
61         return; /*Fully clipped, nothing to do*/
62 
63     lv_area_move(&clip_area, -layer->buf_area.x1, -layer->buf_area.y1);
64 
65     lv_point_t point1 = {dsc->p1.x - layer->buf_area.x1, dsc->p1.y - layer->buf_area.y1};
66     lv_point_t point2 = {dsc->p2.x - layer->buf_area.x1, dsc->p2.y - layer->buf_area.y1};
67 
68     nema_set_clip(clip_area.x1, clip_area.y1, lv_area_get_width(&clip_area), lv_area_get_height(&clip_area));
69 
70     lv_color32_t col32 = lv_color_to_32(dsc->color, dsc->opa);
71 
72     uint32_t bg_color = nema_rgba(col32.red, col32.green, col32.blue, col32.alpha);
73 
74     lv_color_format_t dst_cf = layer->draw_buf->header.cf;
75     uint32_t dst_nema_cf = lv_nemagfx_cf_to_nema(dst_cf);
76 
77     nema_bind_dst_tex((uintptr_t)NEMA_VIRT2PHYS(layer->draw_buf->data), lv_area_get_width(&(layer->buf_area)),
78                       lv_area_get_height(&(layer->buf_area)), dst_nema_cf,
79                       lv_area_get_width(&(layer->buf_area))*lv_color_format_get_size(dst_cf));
80 
81     if(col32.alpha < 255U) {
82         nema_set_blend_fill(NEMA_BL_SIMPLE);
83     }
84     else {
85         nema_set_blend_fill(NEMA_BL_SRC);
86     }
87 
88     nema_draw_line_aa(point1.x, point1.y, point2.x, point2.y, dsc->width, bg_color);
89 
90     nema_cl_submit(&(draw_nema_gfx_unit->cl));
91 
92 }
93 #endif
94