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