tizen 2.3 release
[adaptation/xorg/driver/xserver-xorg-module-xdbg.git] / common / xdbg_evlog_damage.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 <X11/extensions/Xdamage.h>
55 #include <X11/extensions/damageproto.h>
56
57
58 #include "xdbg_types.h"
59 #include "xdbg_evlog_damage.h"
60 #include "xdbg_evlog.h"
61
62 static char *
63 _EvlogRequestDamage(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_DamageCreate:
70         {
71             xDamageCreateReq *stuff = (xDamageCreateReq *)req;
72             REPLY (": XID(0x%x) Drawable(0x%x)",
73                 (unsigned int)stuff->damage,
74                 (unsigned int)stuff->drawable);
75
76             if (detail_level >= EVLOG_PRINT_DETAIL)
77             {
78                 const char *level;
79                 char dlevel[10];
80
81                 switch (stuff->level)
82                 {
83                     case XDamageReportRawRectangles:  level = "DamageReportRawRegion"; break;
84                     case XDamageReportDeltaRectangles:  level = "DamageReportDeltaRegion"; break;
85                     case XDamageReportBoundingBox:  level = "DamageReportBoundingBox"; break;
86                     case XDamageReportNonEmpty:  level = "DamageReportNonEmpty"; break;
87                     default:  level = dlevel; snprintf (dlevel, 10, "%d", stuff->level); break;
88                 }
89
90                 REPLY (" level(%s)",
91                     level);
92             }
93
94             return reply;
95         }
96
97     case X_DamageDestroy:
98         {
99             xDamageDestroyReq *stuff = (xDamageDestroyReq *)req;
100             REPLY (": XID(0x%x)",
101                 (unsigned int)stuff->damage);
102
103             return reply;
104         }
105
106     default:
107             break;
108     }
109
110     return reply;
111 }
112
113 static char*
114 _EvlogEventDamage (EvlogInfo *evinfo, int first_base, int detail_level, char *reply, int *len)
115 {
116     xEvent *evt = evinfo->evt.ptr;
117
118     switch ((evt->u.u.type & 0x7F) - first_base)
119     {
120     case XDamageNotify:
121         {
122             xDamageNotifyEvent *stuff = (xDamageNotifyEvent*)evt;
123             REPLY (": XID(0x%x) Damage(0x%x) area(%d,%d %dx%d) geo(%d,%d %dx%d)",
124                 (unsigned int)stuff->drawable,
125                 (unsigned int)stuff->damage,
126                 stuff->area.x,
127                 stuff->area.y,
128                 stuff->area.width,
129                 stuff->area.height,
130                 stuff->geometry.x,
131                 stuff->geometry.y,
132                 stuff->geometry.width,
133                 stuff->geometry.height);
134
135             if (detail_level >= EVLOG_PRINT_DETAIL)
136             {
137                 REPLY ("\n");
138                 REPLY ("%67s time(%lums) level(%d) sequence_num(%d)",
139                     " ",
140                     (unsigned long)stuff->timestamp,
141                     stuff->level,
142                     stuff->sequenceNumber);
143             }
144
145             return reply;
146         }
147
148     default:
149             break;
150     }
151
152     return reply;
153 }
154
155 static char *
156 _EvlogReplyDamage (EvlogInfo *evinfo, int detail_level, char *reply, int *len)
157 {
158 #if 0
159     xGenericReply *rep = evinfo->rep.ptr;
160
161     switch (evinfo->rep.reqData)
162     {
163
164     default:
165             break;
166     }
167 #endif
168     return reply;
169 }
170
171 void
172 xDbgEvlogDamageGetBase (ExtensionInfo *extinfo)
173 {
174 #ifdef XDBG_CLIENT
175     RETURN_IF_FAIL (extinfo != NULL);
176
177     extinfo->req_func = _EvlogRequestDamage;
178     extinfo->evt_func = _EvlogEventDamage;
179     extinfo->rep_func = _EvlogReplyDamage;
180 #else
181     ExtensionEntry *xext = CheckExtension (DAMAGE_NAME);
182     RETURN_IF_FAIL (xext != NULL);
183     RETURN_IF_FAIL (extinfo != NULL);
184
185     extinfo->opcode = xext->base;
186     extinfo->evt_base = xext->eventBase;
187     extinfo->err_base = xext->errorBase;
188     extinfo->req_func = _EvlogRequestDamage;
189     extinfo->evt_func = _EvlogEventDamage;
190     extinfo->rep_func = _EvlogReplyDamage;
191 #endif
192 }