38b57a4b55a174ecdba50d472578d3799cea155f
[platform/adaptation/ap_samsung/libexynos-common.git] / include / exynos_gscaler.h
1 /*
2  *
3  * Copyright 2012 Samsung Electronics S.LSI Co. LTD
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 /*!
19  * \file      exynos_gscaler.h
20  * \brief     header file for Gscaler HAL
21  * \author    ShinWon Lee (shinwon.lee@samsung.com)
22  * \date      2012/01/09
23  *
24  * <b>Revision History: </b>
25  * - 2012/01/09 : ShinWon Lee(shinwon.lee@samsung.com) \n
26  *   Create
27  *
28  * - 2012/02/07 : ShinWon Lee(shinwon.lee@samsung.com) \n
29  *   Change file name to exynos_gscaler.h
30  *
31  * - 2012/02/09 : Sangwoo, Parkk(sw5771.park@samsung.com) \n
32  *   Use Multiple Gscaler by Multiple Process
33  *
34  * - 2012/02/20 : Sangwoo, Park(sw5771.park@samsung.com) \n
35  *   Add exynos_gsc_set_rotation() API
36  *
37  * - 2012/02/20 : ShinWon Lee(shinwon.lee@samsung.com) \n
38  *   Add size constrain
39  *
40  */
41
42 /*!
43  * \defgroup exynos_gscaler
44  * \brief API for gscaler
45  * \addtogroup Exynos
46  */
47
48 #ifndef EXYNOS_GSCALER_H_
49 #define EXYNOS_GSCALER_H_
50
51 #include <stdint.h>
52
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56
57 //#define EXYNOS_GSC_TRACE 1
58 #ifdef EXYNOS_GSC_TRACE
59 #define EXYNOS_GSC_LOG_TAG "Exynos_gscaler"
60 #define Exynos_gsc_In() Exynos_Log(EXYNOS_DEV_LOG_DEBUG, EXYNOS_GSC_LOG_TAG, "%s In , Line: %d", __FUNCTION__, __LINE__)
61 #define Exynos_gsc_Out() Exynos_Log(EXYNOS_DEV_LOG_DEBUG, EXYNOS_GSC_LOG_TAG, "%s Out , Line: %d", __FUNCTION__, __LINE__)
62 #else
63 #define Exynos_gsc_In() ((void *)0)
64 #define Exynos_gsc_Out() ((void *)0)
65 #endif
66
67 typedef struct {
68     uint32_t x;
69     uint32_t y;
70     uint32_t w;
71     uint32_t h;
72     uint32_t fw;
73     uint32_t fh;
74     uint32_t format;
75     unsigned long yaddr;
76     unsigned long uaddr;
77     unsigned long vaddr;
78     uint32_t rot;
79     uint32_t cacheable;
80     uint32_t drmMode;
81     uint32_t narrowRgb;
82     int      acquireFenceFd;
83     int      releaseFenceFd;
84     int      mem_type;
85     uint32_t pre_multi;
86 } exynos_mpp_img;
87
88 enum SRC_BL_OP {
89         /* [0, 0] */
90         SRC_BL_OP_CLR = 1,
91         /* [Sa, Sc] */
92         SRC_BL_OP_SRC,
93         /* [Da, Dc] */
94         SRC_BL_OP_DST,
95         /* [Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc] */
96         SRC_BL_OP_SRC_OVER,
97         /* [Sa + (1 - Sa)*Da, Rc = Dc + (1 - Da)*Sc] */
98         SRC_BL_OP_DST_OVER,
99         /* [Sa * Da, Sc * Da] */
100         SRC_BL_OP_SRC_IN,
101         /* [Sa * Da, Sa * Dc] */
102         SRC_BL_OP_DST_IN,
103         /* [Sa * (1 - Da), Sc * (1 - Da)] */
104         SRC_BL_OP_SRC_OUT,
105         /* [Da * (1 - Sa), Dc * (1 - Sa)] */
106         SRC_BL_OP_DST_OUT,
107         /* [Da, Sc * Da + (1 - Sa) * Dc] */
108         SRC_BL_OP_SRC_ATOP,
109         /* [Sa, Sc * (1 - Da) + Sa * Dc ] */
110         SRC_BL_OP_DST_ATOP,
111         /* [-(Sa * Da), Sc * (1 - Da) + (1 - Sa) * Dc] */
112         SRC_BL_OP_XOR,
113         /* [Sa + Da - Sa*Da, Sc*(1 - Da) + Dc*(1 - Sa) + min(Sc, Dc)] */
114         SRC_BL_OP_DARKEN,
115         /* [Sa + Da - Sa*Da, Sc*(1 - Da) + Dc*(1 - Sa) + max(Sc, Dc)] */
116         SRC_BL_OP_LIGHTEN,
117         /** [Sa * Da, Sc * Dc] */
118         SRC_BL_OP_MULTIPLY,
119         /* [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc] */
120         SRC_BL_OP_SCREEN,
121         /* Saturate(S + D) */
122         SRC_BL_OP_ADD
123 };
124
125 enum colorspace {
126     COLORSPACE_SMPTE170M,
127     COLORSPACE_SMPTE240M,
128     COLORSPACE_REC709,
129     COLORSPACE_BT878,
130     COLORSPACE_470_SYSTEM_M,
131     COLORSPACE_470_SYSTEM_BG,
132     COLORSPACE_JPEG,
133     COLORSPACE_SRGB,
134 };
135
136 struct SrcGlobalAlpha {
137         uint32_t enable;
138         unsigned int val;
139 };
140
141 struct CSC_Spec{
142         uint32_t enable;    // set 'true' for user-defined
143         enum colorspace space;
144         uint32_t wide;
145 };
146
147 struct SrcBlendInfo {
148         enum SRC_BL_OP blop;
149         unsigned int srcblendfmt;
150         unsigned int srcblendhpos;
151         unsigned int srcblendvpos;
152         unsigned int srcblendpremulti;
153         unsigned int srcblendstride;
154         unsigned int srcblendwidth;
155         unsigned int srcblendheight;
156         struct SrcGlobalAlpha globalalpha;
157         struct CSC_Spec cscspec;
158 };
159
160 /*
161  * Create libgscaler handle.
162  * Gscaler dev_num is dynamically changed.
163  *
164  * \ingroup exynos_gscaler
165  *
166  * \return
167  *   libgscaler handle
168  */
169 void *exynos_gsc_create(
170     void);
171
172 /*!
173  * Create exclusive libgscaler handle.
174  * Other module can't use dev_num of Gscaler.
175  *
176  * \ingroup exynos_gscaler
177  *
178  * \param dev_num
179  *   gscaler dev_num[in]
180  * \param gsc_mode
181  *It should be set to GSC_M2M_MODE or GSC_OUTPUT_MODE.
182  *
183  *\param out_mode
184  *It should be set to GSC_OUT_FIMD or GSC_OUT_TV.
185  *
186  * \return
187  *   libgscaler handle
188  */
189 void *exynos_gsc_create_exclusive(
190     int dev_num,
191     int gsc_mode,
192     int out_mode,
193     int allow_drm);
194
195 /*!
196  * Destroy libgscaler handle
197  *
198  * \ingroup exynos_gscaler
199  *
200  * \param handle
201  *   libgscaler handle[in]
202  */
203 void exynos_gsc_destroy(
204     void *handle);
205
206 /*!
207  * Set csc equation property
208  *
209  * \ingroup exynos_gscaler
210  *
211  * \param handle
212  *   libgscaler handle[in]
213  *
214  * \param eq_auto
215  *   csc mode (0: user, 1: auto)[in]
216  *
217  * \param range_full
218  *   csc range (0: narrow, 1: full)[in]
219  *
220  * \param v4l2_colorspace
221  *   ITU_R v4l2 colorspace(1: 601, 3: 709)[in]
222  */
223 int exynos_gsc_set_csc_property(
224     void        *handle,
225     unsigned int eq_auto,
226     unsigned int range_full,
227     unsigned int v4l2_colorspace);
228
229 /*!
230  * Set source format.
231  *
232  * \ingroup exynos_gscaler
233  *
234  * \param handle
235  *   libgscaler handle[in]
236  *
237  * \param width
238  *   image width[in]
239  *
240  * \param height
241  *   image height[in]
242  *
243  * \param crop_left
244  *   image left crop size[in]
245  *
246  * \param crop_top
247  *   image top crop size[in]
248  *
249  * \param crop_width
250  *   cropped image width[in]
251  *
252  * \param crop_height
253  *   cropped image height[in]
254  *
255  * \param v4l2_colorformat
256  *   color format[in]
257  *
258  * \param cacheable
259  *   ccacheable[in]
260  *
261  * \param mode_drm
262  *   mode_drm[in]
263  *
264  * \return
265  *   error code
266  */
267 int exynos_gsc_set_src_format(
268     void        *handle,
269     unsigned int width,
270     unsigned int height,
271     unsigned int crop_left,
272     unsigned int crop_top,
273     unsigned int crop_width,
274     unsigned int crop_height,
275     unsigned int v4l2_colorformat,
276     unsigned int cacheable,
277     unsigned int mode_drm);
278
279 /*!
280  * Set destination format.
281  *
282  * \ingroup exynos_gscaler
283  *
284  * \param handle
285  *   libgscaler handle[in]
286  *
287  * \param width
288  *   image width[in]
289  *
290  * \param height
291  *   image height[in]
292  *
293  * \param crop_left
294  *   image left crop size[in]
295  *
296  * \param crop_top
297  *   image top crop size[in]
298  *
299  * \param crop_width
300  *   cropped image width[in]
301  *
302  * \param crop_height
303  *   cropped image height[in]
304  *
305  * \param v4l2_colorformat
306  *   color format[in]
307  *
308  * \param cacheable
309  *   ccacheable[in]
310  *
311  * \param mode_drm
312  *   mode_drm[in]
313  *
314  * \return
315  *   error code
316  */
317 int exynos_gsc_set_dst_format(
318     void        *handle,
319     unsigned int width,
320     unsigned int height,
321     unsigned int crop_left,
322     unsigned int crop_top,
323     unsigned int crop_width,
324     unsigned int crop_height,
325     unsigned int v4l2_colorformat,
326     unsigned int cacheable,
327     unsigned int mode_drm);
328
329 /*!
330  * Set rotation.
331  *
332  * \ingroup exynos_gscaler
333  *
334  * \param handle
335  *   libgscaler handle[in]
336  *
337  * \param rotation
338  *   image rotation. It should be multiple of 90[in]
339  *
340  * \param flip_horizontal
341  *   image flip_horizontal[in]
342  *
343  * \param flip_vertical
344  *   image flip_vertical[in]
345  *
346  * \return
347  *   error code
348  */
349 int exynos_gsc_set_rotation(
350     void *handle,
351     int   rotation,
352     int   flip_horizontal,
353     int   flip_vertical);
354
355 /*!
356  * Set source buffer
357  *
358  * \ingroup exynos_gscaler
359  *
360  * \param handle
361  *   libgscaler handle[in]
362  *
363  * \param addr
364  *   buffer pointer array[in]
365  *
366  * \param acquireFenceFd
367  *   acquire fence fd for the buffer or -1[in]
368  *
369  * \return
370  *   error code
371  */
372 int exynos_gsc_set_src_addr(
373     void *handle,
374     void *addr[3],
375     int mem_type,
376     int acquireFenceFd);
377
378 /*!
379  * Set destination buffer
380  *
381  * \param handle
382  *   libgscaler handle[in]
383  *
384  * \param addr
385  *   buffer pointer array[in]
386  *
387  * \param acquireFenceFd
388  *   acquire fence fd for the buffer or -1[in]
389  *
390  * \return
391  *   error code
392  */
393 int exynos_gsc_set_dst_addr(
394     void *handle,
395     void *addr[3],
396     int mem_type,
397     int acquireFenceFd);
398
399 /*!
400  * Convert color space with presetup color format
401  *
402  * \ingroup exynos_gscaler
403  *
404  * \param handle
405  *   libgscaler handle[in]
406  *
407  * \return
408  *   error code
409  */
410 int exynos_gsc_convert(
411     void *handle);
412
413 /*
414  * API for setting GSC subdev crop
415  * Used in OTF mode
416  */
417 int exynos_gsc_subdev_s_crop(
418         void *handle,
419         exynos_mpp_img *src_img,
420         exynos_mpp_img *dst_img);
421
422 /*
423 *api for setting the GSC config.
424 It configures the GSC for given config
425 */
426 int exynos_gsc_config_exclusive(
427     void *handle,
428     exynos_mpp_img *src_img,
429     exynos_mpp_img *dst_img);
430
431 /*
432 *api for GSC-OUT run.
433 It queues the srcBuf to GSC and deques a buf from driver.
434 It should be called after configuring the GSC.
435 */
436 int exynos_gsc_run_exclusive(
437     void *handle,
438     exynos_mpp_img *src_img,
439     exynos_mpp_img *dst_img);
440
441 /*!
442  * Create exclusive libgscaler blend handle.
443  * Other module can't use dev_num of Gscaler.
444  *
445  * \ingroup exynos_gscaler
446  *
447  * \param dev_num
448  *   gscaler dev_num[in]
449  * \param gsc_mode
450  * \return
451  *   libgscaler handle
452  */
453 void *exynos_gsc_create_blend_exclusive(
454     int dev_num,
455     int gsc_mode,
456     int out_mode,
457     int allow_drm);
458
459 /*
460 *api for setting the GSC blend config.
461 It configures the GSC for given config
462 */
463 int exynos_gsc_config_blend_exclusive(
464     void *handle,
465     exynos_mpp_img *src_img,
466     exynos_mpp_img *dst_img,
467     struct SrcBlendInfo  *srcblendinfo);
468
469 /*
470  * Blocks until the current frame is done processing.
471  */
472 int exynos_gsc_wait_frame_done_exclusive
473 (void *handle);
474
475 /*
476 *api for GSC stop.
477 It stops the GSC OUT streaming.
478 */
479 int exynos_gsc_stop_exclusive
480 (void *handle);
481
482 /*
483 *api for GSC free_and_close.
484 */
485 int exynos_gsc_free_and_close
486 (void *handle);
487
488 enum {
489     GSC_M2M_MODE = 0,
490     GSC_OUTPUT_MODE,
491     GSC_CAPTURE_MODE,
492     GSC_RESERVED_MODE,
493 };
494
495 /*flag info */
496 enum {
497     GSC_DUMMY = 0,
498     GSC_OUT_FIMD,
499     GSC_OUT_TV,
500     GSC_RESERVED,
501 };
502
503 enum {
504     GSC_DONE_CNG_CFG = 0,
505     GSC_NEED_CNG_CFG,
506 };
507
508 enum {
509     GSC_MEM_MMAP = 1,
510     GSC_MEM_USERPTR,
511     GSC_MEM_OVERLAY,
512     GSC_MEM_DMABUF,
513 };
514
515 #ifdef __cplusplus
516 }
517 #endif
518
519 #endif /*EXYNOS_GSCALER_H_*/