1 /**
2 * @file lv_vglite_utils.c
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 /*********************
31 * INCLUDES
32 *********************/
33
34 #include "lv_vglite_utils.h"
35
36 #if LV_USE_GPU_NXP_VG_LITE
37 #include "../../../core/lv_refr.h"
38
39 /*********************
40 * DEFINES
41 *********************/
42
43 /**********************
44 * TYPEDEFS
45 **********************/
46
47 /**********************
48 * STATIC PROTOTYPES
49 **********************/
50
51 /**
52 * Clean and invalidate cache.
53 */
54 static inline void invalidate_cache(void);
55
56 /**********************
57 * STATIC VARIABLES
58 **********************/
59
60 /**********************
61 * MACROS
62 **********************/
63
64 /**********************
65 * GLOBAL FUNCTIONS
66 **********************/
67
lv_vglite_run(void)68 lv_res_t lv_vglite_run(void)
69 {
70 invalidate_cache();
71
72 VG_LITE_ERR_RETURN_INV(vg_lite_flush(), "Flush failed.");
73
74 return LV_RES_OK;
75 }
76
lv_vglite_premult_and_swizzle(vg_lite_color_t * vg_col32,lv_color32_t lv_col32,lv_opa_t opa,vg_lite_buffer_format_t vg_col_format)77 lv_res_t lv_vglite_premult_and_swizzle(vg_lite_color_t * vg_col32, lv_color32_t lv_col32, lv_opa_t opa,
78 vg_lite_buffer_format_t vg_col_format)
79 {
80
81 lv_color32_t lv_col32_premul = lv_col32;
82 if(opa <= (lv_opa_t)LV_OPA_MAX) {
83 /* Only pre-multiply color if hardware pre-multiplication is not present */
84 if(!vg_lite_query_feature(gcFEATURE_BIT_VG_PE_PREMULTIPLY)) {
85 lv_col32_premul.ch.red = (uint8_t)(((uint16_t)lv_col32.ch.red * opa) >> 8);
86 lv_col32_premul.ch.green = (uint8_t)(((uint16_t)lv_col32.ch.green * opa) >> 8);
87 lv_col32_premul.ch.blue = (uint8_t)(((uint16_t)lv_col32.ch.blue * opa) >> 8);
88 }
89 lv_col32_premul.ch.alpha = opa;
90 }
91
92 switch(vg_col_format) {
93 case VG_LITE_BGRA8888:
94 *vg_col32 = lv_col32_premul.full;
95 break;
96 case VG_LITE_RGBA8888:
97 *vg_col32 = ((uint32_t)lv_col32_premul.ch.red << 24) | ((uint32_t)lv_col32_premul.ch.green << 16) |
98 ((uint32_t)lv_col32_premul.ch.blue << 8) | (uint32_t)lv_col32_premul.ch.alpha;
99 break;
100 case VG_LITE_ABGR8888:
101 *vg_col32 = ((uint32_t)lv_col32_premul.ch.alpha << 24) | ((uint32_t)lv_col32_premul.ch.blue << 16) |
102 ((uint32_t)lv_col32_premul.ch.green << 8) | (uint32_t)lv_col32_premul.ch.red;
103 break;
104 case VG_LITE_ARGB8888:
105 *vg_col32 = ((uint32_t)lv_col32_premul.ch.alpha << 24) | ((uint32_t)lv_col32_premul.ch.red << 16) |
106 ((uint32_t)lv_col32_premul.ch.green << 8) | (uint32_t)lv_col32_premul.ch.blue;
107 break;
108 default:
109 return LV_RES_INV;
110 }
111
112 return LV_RES_OK;
113 }
114
lv_vglite_get_blend_mode(lv_blend_mode_t lv_blend_mode)115 vg_lite_blend_t lv_vglite_get_blend_mode(lv_blend_mode_t lv_blend_mode)
116 {
117 vg_lite_blend_t vg_blend_mode;
118 switch(lv_blend_mode) {
119 case LV_BLEND_MODE_ADDITIVE:
120 vg_blend_mode = VG_LITE_BLEND_ADDITIVE;
121 break;
122 case LV_BLEND_MODE_SUBTRACTIVE:
123 vg_blend_mode = VG_LITE_BLEND_SUBTRACT;
124 break;
125 case LV_BLEND_MODE_MULTIPLY:
126 vg_blend_mode = VG_LITE_BLEND_MULTIPLY;
127 break;
128 case LV_BLEND_MODE_REPLACE:
129 vg_blend_mode = VG_LITE_BLEND_NONE;
130 break;
131 default:
132 vg_blend_mode = VG_LITE_BLEND_SRC_OVER;
133 break;
134 }
135 return vg_blend_mode;
136 }
137
138 /**********************
139 * STATIC FUNCTIONS
140 **********************/
141
invalidate_cache(void)142 static inline void invalidate_cache(void)
143 {
144 lv_disp_t * disp = _lv_refr_get_disp_refreshing();
145 if(disp->driver->clean_dcache_cb)
146 disp->driver->clean_dcache_cb(disp->driver);
147 }
148
149 #endif /*LV_USE_GPU_NXP_VG_LITE*/
150