add supplementary log of reply type
[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, 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%lx)",
73                 stuff->drawable);
74
75             return reply;
76         }
77
78     case X_DRI2DestroyDrawable:
79         {
80             xDRI2DestroyDrawableReq *stuff = (xDRI2DestroyDrawableReq *)req;
81             REPLY (": XID(0x%lx)",
82                 stuff->drawable);
83
84             return reply;
85         }
86
87     case X_DRI2GetBuffers:
88         {
89             xDRI2GetBuffersReq *stuff = (xDRI2GetBuffersReq *)req;
90             REPLY (": XID(0x%lx) Count(%ld)",
91                 stuff->drawable,
92                 stuff->count);
93
94             return reply;
95         }
96
97     case X_DRI2CopyRegion:
98         {
99             xDRI2CopyRegionReq *stuff = (xDRI2CopyRegionReq *)req;
100             REPLY (": XID(0x%lx) src(0x%lx) dst(0x%lx)",
101                 stuff->drawable,
102                 stuff->src,
103                 stuff->dest);
104
105             REPLY (" Region");
106             reply = xDbgGetRegion(stuff->region, evinfo, reply, len);
107
108             return reply;
109         }
110
111     case X_DRI2GetBuffersWithFormat:
112         {
113             xDRI2GetBuffersReq *stuff = (xDRI2GetBuffersReq *)req;
114             REPLY (": XID(0x%lx) count(%ld)",
115                 stuff->drawable,
116                 stuff->count);
117
118             return reply;
119         }
120
121
122     case X_DRI2SwapBuffers:
123         {
124             xDRI2SwapBuffersReq *stuff = (xDRI2SwapBuffersReq *)req;
125             REPLY (": XID(0x%lx) msc(0x%lx/0x%lx) divisor(0x%lx/0x%lx) remainder(0x%lx/0x%lx)",
126                 stuff->drawable,
127                 stuff->target_msc_hi,
128                 stuff->target_msc_lo,
129                 stuff->divisor_hi,
130                 stuff->divisor_lo,
131                 stuff->remainder_hi,
132                 stuff->remainder_lo);
133
134             return reply;
135         }
136
137     case X_DRI2SwapInterval:
138         {
139             xDRI2SwapIntervalReq *stuff = (xDRI2SwapIntervalReq *)req;
140             REPLY (": XID(0x%lx) Interval(%ld)",
141                 stuff->drawable,
142                 stuff->interval);
143
144             return reply;
145         }
146
147     case X_DRI2SwapBuffersWithRegion:
148         {
149             xDRI2SwapBuffersWithRegionReq *stuff = (xDRI2SwapBuffersWithRegionReq *)req;
150             REPLY (": XID(0x%lx)",
151                 stuff->drawable);
152
153             REPLY (" Region");
154             reply = xDbgGetRegion(stuff->region, evinfo, reply, len);
155
156             return reply;
157         }
158
159     default:
160             break;
161     }
162
163     return reply;
164 }
165
166
167 static char *
168 _EvlogEventDri2 (EvlogInfo *evinfo, int first_base, char *reply, int *len)
169 {
170     xEvent *evt = evinfo->evt.ptr;
171
172     switch ((evt->u.u.type & 0x7F) - first_base)
173     {
174     case DRI2_BufferSwapComplete:
175         {
176             xDRI2BufferSwapComplete *stuff = (xDRI2BufferSwapComplete *) evt;
177             REPLY (": XID(0x%lx) ust(0x%lx/0x%lx) msc(0x%lx/0x%lx) sbc(0x%lx/0x%lx)",
178                 stuff->drawable,
179                 stuff->ust_hi,
180                 stuff->ust_lo,
181                 stuff->msc_hi,
182                 stuff->msc_lo,
183                 stuff->sbc_hi,
184                 stuff->sbc_lo);
185
186             evinfo->evt.size = sizeof (xDRI2BufferSwapComplete);
187
188             return reply;
189         }
190
191     case DRI2_InvalidateBuffers:
192         {
193             xDRI2InvalidateBuffers *stuff = (xDRI2InvalidateBuffers *) evt;
194             REPLY (": XID(0x%lx)",
195                 stuff->drawable);
196
197             return reply;
198         }
199
200     default:
201             break;
202     }
203
204     return reply;
205 }
206
207 static char *
208 _EvlogReplyDri2 (EvlogInfo *evinfo, char *reply, int *len)
209 {
210     xGenericReply *rep = evinfo->rep.ptr;
211
212     switch (evinfo->rep.reqData)
213     {
214     case X_DRI2GetBuffers:
215         {
216             if (evinfo->rep.isStart)
217             {
218                 xDRI2GetBuffersReply *stuff = (xDRI2GetBuffersReply *)rep;
219                 REPLY (": size(%ldx%ld) Count(%ld)",
220                     stuff->width,
221                     stuff->height,
222                     stuff->count);
223             }
224             else
225             {
226                 xDRI2Buffer *stuff = (xDRI2Buffer *)rep;
227
228                 REPLY ("attachment(0x%lx) Name(0x%lx) pitch(0x%lx) cpp(0x%lx)",
229                     stuff->attachment,
230                     stuff->name,
231                     stuff->pitch,
232                     stuff->cpp);
233             }
234
235             return reply;
236         }
237
238     case X_DRI2SwapBuffers:
239         {
240             if (evinfo->rep.isStart)
241             {
242                 xDRI2SwapBuffersReply *stuff = (xDRI2SwapBuffersReply *)rep;
243                 REPLY (": swap(%ld/%ld)",
244                     stuff->swap_hi,
245                     stuff->swap_lo);
246             }
247             else
248             {
249                 return reply;
250             }
251
252             return reply;
253         }
254
255     default:
256             break;
257     }
258
259     return reply;
260 }
261
262 void
263 xDbgEvlogDri2GetBase (ExtensionInfo *extinfo)
264 {
265 #ifdef XDBG_CLIENT
266     RETURN_IF_FAIL (extinfo != NULL);
267
268     extinfo->req_func = _EvlogRequestDri2;
269     extinfo->evt_func = _EvlogEventDri2;
270     extinfo->rep_func = _EvlogReplyDri2;
271 #else
272     ExtensionEntry *xext = CheckExtension (DRI2_NAME);
273     RETURN_IF_FAIL (xext != NULL);
274     RETURN_IF_FAIL (extinfo != NULL);
275
276     extinfo->opcode = xext->base;
277     extinfo->evt_base = xext->eventBase;
278     extinfo->err_base = xext->errorBase;
279     extinfo->req_func = _EvlogRequestDri2;
280     extinfo->evt_func = _EvlogEventDri2;
281     extinfo->rep_func = _EvlogReplyDri2;
282 #endif
283 }