1 /**
2  * @file lv_draw_dma2d_fill.c
3  *
4  */
5 
6 /*********************
7  *      INCLUDES
8  *********************/
9 
10 #include "lv_draw_dma2d_private.h"
11 #if LV_USE_DRAW_DMA2D
12 
13 /*********************
14  *      DEFINES
15  *********************/
16 
17 /**********************
18  *      TYPEDEFS
19  **********************/
20 
21 /**********************
22  *  STATIC PROTOTYPES
23  **********************/
24 
25 /**********************
26  *  STATIC VARIABLES
27  **********************/
28 
29 /**********************
30  *      MACROS
31  **********************/
32 
33 /**********************
34  *   GLOBAL FUNCTIONS
35  **********************/
36 
lv_draw_dma2d_opaque_fill(lv_draw_dma2d_unit_t * u,void * first_pixel,int32_t w,int32_t h,int32_t stride)37 void lv_draw_dma2d_opaque_fill(lv_draw_dma2d_unit_t * u, void * first_pixel, int32_t w, int32_t h, int32_t stride)
38 {
39     lv_draw_fill_dsc_t * dsc = u->task_act->draw_dsc;
40     lv_color_format_t cf = dsc->base.layer->color_format;
41 
42     lv_draw_dma2d_output_cf_t output_cf = lv_draw_dma2d_cf_to_dma2d_output_cf(cf);
43     uint32_t cf_size = LV_COLOR_FORMAT_GET_SIZE(cf);
44     uint32_t reg_to_mem_color = lv_draw_dma2d_color_to_dma2d_color(output_cf, dsc->color);
45 
46 #if LV_DRAW_DMA2D_CACHE
47     lv_draw_dma2d_cache_area_t cache_area = {
48         .first_byte = first_pixel,
49         .width_bytes = w * cf_size,
50         .height = h,
51         .stride = stride
52     };
53     lv_memcpy(&u->writing_area, &cache_area, sizeof(lv_draw_dma2d_cache_area_t));
54 #endif
55 
56     lv_draw_dma2d_configuration_t conf = {
57         .mode = LV_DRAW_DMA2D_MODE_REGISTER_TO_MEMORY,
58         .w = w,
59         .h = h,
60 
61         .output_address = first_pixel,
62         .output_offset = (stride / cf_size) - w,
63         .output_cf = output_cf,
64 
65         .reg_to_mem_mode_color = reg_to_mem_color
66     };
67     lv_draw_dma2d_configure_and_start_transfer(&conf);
68 }
69 
lv_draw_dma2d_fill(lv_draw_dma2d_unit_t * u,void * first_pixel,int32_t w,int32_t h,int32_t stride)70 void lv_draw_dma2d_fill(lv_draw_dma2d_unit_t * u, void * first_pixel, int32_t w, int32_t h, int32_t stride)
71 {
72     lv_draw_fill_dsc_t * dsc = u->task_act->draw_dsc;
73     lv_color_t color = dsc->color;
74     lv_color_format_t cf = dsc->base.layer->color_format;
75     lv_opa_t opa = dsc->opa;
76 
77     lv_draw_dma2d_output_cf_t output_cf = lv_draw_dma2d_cf_to_dma2d_output_cf(cf);
78     uint32_t cf_size = LV_COLOR_FORMAT_GET_SIZE(cf);
79 
80 #if LV_DRAW_DMA2D_CACHE
81     lv_draw_dma2d_cache_area_t cache_area = {
82         .first_byte = first_pixel,
83         .width_bytes = w * cf_size,
84         .height = h,
85         .stride = stride
86     };
87     lv_memcpy(&u->writing_area, &cache_area, sizeof(lv_draw_dma2d_cache_area_t));
88 
89     /* make sure the background area DMA2D is blending is up-to-date in main memory */
90     lv_draw_dma2d_clean_cache(&cache_area);
91 #endif
92 
93     uint32_t output_offset = (stride / cf_size) - w;
94     lv_draw_dma2d_configuration_t conf = {
95         .mode = LV_DRAW_DMA2D_MODE_MEMORY_TO_MEMORY_WITH_BLENDING_AND_FIXED_COLOR_FG,
96         .w = w,
97         .h = h,
98 
99         .output_address = first_pixel,
100         .output_offset = output_offset,
101         .output_cf = output_cf,
102 
103         .fg_color = lv_color_to_u32(color),
104         .fg_alpha_mode = LV_DRAW_DMA2D_ALPHA_MODE_REPLACE_ALPHA_CHANNEL,
105         .fg_alpha = opa,
106 
107         .bg_address = first_pixel,
108         .bg_offset = output_offset,
109         .bg_cf = (lv_draw_dma2d_fgbg_cf_t) output_cf
110     };
111 
112     /* Background alpha channel should be treated as 0xFF if the cf is XRGB */
113     if(cf == LV_COLOR_FORMAT_XRGB8888) {
114         conf.bg_alpha_mode = LV_DRAW_DMA2D_ALPHA_MODE_REPLACE_ALPHA_CHANNEL;
115         conf.bg_alpha = 0xff;
116     }
117 
118     lv_draw_dma2d_configure_and_start_transfer(&conf);
119 }
120 
121 /**********************
122  *   STATIC FUNCTIONS
123  **********************/
124 
125 #endif /*LV_USE_DRAW_DMA2D*/
126