xref: /OK3568_Linux_fs/external/linux-rga/core/NormalRga.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright (C) 2016 Rockchip Electronics Co., Ltd.
3  * Authors:
4  *  Zhiqin Wei <wzq@rock-chips.com>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef _rockchip_normal_rga_h_
20 #define _rockchip_normal_rga_h_
21 
22 #include <stdint.h>
23 #include <vector>
24 #include <sys/types.h>
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include <errno.h>
29 #include <time.h>
30 #include <unistd.h>
31 #include <fcntl.h>
32 #include <sys/mman.h>
33 #include <linux/stddef.h>
34 
35 #ifdef ANDROID
36 #include <utils/Atomic.h>
37 #include <utils/Errors.h>
38 #include <utils/Log.h>
39 #include <ui/PixelFormat.h>
40 #include <utils/Thread.h>
41 #include <hardware/hardware.h>
42 #endif
43 
44 #include "drmrga.h"
45 #include "rga.h"
46 #include "rga_ioctl.h"
47 
48 #include "NormalRgaContext.h"
49 
50 int         RgaInit(void **ctx);
51 int         RgaDeInit(void **ctx);
52 int         RgaBlit(rga_info_t *src, rga_info_t *dst, rga_info_t *src1);
53 int         RgaFlush();
54 int         RgaCollorFill(rga_info_t *dst);
55 int         RgaCollorPalette(rga_info *src, rga_info *dst, rga_info *lut);
56 
57 
58 int         NormalRgaInitTables();
59 int         NormalRgaScale();
60 int         NormalRgaRoate();
61 int         NormalRgaRoateScale();
62 #ifdef ANDROID
63 int         NormalRgaGetRects(buffer_handle_t src, buffer_handle_t dst,
64                               int *sType, int *dType, drm_rga_t* tmpRects);
65 int         NormalRgaGetRect(buffer_handle_t hnd, rga_rect_t *rect);
66 int         NormalRgaGetMmuType(buffer_handle_t hnd, int *mmuType);
67 #endif
68 
69 int         RkRgaCompatibleFormat(int format);
70 int         RkRgaGetRgaFormat(int format);
71 int         RkRgaGetRgaFormatFromAndroid(int format);
72 
73 uint32_t    bytesPerPixel(int format);
74 
75 /*
76 @fun NormalRgaSetRects:For use to set the rects esayly
77 
78 @param rect:The rect user want to set,like setting the src rect:
79     drm_rga_t rects;
80     NormalRgaSetRects(rects.src,0,0,1920,1080,1920,NV12);
81     mean to set the src rect to the value.
82 */
83 int         checkRectForRga(rga_rect_t rect);
84 int         isRectValid(rga_rect_t rect);
85 
86 int         NormalRgaSetRect(rga_rect_t *rect, int x, int y,
87                              int w, int h, int s, int f);
88 
89 void        NormalRgaLogOutRgaReq(struct rga_req rgaReg);
90 
91 void        is_debug_log(void);
92 int         is_out_log(void);
93 int         get_int_property(void);
94 
95 int         NormalRgaSetFdsOffsets(struct rga_req *req,
96                                    uint16_t src_fd,     uint16_t dst_fd,
97                                    uint32_t src_offset, uint32_t dst_offset);
98 
99 int         NormalRgaSetSrcActiveInfo(struct rga_req *req,
100                                       unsigned int width, unsigned int height,
101                                       unsigned int x_off, unsigned int y_off);
102 
103 
104 #if defined(__arm64__) || defined(__aarch64__)
105 int         NormalRgaSetSrcVirtualInfo(struct rga_req *req,
106                                        unsigned long yrgb_addr,unsigned long uv_addr,unsigned long v_addr,
107                                        unsigned int vir_w,unsigned int vir_h, unsigned int format,
108                                        unsigned char a_swap_en);
109 #else
110 int         NormalRgaSetSrcVirtualInfo(struct rga_req *req,
111                                        unsigned int yrgb_addr, unsigned int uv_addr,unsigned int v_addr,
112                                        unsigned int vir_w, unsigned int vir_h, unsigned int format,
113                                        unsigned char a_swap_en);
114 #endif
115 
116 
117 int         NormalRgaSetDstActiveInfo(struct rga_req *req,
118                                       unsigned int width, unsigned int height,
119                                       unsigned int x_off, unsigned int y_off);
120 
121 
122 #if defined(__arm64__) || defined(__aarch64__)
123 int         NormalRgaSetDstVirtualInfo(struct rga_req *msg,
124                                        unsigned long yrgb_addr,unsigned long uv_addr,unsigned long v_addr,
125                                        unsigned int  vir_w,    unsigned int vir_h,
126                                        RECT          *clip,
127                                        unsigned int format, unsigned char a_swap_en);
128 #else
129 int         NormalRgaSetDstVirtualInfo(struct rga_req *msg,
130                                        unsigned int yrgb_addr,unsigned int uv_addr,  unsigned int v_addr,
131                                        unsigned int vir_w,    unsigned int vir_h,
132                                        RECT *clip,
133                                        unsigned int  format, unsigned char a_swap_en);
134 #endif
135 
136 
137 int         NormalRgaSetPatInfo(struct rga_req *msg,
138                                 unsigned int width,unsigned int height,unsigned int x_off,
139                                 unsigned int y_off, unsigned int pat_format);
140 
141 int         NormalRgaSetPatActiveInfo(struct rga_req *req,
142                                       unsigned int width, unsigned int height,
143                                       unsigned int x_off, unsigned int y_off);
144 
145 #if defined(__arm64__) || defined(__aarch64__)
146 int         NormalRgaSetPatVirtualInfo(struct rga_req *msg,
147                                        unsigned long yrgb_addr,unsigned long uv_addr,unsigned long v_addr,
148                                        unsigned int  vir_w,    unsigned int vir_h,
149                                        RECT *clip,
150                                        unsigned int format, unsigned char a_swap_en);
151 #else
152 int         NormalRgaSetPatVirtualInfo(struct rga_req *msg,
153                                        unsigned int yrgb_addr,unsigned int uv_addr,  unsigned int v_addr,
154                                        unsigned int vir_w,    unsigned int vir_h,
155                                        RECT *clip,
156                                        unsigned int  format, unsigned char a_swap_en);
157 #endif
158 
159 #if defined(__arm64__) || defined(__aarch64__)
160 int         NormalRgaSetRopMaskInfo(struct rga_req *msg,
161                                     unsigned long rop_mask_addr,unsigned int rop_mask_endian_mode);
162 #else
163 int         NormalRgaSetRopMaskInfo(struct rga_req *msg,
164                                     unsigned int rop_mask_addr,unsigned int rop_mask_endian_mode);
165 #endif
166 
167 
168 /* 0:alpha' = alpha + (alpha>>7) | alpha' = alpha */
169 /* 0 global alpha / 1 per pixel alpha / 2 mix mode */
170 
171 /* porter duff alpha mode en */
172 
173 /* use dst alpha  */
174 
175 int         NormalRgaSetAlphaEnInfo(struct rga_req *msg,
176                                     unsigned int alpha_cal_mode, unsigned int alpha_mode,
177                                     unsigned int global_a_value, unsigned int PD_en,
178                                     unsigned int PD_mode,        unsigned int dst_alpha_en );
179 
180 
181 
182 int         NormalRgaSetRopEnInfo(struct rga_req *msg,
183                                   unsigned int ROP_mode, unsigned int ROP_code,
184                                   unsigned int color_mode,unsigned int solid_color);
185 
186 
187 int         NormalRgaSetFadingEnInfo(struct rga_req *msg,
188                                      unsigned char r,unsigned char g,unsigned char b);
189 
190 
191 int         NormalRgaSetSrcTransModeInfo(struct rga_req *msg,
192         unsigned char trans_mode,unsigned char a_en,unsigned char b_en,
193         unsigned char g_en,unsigned char r_en,unsigned int color_key_min,
194         unsigned int color_key_max,unsigned char zero_mode_en);
195 
196 bool        NormalRgaIsBppFormat(int format);
197 
198 bool        NormalRgaIsYuvFormat(int format);
199 
200 bool        NormalRgaIsRgbFormat(int format);
201 
202 bool        NormalRgaFormatHasAlpha(int format);
203 
204 // 0/near  1/bilnear  2/bicubic
205 // 0/copy 1/rotate_scale 2/x_mirror 3/y_mirror
206 // rotate angle
207 // dither en flag
208 // AA flag
209 int         NormalRgaSetBitbltMode(struct rga_req *msg,
210                                    unsigned char scale_mode,  unsigned char rotate_mode,
211                                    unsigned int  angle,       unsigned int  dither_en,
212                                    unsigned int  AA_en,       unsigned int  yuv2rgb_mode);
213 
214 
215 /* 1bpp/2bpp/4bpp/8bpp */
216 /* src endian mode sel */
217 /* BPP1 = 0 */
218 /* BPP1 = 1 */
219 int         NormalRgaSetColorPaletteMode(struct rga_req *msg,
220         unsigned char  palette_mode,unsigned char  endian_mode,
221         unsigned int  bpp1_0_color, unsigned int  bpp1_1_color);
222 
223 /* gradient color part         */
224 /* saturation mode             */
225 /* patten fill or solid fill   */
226 /* solid color                 */
227 /* pattern width               */
228 /* pattern height              */
229 /* pattern x offset            */
230 /* pattern y offset            */
231 /* alpha en                    */
232 int         NormalRgaSetColorFillMode(
233     struct rga_req *msg,                COLOR_FILL  *gr_color,
234     unsigned char  gr_satur_mode,       unsigned char  cf_mode,
235     unsigned int color,                 unsigned short pat_width,
236     unsigned short pat_height,          unsigned char pat_x_off,
237     unsigned char pat_y_off,            unsigned char aa_en);
238 
239 
240 /* start point              */
241 /* end   point              */
242 /* line point drawing color */
243 /* line width               */
244 /* AA en                    */
245 /* last point en            */
246 int         NormalRgaSetLineDrawingMode(struct rga_req *msg,
247                                         POINT sp,                     POINT ep,
248                                         unsigned int color,           unsigned int line_width,
249                                         unsigned char AA_en,          unsigned char last_point_en);
250 
251 
252 
253 /* blur/sharpness   */
254 /* filter intensity */
255 /* dither_en flag   */
256 
257 int         NormalRgaSetBlurSharpFilterMode(
258     struct rga_req *msg,         unsigned char filter_mode,
259     unsigned char filter_type,   unsigned char dither_en);
260 
261 
262 int         NormalRgaSetPreScalingMode(
263     struct rga_req *msg, unsigned char dither_en);
264 
265 
266 /* LUT table addr      */
267 /* 1bpp/2bpp/4bpp/8bpp */
268 #if defined(__arm64__) || defined(__aarch64__)
269 int         NormalRgaUpdatePaletteTableMode(
270     struct rga_req *msg,unsigned long LUT_addr,unsigned int palette_mode);
271 #else
272 int         NormalRgaUpdatePaletteTableMode(
273     struct rga_req *msg,unsigned int LUT_addr, unsigned int palette_mode);
274 #endif
275 
276 
277 /* patten addr    */
278 /* patten width   */
279 /* patten height  */
280 /* patten format  */
281 
282 int         NormalRgaUpdatePattenBuffMode(struct rga_req *msg,
283         unsigned int pat_addr, unsigned int w,
284         unsigned int h,        unsigned int format);
285 
286 int NormalRgaNNQuantizeMode(struct rga_req *msg, rga_info *dst);
287 
288 int NormalRgaFullColorSpaceConvert(struct rga_req *msg, int color_space_mode);
289 
290 int NormalRgaDitherMode(struct rga_req *msg, rga_info *dst, int format);
291 
292 #if defined(__arm64__) || defined(__aarch64__)
293 int         NormalRgaMmuInfo(struct rga_req *msg,
294                              unsigned char  mmu_en,   unsigned char  src_flush,
295                              unsigned char  dst_flush,unsigned char  cmd_flush,
296                              unsigned long base_addr, unsigned char  page_size);
297 #else
298 int         NormalRgaMmuInfo(struct rga_req *msg,
299                              unsigned char  mmu_en,   unsigned char  src_flush,
300                              unsigned char  dst_flush,unsigned char  cmd_flush,
301                              unsigned int base_addr,  unsigned char  page_size);
302 #endif
303 
304 int         NormalRgaMmuFlag(struct rga_req *msg,
305                              int  src_mmu_en,   int  dst_mmu_en);
306 
307 #endif
308 
309 void NormalRgaCompatModeConvertRga2(rga2_req *req, rga_req *orig_req);
310