1 /**
2  * @file lv_vglite_utils.h
3  *
4  */
5 
6 /**
7  * Copyright 2022-2024 NXP
8  *
9  * SPDX-License-Identifier: MIT
10  */
11 
12 #ifndef LV_VGLITE_UTILS_H
13 #define LV_VGLITE_UTILS_H
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 /*********************
20  *      INCLUDES
21  *********************/
22 #include "../../../lv_conf_internal.h"
23 
24 #if LV_USE_DRAW_VGLITE
25 #include "../../lv_draw.h"
26 
27 #include "vg_lite.h"
28 #include "vg_lite_options.h"
29 
30 /*********************
31  *      DEFINES
32  *********************/
33 
34 #define ENUM_TO_STRING(e) \
35     case (e):             \
36     return #e
37 
38 #if LV_USE_VGLITE_ASSERT
39 #define VGLITE_ASSERT(expr) LV_ASSERT(expr)
40 #else
41 #define VGLITE_ASSERT(expr)
42 #endif
43 
44 #define VGLITE_ASSERT_MSG(expr, msg)                                 \
45     do {                                                             \
46         if(!(expr)) {                                                \
47             LV_LOG_ERROR(msg);                                       \
48             VGLITE_ASSERT(false);                                    \
49         }                                                            \
50     } while(0)
51 
52 #define VGLITE_CHECK_ERROR(function)                                 \
53     do {                                                             \
54         vg_lite_error_t error = function;                            \
55         if(error != VG_LITE_SUCCESS) {                               \
56             LV_LOG_ERROR("Execute '" #function "' error(%d): %s",    \
57                          (int)error, vglite_error_to_string(error)); \
58             VGLITE_ASSERT(false);                                    \
59         }                                                            \
60     } while (0)
61 
62 /**********************
63  *      TYPEDEFS
64  **********************/
65 
66 /**********************
67  *  STATIC PROTOTYPES
68  **********************/
69 
70 /**
71  * Set the clipping box.
72  *
73  * @param[in] clip_area Clip area with relative coordinates of destination buffer
74  *
75  */
76 static inline void vglite_set_scissor(const lv_area_t * clip_area);
77 
78 /**********************
79  * GLOBAL PROTOTYPES
80  **********************/
81 
82 const char * vglite_error_to_string(vg_lite_error_t error);
83 
84 #if LV_USE_VGLITE_DRAW_ASYNC
85 /**
86  * Get VG-Lite command buffer flushed status.
87  *
88  */
89 bool vglite_cmd_buf_is_flushed(void);
90 #endif
91 
92 /**
93  * Flush command to VG-Lite.
94  *
95  */
96 void vglite_run(void);
97 
98 /**
99  * Wait for VG-Lite finish.
100  *
101  */
102 #if LV_USE_VGLITE_DRAW_ASYNC
103 void vglite_wait_for_finish(void);
104 #endif
105 
106 /**
107  * Get vglite color. Premultiplies (if not hw already) and swizzles the given
108  * LVGL 32bit color to obtain vglite color.
109  *
110  * @param[in] lv_col32 The initial LVGL 32bit color
111  * @param[in] gradient True for gradient color
112  *
113  * @retval The vglite 32-bit color value:
114  *
115  */
116 vg_lite_color_t vglite_get_color(lv_color32_t lv_col32, bool gradient);
117 
118 /**
119  * Get vglite blend mode.
120  *
121  * @param[in] lv_blend_mode The LVGL blend mode
122  *
123  * @retval The vglite blend mode
124  *
125  */
126 vg_lite_blend_t vglite_get_blend_mode(lv_blend_mode_t lv_blend_mode);
127 
128 /**
129  * Get vglite buffer format.
130  *
131  * @param[in] cf Color format
132  *
133  * @retval The vglite buffer format
134  *
135  */
136 vg_lite_buffer_format_t vglite_get_buf_format(lv_color_format_t cf);
137 
138 /**
139  * Get vglite stride alignment.
140  *
141  * @param[in] cf Color format
142  *
143  * @retval Alignment requirement in bytes
144  *
145  */
146 uint8_t vglite_get_stride_alignment(lv_color_format_t cf);
147 
148 /**
149  * Check source start address and stride alignment.
150  *
151  * @param[in] buf Buffer address
152  * @param[in] stride Stride of buffer in bytes
153  * @param[in] cf Color format - to calculate the expected alignment
154  *
155  * @retval true Alignment OK
156  *
157  */
158 bool vglite_src_buf_aligned(const void * buf, uint32_t stride, lv_color_format_t cf);
159 
160 /**********************
161  *      MACROS
162  **********************/
163 
164 /**********************
165  *   STATIC FUNCTIONS
166  **********************/
167 
vglite_set_scissor(const lv_area_t * clip_area)168 static inline void vglite_set_scissor(const lv_area_t * clip_area)
169 {
170     vg_lite_set_scissor(clip_area->x1, clip_area->y1, clip_area->x2 + 1, clip_area->y2 + 1);
171 }
172 
173 #endif /*LV_USE_DRAW_VGLITE*/
174 
175 #ifdef __cplusplus
176 } /*extern "C"*/
177 #endif
178 
179 #endif /*LV_VGLITE_UTILS_H*/
180