24524717384cdf88926cd5f741cbd82cb60067bc
[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(void *dpy, EvlogInfo *evinfo, 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             return reply;
77         }
78
79     case xv_UngrabPort:
80         {
81             xvUngrabPortReq *stuff = (xvUngrabPortReq *)req;
82             REPLY (": XID(0x%lx)",
83                 stuff->port);
84
85             return reply;
86         }
87
88     case xv_PutStill:
89         {
90             xvPutStillReq *stuff = (xvPutStillReq *)req;
91             REPLY (": XID(0x%lx) Drawable(0x%lx) GC(0x%lx) Vid(%d,%d %dx%d) Drw(%d,%d %dx%d)",
92                 stuff->port,
93                 stuff->drawable,
94                 stuff->gc,
95                 stuff->vid_x,
96                 stuff->vid_y,
97                 stuff->vid_w,
98                 stuff->vid_h,
99                 stuff->drw_x,
100                 stuff->drw_y,
101                 stuff->drw_w,
102                 stuff->drw_h);
103
104             return reply;
105         }
106
107     case xv_GetStill:
108         {
109             xvGetStillReq *stuff = (xvGetStillReq *)req;
110             REPLY (": XID(0x%lx) Drawable(0x%lx) GC(0x%lx) Vid(%d,%d %dx%d) Drw(%d,%d %dx%d)",
111                 stuff->port,
112                 stuff->drawable,
113                 stuff->gc,
114                 stuff->vid_x,
115                 stuff->vid_y,
116                 stuff->vid_w,
117                 stuff->vid_h,
118                 stuff->drw_x,
119                 stuff->drw_y,
120                 stuff->drw_w,
121                 stuff->drw_h);
122
123             return reply;
124         }
125
126     case xv_PutVideo:
127         {
128             xvPutVideoReq *stuff = (xvPutVideoReq *)req;
129             REPLY (": XID(0x%lx) Drawable(0x%lx) GC(0x%lx) Vid(%d,%d %dx%d) Drw(%d,%d %dx%d)",
130                 stuff->port,
131                 stuff->drawable,
132                 stuff->gc,
133                 stuff->vid_x,
134                 stuff->vid_y,
135                 stuff->vid_w,
136                 stuff->vid_h,
137                 stuff->drw_x,
138                 stuff->drw_y,
139                 stuff->drw_w,
140                 stuff->drw_h);
141
142             return reply;
143         }
144
145     case xv_GetVideo:
146         {
147             xvGetVideoReq *stuff = (xvGetVideoReq *)req;
148             REPLY (": XID(0x%lx) Drawable(0x%lx) GC(0x%lx) Vid(%d,%d %dx%d) Drw(%d,%d %dx%d)",
149                 stuff->port,
150                 stuff->drawable,
151                 stuff->gc,
152                 stuff->vid_x,
153                 stuff->vid_y,
154                 stuff->vid_w,
155                 stuff->vid_h,
156                 stuff->drw_x,
157                 stuff->drw_y,
158                 stuff->drw_w,
159                 stuff->drw_h);
160
161             return reply;
162         }
163
164     case xv_StopVideo:
165         {
166             xvStopVideoReq *stuff = (xvStopVideoReq *)req;
167             REPLY (": XID(0x%lx) Drawable(0x%lx)",
168                 stuff->port,
169                 stuff->drawable);
170
171             return reply;
172         }
173
174     case xv_SelectVideoNotify:
175         {
176             xvSelectVideoNotifyReq *stuff = (xvSelectVideoNotifyReq *)req;
177             REPLY (": XID(0x%lx) On/Off(%d)",
178                 stuff->drawable,
179                 stuff->onoff);
180
181             return reply;
182         }
183
184     case xv_SelectPortNotify:
185         {
186             xvSelectPortNotifyReq *stuff = (xvSelectPortNotifyReq *)req;
187             REPLY (": XID(0x%lx) On/Off(%d)",
188                 stuff->port,
189                 stuff->onoff);
190
191             return reply;
192         }
193
194     case xv_QueryBestSize:
195         {
196             xvQueryBestSizeReq *stuff = (xvQueryBestSizeReq *)req;
197             REPLY (": XID(0x%lx) VidSize(%dx%d) DrwSize(%dx%d)",
198                 stuff->port,
199                 stuff->vid_w,
200                 stuff->vid_h,
201                 stuff->drw_w,
202                 stuff->drw_h);
203
204             return reply;
205         }
206
207     case xv_SetPortAttribute:
208         {
209             xvSetPortAttributeReq *stuff = (xvSetPortAttributeReq *)req;
210             REPLY (": XID(0x%lx) value(%ld)",
211                 stuff->port,
212                 stuff->value);
213
214             REPLY (" Attribute");
215             reply = xDbgGetAtom(dpy, stuff->attribute, reply, len);
216
217             return reply;
218         }
219
220     case xv_GetPortAttribute:
221         {
222             xvGetPortAttributeReq *stuff = (xvGetPortAttributeReq *)req;
223             REPLY (": XID(0x%lx)",
224                 stuff->port);
225
226             REPLY (" Attribute");
227             reply = xDbgGetAtom(dpy, stuff->attribute, reply, len);
228
229             return reply;
230         }
231
232     case xv_PutImage:
233         {
234             xvPutImageReq *stuff = (xvPutImageReq *)req;
235             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)",
236                 stuff->port,
237                 stuff->drawable,
238                 stuff->gc,
239                 stuff->id,
240                 stuff->width,
241                 stuff->height,
242                 stuff->src_x,
243                 stuff->src_y,
244                 stuff->src_w,
245                 stuff->src_h,
246                 stuff->drw_x,
247                 stuff->drw_y,
248                 stuff->drw_w,
249                 stuff->drw_h);
250
251             return reply;
252         }
253
254     case xv_ShmPutImage:
255         {
256             xvShmPutImageReq *stuff = (xvShmPutImageReq *)req;
257             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) sendevent(%d)",
258                 stuff->port,
259                 stuff->drawable,
260                 stuff->gc,
261                 stuff->id,
262                 stuff->width,
263                 stuff->height,
264                 stuff->src_x,
265                 stuff->src_y,
266                 stuff->src_w,
267                 stuff->src_h,
268                 stuff->drw_x,
269                 stuff->drw_y,
270                 stuff->drw_w,
271                 stuff->drw_h,
272                 stuff->send_event);
273
274             return reply;
275         }
276
277     default:
278             break;
279     }
280
281     return reply;
282 }
283
284 static char *
285 _EvlogEventXv (void *dpy, EvlogInfo *evinfo, int first_base, char *reply, int *len)
286 {
287     xEvent *evt = evinfo->evt.ptr;
288
289     switch ((evt->u.u.type & 0x7F) - first_base)
290     {
291     case XvVideoNotify:
292         {
293             XvVideoNotifyEvent *stuff = (XvVideoNotifyEvent *) evt;
294             REPLY (": XID(0x%lx) reason(%ld) portID(0x%lx)",
295                 stuff->drawable,
296                 stuff->reason,
297                 stuff->port_id);
298
299             return reply;
300         }
301
302     case XvPortNotify:
303         {
304             XvPortNotifyEvent *stuff = (XvPortNotifyEvent *) evt;
305             REPLY (": XID(0x%lx) Value(%ld)",
306                 stuff->port_id,
307                 stuff->value);
308
309             REPLY (" Attribute");
310             reply = xDbgGetAtom(dpy, stuff->attribute, reply, len);
311
312             return reply;
313         }
314
315     default:
316             break;
317     }
318
319     return reply;
320 }
321
322 void
323 xDbgEvlogXvGetBase (void *dpy, ExtensionInfo *extinfo)
324 {
325 #ifdef XDBG_CLIENT
326     Display *d = (Display*)dpy;
327
328     RETURN_IF_FAIL (d != NULL);
329     RETURN_IF_FAIL (extinfo != NULL);
330
331     if (!XQueryExtension(d, XvName, &extinfo->opcode, &extinfo->evt_base, &extinfo->err_base))
332     {
333         XDBG_LOG ("no Xv extension. \n");
334         return;
335     }
336     extinfo->req_func = _EvlogRequestXv;
337     extinfo->evt_func = _EvlogEventXv;
338 #else
339     ExtensionEntry *xext = CheckExtension (XvName);
340     RETURN_IF_FAIL (xext != NULL);
341
342     extinfo->opcode = xext->base;
343     extinfo->evt_base = xext->eventBase;
344     extinfo->err_base = xext->errorBase;
345     extinfo->req_func = _EvlogRequestXv;
346     extinfo->evt_func = _EvlogEventXv;
347
348 #endif
349 }