• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef __HIFB_H__
17 #define __HIFB_H__
18 
19 #ifdef __HuaweiLite__
20 #include <fb.h>
21 #include "stdlib.h"
22 #else
23 #include <linux/fb.h>
24 #endif
25 
26 #include "hi_type.h"
27 #include "hi_common.h"
28 
29 #ifdef __cplusplus
30 #if __cplusplus
31 extern "C" {
32 #endif
33 #endif /* __cplusplus */
34 
35 #define IOC_TYPE_HIFB 'F'
36 /* To obtain the colorkey of an overlay layer */
37 #define FBIOGET_COLORKEY_HIFB _IOR(IOC_TYPE_HIFB, 90, HIFB_COLORKEY_S)
38 /* To set the colorkey of an overlay layer */
39 #define FBIOPUT_COLORKEY_HIFB _IOW(IOC_TYPE_HIFB, 91, HIFB_COLORKEY_S)
40 /* To get the alpha of an overlay layer */
41 #define FBIOGET_ALPHA_HIFB _IOR(IOC_TYPE_HIFB, 92, HIFB_ALPHA_S)
42 /* To set the alpha of an overlay layer */
43 #define FBIOPUT_ALPHA_HIFB _IOW(IOC_TYPE_HIFB, 93, HIFB_ALPHA_S)
44 /* To get the origin of an overlay layer on the screen */
45 #define FBIOGET_SCREEN_ORIGIN_HIFB _IOR(IOC_TYPE_HIFB, 94, HIFB_POINT_S)
46 /* To set the origin of an overlay layer on the screen */
47 #define FBIOPUT_SCREEN_ORIGIN_HIFB _IOW(IOC_TYPE_HIFB, 95, HIFB_POINT_S)
48 /* To obtain the anti-flicker setting of an overlay layer */
49 #define FBIOGET_DEFLICKER_HIFB _IOR(IOC_TYPE_HIFB, 98, HIFB_DEFLICKER_S)
50 /* To set the anti-flicker setting of an overlay layer */
51 #define FBIOPUT_DEFLICKER_HIFB _IOW(IOC_TYPE_HIFB, 99, HIFB_DEFLICKER_S)
52 /* To wait for the vertical blanking region of an overlay layer */
53 #define FBIOGET_VBLANK_HIFB _IO(IOC_TYPE_HIFB, 100)
54 /* To set the display state of an overlay layer */
55 #define FBIOPUT_SHOW_HIFB _IOW(IOC_TYPE_HIFB, 101, HI_BOOL)
56 /* To obtain the display state of an overlay layer */
57 #define FBIOGET_SHOW_HIFB _IOR(IOC_TYPE_HIFB, 102, HI_BOOL)
58 /* to obtain the capability of an overlay layer */
59 #define FBIOGET_CAPABILITY_HIFB _IOR(IOC_TYPE_HIFB, 103, HIFB_CAPABILITY_S)
60 /* set the screen output size */
61 #define FBIOPUT_SCREENSIZE _IOW(IOC_TYPE_HIFB, 130, HIFB_SIZE_S)
62 /* get the screen output size */
63 #define FBIOGET_SCREENSIZE _IOR(IOC_TYPE_HIFB, 131, HIFB_SIZE_S)
64 
65 /* To display multiple surfaces in turn and set the alpha and colorkey attributes */
66 #define FBIOFLIP_SURFACE _IOW(IOC_TYPE_HIFB, 132, HIFB_SURFACEEX_S)
67 
68 /* To set the compression function status of an overlay layer */
69 #define FBIOPUT_COMPRESSION_HIFB _IOW(IOC_TYPE_HIFB, 133, HI_BOOL)
70 /* To obtain the compression function status of an overlay layer */
71 #define FBIOGET_COMPRESSION_HIFB _IOR(IOC_TYPE_HIFB, 134, HI_BOOL)
72 
73 /* To set the hdr function status of an overlay layer */
74 #define FBIOPUT_DYNAMIC_RANGE_HIFB _IOW(IOC_TYPE_HIFB, 139, HIFB_DYNAMIC_RANGE_E)
75 /* To get the hdr function status of an overlay layer */
76 #define FBIOGET_DYNAMIC_RANGE_HIFB _IOR(IOC_TYPE_HIFB, 140, HIFB_DYNAMIC_RANGE_E)
77 
78 /* To create the layer */
79 #define FBIO_CREATE_LAYER _IO(IOC_TYPE_HIFB, 149)
80 /* To destroy the layer */
81 #define FBIO_DESTROY_LAYER _IO(IOC_TYPE_HIFB, 150)
82 
83 typedef struct {
84     HI_U32 u32Width;
85     HI_U32 u32Height;
86 } HIFB_SIZE_S;
87 
88 #ifndef __HuaweiLite__
hifb_rgb(const struct fb_bitfield * pBit,HI_S32 color)89 static inline HI_U8 hifb_rgb(const struct fb_bitfield *pBit, HI_S32 color)
90 {
91     return ((HI_U8)((((HI_U32)color) >> pBit->offset) << (8 - pBit->length)) + /* 8 Digits to flip */
92             ((HI_U8)(((HI_U32)(color) >> pBit->offset) << (8 - pBit->length)) >> pBit->length)); /* 8 Digits to flip */
93 }
94 
hifb_color2key(const struct fb_var_screeninfo * pVar,HI_S32 color)95 static inline HI_S32 hifb_color2key(const struct fb_var_screeninfo *pVar, HI_S32 color)
96 {
97     if (pVar->bits_per_pixel <= 8) { /* 8 left shift */
98         return color;
99     } else {
100         HI_U8 r, g, b;
101         r = hifb_rgb(&pVar->red, color);
102         g = hifb_rgb(&pVar->green, color);
103         b = hifb_rgb(&pVar->blue, color);
104         return (r << 16) + (g << 8) + b; /* left shift altitude 16 8 */
105     }
106 }
107 #endif
108 
109 typedef enum {
110     HIFB_DYNAMIC_RANGE_SDR8 = 0,
111     HIFB_DYNAMIC_RANGE_SDR10,
112     HIFB_DYNAMIC_RANGE_HDR10,
113     HIFB_DYNAMIC_RANGE_HLG,
114     HIFB_DYNAMIC_RANGE_SLF,
115     HIFB_DYNAMIC_RANGE_BUTT
116 } HIFB_DYNAMIC_RANGE_E;
117 
118 typedef struct {
119     HI_BOOL bKeyEnable; /* colorkey enable flag */
120     HI_U32 u32Key;      /* colorkey value, maybe contains alpha */
121 } HIFB_COLORKEY_S;
122 
123 typedef struct {
124     HI_S32 x;
125     HI_S32 y;
126     HI_S32 w;
127     HI_S32 h;
128 } HIFB_RECT;
129 
130 typedef struct {
131     HI_S32 s32XPos; /* horizontal position */
132     HI_S32 s32YPos; /* vertical position */
133 } HIFB_POINT_S;
134 
135 typedef struct {
136     HI_U32 u32HDfLevel;          /* horizontal deflicker level */
137     HI_U32 u32VDfLevel;          /* vertical deflicker level */
138     HI_U8 ATTRIBUTE *pu8HDfCoef; /* horizontal deflicker coefficient */
139     HI_U8 ATTRIBUTE *pu8VDfCoef; /* vertical deflicker coefficient */
140 } HIFB_DEFLICKER_S;
141 
142 /* Alpha info */
143 typedef struct {
144     HI_BOOL bAlphaEnable;  /* alpha enable flag */
145     HI_BOOL bAlphaChannel; /* alpha channel enable flag */
146     HI_U8 u8Alpha0;        /* alpha0 value, used in ARGB1555 */
147     HI_U8 u8Alpha1;        /* alpha1 value, used in ARGB1555 */
148     HI_U8 u8GlobalAlpha;   /* global alpha value */
149     HI_U8 u8Reserved;
150 } HIFB_ALPHA_S;
151 
152 typedef enum {
153     HIFB_FMT_RGB565 = 0,
154     HIFB_FMT_RGB888, /* RGB888 24bpp */
155 
156     HIFB_FMT_KRGB444, /* RGB444 16bpp */
157     HIFB_FMT_KRGB555, /* RGB555 16bpp */
158     HIFB_FMT_KRGB888, /* RGB888 32bpp */
159 
160     HIFB_FMT_ARGB4444, /* ARGB4444 */
161     HIFB_FMT_ARGB1555, /* ARGB1555 */
162     HIFB_FMT_ARGB8888, /* ARGB8888 */
163     HIFB_FMT_ARGB8565, /* ARGB8565 */
164 
165     HIFB_FMT_RGBA4444, /* ARGB4444 */
166     HIFB_FMT_RGBA5551, /* RGBA5551 */
167     HIFB_FMT_RGBA5658, /* RGBA5658 */
168     HIFB_FMT_RGBA8888, /* RGBA8888 */
169 
170     HIFB_FMT_BGR565,   /* BGR565 */
171     HIFB_FMT_BGR888,   /* BGR888 */
172     HIFB_FMT_ABGR4444, /* ABGR4444 */
173     HIFB_FMT_ABGR1555, /* ABGR1555 */
174     HIFB_FMT_ABGR8888, /* ABGR8888 */
175     HIFB_FMT_ABGR8565, /* ABGR8565 */
176     HIFB_FMT_KBGR444,  /* BGR444 16bpp */
177     HIFB_FMT_KBGR555,  /* BGR555 16bpp */
178     HIFB_FMT_KBGR888,  /* BGR888 32bpp */
179 
180     HIFB_FMT_1BPP,     /* clut1 */
181     HIFB_FMT_2BPP,     /* clut2 */
182     HIFB_FMT_4BPP,     /* clut4 */
183     HIFB_FMT_8BPP,     /* clut8 */
184     HIFB_FMT_ACLUT44,  /* AClUT44 */
185     HIFB_FMT_ACLUT88,  /* ACLUT88 */
186     HIFB_FMT_PUYVY,    /* UYVY */
187     HIFB_FMT_PYUYV,    /* YUYV */
188     HIFB_FMT_PYVYU,    /* YVYU */
189     HIFB_FMT_YUV888,   /* YUV888 */
190     HIFB_FMT_AYUV8888, /* AYUV8888 */
191     HIFB_FMT_YUVA8888, /* YUVA8888 */
192     HIFB_FMT_BUTT
193 } HIFB_COLOR_FMT_E;
194 
195 typedef struct {
196     HI_BOOL bKeyRgb;
197     HI_BOOL bKeyAlpha;              /* whether support colorkey alpha */
198     HI_BOOL bGlobalAlpha;           /* whether support global alpha */
199     HI_BOOL bCmap;                  /* whether support color map */
200     HI_BOOL bHasCmapReg;            /* whether has color map register */
201     HI_BOOL bColFmt[HIFB_FMT_BUTT]; /* support which color format */
202     HI_BOOL bVoScale;               /* support vo scale */
203     /* whether support a certain layer, for example:x5 HD support HIFB_SD_0 not support HIFB_SD_1 */
204     HI_BOOL bLayerSupported;
205     HI_U32 u32MaxWidth;     /* the max pixels per line */
206     HI_U32 u32MaxHeight;    /* the max lines */
207     HI_U32 u32MinWidth;     /* the min pixels per line */
208     HI_U32 u32MinHeight;    /* the min lines */
209     HI_U32 u32VDefLevel;    /* vertical deflicker level, 0 means vertical deflicker is unsupported */
210     HI_U32 u32HDefLevel;    /* horizontal deflicker level, 0 means horizontal deflicker is unsupported */
211     HI_BOOL bDcmp;
212     HI_BOOL bPreMul;
213     HI_BOOL bGHDR; /* NEW Feature. Is GHDR supported. */
214 } HIFB_CAPABILITY_S;
215 
216 /* refresh mode */
217 typedef enum {
218     HIFB_LAYER_BUF_DOUBLE = 0x0, /* 2 display buf in fb */
219     HIFB_LAYER_BUF_ONE = 0x1,    /* 1 display buf in fb */
220     HIFB_LAYER_BUF_NONE = 0x2,   /* no display buf in fb,the buf user refreshed will be directly set to VO */
221     HIFB_LAYER_BUF_DOUBLE_IMMEDIATE = 0x3, /* 2 display buf in fb, each refresh will be displayed */
222     HIFB_LAYER_BUF_FENCE = 0x4,            /* 2 display buf in fb with fence */
223     HIFB_LAYER_BUF_BUTT
224 } HIFB_LAYER_BUF_E;
225 
226 /* surface info */
227 typedef struct {
228     HI_U64 u64PhyAddr;                   /* start physical address */
229     HI_U64 u64GBPhyAddr;
230     HI_U32 u32Width;                     /* width pixels */
231     HI_U32 u32Height;                    /* height pixels */
232     HI_U32 u32Pitch;                     /* line pixels */
233     HIFB_COLOR_FMT_E enFmt;              /* color format */
234     HIFB_DYNAMIC_RANGE_E enDynamicRange; /* NEW dynamic range. */
235 } HIFB_SURFACE_S;
236 
237 typedef struct {
238     HI_U64 u64PhyAddr;
239     HIFB_ALPHA_S stAlpha;
240     HIFB_COLORKEY_S stColorkey;
241 } HIFB_SURFACEEX_S;
242 
243 /* refresh surface info */
244 typedef struct {
245     HIFB_SURFACE_S stCanvas;
246     HIFB_RECT UpdateRect; /* refresh region */
247 } HIFB_BUFFER_S;
248 
249 /* cursor info */
250 typedef struct {
251     HIFB_SURFACE_S stCursor;
252     HIFB_POINT_S stHotPos;
253 } HIFB_CURSOR_S;
254 
255 /* DDR detect zone info */
256 typedef struct {
257     HI_U32 u32StartSection;
258     HI_U32 u32ZoneNums;
259 } HIFB_DDRZONE_S;
260 
261 /* cursor handle */
262 /* Attention:surface in cursor will be released by user */
263 #define FBIOPUT_CURSOR_INFO _IOW(IOC_TYPE_HIFB, 104, HIFB_CURSOR_S)
264 #define FBIOGET_CURSOR_INFO _IOW(IOC_TYPE_HIFB, 105, HIFB_CURSOR_S)
265 
266 #define FBIOPUT_CURSOR_STATE _IOW(IOC_TYPE_HIFB, 106, HI_BOOL)
267 #define FBIOGET_CURSOR_STATE _IOW(IOC_TYPE_HIFB, 107, HI_BOOL)
268 
269 #define FBIOPUT_CURSOR_POS _IOW(IOC_TYPE_HIFB, 108, HIFB_POINT_S)
270 #define FBIOGET_CURSOR_POS _IOR(IOC_TYPE_HIFB, 109, HIFB_POINT_S)
271 
272 #define FBIOPUT_CURSOR_COLORKEY _IOR(IOC_TYPE_HIFB, 110, HIFB_COLORKEY_S)
273 #define FBIOGET_CURSOR_COLORKEY _IOW(IOC_TYPE_HIFB, 111, HIFB_COLORKEY_S)
274 #define FBIOPUT_CURSOR_ALPHA _IOR(IOC_TYPE_HIFB, 112, HIFB_ALPHA_S)
275 #define FBIOGET_CURSOR_ALPHA _IOW(IOC_TYPE_HIFB, 113, HIFB_ALPHA_S)
276 
277 /*
278  * cursor will be separated from attached layer automatically if you attach cursor to another layer,that means
279  * cursor can be attached to only one layer at any time
280  */
281 #define FBIOPUT_CURSOR_ATTCHCURSOR _IOW(IOC_TYPE_HIFB, 114, HI_U32)
282 #define FBIOPUT_CURSOR_DETACHCURSOR _IOW(IOC_TYPE_HIFB, 115, HI_U32)
283 
284 /* Auto means fb will choose a appropriate antiflicker level automatically according to the color info of map */
285 typedef enum {
286     HIFB_LAYER_ANTIFLICKER_NONE = 0x0,   /* no antiflicker */
287     HIFB_LAYER_ANTIFLICKER_LOW = 0x1,    /* low level */
288     HIFB_LAYER_ANTIFLICKER_MIDDLE = 0x2, /* middle level */
289     HIFB_LAYER_ANTIFLICKER_HIGH = 0x3,   /* high level */
290     HIFB_LAYER_ANTIFLICKER_AUTO = 0x4,   /* auto */
291     HIFB_LAYER_ANTIFLICKER_BUTT
292 } HIFB_LAYER_ANTIFLICKER_LEVEL_E;
293 
294 /* MIRROR mode */
295 typedef enum {
296     HIFB_MIRROR_NONE = 0x0,
297     HIFB_MIRROR_HORIZONTAL = 0x1,
298     HIFB_MIRROR_VERTICAL = 0x2,
299     HIFB_MIRROR_BOTH = 0x3,
300     HIFB_MIRROR_BUTT
301 } HIFB_MIRROR_MODE_E;
302 
303 /* ROTATE mode */
304 typedef enum {
305     HIFB_ROTATE_NONE = 0x0,
306     HIFB_ROTATE_90 = 0x1,
307     HIFB_ROTATE_180 = 0x2,
308     HIFB_ROTATE_270 = 0x3,
309     HIFB_ROTATE_BUTT
310 } HIFB_ROTATE_MODE_E;
311 
312 /* layer info maskbit */
313 typedef enum {
314     HIFB_LAYERMASK_BUFMODE = 0x1,          /* BUFMODE bitmask */
315     HIFB_LAYERMASK_ANTIFLICKER_MODE = 0x2, /* ANTIFLICKER_MODE bitmask */
316     HIFB_LAYERMASK_POS = 0x4,              /* the position bitmask */
317     HIFB_LAYERMASK_CANVASSIZE = 0x8,       /* canvassize bitmask */
318     HIFB_LAYERMASK_DISPSIZE = 0x10,        /* displaysize bitmask */
319     HIFB_LAYERMASK_SCREENSIZE = 0x20,      /* screensize bitmask */
320     HIFB_LAYERMASK_BMUL = 0x40,            /* pre-mult bitmask */
321     HIFB_LAYERMASK_BUTT
322 } HIFB_LAYER_INFO_MASKBIT;
323 
324 /* layer info */
325 typedef struct {
326     HIFB_LAYER_BUF_E BufMode;
327     HIFB_LAYER_ANTIFLICKER_LEVEL_E eAntiflickerLevel;
328     HI_S32 s32XPos;          /* the x pos of origin point in screen */
329     HI_S32 s32YPos;          /* the y pos of origin point in screen */
330     HI_U32 u32CanvasWidth;   /* the width of canvas buffer */
331     HI_U32 u32CanvasHeight;  /* the height of canvas buffer */
332     /* the width of display buf in fb.for 0 buf ,there is no display buf in fb, so it's effectless */
333     HI_U32 u32DisplayWidth;
334     HI_U32 u32DisplayHeight; /* the height of display buf in fb. */
335     HI_U32 u32ScreenWidth;   /* the width of screen */
336     HI_U32 u32ScreenHeight;  /* the height of screen */
337     HI_BOOL bPreMul;         /* The data drawn in buf is premul data or not */
338     HI_U32 u32Mask;          /* param modify mask bit */
339 } HIFB_LAYER_INFO_S;
340 
341 /* To set the layer information */
342 #define FBIOPUT_LAYER_INFO _IOW(IOC_TYPE_HIFB, 120, HIFB_LAYER_INFO_S)
343 /* To get the layer information */
344 #define FBIOGET_LAYER_INFO _IOR(IOC_TYPE_HIFB, 121, HIFB_LAYER_INFO_S)
345 /* To get canvas buf */
346 #define FBIOGET_CANVAS_BUFFER _IOR(IOC_TYPE_HIFB, 123, HIFB_BUFFER_S)
347 /* To refresh the displayed contents in extended mode */
348 #define FBIO_REFRESH _IOW(IOC_TYPE_HIFB, 124, HIFB_BUFFER_S)
349 
350 /* sync refresh */
351 #define FBIO_WAITFOR_FREFRESH_DONE _IO(IOC_TYPE_HIFB, 125)
352 
353 /* To set the mirror mode */
354 #define FBIOPUT_MIRROR_MODE _IOW(IOC_TYPE_HIFB, 126, HIFB_MIRROR_MODE_E)
355 /* To get the mirror mode */
356 #define FBIOGET_MIRROR_MODE _IOW(IOC_TYPE_HIFB, 127, HIFB_MIRROR_MODE_E)
357 
358 /* To set the rotate mode */
359 #define FBIOPUT_ROTATE_MODE _IOW(IOC_TYPE_HIFB, 128, HIFB_ROTATE_MODE_E)
360 /* To get the rotate mode */
361 #define FBIOGET_ROTATE_MODE _IOW(IOC_TYPE_HIFB, 129, HIFB_ROTATE_MODE_E)
362 
363 /* To set the DDR detect zone of an overlay layer */
364 #define FBIOPUT_MDDRDETECT_HIFB _IOW(IOC_TYPE_HIFB, 135, HIFB_DDRZONE_S)
365 /* To get the DDR detect zone of an overlay layer */
366 #define FBIOGET_MDDRDETECT_HIFB _IOW(IOC_TYPE_HIFB, 136, HIFB_DDRZONE_S)
367 
368 #ifdef __HuaweiLite__
369 #define FBIOGET_SCREENINFO_HIFB 0x4600
370 #define FBIOPUT_SCREENINFO_HIFB 0x4601
371 #define FBIOPAN_DISPLAY_HIFB 0x4606
372 
373 struct hifb_info {
374     struct fb_vtable_s vtable;     /* FB interfaces */
375     struct fb_videoinfo_s vinfo;   /* This structure descrides the overall video controller */
376     struct fb_overlayinfo_s oinfo; /* This structure descrides one overlay */
377 #ifdef CONFIG_FB_CMAP
378     struct fb_cmap_s cmap; /* Current camp */
379 #endif
380     int activate;
381     void *par; /* Private data */
382 };
383 
384 HI_S32 hifb_init(hi_void *pArgs);
385 #endif
386 
387 #ifdef __cplusplus
388 #if __cplusplus
389 }
390 #endif
391 #endif /* __cplusplus */
392 
393 #endif /* __HIFB_H__ */
394