• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  *
4  * This program is free software; you can redistribute  it and/or modify it
5  * under  the terms of  the GNU General  Public License as published by the
6  * Free Software Foundation;  either version 2 of the  License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  *
17  */
18 
19 #include "mkp_vo_gfx.h"
20 #include "hi_common_vo.h"
21 #include "mkp_vo_gfx.h"
22 #include "mkp_vo_dev.h"
23 #include "mkp_vo_video.h"
24 #include "mkp_vo_comm.h"
25 #include "drv_vo_gfx.h"
26 #include "vo.h"
27 #include "drv_vo.h"
28 #include "common.h"
29 
30 #if VO_DESC("public api")
31 vo_gfxlayer_context g_vo_gfx_layer_ctx[HI_VO_MAX_GFX_LAYER_NUM];
32 
vo_get_gfx_layer_ctx(hi_vo_layer vo_layer)33 vo_gfxlayer_context *vo_get_gfx_layer_ctx(hi_vo_layer vo_layer)
34 {
35     return &(g_vo_gfx_layer_ctx[vo_layer - HI_VO_LAYER_G0]);
36 }
37 
vo_init_gfx(hi_void)38 hi_void vo_init_gfx(hi_void)
39 {
40     hi_vo_layer gfx_layer;
41     vo_gfxlayer_context *gfx_layer_ctx = HI_NULL;
42 
43     for (gfx_layer = HI_VO_LAYER_G0; gfx_layer < HI_VO_LAYER_G0 + HI_VO_MAX_GFX_LAYER_NUM; gfx_layer++) {
44         gfx_layer_ctx = vo_get_gfx_layer_ctx(gfx_layer);
45 
46         gfx_layer_ctx->gfx_csc.csc_matrix = HI_VO_CSC_MATRIX_RGBFULL_TO_BT601FULL;
47         gfx_layer_ctx->gfx_csc.luma = VO_CSC_DEF_VAL;
48         gfx_layer_ctx->gfx_csc.contrast = VO_CSC_DEF_VAL;
49         gfx_layer_ctx->gfx_csc.hue = VO_CSC_DEF_VAL;
50         gfx_layer_ctx->gfx_csc.saturation = VO_CSC_DEF_VAL;
51         gfx_layer_ctx->gfx_csc.ex_csc_en = HI_FALSE;
52         gfx_layer_ctx->csc_param.csc_scale2p = GFX_CSC_SCALE;
53         gfx_layer_ctx->csc_param.csc_clip_min = GFX_CSC_CLIP_MIN;
54         gfx_layer_ctx->csc_param.csc_clip_max = GFX_CSC_CLIP_MAX;
55     }
56 }
57 
vo_get_gfx_bind_dev(hi_vo_layer layer)58 hi_vo_dev vo_get_gfx_bind_dev(hi_vo_layer layer)
59 {
60     return vou_drv_get_gfx_bind_dev(layer);
61 }
62 
vo_check_gfx_id(hi_vo_layer gfx_layer)63 hi_s32 vo_check_gfx_id(hi_vo_layer gfx_layer)
64 {
65     if (vo_def_is_gfx_layer_id(gfx_layer) != HI_TRUE) {
66         return HI_ERR_VO_INVALID_LAYER_ID;
67     }
68 
69     return vo_drv_check_gfx_id(gfx_layer);
70 }
71 #endif
72 
73 #if VO_DESC("gfx attr")
vo_check_gfx_attr_display_rect(hi_vo_dev dev,hi_vo_layer layer,const hi_rect * rect)74 static hi_s32 vo_check_gfx_attr_display_rect(hi_vo_dev dev, hi_vo_layer layer, const hi_rect *rect)
75 {
76     hi_size dev_size;
77 
78     vo_get_dev_max_size(dev, &dev_size);
79     if ((rect->x < 0) || (rect->y < 0) || (rect->width < VO_RESO_MIN_WDT) || (rect->height < VO_RESO_MIN_HGT) ||
80         ((rect->width + rect->x) > dev_size.width) || ((rect->height + rect->y) > dev_size.height)) {
81         vo_err_trace("layer(%d) display rect(%d, %d, %d,%d) is illegal, should between (%d, %d) and (%d, %d)\n",
82             layer, rect->x, rect->y, rect->width, rect->height,
83             VO_RESO_MIN_WDT, VO_RESO_MIN_HGT, dev_size.width, dev_size.height);
84         return HI_ERR_VO_ILLEGAL_PARAM;
85     }
86 
87     if (vo_check_rect_align(rect) != HI_SUCCESS) {
88         vo_err_trace("layer(%d), display rect (%d, %d, %d, %d) dosen't aligned by 2 pixels!\n",
89             layer, rect->x, rect->y, rect->width, rect->height);
90         return HI_ERR_VO_ILLEGAL_PARAM;
91     }
92 
93     return vo_drv_check_gfx_attr_display_rect(layer, rect);
94 }
95 
vo_check_gfx_attr_stride(hi_vo_layer layer,const hi_vo_gfx_attr * attr)96 static hi_s32 vo_check_gfx_attr_stride(hi_vo_layer layer, const hi_vo_gfx_attr *attr)
97 {
98     if (((attr->stride % VO_RECT_ALIGN) != 0)) {
99         vo_err_trace("layer%d's stride %d is illegal!\n", layer, attr->stride);
100         return HI_ERR_VO_ILLEGAL_PARAM;
101     }
102 
103     if (((attr->address % VO_ADDR_ALIGN) != 0)) {
104         vo_err_trace("layer%d's addr 0x%lx is illegal, it should be %d bytes align!\n", layer, attr->address,
105             VO_ADDR_ALIGN);
106         return HI_ERR_VO_ILLEGAL_PARAM;
107     }
108 
109     return HI_SUCCESS;
110 }
111 
vo_check_gfx_attr_type(hi_vo_layer layer,const hi_vo_gfx_attr * attr)112 static hi_s32 vo_check_gfx_attr_type(hi_vo_layer layer, const hi_vo_gfx_attr *attr)
113 {
114     if ((attr->type != HI_VO_GFX_TYPE_ARGB1555) &&
115         (attr->type != HI_VO_GFX_TYPE_BMP1555)) {
116         vo_err_trace("layer%d's picture type %d is illegal!\n", layer, attr->type);
117         return HI_ERR_VO_ILLEGAL_PARAM;
118     }
119 
120     return HI_SUCCESS;
121 }
122 
vo_check_gfx_attr(hi_vo_dev dev,hi_vo_layer layer,const hi_vo_gfx_attr * attr)123 static hi_s32 vo_check_gfx_attr(hi_vo_dev dev, hi_vo_layer layer, const hi_vo_gfx_attr *attr)
124 {
125     hi_s32 ret;
126     ret = vo_check_gfx_attr_display_rect(dev, layer, &attr->display_rect);
127     if (ret != HI_SUCCESS) {
128         return ret;
129     }
130 
131     ret = vo_check_gfx_attr_stride(layer, attr);
132     if (ret != HI_SUCCESS) {
133         return ret;
134     }
135 
136     return vo_check_gfx_attr_type(layer, attr);
137 }
138 
vo_check_set_gfx_attr(hi_vo_layer layer,const hi_vo_gfx_attr * attr)139 static hi_s32 vo_check_set_gfx_attr(hi_vo_layer layer, const hi_vo_gfx_attr *attr)
140 {
141     hi_vo_dev dev;
142 
143     dev = vo_get_gfx_bind_dev(layer);
144     if (vo_check_layer_binded_dev(layer, dev) != HI_SUCCESS) {
145         vo_err_trace("vo layer %d can't set layer attr when the layer has not been binded!\n", layer);
146         return HI_ERR_VO_NOT_BINDED;
147     }
148 
149     if (vo_is_dev_enabled(dev) != HI_TRUE) {
150         vo_err_trace("vo gfx layer %d bind dev %d doesn't enable!\n", layer, dev);
151         return HI_ERR_VO_NOT_ENABLE;
152     }
153 
154     return vo_check_gfx_attr(dev, layer, attr);
155 }
156 
vo_set_gfx_attr_in_drv(hi_vo_layer layer,const hi_vo_gfx_attr * attr)157 static hi_void vo_set_gfx_attr_in_drv(hi_vo_layer layer, const hi_vo_gfx_attr *attr)
158 {
159     hal_disp_layer gfx_layer = HAL_DISP_LAYER_GFX0;
160     vo_gfxlayer_context *gfx_layer_ctx = HI_NULL;
161 
162     gfx_layer_ctx = vo_get_gfx_layer_ctx(layer);
163     vo_drv_get_hal_gfx_layer(layer, &gfx_layer);
164     vo_drv_set_gfx_layer_csc(gfx_layer, &gfx_layer_ctx->gfx_csc, &gfx_layer_ctx->csc_param);
165     vou_drv_layer_csc_enable(gfx_layer, HI_TRUE);
166 }
167 
vo_do_set_gfx_attr(hi_vo_layer layer,const hi_vo_gfx_attr * attr)168 static hi_s32 vo_do_set_gfx_attr(hi_vo_layer layer, const hi_vo_gfx_attr *attr)
169 {
170     hi_s32 ret;
171 
172     ret = vo_check_set_gfx_attr(layer, attr);
173     if (ret != HI_SUCCESS) {
174         return ret;
175     }
176 
177     vo_set_gfx_attr_in_drv(layer, attr);
178 
179     return HI_SUCCESS;
180 }
181 
vo_set_gfx_attr(hi_vo_layer layer,const hi_vo_gfx_attr * attr)182 hi_s32 vo_set_gfx_attr(hi_vo_layer layer, const hi_vo_gfx_attr *attr)
183 {
184     hi_s32 ret;
185 
186     vo_check_null_ptr_return(attr);
187     vo_check_gfx_id_return(layer);
188 
189     ret = vo_do_set_gfx_attr(layer, attr);
190     return ret;
191 }
192 
193 #endif
194 
195 #if VO_DESC("enable gfx")
196 
vo_is_gfx_layer_enabled(hi_vo_layer layer)197 hi_bool vo_is_gfx_layer_enabled(hi_vo_layer layer)
198 {
199     vo_gfxlayer_context *ctx = HI_NULL;
200 
201     ctx = vo_get_gfx_layer_ctx(layer);
202     return ctx->opened;
203 }
204 
vo_is_dev_gfx_layer_enabled(hi_vo_dev dev)205 hi_bool vo_is_dev_gfx_layer_enabled(hi_vo_dev dev)
206 {
207     hi_vo_layer gfx_layer;
208 
209     gfx_layer = vo_drv_get_gfx_layer(dev);
210     if (vo_is_gfx_layer_enabled(gfx_layer) == HI_TRUE) {
211         vo_err_trace("vo %d's gfx layer %d doesn't disable!\n", dev, gfx_layer);
212         return HI_TRUE;
213     }
214 
215     return HI_FALSE;
216 }
217 
vo_check_enable_gfx_layer(hi_vo_layer layer)218 static hi_s32 vo_check_enable_gfx_layer(hi_vo_layer layer)
219 {
220     hi_vo_dev dev;
221 
222     dev = vo_get_gfx_bind_dev(layer);
223     if (vo_check_layer_binded_dev(layer, dev) != HI_SUCCESS) {
224         vo_err_trace("layer(%d) is not bind any dev!\n", layer);
225         return HI_ERR_VO_NOT_BINDED;
226     }
227 
228     if (vo_is_dev_enabled(dev) != HI_TRUE) {
229         vo_err_trace("vo device %d doesn't enable!\n", dev);
230         return HI_ERR_VO_NOT_ENABLE;
231     }
232 
233     return HI_SUCCESS;
234 }
235 
vo_do_enable_gfx_layer(hi_vo_layer layer,const hi_vo_gfx_attr * gfx_attr)236 static hi_s32 vo_do_enable_gfx_layer(hi_vo_layer layer, const hi_vo_gfx_attr *gfx_attr)
237 {
238     hi_s32 ret;
239     vo_gfxlayer_context *gfx_ctx = HI_NULL;
240 
241     gfx_ctx = vo_get_gfx_layer_ctx(layer);
242     if (gfx_ctx->opened == HI_TRUE) {
243         vo_warn_trace("video layer%d has been enabled!\n", layer);
244         return HI_SUCCESS;
245     }
246 
247     ret = vo_check_enable_gfx_layer(layer);
248     if (ret != HI_SUCCESS) {
249         return ret;
250     }
251 
252     gfx_ctx->opened = HI_TRUE;
253 
254     vo_drv_gfx_open(layer, gfx_attr);
255 
256     return HI_SUCCESS;
257 }
258 
vo_enable_gfx_layer(hi_vo_layer layer,const hi_vo_gfx_attr * gfx_attr)259 hi_s32 vo_enable_gfx_layer(hi_vo_layer layer, const hi_vo_gfx_attr *gfx_attr)
260 {
261     hi_s32 ret;
262     vo_check_gfx_id_return(layer);
263     ret = vo_do_enable_gfx_layer(layer, gfx_attr);
264     return ret;
265 }
266 
267 #endif
268 
269 #if VO_DESC("disable gfx")
vo_check_disable_gfx_layer(hi_vo_layer layer)270 static hi_s32 vo_check_disable_gfx_layer(hi_vo_layer layer)
271 {
272     hi_vo_dev dev;
273 
274     dev = vo_get_gfx_bind_dev(layer);
275     if (vo_check_layer_binded_dev(layer, dev) != HI_SUCCESS) {
276         vo_err_trace("layer(%d) is not bind any dev!\n", layer);
277         return HI_ERR_VO_NOT_BINDED;
278     }
279     return HI_SUCCESS;
280 }
281 
vo_do_disable_gfx_layer(hi_vo_layer layer)282 static hi_s32 vo_do_disable_gfx_layer(hi_vo_layer layer)
283 {
284     hi_s32 ret;
285     vo_gfxlayer_context *gfx_layer_ctx = HI_NULL;
286     ret = vo_check_disable_gfx_layer(layer);
287     if (ret != HI_SUCCESS) {
288         return ret;
289     }
290     gfx_layer_ctx = vo_get_gfx_layer_ctx(layer);
291     if (gfx_layer_ctx->opened == HI_FALSE) {
292         return HI_SUCCESS;
293     }
294     vo_drv_gfx_close(layer);
295     /* sleep: msleep(40); */
296     gfx_layer_ctx->opened = HI_FALSE;
297 
298     return HI_SUCCESS;
299 }
300 
vo_disable_gfx_layer(hi_vo_layer layer_id)301 hi_s32 vo_disable_gfx_layer(hi_vo_layer layer_id)
302 {
303     hi_s32 ret;
304 
305     vo_check_gfx_id_return(layer_id);
306     ret = vo_do_disable_gfx_layer(layer_id);
307 
308     return ret;
309 }
310 #endif
311