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 
62 /* The optimal Bezier control point offset for radial unit
63  * see: https://spencermortensen.com/articles/bezier-circle/
64  **/
65 #define BEZIER_OPTIM_CIRCLE 0.551915024494f
66 
67 /* Draw lines for control points of Bezier curves */
68 #define BEZIER_DBG_CONTROL_POINTS   0
69 
70 /**********************
71  *      TYPEDEFS
72  **********************/
73 
74 /**********************
75  * GLOBAL PROTOTYPES
76  **********************/
77 
78 /**
79  * Premultiplies and swizzles given LVGL 32bit color to obtain vglite color.
80  *
81  * @param[in/out] vg_col32 The obtained vglite color
82  * @param[in] lv_col32 The initial LVGL 32bit color
83  * @param[in] opa The opacity to premultiply with
84  * @param[in] vg_col_format The format of the resulting vglite color
85  *
86  * @retval LV_RES_OK Operation completed
87  * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_VG_LITE_LOG_ERRORS)
88  */
89 lv_res_t lv_vglite_premult_and_swizzle(vg_lite_color_t * vg_col32, lv_color32_t lv_col32, lv_opa_t opa,
90                                        vg_lite_buffer_format_t vg_col_format);
91 
92 /**
93  * Get vglite blend mode.
94  *
95  * @param[in] lv_blend_mode The LVGL blend mode
96  *
97  * @retval The vglite blend mode
98  */
99 vg_lite_blend_t lv_vglite_get_blend_mode(lv_blend_mode_t lv_blend_mode);
100 
101 /**
102  * Clear cache and flush command to VG-Lite.
103  *
104  * @retval LV_RES_OK Run completed
105  * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_VG_LITE_LOG_ERRORS)
106  */
107 lv_res_t lv_vglite_run(void);
108 
109 /**********************
110  *      MACROS
111  **********************/
112 
113 #define VG_LITE_COND_STOP(cond, txt)          \
114     do {                                      \
115         if (cond) {                           \
116             LV_LOG_ERROR("%s. STOP!", txt);   \
117             for ( ; ; );                      \
118         }                                     \
119     } while(0)
120 
121 #if LV_GPU_NXP_VG_LITE_LOG_ERRORS
122 #define VG_LITE_ERR_RETURN_INV(err, fmt, ...) \
123     do {                                      \
124         if(err != VG_LITE_SUCCESS) {          \
125             LV_LOG_ERROR(fmt" (err = %d)",    \
126                          err, ##__VA_ARGS__); \
127             return LV_RES_INV;                \
128         }                                     \
129     } while (0)
130 #else
131 #define VG_LITE_ERR_RETURN_INV(err, fmt, ...) \
132     do {                                      \
133         if(err != VG_LITE_SUCCESS) {          \
134             return LV_RES_INV;                \
135         }                                     \
136     }while(0)
137 #endif /*LV_GPU_NXP_VG_LITE_LOG_ERRORS*/
138 
139 #if LV_GPU_NXP_VG_LITE_LOG_TRACES
140 #define VG_LITE_LOG_TRACE(fmt, ...)           \
141     do {                                      \
142         LV_LOG(fmt, ##__VA_ARGS__);     \
143     } while (0)
144 
145 #define VG_LITE_RETURN_INV(fmt, ...)          \
146     do {                                      \
147         LV_LOG_ERROR(fmt, ##__VA_ARGS__);     \
148         return LV_RES_INV;                    \
149     } while (0)
150 #else
151 #define VG_LITE_LOG_TRACE(fmt, ...)           \
152     do {                                      \
153     } while (0)
154 #define VG_LITE_RETURN_INV(fmt, ...)          \
155     do {                                      \
156         return LV_RES_INV;                    \
157     }while(0)
158 #endif /*LV_GPU_NXP_VG_LITE_LOG_TRACES*/
159 
160 #endif /*LV_USE_GPU_NXP_VG_LITE*/
161 
162 #ifdef __cplusplus
163 } /*extern "C"*/
164 #endif
165 
166 #endif /*LV_VGLITE_UTILS_H*/
167