• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your 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, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18 
19 #include "tde_osictl_k.h"
20 #ifndef HI_BUILD_IN_BOOT
21 #include "tde_handle.h"
22 #ifdef CONFIG_HI_PROC_SHOW_SUPPORT
23 #include "tde_proc.h"
24 #endif
25 #else
26 #include "exports.h"
27 #include "tde_handle.h"
28 #endif
29 #include "tde_osictl.h"
30 #include "tde_osilist.h"
31 #include "tde_hal.h"
32 #include "wmalloc.h"
33 #include "hi_math.h"
34 #include "securec.h"
35 #include "tde_adp.h"
36 #include "osal_list.h"
37 
38 /* TDE osi ctl macro definition */
39 #define TDE_CLUT_SIZE (256 * 4)
40 
41 #define tde_min(a, b) \
42     (((a) > (b)) ? (b) : (a))
43 
44 #define drv_tde_mb_src_val(mb_src, theight, twidth)        \
45     do {                                                   \
46         theight = (mb_src)->src_rect->height;              \
47         twidth = (mb_src)->src_rect->width;                \
48     } while (0)
49 
50 #define drv_tde_mb_src_addr(mb_src, typhy_addr, tcb_crphy_addr, tphy)    \
51         do {                                                             \
52             typhy_addr = (mb_src)->mb_surface->y_addr;                   \
53             tcb_crphy_addr = (mb_src)->mb_surface->cbcr_phy_addr;        \
54             tphy = (mb_src)->dst_surface->phy_addr;                      \
55         } while (0)
56 
57 #define tde_get_yc422r_fillvalue(value)                                          \
58     (((value) & 0xffffff) | ((((value) >> 8) & 0xff) << 24))
59 
60 #define ycc2rgb(y, cb, cr, r, g, b)                                                            \
61     do {                                                                                       \
62         r = (((298 * ((y) - 16) + 409 * ((cr) - 128)) >> 7) + 1) >> 1;                         \
63         g = (((298 * ((y) - 16) - 100 * ((cb) - 128) - 208 * ((cr) - 128)) >> 7) + 1) >> 1;    \
64         b = (((298 * ((y) - 16) + 517 * ((cb) - 128)) >> 7) + 1) >> 1;                         \
65     } while (0)
66 
67 #define rgb2ycc(r, g, b, y, cb, cr)                                          \
68     do {                                                                     \
69         y  = ((((263 * (r) + 516 * (g) + 100 * (b)) >> 9) + 1) >> 1) + 16;   \
70         cb = ((((-152 * (r) - 298 * (g) + 450 * (b)) >> 9) + 1) >> 1) + 128; \
71         cr = ((((450 * (r) - 377 * (g) - 73 * (b)) >> 9) + 1) >> 1) + 128;   \
72     } while (0)
73 
74 #define TDE_FOUR_BITS_SHIFT  4
75 #define TDE_THREE_BITS_SHIFT 3
76 #define TDE_TWO_BITS_SHIFT   2
77 #define TDE_ONE_BIT_SHIFT    1
78 #define TDE_ZERO_BIT_SHIFT   0
79 #define TDE_MAX_PATTERNWIDTH 256
80 
81 /* TDE osi ctl struct definition */
82 #if (TDE_CAPABILITY & SLICE)
83 typedef struct {
84     hi_u32 des_width;
85     hi_u32 des_hoffset_pix;
86     hi_u32 des_h_scan_ord;
87     hi_u32 des_crop_en;
88     hi_u32 des_crop_start_x;
89     hi_u32 des_crop_end_x;
90 
91     hi_u32 xdpos;
92     hi_u32 h_scan_ord;
93     hi_u32 width;
94 
95     hi_u32 hlmsc_en;
96     hi_u32 hchmsc_en;
97     hi_u32 hratio;
98     hi_s32 hor_loffset;
99     hi_s32 hor_coffset;
100     hi_u32 zme_ow;
101     hi_u32 zme_iw;
102     hi_u32 hpzme_en;
103     hi_u32 hpzme_mode;
104     hi_u32 hpzme_width;
105 
106     hi_u32 des_xst_pos_blk;
107     hi_u32 des_xed_pos_blk;
108     hi_u32 xed_pos_blk;
109     hi_u32 xst_pos_cord;
110     hi_u32 xed_pos_cord;
111     hi_u32 xst_pos_cord_in;
112     hi_u32 xed_pos_cord_in;
113     hi_u32 hor_loffset_cfg_int_comp;
114     hi_s32 hor_loffset_cfg_int;
115     hi_s32 xst_pos_cord_in_offset;
116     hi_s32 xed_pos_cord_in_offset;
117     hi_u32 xst_pos_cord_in_tap_rgb;
118     hi_u32 xed_pos_cord_in_tap_rgb;
119     hi_u32 node_cfg_zme_iw_rgb;
120     hi_u32 hor_loffset_cfg_fraction;
121     hi_u32 hor_loffset_pix_fraction;
122     hi_u32 hor_loffset_fraction;
123     hi_s32 hor_loffset_int;
124     hi_s32 node_cfg_hor_loffset_rgb;
125     hi_u32 xst_pos_cord_in_tap_luma;
126     hi_u32 xed_pos_cord_in_tap_luma;
127     hi_u32 xst_pos_cord_in_chroma;
128     hi_u32 xed_pos_cord_in_chroma;
129     hi_u32 hor_coffset_cfg_int_comp;
130     hi_s32 hor_coffset_cfg_int;
131     hi_s32 xst_pos_cord_in_offset_chroma;
132     hi_s32 xed_pos_cord_in_offset_chroma;
133     hi_u32 xst_pos_cord_in_tap_chroma;
134     hi_u32 xed_pos_cord_in_tap_chroma;
135     hi_u32 xst_pos_cord_in_tap_chroma_x2;
136     hi_u32 xed_pos_cord_in_tap_chroma_x2;
137     hi_u32 xst_pos_cord_in_tap_sp;
138     hi_u32 xed_pos_cord_in_tap_sp;
139     hi_u32 node_cfg_zme_iw_sp;
140     hi_u32 hor_coffset_cfg_fraction;
141     hi_u32 hor_coffset_pix_fraction;
142     hi_u32 hor_coffset_fraction;
143     hi_s32 hor_loffset_int_sp;
144     hi_s32 hor_coffset_int_sp;
145     hi_u32 hor_loffset_int_sp_complent;
146     hi_u32 hor_coffset_int_sp_complent;
147     hi_s32 node_cfg_hor_loffset_sp;
148     hi_s32 node_cfg_hor_coffset_sp;
149     hi_u32 xst_pos_cord_in_tap;
150     hi_u32 xed_pos_cord_in_tap;
151 
152     hi_u32 hor_loffset_int_complement;
153     hi_u32 node_num;
154 
155     hi_u32 xst_pos_cord_in_tap_hpzme;
156     hi_u32 xed_pos_cord_in_tap_hpzme;
157     hi_u32 xst_pos_cord_in_tap_hpzme_hso;
158     hi_u32 xed_pos_cord_in_tap_hpzme_hso;
159     hi_u32 u32422v_pro;
160     hi_u32 hor_loffset_int_beyond;
161     hi_u32 hor_loffset_int_beyond_complent;
162 
163     hi_u32 slice_width;
164     hi_u32 slice_wi;
165     hi_s32 slice_c_ofst;
166     hi_s32 slice_l_ofst;
167     hi_u32 slice_hoffset;
168     hi_u32 slice_wo;
169     hi_u32 slice_w_hpzme;
170     hi_u32 slice_dst_width;
171     hi_u32 slice_dst_hoffset;
172     hi_u32 fmt;
173 } tde_slice_data;
174 #endif
175 
176 /* pixel format transform type */
177 typedef enum {
178     TDE_COLORFMT_TRANSFORM_ARGB_ARGB = 0,
179     TDE_COLORFMT_TRANSFORM_ARGB_YCBCR,
180     TDE_COLORFMT_TRANSFORM_CLUT_ARGB,
181     TDE_COLORFMT_TRANSFORM_CLUT_YCBCR,
182     TDE_COLORFMT_TRANSFORM_CLUT_CLUT,
183     TDE_COLORFMT_TRANSFORM_YCBCR_ARGB,
184     TDE_COLORFMT_TRANSFORM_YCBCR_YCBCR,
185     TDE_COLORFMT_TRANSFORM_AN_AN,
186     TDE_COLORFMT_TRANSFORM_ARGB_AN,
187     TDE_COLORFMT_TRANSFORM_YCBCR_AN,
188     TDE_COLORFMT_TRANSFORM_BUTT,
189 } tde_colorfmt_transform;
190 
191 /* CLUT table use */
192 typedef enum {
193     TDE_CLUT_COLOREXPENDING = 0, /* color expend */
194     TDE_CLUT_COLORCORRECT,       /* color correct */
195     TDE_CLUT_CLUT_BYPASS,
196     TDE_CLUT_USAGE_BUTT
197 } tde_clut_usage;
198 
199 typedef enum {
200     TDE_OPERATION_SINGLE_SRC1 = 0,
201     TDE_OPERATION_SINGLE_SRC2,
202     TDE_OPERATION_DOUBLE_SRC,
203     TDE_OPERATION_BUTT
204 } tde_operation_category;
205 
206 typedef enum {
207     TDE_PATTERN_OPERATION_SINGLE_SRC = 0,
208     TDE_PATTERN_OPERATION_DOUBLE_SRC,
209     TDE_PATTERN_OPERATION_BUTT
210 } tde_pattern_operation_category;
211 
212 typedef struct {
213     hi_u8 alpha_bits;
214     hi_u8 red_bits;
215     hi_u8 green_bits;
216     hi_u8 blue_bits;
217     hi_u8 alpha_offset;
218     hi_u8 red_offset;
219     hi_u8 green_offset;
220     hi_u8 blue_offset;
221 } tde2_fmt_bitoffset;
222 
223 #ifndef HI_BUILD_IN_BOOT
224 #if (TDE_CAPABILITY & RESIZE)
225 typedef struct {
226     hi_s32 ori_in_width;    /* original image width */
227     hi_s32 ori_in_height;   /* original image height */
228     hi_s32 zme_out_width;   /* output full image width */
229     hi_s32 zme_out_height;  /* output full image height */
230 
231     hi_s32 update_instart_w;  /* the start_x of update area in original image */
232     hi_s32 update_instart_h;  /* the start_y of update area in original image */
233     hi_s32 update_in_width;   /* the width of update area in original image */
234     hi_s32 update_in_height;  /* the height of update area in original image */
235 } tde_update_config;
236 
237 typedef struct {
238     hi_s32 zme_instart_w;  /* the start_x of needed readin area in original image */
239     hi_s32 zme_instart_h;  /* the start_y of needed readin area in original image */
240     hi_s32 zme_in_width;   /* the width of needed readin area in original image */
241     hi_s32 zme_in_height;  /* the height of needed readin area in original image */
242 
243     hi_s32 zme_outstart_w;  /* the start_x of needed update area in output image */
244     hi_s32 zme_outstart_h;  /* the start_y of needed update area in output image */
245     hi_s32 zme_out_width;   /* the width of needed update area in output image */
246     hi_s32 zme_out_height;  /* the height of needed update area in output image */
247 
248     hi_s32 zme_hphase;      /* the start phase of horizontal scale */
249     hi_s32 zme_vphase;      /* the start phase of vertical scale */
250     hi_s32 def_offsetup;    /* the up offset of deflicker */
251     hi_s32 def_offsetdown;  /* the down offset of deflicker */
252 } tde_update_info;
253 #endif
254 #endif
255 
256 /* TDE osi ctl inner variables definition */
257 tde_color_fmt g_tde_common_drv_color_fmt[HI_TDE_COLOR_FMT_MAX + 1] = {
258     TDE_DRV_COLOR_FMT_RGB444, TDE_DRV_COLOR_FMT_RGB444,
259     TDE_DRV_COLOR_FMT_RGB555, TDE_DRV_COLOR_FMT_RGB555,
260     TDE_DRV_COLOR_FMT_RGB565, TDE_DRV_COLOR_FMT_RGB565,
261     TDE_DRV_COLOR_FMT_RGB888, TDE_DRV_COLOR_FMT_RGB888,
262     TDE_DRV_COLOR_FMT_ARGB4444, TDE_DRV_COLOR_FMT_ARGB4444, TDE_DRV_COLOR_FMT_ARGB4444, TDE_DRV_COLOR_FMT_ARGB4444,
263     TDE_DRV_COLOR_FMT_ARGB1555, TDE_DRV_COLOR_FMT_ARGB1555, TDE_DRV_COLOR_FMT_ARGB1555, TDE_DRV_COLOR_FMT_ARGB1555,
264     TDE_DRV_COLOR_FMT_ARGB8565, TDE_DRV_COLOR_FMT_ARGB8565, TDE_DRV_COLOR_FMT_ARGB8565, TDE_DRV_COLOR_FMT_ARGB8565,
265     TDE_DRV_COLOR_FMT_ARGB8888, TDE_DRV_COLOR_FMT_ARGB8888, TDE_DRV_COLOR_FMT_ARGB8888, TDE_DRV_COLOR_FMT_ARGB8888,
266     TDE_DRV_COLOR_FMT_RABG8888,
267     TDE_DRV_COLOR_FMT_CLUT1, TDE_DRV_COLOR_FMT_CLUT2, TDE_DRV_COLOR_FMT_CLUT4,
268     TDE_DRV_COLOR_FMT_CLUT8, /* TDE_DRV_COLOR_FMT_CLUT1B,TDE_DRV_COLOR_FMT_CLUT2B,TDE_DRV_COLOR_FMT_CLUT4B, */
269     TDE_DRV_COLOR_FMT_ACLUT44, TDE_DRV_COLOR_FMT_ACLUT88,
270     TDE_DRV_COLOR_FMT_A1, TDE_DRV_COLOR_FMT_A8, /* TDE_DRV_COLOR_FMT_A1B, */
271     TDE_DRV_COLOR_FMT_YCBCR888, TDE_DRV_COLOR_FMT_AYCBCR8888, TDE_DRV_COLOR_FMT_YCBCR422, TDE_DRV_COLOR_FMT_PKGVYUY,
272     TDE_DRV_COLOR_FMT_BYTE, TDE_DRV_COLOR_FMT_HALFWORD,
273     TDE_DRV_COLOR_FMT_YCBCR400MBP,
274     TDE_DRV_COLOR_FMT_YCBCR422MBH, TDE_DRV_COLOR_FMT_YCBCR422MBV,
275     TDE_DRV_COLOR_FMT_YCBCR420MB, TDE_DRV_COLOR_FMT_YCBCR420MB, TDE_DRV_COLOR_FMT_YCBCR420MB,
276     TDE_DRV_COLOR_FMT_YCBCR420MB,
277     TDE_DRV_COLOR_FMT_YCBCR444MB, TDE_DRV_COLOR_FMT_MAX
278 };
279 
280 static tde_argb_order_mode g_tde_argb_order[HI_TDE_COLOR_FMT_MAX + 1] = {
281     TDE_DRV_ORDER_ARGB, TDE_DRV_ORDER_ABGR,
282     TDE_DRV_ORDER_ARGB, TDE_DRV_ORDER_ABGR,
283     TDE_DRV_ORDER_ARGB, TDE_DRV_ORDER_ABGR,
284     TDE_DRV_ORDER_ARGB, TDE_DRV_ORDER_ABGR,
285     TDE_DRV_ORDER_ARGB, TDE_DRV_ORDER_ABGR, TDE_DRV_ORDER_RGBA, TDE_DRV_ORDER_BGRA,
286     TDE_DRV_ORDER_ARGB, TDE_DRV_ORDER_ABGR, TDE_DRV_ORDER_RGBA, TDE_DRV_ORDER_BGRA,
287     TDE_DRV_ORDER_ARGB, TDE_DRV_ORDER_ABGR, TDE_DRV_ORDER_RGBA, TDE_DRV_ORDER_BGRA,
288     TDE_DRV_ORDER_ARGB, TDE_DRV_ORDER_ABGR, TDE_DRV_ORDER_RGBA, TDE_DRV_ORDER_BGRA,
289     TDE_DRV_ORDER_RABG,
290     TDE_DRV_ORDER_MAX, TDE_DRV_ORDER_MAX, TDE_DRV_ORDER_MAX,
291     TDE_DRV_ORDER_MAX, /* TDE_DRV_ORDER_MAX, TDE_DRV_ORDER_MAX, TDE_DRV_ORDER_MAX, */
292     TDE_DRV_ORDER_MAX, TDE_DRV_ORDER_MAX,
293     TDE_DRV_ORDER_MAX, TDE_DRV_ORDER_MAX, /* TDE_DRV_ORDER_MAX, */
294     TDE_DRV_ORDER_MAX, TDE_DRV_ORDER_MAX, TDE_DRV_ORDER_MAX, TDE_DRV_ORDER_MAX,
295     TDE_DRV_ORDER_MAX, TDE_DRV_ORDER_MAX,
296     TDE_DRV_ORDER_MAX,
297     TDE_DRV_ORDER_MAX, TDE_DRV_ORDER_MAX,
298     TDE_DRV_ORDER_MAX, TDE_DRV_ORDER_MAX, TDE_DRV_ORDER_MAX,
299     TDE_DRV_ORDER_MAX,
300     TDE_DRV_ORDER_MAX
301 };
302 
303 #ifndef HI_BUILD_IN_BOOT /* codecc */
304 /* if local deflicker flag */
305 static hi_bool g_region_deflicker = HI_FALSE;
306 static hi_bool g_is_resize_filter = HI_TRUE;
307 #endif
308 
309 /* TDE osi ctl inner interface definition */
310 static hi_void tde_unify_rect(hi_tde_rect *src_rect, hi_tde_rect *dst_rect);
311 static tde_colorfmt_category tde_osi_get_fmt_category(hi_tde_color_fmt fmt);
312 
313 static tde_colorfmt_transform tde_osi_get_fmt_trans_type(hi_tde_color_fmt src2_fmt, hi_tde_color_fmt dst_fmt);
314 
315 static hi_s32 tde_osi_set_clut_opt(hi_tde_surface *clut_sur, hi_tde_surface *out_sur, tde_clut_usage *pen_clut_usage,
316                                    hi_bool clut_reload, tde_hw_node *hw_node);
317 
318 static tde_clut_usage tde_osi_get_clut_usage(hi_tde_color_fmt src_fmt, hi_tde_color_fmt dst_fmt);
319 
320 static hi_s32 tde_osi_get_scan_info_ex(hi_tde_single_src *single_src, hi_tde_opt *opt,
321                                        tde_scandirection_mode *src_direction,
322                                        tde_scandirection_mode *dst_direction);
323 
324 static hi_s32 tde_osi_get_inter_rect(hi_tde_rect *rect1, hi_tde_rect *rect2, hi_tde_rect *inter_rect);
325 
326 static hi_s32 tde_osi_set_mb_para(hi_s32 handle, hi_tde_mb_src *mb_src, hi_tde_mb_opt *mb_opt);
327 
328 static hi_s32 tde_osi_set_filter_node(hi_s32 handle, tde_hw_node *node, hi_tde_double_src *double_src,
329                                       hi_tde_deflicker_mode deflicker_mode, hi_tde_deflicker_mode fliter_mode);
330 
331 static hi_s32 tde_osi_1_source_fill(hi_s32 handle, hi_tde_surface *dst_surface,
332                                     hi_tde_rect *dst_rect, hi_tde_fill_color *fill_color,
333                                     hi_tde_opt *opt);
334 
335 static hi_s32 tde_osi_single_src_2_blit(hi_s32 handle, hi_tde_single_src *single_src,
336                                         hi_tde_opt *opt, hi_bool mmz_for_src, hi_bool mmz_for_dst);
337 
338 #ifndef HI_BUILD_IN_BOOT
339 static hi_s32 tde_osi_2_source_fill(hi_s32 handle, hi_tde_single_src *single_src, hi_tde_fill_color *fill_color,
340                                     hi_tde_opt *opt);
341 
342 static hi_s32 tde_osi_set_color_key(hi_tde_double_src *double_src,
343                                     tde_hw_node *hw_node, hi_tde_color_key color_key_value,
344                                     hi_tde_color_key_mode color_key_mode,
345                                     tde_clut_usage clut_usage);
346 static hi_s32 tde_osi_set_blend(tde_hw_node *hw_node, hi_tde_alpha_blending alpha_blending_cmd,
347                                 hi_tde_blend_opt blend_opt,
348                                 tde_alu_mode *alu_mode, hi_bool check_blend);
349 
350 #if (TDE_CAPABILITY & ROP)
351 
352 static hi_s32 tde_osi_set_rop(tde_hw_node *hw_node, hi_tde_alpha_blending alpha_blending_cmd,
353                               hi_tde_rop_mode rop_code_color,
354                               hi_tde_rop_mode rop_alpha, tde_alu_mode *alu_mode, hi_bool single_sr2_rop);
355 #endif
356 
357 #if (TDE_CAPABILITY & COLORIZE)
358 
359 static hi_s32 tde_osi_set_colorize(tde_hw_node *hw_node, hi_tde_alpha_blending alpha_blending_cmd,
360     hi_s32 color_resize);
361 #endif
362 
363 static hi_s32 tde_osi_check_double_src_pattern_fill_para(hi_tde_double_src *double_src,
364                                                          hi_tde_pattern_fill_opt *opt);
365 
366 static hi_s32 tde_osi_check_single_src_pattern_fill_para(hi_tde_single_src *single_src,
367                                                          hi_tde_pattern_fill_opt *opt);
368 
369 static tde_pattern_operation_category tde_osi_check_single_src_pattern_operation(hi_tde_double_src *double_src,
370     hi_tde_pattern_fill_opt *opt);
371 
372 static tde_pattern_operation_category tde_osi_double_src_pattern_operation(hi_tde_double_src *double_src,
373                                                                            hi_tde_pattern_fill_opt *opt);
374 
375 static hi_s32 tde_osi_single_src_1_blit(hi_s32 handle, hi_tde_single_src *single_src,
376                                         hi_bool mmz_for_src, hi_bool mmz_for_dst);
377 
378 static hi_s32 tde_osi_set_foreground_color_key(tde_hw_node *hw_node, hi_tde_surface *src_surface, hi_tde_opt *opt,
379                                                tde_clut_usage clut_usage);
380 #endif
381 
382 static tde_operation_category tde_osi_single_src_operation(hi_tde_double_src *double_src, hi_tde_opt *opt);
383 
384 static tde_operation_category tde_osi_double_src_operation(hi_tde_double_src *double_src, hi_tde_opt *opt);
385 
386 static hi_s32 tde_osi_check_surface(hi_tde_surface *surface, hi_tde_rect *rect);
387 
388 static tde_operation_category tde_osi_get_opt_category(hi_tde_double_src *double_src, hi_tde_opt *opt);
389 
390 static hi_void tde_osi_convert_surface(hi_tde_surface *sur, hi_tde_rect *rect,
391                                        tde_scandirection_mode *scan_info,
392                                        tde_surface_msg *drv_sur);
393 
394 static hi_s32 tde_osi_set_clip_para(hi_tde_double_src *double_src, hi_tde_opt *opt, tde_hw_node *hw_node);
395 
396 static hi_s32 tde_osi_set_base_opt_para_for_blit(hi_tde_opt *opt, hi_tde_surface *src1, hi_tde_surface *src2,
397                                                  tde_operation_category opt_category, tde_hw_node *hw_node);
398 
399 static hi_s32 tde_osi_adj_clip_para(tde_hw_node *hw_node);
400 
401 static hi_s32 tde_osi_set_node_finish(hi_s32 handle, tde_hw_node *hw_node,
402                                       hi_u32 work_buf_num, tde_node_subm_type subm_type);
403 
404 static hi_s32 tde_osi_check_resize_para(hi_u32 in_width, hi_u32 in_height,
405                                         hi_u32 out_width, hi_u32 out_height);
406 static hi_bool tde_osi_whether_contain_alpha(hi_tde_color_fmt color_fmt);
407 static hi_void tde_osi_set_ext_alpha(hi_tde_surface *back_ground, hi_tde_surface *fore_ground,
408                                      tde_hw_node *hw_node);
409 
410 static hi_s32 tde_osi_pre_check_surface_ex(hi_tde_surface *surface, hi_tde_rect *rect);
411 
412 static hi_s32 tde_osi_raster_fmt_check_align(hi_tde_surface *surface);
413 
414 static hi_s32 tde_osi_check_mb_blit_para(hi_tde_mb_src *mb_src, hi_tde_mb_opt *mb_opt);
415 
416 static hi_s32 tde_osi_get_double_cycle_data(hi_tde_rect *mb_rect, hi_u32 *i, hi_u32 *j);
417 static hi_s32 tde_osi_get_bpp_by_fmt_1(hi_tde_color_fmt fmt);
418 static hi_s32 tde_osi_get_bpp_by_fmt_2(hi_tde_color_fmt fmt);
419 static hi_s32 tde_osi_get_bpp_by_fmt_4(hi_tde_color_fmt fmt);
420 static hi_s32 tde_osi_get_bpp_by_fmt_8(hi_tde_color_fmt fmt);
421 static hi_s32 tde_osi_get_bpp_by_fmt_16(hi_tde_color_fmt fmt);
422 static hi_s32 tde_osi_get_bpp_by_fmt_24(hi_tde_color_fmt fmt);
423 static hi_s32 tde_osi_get_bpp_by_fmt_32(hi_tde_color_fmt fmt);
424 static hi_s32 tde_osi_check_single_src_to_para(hi_tde_surface *fore_ground, hi_tde_rect *fore_ground_rect,
425                                                hi_tde_surface *dst_surface, hi_tde_rect *dst_rect,
426                                                hi_tde_opt *opt);
427 
428 static hi_s32 tde_osi_double_src_2_blit(hi_s32 handle, hi_tde_double_src *double_src, hi_tde_opt *opt);
429 
tde_unify_rect(hi_tde_rect * src_rect,hi_tde_rect * dst_rect)430 static hi_void tde_unify_rect(hi_tde_rect *src_rect, hi_tde_rect *dst_rect)
431 {
432     if (src_rect->height != dst_rect->height) {
433         src_rect->height = tde_min(src_rect->height, dst_rect->height);
434         dst_rect->height = src_rect->height;
435     }
436     if (src_rect->width != dst_rect->width) {
437         src_rect->width = tde_min(src_rect->width, dst_rect->width);
438         dst_rect->width = src_rect->width;
439     }
440 
441     return;
442 }
443 
444 static tde2_fmt_bitoffset g_fmt_bit_and_offset_array[HI_TDE_COLOR_FMT_AYCBCR8888 + 1] = {
445     { 0, 4, 4, 4, 12, 8,  4,  0 },  /* HI_TDE_COLOR_FMT_RGB444 */
446     { 0, 4, 4, 4, 12, 0,  4,  8 },  /* HI_TDE_COLOR_FMT_BGR444 */
447     { 0, 5, 5, 5, 15, 10, 5,  0 },  /* HI_TDE_COLOR_FMT_RGB555 */
448     { 0, 5, 5, 5, 15, 0,  5,  10 }, /* HI_TDE_COLOR_FMT_BGR555 */
449     { 0, 5, 6, 5, 16, 11, 5,  0 },  /* HI_TDE_COLOR_FMT_RGB565 */
450     { 0, 5, 6, 6, 16, 0,  5,  11 }, /* HI_TDE_COLOR_FMT_BGR565 */
451     { 0, 8, 8, 8, 24, 16, 8,  0 },  /* HI_TDE_COLOR_FMT_RGB888 */
452     { 0, 8, 8, 8, 24, 0,  8,  16 }, /* HI_TDE_COLOR_FMT_BGR888 */
453     { 4, 4, 4, 4, 12, 8,  4,  0 },  /* HI_TDE_COLOR_FMT_ARGB4444 */
454     { 4, 4, 4, 4, 12, 0,  4,  8 },  /* HI_TDE_COLOR_FMT_ABGR4444 */
455     { 4, 4, 4, 4, 0,  12, 8,  4 },  /* HI_TDE_COLOR_FMT_RGBA4444 */
456     { 4, 4, 4, 4, 0,  4,  8,  12 }, /* HI_TDE_COLOR_FMT_BGRA4444 */
457     { 1, 5, 5, 5, 15, 10, 5,  0 },  /* HI_TDE_COLOR_FMT_ARGB1555 */
458     { 1, 5, 5, 5, 15, 0,  5,  10 }, /* HI_TDE_COLOR_FMT_ABGR1555 */
459     { 1, 5, 5, 5, 0,  11, 6,  1 },  /* HI_TDE_COLOR_FMT_RGBA1555 */
460     { 1, 5, 5, 5, 0,  1,  6,  11 }, /* HI_TDE_COLOR_FMT_BGRA1555 */
461     { 8, 5, 6, 5, 16, 11, 5,  0 },  /* HI_TDE_COLOR_FMT_ARGB8565 */
462     { 8, 5, 6, 5, 16, 0,  5,  11 }, /* HI_TDE_COLOR_FMT_ABGR8565 */
463     { 8, 5, 6, 5, 0,  19, 13, 8 },  /* HI_TDE_COLOR_FMT_RGBA8565 */
464     { 8, 5, 6, 6, 0,  8,  13, 19 }, /* HI_TDE_COLOR_FMT_BGRA8565 */
465     { 8, 8, 8, 8, 24, 16, 8,  0 },  /* HI_TDE_COLOR_FMT_ARGB8888 */
466     { 8, 8, 8, 8, 24, 0,  8,  16 }, /* HI_TDE_COLOR_FMT_ABGR8888 */
467     { 8, 8, 8, 8, 0,  24, 16, 8 },  /* HI_TDE_COLOR_FMT_RGBA8888 */
468     { 8, 8, 8, 8, 0,  8,  16, 24 }, /* HI_TDE_COLOR_FMT_BGRA8888 */
469     { 8, 8, 8, 8, 16, 24, 0,  8 },  /* HI_TDE_COLOR_FMT_RABG8888 */
470 
471     { 0, 0, 0, 0, 0,  0,  0, 0 },
472     { 0, 0, 0, 0, 0,  0,  0, 0 },
473     { 0, 0, 0, 0, 0,  0,  0, 0 },
474     { 0, 0, 0, 0, 0,  0,  0, 0 },
475     { 0, 0, 0, 0, 0,  0,  0, 0 },
476     { 0, 0, 0, 0, 0,  0,  0, 0 },
477     { 0, 0, 0, 0, 0,  0,  0, 0 },
478     { 0, 0, 0, 0, 0,  0,  0, 0 },
479     { 0, 8, 8, 8, 24, 16, 8, 0 }, /* HI_TDE_COLOR_FMT_YCbCr888 */
480     { 8, 8, 8, 8, 24, 16, 8, 0 }, /* HI_TDE_COLOR_FMT_AYCbCr8888 */
481 };
482 
tde_get_common_drv_color_fmt(hi_u32 count)483 tde_color_fmt tde_get_common_drv_color_fmt(hi_u32 count)
484 {
485     return g_tde_common_drv_color_fmt[count];
486 }
487 
color_convert_check(hi_tde_fill_color * fill_color,hi_tde_surface * sur,hi_u32 * out_color,tde_colorfmt_transform * color_trans)488 static hi_s32 color_convert_check(hi_tde_fill_color *fill_color, hi_tde_surface *sur, hi_u32 *out_color,
489     tde_colorfmt_transform *color_trans)
490 {
491     if (fill_color == HI_NULL) {
492         tde_error("pstFillColor is null %s(line=%d)\n", __FUNCTION__, __LINE__);
493         return HI_ERR_TDE_NULL_PTR;
494     }
495     if (sur == HI_NULL) {
496         tde_error("pstSur is null %s(line=%d)\n", __FUNCTION__, __LINE__);
497         return HI_ERR_TDE_NULL_PTR;
498     }
499     if (out_color == HI_NULL) {
500         tde_error("pu32OutColor is null %s(line=%d)\n", __FUNCTION__, __LINE__);
501         return HI_ERR_TDE_NULL_PTR;
502     }
503     *color_trans = tde_osi_get_fmt_trans_type(fill_color->color_fmt, sur->color_fmt);
504 
505     if (((fill_color->color_fmt >= HI_TDE_COLOR_FMT_CLUT1) &&
506          (fill_color->color_fmt <= HI_TDE_COLOR_FMT_A8)) ||
507         (fill_color->color_fmt >= HI_TDE_COLOR_FMT_YCBCR422)) {
508         tde_error("Unsupported color!\n");
509         return -1;
510     }
511     return 0;
512 }
513 
tde_osi_color_convert(hi_tde_fill_color * fill_color,hi_tde_surface * sur,hi_u32 * out_color)514 static hi_s32 tde_osi_color_convert(hi_tde_fill_color *fill_color, hi_tde_surface *sur, hi_u32 *out_color)
515 {
516     hi_u8 a, r, g, b, y, cb, cr;
517     hi_s32 ret;
518     tde_colorfmt_transform color_trans;
519 
520     ret = color_convert_check(fill_color, sur, out_color, &color_trans);
521     if (ret != 0) {
522         return ret;
523     }
524     a = (fill_color->color_value >> g_fmt_bit_and_offset_array[fill_color->color_fmt].alpha_offset) &
525         /* 8 Data from the, 0xff mask */
526         (0xff >> (8 - g_fmt_bit_and_offset_array[fill_color->color_fmt].alpha_bits));
527     r = (fill_color->color_value >> g_fmt_bit_and_offset_array[fill_color->color_fmt].red_offset) &
528         /* 8 Data from the, 0xff mask */
529         (0xff >> (8 - g_fmt_bit_and_offset_array[fill_color->color_fmt].red_bits));
530     g = (fill_color->color_value >> g_fmt_bit_and_offset_array[fill_color->color_fmt].green_offset) &
531         /* 8 Data from the, 0xff mask */
532         (0xff >> (8 - g_fmt_bit_and_offset_array[fill_color->color_fmt].green_bits));
533     b = (fill_color->color_value >> g_fmt_bit_and_offset_array[fill_color->color_fmt].blue_offset) &
534         /* 8 Data from the, 0xff mask */
535         (0xff >> (8 - g_fmt_bit_and_offset_array[fill_color->color_fmt].blue_bits));
536 
537     if ((HI_TDE_COLOR_FMT_ARGB1555 <= fill_color->color_fmt) &&
538         (fill_color->color_fmt <= HI_TDE_COLOR_FMT_BGRA1555)) {
539         if (a) {
540             a = sur->alpha1;
541         } else {
542             a = sur->alpha0;
543         }
544     } else {
545         a = a << (8 - g_fmt_bit_and_offset_array[fill_color->color_fmt].alpha_bits); /* 8 Data from the */
546     }
547 
548     r = r << (8 - g_fmt_bit_and_offset_array[fill_color->color_fmt].red_bits);   /* 8 Data from the */
549     g = g << (8 - g_fmt_bit_and_offset_array[fill_color->color_fmt].green_bits); /* 8 Data from the */
550     b = b << (8 - g_fmt_bit_and_offset_array[fill_color->color_fmt].blue_bits);  /* 8 Data from the */
551 
552     switch (color_trans) {
553         case TDE_COLORFMT_TRANSFORM_ARGB_ARGB:
554         case TDE_COLORFMT_TRANSFORM_YCBCR_YCBCR:
555             *out_color = (a << 24) + (r << 16) + (g << 8) + b;   /* 8 16 24 Data from the */
556             return 0;
557         case TDE_COLORFMT_TRANSFORM_ARGB_YCBCR:
558             rgb2ycc(r, g, b, y, cb, cr);
559             *out_color = (a << 24) + (y << 16) + (cb << 8) + cr; /* 8 16 24 Data from the */
560             return 0;
561         case TDE_COLORFMT_TRANSFORM_YCBCR_ARGB:
562             ycc2rgb(r, g, b, y, cb, cr);
563             *out_color = (a << 24) + (y << 16) + (cb << 8) + cr; /* 8 16 24 Data from the */
564             return 0;
565         default:
566             tde_error("Unsupported color transport!\n");
567             return -1;
568     }
569 }
570 
571 /*
572  * Function:      tde_osi_check_resize_para
573  * Description:   check zoom ratio limit
574  * Return:        TDE_COLORFMT_CATEGORY_E   pixel format category
575  */
tde_osi_check_resize_para(hi_u32 in_width,hi_u32 in_height,hi_u32 out_width,hi_u32 out_height)576 static hi_s32 tde_osi_check_resize_para(hi_u32 in_width, hi_u32 in_height,
577                                         hi_u32 out_width, hi_u32 out_height)
578 {
579     if (((in_width > TDE_MAX_RECT_WIDTH)) ||
580         (in_height > TDE_MAX_RECT_HEIGHT) || ((out_width > TDE_MAX_RECT_WIDTH)) ||
581         (out_height > TDE_MAX_RECT_HEIGHT)) {
582         if ((in_width != out_width) || (in_height != out_height)) {
583             tde_error("Can not support resize!\n");
584             return HI_ERR_TDE_INVALID_PARA;
585         }
586     }
587 
588     if (((out_width * TDE_MAX_MINIFICATION_H) < in_width) ||
589         ((out_height * TDE_MAX_MINIFICATION_V) < in_height)) {
590         tde_error("Resize parameter error!\n");
591         return -1;
592     } else {
593         return 0;
594     }
595 }
596 
597 #if (TDE_CAPABILITY & ROTATE)
tde_osi_check_rotate_para(hi_tde_single_src * single_src,hi_tde_rotate_angle rotate_angle)598 static hi_s32 tde_osi_check_rotate_para(hi_tde_single_src *single_src, hi_tde_rotate_angle rotate_angle)
599 {
600     hi_bool is_unsupport_format = ((single_src->src_surface->color_fmt != HI_TDE_COLOR_FMT_RGB888) &&
601                                    ((single_src->src_surface->color_fmt != HI_TDE_COLOR_FMT_YCBCR888)) &&
602                                    (single_src->src_surface->color_fmt != HI_TDE_COLOR_FMT_YCBCR422) &&
603                                    (single_src->src_surface->color_fmt != HI_TDE_COLOR_FMT_PKGVYUY) && (
604                                    (single_src->src_surface->color_fmt != HI_TDE_COLOR_FMT_ARGB8888)) &&
605                                    (single_src->src_surface->color_fmt != HI_TDE_COLOR_FMT_ARGB4444) &&
606                                    (single_src->src_surface->color_fmt != HI_TDE_COLOR_FMT_ARGB1555));
607 
608     if (rotate_angle >= HI_TDE_ROTATE_MAX) {
609         tde_error("enRotateMode error!\n");
610         return HI_ERR_TDE_INVALID_PARA;
611     }
612 
613     if (single_src->src_surface->color_fmt != single_src->dst_surface->color_fmt) {
614         tde_error("Rotate parameter error!\n");
615         return -1;
616     }
617     if (is_unsupport_format) {
618         tde_error("Rotate Operation can not support the format!\n");
619         return -1;
620     }
621 
622     if (((single_src->src_surface->color_fmt == HI_TDE_COLOR_FMT_YCBCR422) ||
623          (single_src->src_surface->color_fmt == HI_TDE_COLOR_FMT_PKGVYUY)) &&
624         ((single_src->src_rect->height & 0x1) || (single_src->src_rect->width & 0x1))) {
625         tde_error("Height, width of YCbCr422R couldn't be odd!\n");
626         return -1;
627     }
628 
629     if ((single_src->src_surface->phy_addr % 4) || (single_src->dst_surface->phy_addr % 4)) { /* 4 alg data */
630         tde_error("Bitmap address is not aligned!\n");
631         return -1;
632     }
633 
634     if ((single_src->src_surface->stride % 4) || (single_src->dst_surface->stride % 4)) { /* 4 alg data */
635         tde_error("stride is not aligned!\n");
636         return -1;
637     }
638 
639     if ((rotate_angle != HI_TDE_ROTATE_CLOCKWISE_180) &&
640         ((single_src->src_rect->height != single_src->dst_rect->width) ||
641          (single_src->src_rect->width != single_src->dst_rect->height))) {
642         tde_error("Rotate operation rect is wrong!\n");
643         return -1;
644     }
645 
646     if ((rotate_angle == HI_TDE_ROTATE_CLOCKWISE_180) &&
647         ((single_src->src_rect->height != single_src->dst_rect->height) ||
648          (single_src->src_rect->width != single_src->dst_rect->width))) {
649         tde_error("Rotate 180 operation rect is wrong!\n");
650         return -1;
651     }
652 
653     return 0;
654 }
655 #endif
656 
657 #if (TDE_CAPABILITY & COMPRESS)
tde_osi_check_compress_para(hi_tde_surface * fore_ground,hi_tde_rect * fore_ground_rect,hi_tde_surface * dst_surface,hi_tde_rect * dst_rect,hi_tde_opt * opt)658 static hi_s32 tde_osi_check_compress_para(hi_tde_surface *fore_ground, hi_tde_rect *fore_ground_rect,
659                                           hi_tde_surface *dst_surface, hi_tde_rect *dst_rect, hi_tde_opt *opt)
660 {
661     hi_unused(fore_ground);
662     hi_unused(fore_ground_rect);
663     hi_unused(dst_rect);
664     if ((dst_surface->color_fmt != HI_TDE_COLOR_FMT_ARGB1555) &&
665         (dst_surface->color_fmt != HI_TDE_COLOR_FMT_ARGB8888) &&
666         (dst_surface->color_fmt != HI_TDE_COLOR_FMT_ARGB4444) &&
667         (dst_surface->color_fmt != HI_TDE_COLOR_FMT_RGB888)   &&
668         (dst_surface->color_fmt != HI_TDE_COLOR_FMT_YCBCR888) &&
669         (dst_surface->color_fmt != HI_TDE_COLOR_FMT_RGB565)) {
670         tde_error("Compress operation can not support the fmt !\n");
671         return HI_ERR_TDE_INVALID_PARA;
672     }
673     if (opt->mirror) {
674         tde_error("Could not support Mirror\n!");
675         return -1;
676     }
677     if (opt->clip_mode != HI_TDE_CLIP_MODE_NONE) {
678         tde_error("Could not support Clip\n!");
679         return -1;
680     }
681     return 0;
682 }
683 
tde_osi_check_decompress_para(hi_tde_surface * fore_ground,hi_tde_rect * fore_ground_rect,hi_tde_surface * dst_surface,hi_tde_rect * dst_rect,hi_tde_opt * opt)684 static hi_s32 tde_osi_check_decompress_para(hi_tde_surface *fore_ground, hi_tde_rect *fore_ground_rect,
685                                             hi_tde_surface *dst_surface, hi_tde_rect *dst_rect, hi_tde_opt *opt)
686 {
687     hi_unused(fore_ground_rect);
688     hi_unused(dst_surface);
689     hi_unused(dst_rect);
690     if ((fore_ground->color_fmt != HI_TDE_COLOR_FMT_ARGB1555) &&
691         (fore_ground->color_fmt != HI_TDE_COLOR_FMT_ARGB8888) &&
692         (fore_ground->color_fmt != HI_TDE_COLOR_FMT_ARGB4444) &&
693         (fore_ground->color_fmt != HI_TDE_COLOR_FMT_RGB888)   &&
694         (fore_ground->color_fmt != HI_TDE_COLOR_FMT_YCBCR888) &&
695         (fore_ground->color_fmt != HI_TDE_COLOR_FMT_RGB565)) {
696         tde_error("Compress operation can not support the fmt !\n");
697         return HI_ERR_TDE_INVALID_PARA;
698     }
699     if (opt->mirror) {
700         tde_error("Could not support Mirror\n!");
701         return -1;
702     }
703     return 0;
704 }
705 
706 #endif
707 
tde_osi_covert_mb_fmt(hi_tde_mb_color_fmt fmt)708 hi_tde_color_fmt tde_osi_covert_mb_fmt(hi_tde_mb_color_fmt fmt)
709 {
710     switch (fmt) {
711         case HI_TDE_MB_COLOR_FMT_JPG_YCBCR400MBP:
712             return HI_TDE_COLOR_FMT_JPG_YCBCR400MBP;
713         case HI_TDE_MB_COLOR_FMT_JPG_YCBCR422MBHP:
714             return HI_TDE_COLOR_FMT_JPG_YCBCR422MBHP;
715         case HI_TDE_MB_COLOR_FMT_JPG_YCBCR422MBVP:
716             return HI_TDE_COLOR_FMT_JPG_YCBCR422MBVP;
717         case HI_TDE_MB_COLOR_FMT_MP1_YCBCR420MBP:
718             return HI_TDE_COLOR_FMT_MP1_YCBCR420MBP;
719         case HI_TDE_MB_COLOR_FMT_MP2_YCBCR420MBP:
720             return HI_TDE_COLOR_FMT_MP2_YCBCR420MBP;
721         case HI_TDE_MB_COLOR_FMT_MP2_YCBCR420MBI:
722             return HI_TDE_COLOR_FMT_MP2_YCBCR420MBI;
723         case HI_TDE_MB_COLOR_FMT_JPG_YCBCR420MBP:
724             return HI_TDE_COLOR_FMT_JPG_YCBCR420MBP;
725         case HI_TDE_MB_COLOR_FMT_JPG_YCBCR444MBP:
726             return HI_TDE_COLOR_FMT_JPG_YCBCR444MBP;
727         default:
728             return HI_TDE_COLOR_FMT_MAX;
729     }
730 }
731 
732 /*
733  * Function:      tde_osi_get_fmt_category
734  * Description:   get pixel format category info
735  * Input:         fmt: pixel format
736  * Return:        TDE_COLORFMT_CATEGORY_E  pixel format category
737  */
tde_osi_get_fmt_category(hi_tde_color_fmt fmt)738 static tde_colorfmt_category tde_osi_get_fmt_category(hi_tde_color_fmt fmt)
739 {
740     /* target is ARGB format */
741     if (fmt <= HI_TDE_COLOR_FMT_RABG8888) {
742         return TDE_COLORFMT_CATEGORY_ARGB;
743     } else if (fmt <= HI_TDE_COLOR_FMT_ACLUT88) {
744         /* target is CLUT table format */
745         return TDE_COLORFMT_CATEGORY_CLUT;
746     } else if (fmt <= HI_TDE_COLOR_FMT_A8) {
747         /* target is alpha CLUT table format */
748         return TDE_COLORFMT_CATEGORY_AN;
749     } else if (fmt <= HI_TDE_COLOR_FMT_PKGVYUY) {
750         /* target is YCbCr format */
751         return TDE_COLORFMT_CATEGORY_YCBCR;
752     } else if (fmt == HI_TDE_COLOR_FMT_BYTE) {
753         /* byte format */
754         return TDE_COLORFMT_CATEGORY_BYTE;
755     } else if (fmt == HI_TDE_COLOR_FMT_HALFWORD) {
756         /* halfword  format */
757         return TDE_COLORFMT_CATEGORY_HALFWORD;
758     } else if (fmt <= HI_TDE_COLOR_FMT_JPG_YCBCR444MBP) {
759         return TDE_COLORFMT_CATEGORY_YCBCR;
760     } else {
761         /* error format */
762         return TDE_COLORFMT_CATEGORY_BUTT;
763     }
764 }
765 
766 /*
767  * Function:      tde_osi_get_fmt_trans_type
768  * Description:   get pixel format transform type
769  * Input:         src2_fmt: foreground pixel format
770                   dst_fmt: target pixel format
771  * Return:        TDE_COLORFMT_TRANSFORM_E pixel format transform type
772  */
tde_osi_get_fmt_trans_type(hi_tde_color_fmt src2_fmt,hi_tde_color_fmt dst_fmt)773 static tde_colorfmt_transform tde_osi_get_fmt_trans_type(hi_tde_color_fmt src2_fmt, hi_tde_color_fmt dst_fmt)
774 {
775     tde_colorfmt_category src_category;
776     tde_colorfmt_category dst_category;
777 
778     /* get foreground pixel format category */
779     src_category = tde_osi_get_fmt_category(src2_fmt);
780 
781     /* get target pixel format category */
782     dst_category = tde_osi_get_fmt_category(dst_fmt);
783 
784     switch (src_category) {
785         case TDE_COLORFMT_CATEGORY_ARGB:
786             if (dst_category == TDE_COLORFMT_CATEGORY_ARGB) {
787                 return TDE_COLORFMT_TRANSFORM_ARGB_ARGB;
788             } else if (dst_category == TDE_COLORFMT_CATEGORY_YCBCR) {
789                 return TDE_COLORFMT_TRANSFORM_ARGB_YCBCR;
790             } else if (dst_category == TDE_COLORFMT_CATEGORY_AN) {
791                 return TDE_COLORFMT_TRANSFORM_ARGB_AN;
792             }
793             return TDE_COLORFMT_TRANSFORM_BUTT;
794 
795         case TDE_COLORFMT_CATEGORY_CLUT:
796             if (dst_category == TDE_COLORFMT_CATEGORY_ARGB) {
797                 return TDE_COLORFMT_TRANSFORM_CLUT_ARGB;
798             } else if (dst_category == TDE_COLORFMT_CATEGORY_YCBCR) {
799                 return TDE_COLORFMT_TRANSFORM_CLUT_YCBCR;
800             } else if (dst_category == TDE_COLORFMT_CATEGORY_CLUT) {
801                 return TDE_COLORFMT_TRANSFORM_CLUT_CLUT;
802             }
803             return TDE_COLORFMT_TRANSFORM_BUTT;
804 
805         case TDE_COLORFMT_CATEGORY_YCBCR:
806             if (dst_category == TDE_COLORFMT_CATEGORY_ARGB) {
807                 return TDE_COLORFMT_TRANSFORM_YCBCR_ARGB;
808             } else if (dst_category == TDE_COLORFMT_CATEGORY_YCBCR) {
809                 return TDE_COLORFMT_TRANSFORM_YCBCR_YCBCR;
810             } else if (dst_category == TDE_COLORFMT_CATEGORY_AN) {
811                 return TDE_COLORFMT_TRANSFORM_ARGB_AN;
812             }
813             return TDE_COLORFMT_TRANSFORM_BUTT;
814 
815         case TDE_COLORFMT_CATEGORY_AN:
816             if (dst_category == TDE_COLORFMT_CATEGORY_AN) {
817                 return TDE_COLORFMT_TRANSFORM_AN_AN;
818             }
819             return TDE_COLORFMT_TRANSFORM_BUTT;
820 
821         default:
822             return TDE_COLORFMT_TRANSFORM_BUTT;
823     }
824 }
825 
826 /*
827  * Function:      tde_osi_is_single_src_to_rop
828  * Description:   query if ROP operate is if single source2 operate
829  * Input:         rop: rop operate type
830  * Return:        HI_TRUE: single ROP;HI_FALSE: non single ROP
831  */
832 #if (TDE_CAPABILITY & ROP)
tde_osi_is_single_src_to_rop(hi_tde_rop_mode rop)833 static hi_bool tde_osi_is_single_src_to_rop(hi_tde_rop_mode rop)
834 {
835     switch (rop) {
836         case HI_TDE_ROP_BLACK:
837         case HI_TDE_ROP_NOTCOPYPEN:
838         case HI_TDE_ROP_COPYPEN:
839         case HI_TDE_ROP_WHITE:
840             return HI_TRUE;
841 
842         default:
843             return HI_FALSE;
844     }
845 }
846 #endif
847 
848 /*
849  * Function:      tde_osi_get_clut_usage
850  * Description:   get CLUT table usage
851  * Input:         src_fmt foreground pixel format
852                   dst_fmt  target pixel format
853  * Return:        TDE_CLUT_USAGE_E:  clut  usage
854  */
tde_osi_get_clut_usage(hi_tde_color_fmt src_fmt,hi_tde_color_fmt dst_fmt)855 static tde_clut_usage tde_osi_get_clut_usage(hi_tde_color_fmt src_fmt, hi_tde_color_fmt dst_fmt)
856 {
857     tde_colorfmt_transform color_trans_type;
858 
859     color_trans_type = tde_osi_get_fmt_trans_type(src_fmt, dst_fmt);
860 
861     switch (color_trans_type) {
862         case TDE_COLORFMT_TRANSFORM_CLUT_ARGB:
863         case TDE_COLORFMT_TRANSFORM_CLUT_YCBCR:
864             return TDE_CLUT_COLOREXPENDING; /* color expand */
865 
866         case TDE_COLORFMT_TRANSFORM_ARGB_ARGB:
867         case TDE_COLORFMT_TRANSFORM_YCBCR_YCBCR:
868             return TDE_CLUT_COLORCORRECT; /* color adjust */
869 
870         case TDE_COLORFMT_TRANSFORM_CLUT_CLUT:
871             return TDE_CLUT_CLUT_BYPASS;
872 
873         default:
874             return TDE_CLUT_USAGE_BUTT;
875     }
876 }
877 
tde_osi_whether_contain_alpha(hi_tde_color_fmt color_fmt)878 static hi_bool tde_osi_whether_contain_alpha(hi_tde_color_fmt color_fmt)
879 {
880     switch (color_fmt) {
881         case HI_TDE_COLOR_FMT_ARGB4444:
882         case HI_TDE_COLOR_FMT_ABGR4444:
883         case HI_TDE_COLOR_FMT_RGBA4444:
884         case HI_TDE_COLOR_FMT_BGRA4444:
885         case HI_TDE_COLOR_FMT_ARGB1555:
886         case HI_TDE_COLOR_FMT_ABGR1555:
887         case HI_TDE_COLOR_FMT_RGBA1555:
888         case HI_TDE_COLOR_FMT_BGRA1555:
889         case HI_TDE_COLOR_FMT_ARGB8565:
890         case HI_TDE_COLOR_FMT_ABGR8565:
891         case HI_TDE_COLOR_FMT_RGBA8565:
892         case HI_TDE_COLOR_FMT_BGRA8565:
893         case HI_TDE_COLOR_FMT_ARGB8888:
894         case HI_TDE_COLOR_FMT_ABGR8888:
895         case HI_TDE_COLOR_FMT_RGBA8888:
896         case HI_TDE_COLOR_FMT_BGRA8888:
897         case HI_TDE_COLOR_FMT_AYCBCR8888:
898         case HI_TDE_COLOR_FMT_RABG8888:
899             return HI_TRUE;
900         default:
901             return HI_FALSE;
902     }
903 }
904 
905 /*
906  * Function:      tde_osi_set_clut_opt
907  * Description:   set clut parameter
908  * Input:         clut_sur Clut bitmap info
909  *                pen_clut_usage  return clut usage type: expand/adjust
910  *                clut_reload   if reload clut
911  *                hw_node     hardware node information
912  * Return:        TDE_CLUT_USAGE_E: clut usage
913  */
tde_osi_set_clut_opt(hi_tde_surface * clut_sur,hi_tde_surface * out_sur,tde_clut_usage * pen_clut_usage,hi_bool clut_reload,tde_hw_node * hw_node)914 static hi_s32 tde_osi_set_clut_opt(hi_tde_surface *clut_sur, hi_tde_surface *out_sur, tde_clut_usage *pen_clut_usage,
915                                    hi_bool clut_reload, tde_hw_node *hw_node)
916 {
917     tde_colorfmt_category fmt_cate;
918     tde_clut_cmd clut_cmd;
919     hi_u64 clut_phyaddr;
920     /* 0xffffffffffffffffUL flag value */
921     if (!((clut_sur->clut_phy_addr != 0xffffffffffffffffUL) && (clut_sur->clut_phy_addr != 0))) {
922         return HI_SUCCESS;
923     }
924     clut_phyaddr = clut_sur->clut_phy_addr;
925     fmt_cate = tde_osi_get_fmt_category(out_sur->color_fmt);
926     /* when user input the type of clut is not consistent with output format,return error */
927     if ((!clut_sur->is_ycbcr_clut && (fmt_cate == TDE_COLORFMT_CATEGORY_YCBCR)) ||
928         (clut_sur->is_ycbcr_clut && (fmt_cate == TDE_COLORFMT_CATEGORY_ARGB))) {
929         tde_error("clut fmt not same\n");
930         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
931     }
932 
933     /*
934      * Because of unsupported output CSC, input and background color zone is consistent.
935      * In trine sources operation,clut need use background, so output color zone instand of background's
936      */
937     *pen_clut_usage = tde_osi_get_clut_usage(clut_sur->color_fmt, out_sur->color_fmt);
938 
939     if (*pen_clut_usage >= TDE_CLUT_CLUT_BYPASS) {
940         return HI_SUCCESS;
941     }
942 
943     if (*pen_clut_usage == TDE_CLUT_COLOREXPENDING) {
944         clut_cmd.clut_mode = TDE_COLOR_EXP_CLUT_MODE;
945     } else {
946         clut_cmd.clut_mode = TDE_COLOR_CORRCT_CLUT_MODE;
947     }
948 
949     if (osal_div_u64_rem(clut_phyaddr, 4)) { /* 4 size */
950         tde_error("clut_phy_addr=0x%llx is not aligned!\n", clut_sur->clut_phy_addr);
951         return HI_ERR_TDE_NOT_ALIGNED;
952     }
953 
954     clut_cmd.phy_clut_addr = clut_sur->clut_phy_addr;
955 
956     if (tde_hal_node_set_clut_opt(hw_node, &clut_cmd, clut_reload) != HI_SUCCESS) {
957         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
958     }
959 
960     return HI_SUCCESS;
961 }
962 
tde_osi_check_single_opt(hi_tde_opt * opt)963 static hi_s32 tde_osi_check_single_opt(hi_tde_opt *opt)
964 {
965     hi_bool real = (((opt->blend_opt.global_alpha_en != HI_TRUE) && (opt->blend_opt.global_alpha_en != HI_FALSE)) ||
966         ((opt->blend_opt.pixel_alpha_en != HI_TRUE) && (opt->blend_opt.pixel_alpha_en != HI_FALSE)) ||
967         ((opt->blend_opt.src1_alpha_premulti != HI_TRUE) && (opt->blend_opt.src1_alpha_premulti != HI_FALSE)) ||
968         ((opt->blend_opt.src2_alpha_premulti != HI_TRUE) && (opt->blend_opt.src2_alpha_premulti != HI_FALSE)) ||
969         ((opt->clut_reload != HI_TRUE) && (opt->clut_reload != HI_FALSE)) ||
970         ((opt->resize != HI_TRUE) && (opt->resize != HI_FALSE)) ||
971         ((opt->is_compress != HI_TRUE) && (opt->is_compress != HI_FALSE)) ||
972         ((opt->is_decompress != HI_TRUE) && (opt->is_decompress != HI_FALSE)));
973 
974     /* return error, if enable color key */
975     if (opt->color_key_mode != HI_TDE_COLOR_KEY_MODE_NONE) {
976         tde_error("It doesn't support colorkey in single source mode!\n");
977         return -1;
978     }
979 
980     if (opt->alpha_blending_cmd >= HI_TDE_ALPHA_BLENDING_MAX) {
981         tde_error("alpha_blending_cmd error!\n");
982         return HI_ERR_TDE_INVALID_PARA;
983     }
984 
985     if (real) {
986         tde_error("hi_bool should be HI_TRUE or HI_FALSE!!\n");
987         return HI_ERR_TDE_INVALID_PARA;
988     }
989 
990     if ((opt->deflicker_mode >= HI_TDE_DEFLICKER_LEVEL_MODE_MAX) ||
991         (opt->deflicker_mode < HI_TDE_DEFLICKER_LEVEL_MODE_NONE)) {
992         tde_error("deflicker_mode error!\n");
993         return HI_ERR_TDE_INVALID_PARA;
994     }
995 
996     if ((opt->mirror >= HI_TDE_MIRROR_MAX) || (opt->mirror < HI_TDE_MIRROR_NONE)) {
997         tde_error("mirror error!\n");
998         return HI_ERR_TDE_INVALID_PARA;
999     }
1000 
1001     if ((opt->filter_mode >= HI_TDE_FILTER_MODE_MAX) || (opt->filter_mode < HI_TDE_FILTER_MODE_COLOR)) {
1002         tde_error("filter_mode error!\n");
1003         return HI_ERR_TDE_INVALID_PARA;
1004     }
1005 
1006     return HI_SUCCESS;
1007 }
1008 
1009 #if ((HICHIP == HI3519A_V100) || (HICHIP == HI3516C_V500))
tde_osi_check_dst_fmt(hi_tde_color_fmt fmt)1010 static hi_s32 tde_osi_check_dst_fmt(hi_tde_color_fmt fmt)
1011 {
1012     if (((fmt >= HI_TDE_COLOR_FMT_JPG_YCBCR400MBP) && (fmt <= HI_TDE_COLOR_FMT_JPG_YCBCR422MBVP)) ||
1013         (fmt >= HI_TDE_COLOR_FMT_JPG_YCBCR444MBP) || ((fmt >= HI_TDE_COLOR_FMT_CLUT1) &&
1014         (fmt <= HI_TDE_COLOR_FMT_A8))) {
1015         tde_error("This enFmt %d doesn't support!\n", fmt);
1016         return HI_ERR_TDE_INVALID_PARA;
1017     }
1018     return HI_SUCCESS;
1019 }
1020 #else
tde_osi_check_dst_fmt(hi_tde_color_fmt fmt)1021 static hi_s32 tde_osi_check_dst_fmt(hi_tde_color_fmt fmt)
1022 {
1023     if (((fmt >= HI_TDE_COLOR_FMT_YCBCR888) && (fmt <= HI_TDE_COLOR_FMT_PKGVYUY)) ||
1024         ((fmt >= HI_TDE_COLOR_FMT_JPG_YCBCR400MBP) &&
1025         (fmt <= HI_TDE_COLOR_FMT_JPG_YCBCR422MBVP)) ||
1026         (fmt >= HI_TDE_COLOR_FMT_JPG_YCBCR444MBP) ||
1027         ((fmt >= HI_TDE_COLOR_FMT_CLUT1) && (fmt <= HI_TDE_COLOR_FMT_A8))) {
1028         tde_error("This enFmt %d doesn't support!\n", fmt);
1029         return HI_ERR_TDE_INVALID_PARA;
1030     }
1031     return HI_SUCCESS;
1032 }
1033 #endif
1034 
1035 /*
1036  * Function:      tde_osi_check_single_src_to_opt
1037  * Description:   check if valid of foreground single source operate
1038  * Input:         src2_fmt foreground pixel format
1039                   dst_fmt  target pixel format
1040                   opt     operate attribute pointer
1041  * Return:        0  valid parameter;
1042                   -1 invalid parameter;
1043  */
tde_osi_check_single_src_to_opt(hi_tde_color_fmt src2_fmt,hi_tde_color_fmt dst_fmt,hi_tde_opt * opt)1044 static hi_s32 tde_osi_check_single_src_to_opt(hi_tde_color_fmt src2_fmt, hi_tde_color_fmt dst_fmt, hi_tde_opt *opt)
1045 {
1046     tde_colorfmt_transform color_trans_type;
1047     hi_s32 ret = tde_osi_check_single_opt(opt);
1048     if (ret != HI_SUCCESS) {
1049         return ret;
1050     }
1051 
1052 #if (TDE_CAPABILITY & ROP)
1053     /* if operate type is ROP and it is not single operate,return error */
1054     if ((hi_u32)opt->alpha_blending_cmd & HI_TDE_ALPHA_BLENDING_ROP) {
1055         if (((opt->rop_alpha >= HI_TDE_ROP_MAX) || (opt->rop_alpha < HI_TDE_ROP_BLACK)) ||
1056             ((opt->rop_color >= HI_TDE_ROP_MAX) || (opt->rop_color < HI_TDE_ROP_BLACK))) {
1057             return HI_ERR_TDE_INVALID_PARA;
1058         }
1059 
1060         if ((!tde_osi_is_single_src_to_rop(opt->rop_alpha)) || (!tde_osi_is_single_src_to_rop(opt->rop_color))) {
1061             tde_error("Only support single s2 rop!\n");
1062             return -1;
1063         }
1064     }
1065 #endif
1066     /* single source can not do blend operate */
1067     if ((hi_u32)opt->alpha_blending_cmd & HI_TDE_ALPHA_BLENDING_BLEND) {
1068         tde_error("Alu mode error!\n");
1069         return -1;
1070     }
1071     ret = tde_osi_check_dst_fmt(dst_fmt);
1072     if (ret != HI_SUCCESS) {
1073         return ret;
1074     }
1075     color_trans_type = tde_osi_get_fmt_trans_type(src2_fmt, dst_fmt);
1076     if (color_trans_type == TDE_COLORFMT_TRANSFORM_BUTT) {
1077         tde_error("Unknown color transport type!\n");
1078         return -1;
1079     }
1080 
1081     if (color_trans_type == TDE_COLORFMT_TRANSFORM_CLUT_CLUT) {
1082         /* unsupported deflicker,zoom, Rop, mirror,colorize */
1083         if ((opt->resize) || (opt->deflicker_mode != HI_TDE_DEFLICKER_LEVEL_MODE_NONE) ||
1084             ((hi_u32)opt->alpha_blending_cmd & HI_TDE_ALPHA_BLENDING_ROP) ||
1085             ((hi_u32)opt->alpha_blending_cmd & HI_TDE_ALPHA_BLENDING_COLORIZE)) {
1086             tde_error("It doesn't support deflicker or ROP or mirror!\n");
1087             return -1;
1088         }
1089     }
1090 
1091     return 0;
1092 }
1093 
tde_osi_check_bool_single_opt(hi_tde_opt * opt)1094 static hi_s32 tde_osi_check_bool_single_opt(hi_tde_opt *opt)
1095 {
1096     hi_bool real = (((opt->blend_opt.global_alpha_en != HI_TRUE) && (opt->blend_opt.global_alpha_en != HI_FALSE)) ||
1097         ((opt->blend_opt.pixel_alpha_en != HI_TRUE) && (opt->blend_opt.pixel_alpha_en != HI_FALSE)) ||
1098         ((opt->blend_opt.src1_alpha_premulti != HI_TRUE) && (opt->blend_opt.src1_alpha_premulti != HI_FALSE)) ||
1099         ((opt->blend_opt.src2_alpha_premulti != HI_TRUE) && (opt->blend_opt.src2_alpha_premulti != HI_FALSE)) ||
1100         ((opt->clut_reload != HI_TRUE) && (opt->clut_reload != HI_FALSE)) ||
1101         ((opt->resize != HI_TRUE) && (opt->resize != HI_FALSE)) ||
1102         ((opt->is_compress != HI_TRUE) && (opt->is_compress != HI_FALSE)) ||
1103         ((opt->is_decompress != HI_TRUE) && (opt->is_decompress != HI_FALSE)));
1104     if (real) {
1105         tde_error("hi_bool should be HI_TRUE or HI_FALSE!!\n");
1106         return HI_ERR_TDE_INVALID_PARA;
1107     }
1108 
1109     if ((opt->deflicker_mode >= HI_TDE_DEFLICKER_LEVEL_MODE_MAX) ||
1110         (opt->deflicker_mode < HI_TDE_DEFLICKER_LEVEL_MODE_NONE)) {
1111         tde_error("deflicker_mode error!\n");
1112         return HI_ERR_TDE_INVALID_PARA;
1113     }
1114 
1115     if ((opt->mirror >= HI_TDE_MIRROR_MAX) || (opt->mirror < HI_TDE_MIRROR_NONE)) {
1116         tde_error("mirror error!\n");
1117         return HI_ERR_TDE_INVALID_PARA;
1118     }
1119 
1120     if ((opt->filter_mode >= HI_TDE_FILTER_MODE_MAX) || (opt->filter_mode < HI_TDE_FILTER_MODE_COLOR)) {
1121         tde_error("filter_mode error!\n");
1122         return HI_ERR_TDE_INVALID_PARA;
1123     }
1124     return HI_SUCCESS;
1125 }
1126 
tde_osi_check_fmt_single_opt(hi_tde_color_fmt src1_fmt,hi_tde_opt * opt)1127 static hi_s32 tde_osi_check_fmt_single_opt(hi_tde_color_fmt src1_fmt, hi_tde_opt *opt)
1128 {
1129     hi_s32 ret;
1130 
1131 #if ((HICHIP == HI3519A_V100) || (HICHIP == HI3516C_V500))
1132     if ((src1_fmt == HI_TDE_COLOR_FMT_YCBCR422) || (src1_fmt == HI_TDE_COLOR_FMT_PKGVYUY)) {
1133         tde_error("This operation doesn't support PKG!\n");
1134         return HI_ERR_TDE_INVALID_PARA;
1135     }
1136 #else
1137     hi_unused(src1_fmt);
1138 #endif
1139     if (opt->alpha_blending_cmd >= HI_TDE_ALPHA_BLENDING_MAX) {
1140         tde_error("alpha_blending_cmd error!\n");
1141         return HI_ERR_TDE_INVALID_PARA;
1142     }
1143     ret = tde_osi_check_bool_single_opt(opt);
1144     if (ret != HI_SUCCESS) {
1145         return ret;
1146     }
1147     return HI_SUCCESS;
1148 }
1149 
tde_osi_check_cmd_single_opt(hi_tde_opt * opt)1150 static hi_s32 tde_osi_check_cmd_single_opt(hi_tde_opt *opt)
1151 {
1152 #if (TDE_CAPABILITY & ROP)
1153     if ((hi_u32)opt->alpha_blending_cmd & HI_TDE_ALPHA_BLENDING_ROP) {
1154         if (((opt->rop_alpha >= HI_TDE_ROP_MAX) || (opt->rop_alpha < HI_TDE_ROP_BLACK)) ||
1155             ((opt->rop_color >= HI_TDE_ROP_MAX) || (opt->rop_color < HI_TDE_ROP_BLACK))) {
1156             tde_error("enRopCode error!\n");
1157             return HI_ERR_TDE_INVALID_PARA;
1158         }
1159     }
1160 #endif
1161     if ((hi_u32)opt->alpha_blending_cmd & HI_TDE_ALPHA_BLENDING_BLEND) {
1162         if ((opt->blend_opt.blend_cmd >= HI_TDE_BLEND_CMD_MAX) ||
1163             (opt->blend_opt.blend_cmd < HI_TDE_BLEND_CMD_NONE)) {
1164             tde_error("Unknown blend cmd!\n");
1165             return HI_ERR_TDE_INVALID_PARA;
1166         }
1167 
1168         if (opt->blend_opt.blend_cmd == HI_TDE_BLEND_CMD_CONFIG) {
1169             if ((opt->blend_opt.src1_blend_mode >= HI_TDE_BLEND_MAX) ||
1170                 (opt->blend_opt.src2_blend_mode >= HI_TDE_BLEND_MAX)) {
1171                 tde_error("Unknown blend mode!\n");
1172                 return HI_ERR_TDE_INVALID_PARA;
1173             }
1174         }
1175     }
1176     return HI_SUCCESS;
1177 }
1178 
1179 /*
1180  * Function:      tde_osi_check_double_src_opt
1181  * Description:   check if valid of dual source operate
1182  * Input:         src1_fmt background pixel format
1183                   src2_fmt foreground pixel format
1184                   dst_fmt  target pixel format
1185                   opt    operate attribute operate
1186  * Return:        0  valid parameter;
1187                   -1 invalid parameter;
1188  */
tde_osi_check_double_src_opt(hi_tde_color_fmt src1_fmt,hi_tde_color_fmt src2_fmt,hi_tde_color_fmt dst_fmt,hi_tde_opt * opt)1189 static hi_s32 tde_osi_check_double_src_opt(hi_tde_color_fmt src1_fmt, hi_tde_color_fmt src2_fmt,
1190                                            hi_tde_color_fmt dst_fmt, hi_tde_opt *opt)
1191 {
1192     tde_colorfmt_category src1_category, src2_category, dst_category;
1193     hi_bool temp_fmt = HI_FALSE;
1194     hi_s32 ret = tde_osi_check_dst_fmt(dst_fmt);
1195     if (ret != HI_SUCCESS) {
1196         return ret;
1197     }
1198     ret = tde_osi_check_fmt_single_opt(src1_fmt, opt);
1199     if (ret != HI_SUCCESS) {
1200         return ret;
1201     }
1202     /* get background pixel format category */
1203     src1_category = tde_osi_get_fmt_category(src1_fmt);
1204 
1205     /* get foreground pixel format category  */
1206     src2_category = tde_osi_get_fmt_category(src2_fmt);
1207 
1208     /* get target pixel format category  */
1209     dst_category = tde_osi_get_fmt_category(dst_fmt);
1210     if ((src1_category >= TDE_COLORFMT_CATEGORY_BYTE) || (src2_category >= TDE_COLORFMT_CATEGORY_BYTE) ||
1211         (dst_category >= TDE_COLORFMT_CATEGORY_BYTE)) {
1212         tde_error("unknown format!\n");
1213         return HI_ERR_TDE_INVALID_PARA;
1214     }
1215     temp_fmt = tde_osi_whether_contain_alpha(dst_fmt);
1216     if (((src1_category == TDE_COLORFMT_CATEGORY_ARGB) || (src1_category == TDE_COLORFMT_CATEGORY_YCBCR)) &&
1217         (src2_category == TDE_COLORFMT_CATEGORY_AN) && (!temp_fmt)) {
1218         tde_error("Target must have alpha component!\n");
1219         return HI_ERR_TDE_INVALID_PARA;
1220     }
1221 
1222     if ((src1_category == TDE_COLORFMT_CATEGORY_CLUT) && ((src2_category != TDE_COLORFMT_CATEGORY_CLUT) ||
1223         (dst_category != TDE_COLORFMT_CATEGORY_CLUT))) {
1224         tde_error("Unsupported operation!\n");
1225         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
1226     }
1227     if (((opt->deflicker_mode != HI_TDE_DEFLICKER_LEVEL_MODE_NONE) ||
1228         (opt->resize) || (opt->alpha_blending_cmd != HI_TDE_ALPHA_BLENDING_NONE)) &&
1229         (src1_category == TDE_COLORFMT_CATEGORY_CLUT)) {
1230         tde_error("It doesn't support deflicker or ROP or mirror!\n");
1231         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
1232     }
1233 
1234     if ((src1_category == TDE_COLORFMT_CATEGORY_AN) && (src2_category == TDE_COLORFMT_CATEGORY_AN) &&
1235         (dst_category == TDE_COLORFMT_CATEGORY_AN) && (opt->alpha_blending_cmd != HI_TDE_ALPHA_BLENDING_NONE)) {
1236         tde_error("It doesn't support ROP or mirror!\n");
1237         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
1238     }
1239     ret = tde_osi_check_cmd_single_opt(opt);
1240     if (ret != HI_SUCCESS) {
1241         return ret;
1242     }
1243     return HI_SUCCESS;
1244 }
1245 
tde_osi_get_code1(tde_colorfmt_transform color_trans_type)1246 static hi_u16 tde_osi_get_code1(tde_colorfmt_transform color_trans_type)
1247 {
1248     switch (color_trans_type) {
1249         case TDE_COLORFMT_TRANSFORM_ARGB_ARGB:
1250             return 0x0;
1251         case TDE_COLORFMT_TRANSFORM_ARGB_YCBCR:
1252             return 0x5;
1253         case TDE_COLORFMT_TRANSFORM_CLUT_ARGB:
1254             return 0x8;
1255         case TDE_COLORFMT_TRANSFORM_CLUT_YCBCR:
1256             return 0x8 | 0x10 | 0x1;
1257         case TDE_COLORFMT_TRANSFORM_YCBCR_ARGB:
1258             return 0x1;
1259         case TDE_COLORFMT_TRANSFORM_YCBCR_YCBCR:
1260             return 0x0;
1261         default:
1262             return 0x8000;
1263     }
1264 }
1265 
tde_osi_get_code2(tde_colorfmt_transform color_trans_type,hi_tde_color_fmt src2_fmt)1266 static hi_u16 tde_osi_get_code2(tde_colorfmt_transform color_trans_type, hi_tde_color_fmt src2_fmt)
1267 {
1268     hi_u16 code2;
1269     switch (color_trans_type) {
1270         case TDE_COLORFMT_TRANSFORM_ARGB_ARGB:
1271             return 0x0;
1272         case TDE_COLORFMT_TRANSFORM_ARGB_YCBCR:
1273             return 0x2;
1274         case TDE_COLORFMT_TRANSFORM_CLUT_ARGB:
1275             return 0x8;
1276         case TDE_COLORFMT_TRANSFORM_CLUT_YCBCR:
1277             return 0xa;
1278         case TDE_COLORFMT_TRANSFORM_YCBCR_ARGB:
1279             code2 = 0x2 | 0x4;
1280             if ((src2_fmt >= HI_TDE_COLOR_FMT_CLUT1) && (src2_fmt <= HI_TDE_COLOR_FMT_ACLUT88)) {
1281                 code2 = 0;
1282             }
1283             return code2;
1284         case TDE_COLORFMT_TRANSFORM_YCBCR_YCBCR:
1285             code2 = 0x0;
1286             if ((src2_fmt >= HI_TDE_COLOR_FMT_CLUT1) && (src2_fmt <= HI_TDE_COLOR_FMT_ACLUT88)) {
1287                 code2 = 0x2;
1288             }
1289             return code2;
1290         default:
1291             return 0x8000;
1292     }
1293 }
1294 
1295 /*
1296  * Function:      tde_osi_double_src_get_opt_code
1297  * Description:   get dual source operate encode
1298  * Input:         src1_fmt background pixel format
1299                   src2_fmt foreground pixel format
1300                   dst_fmt: target pixel format
1301  * Return:        code value
1302  */
tde_osi_double_src_get_opt_code(hi_tde_color_fmt src1_fmt,hi_tde_color_fmt src2_fmt,hi_tde_color_fmt dst_fmt)1303 static hi_u16 tde_osi_double_src_get_opt_code(hi_tde_color_fmt src1_fmt, hi_tde_color_fmt src2_fmt,
1304                                               hi_tde_color_fmt dst_fmt)
1305 {
1306     hi_u16 code1;
1307     hi_u16 code2;
1308     tde_colorfmt_transform color_trans_type;
1309 
1310     color_trans_type = tde_osi_get_fmt_trans_type(src2_fmt, src1_fmt);
1311     code1 = tde_osi_get_code1(color_trans_type);
1312     if (code1 == 0x8000) { /* 0x8000 flag value */
1313         return code1;
1314     }
1315 
1316     color_trans_type = tde_osi_get_fmt_trans_type(src1_fmt, dst_fmt);
1317 
1318     code2 = tde_osi_get_code2(color_trans_type, src2_fmt);
1319     if (code2 == 0x8000) { /* 0x8000 flag value */
1320         return code2;
1321     }
1322     return (code1 | code2);
1323 }
1324 
1325 /*
1326  * Function:      tde_osi_single_src_to_get_opt_code
1327  * Description:   get dual source operate encode
1328  * Input:         src2_fmt foreground pixel format
1329                   dst_fmt  target pixel format
1330  * Return:        encode value, expression is fllowinf:
1331 
1332  |------0-----|------1-----|------2-------|------3-----|
1333  |-----ICSC---|-----OCSC---|(in)RGB->YCbCr|-----CLUT---|
1334 
1335  */
tde_osi_single_src_to_get_opt_code(hi_tde_color_fmt src2_fmt,hi_tde_color_fmt dst_fmt)1336 static hi_u16 tde_osi_single_src_to_get_opt_code(hi_tde_color_fmt src2_fmt, hi_tde_color_fmt dst_fmt)
1337 {
1338     hi_u16 code;
1339     tde_colorfmt_transform color_trans_type;
1340 
1341     color_trans_type = tde_osi_get_fmt_trans_type(src2_fmt, dst_fmt);
1342 
1343     switch (color_trans_type) {
1344         case TDE_COLORFMT_TRANSFORM_ARGB_ARGB:
1345             code = 0x0;
1346             break;
1347         case TDE_COLORFMT_TRANSFORM_ARGB_YCBCR:
1348             code = 0x5;
1349             break;
1350         case TDE_COLORFMT_TRANSFORM_CLUT_ARGB:
1351             code = 0x8;
1352             break;
1353         case TDE_COLORFMT_TRANSFORM_CLUT_CLUT:
1354             code = 0x0;
1355             break;
1356         case TDE_COLORFMT_TRANSFORM_CLUT_YCBCR:
1357             code = 0xA;
1358             break;
1359         case TDE_COLORFMT_TRANSFORM_YCBCR_ARGB:
1360             code = 0x1;
1361             break;
1362         case TDE_COLORFMT_TRANSFORM_YCBCR_YCBCR:
1363             code = 0x0;
1364             break;
1365         default:
1366             code = 0x8000;
1367     }
1368     return code;
1369 }
1370 
1371 /*
1372  * Function:      tde_osi_get_conv_by_code
1373  * Description:   get format conversion manner by format conversion code
1374  * Input:         code  format conversion code
1375  *                conv  format conversion struct
1376  * Return:        encode value
1377  */
tde_osi_get_conv_by_code(hi_u16 code,tde_conv_mode_cmd * conv)1378 static hi_void tde_osi_get_conv_by_code(hi_u16 code, tde_conv_mode_cmd *conv)
1379 {
1380     conv->in_conv = code & 0x1;
1381     conv->out_conv = (code >> 1) & 0x1;
1382     conv->in_rgb2_yc = ((code >> 2) & 0x1);   /* 2 Expand the digits */
1383     conv->in_src1_conv = ((code >> 4) & 0x1); /* 4 Expand the digits */
1384 
1385     return;
1386 }
1387 
1388 /*
1389  * Function:      tde_osi_get_bpp_by_fmt
1390  * Description:   get pixel bit of pixel format
1391  * Input:         fmt  target pixel format
1392  * Return:        -1 fail; other:pixel bit
1393  */
tde_osi_get_bpp_by_fmt(hi_tde_color_fmt fmt)1394 static hi_s32 tde_osi_get_bpp_by_fmt(hi_tde_color_fmt fmt)
1395 {
1396     if (tde_osi_get_bpp_by_fmt_16(fmt) == 16) { /* 16 bpp fmt */
1397         return 16;
1398     } else if (tde_osi_get_bpp_by_fmt_24(fmt) == 24) { /* 24 bpp fmt */
1399         return 24;
1400     } else if (tde_osi_get_bpp_by_fmt_32(fmt) == 32) { /* 32 bpp fmt */
1401         return 32;
1402     } else if (tde_osi_get_bpp_by_fmt_1(fmt) == 1) {
1403         return 1;
1404     } else if (tde_osi_get_bpp_by_fmt_2(fmt) == 2) { /* 2 bpp fmt */
1405         return 2;
1406     } else if (tde_osi_get_bpp_by_fmt_4(fmt) == 4) { /* 4 bpp fmt */
1407         return 4;
1408     } else if (tde_osi_get_bpp_by_fmt_8(fmt) == 8) { /* 8 bpp fmt */
1409         return 8;
1410     } else {
1411         return -1;
1412     }
1413 }
1414 
tde_osi_get_bpp_by_fmt_16(hi_tde_color_fmt fmt)1415 static hi_s32 tde_osi_get_bpp_by_fmt_16(hi_tde_color_fmt fmt)
1416 {
1417     switch (fmt) {
1418         case HI_TDE_COLOR_FMT_RGB444:
1419         case HI_TDE_COLOR_FMT_BGR444:
1420         case HI_TDE_COLOR_FMT_RGB555:
1421         case HI_TDE_COLOR_FMT_BGR555:
1422         case HI_TDE_COLOR_FMT_RGB565:
1423         case HI_TDE_COLOR_FMT_BGR565:
1424         case HI_TDE_COLOR_FMT_ARGB4444:
1425         case HI_TDE_COLOR_FMT_ABGR4444:
1426         case HI_TDE_COLOR_FMT_RGBA4444:
1427         case HI_TDE_COLOR_FMT_BGRA4444:
1428         case HI_TDE_COLOR_FMT_ARGB1555:
1429         case HI_TDE_COLOR_FMT_ABGR1555:
1430         case HI_TDE_COLOR_FMT_RGBA1555:
1431         case HI_TDE_COLOR_FMT_BGRA1555:
1432         case HI_TDE_COLOR_FMT_ACLUT88:
1433         case HI_TDE_COLOR_FMT_YCBCR422:
1434         case HI_TDE_COLOR_FMT_HALFWORD:
1435         case HI_TDE_COLOR_FMT_PKGVYUY:
1436             return 16; /* 16 bpp fmt */
1437         default:
1438             return -1;
1439     }
1440 }
1441 
tde_osi_get_bpp_by_fmt_24(hi_tde_color_fmt fmt)1442 static hi_s32 tde_osi_get_bpp_by_fmt_24(hi_tde_color_fmt fmt)
1443 {
1444     switch (fmt) {
1445         case HI_TDE_COLOR_FMT_RGB888:
1446         case HI_TDE_COLOR_FMT_BGR888:
1447         case HI_TDE_COLOR_FMT_ARGB8565:
1448         case HI_TDE_COLOR_FMT_ABGR8565:
1449         case HI_TDE_COLOR_FMT_RGBA8565:
1450         case HI_TDE_COLOR_FMT_BGRA8565:
1451         case HI_TDE_COLOR_FMT_YCBCR888:
1452             return 24; /* 24 bpp fmt */
1453         default:
1454             return -1;
1455     }
1456 }
1457 
tde_osi_get_bpp_by_fmt_32(hi_tde_color_fmt fmt)1458 static hi_s32 tde_osi_get_bpp_by_fmt_32(hi_tde_color_fmt fmt)
1459 {
1460     switch (fmt) {
1461         case HI_TDE_COLOR_FMT_ARGB8888:
1462         case HI_TDE_COLOR_FMT_ABGR8888:
1463         case HI_TDE_COLOR_FMT_RGBA8888:
1464         case HI_TDE_COLOR_FMT_BGRA8888:
1465         case HI_TDE_COLOR_FMT_AYCBCR8888:
1466         case HI_TDE_COLOR_FMT_RABG8888:
1467             return 32; /* 32 bpp fmt */
1468         default:
1469             return -1;
1470     }
1471 }
1472 
tde_osi_get_bpp_by_fmt_8(hi_tde_color_fmt fmt)1473 static hi_s32 tde_osi_get_bpp_by_fmt_8(hi_tde_color_fmt fmt)
1474 {
1475     switch (fmt) {
1476         case HI_TDE_COLOR_FMT_CLUT8:
1477         case HI_TDE_COLOR_FMT_ACLUT44:
1478         case HI_TDE_COLOR_FMT_A8:
1479         case HI_TDE_COLOR_FMT_BYTE:
1480             return 8; /* 8 bpp fmt */
1481         default:
1482             return -1;
1483     }
1484 }
1485 
tde_osi_get_bpp_by_fmt_4(hi_tde_color_fmt fmt)1486 static hi_s32 tde_osi_get_bpp_by_fmt_4(hi_tde_color_fmt fmt)
1487 {
1488     switch (fmt) {
1489         case HI_TDE_COLOR_FMT_CLUT4:
1490             return 4; /* 4 bpp fmt */
1491         default:
1492             return -1;
1493     }
1494 }
1495 
tde_osi_get_bpp_by_fmt_2(hi_tde_color_fmt fmt)1496 static hi_s32 tde_osi_get_bpp_by_fmt_2(hi_tde_color_fmt fmt)
1497 {
1498     switch (fmt) {
1499         case HI_TDE_COLOR_FMT_CLUT2:
1500             return 2; /* 2 bpp fmt */
1501         default:
1502             return -1;
1503     }
1504 }
1505 
tde_osi_get_bpp_by_fmt_1(hi_tde_color_fmt fmt)1506 static hi_s32 tde_osi_get_bpp_by_fmt_1(hi_tde_color_fmt fmt)
1507 {
1508     switch (fmt) {
1509         case HI_TDE_COLOR_FMT_CLUT1:
1510         case HI_TDE_COLOR_FMT_A1:
1511             return 1;
1512         default:
1513             return -1;
1514     }
1515 }
1516 
1517 /*
1518  * Function:      tde_osi_check_src
1519  * Description:   get scanning direction, avoid lap
1520  * Input:         pSrc source bitmap
1521                   dst_surface target bitmap
1522                   mirror mirror type
1523  * Output:        pstSrcDirection source scanning information
1524                   pstDstDirection target scanning information
1525  * Return:        0  success
1526                   -1 fail
1527  * Others:        add  antiscan handle to YCbCr422R
1528  */
tde_osi_check_src(hi_tde_single_src * single_src,tde_scandirection_mode * src_direction,tde_scandirection_mode * dst_direction)1529 static hi_s32 tde_osi_check_src(hi_tde_single_src *single_src, tde_scandirection_mode *src_direction,
1530     tde_scandirection_mode *dst_direction)
1531 {
1532     hi_s32 bpp;
1533 
1534     if (single_src->src_surface == HI_NULL) {
1535         tde_error("single_src->src_surface is null %s(line=%d)\n", __FUNCTION__, __LINE__);
1536         return HI_ERR_TDE_NULL_PTR;
1537     }
1538 
1539     if (single_src->src_rect == HI_NULL) {
1540         tde_error("single_src->src_rect is null %s(line=%d)\n", __FUNCTION__, __LINE__);
1541         return HI_ERR_TDE_NULL_PTR;
1542     }
1543 
1544     if (single_src->dst_surface == HI_NULL) {
1545         tde_error("single_src->dst_surface is null %s(line=%d)\n", __FUNCTION__, __LINE__);
1546         return HI_ERR_TDE_NULL_PTR;
1547     }
1548 
1549     if (single_src->dst_rect == HI_NULL) {
1550         tde_error("single_src->dst_rect is null %s(line=%d)\n", __FUNCTION__, __LINE__);
1551         return HI_ERR_TDE_NULL_PTR;
1552     }
1553 
1554     if (src_direction == HI_NULL) {
1555         tde_error("pstSrcDirection is null %s(line=%d)\n", __FUNCTION__, __LINE__);
1556         return HI_ERR_TDE_NULL_PTR;
1557     }
1558 
1559     if (dst_direction == HI_NULL) {
1560         tde_error("pstDstDirection is null %s(line=%d)\n", __FUNCTION__, __LINE__);
1561         return HI_ERR_TDE_NULL_PTR;
1562     }
1563     bpp = tde_osi_get_bpp_by_fmt(single_src->dst_surface->color_fmt);
1564     if (bpp < 0) {
1565         tde_error("Unknown color format!\n");
1566         return HI_ERR_TDE_INVALID_PARA;
1567     }
1568 
1569     if (bpp < 8) { /* 8 is bpp */
1570         /* when writing, 8 subbyte format align ask start point byte align */
1571         if ((single_src->dst_rect->pos_x * bpp % 8) || (single_src->dst_rect->width * bpp % 8)) {
1572             tde_error("Subbyte's start or width for writing is not aligned!\n");
1573             return HI_ERR_TDE_INVALID_PARA;
1574         }
1575     }
1576     return HI_SUCCESS;
1577 }
1578 
tde_check_reverse_scan(hi_u32 src_addr,hi_u32 dst_addr,tde_scandirection_mode * src_direction,tde_scandirection_mode * dst_direction)1579 static hi_void tde_check_reverse_scan(hi_u32 src_addr, hi_u32 dst_addr, tde_scandirection_mode *src_direction,
1580     tde_scandirection_mode *dst_direction)
1581 {
1582     if (src_addr <= dst_addr) {
1583         src_direction->v_scan = TDE_SCAN_DOWN_UP;
1584         dst_direction->v_scan = TDE_SCAN_DOWN_UP;
1585 
1586         src_direction->h_scan = TDE_SCAN_RIGHT_LEFT;
1587         dst_direction->h_scan = TDE_SCAN_RIGHT_LEFT;
1588     }
1589     return;
1590 }
1591 
tde_osi_get_src_direction(hi_tde_mirror_mode mirror,tde_scandirection_mode * src_direction)1592 static hi_void tde_osi_get_src_direction(hi_tde_mirror_mode mirror, tde_scandirection_mode *src_direction)
1593 {
1594     switch (mirror) {
1595         case HI_TDE_MIRROR_HORIZONTAL:
1596             src_direction->h_scan = !(src_direction->h_scan);
1597             break;
1598         case HI_TDE_MIRROR_VERTICAL:
1599             src_direction->v_scan = !(src_direction->v_scan);
1600             break;
1601         case HI_TDE_MIRROR_BOTH:
1602             src_direction->h_scan = !(src_direction->h_scan);
1603             src_direction->v_scan = !(src_direction->v_scan);
1604             break;
1605         default:
1606             break;
1607     }
1608 }
1609 
tde_osi_get_scan_info_ex(hi_tde_single_src * single_src,hi_tde_opt * opt,tde_scandirection_mode * src_direction,tde_scandirection_mode * dst_direction)1610 static hi_s32 tde_osi_get_scan_info_ex(hi_tde_single_src *single_src, hi_tde_opt *opt,
1611     tde_scandirection_mode *src_direction, tde_scandirection_mode *dst_direction)
1612 {
1613     hi_u32 src_addr, dst_addr;
1614     hi_tde_mirror_mode mirror = HI_TDE_MIRROR_NONE;
1615     hi_s32 srcd_bpp, dst_bpp, ret;
1616 
1617     ret = tde_osi_check_src(single_src, src_direction, dst_direction);
1618     if (ret != HI_SUCCESS) {
1619         return ret;
1620     }
1621 
1622     /* default scanning direction */
1623     src_direction->h_scan = TDE_SCAN_LEFT_RIGHT;
1624     src_direction->v_scan = TDE_SCAN_UP_DOWN;
1625     dst_direction->h_scan = TDE_SCAN_LEFT_RIGHT;
1626     dst_direction->v_scan = TDE_SCAN_UP_DOWN;
1627 
1628     if (opt != HI_NULL) {
1629         mirror = opt->mirror;
1630     }
1631 
1632     if (mirror != HI_TDE_MIRROR_NONE) {
1633         tde_osi_get_src_direction(mirror, src_direction);
1634     } else {
1635         /* only if stride is the same, can be do conversion */
1636         if ((single_src->src_surface->stride != single_src->dst_surface->stride) ||
1637             (single_src->src_surface->color_fmt >= HI_TDE_COLOR_FMT_JPG_YCBCR400MBP)) {
1638             return 0;
1639         }
1640         srcd_bpp = tde_osi_get_bpp_by_fmt(single_src->src_surface->color_fmt);
1641         dst_bpp = tde_osi_get_bpp_by_fmt(single_src->dst_surface->color_fmt);
1642         if ((dst_bpp < 0) || (srcd_bpp < 0)) {
1643             tde_error("bits per pixel less than 0!src fmt:%d,dst fmt:%d\n",
1644                 single_src->src_surface->color_fmt, single_src->dst_surface->color_fmt);
1645             return -1;
1646         }
1647 
1648         src_addr = single_src->src_surface->phy_addr + single_src->src_rect->pos_y *
1649             single_src->src_surface->stride + ((hi_u32)(single_src->src_rect->pos_x * srcd_bpp) >> 3); /* 3 bpp fmt */
1650         dst_addr = single_src->dst_surface->phy_addr + single_src->dst_rect->pos_y *
1651             /* 3 bpp fmt */
1652             single_src->dst_surface->stride  + ((hi_u32)(single_src->dst_rect->pos_x * dst_bpp) >> 3);
1653 
1654         /* clip and reverse cannot open at the same time, the effect will be abnormal */
1655         if ((opt != HI_NULL) && (opt->clip_mode != HI_TDE_CLIP_MODE_NONE) && (opt->resize)) {
1656             return 0;
1657         }
1658 
1659         /* source is above of target or on the left of the same direction */
1660         tde_check_reverse_scan(src_addr, dst_addr, src_direction, dst_direction);
1661     }
1662     return 0;
1663 }
1664 
1665 /*
1666  * Function:      tde_osi_get_inter_rect
1667  * Description:   get inter rect of two rectangles
1668  * Output:        inter_rect output inter rectangle
1669  * Return:        0  have inter zone
1670                   -1 no inter zone
1671  */
tde_osi_get_inter_rect(hi_tde_rect * dst_rect,hi_tde_rect * clip_rect,hi_tde_rect * inter_rect)1672 static hi_s32 tde_osi_get_inter_rect(hi_tde_rect *dst_rect, hi_tde_rect *clip_rect, hi_tde_rect *inter_rect)
1673 {
1674     hi_s32 left, top, right, bottom;
1675     hi_s32 right1, bottom1, right2, bottom2;
1676     hi_s32 pos_x, pos_y;
1677 
1678     pos_x = dst_rect->pos_x;
1679     pos_y = dst_rect->pos_y;
1680     left = (pos_x > clip_rect->pos_x) ? pos_x : clip_rect->pos_x;
1681     top = (pos_y > clip_rect->pos_y) ? pos_y : clip_rect->pos_y;
1682 
1683     right1 = pos_x + dst_rect->width - 1;
1684     right2 = clip_rect->pos_x + clip_rect->width - 1;
1685     right = (right1 > right2) ? right2 : right1;
1686 
1687     bottom1 = pos_y + dst_rect->height - 1;
1688     bottom2 = clip_rect->pos_y + clip_rect->height - 1;
1689     bottom = (bottom1 > bottom2) ? bottom2 : bottom1;
1690 
1691     if ((left > right) || (top > bottom)) {
1692         return HI_ERR_TDE_INVALID_PARA;
1693     }
1694 
1695     inter_rect->pos_x = left;
1696     inter_rect->pos_y = top;
1697     inter_rect->width = right - left + 1;
1698     inter_rect->height = bottom - top + 1;
1699     return HI_SUCCESS;
1700 }
1701 
1702 /*
1703  * Function:      tde_osi_is_rect1_in_rect2
1704  * Description:   Rect1 is if inside Rect2
1705  * Input:         rect1  input rectangle1
1706                   rect2  input rectangle2
1707  * Return:        1  have inter zone
1708                   0  no inter zone
1709  */
tde_osi_is_rect1_in_rect2(hi_tde_rect * rect1,hi_tde_rect * rect2)1710 static hi_bool tde_osi_is_rect1_in_rect2(hi_tde_rect *rect1, hi_tde_rect *rect2)
1711 {
1712     hi_s32 right1 = rect1->pos_x + rect1->width - 1;
1713     hi_s32 right2 = rect2->pos_x + rect2->width - 1;
1714 
1715     hi_s32 bottom1 = rect1->pos_y + rect1->height - 1;
1716     hi_s32 bottom2 = rect2->pos_y + rect2->height - 1;
1717 
1718     if ((rect1->pos_x >= rect2->pos_x) &&
1719         (rect1->pos_y >= rect2->pos_y) &&
1720         (right1 <= right2) &&
1721         (bottom1 <= bottom2)) {
1722         return HI_TRUE;
1723     }
1724 
1725     return HI_FALSE;
1726 }
1727 
1728 /*
1729  * Function:      tde_osi_set_mb_para
1730  * Description:   MB operate setting parameter interface
1731  * Input:         handle: task handle
1732  *                dst_surface:  target bitmap information struct
1733  *                dst_rect: target bitmap operate zone
1734  *                mb_opt:  operate parameter setting struct
1735  */
tde_osi_set_mb_para(hi_s32 handle,hi_tde_mb_src * mb_src,hi_tde_mb_opt * mb_opt)1736 static hi_s32 tde_osi_set_mb_para(hi_s32 handle, hi_tde_mb_src *mb_src, hi_tde_mb_opt *mb_opt)
1737 {
1738     hi_tde_surface *fore_ground = HI_NULL;
1739     hi_tde_opt *opt = HI_NULL;
1740     hi_s32 ret;
1741     hi_tde_single_src single_src;
1742 
1743     fore_ground = (hi_tde_surface *)tde_malloc(sizeof(hi_tde_surface));
1744     if (fore_ground == HI_NULL) {
1745         tde_error ("malloc pstForeGround failed, size=%ld!\n", (unsigned long)(sizeof(hi_tde_surface)));
1746         return HI_ERR_TDE_NO_MEM;
1747     }
1748     opt = (hi_tde_opt *)tde_malloc(sizeof(hi_tde_opt));
1749     if (opt == HI_NULL) {
1750         tde_error ("malloc pstOpt failed, size=%ld!\n", (unsigned long)(sizeof(hi_tde_opt)));
1751         tde_free((hi_void *)fore_ground);
1752         return HI_ERR_TDE_NO_MEM;
1753     }
1754     fore_ground->phy_addr = mb_src->mb_surface->y_addr;
1755     fore_ground->stride = mb_src->mb_surface->y_stride;
1756     fore_ground->width = mb_src->mb_surface->y_width;
1757     fore_ground->color_fmt = tde_osi_covert_mb_fmt(mb_src->mb_surface->mb_color_fmt);
1758     fore_ground->height = mb_src->mb_surface->y_height;
1759     fore_ground->cbcr_phy_addr = mb_src->mb_surface->cbcr_phy_addr;
1760     fore_ground->cbcr_stride = mb_src->mb_surface->cbcr_stride;
1761 
1762 #if (TDE_CAPABILITY & DEFLICKER)
1763     opt->deflicker_mode = (mb_opt->is_deflicker) ? HI_TDE_DEFLICKER_LEVEL_MODE_BOTH :
1764         HI_TDE_DEFLICKER_LEVEL_MODE_NONE;
1765 #endif
1766 
1767     opt->out_alpha_from = (mb_opt->is_set_out_alpha) ? HI_TDE_OUT_ALPHA_FROM_GLOBALALPHA :
1768         HI_TDE_OUT_ALPHA_FROM_NORM;
1769     opt->resize = (mb_opt->resize_en == HI_TDE_MB_RESIZE_NONE) ? HI_FALSE : HI_TRUE;
1770     opt->clip_rect = mb_opt->clip_rect;
1771     opt->global_alpha = mb_opt->out_alpha;
1772     opt->clip_mode = mb_opt->clip_mode;
1773 
1774     single_src.src_surface      = fore_ground;
1775     single_src.src_rect         = mb_src->src_rect;
1776     single_src.dst_surface      = mb_src->dst_surface;
1777     single_src.dst_rect         = mb_src->dst_rect;
1778     ret = tde_osi_single_src_2_blit(handle, &single_src, opt, HI_FALSE, HI_FALSE);
1779     tde_free((hi_void *)fore_ground);
1780     tde_free((hi_void *)opt);
1781     return ret;
1782 }
1783 
1784 #if (TDE_CAPABILITY & SLICE)
1785 /* data_in :positive or negetive  ;  bit:complement width */
tde_true_value_to_complement(hi_s32 data_in,hi_u32 bit)1786 static hi_u32 tde_true_value_to_complement(hi_s32 data_in, hi_u32 bit)
1787 {
1788     hi_u32 data_out;
1789     hi_u32 data_in_tmp;
1790 
1791     if (data_in >> (bit - 1)) {
1792         data_in_tmp = 0 - data_in;
1793         data_out = ((1 << (bit - 1)) | (((~data_in_tmp) & ((1 << (bit - 1)) - 1)) + 1)) & ((1 << bit) - 1);
1794     } else {
1795         data_out = data_in;
1796     }
1797 
1798     return data_out;
1799 }
1800 
1801 /* data_in :positive or negetive  ;  bit:complement width */
tde_complement_to_true_value(hi_u32 data_in,hi_u32 bit)1802 static hi_s32 tde_complement_to_true_value(hi_u32 data_in, hi_u32 bit)
1803 {
1804     hi_s32 data_out;
1805     hi_u32 data_in_tmp;
1806 
1807     if (data_in >> (bit - 1)) {
1808         data_in_tmp = data_in & ((1 << (bit - 1)) - 1);
1809         data_out = (((~data_in_tmp) & ((1 << (bit - 1)) - 1)) + 1) * (-1);
1810     } else {
1811         data_out = data_in;
1812     }
1813 
1814     return data_out;
1815 }
1816 
tde_osi_init_slice_data(tde_slice_data * slice_data,tde_hw_node * child_node,hi_u32 i)1817 static hi_void tde_osi_init_slice_data(tde_slice_data *slice_data, tde_hw_node *child_node, hi_u32 i)
1818 {
1819     if (i == 0) {
1820         slice_data->fmt = child_node->src1_ctrl.bits.src1_fmt;
1821         slice_data->h_scan_ord = child_node->src1_ctrl.bits.src1_h_scan_ord;
1822         slice_data->width = child_node->src1_imgsize.bits.src1_width + 1;
1823 
1824         slice_data->u32422v_pro = child_node->src1_ctrl.bits.src1_422v_pro;
1825 
1826         slice_data->hlmsc_en = child_node->src1_hsp.bits.hlmsc_en;
1827         slice_data->hchmsc_en = child_node->src1_hsp.bits.hchmsc_en;
1828         slice_data->hratio = child_node->src1_hsp.bits.hratio;
1829         slice_data->hor_loffset = child_node->src1_hloffset;
1830         slice_data->hor_coffset = child_node->src1_hcoffset;
1831         slice_data->zme_ow = child_node->src1_zmeoreso.bits.ow + 1;
1832         slice_data->zme_iw = child_node->src1_zmeireso.bits.iw + 1;
1833         slice_data->hpzme_en = child_node->src1_hpzme.bits.src1_hpzme_en;
1834         slice_data->hpzme_mode = child_node->src1_hpzme.bits.src1_hpzme_mode;
1835         slice_data->hpzme_width = child_node->src1_hpzme_size.bits.src1_hpzme_width + 1;
1836     } else {
1837         slice_data->fmt = child_node->src2_ctrl.bits.src2_fmt;
1838         slice_data->h_scan_ord = child_node->src2_ctrl.bits.src2_h_scan_ord;
1839         slice_data->width = child_node->src2_imgsize.bits.src2_width + 1;
1840         slice_data->u32422v_pro = child_node->src2_ctrl.bits.src2_422v_pro;
1841         slice_data->hlmsc_en =  child_node->src2_hsp.bits.hlmsc_en;
1842         slice_data->hchmsc_en = child_node->src2_hsp.bits.hchmsc_en;
1843         slice_data->hratio = child_node->src2_hsp.bits.hratio;
1844         slice_data->hor_loffset =  child_node->src2_hloffset;
1845         slice_data->hor_coffset =  child_node->src2_hcoffset;
1846         slice_data->zme_ow = child_node->src2_zmeoreso.bits.ow + 1;
1847         slice_data->zme_iw = child_node->src2_zmeireso.bits.iw + 1;
1848         slice_data->hpzme_en =  child_node->src2_hpzme.bits.src2_hpzme_en;
1849         slice_data->hpzme_mode = child_node->src2_hpzme.bits.src2_hpzme_mode;
1850         slice_data->hpzme_width = child_node->src2_hpzme_size.bits.src2_hpzme_width + 1;
1851     }
1852 
1853     return;
1854 }
1855 
1856 /*
1857  * The constants used in this function are algorithm-specific values and are not part of the devil number
1858  * 0xfffff 0xfff00000 is mask
1859  */
tde_osi_calc_slice_s1(tde_slice_data * slice_data)1860 static hi_void tde_osi_calc_slice_s1(tde_slice_data *slice_data)
1861 {
1862     slice_data->xdpos = (slice_data->hlmsc_en | slice_data->hchmsc_en) ? (slice_data->zme_ow - 1) :
1863         (slice_data->hpzme_en ? (slice_data->hpzme_width - 1) : (slice_data->width - 1));
1864     slice_data->xed_pos_blk = MIN2(slice_data->des_xed_pos_blk, slice_data->xdpos);
1865     /* step2 : out pos relative to s1 disp start */
1866     slice_data->xst_pos_cord = slice_data->des_xst_pos_blk;
1867     slice_data->xed_pos_cord = slice_data->xed_pos_blk;
1868 
1869     /* setp2 : calc s1 zme parameter */
1870     slice_data->xst_pos_cord_in = (slice_data->xst_pos_cord * slice_data->hratio) >> 20; /* 20 alg data */
1871     slice_data->xed_pos_cord_in = (slice_data->xed_pos_cord * slice_data->hratio) >> 20; /* 20 alg data */
1872     slice_data->hor_loffset_cfg_int_comp = slice_data->hor_loffset >> 20; /* 20 alg data */
1873     /* 8 alg data */
1874     slice_data->hor_loffset_cfg_int = tde_complement_to_true_value(slice_data->hor_loffset_cfg_int_comp, 8);
1875     slice_data->hor_loffset_cfg_fraction = slice_data->hor_loffset & 0xfffff;
1876     slice_data->hor_loffset_pix_fraction = (slice_data->xst_pos_cord * slice_data->hratio) & 0xfffff;
1877     slice_data->hor_loffset_fraction = (slice_data->hor_loffset_cfg_fraction +
1878                                         slice_data->hor_loffset_pix_fraction) & 0xfffff;
1879 
1880     slice_data->xst_pos_cord_in_offset = slice_data->xst_pos_cord_in + slice_data->hor_loffset_cfg_int + (
1881         ((slice_data->hor_loffset_cfg_fraction + slice_data->hor_loffset_pix_fraction) & 0xfff00000) != 0);
1882     slice_data->xed_pos_cord_in_offset = slice_data->xed_pos_cord_in + slice_data->hor_loffset_cfg_int + (
1883         ((slice_data->hor_loffset_cfg_fraction + slice_data->hor_loffset_pix_fraction) & 0xfff00000) != 0);
1884     slice_data->xst_pos_cord_in_tap_rgb = slice_data->xst_pos_cord_in_offset < 0 ? 0 : (
1885         (slice_data->xst_pos_cord_in_offset >= (TDE_MAX_ZOOM_OUT_STEP / 2 - 1)) ?  /* 2 alg data */
1886         (slice_data->xst_pos_cord_in_offset - (TDE_MAX_ZOOM_OUT_STEP / 2 - 1)) : 0); /* 2 alg data */
1887     slice_data->xed_pos_cord_in_tap_rgb = (slice_data->xed_pos_cord_in_offset + TDE_MAX_ZOOM_OUT_STEP / 2) < 0 ?
1888         0 : (((slice_data->xed_pos_cord_in_offset + TDE_MAX_ZOOM_OUT_STEP / 2) >= /* 2 alg data */
1889         slice_data->zme_iw - 1) ? slice_data->zme_iw - 1 : (slice_data->xed_pos_cord_in_offset +
1890         TDE_MAX_ZOOM_OUT_STEP / 2)); /* 2 alg data */
1891     slice_data->node_cfg_zme_iw_rgb = slice_data->xed_pos_cord_in_tap_rgb - slice_data->xst_pos_cord_in_tap_rgb + 1;
1892     slice_data->hor_loffset_int = (slice_data->xst_pos_cord_in_offset - slice_data->xst_pos_cord_in_tap_rgb);
1893     /* 8 alg data */
1894     slice_data->hor_loffset_int_complement = tde_true_value_to_complement(slice_data->hor_loffset_int, 8);
1895     slice_data->node_cfg_hor_loffset_rgb = (slice_data->hor_loffset_int_complement << 20) + /* 20 alg data */
1896                                             slice_data->hor_loffset_fraction;
1897     slice_data->xst_pos_cord_in_tap_luma = ((slice_data->xst_pos_cord_in_tap_rgb % 2) == 1) ? /* 2 alg data */
1898         slice_data->xst_pos_cord_in_tap_rgb - 1 : slice_data->xst_pos_cord_in_tap_rgb;
1899     slice_data->xed_pos_cord_in_tap_luma = (((slice_data->xed_pos_cord_in_tap_rgb % 2) == 0) ? /* 2 alg data */
1900         slice_data->xed_pos_cord_in_tap_rgb + 1 : slice_data->xed_pos_cord_in_tap_rgb) > (
1901         /* 2 alg data */
1902         slice_data->zme_iw - 1) ? (slice_data->zme_iw - 1) : (((slice_data->xed_pos_cord_in_tap_rgb % 2) == 0) ?
1903         slice_data->xed_pos_cord_in_tap_rgb + 1 : slice_data->xed_pos_cord_in_tap_rgb);
1904     slice_data->xst_pos_cord_in_chroma = (slice_data->fmt == 50) ? (slice_data->xst_pos_cord * /* 50 alg data */
1905         (slice_data->hratio)) >> 20 : (slice_data->xst_pos_cord * (slice_data->hratio / 2)) >> 20; /* 20 alg data */
1906     slice_data->xed_pos_cord_in_chroma = (slice_data->fmt == 50) ? (slice_data->xed_pos_cord * /* 50 alg data */
1907         (slice_data->hratio)) >> 20 : (slice_data->xed_pos_cord * (slice_data->hratio / 2)) >> 20; /* 20 alg data */
1908     slice_data->hor_coffset_cfg_int_comp = slice_data->hor_coffset >> 20; /* 20 alg data */
1909     /* 8 alg data */
1910     slice_data->hor_coffset_cfg_int = tde_complement_to_true_value(slice_data->hor_coffset_cfg_int_comp, 8);
1911     slice_data->hor_coffset_cfg_fraction = slice_data->hor_coffset & 0xfffff;
1912     return;
1913 }
1914 
1915 /*
1916  * The constants used in this function are algorithm-specific values and are not part of the devil number
1917  * 0xfffff 0xfff00000 is mask
1918  */
tde_osi_calc_slice_sp(tde_slice_data * slice_data)1919 static hi_void tde_osi_calc_slice_sp(tde_slice_data *slice_data)
1920 {
1921     /* 50 alg data */
1922     slice_data->hor_coffset_pix_fraction = ((slice_data->fmt == 50) ? (slice_data->xst_pos_cord *
1923         (slice_data->hratio)) : (slice_data->xst_pos_cord * (slice_data->hratio / 2))) & 0xfffff; /* 2 alg data */
1924     slice_data->hor_coffset_fraction = (slice_data->hor_coffset_cfg_fraction +
1925         slice_data->hor_coffset_pix_fraction) & 0xfffff;
1926     slice_data->xst_pos_cord_in_offset_chroma = slice_data->xst_pos_cord_in_chroma +
1927         slice_data->hor_coffset_cfg_int + (((slice_data->hor_coffset_cfg_fraction +
1928         slice_data->hor_coffset_pix_fraction) & 0xfff00000) != 0);
1929     slice_data->xed_pos_cord_in_offset_chroma = slice_data->xed_pos_cord_in_chroma +
1930         slice_data->hor_coffset_cfg_int + (((slice_data->hor_coffset_cfg_fraction +
1931         slice_data->hor_coffset_pix_fraction) & 0xfff00000) != 0);
1932     slice_data->xst_pos_cord_in_tap_chroma = slice_data->xst_pos_cord_in_offset_chroma < 0 ? 0 :
1933         ((slice_data->xst_pos_cord_in_offset_chroma >= (TDE_MAX_ZOOM_OUT_STEP / 2 - 1)) ? /* 2 alg data */
1934         (slice_data->xst_pos_cord_in_offset_chroma - (TDE_MAX_ZOOM_OUT_STEP / 2 - 1)) : 0); /* 2 alg data */
1935     /* 2 alg data */
1936     slice_data->xed_pos_cord_in_tap_chroma = (slice_data->xed_pos_cord_in_offset_chroma + TDE_MAX_ZOOM_OUT_STEP / 2)
1937         < 0 ? 0 : (((slice_data->xed_pos_cord_in_offset_chroma + TDE_MAX_ZOOM_OUT_STEP / 2) >= /* 2 alg data */
1938         /* 2 50 alg data */
1939         ((slice_data->fmt == 50) ? ((slice_data->zme_iw - 1)) : ((slice_data->zme_iw - 1) / 2))) ? ((
1940         /* 2 50 alg data */
1941         slice_data->fmt == 50) ? ((slice_data->zme_iw - 1)) : ((slice_data->zme_iw - 1) / 2)) :
1942         (slice_data->xed_pos_cord_in_offset_chroma + TDE_MAX_ZOOM_OUT_STEP / 2)); /* 2 alg data */
1943     /* 50 alg data */
1944     slice_data->xst_pos_cord_in_tap_chroma_x2 = (slice_data->fmt == 50) ? slice_data->xst_pos_cord_in_tap_chroma :
1945                                                  slice_data->xst_pos_cord_in_tap_chroma * 2; /* 2 alg data */
1946     /* 50 alg data */
1947     slice_data->xed_pos_cord_in_tap_chroma_x2 = (slice_data->fmt == 50) ? slice_data->xed_pos_cord_in_tap_chroma :
1948                                                  slice_data->xed_pos_cord_in_tap_chroma * 2 + 1; /* 2 alg data */
1949 
1950     slice_data->xst_pos_cord_in_tap_sp = MIN2(slice_data->xst_pos_cord_in_tap_luma,
1951                                               slice_data->xst_pos_cord_in_tap_chroma_x2);
1952     slice_data->xed_pos_cord_in_tap_sp = MAX2(slice_data->xed_pos_cord_in_tap_luma,
1953                                               slice_data->xed_pos_cord_in_tap_chroma_x2);
1954 
1955     slice_data->node_cfg_zme_iw_sp = slice_data->xed_pos_cord_in_tap_sp - slice_data->xst_pos_cord_in_tap_sp + 1;
1956     slice_data->hor_loffset_int_sp = (slice_data->xst_pos_cord_in_offset - slice_data->xst_pos_cord_in_tap_sp);
1957     slice_data->hor_coffset_int_sp = (slice_data->xst_pos_cord_in_offset_chroma - (
1958         /* 50 2 alg data */
1959         (slice_data->fmt == 50) ? slice_data->xst_pos_cord_in_tap_sp : slice_data->xst_pos_cord_in_tap_sp / 2));
1960     /* 8 alg data */
1961     slice_data->hor_loffset_int_sp_complent = tde_true_value_to_complement(slice_data->hor_loffset_int_sp, 8);
1962     /* 8 alg data */
1963     slice_data->hor_coffset_int_sp_complent = tde_true_value_to_complement(slice_data->hor_coffset_int_sp, 8);
1964     slice_data->node_cfg_hor_loffset_sp = (slice_data->hor_loffset_int_sp_complent << 20) + /* 20 alg data */
1965                                            slice_data->hor_loffset_fraction;
1966     slice_data->node_cfg_hor_coffset_sp = (slice_data->hor_coffset_int_sp_complent << 20) + /* 20 alg data */
1967                                            slice_data->hor_coffset_fraction;
1968     return;
1969 }
1970 
1971 /* The constants used in this function are algorithm-specific values and are not part of the devil number */
tde_osi_calc_slice_node(tde_slice_data * slice_data,tde_hw_node * child_node,hi_u32 i)1972 static hi_void tde_osi_calc_slice_node(tde_slice_data *slice_data, tde_hw_node *child_node, hi_u32 i)
1973 {
1974     hi_bool set_slice_size = HI_FALSE;
1975     /* 0 2 1 alg data */
1976     set_slice_size = ((slice_data->hpzme_en == 0) && (slice_data->slice_width % 2 == 1) &&
1977         ((slice_data->fmt == 48) || ((slice_data->fmt == 50) && !slice_data->u32422v_pro) || /* 48 50 alg data */
1978         (slice_data->fmt == 52)) && (slice_data->xed_pos_cord_in_tap_hpzme_hso == /* 52 alg data */
1979         slice_data->width - 1) && (slice_data->width % 2 == 0)); /* 52 alg data */
1980     if (set_slice_size) {
1981         if (slice_data->h_scan_ord) {
1982             slice_data->slice_wi = slice_data->slice_wi + 1;
1983             slice_data->slice_width = slice_data->slice_width + 1;
1984             slice_data->slice_hoffset = slice_data->slice_hoffset - 1;
1985         } else {
1986             slice_data->slice_wi = slice_data->slice_wi + 1;
1987             slice_data->slice_width = slice_data->slice_width + 1;
1988             slice_data->slice_hoffset = slice_data->slice_hoffset - 1;
1989             slice_data->slice_l_ofst = slice_data->slice_l_ofst + (
1990             slice_data->hor_loffset_int_beyond_complent << 20); /* 20 alg data */
1991             slice_data->slice_c_ofst = slice_data->slice_c_ofst + (
1992             slice_data->hor_loffset_int_beyond_complent << 20); /* 20 alg data */
1993         }
1994     }
1995 
1996     if (i == 0) {
1997         child_node->src1_zmeoreso.bits.ow = slice_data->slice_wo;
1998         child_node->src1_hloffset = slice_data->slice_l_ofst;
1999         child_node->src1_hcoffset = slice_data->slice_c_ofst;
2000         child_node->src1_pix_offset.bits.src1_hoffset_pix = slice_data->slice_hoffset;
2001         child_node->src1_imgsize.bits.src1_width = slice_data->slice_width - 1;
2002         child_node->src1_zmeireso.bits.iw = slice_data->slice_wi;
2003         child_node->src1_hpzme_size.bits.src1_hpzme_width = slice_data->slice_w_hpzme - 1;
2004 
2005         return;
2006     }
2007 
2008     child_node->src2_zmeoreso.bits.ow = slice_data->slice_wo;
2009     child_node->src2_hloffset = slice_data->slice_l_ofst;
2010     child_node->src2_hcoffset = slice_data->slice_c_ofst;
2011     child_node->src2_pix_offset.bits.src2_hoffset_pix = slice_data->slice_hoffset;
2012     child_node->src2_imgsize.bits.src2_width = slice_data->slice_width - 1;
2013     child_node->src2_zmeireso.bits.iw = slice_data->slice_wi;
2014     child_node->src2_hpzme_size.bits.src2_hpzme_width = slice_data->slice_w_hpzme - 1;
2015 }
2016 
2017 /* The constants used in this function are algorithm-specific values and are not part of the devil number */
tde_osi_calc_slice_mux(tde_slice_data * slice_data,tde_hw_node * child_node,hi_u32 i)2018 static hi_void tde_osi_calc_slice_mux(tde_slice_data *slice_data, tde_hw_node *child_node, hi_u32 i)
2019 {
2020     hi_bool cfg_zme_iw_sp = HI_FALSE;
2021     hi_bool cfg_hor_loffset_sp = HI_FALSE;
2022     hi_bool cfg_hor_coffset_sp = HI_FALSE;
2023 
2024     slice_data->slice_wo = slice_data->xed_pos_cord - slice_data->xst_pos_cord + 1;
2025     /* 32 48 50 alg data */
2026     cfg_zme_iw_sp = ((slice_data->fmt >= 32) && (slice_data->fmt != 48) && (!((slice_data->fmt == 50) &&
2027                      !slice_data->u32422v_pro)) && (slice_data->fmt != 52)); /* 52 alg data */
2028     slice_data->slice_wi = (cfg_zme_iw_sp) ? slice_data->node_cfg_zme_iw_sp : ((slice_data->hlmsc_en ||
2029                             slice_data->hchmsc_en) ? slice_data->node_cfg_zme_iw_rgb : slice_data->slice_wo);
2030     /* 32 48 50 alg data */
2031     cfg_hor_loffset_sp = ((slice_data->fmt >= 32) && (slice_data->fmt != 48) && (!((slice_data->fmt == 50) &&
2032                           !slice_data->u32422v_pro)) && (slice_data->fmt != 52)); /* 52 alg data */
2033     slice_data->slice_l_ofst = (cfg_hor_loffset_sp) ? slice_data->node_cfg_hor_loffset_sp :
2034                                 slice_data->node_cfg_hor_loffset_rgb;
2035 
2036     cfg_hor_coffset_sp = cfg_hor_loffset_sp;
2037     slice_data->slice_c_ofst = (cfg_hor_coffset_sp) ? slice_data->node_cfg_hor_coffset_sp :
2038                                 slice_data->node_cfg_hor_loffset_rgb;
2039 
2040     slice_data->slice_w_hpzme = slice_data->slice_wi;
2041     slice_data->slice_wo = slice_data->slice_wo - 1;
2042     slice_data->slice_wi = slice_data->slice_wi - 1;
2043 
2044     slice_data->xst_pos_cord_in_tap = (slice_data->hlmsc_en || slice_data->hchmsc_en) ?
2045         /* 32 48 50 alg data */
2046         (((slice_data->fmt >= 32) && (slice_data->fmt != 48) && (!((slice_data->fmt == 50) &&
2047         /* 52 alg data */
2048         !slice_data->u32422v_pro)) && (slice_data->fmt != 52)) ? slice_data->xst_pos_cord_in_tap_sp :
2049         slice_data->xst_pos_cord_in_tap_rgb) : slice_data->xst_pos_cord;
2050 
2051     slice_data->xed_pos_cord_in_tap = (slice_data->hlmsc_en || slice_data->hchmsc_en) ?
2052         /* 32 48 50 alg data */
2053         (((slice_data->fmt >= 32) && (slice_data->fmt != 48) && (!((slice_data->fmt == 50) &&
2054         /* 52 alg data */
2055         !slice_data->u32422v_pro)) && (slice_data->fmt != 52)) ? slice_data->xed_pos_cord_in_tap_sp :
2056         slice_data->xed_pos_cord_in_tap_rgb) : slice_data->xed_pos_cord;
2057 
2058     slice_data->xst_pos_cord_in_tap_hpzme = slice_data->hpzme_en ? (slice_data->xst_pos_cord_in_tap *
2059        (slice_data->hpzme_mode + 1)) : slice_data->xst_pos_cord_in_tap;
2060     slice_data->xed_pos_cord_in_tap_hpzme = slice_data->hpzme_en ? ((slice_data->xed_pos_cord_in_tap + 1) *
2061        (slice_data->hpzme_mode + 1) - 1) : slice_data->xed_pos_cord_in_tap;
2062 
2063     if (slice_data->h_scan_ord) {
2064         slice_data->xst_pos_cord_in_tap_hpzme_hso = slice_data->width - 1 - slice_data->xed_pos_cord_in_tap_hpzme;
2065         slice_data->xed_pos_cord_in_tap_hpzme_hso = slice_data->width - 1 - slice_data->xst_pos_cord_in_tap_hpzme;
2066     } else {
2067         slice_data->xst_pos_cord_in_tap_hpzme_hso = slice_data->xst_pos_cord_in_tap_hpzme;
2068         slice_data->xed_pos_cord_in_tap_hpzme_hso = slice_data->xed_pos_cord_in_tap_hpzme;
2069     }
2070 
2071     slice_data->slice_width = (slice_data->xed_pos_cord_in_tap_hpzme_hso -
2072                                slice_data->xst_pos_cord_in_tap_hpzme_hso + 1);
2073     slice_data->slice_hoffset = slice_data->xst_pos_cord_in_tap_hpzme_hso;
2074 
2075     slice_data->hor_loffset_int_beyond = 1;
2076     /* 8 alg data */
2077     slice_data->hor_loffset_int_beyond_complent = tde_true_value_to_complement(slice_data->hor_loffset_int_beyond, 8);
2078 }
2079 
tde_osi_finalize_slice_calculation(tde_slice_data * slice_data,tde_hw_node * child_node)2080 static hi_void tde_osi_finalize_slice_calculation(tde_slice_data *slice_data, tde_hw_node *child_node)
2081 {
2082     slice_data->slice_dst_width = slice_data->des_xed_pos_blk - slice_data->des_xst_pos_blk + 1;
2083     slice_data->slice_dst_hoffset = (slice_data->des_h_scan_ord ? (slice_data->des_width - 1 -
2084         slice_data->des_xed_pos_blk) : slice_data->des_xst_pos_blk) + slice_data->des_hoffset_pix;
2085     slice_data->des_crop_en = (!((slice_data->des_crop_start_x > slice_data->des_xed_pos_blk) ||
2086         (slice_data->des_crop_end_x < slice_data->des_xst_pos_blk))) && slice_data->des_crop_en;
2087     slice_data->des_crop_start_x = slice_data->des_crop_en ? (MAX2(slice_data->des_xst_pos_blk,
2088         slice_data->des_crop_start_x) - slice_data->des_xst_pos_blk) : 0;
2089     slice_data->des_crop_end_x = slice_data->des_crop_en ? (MIN2(slice_data->des_xed_pos_blk,
2090         slice_data->des_crop_end_x) - slice_data->des_xst_pos_blk) : 0;
2091 
2092     child_node->des_imgsize.bits.des_width = slice_data->slice_dst_width - 1;
2093     child_node->des_pix_offset.bits.des_hoffset_pix = slice_data->slice_dst_hoffset;
2094     child_node->des_alpha.bits.des_crop_en = slice_data->des_crop_en;
2095     child_node->des_crop_pos_st.bits.des_crop_start_x = slice_data->des_crop_start_x;
2096     child_node->des_crop_pos_ed.bits.des_crop_end_x = slice_data->des_crop_end_x;
2097 
2098     return;
2099 }
2100 
tde_osi_calc_slice(hi_s32 handle,tde_hw_node * node)2101 hi_s32 tde_osi_calc_slice(hi_s32 handle, tde_hw_node *node)
2102 {
2103     tde_slice_data slice_data = { 0 };
2104     hi_u32 n;
2105     hi_u32 i;
2106     hi_s32 ret;
2107 
2108     slice_data.des_width = node->des_imgsize.bits.des_width + 1;
2109     slice_data.des_hoffset_pix = 0;
2110     slice_data.des_h_scan_ord = node->des_ctrl.bits.des_h_scan_ord;
2111 
2112     slice_data.des_crop_en = node->des_alpha.bits.des_crop_en;
2113     slice_data.des_crop_start_x = node->des_crop_pos_st.bits.des_crop_start_x;
2114     slice_data.des_crop_end_x = node->des_crop_pos_ed.bits.des_crop_end_x;
2115     /* 256 alg data */
2116     slice_data.node_num = slice_data.des_width / 256 + ((slice_data.des_width % 256) != 0);
2117 
2118     for (n = 0; n < slice_data.node_num; n++) {
2119         tde_hw_node *child_node;
2120         hi_void *buf = HI_NULL;
2121         buf = (hi_void *)tde_malloc(sizeof(tde_hw_node) + TDE_NODE_HEAD_BYTE + TDE_NODE_TAIL_BYTE);
2122         if (buf == HI_NULL) {
2123             tde_error("malloc (%d) failed, wgetfreenum(%d)!\n", (sizeof(tde_hw_node)), wgetfreenum());
2124             return HI_ERR_TDE_NO_MEM;
2125         }
2126 
2127         child_node = (tde_hw_node *)(buf + TDE_NODE_HEAD_BYTE);
2128 
2129         if (memcpy_s(child_node, sizeof(tde_hw_node), node, sizeof(tde_hw_node)) != EOK) {
2130             tde_hal_free_node_buf(child_node);
2131             return HI_ERR_TDE_INVALID_PARA;
2132         }
2133 
2134         slice_data.des_xst_pos_blk = n * TDE_MAX_SLICE_WIDTH;
2135         slice_data.des_xed_pos_blk = (((n + 1) * TDE_MAX_SLICE_WIDTH) <= slice_data.des_width) ? (
2136             ((n + 1) * TDE_MAX_SLICE_WIDTH) - 1) : slice_data.des_width - 1;
2137 
2138         for (i = 0; i < 2; i++) { /* 2 alg data */
2139             tde_osi_init_slice_data(&slice_data, child_node, i);
2140 
2141             tde_osi_calc_slice_s1(&slice_data);
2142 
2143             tde_osi_calc_slice_sp(&slice_data);
2144 
2145             tde_osi_calc_slice_mux(&slice_data, child_node, i);
2146         }
2147 
2148         tde_osi_finalize_slice_calculation(&slice_data, child_node);
2149         ret = tde_osi_set_node_finish(handle, child_node, 0, TDE_NODE_SUBM_ALONE);
2150         if (ret != HI_SUCCESS) {
2151             tde_hal_free_node_buf(child_node);
2152             return ret;
2153         }
2154     }
2155     return HI_SUCCESS;
2156 }
2157 
2158 #endif
2159 
2160 #ifndef HI_BUILD_IN_BOOT /* codecc */
2161 
2162 #if (TDE_CAPABILITY & RESIZE)
tde_osi_set_value_to_clear(hi_s32 * zme_vin,hi_s32 * zme_vout,hi_s32 * zme_vphase)2163 static hi_void tde_osi_set_value_to_clear(hi_s32 *zme_vin, hi_s32 *zme_vout, hi_s32 *zme_vphase)
2164 {
2165     *zme_vin = 0;
2166     *zme_vout = 0;
2167     *zme_vphase = 0;
2168 }
tde_osi_get_info_zme(tde_update_config * reg,tde_update_info * info)2169 static hi_void tde_osi_get_info_zme(tde_update_config *reg, tde_update_info *info)
2170 {
2171     info->zme_instart_w = reg->update_instart_w;
2172     info->zme_outstart_w = reg->update_instart_w;
2173     info->zme_in_width = reg->update_in_width;
2174     info->zme_out_width = reg->update_in_width;
2175     info->zme_hphase = 0;
2176 }
2177 
2178 /* The constants used in this function are algorithm-specific values and are not part of the devil number */
tde_osi_get_hupdate_info(tde_update_config * reg,tde_update_info * info,hi_bool scaler)2179 static hi_void tde_osi_get_hupdate_info(tde_update_config *reg, tde_update_info *info, hi_bool scaler)
2180 {
2181     hi_s32 zme_hinstart, zme_hinstop, zme_houtstart, zme_houtstop, zme_hphase, ratio, dratio;
2182     hi_s32 update_hstart = reg->update_instart_w;
2183     hi_s32 update_hstop = update_hstart + reg->update_in_width - 1;
2184 
2185     if (((reg->zme_out_width - 1) == 0) || ((reg->ori_in_width - 1) == 0)) {
2186         return;
2187     }
2188 
2189     /* 4096 2 alg data */
2190     ratio = (hi_s32)(4096 * (reg->ori_in_width - 1) / (reg->zme_out_width - 1) + 1 / 2);
2191     /* 4096 alg data */
2192     dratio = 4096 * (reg->zme_out_width - 1) / (reg->ori_in_width - 1);
2193 
2194     if (scaler != HI_TRUE) { /* hor_scaler not enable */
2195         tde_osi_get_info_zme(reg, info);
2196         return;
2197     }
2198 
2199     if ((update_hstart >= 0) && (update_hstart < 3)) { /* 3 alg data */
2200         /* update outstretched area exceed left limit bordline */
2201         tde_osi_set_value_to_clear(&zme_hinstart, &zme_houtstart, &zme_hphase);
2202     } else {
2203         /* update outstretched area didn't exceed the left limit bordline */
2204         zme_hinstart = (update_hstart - 3) * dratio; /* 3 alg data */
2205         /* 12 4096 alg data */
2206         zme_houtstart = (zme_hinstart % 4096) == 0 ? ((hi_u32)zme_hinstart >> 12) : (((hi_u32)zme_hinstart >> 12) + 1);
2207         zme_hinstart = (hi_u32)(zme_houtstart * ratio) >> 12; /* 12 alg data */
2208         if (zme_hinstart - 2 < 0) { /* 2 alg data */
2209             /* 4096 the left few point need mirror pixels when scale */
2210             zme_hphase = (zme_houtstart * ratio) % 4096 + zme_hinstart * 4096;
2211             zme_hinstart = 0;
2212         } else {
2213             /* 4096 3 the left few point not need mirror pixels when scale */
2214             zme_hphase = (zme_houtstart * ratio) % 4096 + 3 * 4096;
2215             zme_hinstart = zme_hinstart - 2; /* 2 alg data */
2216         }
2217     }
2218 
2219     if ((update_hstop > (reg->ori_in_width - 3)) && (update_hstop < reg->ori_in_width)) { /* 3 alg data */
2220         /* update outstretched area exceed the right limit bordline */
2221         zme_hinstop = reg->ori_in_width - 1;
2222         zme_houtstop = reg->zme_out_width - 1;
2223     } else {
2224         /* 2 1 alg data, update outstretched area didn't exceed the right limit bordline */
2225         zme_hinstop = (update_hstop + 2 + 1) * dratio;
2226         /* 12 4096 alg data */
2227         zme_houtstop = (zme_hinstop % 4096) == 0 ? (((hi_u32)zme_hinstop >> 12) - 1) : ((hi_u32)zme_hinstop >> 12);
2228         zme_hinstop = (hi_u32)(zme_houtstop * ratio) >> 12;  /* 12 alg data */
2229         if (zme_hinstop + 3 > (reg->ori_in_width - 1)) { /* 3 alg data */
2230             /* the right few point need mirror pixels when scale */
2231             zme_hinstop = reg->ori_in_width - 1;
2232         } else {
2233             /* the right few point need mirror pixels when scale */
2234             zme_hinstop = zme_hinstop + 3; /* 3 alg data */
2235         }
2236     }
2237 
2238     info->zme_instart_w = zme_hinstart;
2239     info->zme_outstart_w = zme_houtstart;
2240     info->zme_in_width = zme_hinstop - zme_hinstart + 1;
2241     info->zme_out_width = zme_houtstop - zme_houtstart + 1;
2242     info->zme_hphase = zme_hphase;
2243 }
2244 
tde_osi_get_info_to_reg(tde_update_config * reg,tde_update_info * info)2245 static hi_void tde_osi_get_info_to_reg(tde_update_config *reg, tde_update_info *info)
2246 {
2247     info->zme_instart_h = reg->update_instart_h;
2248     info->zme_in_height = reg->update_in_height;
2249     info->zme_outstart_h = reg->update_instart_h;
2250     info->zme_out_height = reg->update_in_height;
2251     info->zme_vphase = 0;
2252     info->def_offsetup = 0;
2253     info->def_offsetdown = 0;
2254 }
2255 
tde_osi_get_vupdate_info(tde_update_config * reg,tde_update_info * info,int scaler,int is_deflicker)2256 static hi_void tde_osi_get_vupdate_info(tde_update_config *reg, tde_update_info *info, int scaler, int is_deflicker)
2257 {
2258     hi_s32 zme_vinstart, zme_vinstop, zme_voutstart, zme_voutstop, zme_vphase, ratio, dratio;
2259     hi_s32 update_vstart = reg->update_instart_h;
2260     hi_s32 update_vstop = update_vstart + reg->update_in_height - 1;
2261     hi_unused(is_deflicker);
2262 
2263     if ((reg->zme_out_height == 0) || (reg->ori_in_height == 0)) {
2264         return;
2265     }
2266 
2267     ratio = (hi_s32)(4096 * (reg->ori_in_height) / (reg->zme_out_height)); /* 4096 alg data */
2268     dratio = 4096 * (reg->zme_out_height) / (reg->ori_in_height); /* 4096 alg data */
2269 
2270     if (scaler != HI_TRUE) {
2271         tde_osi_get_info_to_reg(reg, info);
2272         return;
2273     }
2274 
2275     /* ver_scale enable & deflicker not enable */
2276     if ((update_vstart >= 0) && (update_vstart < 2)) { /* 2 Vstart */
2277         /* the update outstreatched area exceed the up limit bordline */
2278         tde_osi_set_value_to_clear(&zme_vinstart, &zme_voutstart, &zme_vphase);
2279     } else {
2280         /* the update outstreatched area didn't exceed the up limit bordline */
2281         zme_vinstart = (update_vstart - 2) * dratio; /* 2 alg data */
2282         /* 4096 12 alg data */
2283         zme_voutstart = (zme_vinstart % 4096) == 0 ? ((hi_u32)zme_vinstart >> 12) : (((hi_u32)zme_vinstart >> 12) + 1);
2284         zme_vinstart = (hi_u32)(zme_voutstart * ratio) >> 12; /* 12 alg data */
2285         if (zme_vinstart - 1 < 0) {
2286             /* the up few point need mirror pixels when scale */
2287             zme_vphase = (zme_voutstart * ratio) % 4096 + zme_vinstart * 4096; /* 4096 alg data */
2288             zme_vinstart = 0;
2289         } else {
2290             /* the up few point not need mirror pixels when scale */
2291             zme_vphase = (zme_voutstart * ratio) % 4096 + 1 * 4096; /* 4096 alg data */
2292             zme_vinstart = zme_vinstart - 1;
2293         }
2294     }
2295     /* 2 alg data */
2296     if ((update_vstop > (reg->ori_in_height - 2)) && (update_vstop < reg->ori_in_height)) {
2297         /* the update outstreatched area exceed the down limit bordline */
2298         zme_vinstop = reg->ori_in_height - 1;
2299         zme_voutstop = reg->zme_out_height - 1;
2300     } else {
2301         /* the update outstreatched area didn't exceed the down limit bordline */
2302         zme_vinstop = (update_vstop + 1 + 1) * dratio;
2303         /* 4096 12 alg data */
2304         zme_voutstop = (zme_vinstop % 4096) == 0 ? (((hi_u32)zme_vinstop >> 12) - 1) : ((hi_u32)zme_vinstop >> 12);
2305         zme_vinstop = (hi_u32)(zme_voutstop * ratio) >> 12; /* 12 alg data */
2306         if (zme_vinstop + 2 > (reg->ori_in_height - 1)) { /* 2 alg data */
2307             /* the down few point need mirror pixels when scale */
2308             zme_vinstop = reg->ori_in_height - 1;
2309         } else {
2310             /* the down few point not need mirror pixels when scale */
2311             zme_vinstop = zme_vinstop + 2; /* 2 alg data */
2312         }
2313     }
2314 
2315     info->zme_in_height = zme_vinstop - zme_vinstart + 1;
2316     info->zme_instart_h = zme_vinstart;
2317     info->zme_outstart_h = zme_voutstart;
2318     info->zme_out_height = zme_voutstop - zme_voutstart + 1;
2319     info->zme_vphase = zme_vphase;
2320     info->def_offsetup = 0;
2321     info->def_offsetdown = 0;
2322 }
2323 #endif
2324 #endif
2325 
2326 #ifndef HI_BUILD_IN_BOOT
tde_osi_src2_filter_reg(hi_tde_double_src * double_src,tde_update_config * reg)2327 static hi_void tde_osi_src2_filter_reg(hi_tde_double_src *double_src, tde_update_config *reg)
2328 {
2329     reg->ori_in_height = double_src->fg_surface->height;
2330     reg->ori_in_width = double_src->fg_surface->width;
2331     reg->zme_out_height = double_src->dst_surface->height;
2332     reg->zme_out_width = double_src->dst_surface->width;
2333     reg->update_instart_w = double_src->fg_rect->pos_x;
2334     reg->update_instart_h = double_src->fg_rect->pos_y;
2335     reg->update_in_width = double_src->fg_rect->width;
2336     reg->update_in_height = double_src->fg_rect->height;
2337 }
2338 
tde_osi_src2_filter_rect_opt(tde_rect_opt * rect_opt,tde_update_info * info)2339 static hi_void tde_osi_src2_filter_rect_opt(tde_rect_opt *rect_opt, tde_update_info *info)
2340 {
2341     rect_opt->in_rect->pos_x = info->zme_instart_w;
2342     rect_opt->in_rect->pos_y = info->zme_instart_h;
2343     rect_opt->in_rect->width = info->zme_in_width;
2344     rect_opt->in_rect->height = info->zme_in_height;
2345 
2346     rect_opt->out_rect->pos_x = info->zme_outstart_w;
2347     rect_opt->out_rect->pos_y = info->zme_outstart_h;
2348     rect_opt->out_rect->width = info->zme_out_width;
2349     rect_opt->out_rect->height = info->zme_out_height;
2350 }
2351 
tde_osi_src2_filter_opt(tde_hw_node * node,hi_tde_double_src * double_src,tde_rect_opt * rect_opt,hi_tde_deflicker_mode deflicker_mode,hi_tde_deflicker_mode filter_mode)2352 static hi_s32 tde_osi_src2_filter_opt(tde_hw_node *node, hi_tde_double_src *double_src, tde_rect_opt *rect_opt,
2353     hi_tde_deflicker_mode deflicker_mode, hi_tde_deflicker_mode filter_mode)
2354 {
2355     hi_s32 ret;
2356     tde_update_config reg = { 0 };
2357     tde_update_info info = { 0 };
2358     hi_bool is_deflicker = HI_FALSE;
2359     hi_bool scale = HI_FALSE;
2360 
2361 #if (TDE_CAPABILITY & DEFLICKER)
2362     is_deflicker = (deflicker_mode == HI_TDE_DEFLICKER_LEVEL_MODE_NONE) ? HI_FALSE : HI_TRUE;
2363 #else
2364     hi_unused(deflicker_mode);
2365 #endif
2366     tde_osi_src2_filter_reg(double_src, &reg);
2367     if (node->src2_hsp.bits.hratio != TDE_NO_SCALE_HSTEP) {
2368         scale = HI_TRUE;
2369     }
2370 
2371     tde_info("bHScale:%x\n", scale);
2372     tde_osi_get_hupdate_info(&reg, &info, scale);
2373 
2374     scale = HI_FALSE;
2375     if (node->src2_vsr.bits.vratio != TDE_NO_SCALE_VSTEP) {
2376         scale = HI_TRUE;
2377     }
2378     tde_info("bVScale:%x\n", scale);
2379     tde_osi_get_vupdate_info(&reg, &info, scale, is_deflicker);
2380 
2381     node->src2_imgsize.bits.src2_width = info.zme_in_width - 1;
2382     node->src2_zmeireso.bits.iw = info.zme_in_width - 1;
2383 
2384     node->src2_imgsize.bits.src2_height = info.zme_in_height - 1;
2385     node->src2_zmeireso.bits.ih = info.zme_in_height - 1;
2386 
2387     double_src->dst_rect->pos_x = info.zme_outstart_w;
2388     double_src->dst_rect->pos_y = info.zme_outstart_h;
2389     double_src->dst_rect->width = info.zme_out_width;
2390     double_src->dst_rect->height = info.zme_out_height;
2391 
2392     node->src2_hcoffset = info.zme_hphase;
2393     node->src2_voffset.bits.vluma_offset = info.zme_vphase;
2394 
2395     tde_osi_src2_filter_rect_opt(rect_opt, &info);
2396 #if ((HICHIP == HI3516C_V500) || (HICHIP == HI3519A_V100))
2397     if ((rect_opt->in_rect->width > MAX_LINE_BUFFER) && (rect_opt->out_rect->width > MAX_LINE_BUFFER)) {
2398     tde_error("it does not support local resize in width %d && out width %d over max line buffer %d!! \n",
2399               rect_opt->in_rect->width, rect_opt->out_rect->width, MAX_LINE_BUFFER);
2400         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
2401     }
2402 #endif
2403     ret = tde_hal_calc_src2_filter_opt(node, rect_opt, is_deflicker, filter_mode);
2404     if (ret != HI_SUCCESS) {
2405         return ret;
2406     }
2407     return HI_SUCCESS;
2408 }
2409 
tde_osi_filter_reg(tde_hw_node * node,hi_tde_double_src * double_src,hi_tde_deflicker_mode deflicker_mode,hi_tde_deflicker_mode filter_mode)2410 static hi_s32 tde_osi_filter_reg(tde_hw_node *node, hi_tde_double_src *double_src,
2411     hi_tde_deflicker_mode deflicker_mode, hi_tde_deflicker_mode filter_mode)
2412 {
2413     hi_s32 ret;
2414     tde_rect_opt rect_opt;
2415     hi_tde_rect in_rect, out_rect;
2416     hi_u64 src2_addr, dst_addr;
2417     hi_tde_color_fmt out_fmt = double_src->dst_surface->color_fmt;
2418     hi_bool back_ground_operation = ((double_src->bg_surface != HI_NULL) && (double_src->bg_rect != HI_NULL));
2419 
2420     rect_opt.in_fmt = double_src->fg_surface->color_fmt;
2421     rect_opt.in_rect = &in_rect;
2422     rect_opt.out_rect = &out_rect;
2423     if (((double_src->fg_surface->width != double_src->fg_rect->width) ||
2424          (double_src->fg_surface->height != double_src->fg_rect->height)) && g_region_deflicker) {
2425         ret = tde_osi_src2_filter_opt(node, double_src, &rect_opt, deflicker_mode, filter_mode);
2426         if (ret != HI_SUCCESS) {
2427             return ret;
2428         }
2429         if (double_src->dst_surface->width <= 1) {
2430             node->src2_hsp.bits.hratio = 0;
2431         } else {
2432             node->src2_hsp.bits.hratio = osal_div_u64(
2433                 ((hi_u64)(double_src->fg_surface->width) << TDE_HAL_HSTEP_FLOATLEN),
2434                 (double_src->dst_surface->width));
2435         }
2436 
2437         if (double_src->dst_surface->height <= 1) {
2438             node->src2_vsr.bits.vratio = 0;
2439         } else {
2440             node->src2_vsr.bits.vratio = osal_div_u64(((hi_u64)(double_src->fg_surface->height) << TDE_FLOAT_BITLEN),
2441                                                       (double_src->dst_surface->height));
2442         }
2443         src2_addr = double_src->fg_surface->phy_addr;
2444         dst_addr = double_src->dst_surface->phy_addr;
2445         src2_addr += rect_opt.in_rect->pos_y * node->src2_ch0_stride.bits.src2_ch0_stride  +
2446             ((hi_u32)(rect_opt.in_rect->pos_x * tde_osi_get_bpp_by_fmt(rect_opt.in_fmt)) >> 3); /* 2^3 pos_x data */
2447         dst_addr += rect_opt.out_rect->pos_y * node->des_ch0_stride.bits.des_ch0_stride +
2448             ((hi_u32)(rect_opt.out_rect->pos_x * tde_osi_get_bpp_by_fmt(out_fmt)) >> 3); /* 2^3 pos_x data */
2449 
2450         node->src2_ch0_addr_low.bits.src2_ch0_addr_low = GetLowAddr(src2_addr);
2451         node->src2_ch0_addr_high.bits.src2_ch0_addr_high = GetHighAddr(src2_addr);
2452 
2453         node->des_ch0_addr_low.bits.des_ch0_addr_low = GetLowAddr(dst_addr);
2454         node->des_ch0_addr_high.bits.des_ch0_addr_high = GetHighAddr(dst_addr);
2455         if (back_ground_operation) {
2456             node->src1_imgsize.bits.src1_width = node->des_imgsize.bits.des_width;
2457             node->src1_imgsize.bits.src1_height = node->des_imgsize.bits.des_height;
2458         }
2459     }
2460     return HI_SUCCESS;
2461 }
2462 #endif
2463 
tde_osi_filter_opera(tde_hw_node * node,hi_tde_double_src * double_src,hi_tde_deflicker_mode deflicker_mode,hi_tde_deflicker_mode filter_mode)2464 static hi_s32 tde_osi_filter_opera(tde_hw_node *node, hi_tde_double_src *double_src,
2465     hi_tde_deflicker_mode deflicker_mode, hi_tde_deflicker_mode filter_mode)
2466 {
2467     hi_s32 ret;
2468     hi_bool is_deflicker = HI_FALSE;
2469     tde_rect_opt rect_opt;
2470     hi_bool fore_ground_operation = ((double_src->fg_surface != HI_NULL) && (double_src->fg_rect != HI_NULL));
2471 
2472 #if (TDE_CAPABILITY & DEFLICKER)
2473     is_deflicker = (deflicker_mode == HI_TDE_DEFLICKER_LEVEL_MODE_NONE) ? HI_FALSE : HI_TRUE;
2474 #endif
2475     if (fore_ground_operation) {
2476 #if ((HICHIP == HI3516C_V500) || (HICHIP == HI3519A_V100))
2477         if ((double_src->fg_rect->width > MAX_LINE_BUFFER) && (double_src->dst_rect->width > MAX_LINE_BUFFER)) {
2478             tde_error("it does not support resize in width %d && out width %d over max line buffer %d!! \n",
2479                       double_src->fg_rect->width, double_src->dst_rect->width, MAX_LINE_BUFFER);
2480             return HI_ERR_TDE_UNSUPPORTED_OPERATION;
2481         }
2482 #endif
2483         rect_opt.in_fmt = double_src->fg_surface->color_fmt;
2484         rect_opt.in_rect = double_src->fg_rect;
2485         rect_opt.out_rect = double_src->dst_rect;
2486         ret = tde_hal_calc_src2_filter_opt(node, &rect_opt, is_deflicker, filter_mode);
2487         if (ret != HI_SUCCESS) {
2488             return ret;
2489         }
2490 #ifndef HI_BUILD_IN_BOOT
2491         ret = tde_osi_filter_reg(node, double_src, deflicker_mode, filter_mode);
2492         if (ret != HI_SUCCESS) {
2493             return ret;
2494         }
2495 #endif
2496     }
2497     return HI_SUCCESS;
2498 }
2499 
tde_osi_set_filter_node(hi_s32 handle,tde_hw_node * node,hi_tde_double_src * double_src,hi_tde_deflicker_mode deflicker_mode,hi_tde_deflicker_mode filter_mode)2500 static hi_s32 tde_osi_set_filter_node(hi_s32 handle, tde_hw_node *node, hi_tde_double_src *double_src,
2501     hi_tde_deflicker_mode deflicker_mode, hi_tde_deflicker_mode filter_mode)
2502 {
2503     hi_s32 ret;
2504     hi_bool back_ground_operation = ((double_src->bg_surface != HI_NULL) && (double_src->bg_rect != HI_NULL));
2505 
2506     if (back_ground_operation == HI_TRUE && g_region_deflicker == HI_FALSE) {
2507 #if ((HICHIP == HI3516C_V500) || (HICHIP == HI3519A_V100))
2508         if ((double_src->bg_rect->width != double_src->dst_rect->width) ||
2509             (double_src->bg_rect->height != double_src->dst_rect->height)) {
2510             tde_error("it does not support  src1 resize!! \n");
2511             return HI_ERR_TDE_UNSUPPORTED_OPERATION;
2512         }
2513 #else
2514         tde_hal_calc_src1_filter_opt(node, double_src->bg_surface->color_fmt, double_src->bg_rect,
2515             double_src->dst_rect, filter_mode);
2516 #endif
2517     }
2518     ret = tde_osi_filter_opera(node, double_src, deflicker_mode, filter_mode);
2519     if (ret != HI_SUCCESS) {
2520         return ret;
2521     }
2522 #if (TDE_CAPABILITY & SLICE)
2523     return tde_osi_calc_slice(handle, node);
2524 #else
2525     ret = tde_osi_set_node_finish(handle, node, 0, TDE_NODE_SUBM_ALONE);
2526     if (ret < 0) {
2527         return ret;
2528     }
2529     return HI_SUCCESS;
2530 #endif
2531 }
2532 
2533 /*
2534  * Function:      tde_osi_adj_para4_ycb_cr422_r
2535  * Description:   when fill color is YCbCr422R, fill by word
2536  * Input:         dst_surface: target bitmap info struct
2537  *                dst_rect: target operate zone
2538  *                fill_color: fill color
2539  * Others:        add software fill, when YCbCr422, fill function by word
2540  */
tde_osi_adj_para4_ycb_cr422_r(hi_tde_surface * dst_surface,hi_tde_rect * dst_rect,hi_tde_fill_color * fill_color)2541 static hi_void tde_osi_adj_para4_ycb_cr422_r(hi_tde_surface *dst_surface, hi_tde_rect *dst_rect,
2542                                              hi_tde_fill_color *fill_color)
2543 {
2544     if ((dst_surface->color_fmt != HI_TDE_COLOR_FMT_YCBCR422) &&
2545         (dst_surface->color_fmt != HI_TDE_COLOR_FMT_PKGVYUY)) {
2546         return;
2547     }
2548 
2549     dst_surface->color_fmt = HI_TDE_COLOR_FMT_AYCBCR8888;
2550     dst_surface->alpha_max_is_255 = HI_TRUE;
2551     fill_color->color_fmt = HI_TDE_COLOR_FMT_AYCBCR8888;
2552 
2553     dst_surface->width /= 2; /* 2 width */
2554 
2555     dst_rect->width /= 2; /* 2 width */
2556     dst_rect->pos_x /= 2; /* 2 pos_x */
2557 
2558     fill_color->color_value = tde_get_yc422r_fillvalue(fill_color->color_value);
2559 }
2560 
tde_osi_check_fill_opt(hi_tde_opt * opt)2561 static hi_s32 tde_osi_check_fill_opt(hi_tde_opt *opt)
2562 {
2563     hi_bool real = (((opt->blend_opt.global_alpha_en != HI_TRUE) && (opt->blend_opt.global_alpha_en != HI_FALSE)) ||
2564         ((opt->blend_opt.pixel_alpha_en != HI_TRUE) && (opt->blend_opt.pixel_alpha_en != HI_FALSE)) ||
2565         ((opt->blend_opt.src1_alpha_premulti != HI_TRUE) && (opt->blend_opt.src1_alpha_premulti != HI_FALSE)) ||
2566         ((opt->blend_opt.src2_alpha_premulti != HI_TRUE) && (opt->blend_opt.src2_alpha_premulti != HI_FALSE)) ||
2567         ((opt->clut_reload != HI_TRUE) && (opt->clut_reload != HI_FALSE)) ||
2568         ((opt->is_compress != HI_TRUE) && (opt->is_compress != HI_FALSE)) ||
2569         ((opt->is_decompress != HI_TRUE) && (opt->is_decompress != HI_FALSE)));
2570 
2571     if ((opt->color_key_mode >= HI_TDE_COLOR_KEY_MODE_MAX) ||
2572         (opt->color_key_mode < HI_TDE_COLOR_KEY_MODE_NONE)) {
2573         tde_error("color_key_mode error!\n");
2574         return HI_ERR_TDE_INVALID_PARA;
2575     }
2576 
2577     if (real) {
2578         tde_error("hi_bool should be HI_TRUE or HI_FALSE!!\n");
2579         return HI_ERR_TDE_INVALID_PARA;
2580     }
2581 
2582     if ((opt->deflicker_mode >= HI_TDE_DEFLICKER_LEVEL_MODE_MAX) ||
2583         (opt->deflicker_mode < HI_TDE_DEFLICKER_LEVEL_MODE_NONE)) {
2584         tde_error("deflicker_mode error!\n");
2585         return HI_ERR_TDE_INVALID_PARA;
2586     }
2587 
2588     if ((opt->filter_mode >= HI_TDE_FILTER_MODE_MAX) || (opt->filter_mode < HI_TDE_FILTER_MODE_COLOR)) {
2589         tde_error("filter_mode error!\n");
2590         return HI_ERR_TDE_INVALID_PARA;
2591     }
2592 
2593     if ((opt->mirror >= HI_TDE_MIRROR_MAX) || (opt->mirror < HI_TDE_MIRROR_NONE)) {
2594         tde_error("mirror error!\n");
2595         return HI_ERR_TDE_INVALID_PARA;
2596     }
2597 
2598     if (opt->alpha_blending_cmd >= HI_TDE_ALPHA_BLENDING_MAX ||
2599         opt->alpha_blending_cmd < HI_TDE_ALPHA_BLENDING_NONE) {
2600         tde_error("alpha_blending_cmd error!\n");
2601         return HI_ERR_TDE_INVALID_PARA;
2602     }
2603 
2604     if (opt->alpha_blending_cmd != HI_TDE_ALPHA_BLENDING_NONE) {
2605         tde_error("invalid alu command!\n");
2606         return HI_ERR_TDE_INVALID_PARA;
2607     }
2608 
2609     if (opt->resize) {
2610         tde_error("Not support resize in single source fill operation!\n");
2611         return HI_ERR_TDE_INVALID_PARA;
2612     }
2613     return HI_SUCCESS;
2614 }
2615 
2616 #ifndef HI_BUILD_IN_BOOT
tde_osi_1_source_src1(hi_tde_surface * dst_surface,hi_tde_opt * opt,tde_hw_node * hw_node,hi_tde_rect * dst_rect)2617 static hi_s32 tde_osi_1_source_src1(hi_tde_surface *dst_surface, hi_tde_opt *opt, tde_hw_node *hw_node,
2618                                     hi_tde_rect *dst_rect)
2619 {
2620     hi_s32 ret;
2621     hi_tde_double_src double_src;
2622     ret = tde_osi_check_fill_opt(opt);
2623     if (ret != HI_SUCCESS) {
2624         tde_hal_free_node_buf(hw_node);
2625         return HI_ERR_TDE_INVALID_PARA;
2626     }
2627     if ((opt->out_alpha_from >= HI_TDE_OUT_ALPHA_FROM_MAX) ||
2628         (opt->out_alpha_from == HI_TDE_OUT_ALPHA_FROM_FOREGROUND)) {
2629         tde_error("out_alpha_from error!\n");
2630         tde_hal_free_node_buf(hw_node);
2631         return HI_ERR_TDE_INVALID_PARA;
2632     }
2633 
2634     tde_hal_node_set_global_alpha(hw_node, opt->global_alpha, opt->blend_opt.global_alpha_en);
2635 
2636     double_src.bg_surface = HI_NULL;
2637     double_src.bg_rect = HI_NULL;
2638     double_src.fg_surface = dst_surface;
2639     double_src.fg_rect = dst_rect;
2640     double_src.dst_surface = dst_surface;
2641     double_src.dst_rect = dst_rect;
2642     if (tde_osi_set_clip_para(&double_src, opt, hw_node) != HI_SUCCESS) {
2643         tde_hal_free_node_buf(hw_node);
2644         return HI_ERR_TDE_CLIP_AREA;
2645     }
2646     return HI_SUCCESS;
2647 }
2648 #endif
2649 
tde_osi_1_source_check(hi_tde_surface * dst_surface,hi_tde_rect * dst_rect,hi_tde_fill_color * fill_color,hi_tde_rect * rect)2650 static hi_s32 tde_osi_1_source_check(hi_tde_surface *dst_surface, hi_tde_rect *dst_rect,
2651                                      hi_tde_fill_color *fill_color, hi_tde_rect *rect)
2652 {
2653     hi_bool null_ptr = ((dst_surface == HI_NULL) || (dst_rect == HI_NULL) || (fill_color == HI_NULL));
2654     hi_s32 bpp;
2655 
2656     if (null_ptr) {
2657         tde_error("HI_NULL pointer!\n");
2658         return HI_ERR_TDE_NULL_PTR;
2659     }
2660     if (memcpy_s(rect, sizeof(hi_tde_rect), dst_rect, sizeof(hi_tde_rect)) != EOK) {
2661         tde_error("secure function failure\n");
2662         return HI_ERR_TDE_INVALID_PARA;
2663     }
2664 
2665     if ((dst_surface->color_fmt >= HI_TDE_COLOR_FMT_JPG_YCBCR400MBP) ||
2666         (fill_color->color_fmt >= HI_TDE_COLOR_FMT_JPG_YCBCR400MBP)) {
2667         tde_error("This operation doesn't support Semi-plannar!\n");
2668         return HI_ERR_TDE_INVALID_PARA;
2669     }
2670 
2671 #ifdef TDE_BACKGROUND_COLORFOMATSUPPORT_YCBCR422
2672     if (dst_surface->color_fmt >= HI_TDE_COLOR_FMT_YCBCR422) {
2673         tde_error("Background  doesn't support the colorfmt!\n");
2674         return HI_ERR_TDE_INVALID_PARA;
2675     }
2676 #endif
2677 
2678     if (tde_osi_check_surface(dst_surface, rect) != HI_SUCCESS) {
2679         return HI_ERR_TDE_INVALID_PARA;
2680     }
2681 
2682     bpp = tde_osi_get_bpp_by_fmt(dst_surface->color_fmt);
2683     if (bpp < 0) {
2684         tde_error("Unknown color format!\n");
2685         return HI_ERR_TDE_INVALID_PARA;
2686     }
2687 
2688     if (bpp < 8) { /* 8 is bpp */
2689         /* when writing, 8 subbyte format align ask start point byte align */
2690         if ((rect->pos_x % 8) || (rect->width * bpp % 8)) {
2691             tde_error("Subbyte's start or width for writing is not aligned!\n");
2692             return HI_ERR_TDE_INVALID_PARA;
2693         }
2694     }
2695     tde_osi_adj_para4_ycb_cr422_r(dst_surface, rect, fill_color);
2696     return HI_SUCCESS;
2697 }
2698 
tde_osi_1_source_drv(hi_tde_surface * dst_surface,tde_base_opt_mode base_mode,hi_tde_rect * dst_rect,tde_hw_node * hw_node,hi_tde_out_alpha_from out_alpha_from)2699 static hi_void tde_osi_1_source_drv(hi_tde_surface *dst_surface, tde_base_opt_mode base_mode, hi_tde_rect *dst_rect,
2700                                     tde_hw_node *hw_node, hi_tde_out_alpha_from out_alpha_from)
2701 {
2702     tde_scandirection_mode scan_info = { 0 };
2703     tde_surface_msg drv_surface = { 0 };
2704     scan_info.h_scan = TDE_SCAN_LEFT_RIGHT;
2705     scan_info.v_scan = TDE_SCAN_UP_DOWN;
2706     tde_osi_convert_surface(dst_surface, dst_rect, &scan_info, &drv_surface);
2707 
2708     if (base_mode == TDE_NORM_FILL_1OPT) {
2709         tde_hal_node_set_src1(hw_node, &drv_surface);
2710     }
2711 
2712     tde_hal_node_set_tqt(hw_node, &drv_surface, out_alpha_from);
2713 
2714     tde_osi_set_ext_alpha(dst_surface, HI_NULL, hw_node);
2715     return;
2716 }
2717 
2718 /*
2719  * Function:      tde_osi_1_source_fill
2720  * Description:   single source fill operate,source1 is fill color,target bitmap is dst_surface,
2721                   support source1 and fill color do ROP or alpha blending to target bitmap,
2722                   unsupported mirror,colorkey
2723  *                src bitmap is not support MB color format
2724  * Input:         handle: task handle
2725  *                dst_surface: foreground bitmap info struct
2726  *                fill_color:  target bitmap info struct
2727  *                opt: operate parameter setting struct
2728  * Return:        HI_SUCCESS/HI_FAILURE
2729  */
tde_osi_1_source_fill(hi_s32 handle,hi_tde_surface * dst_surface,hi_tde_rect * dst_rect,hi_tde_fill_color * fill_color,hi_tde_opt * opt)2730 static hi_s32 tde_osi_1_source_fill(hi_s32 handle, hi_tde_surface *dst_surface, hi_tde_rect *dst_rect,
2731                                     hi_tde_fill_color *fill_color, hi_tde_opt *opt)
2732 {
2733     tde_base_opt_mode base_mode = { 0 };
2734     tde_hw_node *hw_node = HI_NULL;
2735     hi_tde_out_alpha_from out_alpha_from = HI_TDE_OUT_ALPHA_FROM_NORM;
2736     hi_tde_rect rect = { 0 };
2737     tde_color_fill drv_color_fill = { 0 };
2738     hi_s32 ret = tde_osi_1_source_check(dst_surface, dst_rect, fill_color, &rect);
2739     if (ret != HI_SUCCESS) {
2740         return ret;
2741     }
2742     if (tde_hal_node_init_nd(&hw_node) != HI_SUCCESS) {
2743         return HI_ERR_TDE_NO_MEM;
2744     }
2745 
2746     if (opt == HI_NULL) {
2747         base_mode = (fill_color->color_fmt == dst_surface->color_fmt) ? TDE_QUIKE_FILL : TDE_NORM_FILL_1OPT;
2748         out_alpha_from = HI_TDE_OUT_ALPHA_FROM_NORM;
2749     } else {
2750 #ifndef HI_BUILD_IN_BOOT
2751         ret = tde_osi_1_source_src1(dst_surface, opt, hw_node, &rect);
2752         if (ret != HI_SUCCESS) {
2753             return ret;
2754         }
2755         out_alpha_from = opt->out_alpha_from;
2756         base_mode = (fill_color->color_fmt == dst_surface->color_fmt) ? TDE_QUIKE_FILL : TDE_NORM_FILL_1OPT;
2757 #endif
2758     }
2759     if (base_mode == TDE_NORM_FILL_1OPT) {
2760         if (tde_osi_color_convert(fill_color, dst_surface, &drv_color_fill.fill_data) != HI_SUCCESS) {
2761             tde_hal_free_node_buf(hw_node);
2762             return HI_ERR_TDE_INVALID_PARA;
2763         }
2764         drv_color_fill.drv_color_fmt = TDE_DRV_COLOR_FMT_ARGB8888;
2765     } else {
2766         drv_color_fill.fill_data = fill_color->color_value;
2767         drv_color_fill.drv_color_fmt = g_tde_common_drv_color_fmt[fill_color->color_fmt];
2768     }
2769     if (tde_hal_node_set_base_operate(hw_node, base_mode, TDE_ALU_NONE, &drv_color_fill) != HI_SUCCESS) {
2770         tde_hal_free_node_buf(hw_node);
2771         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
2772     }
2773     tde_osi_1_source_drv(dst_surface, base_mode, &rect, hw_node, out_alpha_from);
2774     ret = tde_osi_set_node_finish(handle, hw_node, 0, TDE_NODE_SUBM_ALONE);
2775     if (ret != HI_SUCCESS) {
2776         tde_hal_free_node_buf(hw_node);
2777         return ret;
2778     }
2779     return HI_SUCCESS;
2780 }
2781 
2782 #ifndef HI_BUILD_IN_BOOT
tde_osi_2_check_opt(hi_tde_opt * opt)2783 static hi_s32 tde_osi_2_check_opt(hi_tde_opt *opt)
2784 {
2785     hi_bool real = (((opt->blend_opt.global_alpha_en != HI_TRUE) && (opt->blend_opt.global_alpha_en != HI_FALSE)) ||
2786         ((opt->blend_opt.pixel_alpha_en != HI_TRUE) && (opt->blend_opt.pixel_alpha_en != HI_FALSE)) ||
2787         ((opt->blend_opt.src1_alpha_premulti != HI_TRUE) && (opt->blend_opt.src1_alpha_premulti != HI_FALSE)) ||
2788         ((opt->blend_opt.src2_alpha_premulti != HI_TRUE) && (opt->blend_opt.src2_alpha_premulti != HI_FALSE)) ||
2789         ((opt->clut_reload != HI_TRUE) && (opt->clut_reload != HI_FALSE)) ||
2790         ((opt->is_compress != HI_TRUE) && (opt->is_compress != HI_FALSE)) ||
2791         ((opt->is_decompress != HI_TRUE) && (opt->is_decompress != HI_FALSE)));
2792 
2793     if (opt->out_alpha_from >= HI_TDE_OUT_ALPHA_FROM_MAX) {
2794         tde_error("out_alpha_from error!\n");
2795         return HI_ERR_TDE_INVALID_PARA;
2796     }
2797 
2798     if (opt->alpha_blending_cmd >= HI_TDE_ALPHA_BLENDING_MAX) {
2799         tde_error("alpha_blending_cmd error!\n");
2800         return HI_ERR_TDE_INVALID_PARA;
2801     }
2802 
2803     if ((opt->color_key_mode >= HI_TDE_COLOR_KEY_MODE_MAX) ||
2804         (opt->color_key_mode < HI_TDE_COLOR_KEY_MODE_NONE)) {
2805         tde_error("color_key_mode error!\n");
2806         return HI_ERR_TDE_INVALID_PARA;
2807     }
2808 
2809     if (real) {
2810         tde_error("hi_bool should be HI_TRUE or HI_FALSE!!\n");
2811         return HI_ERR_TDE_INVALID_PARA;
2812     }
2813 
2814     if ((opt->deflicker_mode >= HI_TDE_DEFLICKER_LEVEL_MODE_MAX) ||
2815         (opt->deflicker_mode < HI_TDE_DEFLICKER_LEVEL_MODE_NONE)) {
2816         tde_error("deflicker_mode error!\n");
2817         return HI_ERR_TDE_INVALID_PARA;
2818     }
2819 
2820     if ((opt->filter_mode >= HI_TDE_FILTER_MODE_MAX) || (opt->filter_mode < HI_TDE_FILTER_MODE_COLOR)) {
2821         tde_error("filter_mode error!\n");
2822         return HI_ERR_TDE_INVALID_PARA;
2823     }
2824 
2825     if ((opt->mirror >= HI_TDE_MIRROR_MAX) || (opt->mirror < HI_TDE_MIRROR_NONE)) {
2826         tde_error("mirror error!\n");
2827         return HI_ERR_TDE_INVALID_PARA;
2828     }
2829     return HI_SUCCESS;
2830 }
2831 
tde_osi_2_source_check(hi_tde_single_src * single_src,hi_tde_fill_color * fill_color,hi_tde_opt * opt,hi_tde_single_src * single_surface_dou)2832 static hi_s32 tde_osi_2_source_check(hi_tde_single_src *single_src, hi_tde_fill_color *fill_color,
2833                                      hi_tde_opt *opt, hi_tde_single_src *single_surface_dou)
2834 {
2835     hi_s32 ret;
2836     hi_bool null_ptr = ((single_src->dst_surface == HI_NULL) || (single_src->dst_rect == HI_NULL) ||
2837                         (fill_color == HI_NULL) || ((opt == HI_NULL)) ||
2838                         (single_src->src_surface == HI_NULL) || (single_src->src_rect == HI_NULL));
2839 
2840     if (null_ptr) {
2841         return HI_ERR_TDE_NULL_PTR;
2842     }
2843 
2844     ret = memcpy_s(single_surface_dou->src_rect, sizeof(hi_tde_rect), single_src->src_rect, sizeof(hi_tde_rect));
2845     tde_unequal_eok_return(ret);
2846     ret = memcpy_s(single_surface_dou->dst_rect, sizeof(hi_tde_rect), single_src->dst_rect, sizeof(hi_tde_rect));
2847     tde_unequal_eok_return(ret);
2848     if (fill_color->color_fmt >= HI_TDE_COLOR_FMT_MAX) {
2849         tde_error("color format error!\n");
2850         return HI_ERR_TDE_INVALID_PARA;
2851     }
2852 
2853     ret = tde_osi_check_dst_fmt(single_src->dst_surface->color_fmt);
2854     if (ret != HI_SUCCESS) {
2855         return ret;
2856     }
2857 #if ((HICHIP == HI3519A_V100) || (HICHIP == HI3516C_V500))
2858     if ((single_src->src_surface->color_fmt == HI_TDE_COLOR_FMT_YCBCR422) ||
2859         (single_src->src_surface->color_fmt == HI_TDE_COLOR_FMT_PKGVYUY)) {
2860         tde_error("This operation doesn't support PKG!\n");
2861         return HI_ERR_TDE_INVALID_PARA;
2862     }
2863 #endif
2864 
2865     ret = tde_osi_2_check_opt(opt);
2866     if (ret != HI_SUCCESS) {
2867         return ret;
2868     }
2869     if (tde_osi_check_surface(single_src->dst_surface, single_surface_dou->dst_rect) != HI_SUCCESS) {
2870         return HI_ERR_TDE_INVALID_PARA;
2871     }
2872 
2873     if (tde_osi_check_surface(single_src->src_surface, single_surface_dou->src_rect) != HI_SUCCESS) {
2874         return HI_ERR_TDE_INVALID_PARA;
2875     }
2876 
2877     if (opt->resize) {
2878         if (tde_osi_check_resize_para(single_src->src_rect->width, single_src->src_rect->height,
2879                                       single_src->dst_rect->width, single_src->dst_rect->height) != HI_SUCCESS) {
2880             return HI_ERR_TDE_MINIFICATION;
2881         }
2882     }
2883 
2884     if (!opt->resize) {
2885         tde_unify_rect(single_surface_dou->src_rect, single_surface_dou->dst_rect);
2886     }
2887     return HI_SUCCESS;
2888 }
2889 
tde_osi_2_source_para(hi_tde_single_src * single_src,hi_tde_fill_color * fill_color,hi_tde_opt * opt,tde_hw_node * hw_node,hi_tde_single_src * single_surface_dou)2890 static hi_s32 tde_osi_2_source_para(hi_tde_single_src *single_src, hi_tde_fill_color *fill_color,
2891     hi_tde_opt *opt, tde_hw_node *hw_node, hi_tde_single_src *single_surface_dou)
2892 {
2893     hi_s32 ret;
2894     hi_tde_double_src double_src;
2895     tde_alu_mode alu_mode = TDE_ALU_NONE;
2896     tde_color_fill drv_color_fill = { 0 };
2897 
2898 #if (TDE_CAPABILITY & ROP)
2899     ret = tde_osi_set_rop(hw_node, opt->alpha_blending_cmd, opt->rop_color, opt->rop_alpha, &alu_mode, HI_FALSE);
2900     if (ret != HI_SUCCESS) {
2901         tde_hal_free_node_buf(hw_node);
2902         return ret;
2903     }
2904 #endif
2905 
2906     ret = tde_osi_set_blend(hw_node, opt->alpha_blending_cmd, opt->blend_opt, &alu_mode, HI_TRUE);
2907     if (ret != HI_SUCCESS) {
2908         tde_hal_free_node_buf(hw_node);
2909         return ret;
2910     }
2911 #if (TDE_CAPABILITY & COLORIZE)
2912     ret = tde_osi_set_colorize(hw_node, opt->alpha_blending_cmd, opt->color_resize);
2913     if (ret != HI_SUCCESS) {
2914         tde_hal_free_node_buf(hw_node);
2915         return ret;
2916     }
2917 #endif
2918     tde_hal_node_set_global_alpha(hw_node, opt->global_alpha, opt->blend_opt.global_alpha_en);
2919 
2920     double_src.bg_surface = HI_NULL;
2921     double_src.bg_rect = HI_NULL;
2922     double_src.fg_surface = single_src->src_surface;
2923     double_src.fg_rect = single_surface_dou->src_rect;
2924     double_src.dst_surface = single_src->dst_surface;
2925     double_src.dst_rect = single_surface_dou->dst_rect;
2926     if (tde_osi_set_clip_para(&double_src, opt, hw_node) != HI_SUCCESS) {
2927         tde_hal_free_node_buf(hw_node);
2928         return HI_ERR_TDE_CLIP_AREA;
2929     }
2930 
2931     if (tde_osi_color_convert(fill_color, single_src->src_surface, &drv_color_fill.fill_data) != HI_SUCCESS) {
2932         tde_hal_free_node_buf(hw_node);
2933         return HI_ERR_TDE_INVALID_PARA;
2934     }
2935 
2936     if (tde_hal_node_set_base_operate(hw_node, TDE_NORM_FILL_2OPT, alu_mode, &drv_color_fill) != HI_SUCCESS) {
2937         tde_hal_free_node_buf(hw_node);
2938         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
2939     }
2940     return HI_SUCCESS;
2941 }
2942 
tde_osi_2_source_node(hi_s32 handle,hi_tde_single_src * single_src,hi_tde_opt * opt,tde_hw_node * hw_node,hi_tde_single_src * single_surface_dou)2943 static hi_s32 tde_osi_2_source_node(hi_s32 handle, hi_tde_single_src *single_src, hi_tde_opt *opt,
2944                                     tde_hw_node *hw_node, hi_tde_single_src *single_surface_dou)
2945 {
2946     hi_tde_double_src double_src;
2947     tde_clut_usage clut_usage = TDE_CLUT_USAGE_BUTT;
2948     hi_bool set_file_node = HI_FALSE;
2949     hi_s32 ret = tde_osi_set_clut_opt(single_src->src_surface, single_src->dst_surface, &clut_usage,
2950         opt->clut_reload, hw_node);
2951     if (ret != HI_SUCCESS) {
2952         tde_hal_free_node_buf(hw_node);
2953         return ret;
2954     }
2955 
2956     ret = tde_osi_set_foreground_color_key(hw_node, single_src->src_surface, opt, clut_usage);
2957     if (ret != HI_SUCCESS) {
2958         tde_hal_free_node_buf(hw_node);
2959         return ret;
2960     }
2961 
2962     set_file_node = ((opt->resize) || (opt->deflicker_mode != HI_TDE_DEFLICKER_LEVEL_MODE_NONE) ||
2963                      (single_src->src_surface->color_fmt >= HI_TDE_COLOR_FMT_YCBCR422));
2964     if (set_file_node) {
2965         double_src.bg_surface = single_src->src_surface;
2966         double_src.bg_rect = single_surface_dou->src_rect;
2967         double_src.fg_surface = HI_NULL;
2968         double_src.fg_rect = HI_NULL;
2969         double_src.dst_surface = single_src->dst_surface;
2970         double_src.dst_rect = single_surface_dou->dst_rect;
2971         ret = tde_osi_set_filter_node(handle, hw_node, &double_src,
2972                                       opt->deflicker_mode, opt->filter_mode);
2973         if (ret != HI_SUCCESS) {
2974             tde_hal_free_node_buf(hw_node);
2975             return ret;
2976         }
2977 #if (TDE_CAPABILITY & SLICE)
2978         tde_hal_free_node_buf(hw_node);
2979 #endif
2980         return HI_SUCCESS;
2981     }
2982     ret = tde_osi_set_node_finish(handle, hw_node, 0, TDE_NODE_SUBM_ALONE);
2983     if (ret != HI_SUCCESS) {
2984         tde_hal_free_node_buf(hw_node);
2985         return ret;
2986     }
2987     return HI_SUCCESS;
2988 }
2989 
tde_osi_2_source_fill(hi_s32 handle,hi_tde_single_src * single_src,hi_tde_fill_color * fill_color,hi_tde_opt * opt)2990 static hi_s32 tde_osi_2_source_fill(hi_s32 handle, hi_tde_single_src *single_src, hi_tde_fill_color *fill_color,
2991                                     hi_tde_opt *opt)
2992 {
2993     tde_hw_node *hw_node = HI_NULL;
2994     tde_surface_msg drv_surface = { 0 };
2995     tde_scandirection_mode src_scan_info = { 0 };
2996     tde_scandirection_mode dst_scan_info = { 0 };
2997     hi_tde_rect src_rect = { 0 };
2998     hi_tde_rect dst_rect = { 0 };
2999     hi_s32 ret;
3000     hi_tde_single_src single_surface_dou;
3001 
3002     single_surface_dou.dst_rect = &dst_rect;
3003     single_surface_dou.dst_surface = HI_NULL;
3004     single_surface_dou.src_rect = &src_rect;
3005     single_surface_dou.src_surface = HI_NULL;
3006     ret = tde_osi_2_source_check(single_src, fill_color, opt, &single_surface_dou);
3007     if (ret != HI_SUCCESS) {
3008         return ret;
3009     }
3010     if (tde_hal_node_init_nd(&hw_node) != HI_SUCCESS) {
3011         return HI_ERR_TDE_NO_MEM;
3012     }
3013 
3014     ret = tde_osi_2_source_para(single_src, fill_color, opt, hw_node, &single_surface_dou);
3015     if (ret != HI_SUCCESS) {
3016         return ret;
3017     }
3018     tde_osi_set_ext_alpha(HI_NULL, single_src->src_surface, hw_node);
3019     single_surface_dou.src_surface = single_src->src_surface;
3020     single_surface_dou.dst_surface = single_src->dst_surface;
3021     if (tde_osi_get_scan_info_ex(&single_surface_dou, opt, &src_scan_info, &dst_scan_info) != HI_SUCCESS) {
3022         tde_hal_free_node_buf(hw_node);
3023         return HI_ERR_TDE_INVALID_PARA;
3024     }
3025 
3026     tde_osi_convert_surface(single_src->src_surface, single_surface_dou.src_rect, &src_scan_info, &drv_surface);
3027 
3028     tde_hal_node_set_src1(hw_node, &drv_surface);
3029 
3030     tde_osi_convert_surface(single_src->dst_surface, single_surface_dou.dst_rect, &dst_scan_info, &drv_surface);
3031 
3032     tde_hal_node_set_tqt(hw_node, &drv_surface, opt->out_alpha_from);
3033     ret = tde_osi_2_source_node(handle, single_src, opt, hw_node, &single_surface_dou);
3034     if (ret != HI_SUCCESS) {
3035         return ret;
3036     }
3037 
3038     return HI_SUCCESS;
3039 }
3040 
tde_osi_set_foreground_color_key(tde_hw_node * hw_node,hi_tde_surface * src_surface,hi_tde_opt * opt,tde_clut_usage clut_usage)3041 static hi_s32 tde_osi_set_foreground_color_key(tde_hw_node *hw_node, hi_tde_surface *src_surface, hi_tde_opt *opt,
3042                                                tde_clut_usage clut_usage)
3043 {
3044     tde_color_key_cmd color_key;
3045     tde_colorfmt_category fmt_category;
3046     hi_bool foreground_colorkey_after_clut = HI_FALSE;
3047     color_key.color_key_value = opt->color_key_value;
3048     foreground_colorkey_after_clut = ((clut_usage != TDE_CLUT_COLOREXPENDING) && (clut_usage != TDE_CLUT_CLUT_BYPASS));
3049 
3050     if (opt->color_key_mode == HI_TDE_COLOR_KEY_MODE_BACKGROUND) {
3051         tde_error("Unsupported solidraw colorkey in background mode!\n");
3052 
3053         return HI_ERR_TDE_INVALID_PARA;
3054     }
3055 
3056     if ((opt->color_key_mode != HI_TDE_COLOR_KEY_MODE_FOREGROUND) &&
3057         (opt->color_key_mode != HI_TDE_COLOR_KEY_MODE_BACKGROUND)) {
3058         return HI_SUCCESS;
3059     }
3060 
3061     color_key.color_key_mode = (foreground_colorkey_after_clut) ? TDE_DRV_COLORKEY_FOREGROUND_AFTER_CLUT :
3062                                 TDE_DRV_COLORKEY_FOREGROUND_BEFORE_CLUT;
3063 
3064     fmt_category = tde_osi_get_fmt_category(src_surface->color_fmt);
3065     if (fmt_category >= TDE_COLORFMT_CATEGORY_BUTT) {
3066         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
3067     }
3068 
3069     if (tde_hal_node_set_colorkey(hw_node, fmt_category, &color_key) != HI_SUCCESS) {
3070         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
3071     }
3072 
3073     return HI_SUCCESS;
3074 }
3075 #endif
3076 
3077 /*
3078  * Function:      tde_osi_check_surface
3079  * Description:   adjust right operate zone, according by the size of bitmap and operate zone from user upload
3080  * Input:         surface: bitmap info
3081  *                rect: bitmap operate zone
3082  * Return:        success/fail
3083  */
tde_osi_check_surface(hi_tde_surface * surface,hi_tde_rect * rect)3084 static hi_s32 tde_osi_check_surface(hi_tde_surface *surface, hi_tde_rect *rect)
3085 {
3086     hi_bool invalid_operation_area = HI_FALSE;
3087     hi_s32 ret = tde_osi_pre_check_surface_ex(surface, rect);
3088     if (ret != HI_SUCCESS) {
3089         return ret;
3090     }
3091 
3092     invalid_operation_area = ((TDE_MAX_RECT_WIDTH < rect->width) || (TDE_MAX_RECT_HEIGHT < rect->height));
3093 
3094     if (invalid_operation_area) {
3095         tde_error("operation area is over maximum!Width:%d,Height:%d\n", rect->width, rect->height);
3096         return HI_ERR_TDE_INVALID_PARA;
3097     }
3098 
3099     return HI_SUCCESS;
3100 }
3101 
tde_osi_pre_check_surface(hi_tde_surface * surface,hi_tde_rect * rect)3102 static hi_s32 tde_osi_pre_check_surface(hi_tde_surface *surface, hi_tde_rect *rect)
3103 {
3104     hi_bool real = ((surface->stride > TDE_MAX_SURFACE_PITCH) || (surface->stride == 0) || (rect->height == 0) ||
3105         (rect->width == 0) || (rect->pos_x < 0) || ((hi_u32)rect->pos_x >= surface->width) ||
3106         (rect->pos_y < 0) || ((hi_u32)rect->pos_y >= surface->height) || (surface->phy_addr == 0));
3107 
3108     if (surface->color_fmt >= HI_TDE_COLOR_FMT_MAX) {
3109         tde_error("color format error!\n");
3110         return HI_ERR_TDE_INVALID_PARA;
3111     }
3112 
3113     if (real) {
3114         tde_error("sw:%d, sh:%d, stride:%d, sphy:%llx, x:%d, y:%d, w:%d, h:%d\n", surface->width,
3115             surface->height, surface->stride, surface->phy_addr, rect->pos_x,
3116             rect->pos_y, rect->width, rect->height);
3117         tde_error("invalid surface phyaddr or invalid surface size or operation area!");
3118         return -1;
3119     }
3120     real = (((surface->support_alpha_ext_1555 != HI_TRUE) && (surface->support_alpha_ext_1555 != HI_FALSE)) ||
3121         ((surface->alpha_max_is_255 != HI_TRUE) && (surface->alpha_max_is_255 != HI_FALSE)) ||
3122         ((surface->is_ycbcr_clut != HI_TRUE) && (surface->is_ycbcr_clut != HI_FALSE)));
3123     if (real) {
3124         tde_error("hi_bool should be HI_TRUE or HI_FALSE!!\n");
3125         return HI_ERR_TDE_INVALID_PARA;
3126     }
3127 
3128     return HI_SUCCESS;
3129 }
3130 
3131 #ifdef  CONFIG_DRM_HISI_HISMART
3132 extern int drm_check_dumb_phy_addr(unsigned long long addr_start, unsigned long long size);
tde_osi_pre_check_drm_dumb(hi_tde_surface * surface,hi_u32 size)3133 static hi_s32 tde_osi_pre_check_drm_dumb(hi_tde_surface *surface, hi_u32 size)
3134 {
3135     hi_s32 ret;
3136     ret = drm_check_dumb_phy_addr(surface->phy_addr, size);
3137     if (ret != HI_SUCCESS) {
3138         return HI_ERR_TDE_INVALID_PARA;
3139     }
3140     if (surface->cbcr_phy_addr != 0) {
3141         size = surface->cbcr_stride * surface->height;
3142         if ((surface->color_fmt == HI_TDE_COLOR_FMT_JPG_YCBCR422MBVP) ||
3143             (surface->color_fmt == HI_TDE_COLOR_FMT_MP1_YCBCR420MBP) ||
3144             (surface->color_fmt == HI_TDE_COLOR_FMT_MP2_YCBCR420MBP) ||
3145             (surface->color_fmt == HI_TDE_COLOR_FMT_MP2_YCBCR420MBI) ||
3146             (surface->color_fmt == HI_TDE_COLOR_FMT_JPG_YCBCR420MBP)) {
3147             size = surface->cbcr_stride * (surface->height / 2); /* 2 half data height */
3148         }
3149         ret = drm_check_dumb_phy_addr(surface->cbcr_phy_addr, size);
3150         if (ret != HI_SUCCESS) {
3151             return HI_ERR_TDE_INVALID_PARA;
3152         }
3153     }
3154     return HI_SUCCESS;
3155 }
3156 #endif
3157 
tde_osi_pre_check_mmz(hi_tde_surface * surface,hi_u32 size)3158 static hi_s32 tde_osi_pre_check_mmz(hi_tde_surface *surface, hi_u32 size)
3159 {
3160     hi_s32 ret;
3161 #ifdef  CONFIG_DRM_HISI_HISMART
3162     ret = tde_osi_pre_check_drm_dumb(surface, size);
3163     if (ret == HI_SUCCESS) {
3164         return HI_SUCCESS;
3165     }
3166 #endif
3167     ret = cmpi_check_mmz_phy_addr(surface->phy_addr, size);
3168     if (ret != HI_SUCCESS) {
3169         tde_error("Check surface phy addr failed!\n");
3170         return HI_ERR_TDE_INVALID_PARA;
3171     }
3172     if (surface->cbcr_phy_addr != 0) {
3173         size = surface->cbcr_stride * surface->height;
3174         if ((surface->color_fmt == HI_TDE_COLOR_FMT_JPG_YCBCR422MBVP) ||
3175             (surface->color_fmt == HI_TDE_COLOR_FMT_MP1_YCBCR420MBP) ||
3176             (surface->color_fmt == HI_TDE_COLOR_FMT_MP2_YCBCR420MBP) ||
3177             (surface->color_fmt == HI_TDE_COLOR_FMT_MP2_YCBCR420MBI) ||
3178             (surface->color_fmt == HI_TDE_COLOR_FMT_JPG_YCBCR420MBP)) {
3179             size = surface->cbcr_stride * (surface->height / 2); /* 2 half data height */
3180         }
3181         ret = cmpi_check_mmz_phy_addr(surface->cbcr_phy_addr, size);
3182         if (ret != HI_SUCCESS) {
3183             tde_error("Check MB surface cbcr_phy_addr addr failed!\n");
3184             return HI_ERR_TDE_INVALID_PARA;
3185         }
3186     }
3187     return HI_SUCCESS;
3188 }
3189 
tde_osi_get_rect_wh(hi_tde_surface * surface,hi_tde_rect * rect)3190 static hi_void tde_osi_get_rect_wh(hi_tde_surface *surface, hi_tde_rect *rect)
3191 {
3192     if (rect->pos_x + rect->width > surface->width) {
3193         rect->width = surface->width - rect->pos_x;
3194     }
3195 
3196     if (rect->pos_y + rect->height > surface->height) {
3197         rect->height = surface->height - rect->pos_y;
3198     }
3199 }
3200 
tde_osi_pre_check_surface_ex(hi_tde_surface * surface,hi_tde_rect * rect)3201 static hi_s32 tde_osi_pre_check_surface_ex(hi_tde_surface *surface, hi_tde_rect *rect)
3202 {
3203     hi_bool unknown_color_fmt = HI_FALSE;
3204     hi_bool raster_fmt = HI_FALSE;
3205     hi_u32 size;
3206     hi_s32 bpp;
3207     hi_s32 ret = tde_osi_pre_check_surface(surface, rect);
3208     if (ret != HI_SUCCESS) {
3209         return ret;
3210     }
3211     bpp = tde_osi_get_bpp_by_fmt(surface->color_fmt);
3212     /* CMPI_CheckMmzphy_addr Call a semaphore,Cannot be used in the interrupt */
3213     if (!osal_in_interrupt()) {
3214         if (bpp >= 8) { /* 8 bpp data */
3215             size = (surface->stride * (surface->height - 1)) + (surface->width * bpp / 8);
3216         } else {
3217             size = surface->stride * surface->height;
3218         }
3219         ret = tde_osi_pre_check_mmz(surface, size);
3220         if (ret != HI_SUCCESS) {
3221             return ret;
3222         }
3223     }
3224     unknown_color_fmt = (surface->color_fmt >= HI_TDE_COLOR_FMT_MAX);
3225     if (unknown_color_fmt) {
3226         tde_error("Unknown color format!\n");
3227         return HI_ERR_TDE_INVALID_PARA;
3228     }
3229 
3230     unknown_color_fmt = ((((hi_u32)(rect->pos_x) & 0x1) || (rect->width & 0x1)) &&
3231         ((surface->color_fmt == HI_TDE_COLOR_FMT_YCBCR422) || (surface->color_fmt == HI_TDE_COLOR_FMT_PKGVYUY)));
3232     if (unknown_color_fmt) {
3233         tde_error("x, width of YCbCr422R couldn't be odd!\n");
3234         return HI_ERR_TDE_INVALID_PARA;
3235     }
3236 
3237     raster_fmt = (surface->color_fmt <= HI_TDE_COLOR_FMT_HALFWORD);
3238     if (raster_fmt) {
3239         ret = tde_osi_raster_fmt_check_align(surface);
3240         if (ret != HI_SUCCESS) {
3241             return ret;
3242         }
3243     } else {
3244         if (((surface->cbcr_stride > TDE_MAX_SURFACE_PITCH) || (surface->cbcr_stride == 0)) &&
3245             (surface->color_fmt != HI_TDE_COLOR_FMT_JPG_YCBCR400MBP)) {
3246             tde_error("Invalid CbCr stride!\n");
3247             return HI_ERR_TDE_INVALID_PARA;
3248         }
3249     }
3250     tde_osi_get_rect_wh(surface, rect);
3251     return HI_SUCCESS;
3252 }
3253 
tde_osi_raster_fmt_check_align(hi_tde_surface * surface)3254 static hi_s32 tde_osi_raster_fmt_check_align(hi_tde_surface *surface)
3255 {
3256     hi_u32 byte_per_pixel;
3257     hi_s32 bpp = tde_osi_get_bpp_by_fmt(surface->color_fmt);
3258     if ((bpp >= 8) && (bpp != 24)) { /* 8 24 Bpp */
3259         byte_per_pixel = ((hi_u32)bpp >> 3); /* 3 Bpp /8 */
3260 
3261         if (osal_div_u64_rem(surface->phy_addr, byte_per_pixel)) {
3262             tde_error("Bitmap address is not aligned!\n");
3263             return HI_ERR_TDE_NOT_ALIGNED;
3264         }
3265 
3266         if (surface->stride % byte_per_pixel) {
3267             tde_error("stride is not aligned!\n");
3268             return HI_ERR_TDE_NOT_ALIGNED;
3269         }
3270     } else if (bpp == 24) { /* 24 Bpp */
3271         if (osal_div_u64_rem(surface->phy_addr, 4)) { /* 4 align_num */
3272             tde_error("Bitmap address is not aligned!\n");
3273             return HI_ERR_TDE_NOT_ALIGNED;
3274         }
3275         if (surface->stride % 4) { /* 4 align_num */
3276             tde_error("stride is not aligned!\n");
3277             return HI_ERR_TDE_NOT_ALIGNED;
3278         }
3279     }
3280 
3281     return HI_SUCCESS;
3282 }
3283 
3284 #ifndef HI_BUILD_IN_BOOT
3285 /*
3286  * Function:      tde_osi_check_mb_surface_ex
3287  * Description:   adjust right operate zone,
3288                   according by the size of bitmap is more than 4095*4095 and less than 8190*8190
3289  * Input:         mb_surface: bitmap info
3290  *                rect: bitmap operate zone
3291  * Return:        success/fail
3292  */
tde_osi_check_mb_surface_ex(hi_tde_mb_surface * mb_surface,hi_tde_rect * rect)3293 static hi_s32 tde_osi_check_mb_surface_ex(hi_tde_mb_surface *mb_surface, hi_tde_rect *rect)
3294 {
3295     hi_bool real = ((rect->pos_x < 0) || (rect->width > TDE_MAX_RECT_WIDTH_EX) ||
3296         (rect->height > TDE_MAX_RECT_HEIGHT_EX) || (rect->height == 0) || (rect->width == 0) ||
3297         (mb_surface->y_stride > TDE_MAX_SURFACE_PITCH) || (mb_surface->cbcr_stride > TDE_MAX_SURFACE_PITCH) ||
3298         ((hi_u32)rect->pos_x >= mb_surface->y_width) || (rect->pos_y < 0) ||
3299         ((hi_u32)rect->pos_y >= mb_surface->y_height) || (mb_surface->y_addr == 0));
3300 
3301     if (mb_surface->mb_color_fmt >= HI_TDE_MB_COLOR_FMT_MAX) {
3302         tde_error("mb color format error!\n");
3303         return HI_ERR_TDE_INVALID_PARA;
3304     }
3305 
3306     if ((mb_surface->mb_color_fmt > HI_TDE_MB_COLOR_FMT_JPG_YCBCR400MBP) &&
3307         (mb_surface->mb_color_fmt < HI_TDE_MB_COLOR_FMT_MAX)) {
3308         if (mb_surface->cbcr_stride == 0) {
3309             tde_error(" mb cbcr_stride is null !\n");
3310             return HI_ERR_TDE_INVALID_PARA;
3311         }
3312         if (mb_surface->cbcr_phy_addr == 0) {
3313             tde_error("mb cbcr_phy_addr is 0!\n");
3314             return HI_ERR_TDE_INVALID_PARA;
3315         }
3316     }
3317     if (real) {
3318         tde_error("syw:%d, syh:%d, systride:%x, syphy:%llx, scbcrstride:%x, scbcrphy:%llx, x:%d, y:%d, w:%d, h:%d\n",
3319             mb_surface->y_width, mb_surface->y_height, mb_surface->y_stride, mb_surface->y_addr,
3320             mb_surface->cbcr_stride, mb_surface->cbcr_phy_addr, rect->pos_x, rect->pos_y, rect->width,
3321             rect->height);
3322         tde_error("invalid mbsurface phyaddr or invalid surface size or operation area!\n");
3323         return -1;
3324     }
3325     if ((mb_surface->y_stride % 4) || (mb_surface->cbcr_stride % 4)) { /* 4 align_num */
3326         tde_error("stride is not aligned!\n");
3327         return HI_ERR_TDE_NOT_ALIGNED;
3328     }
3329 
3330     if ((mb_surface->mb_color_fmt != HI_TDE_MB_COLOR_FMT_JPG_YCBCR400MBP) && (mb_surface->cbcr_phy_addr == 0)) {
3331         tde_error("MB fmt :%d cbcr_phy_addr is HI_NULL !!\n", mb_surface->mb_color_fmt);
3332         return HI_FAILURE;
3333     }
3334     if (rect->pos_x + rect->width > mb_surface->y_width) {
3335         rect->width = mb_surface->y_width - rect->pos_x;
3336     }
3337 
3338     if (rect->pos_y + rect->height > mb_surface->y_height) {
3339         rect->height = mb_surface->y_height - rect->pos_y;
3340     }
3341 
3342     return HI_SUCCESS;
3343 }
3344 #endif
3345 
3346 /*
3347  * Function:      tde_osi_get_opt_category
3348  * Description:   analyze TDE operate type
3349  * Return:        TDE operate type
3350  */
tde_osi_get_opt_category(hi_tde_double_src * double_src,hi_tde_opt * opt)3351 static tde_operation_category tde_osi_get_opt_category(hi_tde_double_src *double_src, hi_tde_opt *opt)
3352 {
3353     if ((double_src->dst_surface == HI_NULL) || (double_src->dst_rect == HI_NULL)) {
3354         tde_error("dst is HI_NULL!\n");
3355         return TDE_OPERATION_BUTT;
3356     }
3357 
3358     if (double_src->dst_surface->color_fmt >= HI_TDE_COLOR_FMT_JPG_YCBCR400MBP) {
3359         tde_error("This operation doesn't support Semi-plannar!\n");
3360         return HI_ERR_TDE_INVALID_PARA;
3361     }
3362 
3363     if (tde_osi_check_surface(double_src->dst_surface, double_src->dst_rect) != HI_SUCCESS) {
3364         return TDE_OPERATION_BUTT;
3365     }
3366     if ((double_src->bg_surface == HI_NULL) && (double_src->fg_surface == HI_NULL)) {
3367         tde_error("null pointer in single source 2 operation!");
3368         return TDE_OPERATION_BUTT;
3369     } else if ((double_src->bg_surface != HI_NULL) && (double_src->fg_surface != HI_NULL)) {
3370         return tde_osi_double_src_operation(double_src, opt);
3371     } else {
3372         return tde_osi_single_src_operation(double_src, opt);
3373     }
3374 }
3375 
tde_osi_single_src_operation(hi_tde_double_src * double_src,hi_tde_opt * opt)3376 static tde_operation_category tde_osi_single_src_operation(hi_tde_double_src *double_src, hi_tde_opt *opt)
3377 {
3378     hi_tde_surface *tmp_src2 = HI_NULL;
3379     hi_tde_rect *tmp_src2_rect = HI_NULL;
3380 
3381     if ((double_src->bg_surface != HI_NULL) && (double_src->fg_surface == HI_NULL)) {
3382         tmp_src2 = double_src->bg_surface;
3383         tmp_src2_rect = double_src->bg_rect;
3384     } else {
3385         tmp_src2 = double_src->fg_surface;
3386         tmp_src2_rect = double_src->fg_rect;
3387     }
3388 
3389     if (tmp_src2_rect == HI_NULL) {
3390         return TDE_OPERATION_BUTT;
3391     }
3392 
3393     if (tde_osi_check_surface(tmp_src2, tmp_src2_rect) != HI_SUCCESS) {
3394         return TDE_OPERATION_BUTT;
3395     }
3396 
3397     if ((opt == HI_NULL) || (!opt->resize)) {
3398         tde_unify_rect(tmp_src2_rect, double_src->dst_rect);
3399     }
3400 
3401     if ((opt == HI_NULL) && (tmp_src2->color_fmt == double_src->dst_surface->color_fmt)) {
3402         return TDE_OPERATION_SINGLE_SRC1;
3403     }
3404 
3405     if (opt == HI_NULL) {
3406         tde_error("source format must be the same with dst format!\n");
3407         return TDE_OPERATION_BUTT;
3408     }
3409 
3410     return TDE_OPERATION_SINGLE_SRC2;
3411 }
3412 
tde_osi_double_src_operation(hi_tde_double_src * double_src,hi_tde_opt * opt)3413 static tde_operation_category tde_osi_double_src_operation(hi_tde_double_src *double_src, hi_tde_opt *opt)
3414 {
3415     if ((double_src->bg_rect == HI_NULL) || (double_src->fg_rect == HI_NULL) ||
3416         (opt == HI_NULL)) {
3417         tde_error("Null pointer!\n");
3418         return TDE_OPERATION_BUTT;
3419     }
3420 
3421     if (double_src->bg_surface->color_fmt >= HI_TDE_COLOR_FMT_JPG_YCBCR400MBP) {
3422         tde_error("This operation doesn't support Semi-plannar!\n");
3423         return HI_ERR_TDE_INVALID_PARA;
3424     }
3425 
3426 #ifdef TDE_BACKGROUND_COLORFOMATSUPPORT_YCBCR422
3427     if (double_src->bg_surface->color_fmt >= HI_TDE_COLOR_FMT_YCBCR422) {
3428         tde_error("Background  doesn't support the colorfmt!\n");
3429         return HI_ERR_TDE_INVALID_PARA;
3430     }
3431 #endif
3432 
3433     if (tde_osi_check_surface(double_src->bg_surface, double_src->bg_rect) != HI_SUCCESS) {
3434         return TDE_OPERATION_BUTT;
3435     }
3436 
3437     if (tde_osi_check_surface(double_src->fg_surface, double_src->fg_rect) != HI_SUCCESS) {
3438         return TDE_OPERATION_BUTT;
3439     }
3440 
3441     if ((double_src->bg_rect->height != double_src->dst_rect->height) ||
3442         (double_src->bg_rect->width != double_src->dst_rect->width)) {
3443         tde_error("BackGroundRect is not the same with DstRect!\n");
3444         return TDE_OPERATION_BUTT;
3445     }
3446 
3447     if (!opt->resize) {
3448         if (double_src->bg_rect->height != double_src->fg_rect->height) {
3449             double_src->bg_rect->height = tde_min(double_src->bg_rect->height,
3450                 double_src->fg_rect->height);
3451             double_src->dst_rect->height = double_src->bg_rect->height;
3452             double_src->fg_rect->height = double_src->bg_rect->height;
3453         }
3454 
3455         if (double_src->bg_rect->width != double_src->fg_rect->width) {
3456             double_src->bg_rect->width = tde_min(double_src->bg_rect->width,
3457                 double_src->fg_rect->width);
3458             double_src->dst_rect->width = double_src->bg_rect->width;
3459             double_src->fg_rect->width = double_src->bg_rect->width;
3460         }
3461     }
3462 
3463     return TDE_OPERATION_DOUBLE_SRC;
3464 }
3465 
3466 /*
3467  * Function:      tde_osi_convert_surface
3468  * Description:   raster bitmap info by user upload translate to bitmap info which driver and hardware need
3469  * Input:         sur: raster bitmap info by user upload
3470  *                rect: raster bitmap operate zone by user upload
3471  *                scan_info: scanning direction info
3472  *                drv_sur: bitmap info which driver and hardware need
3473  */
tde_osi_convert_surface(hi_tde_surface * sur,hi_tde_rect * rect,tde_scandirection_mode * scan_info,tde_surface_msg * drv_sur)3474 static hi_void tde_osi_convert_surface(hi_tde_surface *sur, hi_tde_rect *rect,
3475                                        tde_scandirection_mode *scan_info,
3476                                        tde_surface_msg *drv_sur)
3477 {
3478     drv_sur->color_fmt = g_tde_common_drv_color_fmt[sur->color_fmt];
3479     drv_sur->width = rect->width;
3480     drv_sur->height = rect->height;
3481     drv_sur->pitch = sur->stride;
3482     drv_sur->alpha_max_is_255 = sur->alpha_max_is_255;
3483     drv_sur->h_scan = scan_info->h_scan;
3484     drv_sur->v_scan = scan_info->v_scan;
3485     drv_sur->phy_addr = sur->phy_addr;
3486     drv_sur->cbcr_phy_addr = sur->cbcr_phy_addr;
3487     drv_sur->cb_cr_pitch = sur->cbcr_stride;
3488     drv_sur->rgb_order = g_tde_argb_order[sur->color_fmt];
3489 
3490     drv_sur->xpos = (hi_u32)rect->pos_x;
3491 
3492     drv_sur->ypos = (hi_u32)rect->pos_y;
3493 
3494     return;
3495 }
3496 
tde_osi_check_clip_para(hi_tde_double_src * double_src,hi_tde_opt * opt,tde_hw_node * hw_node)3497 static hi_s32 tde_osi_check_clip_para(hi_tde_double_src *double_src, hi_tde_opt *opt, tde_hw_node *hw_node)
3498 {
3499     if (double_src->fg_surface == HI_NULL) {
3500         tde_error("double_src->fg_surface is null %s(line=%d)\n", __FUNCTION__, __LINE__);
3501         return HI_ERR_TDE_NULL_PTR;
3502     }
3503     if (double_src->dst_surface == HI_NULL) {
3504         tde_error("double_src->dst_surface is null %s(line=%d)\n", __FUNCTION__, __LINE__);
3505         return HI_ERR_TDE_NULL_PTR;
3506     }
3507     if (opt == HI_NULL) {
3508         tde_error("pstOpt is null %s(line=%d)\n", __FUNCTION__, __LINE__);
3509         return HI_ERR_TDE_NULL_PTR;
3510     }
3511     if (hw_node == HI_NULL) {
3512         tde_error("pstHwNode is null %s(line=%d)\n", __FUNCTION__, __LINE__);
3513         return HI_ERR_TDE_NULL_PTR;
3514     }
3515     if (opt->clip_mode >= HI_TDE_CLIP_MODE_MAX) {
3516         tde_error("clip_mode error!\n");
3517         return HI_ERR_TDE_INVALID_PARA;
3518     }
3519 
3520     if (opt->clip_mode != HI_TDE_CLIP_MODE_NONE) {
3521         if ((opt->clip_rect.height == 0) || (opt->clip_rect.width == 0) || (opt->clip_rect.pos_x < 0) ||
3522             ((hi_u32)opt->clip_rect.pos_x >= TDE_MAX_RECT_WIDTH) ||
3523             (opt->clip_rect.pos_y < 0) || ((hi_u32)opt->clip_rect.pos_y >= TDE_MAX_RECT_HEIGHT) ||
3524             ((hi_u32)opt->clip_rect.width >= TDE_MAX_RECT_WIDTH) ||
3525             ((hi_u32)opt->clip_rect.height >= TDE_MAX_RECT_HEIGHT)) {
3526             tde_error(" Clip rect x:%d, y:%d, w:%d, h:%d error!\n", opt->clip_rect.pos_x,
3527                 opt->clip_rect.pos_y, opt->clip_rect.width, opt->clip_rect.height);
3528             return -1;
3529         }
3530     }
3531     return HI_SUCCESS;
3532 }
3533 
tde_osi_double_src(hi_tde_double_src * double_src,hi_tde_rect * inter_rect)3534 static hi_void tde_osi_double_src(hi_tde_double_src *double_src, hi_tde_rect *inter_rect)
3535 {
3536     if (double_src->bg_surface != HI_NULL) {
3537         double_src->bg_rect->pos_x += inter_rect->pos_x - double_src->dst_rect->pos_x;
3538         double_src->bg_rect->pos_y += inter_rect->pos_y - double_src->dst_rect->pos_y;
3539         double_src->bg_rect->height = inter_rect->height;
3540         double_src->bg_rect->width = inter_rect->width;
3541     }
3542 
3543     double_src->fg_rect->pos_x += inter_rect->pos_x - double_src->dst_rect->pos_x;
3544     double_src->fg_rect->pos_y += inter_rect->pos_y - double_src->dst_rect->pos_y;
3545     double_src->fg_rect->height = inter_rect->height;
3546     double_src->fg_rect->width = inter_rect->width;
3547 
3548     *(double_src->dst_rect) = *inter_rect;
3549 }
3550 
3551 /*
3552  * Function:      tde_osi_set_clip_para
3553  * Description:   set clip zone parameter
3554  * Input:         double_src:  bitmap info
3555  *                opt: operate option
3556  *                hw_node: hardware operate node
3557  */
tde_osi_set_clip_para(hi_tde_double_src * double_src,hi_tde_opt * opt,tde_hw_node * hw_node)3558 static hi_s32 tde_osi_set_clip_para(hi_tde_double_src *double_src, hi_tde_opt *opt, tde_hw_node *hw_node)
3559 {
3560     tde_clip_cmd clip = { 0 };
3561     hi_tde_rect inter_rect = { 0 };
3562     hi_s32 ret;
3563     ret = tde_osi_check_clip_para(double_src, opt, hw_node);
3564     if (ret != HI_SUCCESS) {
3565         return ret;
3566     }
3567     if ((opt->clip_mode == HI_TDE_CLIP_MODE_INSIDE) && (!opt->resize)) {
3568         if (tde_osi_get_inter_rect(double_src->dst_rect, &opt->clip_rect, &inter_rect) != HI_SUCCESS) {
3569             tde_error("clip and operation area have no inrerrect!\n");
3570             return HI_ERR_TDE_CLIP_AREA;
3571         }
3572         tde_osi_double_src(double_src, &inter_rect);
3573     } else if (opt->clip_mode == HI_TDE_CLIP_MODE_INSIDE) {
3574         if (tde_osi_get_inter_rect(double_src->dst_rect, &opt->clip_rect, &inter_rect) != HI_SUCCESS) {
3575             tde_error("clip and operation area have no inter-rect!\n");
3576             return HI_ERR_TDE_CLIP_AREA;
3577         }
3578 
3579         clip.inside_clip = HI_TRUE;
3580         clip.clip_start_x = opt->clip_rect.pos_x - double_src->dst_rect->pos_x;
3581         clip.clip_start_y = opt->clip_rect.pos_y - double_src->dst_rect->pos_y;
3582         clip.clip_end_x = (opt->clip_rect.pos_x - double_src->dst_rect->pos_x) + opt->clip_rect.width - 1;
3583         clip.clip_end_y = (opt->clip_rect.pos_y - double_src->dst_rect->pos_y) + opt->clip_rect.height - 1;
3584         if (tde_hal_node_set_clipping(hw_node, &clip) < 0) {
3585             return HI_ERR_TDE_UNSUPPORTED_OPERATION;
3586         }
3587     } else if (opt->clip_mode == HI_TDE_CLIP_MODE_OUTSIDE) {
3588         if (tde_osi_is_rect1_in_rect2(double_src->dst_rect, &opt->clip_rect)) {
3589             tde_error("clip and operation area have no inter-rect!\n");
3590             return HI_ERR_TDE_CLIP_AREA;
3591         }
3592 
3593         if (tde_osi_get_inter_rect(double_src->dst_rect, &opt->clip_rect, &inter_rect) != HI_SUCCESS) {
3594             return HI_SUCCESS;
3595         }
3596 
3597         clip.inside_clip = HI_FALSE;
3598         clip.clip_start_x = opt->clip_rect.pos_x - double_src->dst_rect->pos_x;
3599         clip.clip_start_y = opt->clip_rect.pos_y - double_src->dst_rect->pos_y;
3600         clip.clip_end_x = (opt->clip_rect.pos_x - double_src->dst_rect->pos_x) + opt->clip_rect.width - 1;
3601         clip.clip_end_y = (opt->clip_rect.pos_y - double_src->dst_rect->pos_y) + opt->clip_rect.height - 1;
3602 
3603         if (tde_hal_node_set_clipping(hw_node, &clip) != HI_SUCCESS) {
3604             return HI_ERR_TDE_UNSUPPORTED_OPERATION;
3605         }
3606     } else if (opt->clip_mode >= HI_TDE_CLIP_MODE_MAX) {
3607         tde_error("error clip mode!\n");
3608         return HI_ERR_TDE_INVALID_PARA;
3609     }
3610 
3611     return HI_SUCCESS;
3612 }
3613 
3614 #ifndef HI_BUILD_IN_BOOT
tde_osi_check_sre_para(hi_tde_double_src * double_src,hi_tde_pattern_fill_opt * opt,tde_hw_node * hw_node)3615 static hi_s32 tde_osi_check_sre_para(hi_tde_double_src *double_src, hi_tde_pattern_fill_opt *opt,
3616                                      tde_hw_node *hw_node)
3617 {
3618     if (double_src->fg_surface == HI_NULL) {
3619         tde_error("double_src->fg_surface is null %s(line=%d)\n", __FUNCTION__, __LINE__);
3620         return HI_ERR_TDE_NULL_PTR;
3621     }
3622     if (double_src->dst_surface == HI_NULL) {
3623         tde_error("double_src->dst_surface is null %s(line=%d)\n", __FUNCTION__, __LINE__);
3624         return HI_ERR_TDE_NULL_PTR;
3625     }
3626     if (opt == HI_NULL) {
3627         tde_error("opt is null %s(line=%d)\n", __FUNCTION__, __LINE__);
3628         return HI_ERR_TDE_NULL_PTR;
3629     }
3630     if (hw_node == HI_NULL) {
3631         tde_error("hw_node is null %s(line=%d)\n", __FUNCTION__, __LINE__);
3632         return HI_ERR_TDE_NULL_PTR;
3633     }
3634     if (opt->clip_mode >= HI_TDE_CLIP_MODE_MAX) {
3635         tde_error("clip_mode error!\n");
3636         return HI_ERR_TDE_INVALID_PARA;
3637     }
3638 
3639     if (opt->clip_mode != HI_TDE_CLIP_MODE_NONE) {
3640         if ((opt->clip_rect.height == 0) || (opt->clip_rect.width == 0) || (opt->clip_rect.pos_x < 0) ||
3641             ((hi_u32)opt->clip_rect.pos_x >= TDE_MAX_RECT_WIDTH) ||
3642             (opt->clip_rect.pos_y < 0) || ((hi_u32)opt->clip_rect.pos_y >= TDE_MAX_RECT_HEIGHT) ||
3643             ((hi_u32)opt->clip_rect.width >= TDE_MAX_RECT_WIDTH) ||
3644             ((hi_u32)opt->clip_rect.height >= TDE_MAX_RECT_HEIGHT)) {
3645             tde_error(" Clip rect x:%d, y:%d, w:%d, h:%d error!\n", opt->clip_rect.pos_x,
3646                 opt->clip_rect.pos_y, opt->clip_rect.width, opt->clip_rect.height);
3647             return -1;
3648         }
3649     }
3650     return HI_SUCCESS;
3651 }
3652 
tde_osi_set_pattern_clip_para(hi_tde_double_src * double_src,hi_tde_pattern_fill_opt * opt,tde_hw_node * hw_node)3653 static hi_s32 tde_osi_set_pattern_clip_para(hi_tde_double_src *double_src, hi_tde_pattern_fill_opt *opt,
3654                                             tde_hw_node *hw_node)
3655 {
3656     tde_clip_cmd clip = {0};
3657     hi_tde_rect inter_rect = {0};
3658     hi_s32 ret;
3659     ret = tde_osi_check_sre_para(double_src, opt, hw_node);
3660     if (ret != HI_SUCCESS) {
3661         return ret;
3662     }
3663 
3664     if (opt->clip_mode == HI_TDE_CLIP_MODE_INSIDE) {
3665         if (tde_osi_get_inter_rect(double_src->dst_rect, &opt->clip_rect, &inter_rect) != HI_SUCCESS) {
3666             tde_error("clip and operation area have no inrerrect!\n");
3667             return HI_ERR_TDE_CLIP_AREA;
3668         }
3669         clip.inside_clip = HI_TRUE;
3670         clip.clip_start_x = opt->clip_rect.pos_x - double_src->dst_rect->pos_x;
3671         clip.clip_start_y = opt->clip_rect.pos_y - double_src->dst_rect->pos_y;
3672         clip.clip_end_x = (opt->clip_rect.pos_x - double_src->dst_rect->pos_x) + opt->clip_rect.width - 1;
3673         clip.clip_end_y = (opt->clip_rect.pos_y - double_src->dst_rect->pos_y) + opt->clip_rect.height - 1;
3674 
3675         if (tde_hal_node_set_clipping(hw_node, &clip) != HI_SUCCESS) {
3676             return HI_ERR_TDE_UNSUPPORTED_OPERATION;
3677         }
3678     } else if (opt->clip_mode == HI_TDE_CLIP_MODE_OUTSIDE) {
3679         if (tde_osi_is_rect1_in_rect2(double_src->dst_rect, &opt->clip_rect)) {
3680             tde_error("clip and operation area have no inter-rect!\n");
3681             return HI_ERR_TDE_CLIP_AREA;
3682         }
3683 
3684         if (tde_osi_get_inter_rect(double_src->dst_rect, &opt->clip_rect, &inter_rect) != HI_SUCCESS) {
3685             return HI_SUCCESS;
3686         }
3687 
3688         clip.inside_clip = HI_FALSE;
3689         clip.clip_start_x = opt->clip_rect.pos_x - double_src->dst_rect->pos_x;
3690         clip.clip_start_y = opt->clip_rect.pos_y - double_src->dst_rect->pos_y;
3691         clip.clip_end_x = (opt->clip_rect.pos_x - double_src->dst_rect->pos_x) + opt->clip_rect.width - 1;
3692         clip.clip_end_y = (opt->clip_rect.pos_y - double_src->dst_rect->pos_y) + opt->clip_rect.height - 1;
3693 
3694         if (tde_hal_node_set_clipping(hw_node, &clip) != HI_SUCCESS) {
3695             return HI_ERR_TDE_UNSUPPORTED_OPERATION;
3696         }
3697     } else if (opt->clip_mode >= HI_TDE_CLIP_MODE_MAX) {
3698         tde_error("error clip mode!\n");
3699         return HI_ERR_TDE_INVALID_PARA;
3700     }
3701 
3702     return HI_SUCCESS;
3703 }
3704 #endif
3705 
tde_osi_set_ext_alpha(hi_tde_surface * back_ground,hi_tde_surface * fore_ground,tde_hw_node * hw_node)3706 static hi_void tde_osi_set_ext_alpha(hi_tde_surface *back_ground, hi_tde_surface *fore_ground,
3707                                      tde_hw_node *hw_node)
3708 {
3709     tde_src_mode src = TDE_DRV_SRC_NONE;
3710     hi_bool real = HI_FALSE;
3711     real = ((fore_ground != HI_NULL) && (fore_ground->color_fmt >= HI_TDE_COLOR_FMT_ARGB1555) &&
3712         (fore_ground->color_fmt <= HI_TDE_COLOR_FMT_BGRA1555));
3713     if (real) {
3714         tde_hal_node_set_src2_alpha(hw_node);
3715     }
3716 
3717     real = ((back_ground != HI_NULL) &&
3718         (back_ground->color_fmt >= HI_TDE_COLOR_FMT_ARGB1555) &&
3719         (back_ground->color_fmt <= HI_TDE_COLOR_FMT_BGRA1555));
3720     if (real) {
3721         tde_hal_node_set_src1_alpha(hw_node);
3722     }
3723 
3724     real = ((fore_ground != HI_NULL) && (fore_ground->support_alpha_ext_1555) &&
3725         (fore_ground->color_fmt >= HI_TDE_COLOR_FMT_ARGB1555) &&
3726         (fore_ground->color_fmt <= HI_TDE_COLOR_FMT_BGRA1555));
3727     if (real) {
3728         src = (hi_u32)src | TDE_DRV_SRC_S2;
3729     }
3730 
3731     real = ((back_ground != HI_NULL) && (back_ground->support_alpha_ext_1555) &&
3732         (back_ground->color_fmt >= HI_TDE_COLOR_FMT_ARGB1555) &&
3733         (back_ground->color_fmt <= HI_TDE_COLOR_FMT_BGRA1555));
3734     if (real) {
3735         src = (hi_u32)src | TDE_DRV_SRC_S1;
3736     }
3737 
3738     if ((hi_u32)src & TDE_DRV_SRC_S1) {
3739         tde_hal_node_set_exp_alpha(hw_node, src, back_ground->alpha0, back_ground->alpha1);
3740     } else if ((hi_u32)src & TDE_DRV_SRC_S2) {
3741         tde_hal_node_set_exp_alpha(hw_node, src, fore_ground->alpha0, fore_ground->alpha1);
3742     }
3743 }
3744 
3745 #ifndef HI_BUILD_IN_BOOT
tde_osi_set_blend_opt_rop(hi_tde_opt * opt,tde_hw_node * hw_node,tde_alu_mode * alu)3746 static hi_s32 tde_osi_set_blend_opt_rop(hi_tde_opt *opt, tde_hw_node *hw_node, tde_alu_mode *alu)
3747 {
3748     if ((hi_u32)opt->alpha_blending_cmd & HI_TDE_ALPHA_BLENDING_BLEND) {
3749         *alu = TDE_ALU_BLEND;
3750         if (tde_hal_node_set_blend(hw_node, &opt->blend_opt) != HI_SUCCESS) {
3751             return HI_ERR_TDE_UNSUPPORTED_OPERATION;
3752         }
3753 #if (TDE_CAPABILITY & ROP)
3754         if ((hi_u32)opt->alpha_blending_cmd & HI_TDE_ALPHA_BLENDING_ROP) {
3755             tde_hal_node_enable_alpha_rop(hw_node);
3756         }
3757 #endif
3758     }
3759 #if (TDE_CAPABILITY & COLORIZE)
3760     if ((hi_u32)opt->alpha_blending_cmd & HI_TDE_ALPHA_BLENDING_COLORIZE) {
3761         if (tde_hal_node_set_colorize(hw_node, opt->color_resize) != HI_SUCCESS) {
3762             return HI_ERR_TDE_UNSUPPORTED_OPERATION;
3763         }
3764     }
3765 #endif
3766     return HI_SUCCESS;
3767 }
3768 #endif
3769 
3770 /*
3771  * Function:      tde_osi_set_base_opt_para_for_blit
3772  * Description:   encapsulation function used to set operate type
3773  * Input:         opt: operate option
3774  *                opt_category: operate category
3775  *                hw_node: nareware operate node
3776  */
tde_osi_set_base_opt_para_for_blit(hi_tde_opt * opt,hi_tde_surface * src1,hi_tde_surface * src2,tde_operation_category opt_category,tde_hw_node * hw_node)3777 static hi_s32 tde_osi_set_base_opt_para_for_blit(hi_tde_opt *opt, hi_tde_surface *src1, hi_tde_surface *src2,
3778                                                  tde_operation_category opt_category, tde_hw_node *hw_node)
3779 {
3780     tde_base_opt_mode base_opt = { 0 };
3781     tde_alu_mode alu = TDE_ALU_NONE;
3782     hi_s32 ret;
3783 
3784     if ((hw_node == HI_NULL) || (opt == HI_NULL)) {
3785         return HI_SUCCESS;
3786     }
3787 
3788     if ((src1 != HI_NULL) && (src2 != HI_NULL)) {
3789         if ((tde_osi_get_fmt_category(src2->color_fmt) == TDE_COLORFMT_CATEGORY_AN) &&
3790             ((tde_osi_get_fmt_category(src1->color_fmt) == TDE_COLORFMT_CATEGORY_ARGB) ||
3791             (tde_osi_get_fmt_category(src1->color_fmt) == TDE_COLORFMT_CATEGORY_YCBCR))) {
3792             alu = TDE_SRC1_BYPASS;
3793         }
3794     }
3795 #if (TDE_CAPABILITY & ROP)
3796     if ((hi_u32)opt->alpha_blending_cmd & HI_TDE_ALPHA_BLENDING_ROP) {
3797         alu = TDE_ALU_ROP;
3798 
3799         if (tde_hal_node_set_rop(hw_node, opt->rop_color, opt->rop_alpha) != HI_SUCCESS) {
3800             return HI_ERR_TDE_UNSUPPORTED_OPERATION;
3801         }
3802     }
3803 #endif
3804 #ifndef HI_BUILD_IN_BOOT
3805     ret = tde_osi_set_blend_opt_rop(opt, hw_node, &alu);
3806     if (ret != HI_SUCCESS) {
3807         return ret;
3808     }
3809 #endif
3810 
3811     base_opt = (opt_category == TDE_OPERATION_DOUBLE_SRC) ? TDE_NORM_BLIT_2OPT : TDE_NORM_BLIT_1OPT;
3812 
3813     tde_hal_node_set_global_alpha(hw_node, opt->global_alpha, opt->blend_opt.global_alpha_en);
3814 
3815     if (tde_hal_node_set_base_operate(hw_node, base_opt, alu, 0) != HI_SUCCESS) {
3816         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
3817     }
3818     ret = tde_set_node_csc(hw_node, opt->csc_opt);
3819 
3820     return ret;
3821 }
3822 
3823 /*
3824  * Function:      tde_osi_adj_clip_para
3825  * Description:   set clip parameter to hardware node
3826  * Input:         hw_node: node need to set
3827  */
tde_osi_adj_clip_para(tde_hw_node * hw_node)3828 static hi_s32 tde_osi_adj_clip_para(tde_hw_node *hw_node)
3829 {
3830     hi_u32 clip_start_x, clip_start_y, clip_end_x, clip_end_y;
3831     hi_u32 out_start_x, out_start_y, out_end_x, out_end_y;
3832     hi_u32 start_x, start_y, end_x, end_y;
3833 
3834     if (!(hw_node->des_alpha.bits.des_crop_en)) {
3835         return HI_SUCCESS;
3836     }
3837 
3838     clip_start_x = hw_node->des_crop_pos_st.bits.des_crop_start_x & 0xfff;
3839     clip_start_y = hw_node->des_crop_pos_st.bits.des_crop_start_y & 0xfff;
3840     clip_end_x = hw_node->des_crop_pos_ed.bits.des_crop_end_x & 0xfff;
3841     clip_end_y = hw_node->des_crop_pos_ed.bits.des_crop_end_y & 0xfff;
3842 
3843     out_start_x = 0;
3844     out_start_y = 0;
3845     out_end_x = out_start_x + ((hw_node->des_imgsize.bits.des_width + 1) & 0xfff) - 1;
3846     out_end_y = out_start_y + ((hw_node->des_imgsize.bits.des_height + 1) & 0xfff) - 1;
3847 
3848     start_x = (clip_start_x > out_start_x) ? clip_start_x : out_start_x;
3849     start_y = (clip_start_y > out_start_y) ? clip_start_y : out_start_y;
3850     end_x = (clip_end_x < out_end_x) ? clip_end_x : out_end_x;
3851     end_y = (clip_end_y < out_end_y) ? clip_end_y : out_end_y;
3852 
3853     if ((start_x > end_x) || (start_y > end_y)) {
3854         hw_node->des_alpha.bits.des_crop_en = 0;
3855     } else {
3856         hw_node->des_crop_pos_st.bits.des_crop_start_x = start_x;
3857         hw_node->des_crop_pos_st.bits.des_crop_start_y = start_y;
3858         hw_node->des_crop_pos_ed.bits.des_crop_end_x = end_x;
3859         hw_node->des_crop_pos_ed.bits.des_crop_end_y = end_y;
3860     }
3861 
3862     return HI_SUCCESS;
3863 }
3864 
tde_osi_none_cmd(tde_hw_node * hw_node,tde_swnode * cmd,tde_swjob * job)3865 static hi_void tde_osi_none_cmd(tde_hw_node *hw_node, tde_swnode *cmd, tde_swjob *job)
3866 {
3867     tde_hw_node *hw_tail_node = HI_NULL;
3868 
3869 #ifndef HI_BUILD_IN_BOOT
3870 #ifdef CONFIG_HI_PROC_SHOW_SUPPORT
3871     tdeproc_record_node(hw_node);
3872 #endif
3873 #endif
3874 
3875 #ifndef __RTOS__
3876     cmd->node_buf.buf = (hi_void *)hw_node - TDE_NODE_HEAD_BYTE;
3877 #else
3878     cmd->node_buf.buf = (hi_u8 *)hw_node - TDE_NODE_HEAD_BYTE;
3879 #endif
3880 
3881     cmd->node_buf.node_sz = sizeof(tde_hw_node);
3882     cmd->node_buf.update = (0xffffffff) | ((hi_u64)0x000003ff << 32); /* 32 alg data */
3883     cmd->node_buf.phy_addr = wgetphy(cmd->node_buf.buf) + TDE_NODE_HEAD_BYTE;
3884     /*
3885      * If the tail node of the job is not null,add the current job node to the tail of the job list of hardware.
3886      * That is to say the next node address of the tail\
3887      * node is the current node address.
3888      */
3889     if (job->tail_node != HI_NULL) {
3890         hw_tail_node = (tde_hw_node *)((hi_u8 *)job->tail_node->node_buf.buf + TDE_NODE_HEAD_BYTE);
3891         hw_tail_node->tde_pnext_low.bits.next_low = GetLowAddr(cmd->node_buf.phy_addr);
3892         hw_tail_node->tde_pnext_hi.bits.next_hi = GetHighAddr(cmd->node_buf.phy_addr);
3893     }
3894     return;
3895 }
3896 
3897 /*
3898  * Function:      tde_osi_set_node_finish
3899  * Description:   complete node config, add node to list signed by handle
3900  * Input:         handle: task handle, which is sumbit list
3901  *                hw_node: set node
3902  *                work_buf_num: temporary buffer number
3903  *                subm_type: submit node type
3904  * Return:        return slice number
3905  * Others:        node struct is following:
3906  *                 ----------------------
3907  *                 |  software node pointer(4)   |
3908  *                 ----------------------
3909  *                 |  config parameter          |
3910  *                 ----------------------
3911  *                 |  physical address of next node(4) |
3912  *                 ----------------------
3913  *                 |  update flag of next node(4) |
3914  *                 ----------------------
3915  */
tde_osi_set_node_finish(hi_s32 handle,tde_hw_node * hw_node,hi_u32 work_buf_num,tde_node_subm_type subm_type)3916 static hi_s32 tde_osi_set_node_finish(hi_s32 handle, tde_hw_node *hw_node,
3917                                       hi_u32 work_buf_num, tde_node_subm_type subm_type)
3918 {
3919     hi_s32 ret;
3920     hi_handle_mgr *handle_mgr = HI_NULL;
3921     tde_swjob *job = HI_NULL;
3922     tde_swnode *cmd = HI_NULL;
3923     hi_bool valid = HI_FALSE;
3924 
3925     ret = tde_osi_adj_clip_para(hw_node);
3926     if (ret != HI_SUCCESS) {
3927         tde_error("Tde osi adj clip para failed, ret = 0x%x\n", ret);
3928     }
3929     valid = tde_query_handle(handle, &handle_mgr);
3930     if (!valid) {
3931         tde_error("invalid handle %d!\n", handle);
3932         return HI_ERR_TDE_INVALID_HANDLE;
3933     }
3934     job = (tde_swjob *)handle_mgr->res;
3935     if (job->submitted) {
3936         tde_error("job %d already submitted!\n", handle);
3937         return HI_ERR_TDE_INVALID_HANDLE;
3938     }
3939     cmd = (tde_swnode *)tde_malloc(sizeof(tde_swnode));
3940     if (cmd == HI_NULL) {
3941         tde_error("malloc failed!\n");
3942         return HI_ERR_TDE_NO_MEM;
3943     }
3944     if (subm_type != TDE_NODE_SUBM_CHILD) {
3945         job->cmd_num++;
3946         if (job->cmd_num == 1) {
3947             job->first_cmd = cmd;
3948 
3949             OSAL_INIT_LIST_HEAD(&cmd->list);
3950         }
3951         job->last_cmd = cmd;
3952     }
3953 
3954     tde_osi_none_cmd(hw_node, cmd, job);
3955     cmd->handle = job->handle;
3956     cmd->index = job->cmd_num;
3957     cmd->subm_type = subm_type;
3958     cmd->phy_buff_num = work_buf_num;
3959     *(((hi_u64 *)cmd->node_buf.buf) + 1) = handle;
3960     osal_list_add_tail(&cmd->list, &job->first_cmd->list); /* Add the cmd to the job list */
3961     job->tail_node = cmd;
3962     job->node_num++;
3963     if (cmd->phy_buff_num != 0) {
3964         job->aq_use_buff = HI_TRUE;
3965     }
3966 
3967     return HI_SUCCESS;
3968 }
3969 
3970 /*
3971  * Function:      tde_osi_begin_job
3972  * Description:   get TDE task handle
3973  * Return:        created task handle
3974  */
tde_osi_begin_job(hi_s32 * handle,hi_void * private_data)3975 hi_s32 tde_osi_begin_job(hi_s32 *handle, hi_void *private_data)
3976 {
3977     if (handle == HI_NULL) {
3978         tde_error("Null ptr!\n");
3979         return HI_ERR_TDE_NULL_PTR;
3980     }
3981 
3982     return tde_osi_list_begin_job(handle, private_data);
3983 }
3984 
tde_osi_begin_job_ex(hi_s32 * handle)3985 hi_s32 tde_osi_begin_job_ex(hi_s32 *handle)
3986 {
3987     if (handle == HI_NULL) {
3988         tde_error("Null ptr!\n");
3989         return HI_ERR_TDE_NULL_PTR;
3990     }
3991 
3992     return tde_osi_list_begin_job(handle, HI_NULL);
3993 }
3994 
tde_osi_end_job(drv_tde_end_job_cmd * end_job,tde_func_cb func_compl_cb,hi_void * func_para)3995 hi_s32 tde_osi_end_job(drv_tde_end_job_cmd *end_job, tde_func_cb func_compl_cb, hi_void *func_para)
3996 {
3997 #ifndef HI_BUILD_IN_BOOT
3998     tde_notify_mode noti_type;
3999 
4000     if (((end_job->is_block != HI_TRUE) && (end_job->is_block != HI_FALSE)) ||
4001         ((end_job->is_sync != HI_TRUE) && (end_job->is_sync != HI_FALSE))) {
4002         tde_error("hi_bool should be HI_TRUE or HI_FALSE!!\n");
4003         return HI_ERR_TDE_INVALID_PARA;
4004     }
4005 
4006     if (end_job->is_block) {
4007         if (osal_in_interrupt()) {
4008             tde_error("can not be block in interrupt!\n");
4009             return HI_ERR_TDE_UNSUPPORTED_OPERATION;
4010         }
4011 
4012         noti_type = TDE_JOB_WAKE_NOTIFY;
4013     } else {
4014         noti_type = TDE_JOB_COMPL_NOTIFY;
4015     }
4016 
4017 #if (TDE_CAPABILITY & SYNC)
4018     return tde_osi_list_submit_job(end_job, func_compl_cb, func_para, noti_type, end_job->is_sync);
4019 #else
4020     return tde_osi_list_submit_job(end_job, func_compl_cb, func_para, noti_type);
4021 #endif
4022 
4023 #else
4024     return tde_osi_list_submit_job(end_job, func_compl_cb, func_para, TDE_JOB_WAKE_NOTIFY);
4025 #endif
4026 }
4027 
4028 #ifndef HI_BUILD_IN_BOOT
4029 
4030 /*
4031  * Function:      tde_osi_cancel_job
4032  * Description:   delete created TDE task, only effective for call before endjob
4033  *                use to release software resource of list of task
4034  * Input:         handle: task handle
4035  * Return:        success/fail
4036  */
tde_osi_cancel_job(hi_s32 handle)4037 hi_s32 tde_osi_cancel_job(hi_s32 handle)
4038 {
4039     return tde_osi_list_cancel_job(handle);
4040 }
4041 
4042 /*
4043  * Function:      tde_osi_wait_for_done
4044  * Description:   wait for completion of submit TDE operate
4045  * Input:         handle: task handle
4046  * Return:        success/fail
4047  */
tde_osi_wait_for_done(hi_s32 handle,hi_u32 time_out)4048 hi_s32 tde_osi_wait_for_done(hi_s32 handle, hi_u32 time_out)
4049 {
4050     if (osal_in_interrupt()) {
4051         tde_error("can not be block in interrupt!\n");
4052         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
4053     }
4054 
4055     return tde_osi_list_wait_for_done(handle, time_out);
4056 }
4057 
4058 /*
4059  * Function:      tde_osi_wait_all_done
4060  * Description:   wait for all TDE operate completion
4061  * Return:        success/fail
4062  */
tde_osi_wait_all_done(hi_bool is_sync)4063 hi_s32 tde_osi_wait_all_done(hi_bool is_sync)
4064 {
4065     hi_unused(is_sync);
4066     if (osal_in_interrupt()) {
4067         tde_error("can not wait in interrupt!\n");
4068         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
4069     }
4070 
4071     return tde_osi_list_wait_all_done();
4072 }
4073 
4074 /*
4075  * Function:      tde_osi_quick_copy
4076  * Description:   quick blit source to target, no any functional operate, the size of source and target are the same
4077  *                format is not MB format
4078  */
tde_osi_quick_copy(hi_s32 handle,hi_tde_single_src * single_src)4079 hi_s32 tde_osi_quick_copy(hi_s32 handle, hi_tde_single_src *single_src)
4080 {
4081     hi_tde_double_src double_src;
4082 
4083     double_src.bg_surface  = HI_NULL;
4084     double_src.bg_rect  = HI_NULL;
4085     double_src.fg_surface = single_src->src_surface;
4086     double_src.fg_rect = single_src->src_rect;
4087     double_src.dst_surface = single_src->dst_surface;
4088     double_src.dst_rect = single_src->dst_rect;
4089 
4090     return tde_osi_blit(handle, &double_src, HI_NULL);
4091 }
4092 
tde_set_resize_filter(hi_bool is_resize_filter)4093 hi_void tde_set_resize_filter(hi_bool is_resize_filter)
4094 {
4095     g_is_resize_filter = is_resize_filter;
4096 }
4097 
4098 #if (TDE_CAPABILITY & RESIZE)
4099 /*
4100  * Function:      tde_osi_quick_resize
4101  * Description:   zoom the size of source bitmap to the size aasigned by target bitmap,
4102                   of which source and target can be the same
4103  * Input:         src_surface: source bitmap info struct
4104  *                dst_surface: target bitmap info struct
4105  * Others:        add support for YCbCr422
4106  */
tde_osi_quick_resize(hi_s32 handle,hi_tde_surface * src_surface,hi_tde_rect * src_rect,hi_tde_surface * dst_surface,hi_tde_rect * dst_rect)4107 hi_s32 tde_osi_quick_resize(hi_s32 handle, hi_tde_surface *src_surface, hi_tde_rect *src_rect,
4108                             hi_tde_surface *dst_surface, hi_tde_rect *dst_rect)
4109 {
4110     hi_tde_opt option = { 0 };
4111     hi_tde_double_src double_src;
4112     option.resize = HI_TRUE;
4113 
4114     if (g_is_resize_filter) {
4115         option.filter_mode = HI_TDE_FILTER_MODE_COLOR;
4116     } else {
4117         option.filter_mode = HI_TDE_FILTER_MODE_NONE;
4118     }
4119     if (src_surface->color_fmt >= HI_TDE_COLOR_FMT_JPG_YCBCR400MBP) {
4120         tde_error("This operation doesn't support Semi-plannar!\n");
4121         return HI_ERR_TDE_INVALID_PARA;
4122     }
4123 
4124     double_src.bg_surface  = HI_NULL;
4125     double_src.bg_rect  = HI_NULL;
4126     double_src.fg_surface = src_surface;
4127     double_src.fg_rect = src_rect;
4128     double_src.dst_surface = dst_surface;
4129     double_src.dst_rect = dst_rect;
4130     return tde_osi_blit(handle, &double_src, &option);
4131 }
4132 #endif
4133 
4134 #if (TDE_CAPABILITY & ROTATE)
tde_osi_quick_rotate_set(tde_hw_node * hw_node,hi_tde_single_src * single_src,hi_tde_rotate_angle rotate_angle)4135 static hi_s32 tde_osi_quick_rotate_set(tde_hw_node *hw_node, hi_tde_single_src *single_src,
4136                                        hi_tde_rotate_angle rotate_angle)
4137 {
4138     tde_scandirection_mode src_scan_info = {0};
4139     tde_scandirection_mode dst_scan_info = {0};
4140     tde_surface_msg src_drv_surface = {0};
4141     tde_surface_msg dst_drv_surface = {0};
4142 
4143     if (tde_hal_node_set_base_operate(hw_node, TDE_NORM_BLIT_1OPT, TDE_ALU_NONE, 0) < 0) {
4144         tde_hal_free_node_buf(hw_node);
4145         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
4146     }
4147     src_scan_info.h_scan = TDE_SCAN_LEFT_RIGHT;
4148     src_scan_info.v_scan = TDE_SCAN_UP_DOWN;
4149     dst_scan_info.h_scan = TDE_SCAN_LEFT_RIGHT;
4150     dst_scan_info.v_scan = TDE_SCAN_UP_DOWN;
4151     if (rotate_angle == HI_TDE_ROTATE_CLOCKWISE_180) {
4152         src_scan_info.h_scan = TDE_SCAN_RIGHT_LEFT;
4153         src_scan_info.v_scan = TDE_SCAN_DOWN_UP;
4154     }
4155 
4156     tde_osi_convert_surface(single_src->src_surface, single_src->src_rect, &src_scan_info, &src_drv_surface);
4157 
4158     tde_hal_node_set_src2(hw_node, &src_drv_surface);
4159 
4160     tde_osi_convert_surface(single_src->dst_surface, single_src->dst_rect, &dst_scan_info, &dst_drv_surface);
4161 
4162     tde_hal_node_set_tqt(hw_node, &dst_drv_surface, HI_TDE_OUT_ALPHA_FROM_NORM);
4163 
4164     if (rotate_angle != HI_TDE_ROTATE_CLOCKWISE_180) {
4165         tde_hal_node_set_rotate(hw_node, rotate_angle);
4166     }
4167     return HI_SUCCESS;
4168 }
4169 
tde_osi_quick_rotate(hi_s32 handle,hi_tde_single_src * single_src,hi_tde_rotate_angle rotate_angle)4170 hi_s32 tde_osi_quick_rotate(hi_s32 handle, hi_tde_single_src *single_src, hi_tde_rotate_angle rotate_angle)
4171 {
4172     hi_s32 ret;
4173     tde_hw_node *hw_node = HI_NULL;
4174     hi_tde_double_src double_src = {0};
4175 
4176     if ((single_src == HI_NULL) || (single_src->src_surface == HI_NULL) || (single_src->src_rect == HI_NULL) ||
4177         (single_src->dst_surface == HI_NULL) || (single_src->dst_rect == HI_NULL)) {
4178         return HI_ERR_TDE_NULL_PTR;
4179     }
4180     if ((single_src->src_surface->color_fmt >= HI_TDE_COLOR_FMT_JPG_YCBCR400MBP) ||
4181         (tde_osi_check_surface(single_src->src_surface, single_src->src_rect) != HI_SUCCESS) ||
4182         (tde_osi_check_surface(single_src->dst_surface, single_src->dst_rect) != HI_SUCCESS) ||
4183         (tde_osi_check_rotate_para(single_src, rotate_angle) < 0)) {
4184         return HI_ERR_TDE_INVALID_PARA;
4185     }
4186 
4187     if (tde_hal_node_init_nd(&hw_node) < 0) {
4188         return HI_ERR_TDE_NO_MEM;
4189     }
4190 
4191     /*
4192      * set:
4193      * set opt
4194      * set src2
4195      * set tqt
4196      * set rotate
4197      */
4198     ret = tde_osi_quick_rotate_set(hw_node, single_src, rotate_angle);
4199     if (ret != HI_SUCCESS) {
4200         return ret;
4201     }
4202     /* set filter node */
4203     if ((rotate_angle == HI_TDE_ROTATE_CLOCKWISE_180) && (single_src->src_surface->color_fmt >=
4204         HI_TDE_COLOR_FMT_YCBCR422)) {
4205         double_src.bg_surface = HI_NULL;
4206         double_src.bg_rect = HI_NULL;
4207         double_src.fg_surface = single_src->src_surface;
4208         double_src.fg_rect = single_src->src_rect;
4209         double_src.dst_surface = single_src->dst_surface;
4210         double_src.dst_rect = single_src->dst_rect;
4211         ret = tde_osi_set_filter_node(handle, hw_node, &double_src, HI_TDE_DEFLICKER_LEVEL_MODE_NONE,
4212                                       HI_TDE_FILTER_MODE_NONE);
4213         if (ret < 0) {
4214             tde_hal_free_node_buf(hw_node);
4215             return ret;
4216         }
4217 #if (TDE_CAPABILITY & SLICE)
4218         tde_hal_free_node_buf(hw_node);
4219 #endif
4220         return HI_SUCCESS;
4221     }
4222 
4223     ret = tde_osi_set_node_finish(handle, hw_node, 0, TDE_NODE_SUBM_ALONE);
4224     if (ret < 0) {
4225         tde_hal_free_node_buf(hw_node);
4226         return ret;
4227     }
4228 
4229     return HI_SUCCESS;
4230 }
4231 #endif
4232 
4233 #if (TDE_CAPABILITY & DEFLICKER)
4234 /*
4235  * Function:      tde_osi_quick_flicker
4236  * Description:   deflicker source bitmap,output to target bitmap,source and target can be the same
4237  * Input:         src_surface: source bitmap info struct
4238  *                dst_surface: terget bitmap info struct
4239  */
tde_osi_quick_flicker(hi_s32 handle,hi_tde_surface * src_surface,hi_tde_rect * src_rect,hi_tde_surface * dst_surface,hi_tde_rect * dst_rect)4240 hi_s32 tde_osi_quick_flicker(hi_s32 handle, hi_tde_surface *src_surface, hi_tde_rect *src_rect,
4241                              hi_tde_surface *dst_surface, hi_tde_rect *dst_rect)
4242 {
4243     hi_s32 ret;
4244     hi_tde_opt option = { 0 };
4245     hi_tde_double_src double_src;
4246 
4247     option.deflicker_mode = HI_TDE_DEFLICKER_LEVEL_MODE_BOTH;
4248     option.resize = HI_TRUE;
4249     if (src_surface->color_fmt >= HI_TDE_COLOR_FMT_JPG_YCBCR400MBP) {
4250         tde_error("This operation doesn't support Semi-plannar!\n");
4251         return HI_ERR_TDE_INVALID_PARA;
4252     }
4253 
4254     double_src.bg_surface  = HI_NULL;
4255     double_src.bg_rect  = HI_NULL;
4256     double_src.fg_surface = src_surface;
4257     double_src.fg_rect = src_rect;
4258     double_src.dst_surface = dst_surface;
4259     double_src.dst_rect = dst_rect;
4260     ret = tde_osi_blit(handle, &double_src, &option);
4261     if (ret < 0) {
4262         return ret;
4263     }
4264     return HI_SUCCESS;
4265 }
4266 #endif
4267 
4268 #endif
4269 
4270 /*
4271  * Function:      tde_osi_blit
4272  * Description:   operate pstBackGround with pstForeGround,which result output to dst_surface,
4273                   operate setting is in pstOpt
4274  * Input:         opt:  operate parameter setting struct
4275  */
tde_osi_blit(hi_s32 handle,hi_tde_double_src * double_src,hi_tde_opt * opt)4276 hi_s32 tde_osi_blit(hi_s32 handle, hi_tde_double_src *double_src, hi_tde_opt *opt)
4277 {
4278     tde_operation_category opt_category;
4279     hi_s32 ret;
4280     hi_tde_single_src single_src;
4281 
4282     opt_category = tde_osi_get_opt_category(double_src, opt);
4283     switch (opt_category) {
4284 #ifndef HI_BUILD_IN_BOOT
4285         case TDE_OPERATION_SINGLE_SRC1:
4286             if (double_src->bg_surface == HI_NULL) {
4287                 single_src.src_surface = double_src->fg_surface;
4288                 single_src.src_rect = double_src->fg_rect;
4289             } else {
4290                 single_src.src_surface = double_src->bg_surface;
4291                 single_src.src_rect = double_src->bg_rect;
4292             }
4293             single_src.dst_surface = double_src->dst_surface;
4294             single_src.dst_rect = double_src->dst_rect;
4295             return tde_osi_single_src_1_blit(handle, &single_src, HI_FALSE, HI_FALSE);
4296             break;
4297         case TDE_OPERATION_SINGLE_SRC2:
4298             if (double_src->bg_surface == HI_NULL) {
4299                 single_src.src_surface = double_src->fg_surface;
4300                 single_src.src_rect = double_src->fg_rect;
4301             } else {
4302                 single_src.src_surface = double_src->bg_surface;
4303                 single_src.src_rect = double_src->bg_rect;
4304             }
4305             single_src.dst_surface = double_src->dst_surface;
4306             single_src.dst_rect = double_src->dst_rect;
4307             ret = tde_osi_single_src_2_blit(handle, &single_src, opt, HI_FALSE, HI_FALSE);
4308             if (ret < 0) {
4309                 return ret;
4310             }
4311             break;
4312 #endif
4313         case TDE_OPERATION_DOUBLE_SRC:
4314             ret = tde_osi_double_src_2_blit(handle, double_src, opt);
4315             if (ret < 0) {
4316                 return ret;
4317             }
4318             break;
4319         default:
4320             return HI_ERR_TDE_INVALID_PARA;
4321     }
4322     return HI_SUCCESS;
4323 }
4324 
4325 /*
4326  * Function:      tde_osi_quick_fill
4327  * Description:   quick fill fixed value to target bitmap, fill value is referred to target bitmap
4328  * Input:         dst_surface: target bitmap info struct
4329  *                fill_data: fill value
4330  *                pFuncComplCB: callback function pointer when operate is over;if null, to say to no need to notice
4331  */
tde_osi_quick_fill(hi_s32 handle,hi_tde_surface * dst_surface,hi_tde_rect * dst_rect,hi_u32 fill_data)4332 hi_s32 tde_osi_quick_fill(hi_s32 handle, hi_tde_surface *dst_surface, hi_tde_rect *dst_rect, hi_u32 fill_data)
4333 {
4334     hi_tde_fill_color fill_color;
4335 
4336     fill_color.color_fmt = dst_surface->color_fmt;
4337     fill_color.color_value = fill_data;
4338 
4339     return tde_osi_1_source_fill(handle, dst_surface, dst_rect, &fill_color, HI_NULL);
4340 }
4341 
4342 #ifndef HI_BUILD_IN_BOOT
4343 /*
4344  * Function:      tde_osi_single_src_1_blit
4345  * Description:   source1 operate realization
4346  * Input:         dst_surface: target bitmap info struct
4347  *                dst_rect: target bitmap operate zone
4348  * Return:        success/fail
4349  */
tde_osi_single_src_1_blit(hi_s32 handle,hi_tde_single_src * single_src,hi_bool mmz_for_src,hi_bool mmz_for_dst)4350 static hi_s32 tde_osi_single_src_1_blit(hi_s32 handle, hi_tde_single_src *single_src,
4351                                         hi_bool mmz_for_src, hi_bool mmz_for_dst)
4352 {
4353     hi_s32 ret;
4354     tde_hw_node *hw_node = HI_NULL;
4355     tde_surface_msg src_drv_surface = { 0 };
4356     tde_surface_msg dst_drv_surface = { 0 };
4357     tde_scandirection_mode src_scan_info = { 0 };
4358     tde_scandirection_mode dst_scan_info = { 0 };
4359 
4360     if ((single_src->src_surface == HI_NULL) || (single_src->src_rect == HI_NULL) ||
4361         (single_src->dst_surface == HI_NULL) || (single_src->dst_rect == HI_NULL)) {
4362         return HI_ERR_TDE_NULL_PTR;
4363     }
4364 
4365 #if ((HICHIP == HI3519A_V100) || (HICHIP == HI3516C_V500))
4366     if ((single_src->src_surface->color_fmt == HI_TDE_COLOR_FMT_YCBCR422) ||
4367         (single_src->src_surface->color_fmt == HI_TDE_COLOR_FMT_PKGVYUY)) {
4368         tde_error("This operation doesn't support PKG!\n");
4369         return HI_ERR_TDE_INVALID_PARA;
4370     }
4371 #endif
4372 
4373     if (single_src->src_surface->color_fmt >= HI_TDE_COLOR_FMT_JPG_YCBCR400MBP) {
4374         tde_error("This operation doesn't support Semi-plannar!\n");
4375         return HI_ERR_TDE_INVALID_PARA;
4376     }
4377 
4378     tde_unify_rect(single_src->src_rect, single_src->dst_rect);
4379 
4380     if (tde_hal_node_init_nd(&hw_node) < 0) {
4381         return HI_ERR_TDE_NO_MEM;
4382     }
4383     if (tde_hal_node_set_base_operate(hw_node, TDE_QUIKE_COPY, TDE_SRC1_BYPASS, 0) < 0) {
4384         tde_hal_free_node_buf(hw_node);
4385         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
4386     }
4387 
4388     if (tde_osi_get_scan_info_ex(single_src, HI_NULL, &src_scan_info, &dst_scan_info) < 0) {
4389         tde_hal_free_node_buf(hw_node);
4390         return HI_ERR_TDE_INVALID_PARA;
4391     }
4392 
4393     tde_osi_convert_surface(single_src->src_surface, single_src->src_rect, &src_scan_info, &src_drv_surface);
4394     src_drv_surface.cma = mmz_for_src;
4395 
4396     tde_hal_node_set_src1(hw_node, &src_drv_surface);
4397 
4398     tde_osi_set_ext_alpha(single_src->src_surface, HI_NULL, hw_node);
4399 
4400     tde_osi_convert_surface(single_src->dst_surface, single_src->dst_rect, &dst_scan_info, &dst_drv_surface);
4401     dst_drv_surface.cma = mmz_for_dst;
4402 
4403     tde_hal_node_set_tqt(hw_node, &dst_drv_surface, HI_TDE_OUT_ALPHA_FROM_NORM);
4404     ret = tde_osi_set_node_finish(handle, hw_node, 0, TDE_NODE_SUBM_ALONE);
4405     if (ret < 0) {
4406         tde_hal_free_node_buf(hw_node);
4407         return ret;
4408     }
4409     return HI_SUCCESS;
4410 }
4411 #endif
4412 
tde_osi_single_para(hi_tde_single_src * single_src,hi_tde_opt * opt,tde_hw_node ** hw_node,tde_scandirection_mode * src_scan_info,tde_scandirection_mode * dst_scan_info)4413 static hi_s32 tde_osi_single_para(hi_tde_single_src *single_src, hi_tde_opt *opt, tde_hw_node **hw_node,
4414     tde_scandirection_mode *src_scan_info, tde_scandirection_mode *dst_scan_info)
4415 {
4416     hi_s32 ret;
4417     hi_tde_double_src double_src;
4418 
4419 #if (TDE_CAPABILITY & COMPRESS)
4420     hi_bool compress_or_decompress = HI_FALSE;
4421 #endif
4422     ret = tde_osi_check_single_src_to_para(single_src->src_surface, single_src->src_rect,
4423                                            single_src->dst_surface, single_src->dst_rect, opt);
4424     if (ret != HI_SUCCESS) {
4425         return ret;
4426     }
4427 
4428     if (tde_hal_node_init_nd(hw_node) != HI_SUCCESS) {
4429         return HI_ERR_TDE_NO_MEM;
4430     }
4431 
4432     double_src.bg_surface = HI_NULL;
4433     double_src.bg_rect = HI_NULL;
4434     double_src.fg_surface = single_src->src_surface;
4435     double_src.fg_rect = single_src->src_rect;
4436     double_src.dst_surface = single_src->dst_surface;
4437     double_src.dst_rect = single_src->dst_rect;
4438     if (tde_osi_set_clip_para(&double_src, opt, *hw_node) != HI_SUCCESS) {
4439         tde_hal_free_node_buf(*hw_node);
4440         return HI_ERR_TDE_CLIP_AREA;
4441     }
4442     if (tde_osi_get_scan_info_ex(single_src, opt, src_scan_info, dst_scan_info) != HI_SUCCESS) {
4443         tde_hal_free_node_buf(*hw_node);
4444         return HI_ERR_TDE_INVALID_PARA;
4445     }
4446 #if (TDE_CAPABILITY & COMPRESS)
4447     compress_or_decompress = ((opt->is_compress) || (opt->is_decompress));
4448     if (compress_or_decompress) {
4449         src_scan_info->h_scan = TDE_SCAN_LEFT_RIGHT;
4450         src_scan_info->v_scan = TDE_SCAN_UP_DOWN;
4451         dst_scan_info->h_scan = TDE_SCAN_LEFT_RIGHT;
4452         dst_scan_info->v_scan = TDE_SCAN_UP_DOWN;
4453     }
4454 #endif
4455     return HI_SUCCESS;
4456 }
4457 
tde_osi_single_opt(hi_tde_opt * opt,hi_tde_single_src * single_src,tde_surface_msg * drv_surface,tde_hw_node * hw_node)4458 static hi_s32 tde_osi_single_opt(hi_tde_opt *opt, hi_tde_single_src *single_src, tde_surface_msg *drv_surface,
4459     tde_hw_node *hw_node)
4460 {
4461     hi_u16 code;
4462     tde_conv_mode_cmd conv = { 0 };
4463     hi_s32 ret;
4464     tde_clut_usage clut_usage = TDE_CLUT_USAGE_BUTT;
4465 
4466 #if (TDE_CAPABILITY & COMPRESS)
4467     if (opt->is_compress) {
4468         tde_hal_node_set_compress_tqt(hw_node, drv_surface, opt->out_alpha_from);
4469         tde_hal_node_set_compress(hw_node);
4470     } else {
4471         tde_hal_node_set_tqt(hw_node, drv_surface, opt->out_alpha_from);
4472     }
4473 #else
4474     tde_hal_node_set_tqt(hw_node, drv_surface, opt->out_alpha_from);
4475 #endif
4476     code = tde_osi_single_src_to_get_opt_code(single_src->src_surface->color_fmt,
4477                                               single_src->dst_surface->color_fmt);
4478 
4479     tde_osi_get_conv_by_code(code, &conv);
4480 
4481     if (tde_hal_node_set_color_convert(hw_node, &conv) != HI_SUCCESS) {
4482         tde_hal_free_node_buf(hw_node);
4483         tde_free((hi_void *)drv_surface);
4484         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
4485     }
4486     ret = tde_osi_set_clut_opt(single_src->src_surface, single_src->dst_surface, &clut_usage,
4487                                opt->clut_reload, hw_node);
4488     if (ret != HI_SUCCESS) {
4489         tde_hal_free_node_buf(hw_node);
4490         tde_free((hi_void *)drv_surface);
4491         return ret;
4492     }
4493 
4494     ret = tde_osi_set_base_opt_para_for_blit(opt, HI_NULL, single_src->src_surface,
4495         TDE_OPERATION_SINGLE_SRC2, hw_node);
4496     if (ret != HI_SUCCESS) {
4497         tde_error("Set base opt para for blit failed, ret = 0x%x\n", ret);
4498     }
4499     tde_osi_set_ext_alpha(HI_NULL, single_src->src_surface, hw_node);
4500     return HI_SUCCESS;
4501 }
4502 
tde_osi_single_node(hi_s32 handle,hi_tde_opt * opt,hi_tde_single_src * single_src,tde_surface_msg * drv_surface,tde_hw_node * hw_node)4503 static hi_s32 tde_osi_single_node(hi_s32 handle, hi_tde_opt *opt, hi_tde_single_src *single_src,
4504     tde_surface_msg *drv_surface, tde_hw_node *hw_node)
4505 {
4506     hi_bool set_filter_node = HI_FALSE;
4507     hi_tde_double_src double_src;
4508     hi_s32 ret;
4509 
4510     set_filter_node = ((opt->resize) || (opt->deflicker_mode != HI_TDE_DEFLICKER_LEVEL_MODE_NONE) ||
4511                        (single_src->src_surface->color_fmt >= HI_TDE_COLOR_FMT_YCBCR422));
4512     if (set_filter_node) {
4513 #if (TDE_CAPABILITY & SLICE)
4514         if ((single_src->src_surface->color_fmt >= HI_TDE_COLOR_FMT_YCBCR422) && (!(opt->resize))) {
4515             single_src->src_rect->height = single_src->dst_rect->height;
4516             single_src->src_rect->width = single_src->dst_rect->width;
4517         }
4518 #endif
4519         double_src.bg_surface = HI_NULL;
4520         double_src.bg_rect = HI_NULL;
4521         double_src.fg_surface = single_src->src_surface;
4522         double_src.fg_rect = single_src->src_rect;
4523         double_src.dst_surface = single_src->dst_surface;
4524         double_src.dst_rect = single_src->dst_rect;
4525         ret = tde_osi_set_filter_node(handle, hw_node, &double_src, opt->deflicker_mode,
4526                                       opt->filter_mode);
4527         if (ret != HI_SUCCESS) {
4528             tde_hal_free_node_buf(hw_node);
4529             tde_free((hi_void *)drv_surface);
4530             return ret;
4531         }
4532 #if (TDE_CAPABILITY & SLICE)
4533         tde_hal_free_node_buf(hw_node);
4534 #endif
4535         tde_free((hi_void *)drv_surface);
4536         return HI_SUCCESS;
4537     }
4538     ret = tde_osi_set_node_finish(handle, hw_node, 0, TDE_NODE_SUBM_ALONE);
4539     if (ret != HI_SUCCESS) {
4540         tde_hal_free_node_buf(hw_node);
4541         tde_free((hi_void *)drv_surface);
4542         return ret;
4543     }
4544     tde_free((hi_void *)drv_surface);
4545     return HI_SUCCESS;
4546 }
4547 
4548 /*
4549  * Function:      tde_osi_single_src_2_blit
4550  * Description:   source2 operate realization
4551  * Input:         dst_surface: target bitmap info struct
4552  *                dst_rect: target bitmap operate zone
4553  * Return:        success/fail
4554  */
tde_osi_single_src_2_blit(hi_s32 handle,hi_tde_single_src * single_src,hi_tde_opt * opt,hi_bool mmz_for_src,hi_bool mmz_for_dst)4555 static hi_s32 tde_osi_single_src_2_blit(hi_s32 handle, hi_tde_single_src *single_src,
4556                                         hi_tde_opt *opt, hi_bool mmz_for_src, hi_bool mmz_for_dst)
4557 {
4558     tde_hw_node *hw_node = HI_NULL;
4559     tde_surface_msg *drv_surface = HI_NULL;
4560     hi_s32 ret;
4561     tde_scandirection_mode src_scan_info = { 0 };
4562     tde_scandirection_mode dst_scan_info = { 0 };
4563 
4564     ret = tde_osi_single_para(single_src, opt, &hw_node, &src_scan_info, &dst_scan_info);
4565     if (ret != HI_SUCCESS) {
4566         return ret;
4567     }
4568 
4569     drv_surface = (tde_surface_msg *)tde_malloc(sizeof(tde_surface_msg));
4570     if (drv_surface == HI_NULL) {
4571         tde_error ("malloc pstDrvSurface failed, size=%ld!\n", (unsigned long)(sizeof(tde_surface_msg)));
4572         tde_hal_free_node_buf(hw_node);
4573         return HI_ERR_TDE_NO_MEM;
4574     }
4575     tde_osi_convert_surface(single_src->src_surface, single_src->src_rect, &src_scan_info, drv_surface);
4576     drv_surface->cma = mmz_for_src;
4577 
4578 #if (TDE_CAPABILITY & COMPRESS)
4579     (opt->is_decompress) ? tde_hal_node_set_src_to_decompress(hw_node, drv_surface) :
4580     tde_hal_node_set_src2(hw_node, drv_surface);
4581 #else
4582     tde_hal_node_set_src2(hw_node, drv_surface);
4583 #endif
4584 
4585     tde_osi_convert_surface(single_src->dst_surface, single_src->dst_rect, &dst_scan_info, drv_surface);
4586     if (opt->out_alpha_from >= HI_TDE_OUT_ALPHA_FROM_MAX) {
4587         tde_error("out_alpha_from error!\n");
4588         tde_hal_free_node_buf(hw_node);
4589         tde_free((hi_void *)drv_surface);
4590         return HI_ERR_TDE_INVALID_PARA;
4591     }
4592 
4593     if (opt->out_alpha_from == HI_TDE_OUT_ALPHA_FROM_BACKGROUND) {
4594         tde_hal_free_node_buf(hw_node);
4595         tde_free((hi_void *)drv_surface);
4596         tde_error("out_alpha_from error!\n");
4597         return HI_ERR_TDE_INVALID_PARA;
4598     }
4599     drv_surface->cma = mmz_for_dst;
4600     ret = tde_osi_single_opt(opt, single_src, drv_surface, hw_node);
4601     if (ret != HI_SUCCESS) {
4602         return ret;
4603     }
4604 
4605     ret = tde_osi_single_node(handle, opt, single_src, drv_surface, hw_node);
4606     if (ret != HI_SUCCESS) {
4607         return ret;
4608     }
4609 
4610     return HI_SUCCESS;
4611 }
4612 
tde_osi_check_single_src_to_para(hi_tde_surface * fore_ground,hi_tde_rect * fore_ground_rect,hi_tde_surface * dst_surface,hi_tde_rect * dst_rect,hi_tde_opt * opt)4613 static hi_s32 tde_osi_check_single_src_to_para(hi_tde_surface *fore_ground, hi_tde_rect *fore_ground_rect,
4614                                                hi_tde_surface *dst_surface, hi_tde_rect *dst_rect,
4615                                                hi_tde_opt *opt)
4616 {
4617     hi_bool null_ptr = HI_FALSE;
4618 
4619     if (opt == HI_NULL) {
4620         tde_error("pstOpt is null %s(line=%d)\n", __FUNCTION__, __LINE__);
4621         return HI_ERR_TDE_NULL_PTR;
4622     }
4623 
4624     null_ptr = ((dst_surface == HI_NULL) || (dst_rect == HI_NULL) || ((opt == HI_NULL)) ||
4625                 (fore_ground == HI_NULL) || (fore_ground_rect == HI_NULL));
4626 
4627     if (null_ptr) {
4628         return HI_ERR_TDE_NULL_PTR;
4629     }
4630 
4631     if (tde_osi_check_single_src_to_opt(fore_ground->color_fmt, dst_surface->color_fmt, opt) != HI_SUCCESS) {
4632         return HI_ERR_TDE_INVALID_PARA;
4633     }
4634 
4635     if (opt->resize) {
4636         if (tde_osi_check_resize_para(fore_ground_rect->width, fore_ground_rect->height,
4637                                       dst_rect->width, dst_rect->height) != HI_SUCCESS) {
4638             return HI_ERR_TDE_MINIFICATION;
4639         }
4640     }
4641 #if TDE_CAPABILITY & COMPRESS
4642     if (opt->is_compress) {
4643         if (tde_osi_check_compress_para(fore_ground, fore_ground_rect, dst_surface, dst_rect, opt) !=
4644             HI_SUCCESS) {
4645             return HI_ERR_TDE_INVALID_PARA;
4646         }
4647     }
4648 
4649     if (opt->is_decompress) {
4650         if (tde_osi_check_decompress_para(fore_ground, fore_ground_rect, dst_surface, dst_rect, opt) !=
4651             HI_SUCCESS) {
4652             return HI_ERR_TDE_INVALID_PARA;
4653         }
4654     }
4655 #endif
4656 
4657     return HI_SUCCESS;
4658 }
4659 
tde_osi_double_para(hi_tde_double_src * double_src,hi_tde_opt * opt,tde_hw_node ** hw_node)4660 static hi_s32 tde_osi_double_para(hi_tde_double_src *double_src, hi_tde_opt *opt, tde_hw_node **hw_node)
4661 {
4662     hi_bool null_ptr = ((double_src->bg_surface == HI_NULL) || ((double_src->bg_rect == HI_NULL)) ||
4663                         (double_src->fg_surface == HI_NULL) || ((double_src->fg_rect == HI_NULL)) ||
4664                         (double_src->dst_surface == HI_NULL) || ((double_src->dst_rect == HI_NULL)) ||
4665                         (opt == HI_NULL));
4666 
4667     if (null_ptr) {
4668         return HI_ERR_TDE_NULL_PTR;
4669     }
4670 
4671     if (tde_osi_check_double_src_opt(double_src->bg_surface->color_fmt, double_src->fg_surface->color_fmt,
4672                                      double_src->dst_surface->color_fmt, opt) != HI_SUCCESS) {
4673         return HI_ERR_TDE_INVALID_PARA;
4674     }
4675     if (opt->resize) {
4676         if (tde_osi_check_resize_para(double_src->fg_rect->width, double_src->fg_rect->height,
4677                                       double_src->dst_rect->width, double_src->dst_rect->height) != HI_SUCCESS) {
4678             return HI_ERR_TDE_MINIFICATION;
4679         }
4680     }
4681 
4682 #if (TDE_CAPABILITY & COMPRESS)
4683     if (opt->is_compress) {
4684         if (tde_osi_check_compress_para(double_src->fg_surface, double_src->fg_rect,
4685                                         double_src->dst_surface, double_src->dst_rect, opt) < 0) {
4686             return HI_ERR_TDE_INVALID_PARA;
4687         }
4688     }
4689 
4690     if (opt->is_decompress) {
4691         if (tde_osi_check_decompress_para(double_src->fg_surface, double_src->fg_rect,
4692                                           double_src->dst_surface, double_src->dst_rect, opt) < 0) {
4693             return HI_ERR_TDE_INVALID_PARA;
4694         }
4695     }
4696 #endif
4697 
4698     if (tde_hal_node_init_nd(hw_node) != HI_SUCCESS) {
4699         return HI_ERR_TDE_NO_MEM;
4700     }
4701 
4702     if (tde_osi_set_clip_para(double_src, opt, *hw_node) != HI_SUCCESS) {
4703         tde_hal_free_node_buf(*hw_node);
4704         return HI_ERR_TDE_CLIP_AREA;
4705     }
4706     return HI_SUCCESS;
4707 }
4708 
tde_osi_double_opt(hi_tde_double_src * double_src,hi_tde_opt * opt,tde_hw_node * hw_node,tde_surface_msg * drv_surface)4709 static hi_s32 tde_osi_double_opt(hi_tde_double_src *double_src, hi_tde_opt *opt, tde_hw_node *hw_node,
4710     tde_surface_msg *drv_surface)
4711 {
4712     hi_s32 ret;
4713     hi_u16 code;
4714     tde_conv_mode_cmd conv = { 0 };
4715     tde_clut_usage clut_usage = TDE_CLUT_USAGE_BUTT;
4716 
4717     if (opt->out_alpha_from >= HI_TDE_OUT_ALPHA_FROM_MAX) {
4718         tde_error("out_alpha_from error!\n");
4719         tde_hal_free_node_buf(hw_node);
4720         return HI_ERR_TDE_INVALID_PARA;
4721     }
4722 
4723 #if (TDE_CAPABILITY & COMPRESS)
4724     if (opt->is_compress) {
4725         tde_hal_node_set_compress_tqt(hw_node, drv_surface, opt->out_alpha_from);
4726         tde_hal_node_set_compress(hw_node);
4727     } else {
4728         tde_hal_node_set_tqt(hw_node, drv_surface, opt->out_alpha_from);
4729     }
4730 #else
4731     tde_hal_node_set_tqt(hw_node, drv_surface, opt->out_alpha_from);
4732 #endif
4733 
4734     code = tde_osi_double_src_get_opt_code(double_src->bg_surface->color_fmt,
4735         double_src->fg_surface->color_fmt, double_src->dst_surface->color_fmt);
4736 
4737     tde_osi_get_conv_by_code(code, &conv);
4738 
4739     if (tde_hal_node_set_color_convert(hw_node, &conv) != HI_SUCCESS) {
4740         tde_hal_free_node_buf(hw_node);
4741         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
4742     }
4743     ret = tde_osi_set_clut_opt(double_src->fg_surface, double_src->dst_surface,
4744                                &clut_usage, opt->clut_reload, hw_node);
4745     if (ret != HI_SUCCESS) {
4746         tde_hal_free_node_buf(hw_node);
4747         return ret;
4748     }
4749 
4750     ret = tde_osi_set_color_key(double_src, hw_node,
4751         opt->color_key_value, opt->color_key_mode, clut_usage);
4752     if (ret != HI_SUCCESS) {
4753         tde_hal_free_node_buf(hw_node);
4754         return ret;
4755     }
4756 
4757     ret = tde_osi_set_base_opt_para_for_blit(opt, double_src->bg_surface, double_src->fg_surface,
4758         TDE_OPERATION_DOUBLE_SRC, hw_node);
4759     if (ret != HI_SUCCESS) {
4760         tde_error("Set base opt para for blit failed, ret = 0x%x\n", ret);
4761     }
4762     tde_osi_set_ext_alpha(double_src->bg_surface, double_src->fg_surface, hw_node);
4763     return HI_SUCCESS;
4764 }
4765 
tde_osi_double_node(hi_s32 handle,hi_tde_double_src * double_src,hi_tde_opt * opt,tde_hw_node * hw_node)4766 static hi_s32 tde_osi_double_node(hi_s32 handle, hi_tde_double_src *double_src, hi_tde_opt *opt,
4767     tde_hw_node *hw_node)
4768 {
4769     hi_s32 ret;
4770     hi_bool set_filter_node = HI_FALSE;
4771 
4772 #if (TDE_CAPABILITY & SLICE)
4773     set_filter_node = ((opt->resize) || ((opt->deflicker_mode != HI_TDE_DEFLICKER_LEVEL_MODE_NONE)) ||
4774                        (double_src->fg_surface->color_fmt >= HI_TDE_COLOR_FMT_YCBCR422) ||
4775                        (double_src->bg_surface->color_fmt >= HI_TDE_COLOR_FMT_YCBCR422));
4776 #else
4777     set_filter_node = ((opt->resize) || (opt->deflicker_mode != HI_TDE_DEFLICKER_LEVEL_MODE_NONE) ||
4778                        (double_src->fg_surface->color_fmt >= HI_TDE_COLOR_FMT_YCBCR422));
4779 #endif
4780     if (set_filter_node) {
4781 #if (TDE_CAPABILITY & SLICE)
4782         double_src->bg_rect->height = double_src->dst_rect->height;
4783         double_src->bg_rect->width = double_src->dst_rect->width;
4784 
4785         if ((double_src->fg_surface->color_fmt >= HI_TDE_COLOR_FMT_YCBCR422) && (!(opt->resize))) {
4786             double_src->fg_rect->height = double_src->dst_rect->height;
4787             double_src->fg_rect->width = double_src->dst_rect->width;
4788         }
4789         ret = tde_osi_set_filter_node(handle, hw_node, double_src,
4790                                       opt->deflicker_mode, opt->filter_mode);
4791         if (ret != HI_SUCCESS) {
4792             tde_hal_free_node_buf(hw_node);
4793             return ret;
4794         }
4795         tde_hal_free_node_buf(hw_node);
4796 #else
4797         ret = tde_osi_set_filter_node(handle, hw_node, double_src, opt->deflicker_mode, opt->filter_mode);
4798         if (ret != HI_SUCCESS) {
4799             tde_hal_free_node_buf(hw_node);
4800             return ret;
4801         }
4802 #endif
4803         return HI_SUCCESS;
4804     }
4805     ret = tde_osi_set_node_finish(handle, hw_node, 0, TDE_NODE_SUBM_ALONE);
4806     if (ret != HI_SUCCESS) {
4807         tde_hal_free_node_buf(hw_node);
4808         return ret;
4809     }
4810     return HI_SUCCESS;
4811 }
4812 
4813 /*
4814  * Function:      tde_osi_double_src_2_blit
4815  * Description:   dual source operate realization
4816  * Input:         double_src:  bitmap info struct
4817  *                opt: config parameter
4818  * Return:        success/fail
4819  * Others:        add support for YCbCr422
4820  */
tde_osi_double_src_2_blit(hi_s32 handle,hi_tde_double_src * double_src,hi_tde_opt * opt)4821 static hi_s32 tde_osi_double_src_2_blit(hi_s32 handle, hi_tde_double_src *double_src, hi_tde_opt *opt)
4822 {
4823     tde_hw_node *hw_node = HI_NULL;
4824     tde_scandirection_mode src_scan_info = { 0 };
4825     tde_scandirection_mode dst_scan_info = { 0 };
4826     tde_surface_msg drv_surface = { 0 };
4827     hi_s32 ret;
4828     hi_tde_single_src single_src;
4829 
4830     ret = tde_osi_double_para(double_src, opt, &hw_node);
4831     if (ret != HI_SUCCESS) {
4832         return ret;
4833     }
4834     single_src.src_surface = double_src->fg_surface;
4835     single_src.src_rect = double_src->fg_rect;
4836     single_src.dst_surface = double_src->dst_surface;
4837     single_src.dst_rect = double_src->dst_rect;
4838     if (tde_osi_get_scan_info_ex(&single_src, opt, &src_scan_info, &dst_scan_info) != HI_SUCCESS) {
4839         tde_hal_free_node_buf(hw_node);
4840         return HI_ERR_TDE_INVALID_PARA;
4841     }
4842 
4843 #if (TDE_CAPABILITY & COMPRESS)
4844     if ((opt->is_compress) || (opt->is_decompress)) {
4845         src_scan_info.h_scan = TDE_SCAN_LEFT_RIGHT;
4846         src_scan_info.v_scan = TDE_SCAN_UP_DOWN;
4847         dst_scan_info.h_scan = TDE_SCAN_LEFT_RIGHT;
4848         dst_scan_info.v_scan = TDE_SCAN_UP_DOWN;
4849     }
4850 #endif
4851 
4852     tde_osi_convert_surface(double_src->bg_surface, double_src->bg_rect, &src_scan_info, &drv_surface);
4853 
4854     tde_hal_node_set_src1(hw_node, &drv_surface);
4855 
4856     tde_osi_convert_surface(double_src->fg_surface, double_src->fg_rect, &src_scan_info, &drv_surface);
4857 
4858     tde_hal_node_set_src2(hw_node, &drv_surface);
4859 
4860     tde_osi_convert_surface(double_src->dst_surface, double_src->dst_rect, &dst_scan_info, &drv_surface);
4861     ret = tde_osi_double_opt(double_src, opt, hw_node, &drv_surface);
4862     if (ret != HI_SUCCESS) {
4863         return ret;
4864     }
4865 
4866     ret = tde_osi_double_node(handle, double_src, opt, hw_node);
4867     if (ret != HI_SUCCESS) {
4868         return ret;
4869     }
4870     return HI_SUCCESS;
4871 }
4872 
4873 #ifndef HI_BUILD_IN_BOOT
tde_osi_set_color_key(hi_tde_double_src * double_src,tde_hw_node * hw_node,hi_tde_color_key color_key_value,hi_tde_color_key_mode color_key_mode,tde_clut_usage clut_usage)4874 static hi_s32 tde_osi_set_color_key(hi_tde_double_src *double_src,
4875                                     tde_hw_node *hw_node, hi_tde_color_key color_key_value,
4876                                     hi_tde_color_key_mode color_key_mode,
4877                                     tde_clut_usage clut_usage)
4878 {
4879     tde_color_key_cmd color_key;
4880     tde_colorfmt_category fmt_category;
4881     hi_bool unknown_fmt_category = HI_FALSE;
4882     hi_bool color_key_foreground_before_clut_mode = (clut_usage != TDE_CLUT_COLOREXPENDING) &&
4883                                                      (clut_usage != TDE_CLUT_CLUT_BYPASS);
4884     hi_bool set_color_key = (color_key_mode != HI_TDE_COLOR_KEY_MODE_NONE);
4885 
4886     color_key.color_key_value = color_key_value;
4887 
4888     if (!set_color_key) {
4889         return HI_SUCCESS;
4890     }
4891 
4892     switch (color_key_mode) {
4893         case HI_TDE_COLOR_KEY_MODE_BACKGROUND:
4894             color_key.color_key_mode = TDE_DRV_COLORKEY_BACKGROUND;
4895             fmt_category = tde_osi_get_fmt_category(double_src->bg_surface->color_fmt);
4896             break;
4897         case HI_TDE_COLOR_KEY_MODE_FOREGROUND:
4898             color_key.color_key_mode = (color_key_foreground_before_clut_mode) ?
4899                 TDE_DRV_COLORKEY_FOREGROUND_AFTER_CLUT : TDE_DRV_COLORKEY_FOREGROUND_BEFORE_CLUT;
4900             fmt_category = tde_osi_get_fmt_category(double_src->fg_surface->color_fmt);
4901             break;
4902         default:
4903             tde_error("invalid ColorKeyMode!\n");
4904             return HI_ERR_TDE_INVALID_PARA;
4905     }
4906 
4907     unknown_fmt_category = fmt_category >= TDE_COLORFMT_CATEGORY_BUTT;
4908 
4909     if (unknown_fmt_category) {
4910         tde_error("Unknown fmt category!\n");
4911         return HI_ERR_TDE_INVALID_PARA;
4912     }
4913 
4914     if (tde_hal_node_set_colorkey(hw_node, fmt_category, &color_key) != HI_SUCCESS) {
4915         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
4916     }
4917 
4918     return HI_SUCCESS;
4919 }
4920 #endif
4921 
tde_osi_mb_val(hi_tde_mb_src * mb_src,hi_tde_mb_opt * mb_opt,hi_u32 * cb_cr_height,hi_u32 * byte_per_pixel,hi_u32 * cb_cr_byte_per_pixel)4922 static hi_s32 tde_osi_mb_val(hi_tde_mb_src *mb_src, hi_tde_mb_opt *mb_opt, hi_u32 *cb_cr_height,
4923     hi_u32 *byte_per_pixel, hi_u32 *cb_cr_byte_per_pixel)
4924 {
4925     hi_s32 ret, bpp;
4926 
4927     ret = tde_osi_check_mb_blit_para(mb_src, mb_opt);
4928     if (ret != HI_SUCCESS) {
4929         return ret;
4930     }
4931 
4932     if ((mb_src->dst_rect->height == mb_src->src_rect->height) &&
4933         (mb_src->dst_rect->width == mb_src->src_rect->width)) {
4934         mb_opt->resize_en = HI_TDE_MB_RESIZE_NONE;
4935     }
4936 
4937     if (mb_opt->resize_en == HI_TDE_MB_RESIZE_NONE) {
4938         tde_unify_rect(mb_src->src_rect, mb_src->dst_rect);
4939     }
4940 
4941     if (tde_osi_check_resize_para(mb_src->src_rect->width, mb_src->src_rect->height,
4942                                   mb_src->dst_rect->width, mb_src->dst_rect->height) != HI_SUCCESS) {
4943         tde_error("The Scale is too large!\n");
4944         return HI_ERR_TDE_MINIFICATION;
4945     }
4946 
4947     *cb_cr_height = TDE_MAX_SLICE_RECT_HEIGHT;
4948     if ((mb_src->mb_surface->mb_color_fmt == HI_TDE_MB_COLOR_FMT_MP1_YCBCR420MBP) ||
4949         (mb_src->mb_surface->mb_color_fmt == HI_TDE_MB_COLOR_FMT_MP2_YCBCR420MBP) ||
4950         (mb_src->mb_surface->mb_color_fmt == HI_TDE_MB_COLOR_FMT_MP2_YCBCR420MBI) ||
4951         (mb_src->mb_surface->mb_color_fmt == HI_TDE_MB_COLOR_FMT_JPG_YCBCR420MBP) ||
4952         (mb_src->mb_surface->mb_color_fmt == HI_TDE_MB_COLOR_FMT_JPG_YCBCR422MBVP)) {
4953         *cb_cr_height = TDE_MAX_SLICE_RECT_HEIGHT / 2; /* 2 half height */
4954     }
4955 
4956     *cb_cr_byte_per_pixel = ((mb_src->mb_surface->mb_color_fmt == HI_TDE_MB_COLOR_FMT_JPG_YCBCR444MBP) ||
4957         (mb_src->mb_surface->mb_color_fmt == HI_TDE_MB_COLOR_FMT_JPG_YCBCR422MBVP)) ? 2 : 1; /* 2 1 byte per pixel */
4958 
4959     bpp = tde_osi_get_bpp_by_fmt(mb_src->dst_surface->color_fmt);
4960     *byte_per_pixel = ((hi_u32)bpp >> 3); /* 3 bpp data */
4961     return HI_SUCCESS;
4962 }
4963 
4964 /*
4965  * Function:      tde_osi_mb_blit
4966  * Description:   Mb blit
4967  * Return:        >0: return task id of current operate; <0: fail
4968  */
tde_osi_mb_blit(hi_s32 handle,hi_tde_mb_src * mb_src,hi_tde_mb_opt * mb_opt)4969 hi_s32 tde_osi_mb_blit(hi_s32 handle, hi_tde_mb_src *mb_src, hi_tde_mb_opt *mb_opt)
4970 {
4971     hi_u32 height, width, i, j, m, n, byte_per_pixel, cbcr_pixel;
4972     hi_u32 cb_cr_height = 0;
4973     static hi_u64 u64phy, yphy_addr, cb_crphy_addr;
4974     hi_s32 ret = tde_osi_mb_val(mb_src, mb_opt, &cb_cr_height, &byte_per_pixel, &cbcr_pixel);
4975     if (ret != HI_SUCCESS) {
4976         return ret;
4977     }
4978 
4979     drv_tde_mb_src_val(mb_src, height, width);
4980     drv_tde_mb_src_addr(mb_src, yphy_addr, cb_crphy_addr, u64phy);
4981     ret = tde_osi_get_double_cycle_data(mb_src->src_rect, &i, &j);
4982     if (ret != HI_SUCCESS) {
4983         tde_error("Tde osi Get double cycle data failed, ret = 0x%x\n", ret);
4984     }
4985     for (n = 0; n < j; n++) {
4986         for (m = 0; m < i; m++) {
4987             if ((i - 1) == m) {
4988                 mb_src->src_rect->width = width - m * TDE_MAX_SLICE_RECT_WIDTH;
4989             } else {
4990                 mb_src->src_rect->width = TDE_MAX_SLICE_RECT_WIDTH;
4991             }
4992 
4993             if (height > TDE_MAX_SLICE_RECT_HEIGHT) {
4994                 mb_src->src_rect->height = TDE_MAX_SLICE_RECT_HEIGHT;
4995             }
4996 
4997             if ((j - 1) == n) {
4998                 mb_src->src_rect->height = height - n * TDE_MAX_SLICE_RECT_HEIGHT;
4999             } else {
5000                 mb_src->src_rect->height = TDE_MAX_SLICE_RECT_HEIGHT;
5001             }
5002             if (!((i == 1) && (j == 1))) {
5003                 mb_src->dst_rect->width = mb_src->src_rect->width;
5004                 mb_src->dst_rect->height = mb_src->src_rect->height;
5005             }
5006             mb_src->mb_surface->y_addr = yphy_addr + (hi_u64)m * TDE_MAX_SLICE_RECT_WIDTH +
5007                 (hi_u64)n * (hi_u64)(mb_src->mb_surface->y_stride) * TDE_MAX_SLICE_RECT_HEIGHT;
5008             mb_src->dst_surface->phy_addr = u64phy + (hi_u64)m * (hi_u64)byte_per_pixel * TDE_MAX_SLICE_RECT_WIDTH +
5009                 (hi_u64)n * (hi_u64)(mb_src->dst_surface->stride) * TDE_MAX_SLICE_RECT_HEIGHT;
5010             mb_src->mb_surface->cbcr_phy_addr = cb_crphy_addr + (hi_u64)m *
5011                 (hi_u64)cbcr_pixel * TDE_MAX_SLICE_RECT_WIDTH +
5012                 (hi_u64)n * (hi_u64)(mb_src->mb_surface->cbcr_stride) * (hi_u64)(cb_cr_height);
5013             ret = tde_osi_set_mb_para(handle, mb_src, mb_opt);
5014             if (ret != HI_SUCCESS) {
5015                 return ret;
5016             }
5017         }
5018     }
5019     return HI_SUCCESS;
5020 }
5021 
tde_osi_check_surface_ex(hi_tde_surface * surface,hi_tde_rect * rect)5022 static hi_s32 tde_osi_check_surface_ex(hi_tde_surface *surface, hi_tde_rect *rect)
5023 {
5024     hi_bool invalid_operation_area = HI_FALSE;
5025     hi_s32 ret = tde_osi_pre_check_surface_ex(surface, rect);
5026     if (ret != HI_SUCCESS) {
5027         return ret;
5028     }
5029 
5030     invalid_operation_area = ((rect->width > TDE_MAX_RECT_WIDTH_EX) ||
5031                               (rect->height > TDE_MAX_RECT_HEIGHT_EX));
5032 
5033     if (invalid_operation_area) {
5034         tde_error("invalid operation SurfaceEX area!width=%d,height=%d\n", rect->width, rect->height);
5035         return HI_ERR_TDE_INVALID_PARA;
5036     }
5037 
5038     return HI_SUCCESS;
5039 }
5040 
5041 #ifndef HI_BUILD_IN_BOOT
tde_osi_check_mb_src_opt(hi_tde_mb_src * mb_src,hi_tde_mb_opt * mb_opt)5042 static hi_s32 tde_osi_check_mb_src_opt(hi_tde_mb_src *mb_src, hi_tde_mb_opt *mb_opt)
5043 {
5044     if (mb_src->dst_surface->color_fmt >= HI_TDE_COLOR_FMT_JPG_YCBCR400MBP) {
5045         tde_error("This operation doesn't support Semi-plannar!\n");
5046         return HI_ERR_TDE_INVALID_PARA;
5047     }
5048 
5049     if (mb_src->mb_surface->mb_color_fmt >= HI_TDE_MB_COLOR_FMT_MAX) {
5050         tde_error("mb color format error!\n");
5051         return HI_ERR_TDE_INVALID_PARA;
5052     }
5053 
5054     if (((mb_opt->is_deflicker != HI_TRUE) && (mb_opt->is_deflicker != HI_FALSE)) ||
5055         ((mb_opt->is_set_out_alpha != HI_TRUE) && (mb_opt->is_set_out_alpha != HI_FALSE))) {
5056         tde_error("hi_bool should be HI_TRUE or HI_FALSE!!\n");
5057         return HI_ERR_TDE_INVALID_PARA;
5058     }
5059 
5060     if (mb_opt->resize_en >= HI_TDE_MB_RESIZE_MAX) {
5061         tde_error("enMBResize error!\n");
5062         return HI_ERR_TDE_INVALID_PARA;
5063     }
5064     return HI_SUCCESS;
5065 }
5066 #endif
5067 
5068 #ifdef  CONFIG_DRM_HISI_HISMART
tde_osi_pre_check_mb_drm_dumb(hi_tde_mb_surface * surface,hi_u32 size)5069 static hi_s32 tde_osi_pre_check_mb_drm_dumb(hi_tde_mb_surface *surface, hi_u32 size)
5070 {
5071     hi_s32 ret;
5072 
5073     ret = drm_check_dumb_phy_addr(surface->y_addr, size);
5074     if (ret != HI_SUCCESS) {
5075         return HI_ERR_TDE_INVALID_PARA;
5076     }
5077 
5078     if (surface->cbcr_phy_addr != 0) {
5079         size = surface->cbcr_stride * surface->y_height;
5080         if ((surface->mb_color_fmt == HI_TDE_MB_COLOR_FMT_JPG_YCBCR422MBVP)  ||
5081             (surface->mb_color_fmt == HI_TDE_MB_COLOR_FMT_MP1_YCBCR420MBP) ||
5082             (surface->mb_color_fmt == HI_TDE_MB_COLOR_FMT_MP2_YCBCR420MBP)   ||
5083             (surface->mb_color_fmt == HI_TDE_MB_COLOR_FMT_MP2_YCBCR420MBI) ||
5084             (surface->mb_color_fmt == HI_TDE_MB_COLOR_FMT_JPG_YCBCR420MBP)) {
5085             size = surface->cbcr_stride * (surface->y_height / 2); /* 2 half height */
5086         }
5087         ret = drm_check_dumb_phy_addr(surface->cbcr_phy_addr, size);
5088         if (ret != HI_SUCCESS) {
5089             return HI_ERR_TDE_INVALID_PARA;
5090         }
5091     }
5092     return HI_SUCCESS;
5093 }
5094 #endif
5095 
tde_osi_pre_check_mb_mmz(hi_tde_mb_surface * surface,hi_u32 size)5096 static hi_s32 tde_osi_pre_check_mb_mmz(hi_tde_mb_surface *surface, hi_u32 size)
5097 {
5098     hi_s32 ret;
5099 
5100 #ifdef  CONFIG_DRM_HISI_HISMART
5101     ret = tde_osi_pre_check_mb_drm_dumb(surface, size);
5102     if (ret == HI_SUCCESS) {
5103         return HI_SUCCESS;
5104     }
5105 #endif
5106     ret = cmpi_check_mmz_phy_addr(surface->y_addr, size);
5107     if (ret != HI_SUCCESS) {
5108         tde_error("Check MB surface phy_addr addr failed!\n");
5109         return HI_ERR_TDE_INVALID_PARA;
5110     }
5111 
5112     if (surface->cbcr_phy_addr != 0) {
5113         size = surface->cbcr_stride * surface->y_height;
5114         if ((surface->mb_color_fmt == HI_TDE_MB_COLOR_FMT_JPG_YCBCR422MBVP)  ||
5115             (surface->mb_color_fmt == HI_TDE_MB_COLOR_FMT_MP1_YCBCR420MBP) ||
5116             (surface->mb_color_fmt == HI_TDE_MB_COLOR_FMT_MP2_YCBCR420MBP)   ||
5117             (surface->mb_color_fmt == HI_TDE_MB_COLOR_FMT_MP2_YCBCR420MBI) ||
5118             (surface->mb_color_fmt == HI_TDE_MB_COLOR_FMT_JPG_YCBCR420MBP)) {
5119             size = surface->cbcr_stride * (surface->y_height / 2); /* 2 half height */
5120         }
5121         ret = cmpi_check_mmz_phy_addr(surface->cbcr_phy_addr, size);
5122         if (ret != HI_SUCCESS) {
5123             tde_error("Check MB surface cbcr_phy_addr addr failed!\n");
5124             return HI_ERR_TDE_INVALID_PARA;
5125         }
5126     }
5127     return HI_SUCCESS;
5128 }
5129 
tde_osi_check_mb_blit_para(hi_tde_mb_src * mb_src,hi_tde_mb_opt * mb_opt)5130 static hi_s32 tde_osi_check_mb_blit_para(hi_tde_mb_src *mb_src, hi_tde_mb_opt *mb_opt)
5131 {
5132     hi_u32 size;
5133     hi_s32 ret;
5134     hi_bool null_ptr = ((mb_src->mb_surface == HI_NULL) || ((mb_src->src_rect == HI_NULL)) ||
5135                         (mb_src->dst_surface == HI_NULL) || (mb_src->dst_rect == HI_NULL) || (mb_opt == HI_NULL));
5136 
5137     if (null_ptr) {
5138         tde_error("Contains HI_NULL ptr!\n");
5139         return HI_ERR_TDE_NULL_PTR;
5140     }
5141 
5142 #ifndef HI_BUILD_IN_BOOT
5143     ret = tde_osi_check_mb_src_opt(mb_src, mb_opt);
5144     if (ret != HI_SUCCESS) {
5145         return ret;
5146     }
5147     if ((tde_osi_check_surface_ex(mb_src->dst_surface, mb_src->dst_rect) != HI_SUCCESS) ||
5148         (tde_osi_check_mb_surface_ex(mb_src->mb_surface, mb_src->src_rect) != HI_SUCCESS)) {
5149         return HI_ERR_TDE_INVALID_PARA;
5150     }
5151     /* CMPI_CheckMmzphy_addr Call a semaphore, Cannot be used in the interrupt */
5152     if (!osal_in_interrupt()) {
5153         size = mb_src->mb_surface->y_stride * mb_src->mb_surface->y_height;
5154         ret = tde_osi_pre_check_mb_mmz(mb_src->mb_surface, size);
5155         if (ret != HI_SUCCESS) {
5156             return HI_ERR_TDE_INVALID_PARA;
5157         }
5158     }
5159 #endif
5160 
5161     return HI_SUCCESS;
5162 }
5163 
tde_osi_get_double_cycle_data(hi_tde_rect * mb_rect,hi_u32 * i,hi_u32 * j)5164 static hi_s32 tde_osi_get_double_cycle_data(hi_tde_rect *mb_rect, hi_u32 *i, hi_u32 *j)
5165 {
5166     if ((mb_rect->height > TDE_MAX_RECT_HEIGHT) && (mb_rect->width > TDE_MAX_RECT_WIDTH)) {
5167         *i = 2; /* 2 double cycle data */
5168         *j = 2; /* 2 double cycle data */
5169     } else if ((mb_rect->height > TDE_MAX_RECT_HEIGHT) && (mb_rect->width <= TDE_MAX_RECT_WIDTH)) {
5170         *i = 1;
5171         *j = 2; /* 2 double cycle data */
5172     } else if ((mb_rect->height <= TDE_MAX_RECT_HEIGHT) && (mb_rect->width > TDE_MAX_RECT_WIDTH)) {
5173         *i = 2; /* 2 double cycle data */
5174         *j = 1;
5175     } else {
5176         *i = 1;
5177         *j = 1;
5178     }
5179     return HI_SUCCESS;
5180 }
5181 
5182 #ifndef HI_BUILD_IN_BOOT
5183 
5184 /*
5185  * Function:      tde_osi_bitmap_mask_check_para
5186  * Description:   check for trinal source operate parameter
5187  * Return:        =0: success; <0: fail
5188  */
5189 #if (TDE_CAPABILITY & MASKROP || TDE_CAPABILITY & MASKBLEND)
tde_osi_bitmap_mask_check_triple_src(hi_tde_triple_src * triple_src)5190 static hi_s32 tde_osi_bitmap_mask_check_triple_src(hi_tde_triple_src *triple_src)
5191 {
5192     if (tde_osi_check_surface(triple_src->bg_surface, triple_src->bg_rect) != HI_SUCCESS) {
5193         tde_error("pstBackGroundRect does not correct!\n");
5194         return HI_ERR_TDE_INVALID_PARA;
5195     }
5196 
5197     if (tde_osi_check_surface(triple_src->fg_surface, triple_src->fg_rect) != HI_SUCCESS) {
5198         tde_error("pstForeGroundRect does not correct!\n");
5199         return HI_ERR_TDE_INVALID_PARA;
5200     }
5201 
5202     if (tde_osi_check_surface(triple_src->mask_surface, triple_src->mask_rect) != HI_SUCCESS) {
5203         tde_error("pstMaskRect does not correct!\n");
5204         return HI_ERR_TDE_INVALID_PARA;
5205     }
5206 
5207     if (tde_osi_check_surface(triple_src->dst_surface, triple_src->dst_rect) != HI_SUCCESS) {
5208         tde_error("dst_rect does not correct!\n");
5209         return HI_ERR_TDE_INVALID_PARA;
5210     }
5211     return HI_SUCCESS;
5212 }
5213 
tde_osi_bitmap_mask_check_para(hi_tde_triple_src * triple_src)5214 static hi_s32 tde_osi_bitmap_mask_check_para(hi_tde_triple_src *triple_src)
5215 {
5216     hi_bool is_unsupport_scale = HI_FALSE;
5217     hi_s32 ret;
5218     is_unsupport_scale = ((triple_src->bg_surface == HI_NULL) || (triple_src->bg_rect == HI_NULL) ||
5219         (triple_src->fg_surface == HI_NULL) || (triple_src->fg_rect == HI_NULL) ||
5220         (triple_src->mask_surface == HI_NULL) || (triple_src->mask_rect == HI_NULL) ||
5221         (triple_src->dst_surface == HI_NULL) || (triple_src->dst_rect == HI_NULL));
5222 
5223     if (is_unsupport_scale) {
5224         tde_error("Contains HI_NULL ptr!\n");
5225         return HI_ERR_TDE_NULL_PTR;
5226     }
5227 
5228     if ((triple_src->fg_surface->color_fmt >= HI_TDE_COLOR_FMT_JPG_YCBCR400MBP) ||
5229         (triple_src->bg_surface->color_fmt >= HI_TDE_COLOR_FMT_JPG_YCBCR400MBP) ||
5230         (triple_src->mask_surface->color_fmt >= HI_TDE_COLOR_FMT_JPG_YCBCR400MBP) ||
5231         (triple_src->dst_surface->color_fmt >= HI_TDE_COLOR_FMT_JPG_YCBCR400MBP)) {
5232         tde_error("This operation doesn't support Semi-plannar!\n");
5233         return HI_ERR_TDE_INVALID_PARA;
5234     }
5235 
5236 #if ((HICHIP == HI3519A_V100) || (HICHIP == HI3516C_V500))
5237     if ((triple_src->bg_surface->color_fmt == HI_TDE_COLOR_FMT_YCBCR422) ||
5238         (triple_src->bg_surface->color_fmt == HI_TDE_COLOR_FMT_PKGVYUY)) {
5239         tde_error("This operation doesn't support PKG!\n");
5240         return HI_ERR_TDE_INVALID_PARA;
5241     }
5242 #endif
5243 
5244     ret = tde_osi_bitmap_mask_check_triple_src(triple_src);
5245     if (ret != HI_SUCCESS) {
5246         return ret;
5247     }
5248 
5249     is_unsupport_scale = ((triple_src->bg_rect->width != triple_src->fg_rect->width) ||
5250                           (triple_src->fg_rect->width != triple_src->mask_rect->width) ||
5251                           (triple_src->mask_rect->width != triple_src->dst_rect->width) ||
5252                           (triple_src->bg_rect->height != triple_src->fg_rect->height) ||
5253                           (triple_src->fg_rect->height != triple_src->mask_rect->height) ||
5254                           (triple_src->mask_rect->height != triple_src->dst_rect->height));
5255 
5256     if (is_unsupport_scale) {
5257         tde_error("Don't support scale!\n");
5258         return HI_ERR_TDE_INVALID_PARA;
5259     }
5260 
5261     return HI_SUCCESS;
5262 }
5263 #endif
5264 
5265 /*
5266  * Function:      tde_osi_bitmap_mask_rop
5267  * Description:   Ropmask foreground and mask at firs, and then ropmask background and middle bitmap
5268  *                output result to target bitmap
5269  */
5270 #if (TDE_CAPABILITY & MASKROP)
tde_osi_bitmap_mask_rop_set_hw_node(tde_hw_node * hw_node,hi_tde_triple_src * triple_src,hi_tde_surface * mid_surface,hi_tde_rect * mid_rect)5271 static hi_s32 tde_osi_bitmap_mask_rop_set_hw_node(tde_hw_node *hw_node, hi_tde_triple_src *triple_src,
5272                                                   hi_tde_surface *mid_surface, hi_tde_rect *mid_rect)
5273 {
5274     tde_scandirection_mode scan_info = {0};
5275     tde_surface_msg src_drv_surface = {0};
5276     tde_surface_msg dst_drv_surface = {0};
5277 
5278     scan_info.h_scan = TDE_SCAN_LEFT_RIGHT;
5279     scan_info.v_scan = TDE_SCAN_UP_DOWN;
5280 
5281     tde_osi_convert_surface(triple_src->fg_surface, triple_src->fg_rect, &scan_info, &src_drv_surface);
5282 
5283     tde_hal_node_set_src1(hw_node, &src_drv_surface);
5284 
5285     tde_osi_convert_surface(triple_src->mask_surface, triple_src->mask_rect, &scan_info, &src_drv_surface);
5286 
5287     tde_hal_node_set_src2(hw_node, &src_drv_surface);
5288 
5289     if (memcpy_s(mid_surface, sizeof(hi_tde_surface), triple_src->fg_surface, sizeof(hi_tde_surface)) != EOK) {
5290         tde_error("secure function failure\n");
5291         return HI_ERR_TDE_INVALID_PARA;
5292     }
5293 
5294     mid_surface->phy_addr = tde_osi_list_get_phy_buff(0);
5295     if (mid_surface->phy_addr == 0) {
5296         tde_error("There is no temp buffer in tde_osi_bitmap_mask_rop!\n");
5297         return HI_ERR_TDE_NO_MEM;
5298     }
5299     mid_surface->clut_phy_addr = 0;
5300     mid_rect->pos_x = 0;
5301     mid_rect->pos_y = 0;
5302     mid_rect->height = triple_src->fg_rect->height;
5303     mid_rect->width = triple_src->fg_rect->width;
5304 
5305     tde_osi_convert_surface(mid_surface, mid_rect, &scan_info, &dst_drv_surface);
5306 
5307     tde_hal_node_set_tqt(hw_node, &dst_drv_surface, HI_TDE_OUT_ALPHA_FROM_NORM);
5308 
5309     tde_osi_set_ext_alpha(triple_src->fg_surface, mid_surface, hw_node);
5310 
5311     if (tde_hal_node_set_base_operate(hw_node, TDE_NORM_BLIT_2OPT, TDE_ALU_MASK_ROP1, 0) != HI_SUCCESS) {
5312         tde_hal_free_node_buf(hw_node);
5313         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
5314     }
5315     return HI_SUCCESS;
5316 }
5317 
tde_osi_bitmap_mask_rop_set_hw_node_pass2(tde_hw_node * hw_node_pass2,hi_tde_triple_src * triple_src,hi_tde_none_src * none_src,hi_tde_rop_mode rop_color,hi_tde_rop_mode rop_alpha)5318 static hi_s32 tde_osi_bitmap_mask_rop_set_hw_node_pass2(tde_hw_node *hw_node_pass2,
5319                                                         hi_tde_triple_src *triple_src,
5320                                                         hi_tde_none_src *none_src,
5321                                                         hi_tde_rop_mode rop_color, hi_tde_rop_mode rop_alpha)
5322 {
5323     tde_scandirection_mode scan_info = {0};
5324     tde_surface_msg src_drv_surface = {0};
5325     tde_surface_msg dst_drv_surface = {0};
5326     hi_u16 code;
5327     tde_conv_mode_cmd conv = {0};
5328 
5329     scan_info.h_scan = TDE_SCAN_LEFT_RIGHT;
5330     scan_info.v_scan = TDE_SCAN_UP_DOWN;
5331 
5332     tde_osi_convert_surface(triple_src->bg_surface, triple_src->bg_rect, &scan_info, &src_drv_surface);
5333 
5334     tde_hal_node_set_src1(hw_node_pass2, &src_drv_surface);
5335 
5336     tde_osi_convert_surface(none_src->dst_surface, none_src->dst_rect, &scan_info, &dst_drv_surface);
5337 
5338     tde_hal_node_set_src2(hw_node_pass2, &dst_drv_surface);
5339 
5340     tde_osi_convert_surface(triple_src->dst_surface, triple_src->dst_rect, &scan_info, &dst_drv_surface);
5341 
5342     tde_hal_node_set_tqt(hw_node_pass2, &dst_drv_surface, HI_TDE_OUT_ALPHA_FROM_NORM);
5343 
5344     code = tde_osi_single_src_to_get_opt_code(triple_src->fg_surface->color_fmt,
5345                                               triple_src->dst_surface->color_fmt);
5346 
5347     tde_osi_get_conv_by_code(code, &conv);
5348 
5349     if (tde_hal_node_set_color_convert(hw_node_pass2, &conv) != HI_SUCCESS) {
5350         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
5351     }
5352     if (tde_hal_node_set_rop(hw_node_pass2, rop_color, rop_alpha) != HI_SUCCESS) {
5353         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
5354     }
5355     tde_osi_set_ext_alpha(triple_src->bg_surface, none_src->dst_surface, hw_node_pass2);
5356 
5357     /* logical operation second passs */
5358     if (tde_hal_node_set_base_operate(hw_node_pass2, TDE_NORM_BLIT_2OPT, TDE_ALU_MASK_ROP2, 0) != HI_SUCCESS) {
5359         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
5360     }
5361     return HI_SUCCESS;
5362 }
5363 
tde_osi_bitmap_mask_rop_check_color(hi_tde_triple_src * triple_src)5364 static hi_s32 tde_osi_bitmap_mask_rop_check_color(hi_tde_triple_src *triple_src)
5365 {
5366     if (!tde_osi_whether_contain_alpha(triple_src->fg_surface->color_fmt)) {
5367         tde_error("ForeGround bitmap must contains alpha component!\n");
5368         return HI_ERR_TDE_INVALID_PARA;
5369     }
5370 
5371     if (triple_src->mask_surface->color_fmt != HI_TDE_COLOR_FMT_A1) {
5372         tde_error("Maskbitmap's colorformat can only be A1 in tde_osi_bitmap_mask_rop!\n");
5373         return HI_ERR_TDE_INVALID_PARA;
5374     }
5375     return HI_SUCCESS;
5376 }
5377 
tde_osi_bitmap_mask_rop(hi_s32 handle,hi_tde_triple_src * triple_src,hi_tde_rop_mode rop_color,hi_tde_rop_mode rop_alpha)5378 hi_s32 tde_osi_bitmap_mask_rop(hi_s32 handle, hi_tde_triple_src *triple_src, hi_tde_rop_mode rop_color,
5379                                hi_tde_rop_mode rop_alpha)
5380 {
5381     tde_hw_node *hw_node = HI_NULL;
5382     tde_hw_node *hw_node_pass2 = HI_NULL;
5383     hi_tde_surface mid_surface = {0};
5384     hi_tde_rect mid_rect = {0};
5385     hi_tde_none_src none_src = {&mid_surface, &mid_rect};
5386     hi_s32 ret;
5387 
5388     ret = tde_osi_bitmap_mask_check_para(triple_src);
5389     if (ret != HI_SUCCESS) {
5390         return ret;
5391     }
5392 
5393     if (tde_osi_bitmap_mask_rop_check_color(triple_src) != HI_SUCCESS) {
5394         return HI_ERR_TDE_INVALID_PARA;
5395     }
5396 
5397     /* init hw_node */
5398     if (tde_hal_node_init_nd(&hw_node) != HI_SUCCESS) {
5399         return HI_ERR_TDE_NO_MEM;
5400     }
5401     /*
5402      * set hw_node:
5403      * set src1
5404      * set src2
5405      * set tqt
5406      * set ext alpha
5407      * set opt
5408      * set global alpha
5409      */
5410     ret = tde_osi_bitmap_mask_rop_set_hw_node(hw_node, triple_src, &mid_surface, &mid_rect);
5411     if (ret != HI_SUCCESS) {
5412         return ret;
5413     }
5414 
5415     ret = tde_osi_set_node_finish(handle, hw_node, 0, TDE_NODE_SUBM_ALONE);
5416     if (ret != HI_SUCCESS) {
5417         tde_osi_list_put_phy_buff(1);
5418         tde_hal_free_node_buf(hw_node);
5419         return ret;
5420     }
5421     /* init hw_node_pass2 */
5422     if (tde_hal_node_init_nd(&hw_node_pass2) != HI_SUCCESS) {
5423         tde_osi_list_put_phy_buff(1);
5424         tde_hal_free_node_buf(hw_node);
5425         return HI_ERR_TDE_NO_MEM;
5426     }
5427 
5428     /*
5429      * set hw_node:
5430      * set src1
5431      * set src2
5432      * set tqt
5433      * set color convert
5434      * set rop
5435      * set ext alpha
5436      * set opt
5437      */
5438     ret = tde_osi_bitmap_mask_rop_set_hw_node_pass2(hw_node_pass2, triple_src, &none_src,
5439                                                     rop_color, rop_alpha);
5440     if (ret != HI_SUCCESS) {
5441         tde_hal_free_node_buf(hw_node);
5442         tde_hal_free_node_buf(hw_node_pass2);
5443         return ret;
5444     }
5445 
5446     ret = tde_osi_set_node_finish(handle, hw_node_pass2, 1, TDE_NODE_SUBM_ALONE);
5447     if (ret != HI_SUCCESS) {
5448         tde_hal_free_node_buf(hw_node);
5449         tde_hal_free_node_buf(hw_node_pass2);
5450         tde_osi_list_put_phy_buff(1);
5451         return ret;
5452     }
5453     return HI_SUCCESS;
5454 }
5455 
5456 #endif
5457 
5458 #if (TDE_CAPABILITY & MASKBLEND)
tde_osi_bitmap_mask_blend_set_hw_node(tde_hw_node * hw_node,hi_tde_triple_src * triple_src,hi_tde_surface * mid_surface,hi_tde_rect * mid_rect)5459 static hi_s32 tde_osi_bitmap_mask_blend_set_hw_node(tde_hw_node *hw_node, hi_tde_triple_src *triple_src,
5460                                                     hi_tde_surface *mid_surface, hi_tde_rect *mid_rect)
5461 {
5462     tde_scandirection_mode scan_info = {0};
5463     tde_surface_msg src_drv_surface = {0};
5464     tde_surface_msg dst_drv_surface = {0};
5465 
5466     scan_info.h_scan = TDE_SCAN_LEFT_RIGHT;
5467     scan_info.v_scan = TDE_SCAN_UP_DOWN;
5468 
5469     tde_osi_convert_surface(triple_src->fg_surface, triple_src->fg_rect, &scan_info, &src_drv_surface);
5470 
5471     tde_hal_node_set_src1(hw_node, &src_drv_surface);
5472 
5473     tde_osi_convert_surface(triple_src->mask_surface, triple_src->mask_rect, &scan_info, &src_drv_surface);
5474 
5475     tde_hal_node_set_src2(hw_node, &src_drv_surface);
5476 
5477     if (memcpy_s(mid_surface, sizeof(hi_tde_surface), triple_src->fg_surface, sizeof(hi_tde_surface)) != EOK) {
5478         tde_error("secure function failure\n");
5479         return HI_ERR_TDE_INVALID_PARA;
5480     }
5481 
5482     mid_surface->phy_addr = tde_osi_list_get_phy_buff(0);
5483     if (mid_surface->phy_addr == 0) {
5484         tde_error("There is no temp buffer in tde_osi_bitmap_mask_blend!\n");
5485         return HI_ERR_TDE_NO_MEM;
5486     }
5487     mid_rect->pos_x = 0;
5488     mid_rect->pos_y = 0;
5489     mid_rect->height = triple_src->fg_rect->height;
5490     mid_rect->width = triple_src->fg_rect->width;
5491 
5492     tde_osi_convert_surface(mid_surface, mid_rect, &scan_info, &dst_drv_surface);
5493 
5494     tde_hal_node_set_tqt(hw_node, &dst_drv_surface, HI_TDE_OUT_ALPHA_FROM_NORM);
5495 
5496     tde_osi_set_ext_alpha(triple_src->fg_surface, mid_surface, hw_node);
5497 
5498     if (tde_hal_node_set_base_operate(hw_node, TDE_NORM_BLIT_2OPT, TDE_ALU_MASK_BLEND, 0) != HI_SUCCESS) {
5499         tde_hal_free_node_buf(hw_node);
5500         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
5501     }
5502 
5503     tde_hal_node_set_global_alpha(hw_node, 0xff, HI_TRUE);
5504     return HI_SUCCESS;
5505 }
5506 
tde_osi_bitmap_mask_blend_set_hw_node_pass2(tde_hw_node * hw_node_pass2,hi_tde_triple_src * triple_src,hi_tde_surface * mid_surface,hi_tde_rect * mid_rect,hi_u8 alpha)5507 static hi_s32 tde_osi_bitmap_mask_blend_set_hw_node_pass2(tde_hw_node *hw_node_pass2,
5508                                                           hi_tde_triple_src *triple_src,
5509                                                           hi_tde_surface *mid_surface, hi_tde_rect *mid_rect,
5510                                                           hi_u8 alpha)
5511 {
5512     tde_scandirection_mode scan_info = {0};
5513     tde_surface_msg src_drv_surface = {0};
5514     tde_surface_msg dst_drv_surface = {0};
5515     hi_u16 code;
5516     tde_conv_mode_cmd conv = {0};
5517     tde_alu_mode drv_alu_mode = TDE_ALU_BLEND;
5518     hi_tde_blend_opt blend_opt = {0};
5519 
5520     scan_info.h_scan = TDE_SCAN_LEFT_RIGHT;
5521     scan_info.v_scan = TDE_SCAN_UP_DOWN;
5522     tde_osi_convert_surface(triple_src->bg_surface, triple_src->bg_rect, &scan_info, &src_drv_surface);
5523 
5524     tde_hal_node_set_src1(hw_node_pass2, &src_drv_surface);
5525 
5526     tde_osi_convert_surface(mid_surface, mid_rect, &scan_info, &dst_drv_surface);
5527 
5528     tde_hal_node_set_src2(hw_node_pass2, &dst_drv_surface);
5529 
5530     tde_osi_convert_surface(triple_src->dst_surface, triple_src->dst_rect, &scan_info, &dst_drv_surface);
5531 
5532     tde_hal_node_set_tqt(hw_node_pass2, &dst_drv_surface, HI_TDE_OUT_ALPHA_FROM_NORM);
5533 
5534     code = tde_osi_single_src_to_get_opt_code(triple_src->fg_surface->color_fmt, triple_src->dst_surface->color_fmt);
5535 
5536     tde_osi_get_conv_by_code(code, &conv);
5537 
5538     if (tde_hal_node_set_color_convert(hw_node_pass2, &conv) != HI_SUCCESS) {
5539         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
5540     }
5541 
5542     tde_hal_node_set_global_alpha(hw_node_pass2, alpha, HI_TRUE);
5543 
5544     if (tde_hal_node_set_base_operate(hw_node_pass2, TDE_NORM_BLIT_2OPT, drv_alu_mode, 0) != HI_SUCCESS) {
5545         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
5546     }
5547 
5548     blend_opt.global_alpha_en = HI_TRUE;
5549     blend_opt.pixel_alpha_en = HI_TRUE;
5550     blend_opt.blend_cmd = HI_TDE_BLEND_CMD_NONE;
5551     if (tde_hal_node_set_blend(hw_node_pass2, &blend_opt) != HI_SUCCESS) {
5552         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
5553     }
5554 
5555     tde_osi_set_ext_alpha(triple_src->bg_surface, mid_surface, hw_node_pass2);
5556     return HI_SUCCESS;
5557 }
5558 
tde_osi_bitmap_mask_blend_check_color(hi_tde_triple_src * triple_src,hi_tde_alpha_blending blend_mode)5559 static hi_s32 tde_osi_bitmap_mask_blend_check_color(hi_tde_triple_src *triple_src,
5560                                                     hi_tde_alpha_blending blend_mode)
5561 {
5562     if ((triple_src->mask_surface->color_fmt != HI_TDE_COLOR_FMT_A1) &&
5563         (triple_src->mask_surface->color_fmt != HI_TDE_COLOR_FMT_A8)) {
5564         tde_error("Maskbitmap's colorformat can only be An in tde_osi_bitmap_mask_blend!\n");
5565         return HI_ERR_TDE_INVALID_PARA;
5566     }
5567 
5568     if (blend_mode != HI_TDE_ALPHA_BLENDING_BLEND) {
5569         tde_error("Alum mode can only be blending in tde_osi_bitmap_mask_blend!\n");
5570         return HI_ERR_TDE_INVALID_PARA;
5571     }
5572     return HI_SUCCESS;
5573 }
5574 
tde_osi_bitmap_mask_blend(hi_s32 handle,hi_tde_triple_src * triple_src,hi_u8 alpha,hi_tde_alpha_blending blend_mode)5575 hi_s32 tde_osi_bitmap_mask_blend(hi_s32 handle, hi_tde_triple_src *triple_src, hi_u8 alpha,
5576                                  hi_tde_alpha_blending blend_mode)
5577 {
5578     tde_hw_node *hw_node = HI_NULL;
5579     tde_hw_node *hw_node_pass2 = HI_NULL;
5580     hi_tde_surface mid_surface = {0};
5581     hi_tde_rect mid_rect = {0};
5582     hi_s32 ret;
5583 
5584     ret = tde_osi_bitmap_mask_check_para(triple_src);
5585     if (ret != HI_SUCCESS) {
5586         return ret;
5587     }
5588     /* check color format and blend mode */
5589     if (tde_osi_bitmap_mask_blend_check_color(triple_src, blend_mode) != HI_SUCCESS) {
5590         return HI_ERR_TDE_INVALID_PARA;
5591     }
5592 
5593     /* init hw_node */
5594     if (tde_hal_node_init_nd(&hw_node) != HI_SUCCESS) {
5595         return HI_ERR_TDE_NO_MEM;
5596     }
5597 
5598     /*
5599      * set hw_node:
5600      * set src1
5601      * set src2
5602      * set tqt
5603      * set ext alpha
5604      * set opt
5605      * set global alpha
5606      */
5607     ret = tde_osi_bitmap_mask_blend_set_hw_node(hw_node, triple_src, &mid_surface, &mid_rect);
5608     if (ret != HI_SUCCESS) {
5609         return ret;
5610     }
5611 
5612     ret = tde_osi_set_node_finish(handle, hw_node, 0, TDE_NODE_SUBM_ALONE);
5613     if (ret != HI_SUCCESS) {
5614         tde_osi_list_put_phy_buff(1);
5615         tde_hal_free_node_buf(hw_node);
5616         return ret;
5617     }
5618 
5619     /* init hw_node_pass2 */
5620     if (tde_hal_node_init_nd(&hw_node_pass2) != HI_SUCCESS) {
5621         tde_osi_list_put_phy_buff(1);
5622         tde_hal_free_node_buf(hw_node);
5623         return HI_ERR_TDE_NO_MEM;
5624     }
5625 
5626     /*
5627      * set hw_node_pass2:
5628      * set src1
5629      * set src2
5630      * set tqt
5631      * set color convert
5632      * set global alpha
5633      * set opt
5634      * set blend
5635      * set ext alpha
5636      */
5637     ret = tde_osi_bitmap_mask_blend_set_hw_node_pass2(hw_node_pass2, triple_src, &mid_surface, &mid_rect,
5638                                                       alpha);
5639     if (ret != HI_SUCCESS) {
5640         tde_hal_free_node_buf(hw_node);
5641         tde_hal_free_node_buf(hw_node_pass2);
5642         return ret;
5643     }
5644 
5645     ret = tde_osi_set_node_finish(handle, hw_node_pass2, 1, TDE_NODE_SUBM_ALONE);
5646     if (ret != HI_SUCCESS) {
5647         tde_hal_free_node_buf(hw_node);
5648         tde_hal_free_node_buf(hw_node_pass2);
5649         tde_osi_list_put_phy_buff(1);
5650         return ret;
5651     }
5652 
5653     return HI_SUCCESS;
5654 }
5655 #endif
5656 
5657 /*
5658  * Function:      tde_osi_solid_draw
5659  * Description:   operate src1 with src2, which result to dst_surface,operate setting is in pstOpt
5660  *                if src is MB, only support single source operate,
5661                   just to say to only support pstBackGround or pstForeGround
5662  * Input:         handle: task handle
5663  *                fill_color:  fill  color
5664  *                opt: operate parameter setting struct
5665  * Return:        HI_SUCCESS/HI_FAILURE
5666  */
tde_osi_solid_draw(hi_s32 handle,hi_tde_single_src * single_src,hi_tde_fill_color * fill_color,hi_tde_opt * opt)5667 hi_s32 tde_osi_solid_draw(hi_s32 handle, hi_tde_single_src *single_src, hi_tde_fill_color *fill_color,
5668                           hi_tde_opt *opt)
5669 {
5670     if (single_src->src_surface == HI_NULL) {
5671         return tde_osi_1_source_fill(handle, single_src->dst_surface, single_src->dst_rect, fill_color, opt);
5672     } else {
5673         if ((single_src->dst_surface == HI_NULL) || (fill_color == HI_NULL)) {
5674             return HI_ERR_TDE_NULL_PTR;
5675         }
5676 
5677         if ((single_src->src_surface->color_fmt >= HI_TDE_COLOR_FMT_JPG_YCBCR400MBP) ||
5678             (single_src->dst_surface->color_fmt >= HI_TDE_COLOR_FMT_JPG_YCBCR400MBP) ||
5679             (fill_color->color_fmt >= HI_TDE_COLOR_FMT_JPG_YCBCR400MBP)) {
5680             tde_error("This operation doesn't support Semi-plannar!\n");
5681             return HI_ERR_TDE_INVALID_PARA;
5682         }
5683         return tde_osi_2_source_fill(handle, single_src, fill_color, opt);
5684     }
5685 }
5686 
5687 #if (TDE_CAPABILITY & DEFLICKER)
tde_osi_set_deflicker_level(hi_tde_deflicker_level deflicker_level)5688 hi_s32 tde_osi_set_deflicker_level(hi_tde_deflicker_level deflicker_level)
5689 {
5690     return tde_hal_set_deflicer_level(deflicker_level);
5691 }
5692 
tde_osi_get_deflicker_level(hi_tde_deflicker_level * deflicker_level)5693 hi_s32 tde_osi_get_deflicker_level(hi_tde_deflicker_level *deflicker_level)
5694 {
5695     if (deflicker_level == HI_NULL) {
5696         return HI_FAILURE;
5697     }
5698     return tde_hal_get_deflicer_level(deflicker_level);
5699 }
5700 #endif
5701 
5702 #endif
5703 
tde_osi_set_alpha_threshold_value(hi_u8 alpha_threshold_value)5704 hi_s32 tde_osi_set_alpha_threshold_value(hi_u8 alpha_threshold_value)
5705 {
5706     return tde_hal_set_alpha_threshold(alpha_threshold_value);
5707 }
5708 #ifndef HI_BUILD_IN_BOOT
5709 #endif
5710 
tde_osi_set_alpha_threshold_state(hi_bool alpha_threshold_en)5711 hi_s32 tde_osi_set_alpha_threshold_state(hi_bool alpha_threshold_en)
5712 {
5713     return tde_hal_set_alpha_threshold_state(alpha_threshold_en);
5714 }
5715 
5716 #ifndef HI_BUILD_IN_BOOT
5717 
tde_osi_get_alpha_threshold_value(hi_u8 * alpha_threshold_value)5718 hi_s32 tde_osi_get_alpha_threshold_value(hi_u8 *alpha_threshold_value)
5719 {
5720     if (alpha_threshold_value == HI_NULL) {
5721         return HI_FAILURE;
5722     }
5723     return tde_hal_get_alpha_threshold(alpha_threshold_value);
5724 }
5725 
tde_osi_get_alpha_threshold_state(hi_bool * alpha_threshold_en)5726 hi_s32 tde_osi_get_alpha_threshold_state(hi_bool *alpha_threshold_en)
5727 {
5728     if (alpha_threshold_en == HI_NULL) {
5729         return HI_FAILURE;
5730     }
5731 
5732     return tde_hal_get_alpha_threshold_state(alpha_threshold_en);
5733 }
5734 
tde_osi_check_src_pattern_fill_opt(hi_tde_pattern_fill_opt * opt)5735 static hi_s32 tde_osi_check_src_pattern_fill_opt(hi_tde_pattern_fill_opt *opt)
5736 {
5737     if (opt == HI_NULL) {
5738         return HI_FAILURE;
5739     }
5740 
5741     if ((opt->color_key_mode >= HI_TDE_COLOR_KEY_MODE_MAX) ||
5742         (opt->color_key_mode < HI_TDE_COLOR_KEY_MODE_NONE)) {
5743         tde_error("color_key_mode error!\n");
5744         return HI_ERR_TDE_INVALID_PARA;
5745     }
5746 
5747     if (((opt->clut_reload != HI_TRUE) && (opt->clut_reload != HI_FALSE)) ||
5748         ((opt->blend_opt.global_alpha_en != HI_TRUE) && (opt->blend_opt.global_alpha_en != HI_FALSE)) ||
5749         ((opt->blend_opt.pixel_alpha_en != HI_TRUE) && (opt->blend_opt.pixel_alpha_en != HI_FALSE)) ||
5750         ((opt->blend_opt.src1_alpha_premulti != HI_TRUE) && (opt->blend_opt.src1_alpha_premulti != HI_FALSE)) ||
5751         ((opt->blend_opt.src2_alpha_premulti != HI_TRUE) && (opt->blend_opt.src2_alpha_premulti != HI_FALSE))) {
5752         tde_error("hi_bool should be HI_TRUE or HI_FALSE!!\n");
5753         return HI_ERR_TDE_INVALID_PARA;
5754     }
5755 
5756     if (opt->color_key_mode != HI_TDE_COLOR_KEY_MODE_NONE) {
5757         tde_error("It doesn't support colorkey in single source pattern mode!\n");
5758         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
5759     }
5760 
5761     if (opt->alpha_blending_cmd >= HI_TDE_ALPHA_BLENDING_MAX) {
5762         tde_error("alpha_blending_cmd error!\n");
5763         return HI_ERR_TDE_INVALID_PARA;
5764     }
5765     return HI_SUCCESS;
5766 }
5767 
5768 /*
5769  * Function:      tde_osi_check_single_src_pattern_opt
5770  * Description:   check if single source mode fill operate is valid
5771  * Input:         src_fmt foreground pixel format
5772                   dst_fmt  target pixel format
5773                   opt    operate attribute pointer
5774  * Return:        0  valid parameter
5775                   -1 invalid parameter
5776  */
tde_osi_check_single_src_pattern_opt(hi_tde_color_fmt src_fmt,hi_tde_color_fmt dst_fmt,hi_tde_pattern_fill_opt * opt)5777 hi_s32 tde_osi_check_single_src_pattern_opt(hi_tde_color_fmt src_fmt,
5778                                             hi_tde_color_fmt dst_fmt, hi_tde_pattern_fill_opt *opt)
5779 {
5780     hi_s32 ret;
5781     tde_colorfmt_transform color_trans_type = tde_osi_get_fmt_trans_type(src_fmt, dst_fmt);
5782     if (color_trans_type == TDE_COLORFMT_TRANSFORM_BUTT) {
5783         tde_error("Unknown color transport type!\n");
5784         return HI_ERR_TDE_INVALID_PARA;
5785     }
5786 
5787     ret = tde_osi_check_src_pattern_fill_opt(opt);
5788     if (ret != HI_SUCCESS) {
5789         if (ret == HI_FAILURE) {
5790             return HI_SUCCESS;
5791         }
5792         return ret;
5793     }
5794 #if (TDE_CAPABILITY & ROP)
5795     if ((hi_u32)opt->alpha_blending_cmd & HI_TDE_ALPHA_BLENDING_ROP) {
5796         if ((!tde_osi_is_single_src_to_rop(opt->rop_alpha)) ||
5797             (!tde_osi_is_single_src_to_rop(opt->rop_color))) {
5798             tde_error("Only support single s2 rop!\n");
5799             return HI_ERR_TDE_INVALID_PARA;
5800         }
5801     } else
5802 #endif
5803         if (opt->alpha_blending_cmd != HI_TDE_ALPHA_BLENDING_NONE) {
5804             tde_error("Alu mode error!\n");
5805             return HI_ERR_TDE_INVALID_PARA;
5806         }
5807 
5808     if (color_trans_type != TDE_COLORFMT_TRANSFORM_CLUT_CLUT) {
5809         return HI_SUCCESS;
5810     }
5811 
5812     if ((opt->alpha_blending_cmd != HI_TDE_ALPHA_BLENDING_NONE)) {
5813         tde_error("It doesn't ROP/Blend/Colorize!\n");
5814         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
5815     }
5816 
5817     if (src_fmt != dst_fmt) {
5818         tde_error("If src fmt and dst fmt are clut, they shoulod be the same fmt!\n");
5819         return HI_ERR_TDE_INVALID_PARA;
5820     }
5821 
5822     return HI_SUCCESS;
5823 }
5824 
tde_osi_check_bool_opt(hi_tde_color_fmt back_ground_fmt,hi_tde_pattern_fill_opt * opt)5825 static hi_s32 tde_osi_check_bool_opt(hi_tde_color_fmt back_ground_fmt, hi_tde_pattern_fill_opt *opt)
5826 {
5827     hi_bool real = (((opt->clut_reload != HI_TRUE) && (opt->clut_reload != HI_FALSE)) ||
5828         ((opt->blend_opt.global_alpha_en != HI_TRUE) && (opt->blend_opt.global_alpha_en != HI_FALSE)) ||
5829         ((opt->blend_opt.pixel_alpha_en != HI_TRUE) && (opt->blend_opt.pixel_alpha_en != HI_FALSE)) ||
5830         ((opt->blend_opt.src1_alpha_premulti != HI_TRUE) && (opt->blend_opt.src1_alpha_premulti != HI_FALSE)) ||
5831         ((opt->blend_opt.src2_alpha_premulti != HI_TRUE) && (opt->blend_opt.src2_alpha_premulti != HI_FALSE)));
5832 
5833     if (opt->alpha_blending_cmd >= HI_TDE_ALPHA_BLENDING_MAX) {
5834         tde_error("alpha_blending_cmd error!\n");
5835         return HI_ERR_TDE_INVALID_PARA;
5836     }
5837 
5838 #if ((HICHIP == HI3519A_V100) || (HICHIP == HI3516C_V500))
5839     if ((back_ground_fmt == HI_TDE_COLOR_FMT_YCBCR422) || (back_ground_fmt == HI_TDE_COLOR_FMT_PKGVYUY)) {
5840         tde_error("This operation doesn't support PKG!\n");
5841         return HI_ERR_TDE_INVALID_PARA;
5842     }
5843 #else
5844     hi_unused(back_ground_fmt);
5845 #endif
5846 
5847     if (real) {
5848         tde_error("hi_bool should be HI_TRUE or HI_FALSE!!\n");
5849         return HI_ERR_TDE_INVALID_PARA;
5850     }
5851 
5852     if ((opt->color_key_mode >= HI_TDE_COLOR_KEY_MODE_MAX) ||
5853         (opt->color_key_mode < HI_TDE_COLOR_KEY_MODE_NONE)) {
5854         tde_error("color_key_mode error!\n");
5855         return HI_ERR_TDE_INVALID_PARA;
5856     }
5857 
5858     if (opt->out_alpha_from >= HI_TDE_OUT_ALPHA_FROM_MAX) {
5859         tde_error("out_alpha_from error!\n");
5860         return HI_ERR_TDE_INVALID_PARA;
5861     }
5862     return HI_SUCCESS;
5863 }
5864 
5865 /*
5866  * Function:      tde_osi_check_double_src_pattern_opt
5867  * Description:   check if doul source mode fill operate parameter is valid
5868  * Input:         back_ground_fmt background pixel format
5869                   fore_ground_fmt foreground pixel format
5870                   dst_fmt  target pixel format
5871                   opt     operate attribute pointer
5872  * Return:        0  valid parameter
5873                   -1 invalid parameter
5874  */
tde_osi_check_double_src_pattern_opt(hi_tde_color_fmt back_ground_fmt,hi_tde_color_fmt fore_ground_fmt,hi_tde_color_fmt dst_fmt,hi_tde_pattern_fill_opt * opt)5875 hi_s32 tde_osi_check_double_src_pattern_opt(hi_tde_color_fmt back_ground_fmt, hi_tde_color_fmt fore_ground_fmt,
5876                                             hi_tde_color_fmt dst_fmt, hi_tde_pattern_fill_opt *opt)
5877 {
5878     tde_colorfmt_category bg_category, fg_category, dst_category;
5879     hi_bool temp_fmt = HI_FALSE;
5880 
5881     hi_s32 ret = tde_osi_check_bool_opt(back_ground_fmt, opt);
5882     if (ret != HI_SUCCESS) {
5883         return ret;
5884     }
5885     bg_category = tde_osi_get_fmt_category(back_ground_fmt);
5886 
5887     fg_category = tde_osi_get_fmt_category(fore_ground_fmt);
5888 
5889     dst_category = tde_osi_get_fmt_category(dst_fmt);
5890     if ((bg_category >= TDE_COLORFMT_CATEGORY_BYTE) ||
5891         (fg_category >= TDE_COLORFMT_CATEGORY_BYTE) || (dst_category >= TDE_COLORFMT_CATEGORY_BYTE)) {
5892         tde_error("unknown format!\n");
5893         return HI_ERR_TDE_INVALID_PARA;
5894     }
5895     temp_fmt = tde_osi_whether_contain_alpha(dst_fmt);
5896     if ((bg_category == TDE_COLORFMT_CATEGORY_ARGB) &&
5897         (fg_category == TDE_COLORFMT_CATEGORY_AN) && (!temp_fmt)) {
5898         tde_error("Target must have alpha component!\n");
5899         return HI_ERR_TDE_INVALID_PARA;
5900     } else if ((fg_category == TDE_COLORFMT_CATEGORY_AN) && ((back_ground_fmt == HI_TDE_COLOR_FMT_YCBCR888) ||
5901         (fore_ground_fmt == HI_TDE_COLOR_FMT_AYCBCR8888))) {
5902         tde_error("Target must have alpha component!\n");
5903         return HI_ERR_TDE_INVALID_PARA;
5904     } else if ((bg_category == TDE_COLORFMT_CATEGORY_CLUT) && (
5905         opt->alpha_blending_cmd != HI_TDE_ALPHA_BLENDING_NONE)) {
5906         tde_error("It doesn't support ROP!\n");
5907         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
5908     } else if ((bg_category == TDE_COLORFMT_CATEGORY_CLUT) &&
5909         ((back_ground_fmt != fore_ground_fmt) || (back_ground_fmt != dst_fmt))) {
5910         tde_error("If background, foreground , dst are clut, they should be the same fmt!\n");
5911         return HI_ERR_TDE_INVALID_PARA;
5912     } else if ((bg_category == TDE_COLORFMT_CATEGORY_CLUT) &&
5913         ((fg_category != TDE_COLORFMT_CATEGORY_CLUT) || (dst_category != TDE_COLORFMT_CATEGORY_CLUT))) {
5914         tde_error("Unsupported operation!\n");
5915         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
5916     } else if ((bg_category == TDE_COLORFMT_CATEGORY_AN) && (fg_category == TDE_COLORFMT_CATEGORY_AN) &&
5917         (dst_category == TDE_COLORFMT_CATEGORY_AN) && (opt->alpha_blending_cmd != HI_TDE_ALPHA_BLENDING_NONE)) {
5918         tde_error("It doesn't support ROP or mirror!\n");
5919         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
5920     } else if ((dst_category == TDE_COLORFMT_CATEGORY_CLUT) && ((fg_category != TDE_COLORFMT_CATEGORY_CLUT) ||
5921         (bg_category != TDE_COLORFMT_CATEGORY_CLUT))) {
5922         tde_error("Unsupported operation!\n");
5923         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
5924     }
5925     return HI_SUCCESS;
5926 }
5927 
5928 /*
5929  * Function:      tde_osi_get_pattern_opt_category
5930  * Description:   analyze pattern fill operate type
5931  * Input:         dst_surface: target bitmap info
5932  *                dst_rect: target bitmap operate zone
5933  *                opt: operate option
5934  * Return:        TDE operate type
5935  */
tde_osi_get_pattern_opt_category(hi_tde_double_src * double_src,hi_tde_pattern_fill_opt * opt)5936 tde_pattern_operation_category tde_osi_get_pattern_opt_category(hi_tde_double_src *double_src,
5937                                                                 hi_tde_pattern_fill_opt *opt)
5938 {
5939     if ((double_src == HI_NULL) || (double_src->dst_surface == HI_NULL) || (double_src->dst_rect == HI_NULL)) {
5940         tde_error("Dst/Dst Rect should not be null!\n");
5941         return TDE_PATTERN_OPERATION_BUTT;
5942     }
5943     if ((HI_TDE_COLOR_FMT_YCBCR422 == double_src->dst_surface->color_fmt) ||
5944         (double_src->dst_surface->color_fmt == HI_TDE_COLOR_FMT_PKGVYUY)) {
5945         tde_error("It doesn't support YCbCr422 in pattern fill!\n");
5946         return -1;
5947     }
5948 
5949     if (double_src->dst_surface->color_fmt >= HI_TDE_COLOR_FMT_JPG_YCBCR400MBP) {
5950         tde_error("This operation doesn't support Semi-plannar!\n");
5951         return HI_ERR_TDE_INVALID_PARA;
5952     }
5953 
5954     if (tde_osi_check_surface(double_src->dst_surface, double_src->dst_rect) != HI_SUCCESS) {
5955         return TDE_PATTERN_OPERATION_BUTT;
5956     }
5957 
5958     if ((double_src->bg_surface == HI_NULL) && (double_src->fg_surface == HI_NULL)) {
5959         tde_error("No src!\n");
5960         return TDE_PATTERN_OPERATION_BUTT;
5961     } else if ((double_src->bg_surface != HI_NULL) && (double_src->fg_surface != HI_NULL)) {
5962         return tde_osi_double_src_pattern_operation(double_src, opt);
5963     } else {
5964         return tde_osi_check_single_src_pattern_operation(double_src, opt);
5965     }
5966 }
5967 
tde_osi_check_single_src_pattern_operation(hi_tde_double_src * double_src,hi_tde_pattern_fill_opt * opt)5968 static tde_pattern_operation_category tde_osi_check_single_src_pattern_operation(hi_tde_double_src *double_src,
5969                                                                                  hi_tde_pattern_fill_opt *opt)
5970 {
5971     hi_tde_surface *tmp_src2 = HI_NULL;
5972     hi_tde_rect *tmp_src2_rect = HI_NULL;
5973     hi_unused(opt);
5974     if (double_src->bg_surface != HI_NULL) {
5975         if (double_src->bg_rect == HI_NULL) {
5976             tde_error("Background rect shouldn't be HI_NULL!\n");
5977             return TDE_PATTERN_OPERATION_BUTT;
5978         }
5979         tmp_src2 = double_src->bg_surface;
5980         tmp_src2_rect = double_src->bg_rect;
5981     } else if (double_src->fg_surface != HI_NULL) {
5982         if (double_src->fg_rect == HI_NULL) {
5983             tde_error("Foreground rect shouldn't be HI_NULL!\n");
5984             return TDE_PATTERN_OPERATION_BUTT;
5985         }
5986         if (double_src->fg_surface->color_fmt == HI_TDE_COLOR_FMT_YCBCR422) {
5987             tde_error("It doesn't support YCbCr422 in pattern fill!\n");
5988             return TDE_PATTERN_OPERATION_BUTT;
5989         }
5990         tmp_src2 = double_src->fg_surface;
5991         tmp_src2_rect = double_src->fg_rect;
5992     }
5993 
5994     if ((tmp_src2 != HI_NULL) && (tmp_src2_rect != HI_NULL)) {
5995         if (tmp_src2->color_fmt >= HI_TDE_COLOR_FMT_JPG_YCBCR400MBP) {
5996             tde_error("This operation doesn't support Semi-plannar!\n");
5997             return HI_ERR_TDE_INVALID_PARA;
5998         }
5999 
6000         if (tmp_src2_rect->width > TDE_MAX_PATTERNWIDTH) {
6001             tde_error("Max pattern width is 256!\n");
6002             return TDE_PATTERN_OPERATION_BUTT;
6003         }
6004         if (tde_osi_check_surface(tmp_src2, tmp_src2_rect) != HI_SUCCESS) {
6005             return TDE_PATTERN_OPERATION_BUTT;
6006         }
6007     }
6008 
6009     return TDE_PATTERN_OPERATION_SINGLE_SRC;
6010 }
6011 
tde_osi_double_src_pattern_operation(hi_tde_double_src * double_src,hi_tde_pattern_fill_opt * opt)6012 static tde_pattern_operation_category tde_osi_double_src_pattern_operation(hi_tde_double_src *double_src,
6013                                                                            hi_tde_pattern_fill_opt *opt)
6014 {
6015     if ((double_src->bg_rect == HI_NULL) || (double_src->fg_rect == HI_NULL) || (opt == HI_NULL)) {
6016         tde_error("Background Rect/Foreground Rect/Opt should not be null in two src pattern fill!\n");
6017         return TDE_PATTERN_OPERATION_BUTT;
6018     }
6019 
6020     if ((double_src->bg_surface->color_fmt >= HI_TDE_COLOR_FMT_JPG_YCBCR400MBP) ||
6021         (double_src->fg_surface->color_fmt >= HI_TDE_COLOR_FMT_JPG_YCBCR400MBP)) {
6022         tde_error("This operation doesn't support Semi-plannar!\n");
6023         return HI_ERR_TDE_INVALID_PARA;
6024     }
6025 
6026     if ((double_src->fg_surface->color_fmt == HI_TDE_COLOR_FMT_YCBCR422) ||
6027         (double_src->fg_surface->color_fmt == HI_TDE_COLOR_FMT_PKGVYUY)) {
6028         tde_error("It doesn't support YCbCr422 in pattern fill!\n");
6029         return TDE_PATTERN_OPERATION_BUTT;
6030     }
6031 
6032     if ((tde_osi_check_surface(double_src->bg_surface, double_src->bg_rect) != HI_SUCCESS) ||
6033         (tde_osi_check_surface(double_src->fg_surface, double_src->fg_rect) != HI_SUCCESS)) {
6034         return TDE_PATTERN_OPERATION_BUTT;
6035     }
6036 
6037     if ((double_src->bg_rect->height != double_src->dst_rect->height) ||
6038         (double_src->bg_rect->width != double_src->dst_rect->width)) {
6039         tde_error("Size of background rect and Dst rect should be the same in two src pattern fill.\n");
6040         tde_error("background x:%d, y:%d, w:%d, h:%d; dst x:%d, y:%d, w:%d, h:%d\n", double_src->bg_rect->pos_x,
6041             double_src->bg_rect->pos_y, double_src->bg_rect->width, double_src->bg_rect->height,
6042             double_src->dst_rect->pos_x, double_src->dst_rect->pos_y, double_src->dst_rect->width,
6043             double_src->dst_rect->height);
6044         return TDE_PATTERN_OPERATION_BUTT;
6045     }
6046 
6047     if (double_src->fg_rect->width > TDE_MAX_PATTERNWIDTH) {
6048         tde_error("Max pattern width is 256!\n");
6049         return TDE_PATTERN_OPERATION_BUTT;
6050     }
6051 
6052     return TDE_PATTERN_OPERATION_DOUBLE_SRC;
6053 }
6054 
tde_osi_check_overlap(hi_tde_surface * sur1,hi_tde_rect * rect1,hi_tde_surface * sur2,hi_tde_rect * rect2)6055 hi_bool tde_osi_check_overlap(hi_tde_surface *sur1, hi_tde_rect *rect1, hi_tde_surface *sur2,
6056                               hi_tde_rect *rect2)
6057 {
6058     hi_u32 rect1_start_phy;
6059     hi_u32 rect1_end_phy;
6060     hi_u32 rect2_start_phy;
6061     hi_u32 rect2_end_phy;
6062     hi_u32 bpp1;
6063     hi_u32 bpp2;
6064 
6065     if (rect2->height < rect1->height) {
6066         rect1->height = rect2->height;
6067     }
6068 
6069     if (rect2->width < rect1->width) {
6070         rect1->width = rect2->width;
6071     }
6072 
6073     bpp1 = tde_osi_get_bpp_by_fmt(sur1->color_fmt) / 8; /* 8 matrixing bpp */
6074     bpp2 = tde_osi_get_bpp_by_fmt(sur2->color_fmt) / 8; /* 8 matrixing bpp */
6075 
6076     rect1_start_phy = sur1->phy_addr + (rect1->pos_y * sur1->stride)  +
6077         rect1->pos_x * bpp1;
6078     rect1_end_phy = rect1_start_phy + (rect1->height - 1) * sur1->stride  +
6079         (rect1->width - 1) * bpp1;
6080 
6081     rect2_start_phy = sur2->phy_addr + (rect2->pos_y * sur2->stride)  +
6082         rect2->pos_x * bpp2;
6083     rect2_end_phy = rect2_start_phy + (rect2->height - 1) * sur2->stride  +
6084         (rect2->width - 1) * bpp2;
6085 
6086     tde_info("u32Rect1StartPhy:%x, u32Rect1EndPhy:%x, u32Rect2StartPhy:%x, u32Rect2EndPhy:%x\n", rect1_start_phy,
6087         rect1_end_phy, rect2_start_phy, rect2_end_phy);
6088     return HI_FALSE;
6089 }
6090 
tde_osi_pattern_fill_opt(tde_hw_node * hw_node,hi_tde_pattern_fill_opt * opt,tde_alu_mode * alu_mode,hi_bool is_check_single_src2rop,hi_bool is_check_blend)6091 static hi_s32 tde_osi_pattern_fill_opt(tde_hw_node *hw_node, hi_tde_pattern_fill_opt *opt,
6092                                        tde_alu_mode *alu_mode, hi_bool is_check_single_src2rop,
6093                                        hi_bool is_check_blend)
6094 {
6095     hi_s32 ret;
6096 #if (TDE_CAPABILITY & ROP)
6097     ret = tde_osi_set_rop(hw_node, opt->alpha_blending_cmd, opt->rop_color, opt->rop_alpha,
6098                           alu_mode, is_check_single_src2rop);
6099     if (ret != HI_SUCCESS) {
6100         tde_hal_free_node_buf(hw_node);
6101         return ret;
6102     }
6103 #endif
6104     ret = tde_osi_set_blend(hw_node, opt->alpha_blending_cmd, opt->blend_opt, alu_mode,
6105                             is_check_blend);
6106     if (ret != HI_SUCCESS) {
6107         tde_hal_free_node_buf(hw_node);
6108         return ret;
6109     }
6110 #if (TDE_CAPABILITY & COLORIZE)
6111     ret = tde_osi_set_colorize(hw_node, opt->alpha_blending_cmd, opt->color_resize);
6112     if (ret != HI_SUCCESS) {
6113         tde_hal_free_node_buf(hw_node);
6114         return ret;
6115     }
6116 #endif
6117     tde_hal_node_set_global_alpha(hw_node, opt->global_alpha, opt->blend_opt.global_alpha_en);
6118     return HI_SUCCESS;
6119 }
6120 
tde_osi_single_pattern_fill_opt(tde_hw_node * hw_node,hi_tde_single_src * single_src,hi_tde_pattern_fill_opt * opt)6121 static hi_s32 tde_osi_single_pattern_fill_opt(tde_hw_node *hw_node, hi_tde_single_src *single_src,
6122                                               hi_tde_pattern_fill_opt *opt)
6123 {
6124     hi_bool is_check_single_src2rop = HI_TRUE;
6125     hi_bool is_check_blend = HI_FALSE;
6126     hi_s32 ret;
6127     tde_alu_mode alu_mode = TDE_ALU_NONE;
6128     tde_base_opt_mode base_mode = TDE_SINGLE_SRC_PATTERN_FILL_OPT;
6129     hi_tde_double_src double_src = {0};
6130 
6131     if (opt != HI_NULL) {
6132         if (opt->out_alpha_from >= HI_TDE_OUT_ALPHA_FROM_MAX) {
6133             tde_error("out_alpha_from error!\n");
6134             tde_hal_free_node_buf(hw_node);
6135             return HI_ERR_TDE_INVALID_PARA;
6136         }
6137 
6138         if (opt->out_alpha_from == HI_TDE_OUT_ALPHA_FROM_BACKGROUND) {
6139             tde_error("Single src pattern fill doesn't support out alpha form background!\n");
6140             tde_hal_free_node_buf(hw_node);
6141             return HI_ERR_TDE_INVALID_PARA;
6142         }
6143 
6144         ret = tde_osi_pattern_fill_opt(hw_node, opt, &alu_mode, is_check_single_src2rop, is_check_blend);
6145         if (ret != HI_SUCCESS) {
6146             return ret;
6147         }
6148 
6149         double_src.bg_surface = HI_NULL;
6150         double_src.bg_rect = HI_NULL;
6151         double_src.fg_surface = single_src->src_surface;
6152         double_src.fg_rect = single_src->src_rect;
6153         double_src.dst_surface = single_src->dst_surface;
6154         double_src.dst_rect = single_src->dst_rect;
6155         if (tde_osi_set_pattern_clip_para(&double_src, opt, hw_node) != HI_SUCCESS) {
6156             tde_hal_free_node_buf(hw_node);
6157             return HI_ERR_TDE_CLIP_AREA;
6158         }
6159     }
6160 
6161     if (tde_hal_node_set_base_operate(hw_node, base_mode, alu_mode, HI_NULL) != HI_SUCCESS) {
6162         tde_hal_free_node_buf(hw_node);
6163         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
6164     }
6165     return HI_SUCCESS;
6166 }
6167 
tde_osi_single_pattern_fill_set_up(tde_hw_node * hw_node,hi_tde_single_src * single_src,hi_tde_pattern_fill_opt * opt)6168 static hi_s32 tde_osi_single_pattern_fill_set_up(tde_hw_node *hw_node, hi_tde_single_src *single_src,
6169                                                  hi_tde_pattern_fill_opt *opt)
6170 {
6171     hi_s32 ret;
6172     tde_scandirection_mode src_scan_info = {0};
6173     tde_scandirection_mode dst_scan_info = {0};
6174     tde_surface_msg src_drv_surface = {0};
6175     tde_surface_msg dst_drv_surface = {0};
6176     hi_u16 code;
6177     tde_conv_mode_cmd conv = { 0 };
6178     tde_clut_usage clut_usage = TDE_CLUT_USAGE_BUTT;
6179 
6180     /* set ext alpha */
6181     tde_osi_set_ext_alpha(HI_NULL, single_src->src_surface, hw_node);
6182     /* set src2 and tqt */
6183     src_scan_info.h_scan = TDE_SCAN_LEFT_RIGHT;
6184     src_scan_info.v_scan = TDE_SCAN_UP_DOWN;
6185     dst_scan_info.h_scan = TDE_SCAN_LEFT_RIGHT;
6186     dst_scan_info.v_scan = TDE_SCAN_UP_DOWN;
6187 
6188     tde_osi_convert_surface(single_src->src_surface, single_src->src_rect, &src_scan_info, &src_drv_surface);
6189 
6190     tde_hal_node_set_src2(hw_node, &src_drv_surface);
6191 
6192     tde_osi_convert_surface(single_src->dst_surface, single_src->dst_rect, &dst_scan_info, &dst_drv_surface);
6193 
6194     (opt != HI_NULL) ? tde_hal_node_set_tqt(hw_node, &dst_drv_surface, opt->out_alpha_from) :
6195         tde_hal_node_set_tqt(hw_node, &dst_drv_surface, HI_TDE_OUT_ALPHA_FROM_FOREGROUND);
6196     /* set color */
6197     code = tde_osi_single_src_to_get_opt_code(single_src->src_surface->color_fmt,
6198         single_src->dst_surface->color_fmt);
6199 
6200     tde_osi_get_conv_by_code(code, &conv);
6201 
6202     if (tde_hal_node_set_color_convert(hw_node, &conv) != HI_SUCCESS) {
6203         tde_hal_free_node_buf(hw_node);
6204         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
6205     }
6206     /* set clut opt */
6207     ret = (opt != HI_NULL) ?
6208            tde_osi_set_clut_opt(single_src->src_surface, single_src->dst_surface, &clut_usage, opt->clut_reload,
6209                                 hw_node) :
6210            tde_osi_set_clut_opt(single_src->src_surface, single_src->dst_surface, &clut_usage, HI_TRUE, hw_node);
6211     if (ret != HI_SUCCESS) {
6212         tde_hal_free_node_buf(hw_node);
6213         return ret;
6214     }
6215     /* set csc */
6216     if (opt != HI_NULL) {
6217         ret = tde_set_node_csc(hw_node, opt->csc_opt);
6218         if (ret != HI_SUCCESS) {
6219             tde_hal_free_node_buf(hw_node);
6220             return ret;
6221         }
6222     }
6223     return HI_SUCCESS;
6224 }
6225 
tde_osi_single_src_pattern_fill(hi_s32 handle,hi_tde_single_src * single_src,hi_tde_pattern_fill_opt * opt)6226 hi_s32 tde_osi_single_src_pattern_fill(hi_s32 handle, hi_tde_single_src *single_src,
6227                                        hi_tde_pattern_fill_opt *opt)
6228 {
6229     tde_hw_node *hw_node = HI_NULL;
6230     hi_s32 ret;
6231     ret = tde_osi_check_single_src_pattern_fill_para(single_src, opt);
6232     if (ret != HI_SUCCESS) {
6233         return ret;
6234     }
6235 
6236     if (tde_hal_node_init_nd(&hw_node) != HI_SUCCESS) {
6237         return HI_ERR_TDE_NO_MEM;
6238     }
6239 
6240     /* deal with opt */
6241     ret = tde_osi_single_pattern_fill_opt(hw_node, single_src, opt);
6242     if (ret != HI_SUCCESS) {
6243         return ret;
6244     }
6245 
6246     /* set:
6247      * set ext alpha
6248      * set src2
6249      * set tqt
6250      * set color format
6251      * set clut opt
6252      * set csc
6253      */
6254     ret = tde_osi_single_pattern_fill_set_up(hw_node, single_src, opt);
6255     if (ret != HI_SUCCESS) {
6256         return ret;
6257     }
6258 
6259     /* set node finish */
6260     ret = tde_osi_set_node_finish(handle, hw_node, 0, TDE_NODE_SUBM_ALONE);
6261     if (ret != HI_SUCCESS) {
6262         tde_hal_free_node_buf(hw_node);
6263         return ret;
6264     }
6265     return HI_SUCCESS;
6266 }
6267 
tde_osi_check_single_src_pattern_fill_para(hi_tde_single_src * single_src,hi_tde_pattern_fill_opt * opt)6268 static hi_s32 tde_osi_check_single_src_pattern_fill_para(hi_tde_single_src *single_src,
6269                                                          hi_tde_pattern_fill_opt *opt)
6270 {
6271     hi_bool is_null_ptr = ((single_src == HI_NULL) || (single_src->src_surface == HI_NULL) ||
6272                            ((single_src->src_rect == HI_NULL)) || (single_src->dst_surface == HI_NULL) ||
6273                            (single_src->dst_rect == HI_NULL));
6274     if (is_null_ptr) {
6275         return HI_ERR_TDE_NULL_PTR;
6276     }
6277 
6278     if (tde_osi_check_single_src_pattern_opt(single_src->src_surface->color_fmt,
6279         single_src->dst_surface->color_fmt, opt) != HI_SUCCESS) {
6280         return HI_ERR_TDE_INVALID_PARA;
6281     }
6282 
6283     if (tde_osi_check_overlap(single_src->src_surface, single_src->src_rect,
6284         single_src->dst_surface, single_src->dst_rect)) {
6285         tde_error("Surface overlap!\n");
6286         return HI_ERR_TDE_INVALID_PARA;
6287     }
6288 
6289     return HI_SUCCESS;
6290 }
6291 
6292 /*
6293  * Function:      tde_osi_double_src_pattern_fill
6294  * Description:   dual resource pattern fill
6295  * Input:         opt: operate option
6296  * Return:        success/fail
6297  */
tde_osi_double_pattern_fill_opt(tde_hw_node * hw_node,hi_tde_double_src * double_src,hi_tde_pattern_fill_opt * opt)6298 static hi_s32 tde_osi_double_pattern_fill_opt(tde_hw_node *hw_node, hi_tde_double_src *double_src,
6299                                               hi_tde_pattern_fill_opt *opt)
6300 {
6301     hi_bool is_check_single_src2rop = HI_FALSE;
6302     hi_bool is_check_blend = HI_TRUE;
6303     tde_alu_mode alu_mode = TDE_ALU_NONE;
6304     hi_s32 ret;
6305     tde_base_opt_mode base_mode = TDE_DOUBLE_SRC_PATTERN_FILL_OPT;
6306 
6307     ret = tde_osi_pattern_fill_opt(hw_node, opt, &alu_mode, is_check_single_src2rop, is_check_blend);
6308     if (ret != HI_SUCCESS) {
6309         return ret;
6310     }
6311 
6312     if (tde_osi_set_pattern_clip_para(double_src, opt, hw_node) != HI_SUCCESS) {
6313         tde_hal_free_node_buf(hw_node);
6314         return HI_ERR_TDE_CLIP_AREA;
6315     }
6316 
6317     if (tde_hal_node_set_base_operate(hw_node, base_mode, alu_mode, HI_NULL) != HI_SUCCESS) {
6318         tde_hal_free_node_buf(hw_node);
6319         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
6320     }
6321     return HI_SUCCESS;
6322 }
6323 
tde_osi_get_scan_info(tde_scandirection_mode * src_scan_info,tde_scandirection_mode * dst_scan_info)6324 static hi_void tde_osi_get_scan_info(tde_scandirection_mode *src_scan_info, tde_scandirection_mode *dst_scan_info)
6325 {
6326     src_scan_info->h_scan = TDE_SCAN_LEFT_RIGHT;
6327     src_scan_info->v_scan = TDE_SCAN_UP_DOWN;
6328     dst_scan_info->h_scan = TDE_SCAN_LEFT_RIGHT;
6329     dst_scan_info->v_scan = TDE_SCAN_UP_DOWN;
6330 }
6331 
tde_osi_double_pattern_fill_set_up(tde_hw_node * hw_node,hi_tde_double_src * double_src,hi_tde_pattern_fill_opt * opt)6332 static hi_s32 tde_osi_double_pattern_fill_set_up(tde_hw_node *hw_node, hi_tde_double_src *double_src,
6333                                                  hi_tde_pattern_fill_opt *opt)
6334 {
6335     tde_scandirection_mode src_scan_info = {0};
6336     tde_scandirection_mode dst_scan_info = {0};
6337     tde_surface_msg src_drv_surface = {0};
6338     tde_surface_msg dst_drv_surface = {0};
6339     hi_u16 code;
6340     tde_conv_mode_cmd conv = { 0 };
6341     tde_clut_usage clut_usage = TDE_CLUT_USAGE_BUTT;
6342     hi_s32 ret;
6343 
6344     tde_osi_set_ext_alpha(double_src->bg_surface, double_src->fg_surface, hw_node);
6345 
6346     tde_osi_get_scan_info(&src_scan_info, &dst_scan_info);
6347 
6348     tde_osi_convert_surface(double_src->bg_surface, double_src->bg_rect, &src_scan_info, &src_drv_surface);
6349 
6350     tde_hal_node_set_src1(hw_node, &src_drv_surface);
6351 
6352     tde_osi_convert_surface(double_src->fg_surface, double_src->fg_rect, &src_scan_info, &src_drv_surface);
6353 
6354     tde_hal_node_set_src2(hw_node, &src_drv_surface);
6355 
6356     tde_osi_convert_surface(double_src->dst_surface, double_src->dst_rect, &dst_scan_info, &dst_drv_surface);
6357 
6358     tde_hal_node_set_tqt(hw_node, &dst_drv_surface, opt->out_alpha_from);
6359 
6360     code = tde_osi_double_src_get_opt_code(double_src->bg_surface->color_fmt,
6361         double_src->fg_surface->color_fmt, double_src->dst_surface->color_fmt);
6362 
6363     tde_osi_get_conv_by_code(code, &conv);
6364 
6365     if (tde_hal_node_set_color_convert(hw_node, &conv) != HI_SUCCESS) {
6366         tde_hal_free_node_buf(hw_node);
6367         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
6368     }
6369 
6370     ret = tde_osi_set_clut_opt(double_src->fg_surface, double_src->bg_surface, &clut_usage, opt->clut_reload, hw_node);
6371     if (ret != HI_SUCCESS) {
6372         tde_hal_free_node_buf(hw_node);
6373         return ret;
6374     }
6375 
6376     if ((opt->color_key_mode >= HI_TDE_COLOR_KEY_MODE_MAX) || (opt->color_key_mode < HI_TDE_COLOR_KEY_MODE_NONE)) {
6377         tde_error("color_key_mode error!\n");
6378         return HI_ERR_TDE_INVALID_PARA;
6379     }
6380 
6381     ret = tde_osi_set_color_key(double_src, hw_node, opt->color_key_value, opt->color_key_mode, clut_usage);
6382     if (ret != HI_SUCCESS) {
6383         tde_hal_free_node_buf(hw_node);
6384         return ret;
6385     }
6386 
6387     ret = tde_set_node_csc(hw_node, opt->csc_opt);
6388     if (ret != HI_SUCCESS) {
6389         tde_hal_free_node_buf(hw_node);
6390         return ret;
6391     }
6392     return HI_SUCCESS;
6393 }
6394 
tde_osi_double_src_pattern_fill(hi_s32 handle,hi_tde_double_src * double_src,hi_tde_pattern_fill_opt * opt)6395 hi_s32 tde_osi_double_src_pattern_fill(hi_s32 handle, hi_tde_double_src *double_src,
6396                                        hi_tde_pattern_fill_opt *opt)
6397 {
6398     tde_hw_node *hw_node = HI_NULL;
6399     hi_s32 ret;
6400 
6401     ret = tde_osi_check_double_src_pattern_fill_para(double_src, opt);
6402     if (ret != HI_SUCCESS) {
6403         return ret;
6404     }
6405 
6406     if (tde_hal_node_init_nd(&hw_node) != HI_SUCCESS) {
6407         return HI_ERR_TDE_NO_MEM;
6408     }
6409 
6410     /* deal with opt */
6411     ret = tde_osi_double_pattern_fill_opt(hw_node, double_src, opt);
6412     if (ret != HI_SUCCESS) {
6413         return ret;
6414     }
6415 
6416     ret = tde_osi_double_pattern_fill_set_up(hw_node, double_src, opt);
6417     if (ret != HI_SUCCESS) {
6418         return ret;
6419     }
6420 
6421     ret = tde_osi_set_node_finish(handle, hw_node, 0, TDE_NODE_SUBM_ALONE);
6422     if (ret != HI_SUCCESS) {
6423         tde_hal_free_node_buf(hw_node);
6424         return ret;
6425     }
6426 
6427     return HI_SUCCESS;
6428 }
6429 
tde_osi_check_double_src_pattern_fill_para(hi_tde_double_src * double_src,hi_tde_pattern_fill_opt * opt)6430 static hi_s32 tde_osi_check_double_src_pattern_fill_para(hi_tde_double_src *double_src,
6431                                                          hi_tde_pattern_fill_opt *opt)
6432 {
6433     hi_bool is_contain_null_ptr = ((double_src == HI_NULL) || (opt == HI_NULL) ||
6434                                    (double_src->bg_surface == HI_NULL) || (double_src->bg_rect == HI_NULL) ||
6435                                    (double_src->fg_surface == HI_NULL) || (double_src->fg_rect == HI_NULL) ||
6436                                    (double_src->dst_surface == HI_NULL) || (double_src->dst_rect == HI_NULL));
6437 
6438     if (is_contain_null_ptr) {
6439         return HI_ERR_TDE_INVALID_PARA;
6440     }
6441 
6442     if (tde_osi_check_double_src_pattern_opt(double_src->bg_surface->color_fmt,
6443         double_src->fg_surface->color_fmt, double_src->dst_surface->color_fmt, opt) != HI_SUCCESS) {
6444         return HI_ERR_TDE_INVALID_PARA;
6445     }
6446 
6447     if (tde_osi_check_overlap(double_src->fg_surface, double_src->fg_rect, double_src->bg_surface,
6448                               double_src->bg_rect) ||
6449         tde_osi_check_overlap(double_src->fg_surface, double_src->fg_rect, double_src->dst_surface,
6450                               double_src->dst_rect)) {
6451         tde_error("Surface overlap!\n");
6452         return HI_ERR_TDE_INVALID_PARA;
6453     }
6454 
6455     return HI_SUCCESS;
6456 }
6457 
tde_osi_set_blend(tde_hw_node * hw_node,hi_tde_alpha_blending alpha_blending_cmd,hi_tde_blend_opt blend_opt,tde_alu_mode * alu_mode,hi_bool check_blend)6458 static hi_s32 tde_osi_set_blend(tde_hw_node *hw_node, hi_tde_alpha_blending alpha_blending_cmd,
6459                                 hi_tde_blend_opt blend_opt,
6460                                 tde_alu_mode *alu_mode, hi_bool check_blend)
6461 {
6462     hi_bool set_blend = ((hi_u32)alpha_blending_cmd & HI_TDE_ALPHA_BLENDING_BLEND) ? HI_TRUE : HI_FALSE;
6463     hi_bool unknown_blend_mode = (blend_opt.blend_cmd == HI_TDE_BLEND_CMD_CONFIG) &&
6464                                  ((blend_opt.src1_blend_mode >= HI_TDE_BLEND_MAX) ||
6465                                  (blend_opt.src2_blend_mode >= HI_TDE_BLEND_MAX));
6466 #if (TDE_CAPABILITY & ROP)
6467     hi_bool enable_alpha_rop = ((hi_u32)alpha_blending_cmd & HI_TDE_ALPHA_BLENDING_ROP) ? HI_TRUE : HI_FALSE;
6468 #endif
6469     hi_bool b_unknown_blend_cmd = (blend_opt.blend_cmd >= HI_TDE_BLEND_CMD_MAX);
6470 
6471     if (!set_blend) {
6472         return HI_SUCCESS;
6473     }
6474 
6475     *alu_mode = TDE_ALU_BLEND;
6476 
6477     if (check_blend) {
6478         if (b_unknown_blend_cmd) {
6479             tde_error("Unknown blend cmd!\n");
6480 
6481             return HI_ERR_TDE_INVALID_PARA;
6482         }
6483 
6484         if (unknown_blend_mode) {
6485             tde_error("Unknown blend mode!\n");
6486 
6487             return HI_ERR_TDE_INVALID_PARA;
6488         }
6489     }
6490 
6491     if (tde_hal_node_set_blend(hw_node, &blend_opt) != HI_SUCCESS) {
6492         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
6493     }
6494 #if (TDE_CAPABILITY & ROP)
6495 
6496     if (enable_alpha_rop) {
6497         tde_hal_node_enable_alpha_rop(hw_node);
6498     }
6499 #endif
6500     return HI_SUCCESS;
6501 }
6502 
6503 #if (TDE_CAPABILITY & COLORIZE)
tde_osi_set_colorize(tde_hw_node * hw_node,hi_tde_alpha_blending alpha_blending_cmd,hi_s32 color_resize)6504 static hi_s32 tde_osi_set_colorize(tde_hw_node *hw_node, hi_tde_alpha_blending alpha_blending_cmd,
6505     hi_s32 color_resize)
6506 {
6507     hi_bool set_colorize = ((hi_u32)alpha_blending_cmd & HI_TDE_ALPHA_BLENDING_COLORIZE) ? HI_TRUE : HI_FALSE;
6508 
6509     if (!set_colorize) {
6510         return HI_SUCCESS;
6511     }
6512 
6513     if (tde_hal_node_set_colorize(hw_node, color_resize) != HI_SUCCESS) {
6514         tde_hal_free_node_buf(hw_node);
6515         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
6516     }
6517 
6518     return HI_SUCCESS;
6519 }
6520 #endif
6521 
6522 #if (TDE_CAPABILITY & ROP)
tde_osi_set_rop(tde_hw_node * hw_node,hi_tde_alpha_blending alpha_blending_cmd,hi_tde_rop_mode rop_code_color,hi_tde_rop_mode rop_code_alpha,tde_alu_mode * alu_mode,hi_bool single_sr2_rop)6523 static hi_s32 tde_osi_set_rop(tde_hw_node *hw_node, hi_tde_alpha_blending alpha_blending_cmd,
6524                               hi_tde_rop_mode rop_code_color,
6525                               hi_tde_rop_mode rop_code_alpha, tde_alu_mode *alu_mode, hi_bool single_sr2_rop)
6526 {
6527     hi_bool set_rop = ((hi_u32)alpha_blending_cmd & HI_TDE_ALPHA_BLENDING_ROP) ? HI_TRUE : HI_FALSE;
6528     hi_bool error_rop_code = (rop_code_color >= HI_TDE_ROP_MAX) || (rop_code_alpha >= HI_TDE_ROP_MAX);
6529     hi_bool only_support_single_sr2_rop = ((!tde_osi_is_single_src_to_rop(rop_code_alpha)) ||
6530                                            (!tde_osi_is_single_src_to_rop(rop_code_color)));
6531 
6532     if (!set_rop) {
6533         return HI_SUCCESS;
6534     }
6535 
6536     *alu_mode = TDE_ALU_ROP;
6537 
6538     if (error_rop_code) {
6539         tde_error("enRopCode error!\n");
6540 
6541         return HI_ERR_TDE_INVALID_PARA;
6542     }
6543 
6544     if (single_sr2_rop) {
6545         if (only_support_single_sr2_rop) {
6546             tde_error("Only support single s2 rop!\n");
6547 
6548             return HI_ERR_TDE_UNSUPPORTED_OPERATION;
6549         }
6550     }
6551 
6552     if (tde_hal_node_set_rop(hw_node, rop_code_color, rop_code_alpha) != HI_SUCCESS) {
6553         return HI_ERR_TDE_UNSUPPORTED_OPERATION;
6554     }
6555 
6556     return HI_SUCCESS;
6557 }
6558 #endif
6559 
6560 /*
6561  * Function:      tde_osi_pattern_fill
6562  * Description:   pattern fill
6563  * Input:         handle:task handle
6564                   opt: operate option
6565  * Return:        success/fail
6566  */
tde_osi_pattern_fill(hi_s32 handle,hi_tde_double_src * double_src,hi_tde_pattern_fill_opt * opt)6567 hi_s32 tde_osi_pattern_fill(hi_s32 handle, hi_tde_double_src *double_src, hi_tde_pattern_fill_opt *opt)
6568 {
6569     tde_pattern_operation_category opt_category_en;
6570     hi_tde_single_src single_src = {0};
6571 
6572     opt_category_en = tde_osi_get_pattern_opt_category(double_src, opt);
6573     switch (opt_category_en) {
6574         case TDE_PATTERN_OPERATION_SINGLE_SRC:
6575             if (double_src->bg_surface != HI_NULL) {
6576                 single_src.src_surface = double_src->bg_surface;
6577                 single_src.src_rect = double_src->bg_rect;
6578                 single_src.dst_surface = double_src->dst_surface;
6579                 single_src.dst_rect = double_src->dst_rect;
6580             } else {
6581                 single_src.src_surface = double_src->fg_surface;
6582                 single_src.src_rect = double_src->fg_rect;
6583                 single_src.dst_surface = double_src->dst_surface;
6584                 single_src.dst_rect = double_src->dst_rect;
6585             }
6586             return tde_osi_single_src_pattern_fill(handle, &single_src, opt);
6587         case TDE_PATTERN_OPERATION_DOUBLE_SRC:
6588             return tde_osi_double_src_pattern_fill(handle, double_src, opt);
6589         default:
6590             return HI_ERR_TDE_INVALID_PARA;
6591     }
6592 }
6593 
6594 /*
6595  * Function:      tde_cal_scale_rect
6596  * Description:   update zoom rect information
6597  * Input:         src_rect:source bitmap operate zone
6598                   dst_rect: target bitmap operate zone
6599  *                rect_in_src: source bitmap scale zone
6600  *                rect_in_dst: target bitmap info atfer calculating
6601  * Return:        success/fail
6602  */
tde_cal_scale_rect(const hi_tde_rect * src_rect,const hi_tde_rect * dst_rect,hi_tde_rect * rect_in_src,hi_tde_rect * rect_in_dst)6603 hi_s32 tde_cal_scale_rect(const hi_tde_rect *src_rect, const hi_tde_rect *dst_rect,
6604                           hi_tde_rect *rect_in_src, hi_tde_rect *rect_in_dst)
6605 {
6606 #if (TDE_CAPABILITY & RESIZE)
6607     tde_update_config reg = { 0 };
6608     tde_update_info info = { 0 };
6609 
6610     reg.ori_in_height = src_rect->height;
6611     reg.ori_in_width = src_rect->width;
6612     reg.zme_out_height = dst_rect->height;
6613     reg.zme_out_width = dst_rect->width;
6614 
6615     reg.update_instart_w = rect_in_src->pos_x;
6616     reg.update_instart_h = rect_in_src->pos_y;
6617     reg.update_in_width = rect_in_src->width;
6618     reg.update_in_height = rect_in_src->height;
6619 
6620     tde_osi_get_hupdate_info(&reg, &info, HI_TRUE);
6621     tde_osi_get_vupdate_info(&reg, &info, HI_TRUE, HI_TRUE);
6622 
6623     rect_in_src->pos_x = info.zme_instart_w;
6624     rect_in_src->pos_y = info.zme_instart_h;
6625     rect_in_src->width = info.zme_in_width;
6626     rect_in_src->height = info.zme_in_height;
6627 
6628     rect_in_dst->pos_x = info.zme_outstart_w;
6629     rect_in_dst->pos_y = info.zme_outstart_h;
6630     rect_in_dst->width = info.zme_out_width;
6631     rect_in_dst->height = info.zme_out_height;
6632 #endif
6633     return HI_SUCCESS;
6634 }
6635 
tde_osi_enable_region_deflicker(hi_bool is_region_deflicker)6636 hi_s32 tde_osi_enable_region_deflicker(hi_bool is_region_deflicker)
6637 {
6638 #if (TDE_CAPABILITY & DEFLICKER)
6639     if ((is_region_deflicker != HI_TRUE) && (is_region_deflicker != HI_FALSE)) {
6640         tde_error("hi_bool should be HI_TRUE or HI_FALSE!!\n");
6641         return HI_ERR_TDE_INVALID_PARA;
6642     }
6643 
6644     g_region_deflicker = is_region_deflicker;
6645 #else
6646     hi_unused(is_region_deflicker);
6647 #endif
6648     return HI_SUCCESS;
6649 }
6650 
6651 #ifdef CONFIG_TDE_BLIT_EX
tde_osi_single_blit_ex(hi_s32 handle,hi_tde_surface * src_surface,hi_tde_rect * src_rect,hi_tde_surface * dst_surface,hi_tde_rect * dst_rect,hi_tde_opt * opt,hi_bool mmz_for_src,hi_bool mmz_for_dst)6652 hi_s32 tde_osi_single_blit_ex(hi_s32 handle, hi_tde_surface *src_surface, hi_tde_rect *src_rect,
6653                               hi_tde_surface *dst_surface, hi_tde_rect *dst_rect,
6654                               hi_tde_opt *opt, hi_bool mmz_for_src, hi_bool mmz_for_dst)
6655 {
6656     hi_s32 ret;
6657     hi_tde_single_src single_src;
6658 
6659     ret = tde_osi_check_surface(src_surface, src_rect);
6660     if (ret < 0) {
6661         return ret;
6662     }
6663     ret = tde_osi_check_surface(dst_surface, dst_rect);
6664     if (ret < 0) {
6665         return ret;
6666     }
6667 
6668     single_src.src_surface = src_surface;
6669     single_src.src_rect    = src_rect;
6670     single_src.dst_surface = dst_surface;
6671     single_src.dst_rect    = dst_rect;
6672     return tde_osi_single_src_2_blit(handle, &single_src, opt, mmz_for_src, mmz_for_dst);
6673 }
6674 #endif
6675 
6676 #endif
6677