1 /**
2 * @file lv_vglite_buf.c
3 *
4 */
5
6 /**
7 * MIT License
8 *
9 * Copyright 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_buf.h"
35
36 #if LV_USE_GPU_NXP_VG_LITE
37
38 /*********************
39 * DEFINES
40 *********************/
41
42 #if LV_COLOR_DEPTH == 16
43 #define VG_LITE_PX_FMT VG_LITE_RGB565
44 #elif LV_COLOR_DEPTH == 32
45 #define VG_LITE_PX_FMT VG_LITE_BGRA8888
46 #else
47 #error Only 16bit and 32bit color depth are supported. Set LV_COLOR_DEPTH to 16 or 32.
48 #endif
49
50 /**********************
51 * TYPEDEFS
52 **********************/
53
54 /**********************
55 * STATIC PROTOTYPES
56 **********************/
57
58 static inline void lv_vglite_set_dest_buf(const lv_color_t * buf, const lv_area_t * area, lv_coord_t stride);
59 static inline void lv_vglite_set_buf_ptr(vg_lite_buffer_t * vgbuf, const lv_color_t * buf);
60
61 /**********************
62 * STATIC VARIABLES
63 **********************/
64
65 static vg_lite_buffer_t dest_vgbuf;
66 static vg_lite_buffer_t src_vgbuf;
67
68 /**********************
69 * MACROS
70 **********************/
71
72 /**********************
73 * GLOBAL FUNCTIONS
74 **********************/
75
lv_gpu_nxp_vglite_init_buf(const lv_color_t * buf,const lv_area_t * area,lv_coord_t stride)76 void lv_gpu_nxp_vglite_init_buf(const lv_color_t * buf, const lv_area_t * area, lv_coord_t stride)
77 {
78 lv_vglite_set_dest_buf(buf, area, stride);
79 }
80
lv_vglite_get_dest_buf(void)81 vg_lite_buffer_t * lv_vglite_get_dest_buf(void)
82 {
83 return &dest_vgbuf;
84 }
85
lv_vglite_get_src_buf(void)86 vg_lite_buffer_t * lv_vglite_get_src_buf(void)
87 {
88 return &src_vgbuf;
89 }
90
lv_vglite_set_dest_buf_ptr(const lv_color_t * buf)91 void lv_vglite_set_dest_buf_ptr(const lv_color_t * buf)
92 {
93 lv_vglite_set_buf_ptr(&dest_vgbuf, buf);
94 }
95
lv_vglite_set_src_buf_ptr(const lv_color_t * buf)96 void lv_vglite_set_src_buf_ptr(const lv_color_t * buf)
97 {
98 lv_vglite_set_buf_ptr(&src_vgbuf, buf);
99 }
100
lv_vglite_set_src_buf(const lv_color_t * buf,const lv_area_t * area,lv_coord_t stride)101 void lv_vglite_set_src_buf(const lv_color_t * buf, const lv_area_t * area, lv_coord_t stride)
102 {
103 if(src_vgbuf.memory != (void *)buf)
104 lv_vglite_set_buf(&src_vgbuf, buf, area, stride);
105 }
106
lv_vglite_set_buf(vg_lite_buffer_t * vgbuf,const lv_color_t * buf,const lv_area_t * area,lv_coord_t stride)107 void lv_vglite_set_buf(vg_lite_buffer_t * vgbuf, const lv_color_t * buf,
108 const lv_area_t * area, lv_coord_t stride)
109 {
110 vgbuf->format = VG_LITE_PX_FMT;
111 vgbuf->tiled = VG_LITE_LINEAR;
112 vgbuf->image_mode = VG_LITE_NORMAL_IMAGE_MODE;
113 vgbuf->transparency_mode = VG_LITE_IMAGE_OPAQUE;
114
115 vgbuf->width = (int32_t)lv_area_get_width(area);
116 vgbuf->height = (int32_t)lv_area_get_height(area);
117 vgbuf->stride = (int32_t)(stride) * sizeof(lv_color_t);
118
119 lv_memset_00(&vgbuf->yuv, sizeof(vgbuf->yuv));
120
121 vgbuf->memory = (void *)buf;
122 vgbuf->address = (uint32_t)vgbuf->memory;
123 vgbuf->handle = NULL;
124 }
125
126 /**********************
127 * STATIC FUNCTIONS
128 **********************/
129
lv_vglite_set_dest_buf(const lv_color_t * buf,const lv_area_t * area,lv_coord_t stride)130 static inline void lv_vglite_set_dest_buf(const lv_color_t * buf, const lv_area_t * area, lv_coord_t stride)
131 {
132 lv_vglite_set_buf(&dest_vgbuf, buf, area, stride);
133 }
134
lv_vglite_set_buf_ptr(vg_lite_buffer_t * vgbuf,const lv_color_t * buf)135 static inline void lv_vglite_set_buf_ptr(vg_lite_buffer_t * vgbuf, const lv_color_t * buf)
136 {
137 vgbuf->memory = (void *)buf;
138 vgbuf->address = (uint32_t)vgbuf->memory;
139 }
140
141 #endif /*LV_USE_GPU_NXP_VG_LITE*/
142