1 /**
2 * @file lv_vglite_utils.h
3 *
4 */
5
6 /**
7 * MIT License
8 *
9 * Copyright 2022, 2023 NXP
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights to
14 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15 * the Software, and to permit persons to whom the Software is furnished to do so,
16 * subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice (including the next paragraph)
19 * shall be included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 *
28 */
29
30 #ifndef LV_VGLITE_UTILS_H
31 #define LV_VGLITE_UTILS_H
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 /*********************
38 * INCLUDES
39 *********************/
40 #include "../../../lv_conf_internal.h"
41
42 #if LV_USE_GPU_NXP_VG_LITE
43 #include "vg_lite.h"
44 #include "../../sw/lv_draw_sw.h"
45 #include "../../../misc/lv_log.h"
46
47 /*********************
48 * DEFINES
49 *********************/
50
51 #ifndef LV_GPU_NXP_VG_LITE_LOG_ERRORS
52 /** Enable logging of VG-Lite errors (\see LV_LOG_ERROR)*/
53 #define LV_GPU_NXP_VG_LITE_LOG_ERRORS 1
54 #endif
55
56 #ifndef LV_GPU_NXP_VG_LITE_LOG_TRACES
57 /** Enable logging of VG-Lite traces (\see LV_LOG_ERROR)*/
58 #define LV_GPU_NXP_VG_LITE_LOG_TRACES 0
59 #endif
60
61 /* The optimal Bezier control point offset for radial unit
62 * see: https://spencermortensen.com/articles/bezier-circle/
63 **/
64 #define BEZIER_OPTIM_CIRCLE 0.551915024494f
65
66 /* Draw lines for control points of Bezier curves */
67 #define BEZIER_DBG_CONTROL_POINTS 0
68
69 /**********************
70 * TYPEDEFS
71 **********************/
72
73 /**********************
74 * STATIC PROTOTYPES
75 **********************/
76
77 /**
78 * Enable scissor and set the clipping box.
79 *
80 * @param[in] clip_area Clip area with relative coordinates of destination buffer
81 */
82 static inline void lv_vglite_set_scissor(const lv_area_t * clip_area);
83
84 /**
85 * Disable scissor.
86 */
87 static inline void lv_vglite_disable_scissor(void);
88
89 /**********************
90 * GLOBAL PROTOTYPES
91 **********************/
92
93 /**
94 * Premultiplies and swizzles given LVGL 32bit color to obtain vglite color.
95 *
96 * @param[in/out] vg_col32 The obtained vglite color
97 * @param[in] lv_col32 The initial LVGL 32bit color
98 * @param[in] opa The opacity to premultiply with
99 * @param[in] vg_col_format The format of the resulting vglite color
100 *
101 * @retval LV_RES_OK Operation completed
102 * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_VG_LITE_LOG_ERRORS)
103 */
104 lv_res_t lv_vglite_premult_and_swizzle(vg_lite_color_t * vg_col32, lv_color32_t lv_col32, lv_opa_t opa,
105 vg_lite_buffer_format_t vg_col_format);
106
107 /**
108 * Get vglite blend mode.
109 *
110 * @param[in] lv_blend_mode The LVGL blend mode
111 *
112 * @retval The vglite blend mode
113 */
114 vg_lite_blend_t lv_vglite_get_blend_mode(lv_blend_mode_t lv_blend_mode);
115
116 /**
117 * Clear cache and flush command to VG-Lite.
118 *
119 * @retval LV_RES_OK Run completed
120 * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_VG_LITE_LOG_ERRORS)
121 */
122 lv_res_t lv_vglite_run(void);
123
124 /**********************
125 * MACROS
126 **********************/
127
128 #define VG_LITE_COND_STOP(cond, txt) \
129 do { \
130 if (cond) { \
131 LV_LOG_ERROR("%s. STOP!", txt); \
132 for ( ; ; ); \
133 } \
134 } while(0)
135
136 #if LV_GPU_NXP_VG_LITE_LOG_ERRORS
137 #define VG_LITE_ERR_RETURN_INV(err, fmt, ...) \
138 do { \
139 if(err != VG_LITE_SUCCESS) { \
140 LV_LOG_ERROR(fmt" (err = %d)", \
141 err, ##__VA_ARGS__); \
142 return LV_RES_INV; \
143 } \
144 } while (0)
145 #else
146 #define VG_LITE_ERR_RETURN_INV(err, fmt, ...) \
147 do { \
148 if(err != VG_LITE_SUCCESS) { \
149 return LV_RES_INV; \
150 } \
151 }while(0)
152 #endif /*LV_GPU_NXP_VG_LITE_LOG_ERRORS*/
153
154 #if LV_GPU_NXP_VG_LITE_LOG_TRACES
155 #define VG_LITE_LOG_TRACE(fmt, ...) \
156 do { \
157 LV_LOG(fmt, ##__VA_ARGS__); \
158 } while (0)
159
160 #define VG_LITE_RETURN_INV(fmt, ...) \
161 do { \
162 LV_LOG_ERROR(fmt, ##__VA_ARGS__); \
163 return LV_RES_INV; \
164 } while (0)
165 #else
166 #define VG_LITE_LOG_TRACE(fmt, ...) \
167 do { \
168 } while (0)
169 #define VG_LITE_RETURN_INV(fmt, ...) \
170 do { \
171 return LV_RES_INV; \
172 }while(0)
173 #endif /*LV_GPU_NXP_VG_LITE_LOG_TRACES*/
174
175 /**********************
176 * STATIC FUNCTIONS
177 **********************/
178
lv_vglite_set_scissor(const lv_area_t * clip_area)179 static inline void lv_vglite_set_scissor(const lv_area_t * clip_area)
180 {
181 vg_lite_enable_scissor();
182 vg_lite_set_scissor((int32_t)clip_area->x1, (int32_t)clip_area->y1,
183 (int32_t)lv_area_get_width(clip_area),
184 (int32_t)lv_area_get_height(clip_area));
185 }
186
lv_vglite_disable_scissor(void)187 static inline void lv_vglite_disable_scissor(void)
188 {
189 vg_lite_disable_scissor();
190 }
191
192 #endif /*LV_USE_GPU_NXP_VG_LITE*/
193
194 #ifdef __cplusplus
195 } /*extern "C"*/
196 #endif
197
198 #endif /*LV_VGLITE_UTILS_H*/
199