exynos: fimg2d: remove TRUE/FALSE from header
[platform/upstream/libdrm.git] / exynos / fimg2d.h
1 /*
2  * Copyright (C) 2013 Samsung Electronics Co.Ltd
3  * Authors:
4  *      Inki Dae <inki.dae@samsung.com>
5  *
6  * This program is free software; you can redistribute  it and/or modify it
7  * under  the terms of  the GNU General  Public License as published by the
8  * Free Software Foundation;  either version 2 of the  License, or (at your
9  * option) any later version.
10  *
11  */
12
13 #ifndef _FIMG2D_H_
14 #define _FIMG2D_H_
15
16 #define G2D_MAX_CMD_NR          64
17 #define G2D_MAX_GEM_CMD_NR      64
18 #define G2D_MAX_CMD_LIST_NR     64
19 #define G2D_PLANE_MAX_NR        2
20
21 enum e_g2d_color_mode {
22         /* COLOR FORMAT */
23         G2D_COLOR_FMT_XRGB8888,
24         G2D_COLOR_FMT_ARGB8888,
25         G2D_COLOR_FMT_RGB565,
26         G2D_COLOR_FMT_XRGB1555,
27         G2D_COLOR_FMT_ARGB1555,
28         G2D_COLOR_FMT_XRGB4444,
29         G2D_COLOR_FMT_ARGB4444,
30         G2D_COLOR_FMT_PRGB888,
31         G2D_COLOR_FMT_YCbCr444,
32         G2D_COLOR_FMT_YCbCr422,
33         G2D_COLOR_FMT_YCbCr420,
34         /* alpha 8bit */
35         G2D_COLOR_FMT_A8,
36         /* Luminance 8bit: gray color */
37         G2D_COLOR_FMT_L8,
38         /* alpha 1bit */
39         G2D_COLOR_FMT_A1,
40         /* alpha 4bit */
41         G2D_COLOR_FMT_A4,
42         G2D_COLOR_FMT_MASK,                             /* VER4.1 */
43
44         /* COLOR ORDER */
45         G2D_ORDER_AXRGB         = (0 << 4),             /* VER4.1 */
46         G2D_ORDER_RGBAX         = (1 << 4),             /* VER4.1 */
47         G2D_ORDER_AXBGR         = (2 << 4),             /* VER4.1 */
48         G2D_ORDER_BGRAX         = (3 << 4),             /* VER4.1 */
49         G2D_ORDER_MASK          = (3 << 4),             /* VER4.1 */
50
51         /* Number of YCbCr plane */
52         G2D_YCbCr_1PLANE        = (0 << 8),             /* VER4.1 */
53         G2D_YCbCr_2PLANE        = (1 << 8),             /* VER4.1 */
54         G2D_YCbCr_PLANE_MASK    = (3 << 8),             /* VER4.1 */
55
56         /* Order in YCbCr */
57         G2D_YCbCr_ORDER_CrY1CbY0 = (0 << 12),                   /* VER4.1 */
58         G2D_YCbCr_ORDER_CbY1CrY0 = (1 << 12),                   /* VER4.1 */
59         G2D_YCbCr_ORDER_Y1CrY0Cb = (2 << 12),                   /* VER4.1 */
60         G2D_YCbCr_ORDER_Y1CbY0Cr = (3 << 12),                   /* VER4.1 */
61         G2D_YCbCr_ORDER_CrCb = G2D_YCbCr_ORDER_CrY1CbY0,        /* VER4.1 */
62         G2D_YCbCr_ORDER_CbCr = G2D_YCbCr_ORDER_CbY1CrY0,        /* VER4.1 */
63         G2D_YCbCr_ORDER_MASK = (3 < 12),                        /* VER4.1 */
64
65         /* CSC */
66         G2D_CSC_601 = (0 << 16),                /* VER4.1 */
67         G2D_CSC_709 = (1 << 16),                /* VER4.1 */
68         G2D_CSC_MASK = (1 << 16),               /* VER4.1 */
69
70         /* Valid value range of YCbCr */
71         G2D_YCbCr_RANGE_NARROW = (0 << 17),     /* VER4.1 */
72         G2D_YCbCr_RANGE_WIDE = (1 << 17),       /* VER4.1 */
73         G2D_YCbCr_RANGE_MASK = (1 << 17),       /* VER4.1 */
74
75         G2D_COLOR_MODE_MASK = 0xFFFFFFFF,
76 };
77
78 enum e_g2d_select_mode {
79         G2D_SELECT_MODE_NORMAL  = (0 << 0),
80         G2D_SELECT_MODE_FGCOLOR = (1 << 0),
81         G2D_SELECT_MODE_BGCOLOR = (2 << 0),
82 };
83
84 enum e_g2d_repeat_mode {
85         G2D_REPEAT_MODE_REPEAT,
86         G2D_REPEAT_MODE_PAD,
87         G2D_REPEAT_MODE_REFLECT,
88         G2D_REPEAT_MODE_CLAMP,
89         G2D_REPEAT_MODE_NONE,
90 };
91
92 enum e_g2d_scale_mode {
93         G2D_SCALE_MODE_NONE = 0,
94         G2D_SCALE_MODE_NEAREST,
95         G2D_SCALE_MODE_BILINEAR,
96         G2D_SCALE_MODE_MAX,
97 };
98
99 enum e_g2d_buf_type {
100         G2D_IMGBUF_COLOR,
101         G2D_IMGBUF_GEM,
102         G2D_IMGBUF_USERPTR,
103 };
104
105 enum e_g2d_rop3_type {
106         G2D_ROP3_DST = 0xAA,
107         G2D_ROP3_SRC = 0xCC,
108         G2D_ROP3_3RD = 0xF0,
109         G2D_ROP3_MASK = 0xFF,
110 };
111
112 enum e_g2d_select_alpha_src {
113         G2D_SELECT_SRC_FOR_ALPHA_BLEND, /* VER4.1 */
114         G2D_SELECT_ROP_FOR_ALPHA_BLEND, /* VER4.1 */
115 };
116
117 enum e_g2d_transparent_mode {
118         G2D_TRANSPARENT_MODE_OPAQUE,
119         G2D_TRANSPARENT_MODE_TRANSPARENT,
120         G2D_TRANSPARENT_MODE_BLUESCREEN,
121         G2D_TRANSPARENT_MODE_MAX,
122 };
123
124 enum e_g2d_color_key_mode {
125         G2D_COLORKEY_MODE_DISABLE       = 0,
126         G2D_COLORKEY_MODE_SRC_RGBA      = (1<<0),
127         G2D_COLORKEY_MODE_DST_RGBA      = (1<<1),
128         G2D_COLORKEY_MODE_SRC_YCbCr     = (1<<2),               /* VER4.1 */
129         G2D_COLORKEY_MODE_DST_YCbCr     = (1<<3),               /* VER4.1 */
130         G2D_COLORKEY_MODE_MASK          = 15,
131 };
132
133 enum e_g2d_alpha_blend_mode {
134         G2D_ALPHA_BLEND_MODE_DISABLE,
135         G2D_ALPHA_BLEND_MODE_ENABLE,
136         G2D_ALPHA_BLEND_MODE_FADING,                            /* VER3.0 */
137         G2D_ALPHA_BLEND_MODE_MAX,
138 };
139
140 enum e_g2d_op {
141         G2D_OP_CLEAR                    = 0x00,
142         G2D_OP_SRC                      = 0x01,
143         G2D_OP_DST                      = 0x02,
144         G2D_OP_OVER                     = 0x03,
145         G2D_OP_DISJOINT_CLEAR           = 0x10,
146         G2D_OP_DISJOINT_SRC             = 0x11,
147         G2D_OP_DISJOINT_DST             = 0x12,
148         G2D_OP_CONJOINT_CLEAR           = 0x20,
149         G2D_OP_CONJOINT_SRC             = 0x21,
150         G2D_OP_CONJOINT_DST             = 0x22,
151 };
152
153 enum e_g2d_coeff_mode {
154         G2D_COEFF_MODE_ONE,
155         G2D_COEFF_MODE_ZERO,
156         G2D_COEFF_MODE_SRC_ALPHA,
157         G2D_COEFF_MODE_SRC_COLOR,
158         G2D_COEFF_MODE_DST_ALPHA,
159         G2D_COEFF_MODE_DST_COLOR,
160         /* Global Alpha : Set by ALPHA_REG(0x618) */
161         G2D_COEFF_MODE_GB_ALPHA,
162         /* Global Alpha : Set by ALPHA_REG(0x618) */
163         G2D_COEFF_MODE_GB_COLOR,
164         /* (1-SRC alpha)/DST Alpha */
165         G2D_COEFF_MODE_DISJOINT_S,
166         /* (1-DST alpha)/SRC Alpha */
167         G2D_COEFF_MODE_DISJOINT_D,
168         /* SRC alpha/DST alpha */
169         G2D_COEFF_MODE_CONJOINT_S,
170         /* DST alpha/SRC alpha */
171         G2D_COEFF_MODE_CONJOINT_D,
172         /* DST alpha/SRC alpha */
173         G2D_COEFF_MODE_MASK
174 };
175
176 enum e_g2d_acoeff_mode {
177         G2D_ACOEFF_MODE_A,          /* alpha */
178         G2D_ACOEFF_MODE_APGA,   /* alpha + global alpha */
179         G2D_ACOEFF_MODE_AMGA,   /* alpha * global alpha */
180         G2D_ACOEFF_MODE_MASK
181 };
182
183 union g2d_point_val {
184         unsigned int val;
185         struct {
186                 /*
187                  * Coordinate of Source Image
188                  * Range: 0 ~ 8000 (Requirement: SrcLeftX < SrcRightX)
189                  * In YCbCr 422 and YCbCr 420 format with even number.
190                  */
191                 unsigned int x:16;
192                 /*
193                  * Y Coordinate of Source Image
194                  * Range: 0 ~ 8000 (Requirement: SrcTopY < SrcBottomY)
195                  * In YCbCr 420 format with even number.
196                  */
197                 unsigned int y:16;
198         } data;
199 };
200
201 union g2d_rop4_val {
202         unsigned int val;
203         struct {
204                 enum e_g2d_rop3_type    unmasked_rop3:8;
205                 enum e_g2d_rop3_type    masked_rop3:8;
206                 unsigned int            reserved:16;
207         } data;
208 };
209
210 union g2d_bitblt_cmd_val {
211         unsigned int val;
212         struct {
213                 /* [0:3] */
214                 unsigned int                    mask_rop4_en:1;
215                 unsigned int                    masking_en:1;
216                 enum e_g2d_select_alpha_src     rop4_alpha_en:1;
217                 unsigned int                    dither_en:1;
218                 /* [4:7] */
219                 unsigned int                    resolved1:4;
220                 /* [8:11] */
221                 unsigned int                    cw_en:4;
222                 /* [12:15] */
223                 enum e_g2d_transparent_mode     transparent_mode:4;
224                 /* [16:19] */
225                 enum e_g2d_color_key_mode       color_key_mode:4;
226                 /* [20:23] */
227                 enum e_g2d_alpha_blend_mode     alpha_blend_mode:4;
228                 /* [24:27] */
229                 unsigned int src_pre_multiply:1;
230                 unsigned int pat_pre_multiply:1;
231                 unsigned int dst_pre_multiply:1;
232                 unsigned int dst_depre_multiply:1;
233                 /* [28:31] */
234                 unsigned int fast_solid_color_fill_en:1;
235                 unsigned int reserved:3;
236         } data;
237 };
238
239 union g2d_blend_func_val {
240         unsigned int val;
241         struct {
242                 /* [0:15] */
243                 enum e_g2d_coeff_mode src_coeff:4;
244                 enum e_g2d_acoeff_mode src_coeff_src_a:2;
245                 enum e_g2d_acoeff_mode src_coeff_dst_a:2;
246                 enum e_g2d_coeff_mode dst_coeff:4;
247                 enum e_g2d_acoeff_mode dst_coeff_src_a:2;
248                 enum e_g2d_acoeff_mode dst_coeff_dst_a:2;
249                 /* [16:19] */
250                 unsigned int inv_src_color_coeff:1;
251                 unsigned int resoled1:1;
252                 unsigned int inv_dst_color_coeff:1;
253                 unsigned int resoled2:1;
254                 /* [20:23] */
255                 unsigned int lighten_en:1;
256                 unsigned int darken_en:1;
257                 unsigned int win_ce_src_over_en:2;
258                 /* [24:31] */
259                 unsigned int reserved:8;
260         } data;
261 };
262
263 struct g2d_image {
264         enum e_g2d_select_mode          select_mode;
265         enum e_g2d_color_mode           color_mode;
266         enum e_g2d_repeat_mode          repeat_mode;
267         enum e_g2d_scale_mode           scale_mode;
268         unsigned int                    xscale;
269         unsigned int                    yscale;
270         unsigned char                   rotate_90;
271         unsigned char                   x_dir;
272         unsigned char                   y_dir;
273         unsigned char                   component_alpha;
274         unsigned int                    width;
275         unsigned int                    height;
276         unsigned int                    stride;
277         unsigned int                    need_free;
278         unsigned int                    color;
279         enum e_g2d_buf_type             buf_type;
280         unsigned int                    bo[G2D_PLANE_MAX_NR];
281         struct drm_exynos_g2d_userptr   user_ptr[G2D_PLANE_MAX_NR];
282         void                            *mapped_ptr[G2D_PLANE_MAX_NR];
283 };
284
285 struct g2d_context {
286         int                             fd;
287         unsigned int                    major;
288         unsigned int                    minor;
289         struct drm_exynos_g2d_cmd       cmd[G2D_MAX_CMD_NR];
290         struct drm_exynos_g2d_cmd       cmd_buf[G2D_MAX_GEM_CMD_NR];
291         unsigned int                    cmd_nr;
292         unsigned int                    cmd_buf_nr;
293         unsigned int                    cmdlist_nr;
294 };
295
296 struct g2d_context *g2d_init(int fd);
297 void g2d_fini(struct g2d_context *ctx);
298 int g2d_exec(struct g2d_context *ctx);
299 int g2d_solid_fill(struct g2d_context *ctx, struct g2d_image *img,
300                         unsigned int x, unsigned int y, unsigned int w,
301                         unsigned int h);
302 int g2d_copy(struct g2d_context *ctx, struct g2d_image *src,
303                 struct g2d_image *dst, unsigned int src_x,
304                 unsigned int src_y, unsigned int dst_x, unsigned int dst_y,
305                 unsigned int w, unsigned int h);
306 int g2d_copy_with_scale(struct g2d_context *ctx, struct g2d_image *src,
307                                 struct g2d_image *dst, unsigned int src_x,
308                                 unsigned int src_y, unsigned int src_w,
309                                 unsigned int src_h, unsigned int dst_x,
310                                 unsigned int dst_y, unsigned int dst_w,
311                                 unsigned int dst_h, unsigned int negative);
312 int g2d_blend(struct g2d_context *ctx, struct g2d_image *src,
313                 struct g2d_image *dst, unsigned int src_x,
314                 unsigned int src_y, unsigned int dst_x, unsigned int dst_y,
315                 unsigned int w, unsigned int h, enum e_g2d_op op);
316 #endif /* _FIMG2D_H_ */