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 static inline void lv_vglite_set_buf(vg_lite_buffer_t * vgbuf, const lv_color_t * buf,
61 const lv_area_t * area, lv_coord_t stride);
62
63 /**********************
64 * STATIC VARIABLES
65 **********************/
66
67 static vg_lite_buffer_t dest_vgbuf;
68 static vg_lite_buffer_t src_vgbuf;
69
70 /**********************
71 * MACROS
72 **********************/
73
74 /**********************
75 * GLOBAL FUNCTIONS
76 **********************/
77
lv_gpu_nxp_vglite_init_buf(const lv_color_t * buf,const lv_area_t * area,lv_coord_t stride)78 void lv_gpu_nxp_vglite_init_buf(const lv_color_t * buf, const lv_area_t * area, lv_coord_t stride)
79 {
80 lv_vglite_set_dest_buf(buf, area, stride);
81 }
82
lv_vglite_get_dest_buf(void)83 vg_lite_buffer_t * lv_vglite_get_dest_buf(void)
84 {
85 return &dest_vgbuf;
86 }
87
lv_vglite_get_src_buf(void)88 vg_lite_buffer_t * lv_vglite_get_src_buf(void)
89 {
90 return &src_vgbuf;
91 }
92
lv_vglite_set_dest_buf_ptr(const lv_color_t * buf)93 void lv_vglite_set_dest_buf_ptr(const lv_color_t * buf)
94 {
95 lv_vglite_set_buf_ptr(&dest_vgbuf, buf);
96 }
97
lv_vglite_set_src_buf_ptr(const lv_color_t * buf)98 void lv_vglite_set_src_buf_ptr(const lv_color_t * buf)
99 {
100 lv_vglite_set_buf_ptr(&src_vgbuf, buf);
101 }
102
lv_vglite_set_src_buf(const lv_color_t * buf,const lv_area_t * area,lv_coord_t stride)103 void lv_vglite_set_src_buf(const lv_color_t * buf, const lv_area_t * area, lv_coord_t stride)
104 {
105 if(src_vgbuf.memory != (void *)buf)
106 lv_vglite_set_buf(&src_vgbuf, buf, area, stride);
107 }
108
109 /**********************
110 * STATIC FUNCTIONS
111 **********************/
112
lv_vglite_set_dest_buf(const lv_color_t * buf,const lv_area_t * area,lv_coord_t stride)113 static inline void lv_vglite_set_dest_buf(const lv_color_t * buf, const lv_area_t * area, lv_coord_t stride)
114 {
115 lv_vglite_set_buf(&dest_vgbuf, buf, area, stride);
116 }
117
lv_vglite_set_buf_ptr(vg_lite_buffer_t * vgbuf,const lv_color_t * buf)118 static inline void lv_vglite_set_buf_ptr(vg_lite_buffer_t * vgbuf, const lv_color_t * buf)
119 {
120 vgbuf->memory = (void *)buf;
121 vgbuf->address = (uint32_t)vgbuf->memory;
122 }
123
lv_vglite_set_buf(vg_lite_buffer_t * vgbuf,const lv_color_t * buf,const lv_area_t * area,lv_coord_t stride)124 static inline void lv_vglite_set_buf(vg_lite_buffer_t * vgbuf, const lv_color_t * buf,
125 const lv_area_t * area, lv_coord_t stride)
126 {
127 vgbuf->format = VG_LITE_PX_FMT;
128 vgbuf->tiled = VG_LITE_LINEAR;
129 vgbuf->image_mode = VG_LITE_NORMAL_IMAGE_MODE;
130 vgbuf->transparency_mode = VG_LITE_IMAGE_OPAQUE;
131
132 vgbuf->width = (int32_t)lv_area_get_width(area);
133 vgbuf->height = (int32_t)lv_area_get_height(area);
134 vgbuf->stride = (int32_t)(stride) * sizeof(lv_color_t);
135
136 lv_memset_00(&vgbuf->yuv, sizeof(vgbuf->yuv));
137
138 vgbuf->memory = (void *)buf;
139 vgbuf->address = (uint32_t)vgbuf->memory;
140 vgbuf->handle = NULL;
141 }
142
143 #endif /*LV_USE_GPU_NXP_VG_LITE*/
144