add supplementary log massage of each major extension
[platform/adaptation/xf86-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
61 static char *
62 _EvlogRequestDri2 (xReq *req, char *reply, int *len)
63 {
64     xReq *stuff = req;
65
66     switch (stuff->data)
67     {
68     case X_DRI2CreateDrawable:
69         {
70             xDRI2CreateDrawableReq *stuff = (xDRI2CreateDrawableReq *)req;
71             REPLY (": XID(0x%lx)",
72                 stuff->drawable);
73
74             return reply;
75         }
76
77     case X_DRI2DestroyDrawable:
78         {
79             xDRI2DestroyDrawableReq *stuff = (xDRI2DestroyDrawableReq *)req;
80             REPLY (": XID(0x%lx)",
81                 stuff->drawable);
82
83             return reply;
84         }
85
86     case X_DRI2GetBuffers:
87         {
88             xDRI2GetBuffersReq *stuff = (xDRI2GetBuffersReq *)req;
89             REPLY (": XID(0x%lx) Count(%ld)",
90                 stuff->drawable,
91                 stuff->count);
92
93             return reply;
94         }
95
96     case X_DRI2CopyRegion:
97         {
98             xDRI2CopyRegionReq *stuff = (xDRI2CopyRegionReq *)req;
99             REPLY (": XID(0x%lx) Region(0x%lx) src(0x%lx) dst(0x%lx)",
100                 stuff->drawable,
101                 stuff->region,
102                 stuff->src,
103                 stuff->dest);
104
105             return reply;
106         }
107
108     case X_DRI2GetBuffersWithFormat:
109         {
110             xDRI2GetBuffersReq *stuff = (xDRI2GetBuffersReq *)req;
111             REPLY (": XID(0x%lx) count(%ld)",
112                 stuff->drawable,
113                 stuff->count);
114
115             return reply;
116         }
117
118
119     case X_DRI2SwapBuffers:
120         {
121             xDRI2SwapBuffersReq *stuff = (xDRI2SwapBuffersReq *)req;
122             REPLY (": XID(0x%lx) msc(0x%lx/0x%lx) divisor(0x%lx/0x%lx) remainder(0x%lx/0x%lx)",
123                 stuff->drawable,
124                 stuff->target_msc_hi,
125                 stuff->target_msc_lo,
126                 stuff->divisor_hi,
127                 stuff->divisor_lo,
128                 stuff->remainder_hi,
129                 stuff->remainder_lo);
130
131             return reply;
132         }
133
134     case X_DRI2SwapInterval:
135         {
136             xDRI2SwapIntervalReq *stuff = (xDRI2SwapIntervalReq *)req;
137             REPLY (": XID(0x%lx) Interval(%ld)",
138                 stuff->drawable,
139                 stuff->interval);
140
141             return reply;
142         }
143
144     case X_DRI2SwapBuffersWithRegion:
145         {
146             xDRI2SwapBuffersWithRegionReq *stuff = (xDRI2SwapBuffersWithRegionReq *)req;
147             REPLY (": XID(0x%lx) Region(0x%lx)",
148                 stuff->drawable,
149                 stuff->region);
150
151             return reply;
152         }
153
154     default:
155             break;
156     }
157
158     return reply;
159 }
160
161
162 static char *
163 _EvlogEventDri2 (xEvent *evt, int first_base, char *reply, int *len)
164 {
165     xEvent *stuff = evt;
166
167     switch ((stuff->u.u.type & 0x7F) - first_base)
168     {
169     case DRI2_BufferSwapComplete:
170         {
171             xDRI2BufferSwapComplete *stuff = (xDRI2BufferSwapComplete *) evt;
172             REPLY (": XID(0x%lx) ust(0x%lx/0x%lx) msc(0x%lx/0x%lx) sbc(0x%lx/0x%lx)",
173                 stuff->drawable,
174                 stuff->ust_hi,
175                 stuff->ust_lo,
176                 stuff->msc_hi,
177                 stuff->msc_lo,
178                 stuff->sbc_hi,
179                 stuff->sbc_lo);
180
181             return reply;
182         }
183
184     case DRI2_InvalidateBuffers:
185         {
186             xDRI2InvalidateBuffers *stuff = (xDRI2InvalidateBuffers *) evt;
187             REPLY (": XID(0x%lx)",
188                 stuff->drawable);
189
190             return reply;
191         }
192
193     default:
194             break;
195     }
196
197     return reply;
198 }
199
200
201
202 void
203 xDbgEvlogDri2GetBase (void *dpy, ExtensionInfo *extinfo)
204 {
205 #ifdef XDBG_CLIENT
206     Display *d = (Display*)dpy;
207
208     RETURN_IF_FAIL (d != NULL);
209     RETURN_IF_FAIL (extinfo != NULL);
210
211     if (!XQueryExtension(d, DRI2_NAME, &extinfo->opcode, &extinfo->evt_base, &extinfo->err_base))
212     {
213         fprintf (stderr, "[UTILX] no DRI2 extension. \n");
214         return;
215     }
216     extinfo->req_func = _EvlogRequestDri2;
217     extinfo->evt_func = _EvlogEventDri2;
218 #else
219     ExtensionEntry *xext = CheckExtension (DRI2_NAME);
220     RETURN_IF_FAIL (xext != NULL);
221
222     extinfo->opcode = xext->base;
223     extinfo->evt_base = xext->eventBase;
224     extinfo->err_base = xext->errorBase;
225     extinfo->req_func = _EvlogRequestDri2;
226     extinfo->evt_func = _EvlogEventDri2;
227 #endif
228 }