add drmevent_pending
[adaptation/xorg/driver/xserver-xorg-module-xdbg.git] / module / xdbg_module_rlist.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 #define __USE_GNU
47 #include <sys/socket.h>
48 #include <linux/socket.h>
49
50 #ifdef HAS_GETPEERUCRED
51 # include <ucred.h>
52 #endif
53
54 #include <xace.h>
55 #include <xacestr.h>
56 #include <X11/Xatom.h>
57 #include <X11/extensions/XI2proto.h>
58 #include <windowstr.h>
59
60 #define XREGISTRY
61 #include <registry.h>
62
63 #include <compositeext.h>
64 #include <xdbg.h>
65
66 #include "xdbg_module_types.h"
67
68
69 #if 0
70 static int sum_pix_size = 0;
71
72 static void
73 _findRtWindow (pointer value, XID id, pointer cdata)
74 {
75     WindowPtr pWin = value;
76     ScreenPtr pScreen = pWin->drawable.pScreen;
77
78     if (pWin->viewable && pWin->realized)
79     {
80         ErrorF ("xid:0x%x geo:(%5d,%5d,%5d,%5d) bpp:%2d viewable:%d realized:%d ",
81                          (unsigned int)id,
82                          pWin->drawable.x, pWin->drawable.y, pWin->drawable.width, pWin->drawable.height,
83                          pWin->drawable.bitsPerPixel,
84                          pWin->viewable,
85                          pWin->realized);
86         if (pWin->parent->parent)
87             ErrorF ("border_id:0x%x ",(unsigned int)(pWin->parent->parent)->drawable.id);
88
89         PixmapPtr pPixmap = (*pScreen->GetWindowPixmap) (pWin);
90         PixmapPtr pScrnPixmap = (*pScreen->GetScreenPixmap) (pScreen);
91         if (pPixmap == pScrnPixmap)
92         {
93             ErrorF ("flip_draw:1 ");
94         }
95
96         ErrorF ("\n");
97     }
98 }
99
100 static void
101 _findRtCompWindow (pointer value, XID id, pointer cdata)
102 {
103     WindowPtr pWin = value;
104     WindowPtr pChild = NULL;
105     WindowPtr pGrandChild = NULL;
106     ScreenPtr pScreen = pWin->drawable.pScreen;
107     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
108     SECPtr pSec = SECPTR (pScrn);
109     PropertyPtr pProp = NULL;
110     int rc;
111
112     if (pWin->viewable && pWin->realized)
113     {
114         ErrorF ("xid:0x%x geo:(%5d,%5d,%5d,%5d) bpp:%2d viewable:%d realized:%d ",
115                          (unsigned int)pWin->drawable.id,
116                          pWin->drawable.x, pWin->drawable.y, pWin->drawable.width, pWin->drawable.height,
117                          pWin->drawable.bitsPerPixel,
118                          pWin->viewable,
119                          pWin->realized);
120
121         /* if pWin->child->child has a dri2 atom, the window is 3D window */
122         for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib)
123         {
124             for (pGrandChild = pChild->firstChild; pGrandChild; pGrandChild = pGrandChild->nextSib)
125             {
126                 rc = dixLookupProperty(&pProp, pGrandChild, pSec->atom_use_dri2, serverClient, DixReadAccess);
127                 if (rc == Success)
128                 {
129                     ErrorF ("dri2_draw:1 ");
130                 }
131             }
132         }
133
134
135
136         ErrorF ("\n");
137     }
138 }
139
140 static void
141 _findRtPixmap (pointer value, XID id, pointer cdata)
142 {
143     PixmapPtr pPix = value;
144
145     ErrorF ("xid:0x%x geo:(%5d,%5d,%5d,%5d) bpp:%2d size:%8d draw_id:0x%x\n",
146                      (unsigned int)id,
147                      pPix->drawable.x, pPix->drawable.y, pPix->drawable.width, pPix->drawable.height,
148                      pPix->drawable.bitsPerPixel,
149                      pPix->devKind*pPix->drawable.height/1024,
150                      (unsigned int)pPix->drawable.id);
151     sum_pix_size = sum_pix_size + (pPix->devKind*pPix->drawable.height);
152 }
153
154 char*
155 xDbgModuleRList (XDbgModule *pMod, char *reply, int *len)
156 {
157     SECPtr pSec = SECPTR (scrn);
158     char *out, *tmp;
159     int i, bufsize;
160
161     bufsize = currentMaxClients * (100 + 1) + 30;
162     out = tmp = malloc (bufsize);
163     if (!tmp)
164         return NULL;
165
166     for (i = 1; i < currentMaxClients && (tmp < out+bufsize); i++)
167     {
168         ClientPtr pClient = clients[i];
169         ModuleClientInfo *info;
170
171         if (!pClient)
172             continue;
173
174         info = GetClientInfo (pClient);
175         if (!info)
176             continue;
177
178         ErrorF(\r\r"\n");
179         ErrorF(\r\r"INDEX    PID   CMD\n");
180         ErrorF(\r\r"%6d %6d %10s\n", info->index, info->pid, info->command);
181         ErrorF(\r\r"  >> WINDOWS\n");
182         FindClientResourcesByType (pClient, RT_WINDOW, _findRtWindow, pClient);
183         ErrorF(\r\r"  >> CompositeClientWindow\n");
184         FindClientResourcesByType (pClient, CompositeClientWindowType, _findRtCompWindow, pClient);
185         ErrorF(\r\r"  >> PIXMAPS\n");
186         sum_pix_size = 0;
187         FindClientResourcesByType (pClient, RT_PIXMAP, _findRtPixmap, pClient);
188         ErrorF(\r\r"  SUM mem: %d\n", sum_pix_size/1024);
189     }
190
191     /*
192        Normal pixmap
193        CREATE_PIXMAP_USAGE_BACKING_PIXMAP
194        CREATE_PIXMAP_USAGE_OVERLAY
195        CREATE_PIXMAP_USAGE_DRI2_FILP_BACK
196        CREATE_PIXMAP_USAGE_FB
197        CREATE_PIXMAP_USAGE_SUB_FB
198        CREATE_PIXMAP_USAGE_DRI2_BACK
199      */
200     ErrorF ("==== sum of pixmap memory ====\n");
201     ErrorF ("Normal pixmap                      = %d\n", pSec->pix_normal/1024);
202     ErrorF ("CREATE_PIXMAP_USAGE_BACKING_PIXMAP = %d\n", pSec->pix_backing_pixmap/1024);
203     ErrorF ("CREATE_PIXMAP_USAGE_OVERLAY        = %d\n", pSec->pix_overlay/1024);
204     ErrorF ("CREATE_PIXMAP_USAGE_DRI2_FILP_BACK = %d\n", pSec->pix_dri2_flip_back/1024);
205     ErrorF ("CREATE_PIXMAP_USAGE_FB             = %d\n", pSec->pix_fb/1024);
206     ErrorF ("CREATE_PIXMAP_USAGE_SUB_FB         = %d\n", pSec->pix_sub_fb/1024);
207     ErrorF ("CREATE_PIXMAP_USAGE_DRI2_BACK      = %d\n", pSec->pix_dri2_back/1024);
208     ErrorF ("TOTAL                              = %d\n",
209             (pSec->pix_normal+pSec->pix_backing_pixmap+pSec->pix_overlay+pSec->pix_dri2_flip_back+pSec->pix_fb+pSec->pix_sub_fb+pSec->pix_dri2_back)/1024);
210     ErrorF ("==============================\n");
211
212
213     return out;
214 }
215 #else
216 char*
217 xDbgModuleRList (XDbgModule *pMod, char *reply, int *len)
218 {
219     XDBG_REPLY ("rlist : Not implemented.\n");
220     return NULL;
221 }
222 #endif