Initialize Tizen 2.3
[adaptation/xorg/driver/xserver-xorg-module-xdbg.git] / common / xdbg_evlog_xv.c
1 /**************************************************************************
2
3 xdbg
4
5 Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
6
7 Contact: Boram Park <boram1288.park@samsung.com>
8          Sangjin LEE <lsj119@samsung.com>
9
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sub license, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
17
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial portions
20 of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
25 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 **************************************************************************/
31
32 #ifdef HAVE_CONFIG_H
33 #include "config.h"
34 #endif
35
36 #include <stdio.h>
37 #include <string.h>
38 #include <strings.h>
39 #include <sys/types.h>
40 #include <sys/fcntl.h>
41 #include <unistd.h>
42 #include <stdarg.h>
43 #include <fcntl.h>
44 #include <unistd.h>
45
46 #include <dix.h>
47 #define XREGISTRY
48 #include <registry.h>
49 #include <xace.h>
50 #include <xacestr.h>
51 #include <X11/Xatom.h>
52 #include <X11/Xlib.h>
53 #include <windowstr.h>
54
55 #include <X11/extensions/Xvlib.h>
56 #include <X11/extensions/Xv.h>
57 #include <X11/extensions/Xvproto.h>
58
59 #include "xdbg_types.h"
60 #include "xdbg_evlog_xv.h"
61 #include "xdbg_evlog.h"
62
63 static char *
64 _EvlogRequestXv(EvlogInfo *evinfo, int detail_level, char *reply, int *len)
65 {
66     xReq *req = evinfo->req.ptr;
67
68     switch (req->data)
69     {
70     case xv_GrabPort:
71         {
72             xvGrabPortReq *stuff = (xvGrabPortReq *)req;
73             REPLY (": XID(0x%lx)",
74                 stuff->port);
75
76             if (detail_level >= EVLOG_PRINT_DETAIL)
77             {
78                 REPLY (" time(%lums)",
79                     stuff->time);
80             }
81
82             return reply;
83         }
84
85     case xv_UngrabPort:
86         {
87             xvUngrabPortReq *stuff = (xvUngrabPortReq *)req;
88             REPLY (": XID(0x%lx)",
89                 stuff->port);
90
91             if (detail_level >= EVLOG_PRINT_DETAIL)
92             {
93                 REPLY (" time(%lums)",
94                     stuff->time);
95             }
96
97             return reply;
98         }
99
100     case xv_PutStill:
101         {
102             xvPutStillReq *stuff = (xvPutStillReq *)req;
103             REPLY (": XID(0x%lx) Drawable(0x%lx) GC(0x%lx) Vid(%d,%d %dx%d) Drw(%d,%d %dx%d)",
104                 stuff->port,
105                 stuff->drawable,
106                 stuff->gc,
107                 stuff->vid_x,
108                 stuff->vid_y,
109                 stuff->vid_w,
110                 stuff->vid_h,
111                 stuff->drw_x,
112                 stuff->drw_y,
113                 stuff->drw_w,
114                 stuff->drw_h);
115
116             return reply;
117         }
118
119     case xv_GetStill:
120         {
121             xvGetStillReq *stuff = (xvGetStillReq *)req;
122             REPLY (": XID(0x%lx) Drawable(0x%lx) GC(0x%lx) Vid(%d,%d %dx%d) Drw(%d,%d %dx%d)",
123                 stuff->port,
124                 stuff->drawable,
125                 stuff->gc,
126                 stuff->vid_x,
127                 stuff->vid_y,
128                 stuff->vid_w,
129                 stuff->vid_h,
130                 stuff->drw_x,
131                 stuff->drw_y,
132                 stuff->drw_w,
133                 stuff->drw_h);
134
135             return reply;
136         }
137
138     case xv_PutVideo:
139         {
140             xvPutVideoReq *stuff = (xvPutVideoReq *)req;
141             REPLY (": XID(0x%lx) Drawable(0x%lx) GC(0x%lx) Vid(%d,%d %dx%d) Drw(%d,%d %dx%d)",
142                 stuff->port,
143                 stuff->drawable,
144                 stuff->gc,
145                 stuff->vid_x,
146                 stuff->vid_y,
147                 stuff->vid_w,
148                 stuff->vid_h,
149                 stuff->drw_x,
150                 stuff->drw_y,
151                 stuff->drw_w,
152                 stuff->drw_h);
153
154             return reply;
155         }
156
157     case xv_GetVideo:
158         {
159             xvGetVideoReq *stuff = (xvGetVideoReq *)req;
160             REPLY (": XID(0x%lx) Drawable(0x%lx) GC(0x%lx) Vid(%d,%d %dx%d) Drw(%d,%d %dx%d)",
161                 stuff->port,
162                 stuff->drawable,
163                 stuff->gc,
164                 stuff->vid_x,
165                 stuff->vid_y,
166                 stuff->vid_w,
167                 stuff->vid_h,
168                 stuff->drw_x,
169                 stuff->drw_y,
170                 stuff->drw_w,
171                 stuff->drw_h);
172
173             return reply;
174         }
175
176     case xv_StopVideo:
177         {
178             xvStopVideoReq *stuff = (xvStopVideoReq *)req;
179             REPLY (": XID(0x%lx) Drawable(0x%lx)",
180                 stuff->port,
181                 stuff->drawable);
182
183             return reply;
184         }
185
186     case xv_SelectVideoNotify:
187         {
188             xvSelectVideoNotifyReq *stuff = (xvSelectVideoNotifyReq *)req;
189             REPLY (": XID(0x%lx)",
190                 stuff->drawable);
191
192             if (detail_level >= EVLOG_PRINT_DETAIL)
193             {
194                 REPLY ("  On/Off(%s)",
195                     stuff->onoff ? "ON" : "OFF");
196             }
197
198             return reply;
199         }
200
201     case xv_SelectPortNotify:
202         {
203             xvSelectPortNotifyReq *stuff = (xvSelectPortNotifyReq *)req;
204             REPLY (": XID(0x%lx)",
205                 stuff->port);
206
207             if (detail_level >= EVLOG_PRINT_DETAIL)
208             {
209                 REPLY ("  On/Off(%s)",
210                     stuff->onoff ? "ON" : "OFF");
211             }
212
213             return reply;
214         }
215
216     case xv_QueryBestSize:
217         {
218             xvQueryBestSizeReq *stuff = (xvQueryBestSizeReq *)req;
219             REPLY (": XID(0x%lx) VidSize(%dx%d) DrwSize(%dx%d)",
220                 stuff->port,
221                 stuff->vid_w,
222                 stuff->vid_h,
223                 stuff->drw_w,
224                 stuff->drw_h);
225
226             if (detail_level >= EVLOG_PRINT_DETAIL)
227             {
228                 REPLY ("  motion(%d)",
229                     stuff->motion);
230             }
231
232             return reply;
233         }
234
235     case xv_SetPortAttribute:
236         {
237             xvSetPortAttributeReq *stuff = (xvSetPortAttributeReq *)req;
238             REPLY (": XID(0x%lx) ",
239                 stuff->port);
240
241             REPLY (" Attribute");
242             reply = xDbgGetAtom(stuff->attribute, evinfo, reply, len);
243
244             if (detail_level >= EVLOG_PRINT_DETAIL)
245             {
246                 REPLY ("  value(%ld)",
247                     stuff->value);
248             }
249
250             return reply;
251         }
252
253     case xv_GetPortAttribute:
254         {
255             xvGetPortAttributeReq *stuff = (xvGetPortAttributeReq *)req;
256             REPLY (": XID(0x%lx)",
257                 stuff->port);
258
259             REPLY (" Attribute");
260             reply = xDbgGetAtom(stuff->attribute, evinfo, reply, len);
261
262             return reply;
263         }
264
265     case xv_PutImage:
266         {
267             xvPutImageReq *stuff = (xvPutImageReq *)req;
268             REPLY (": XID(0x%lx) Drawable(0x%lx) GC(0x%lx) ID(%lx) buf(%dx%d) src(%d,%d %dx%d) drw(%d,%d %dx%d)",
269                 stuff->port,
270                 stuff->drawable,
271                 stuff->gc,
272                 stuff->id,
273                 stuff->width,
274                 stuff->height,
275                 stuff->src_x,
276                 stuff->src_y,
277                 stuff->src_w,
278                 stuff->src_h,
279                 stuff->drw_x,
280                 stuff->drw_y,
281                 stuff->drw_w,
282                 stuff->drw_h);
283
284             return reply;
285         }
286
287     case xv_ShmPutImage:
288         {
289             xvShmPutImageReq *stuff = (xvShmPutImageReq *)req;
290             REPLY (": XID(0x%lx) Drawable(0x%lx) GC(0x%lx) ID(%lx) buf(%dx%d) src(%d,%d %dx%d) drw(%d,%d %dx%d)",
291                 stuff->port,
292                 stuff->drawable,
293                 stuff->gc,
294                 stuff->id,
295                 stuff->width,
296                 stuff->height,
297                 stuff->src_x,
298                 stuff->src_y,
299                 stuff->src_w,
300                 stuff->src_h,
301                 stuff->drw_x,
302                 stuff->drw_y,
303                 stuff->drw_w,
304                 stuff->drw_h);
305
306             if (detail_level >= EVLOG_PRINT_DETAIL)
307             {
308                 REPLY ("\n");
309                 REPLY ("%67s shmseg(0x%lx) offset(%ld) send_event(%s)",
310                     " ",
311                     stuff->shmseg,
312                     stuff->offset,
313                     stuff->send_event ? "YES" : "NO");
314             }
315
316             return reply;
317         }
318
319     default:
320             break;
321     }
322
323     return reply;
324 }
325
326 static char *
327 _EvlogEventXv (EvlogInfo *evinfo, int first_base, int detail_level, char *reply, int *len)
328 {
329     xEvent *evt = evinfo->evt.ptr;
330
331     switch ((evt->u.u.type & 0x7F) - first_base)
332     {
333     case XvVideoNotify:
334         {
335             XvVideoNotifyEvent *stuff = (XvVideoNotifyEvent *) evt;
336             REPLY (": XID(0x%lx) portID(0x%lx)",
337                 stuff->drawable,
338                 stuff->port_id);
339
340             if (detail_level >= EVLOG_PRINT_DETAIL)
341             {
342                 REPLY (" serial(%lu) reason(%lu) time(%lums)",
343                     stuff->serial,
344                     stuff->reason,
345                     stuff->time);
346             }
347
348             return reply;
349         }
350
351     case XvPortNotify:
352         {
353             XvPortNotifyEvent *stuff = (XvPortNotifyEvent *) evt;
354             REPLY (": XID(0x%lx) Value(%ld)",
355                 stuff->port_id,
356                 stuff->value);
357
358             REPLY (" Attribute");
359             reply = xDbgGetAtom(stuff->attribute, evinfo, reply, len);
360
361             if (detail_level >= EVLOG_PRINT_DETAIL)
362             {
363                 REPLY (" serial(%lu) value(%ld) time(%lums)",
364                     stuff->serial,
365                     stuff->value,
366                     stuff->time);
367             }
368
369             return reply;
370         }
371
372     default:
373             break;
374     }
375
376     return reply;
377 }
378
379 static char *
380 _EvlogReplyXv (EvlogInfo *evinfo, int detail_level, char *reply, int *len)
381 {
382     xGenericReply *rep = evinfo->rep.ptr;
383
384     switch (evinfo->rep.reqData)
385     {
386         case xv_QueryBestSize:
387         {
388             if (evinfo->rep.isStart)
389             {
390                 xvQueryBestSizeReply *stuff = (xvQueryBestSizeReply *)rep;
391                 REPLY (": actualSize(%dx%d)",
392                     stuff->actual_width,
393                     stuff->actual_height);
394             }
395             else
396             {
397                 return reply;
398             }
399
400             return reply;
401         }
402
403     default:
404             break;
405     }
406
407     return reply;
408 }
409
410 void
411 xDbgEvlogXvGetBase (ExtensionInfo *extinfo)
412 {
413 #ifdef XDBG_CLIENT
414     RETURN_IF_FAIL (extinfo != NULL);
415
416     extinfo->req_func = _EvlogRequestXv;
417     extinfo->evt_func = _EvlogEventXv;
418     extinfo->rep_func = _EvlogReplyXv;
419 #else
420     ExtensionEntry *xext = CheckExtension (XvName);
421     RETURN_IF_FAIL (xext != NULL);
422     RETURN_IF_FAIL (extinfo != NULL);
423
424     extinfo->opcode = xext->base;
425     extinfo->evt_base = xext->eventBase;
426     extinfo->err_base = xext->errorBase;
427     extinfo->req_func = _EvlogRequestXv;
428     extinfo->evt_func = _EvlogEventXv;
429     extinfo->rep_func = _EvlogReplyXv;
430
431 #endif
432 }