tizen 2.3 release
[adaptation/xorg/driver/xserver-xorg-module-xdbg.git] / common / xdbg_evlog_dri2.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 #include <dri2/dri2.h>
55 #include <X11/extensions/dri2proto.h>
56
57
58 #include "xdbg_types.h"
59 #include "xdbg_evlog_dri2.h"
60 #include "xdbg_evlog.h"
61
62 static char *
63 _EvlogRequestDri2 (EvlogInfo *evinfo, int detail_level, char *reply, int *len)
64 {
65     xReq *req = evinfo->req.ptr;
66
67     switch (req->data)
68     {
69     case X_DRI2CreateDrawable:
70         {
71             xDRI2CreateDrawableReq *stuff = (xDRI2CreateDrawableReq *)req;
72             REPLY (": XID(0x%x)",
73                 (unsigned int)stuff->drawable);
74
75             return reply;
76         }
77
78     case X_DRI2DestroyDrawable:
79         {
80             xDRI2DestroyDrawableReq *stuff = (xDRI2DestroyDrawableReq *)req;
81             REPLY (": XID(0x%x)",
82                 (unsigned int)stuff->drawable);
83
84             return reply;
85         }
86
87     case X_DRI2GetBuffers:
88         {
89             xDRI2GetBuffersReq *stuff = (xDRI2GetBuffersReq *)req;
90             REPLY (": XID(0x%x)",
91                 (unsigned int)stuff->drawable);
92
93             if (detail_level >= EVLOG_PRINT_DETAIL)
94             {
95                 REPLY (" count(%ld)",
96                     (long int)stuff->count);
97             }
98
99             return reply;
100         }
101
102     case X_DRI2CopyRegion:
103         {
104             xDRI2CopyRegionReq *stuff = (xDRI2CopyRegionReq *)req;
105             REPLY (": XID(0x%x) src(0x%x) dst(0x%x)",
106                 (unsigned int)stuff->drawable,
107                 (unsigned int)stuff->src,
108                 (unsigned int)stuff->dest);
109
110             if (detail_level >= EVLOG_PRINT_DETAIL)
111             {
112                 REPLY (" Region");
113                 reply = xDbgGetRegion(stuff->region, evinfo, reply, len);
114             }
115
116             return reply;
117         }
118
119     case X_DRI2GetBuffersWithFormat:
120         {
121             xDRI2GetBuffersReq *stuff = (xDRI2GetBuffersReq *)req;
122             REPLY (": XID(0x%x)",
123                 (unsigned int)stuff->drawable);
124
125             if (detail_level >= EVLOG_PRINT_DETAIL)
126             {
127                 REPLY (" count(%ld)",
128                     (long int)stuff->count);
129             }
130
131             return reply;
132         }
133
134
135     case X_DRI2SwapBuffers:
136         {
137             xDRI2SwapBuffersReq *stuff = (xDRI2SwapBuffersReq *)req;
138             REPLY (": XID(0x%x) msc(0x%x/0x%x) divisor(0x%x/0x%x) remainder(0x%x/0x%x)",
139                 (unsigned int)stuff->drawable,
140                 (unsigned int)stuff->target_msc_hi,
141                 (unsigned int)stuff->target_msc_lo,
142                 (unsigned int)stuff->divisor_hi,
143                 (unsigned int)stuff->divisor_lo,
144                 (unsigned int)stuff->remainder_hi,
145                 (unsigned int)stuff->remainder_lo);
146
147             return reply;
148         }
149
150     case X_DRI2SwapInterval:
151         {
152             xDRI2SwapIntervalReq *stuff = (xDRI2SwapIntervalReq *)req;
153             REPLY (": XID(0x%x)",
154                 (unsigned int)stuff->drawable);
155
156             if (detail_level >= EVLOG_PRINT_DETAIL)
157             {
158                 REPLY (" interval(%ld)",
159                     (long int)stuff->interval);
160             }
161
162             return reply;
163         }
164
165     case X_DRI2SwapBuffersWithRegion:
166         {
167             xDRI2SwapBuffersWithRegionReq *stuff = (xDRI2SwapBuffersWithRegionReq *)req;
168             REPLY (": XID(0x%x)",
169                 (unsigned int)stuff->drawable);
170
171             if (detail_level >= EVLOG_PRINT_DETAIL)
172             {
173                 REPLY (" Region");
174                 reply = xDbgGetRegion(stuff->region, evinfo, reply, len);
175             }
176
177             return reply;
178         }
179
180     default:
181             break;
182     }
183
184     return reply;
185 }
186
187
188 static char *
189 _EvlogEventDri2 (EvlogInfo *evinfo, int first_base, int detail_level, char *reply, int *len)
190 {
191     xEvent *evt = evinfo->evt.ptr;
192
193     switch ((evt->u.u.type & 0x7F) - first_base)
194     {
195     case DRI2_BufferSwapComplete:
196         {
197             xDRI2BufferSwapComplete *stuff = (xDRI2BufferSwapComplete *) evt;
198             REPLY (": XID(0x%x) ust(0x%x/0x%x) msc(0x%x/0x%x) sbc(0x%x/0x%x)",
199                 (unsigned int)stuff->drawable,
200                 (unsigned int)stuff->ust_hi,
201                 (unsigned int)stuff->ust_lo,
202                 (unsigned int)stuff->msc_hi,
203                 (unsigned int)stuff->msc_lo,
204                 (unsigned int)stuff->sbc_hi,
205                 (unsigned int)stuff->sbc_lo);
206
207             evinfo->evt.size = sizeof (xDRI2BufferSwapComplete);
208
209             if (detail_level >= EVLOG_PRINT_DETAIL)
210             {
211                 REPLY ("\n");
212                 REPLY ("%67s sequence_num(%d) event_type(%d)",
213                     " ",
214                     stuff->sequenceNumber,
215                     stuff->event_type);
216             }
217
218             return reply;
219         }
220
221     case DRI2_InvalidateBuffers:
222         {
223             xDRI2InvalidateBuffers *stuff = (xDRI2InvalidateBuffers *) evt;
224             REPLY (": XID(0x%x)",
225                 (unsigned int)stuff->drawable);
226
227             if (detail_level >= EVLOG_PRINT_DETAIL)
228             {
229                 REPLY (" sequence_num(%d)",
230                     stuff->sequenceNumber);
231             }
232
233             return reply;
234         }
235
236     default:
237             break;
238     }
239
240     return reply;
241 }
242
243 static char *
244 _EvlogReplyDri2 (EvlogInfo *evinfo, int detail_level, char *reply, int *len)
245 {
246     xGenericReply *rep = evinfo->rep.ptr;
247
248     switch (evinfo->rep.reqData)
249     {
250     case X_DRI2GetBuffers:
251         {
252             if (evinfo->rep.isStart)
253             {
254                 xDRI2GetBuffersReply *stuff = (xDRI2GetBuffersReply *)rep;
255                 REPLY (": size(%ldx%ld) count(%ld)",
256                     (long int)stuff->width,
257                     (long int)stuff->height,
258                     (long int)stuff->count);
259
260                 if (detail_level >= EVLOG_PRINT_DETAIL)
261                 {
262                     REPLY (" sequence_num(%d)",
263                         stuff->sequenceNumber);
264                 }
265             }
266             else
267             {
268                 xDRI2Buffer *stuff = (xDRI2Buffer *)rep;
269
270                 REPLY ("attachment(0x%x) Name(0x%x) pitch(0x%x) cpp(0x%x) flags(0x%x)",
271                     (unsigned int)stuff->attachment,
272                     (unsigned int)stuff->name,
273                     (unsigned int)stuff->pitch,
274                     (unsigned int)stuff->cpp,
275                     (unsigned int)stuff->flags);
276             }
277
278             return reply;
279         }
280
281     case X_DRI2SwapBuffers:
282         {
283             if (evinfo->rep.isStart)
284             {
285                 xDRI2SwapBuffersReply *stuff = (xDRI2SwapBuffersReply *)rep;
286                 REPLY (": swap(%ld/%ld)",
287                     (long int)stuff->swap_hi,
288                     (long int)stuff->swap_lo);
289
290                 if (detail_level >= EVLOG_PRINT_DETAIL)
291                 {
292                     REPLY (" sequence_num(%d)",
293                         stuff->sequenceNumber);
294                 }
295             }
296             else
297             {
298                 return reply;
299             }
300
301             return reply;
302         }
303
304     default:
305             break;
306     }
307
308     return reply;
309 }
310
311 void
312 xDbgEvlogDri2GetBase (ExtensionInfo *extinfo)
313 {
314 #ifdef XDBG_CLIENT
315     RETURN_IF_FAIL (extinfo != NULL);
316
317     extinfo->req_func = _EvlogRequestDri2;
318     extinfo->evt_func = _EvlogEventDri2;
319     extinfo->rep_func = _EvlogReplyDri2;
320 #else
321     ExtensionEntry *xext = CheckExtension (DRI2_NAME);
322     RETURN_IF_FAIL (xext != NULL);
323     RETURN_IF_FAIL (extinfo != NULL);
324
325     extinfo->opcode = xext->base;
326     extinfo->evt_base = xext->eventBase;
327     extinfo->err_base = xext->errorBase;
328     extinfo->req_func = _EvlogRequestDri2;
329     extinfo->evt_func = _EvlogEventDri2;
330     extinfo->rep_func = _EvlogReplyDri2;
331 #endif
332 }