tizen 2.4 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) type:%d ust(0x%x/0x%x) msc(0x%x/0x%x) sbc(0x%x/0x%x)",
199                 (unsigned int)stuff->drawable,
200                 (int)stuff->event_type,
201                 (unsigned int)stuff->ust_hi,
202                 (unsigned int)stuff->ust_lo,
203                 (unsigned int)stuff->msc_hi,
204                 (unsigned int)stuff->msc_lo,
205                 (unsigned int)stuff->sbc_hi,
206                 (unsigned int)stuff->sbc_lo);
207
208             evinfo->evt.size = sizeof (xDRI2BufferSwapComplete);
209
210             if (detail_level >= EVLOG_PRINT_DETAIL)
211             {
212                 REPLY ("\n");
213                 REPLY ("%67s sequence_num(%d) event_type(%d)",
214                     " ",
215                     stuff->sequenceNumber,
216                     stuff->event_type);
217             }
218
219             return reply;
220         }
221
222     case DRI2_InvalidateBuffers:
223         {
224             xDRI2InvalidateBuffers *stuff = (xDRI2InvalidateBuffers *) evt;
225             REPLY (": XID(0x%x)",
226                 (unsigned int)stuff->drawable);
227
228             if (detail_level >= EVLOG_PRINT_DETAIL)
229             {
230                 REPLY (" sequence_num(%d)",
231                     stuff->sequenceNumber);
232             }
233
234             return reply;
235         }
236
237     default:
238             break;
239     }
240
241     return reply;
242 }
243
244 static char *
245 _EvlogReplyDri2 (EvlogInfo *evinfo, int detail_level, char *reply, int *len)
246 {
247     xGenericReply *rep = evinfo->rep.ptr;
248
249     switch (evinfo->rep.reqData)
250     {
251     case X_DRI2GetBuffers:
252         {
253             if (evinfo->rep.isStart)
254             {
255                 xDRI2GetBuffersReply *stuff = (xDRI2GetBuffersReply *)rep;
256                 REPLY (": size(%ldx%ld) count(%ld)",
257                     (long int)stuff->width,
258                     (long int)stuff->height,
259                     (long int)stuff->count);
260
261                 if (detail_level >= EVLOG_PRINT_DETAIL)
262                 {
263                     REPLY (" sequence_num(%d)",
264                         stuff->sequenceNumber);
265                 }
266             }
267             else
268             {
269                 xDRI2Buffer *stuff = (xDRI2Buffer *)rep;
270
271                 REPLY ("attachment(0x%x) Name(0x%x) pitch(0x%x) cpp(0x%x) flags(0x%x)",
272                     (unsigned int)stuff->attachment,
273                     (unsigned int)stuff->name,
274                     (unsigned int)stuff->pitch,
275                     (unsigned int)stuff->cpp,
276                     (unsigned int)stuff->flags);
277             }
278
279             return reply;
280         }
281
282     case X_DRI2SwapBuffers:
283         {
284             if (evinfo->rep.isStart)
285             {
286                 xDRI2SwapBuffersReply *stuff = (xDRI2SwapBuffersReply *)rep;
287                 REPLY (": swap(%ld/%ld)",
288                     (long int)stuff->swap_hi,
289                     (long int)stuff->swap_lo);
290
291                 if (detail_level >= EVLOG_PRINT_DETAIL)
292                 {
293                     REPLY (" sequence_num(%d)",
294                         stuff->sequenceNumber);
295                 }
296             }
297             else
298             {
299                 return reply;
300             }
301
302             return reply;
303         }
304
305     default:
306             break;
307     }
308
309     return reply;
310 }
311
312 void
313 xDbgEvlogDri2GetBase (ExtensionInfo *extinfo)
314 {
315 #ifdef XDBG_CLIENT
316     RETURN_IF_FAIL (extinfo != NULL);
317
318     extinfo->req_func = _EvlogRequestDri2;
319     extinfo->evt_func = _EvlogEventDri2;
320     extinfo->rep_func = _EvlogReplyDri2;
321 #else
322     ExtensionEntry *xext = CheckExtension (DRI2_NAME);
323     RETURN_IF_FAIL (xext != NULL);
324     RETURN_IF_FAIL (extinfo != NULL);
325
326     extinfo->opcode = xext->base;
327     extinfo->evt_base = xext->eventBase;
328     extinfo->err_base = xext->errorBase;
329     extinfo->req_func = _EvlogRequestDri2;
330     extinfo->evt_func = _EvlogEventDri2;
331     extinfo->rep_func = _EvlogReplyDri2;
332 #endif
333 }