1 /**************************************************************************
3 xserver-xorg-video-exynos
5 Copyright 2010 - 2011 Samsung Electronics co., Ltd. All Rights Reserved.
7 Contact: Boram Park <boram1288.park@samsung.com>
9 Permission is hereby granted, free of charge, to any person obtaining a
10 copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sub license, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial portions
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
24 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
25 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 **************************************************************************/
31 #ifndef __SEC_UTIL_H__
32 #define __SEC_UTIL_H__
42 #include "sec_display.h"
43 #include "sec_video_types.h"
44 #include "sec_xberc.h"
46 #define MFB XDBG_M('F','B',0,0)
47 #define MDISP XDBG_M('D','I','S','P')
48 #define MLYR XDBG_M('L','Y','R',0)
49 #define MPLN XDBG_M('P','L','N',0)
50 #define MSEC XDBG_M('S','E','C',0)
51 #define MEXA XDBG_M('E','X','A',0)
52 #define MEXAS XDBG_M('E','X','A','S')
53 #define MEVT XDBG_M('E','V','T',0)
54 #define MDRI2 XDBG_M('D','R','I','2')
55 #define MDRI3 XDBG_M('D','R','I','3')
56 #define MCRS XDBG_M('C','R','S',0)
57 #define MFLIP XDBG_M('F','L','I','P')
58 #define MDPMS XDBG_M('D','P','M','S')
59 #define MVDO XDBG_M('V','D','O',0)
60 #define MDA XDBG_M('D','A',0,0)
61 #define MTVO XDBG_M('T','V','O',0)
62 #define MWB XDBG_M('W','B',0,0)
63 #define MVA XDBG_M('V','A',0,0)
64 #define MPROP XDBG_M('P','R','O','P')
65 #define MXBRC XDBG_M('X','B','R','C')
66 #define MVBUF XDBG_M('V','B','U','F')
67 #define MDRM XDBG_M('D','R','M',0)
68 #define MACCE XDBG_M('A','C','C','E')
69 #define MCVT XDBG_M('C','V','T',0)
70 #define MEXAH XDBG_M('E','X','A','H')
71 #define MG2D XDBG_M('G','2','D',0)
72 #define MDOUT XDBG_M('D','O','T',0)
74 #define _XID(win) ((unsigned int)(((WindowPtr)win)->drawable.id))
76 #define UTIL_DUMP_OK 0
77 #define UTIL_DUMP_ERR_OPENFILE 1
78 #define UTIL_DUMP_ERR_SHMATTACH 2
79 #define UTIL_DUMP_ERR_SEGSIZE 3
80 #define UTIL_DUMP_ERR_CONFIG 4
81 #define UTIL_DUMP_ERR_INTERNAL 5
85 #define DUMP_DIR "/tmp/xdump"
87 int secUtilDumpBmp (const char * file, const void * data, int width, int height);
88 int secUtilDumpRaw (const char * file, const void * data, int size);
89 int secUtilDumpShm (int shmid, const void * data, int width, int height);
90 int secUtilDumpPixmap (const char * file, PixmapPtr pPixmap);
92 void* secUtilPrepareDump (ScrnInfoPtr pScrn, int bo_size, int buf_cnt);
93 void secUtilDoDumpRaws (void *dump, tbm_bo *bo, int *size, int bo_cnt, const char *file);
94 void secUtilDoDumpBmps (void *d, tbm_bo bo, int w, int h, xRectangle *crop, const char *file);
95 void secUtilDoDumpPixmaps (void *d, PixmapPtr pPixmap, const char *file);
96 void secUtilDoDumpVBuf (void *d, SECVideoBuf *vbuf, const char *file);
97 void secUtilFlushDump (void *dump);
98 void secUtilFinishDump (void *dump);
100 int secUtilDegreeToRotate (int degree);
101 int secUtilRotateToDegree (int rotate);
102 int secUtilRotateAdd (int rot_a, int rot_b);
104 void secUtilCacheFlush (ScrnInfoPtr scrn);
106 void* secUtilCopyImage (int width, int height,
107 char *s, int s_size_w, int s_size_h,
108 int *s_pitches, int *s_offsets, int *s_lengths,
109 char *d, int d_size_w, int d_size_h,
110 int *d_pitches, int *d_offsets, int *d_lengths,
111 int channel, int h_sampling, int v_sampling);
113 void secUtilRotateArea (int *width, int *height, xRectangle *rect, int degree);
114 void secUtilRotateRect2 (int width, int height, xRectangle *rect, int degree, const char *func);
115 #define secUtilRotateRect(w,h,r,d) secUtilRotateRect2(w,h,r,d,__FUNCTION__)
116 void secUtilRotateRegion (int width, int height, RegionPtr region, int degree);
118 void secUtilAlignRect (int src_w, int src_h, int dst_w, int dst_h, xRectangle *fit, Bool hw);
119 void secUtilScaleRect (int src_w, int src_h, int dst_w, int dst_h, xRectangle *scale);
121 const PropertyPtr secUtilGetWindowProperty (WindowPtr pWin, const char* prop_name);
123 int secUtilBoxInBox (BoxPtr base, BoxPtr box);
124 int secUtilBoxArea(BoxPtr pBox);
125 int secUtilBoxIntersect(BoxPtr pDstBox, BoxPtr pBox1, BoxPtr pBox2);
126 void secUtilBoxMove(BoxPtr pBox, int dx, int dy);
128 Bool secUtilRectIntersect (xRectanglePtr pDest, xRectanglePtr pRect1, xRectanglePtr pRect2);
130 void secUtilSaveImage (pixman_image_t *image, char *path);
131 Bool secUtilConvertImage (pixman_op_t op, uchar *srcbuf, uchar *dstbuf,
132 pixman_format_code_t src_format, pixman_format_code_t dst_format,
133 int sw, int sh, xRectangle *sr,
134 int dw, int dh, xRectangle *dr,
135 RegionPtr dst_clip_region,
136 int rotate, int hflip, int vflip);
138 void secUtilConvertBos (ScrnInfoPtr pScrn, int src_id,
139 tbm_bo src_bo, int sw, int sh, xRectangle *sr, int sstride,
140 tbm_bo dst_bo, int dw, int dh, xRectangle *dr, int dstride,
141 Bool composite, int rotate);
143 void secUtilFreeHandle (ScrnInfoPtr scrn, unsigned int handle);
144 Bool secUtilConvertPhyaddress (ScrnInfoPtr scrn, unsigned int phy_addr, int size, unsigned int *handle);
145 Bool secUtilConvertHandle (ScrnInfoPtr scrn, unsigned int handle, unsigned int *phy_addr, int *size);
147 typedef void (*DestroyDataFunc) (void *func_data, void *key_data);
149 void* secUtilListAdd (void *list, void *key, void *key_data);
150 void* secUtilListRemove (void *list, void *key);
151 void* secUtilListGetData (void *list, void *key);
152 Bool secUtilListIsEmpty (void *list);
153 void secUtilListDestroyData (void *list, DestroyDataFunc func, void *func_data);
154 void secUtilListDestroy (void *list);
156 Bool secUtilSetDrmProperty (SECModePtr pSecMode, unsigned int obj_id, unsigned int obj_type,
157 const char *prop_name, unsigned int value);
159 Bool secUtilEnsureExternalCrtc (ScrnInfoPtr scrn);
161 G2dColorMode secUtilGetG2dFormat (unsigned int id);
162 unsigned int secUtilGetDrmFormat (unsigned int id);
163 SECFormatType secUtilGetColorType (unsigned int id);
165 SECVideoBuf* _secUtilAllocVideoBuffer (ScrnInfoPtr scrn, int id, int width, int height,
166 Bool scanout, Bool reset, Bool secure, const char *func);
167 SECVideoBuf* _secUtilCreateVideoBuffer (ScrnInfoPtr scrn, int id, int width, int height,
168 Bool secure, const char *func);
169 SECVideoBuf* secUtilVideoBufferRef (SECVideoBuf *vbuf);
170 void _secUtilVideoBufferUnref (SECVideoBuf *vbuf, const char *func);
171 void _secUtilFreeVideoBuffer (SECVideoBuf *vbuf, const char *func);
172 void secUtilClearVideoBuffer (SECVideoBuf *vbuf);
173 Bool _secUtilIsVbufValid (SECVideoBuf *vbuf, const char *func);
175 typedef void (*FreeVideoBufFunc) (SECVideoBuf *vbuf, void *data);
176 void secUtilAddFreeVideoBufferFunc (SECVideoBuf *vbuf, FreeVideoBufFunc func, void *data);
177 void secUtilRemoveFreeVideoBufferFunc (SECVideoBuf *vbuf, FreeVideoBufFunc func, void *data);
179 #define secUtilAllocVideoBuffer(s,i,w,h,c,r,d) _secUtilAllocVideoBuffer(s,i,w,h,c,r,d,__FUNCTION__)
180 #define secUtilCreateVideoBuffer(s,i,w,h,d) _secUtilCreateVideoBuffer(s,i,w,h,d,__FUNCTION__)
181 #define secUtilVideoBufferUnref(v) _secUtilVideoBufferUnref(v,__FUNCTION__)
182 #define secUtilFreeVideoBuffer(v) _secUtilFreeVideoBuffer(v,__FUNCTION__)
183 #define secUtilIsVbufValid(v) _secUtilIsVbufValid(v,__FUNCTION__)
184 #define VBUF_IS_VALID(v) secUtilIsVbufValid(v)
185 #define VSTMAP(v) ((v)?(v)->stamp:0)
186 #define VBUF_IS_CONVERTING(v) (!xorg_list_is_empty (&((v)->convert_info)))
188 int findActiveConnector (ScrnInfoPtr pScrn);
191 char* secUtilDumpVideoBuffer (char *reply, int *len);
193 #define list_rev_for_each_entry_safe(pos, tmp, head, member) \
194 for (pos = __container_of((head)->prev, pos, member), tmp = __container_of(pos->member.prev, pos, member);\
195 &pos->member != (head);\
196 pos = tmp, tmp = __container_of(pos->member.prev, tmp, member))
198 #endif /* __SEC_UTIL_H__ */