tizen 2.3 release
[adaptation/xorg/driver/xserver-xorg-module-xdbg.git] / lib / xdbg_log_plist.c
1 /**************************************************************************
2
3 xdbg
4
5 Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
6
7 Contact: SooChan Lim <sc1.lim@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 "xorg-server.h"
38 #include "xf86.h"
39 #include <scrnintstr.h>
40 #include <resource.h>
41 #include <windowstr.h>
42 #include <pixmap.h>
43 #include <list.h>
44 #include "xdbg.h"
45 #include "xdbg_log_int.h"
46 #include "xdbg_types.h"
47 #include "xdbg_log_plist.h"
48
49 /* for debug message */
50 #define MMEM    XDBG_M('M','E','M',0)
51
52 #ifndef API
53 #define API __attribute__ ((visibility("default")))
54 #endif
55
56 /*=========================================================================*/
57 /* trace the usage of the pixmaps in xserver                               */
58 /*=========================================================================*/
59
60 #define CLIENT_BITS(id) ((id) & RESOURCE_CLIENT_MASK)
61 #define CLIENT_ID(id) ((int)(CLIENT_BITS(id) >> CLIENTOFFSET))
62 #define MAX_HISTORY  10
63
64 typedef struct {
65     PixmapPtr pPixmap;
66     unsigned int size;
67     unsigned int refs;
68     char *hint;
69     XID refHistorys[MAX_HISTORY];
70     int numHistory;
71     struct xorg_list link;
72 } XDbgPixmap;
73
74 typedef struct {
75     PixmapPtr pPixmap;
76     struct xorg_list link;
77 } XDbgRefPixmap;
78
79 typedef struct {
80     DrawablePtr pDraw;
81     XDbgRefPixmap *pRefPixmap;
82     struct xorg_list link;
83     struct xorg_list refPixmaps;
84 } XDbgDrawable;
85
86 static int init_plist = 0;
87 static struct xorg_list xdbgPixmaps;
88 static struct xorg_list xdbgDrawables;
89 static PixmapPtr pPixRoot = NULL;
90 unsigned int total_size = 0;
91 unsigned int peek_size = 0;
92
93 const struct {
94     unsigned int hint;
95     char* str;
96 } pixmap_hint[] = {
97     {CREATE_PIXMAP_USAGE_SCRATCH,        "scratch"},
98     {CREATE_PIXMAP_USAGE_BACKING_PIXMAP, "backing_pixmap"},
99     {CREATE_PIXMAP_USAGE_GLYPH_PICTURE,  "glyph_picture"},
100     {CREATE_PIXMAP_USAGE_SHARED,         "shared"},
101     {CREATE_PIXMAP_USAGE_OVERLAY,        "overlay"},
102     {CREATE_PIXMAP_USAGE_DRI2_FLIP_BACK, "dri2_flip_back"},
103     {CREATE_PIXMAP_USAGE_FB,             "fb"},
104     {CREATE_PIXMAP_USAGE_SUB_FB,         "sub_fb"},
105     {CREATE_PIXMAP_USAGE_DRI2_BACK,      "dri2_back"},
106     /******END********/
107     {0, "normal"}
108 };
109
110 static char *
111 _get_pixmap_hint_name (signed int usage_hint)
112 {
113     int i = 0;
114
115     while (pixmap_hint[i].hint)
116     {
117         if (pixmap_hint[i].hint == usage_hint)
118             return pixmap_hint[i].str;
119         i++;
120     }
121     return NULL;
122 }
123
124 static XDbgPixmap *
125 _findXDbgPixmap (PixmapPtr pPixmap)
126 {
127     XDbgPixmap *cur = NULL, *tmp = NULL;
128
129     xorg_list_for_each_entry_safe (cur, tmp, &xdbgPixmaps, link)
130     {
131         if (cur->pPixmap == pPixmap)
132             return cur;
133     }
134
135     return NULL;
136 }
137
138 static XDbgDrawable *
139 _findXDbgDrawable (DrawablePtr pDraw)
140 {
141     XDbgDrawable *cur = NULL, *tmp = NULL;
142
143     xorg_list_for_each_entry_safe (cur, tmp, &xdbgDrawables, link)
144     {
145         if (cur->pDraw == pDraw)
146             return cur;
147     }
148
149     return NULL;
150 }
151
152 static XDbgRefPixmap*
153 _findXDbgRefPixmap (XDbgDrawable* pXDbgDrawable, PixmapPtr pPixmap)
154 {
155     XDbgRefPixmap *cur = NULL, *tmp = NULL;
156
157     xorg_list_for_each_entry_safe (cur, tmp, &pXDbgDrawable->refPixmaps, link)
158     {
159         if (cur->pPixmap == pPixmap)
160             return cur;
161     }
162
163     return NULL;
164 }
165
166 static void
167 _addXDbgPixmap (PixmapPtr pPixmap)
168 {
169     XDbgPixmap *cur = NULL;
170     unsigned int size;
171
172     cur = _findXDbgPixmap (pPixmap);
173     if (cur)
174     {
175         size = pPixmap->devKind * pPixmap->drawable.height;
176         if (size == cur->size)
177             return;
178
179         XDBG_TRACE (MMEM, " Change pixmap(%p) size(%d -> %d)\n",
180                     cur->pPixmap, cur->size, size);
181
182         total_size -= cur->size;
183         cur->size = size;
184         cur->hint = _get_pixmap_hint_name (pPixmap->usage_hint);
185     }
186     else
187     {
188         cur = calloc (1, sizeof (XDbgPixmap));
189         cur->pPixmap = pPixmap;
190         cur->size = pPixmap->devKind*pPixmap->drawable.height;
191         cur->hint = _get_pixmap_hint_name (pPixmap->usage_hint);
192         xorg_list_add (&cur->link, &xdbgPixmaps);
193     }
194
195     /* caculate the total_size of pixmaps */
196     total_size += cur->size;
197     if (total_size > peek_size)
198         peek_size = total_size;
199
200     if (pPixmap->usage_hint == CREATE_PIXMAP_USAGE_FB)
201         pPixRoot = pPixmap;
202
203     XDBG_TRACE (MMEM, "Add pixmap(%p) size:%d, hint:%s\n",
204                 cur->pPixmap, cur->size, cur->hint);
205 }
206
207 static void
208 _removeXDbgPixmap (PixmapPtr pPixmap)
209 {
210     XDbgPixmap *cur = NULL;
211
212     cur = _findXDbgPixmap (pPixmap);
213     if (!cur)
214     {
215         XDBG_WARNING (MMEM, "Unknown pixmap XID:0x%x, pPix:%p\n",
216                       (unsigned int)pPixmap->drawable.id, pPixmap);
217         return;
218     }
219
220     if (cur->refs > 0)
221         XDBG_TRACE (MMEM,"Pixmap(%p) refs:%d\n", cur->pPixmap, cur->refs);
222
223     /* caculate the total_size of pixmaps */
224     total_size -= cur->size;
225
226     XDBG_TRACE (MMEM, " Remove pixmap(%p) size:%d, hint:%s\n",
227                 cur->pPixmap, cur->size, cur->hint);
228
229     xorg_list_del(&cur->link);
230     free(cur);
231 }
232
233 #if 0
234 static void
235 _dumpDraws (char *reply, int *len)
236 {
237     XDbgDrawable *cur = NULL, *tmp = NULL;
238     XDbgRefPixmap *p = NULL, *ptmp = NULL;
239     XDbgPixmap *dp = NULL;
240
241     xorg_list_for_each_entry_safe (cur, tmp, &xdbgDrawables, link)
242     {
243         XDBG_REPLY ("[%d] XID:0x%x type:%s %dx%d+%d+%d\n",
244                                 CLIENT_ID(cur->pDraw->id),
245                                 (unsigned int)cur->pDraw->id,
246                                 (cur->pDraw->type == DRAWABLE_WINDOW ? "window":"pixmap"),
247                                 cur->pDraw->width, cur->pDraw->height, cur->pDraw->x, cur->pDraw->y);
248
249         xorg_list_for_each_entry_safe (p, ptmp, &cur->refPixmaps, link)
250         {
251             dp = _findXDbgPixmap (p->pPixmap);
252             if(!dp)
253             {
254                 XDBG_REPLY ("\t***[REF_Pixmap] unknown pixmap(%p)\n", p->pPixmap);
255                 continue;
256             }
257
258             XDBG_REPLY ("\t[REF_Pixmap] %p, hint:%s, size:%d\n",
259                                      dp->pPixmap, dp->hint, (unsigned int)dp->size/1024);
260         }
261     }
262 }
263
264 static void
265 _dumpPixmaps (char *reply, int *len)
266 {
267     XDbgPixmap *cur = NULL, *tmp = NULL;
268     int client_id;
269     int i;
270
271     if (pPixRoot)
272     {
273         cur = _findXDbgPixmap (pPixRoot);
274         XDBG_RETURN_IF_FAIL (cur != NULL);
275         XDBG_REPLY ("ROOT_Pixmap XID:0x%x pixmap(%p) hint:%s(0x%x) size:%d\n",
276                                 (unsigned int)cur->pPixmap->drawable.id, pPixRoot,
277                                 cur->hint, cur->pPixmap->usage_hint,
278                                 (unsigned int)cur->size/1024);
279     }
280
281     xorg_list_for_each_entry_safe (cur, tmp, &xdbgPixmaps, link)
282     {
283         if (cur->pPixmap == pPixRoot)
284             continue;
285
286         if (cur->pPixmap->drawable.id || cur->refs == 0)
287         {
288             client_id = CLIENT_ID(cur->pPixmap->drawable.id);
289             if (cur->pPixmap->drawable.id)
290             {
291                 XDBG_REPLY ("[%d] XID:0x%x %dx%d hint:%s(0x%x) size:%d refs:%d\n",
292                                         client_id, (unsigned int)cur->pPixmap->drawable.id,
293                                         cur->pPixmap->drawable.width, cur->pPixmap->drawable.height,
294                                         cur->hint, cur->pPixmap->usage_hint,
295                                         (unsigned int)cur->size/1024, cur->refs);
296             }
297             else
298             {
299                 XDBG_REPLY ("[%d] Pixmap:%p %dx%d hint:%s(0x%x) size:%d refs:%d\n",
300                                         client_id, cur->pPixmap,
301                                         cur->pPixmap->drawable.width, cur->pPixmap->drawable.height,
302                                         cur->hint, cur->pPixmap->usage_hint,
303                                         (unsigned int)cur->size/1024, cur->refs);
304             }
305
306             if (cur->numHistory)
307             {
308                 XDBG_REPLY ("\t[RefHistory] ");
309                 for (i = 0; i < cur->numHistory; i++)
310                 {
311                     XDBG_REPLY ("0x%x ", (unsigned int)cur->refHistorys[i]);
312                 }
313                 XDBG_REPLY ("\n");
314             }
315         }
316     }
317 }
318 #endif
319
320 CreatePixmapProcPtr fnCreatePixmap;
321 DestroyPixmapProcPtr fnDestroyPixmap;
322 ModifyPixmapHeaderProcPtr fnModifyPixmap;
323 SetWindowPixmapProcPtr fnSetWindowPixmap;
324 DestroyWindowProcPtr fnDestroyWindow;
325
326 static PixmapPtr
327 XDbgLogCreatePixmap (ScreenPtr pScreen, int width, int height,
328                         int depth, unsigned usage_hint)
329 {
330     PixmapPtr pPixmap = NULL;
331
332     pScreen->CreatePixmap = fnCreatePixmap;
333     pPixmap = pScreen->CreatePixmap(pScreen, width, height, depth, usage_hint);
334     pScreen->CreatePixmap = XDbgLogCreatePixmap;
335
336     if(pPixmap)
337         _addXDbgPixmap (pPixmap);
338
339     return pPixmap;
340 }
341
342 static Bool
343 XDbgLogModifyPixmapHeader (PixmapPtr pPixmap, int width, int height,
344                               int depth, int bitsPerPixel, int devKind, pointer pPixData)
345 {
346     Bool ret;
347     ScreenPtr pScreen = pPixmap->drawable.pScreen;
348
349     pScreen->ModifyPixmapHeader = fnModifyPixmap;
350     ret = pScreen->ModifyPixmapHeader (pPixmap, width, height,
351                                        depth, bitsPerPixel, devKind, pPixData);
352     pScreen->ModifyPixmapHeader = XDbgLogModifyPixmapHeader;
353
354     _addXDbgPixmap (pPixmap);
355
356     return ret;
357 }
358
359 static Bool
360 XDbgLogDestroyPixmap (PixmapPtr pPixmap)
361 {
362     Bool ret;
363
364     ScreenPtr pScreen = pPixmap->drawable.pScreen;
365
366     if (pPixmap->refcnt == 1)
367         _removeXDbgPixmap (pPixmap);
368
369     pScreen->DestroyPixmap = fnDestroyPixmap;
370     ret = pScreen->DestroyPixmap(pPixmap);
371     pScreen->DestroyPixmap = XDbgLogDestroyPixmap;
372
373     return ret;
374 }
375
376 static void
377 XDbgLogSetWindowPixmap (WindowPtr pWin, PixmapPtr pPixmap)
378 {
379     ScreenPtr pScreen = (ScreenPtr) pWin->drawable.pScreen;
380     WindowPtr pParent = pWin->parent;
381     XDbgDrawable *d = NULL;
382     XDbgPixmap *p = NULL;
383     XDbgRefPixmap *p_ref = NULL;
384
385     pScreen->SetWindowPixmap = fnSetWindowPixmap;
386     pScreen->SetWindowPixmap (pWin, pPixmap);
387     pScreen->SetWindowPixmap = XDbgLogSetWindowPixmap;
388
389     if (pPixmap != pScreen->GetWindowPixmap(pParent))
390     {
391         //Add to window list
392         p = _findXDbgPixmap (pPixmap);
393         if (!p)
394         {
395             XDBG_WARNING (MMEM, "Unknown pixmap(%p) hint:%s\n",
396                           pPixmap, _get_pixmap_hint_name(pPixmap->usage_hint));
397             return;
398         }
399
400         d = _findXDbgDrawable (&pWin->drawable);
401         if (!d)
402         {
403             d = calloc (1, sizeof(XDbgDrawable));
404             d->pDraw = &pWin->drawable;
405             xorg_list_init (&d->refPixmaps);
406             xorg_list_add (&d->link, &xdbgDrawables);
407             XDBG_TRACE (MMEM, " Add window(0x%x)\n", (unsigned int)pWin->drawable.id);
408         }
409
410         if (d->pRefPixmap)
411         {
412             XDBG_TRACE (MMEM, " Unset WinPixmap win(0x%x), pixmap(%p) hint:%s\n",
413                                    (unsigned int)pWin->drawable.id, p->pPixmap, p->hint);
414             xorg_list_del (&d->pRefPixmap->link);
415             free (d->pRefPixmap);
416             d->pRefPixmap = NULL;
417         }
418
419         p_ref = calloc (1, sizeof(XDbgRefPixmap));
420         p_ref->pPixmap = pPixmap;
421         xorg_list_init (&p_ref->link);
422         xorg_list_add (&p_ref->link, &d->refPixmaps);
423         d->pRefPixmap = p_ref;
424
425         p->refs++;
426         p->refHistorys[p->numHistory++] = pWin->drawable.id;
427
428         XDBG_TRACE (MMEM, " Set WinPixmap win(0x%x), pixmap(%p) hint:%s\n",
429                             (unsigned int)pWin->drawable.id, p->pPixmap, p->hint);
430     }
431     else
432     {
433         //find window
434         d = _findXDbgDrawable (&pWin->drawable);
435
436         //remove window
437         if (d && d->pRefPixmap)
438         {
439             p = _findXDbgPixmap (d->pRefPixmap->pPixmap);
440             if (p)
441             {
442                 if (p->refs > 0)
443                     p->refs--;
444                 else
445                     XDBG_WARNING (MMEM, "pixmap(%p), refs(%d)\n",
446                                   __FUNCTION__, __LINE__, p->pPixmap, p->refs);
447             }
448
449             XDBG_TRACE (MMEM,"Unset WinPixmap win(0x%x): pixmap(%p) to NULL\n",
450                         (unsigned int)pWin->drawable.id, d->pRefPixmap->pPixmap);
451
452             p_ref = _findXDbgRefPixmap (d, d->pRefPixmap->pPixmap);
453             if(p_ref)
454             {
455                 xorg_list_del (&d->pRefPixmap->link);
456                 free (d->pRefPixmap);
457             }
458             else
459                 XDBG_WARNING (MMEM, "Unknown refpixmap : WinPixmap win(0x%x) pixmap(%p) \n",
460                                        (unsigned int)pWin->drawable.id, d->pRefPixmap->pPixmap);
461
462             d->pRefPixmap = NULL;
463
464             if (xorg_list_is_empty (&d->refPixmaps))
465             {
466                 xorg_list_del (&d->link);
467                 free(d);
468             }
469         }
470     }
471 }
472
473 static Bool
474 XDbgLogDestroyWindow (WindowPtr pWindow)
475 {
476     Bool ret;
477     ScreenPtr pScreen = pWindow->drawable.pScreen;
478     XDbgDrawable *d = NULL;
479     XDbgPixmap *p = NULL;
480     XDbgRefPixmap *pos = NULL, *tmp = NULL;
481
482     pScreen->DestroyWindow = fnDestroyWindow;
483     ret = pScreen->DestroyWindow (pWindow);
484     pScreen->DestroyWindow = XDbgLogDestroyWindow;
485
486     d = _findXDbgDrawable (&pWindow->drawable);
487     if (d)
488     {
489         XDBG_TRACE (MMEM, "Remove drawable(0x%x)\n",
490                     (unsigned int)pWindow->drawable.id);
491
492         xorg_list_for_each_entry_safe (pos, tmp, &d->refPixmaps, link)
493         {
494             p = _findXDbgPixmap (pos->pPixmap);
495             if(p)
496                 p->refs--;
497
498             XDBG_TRACE (MMEM, "Remove ref_pixmap(%p), dbgPixmap(%p)\n",
499                         pos->pPixmap, p);
500
501             xorg_list_del (&pos->link);
502             free (pos);
503         }
504
505         xorg_list_del (&d->link);
506         free (d);
507     }
508
509     return ret;
510 }
511
512 API void
513 xDbgLogPListInit (ScreenPtr pScreen)
514 {
515     init_plist = 1;
516
517     xorg_list_init (&xdbgPixmaps);
518     xorg_list_init (&xdbgDrawables);
519
520     fnSetWindowPixmap = pScreen->SetWindowPixmap;
521     fnDestroyWindow = pScreen->DestroyWindow;
522     fnCreatePixmap = pScreen->CreatePixmap;
523     fnModifyPixmap = pScreen->ModifyPixmapHeader;
524     fnDestroyPixmap = pScreen->DestroyPixmap;
525
526     pScreen->CreatePixmap = XDbgLogCreatePixmap;
527     pScreen->DestroyPixmap = XDbgLogDestroyPixmap;
528     pScreen->ModifyPixmapHeader = XDbgLogModifyPixmapHeader;
529     pScreen->SetWindowPixmap = XDbgLogSetWindowPixmap;
530     pScreen->DestroyWindow = XDbgLogDestroyWindow;
531 }
532
533 API void
534 xDbgLogPListDeinit (ScreenPtr pScreen)
535 {}
536
537
538 API void
539 xDbgLogPListDrawAddRefPixmap (DrawablePtr pDraw, PixmapPtr pRefPixmap)
540 {
541     XDbgDrawable *d = NULL;
542     XDbgPixmap *p = NULL;
543     XDbgRefPixmap *p_ref = NULL;
544
545     XDBG_RETURN_IF_FAIL (pDraw != NULL);
546     XDBG_RETURN_IF_FAIL (pRefPixmap != NULL);
547
548     d = _findXDbgDrawable (pDraw);
549     p = _findXDbgPixmap (pRefPixmap);
550     if(!p)
551     {
552         XDBG_WARNING (MMEM, "%s:%d : Unknown pixmap XID:0x%x, pPix:%p\n",
553                       __FUNCTION__, __LINE__,
554                       (unsigned int)pRefPixmap->drawable.id, pRefPixmap);
555         return;
556     }
557
558     if (!d)
559     {
560         d = calloc (1, sizeof(XDbgDrawable));
561         d->pDraw = pDraw;
562         xorg_list_init (&d->refPixmaps);
563         xorg_list_add (&d->link, &xdbgDrawables);
564
565         XDBG_TRACE (MMEM, " Add window(0x%x)\n", (unsigned int)pDraw->id);
566     }
567
568     p_ref =_findXDbgRefPixmap (d, pRefPixmap);
569     if(p_ref)
570         return;
571
572     p_ref = calloc (1, sizeof(XDbgRefPixmap));
573     p_ref->pPixmap = pRefPixmap;
574     xorg_list_init (&p_ref->link);
575     xorg_list_add (&p_ref->link, &d->refPixmaps);
576
577     p->refs++;
578     if (p->numHistory < (MAX_HISTORY-1))
579         p->refHistorys[p->numHistory++] = pDraw->id;
580
581     if (pDraw->type == DRAWABLE_WINDOW)
582         XDBG_TRACE (MMEM, " Add RefPixmap win(0x%x), pixmap(%p) hint:%s\n",
583                     (unsigned int)pDraw->id, p->pPixmap, p->hint);
584     else
585         XDBG_TRACE (MMEM, " Add RefPixmap pix(0x%x), pixmap(%p) hint:%s\n",
586                     (unsigned int)pDraw->id, p->pPixmap, p->hint);
587 }
588
589 API void
590 xDbgLogPListDrawRemoveRefPixmap (DrawablePtr pDraw, PixmapPtr pRefPixmap)
591 {
592     XDbgDrawable *d = NULL;
593     XDbgRefPixmap *p_ref = NULL;
594     XDbgPixmap *p = NULL;
595
596     p = _findXDbgPixmap (pRefPixmap);
597     if (pDraw == NULL)
598     {
599         if (p && p->refs > 0)
600         {
601             XDBG_ERROR (MMEM, "Error:%s:%d null draw pixmap(%p)\n",
602                         __FUNCTION__, __LINE__, pRefPixmap);
603         }
604         return;
605     }
606
607     d = _findXDbgDrawable (pDraw);
608     if (!d)
609     {
610         XDBG_WARNING (MMEM, "%s:%d : Unknown drawable XID:0x%x, pPix:%p\n",
611                       __FUNCTION__, __LINE__, (unsigned int)pDraw->id, pRefPixmap);
612         return;
613     }
614
615     p_ref = _findXDbgRefPixmap (d, pRefPixmap);
616     if(!p_ref)
617     {
618         XDBG_WARNING (MMEM, "%s:%d : Unknown refpixmap XID:0x%x, pPix:%p\n",
619                                   __FUNCTION__, __LINE__, (unsigned int)pDraw->id, pRefPixmap);
620         return;
621     }
622
623     xorg_list_del (&p_ref->link);
624     free (p_ref);
625     if (p)
626         p->refs--;
627
628     if (xorg_list_is_empty (&d->refPixmaps))
629     {
630         xorg_list_del(&d->link);
631         free(d);
632     }
633
634     if (pDraw->type == DRAWABLE_WINDOW)
635         XDBG_TRACE (MMEM, " Remove RefPixmap win(0x%x), pixmap(%p) hint:%s\n",
636                                 (unsigned int)pDraw->id, pRefPixmap,
637                                 _get_pixmap_hint_name(pRefPixmap->usage_hint));
638     else
639         XDBG_TRACE (MMEM, " Remove RefPixmap pix(0x%x), pixmap(%p) hint:%s\n",
640                                 (unsigned int)pDraw->id, pRefPixmap,
641                                 _get_pixmap_hint_name(pRefPixmap->usage_hint));
642 }
643
644
645 API void
646 xDbgLogPList (char *reply, int *len)
647 {
648     if (!init_plist)
649     {
650         XDBG_REPLY ("plist is not supported.\n");
651         return;
652     }
653
654     XDBG_REPLY ("\n\n====================================\n");
655     XDBG_REPLY ("    Total:%d, Peek:%d\n", (unsigned int)total_size/1024, (unsigned int)peek_size/1024);
656     XDBG_REPLY ( "====================================\n");
657
658     XDBG_REPLY ("== WINDOWS ==\n");
659     XDbgDrawable *dd = NULL, *ddtmp = NULL;
660     XDbgRefPixmap *rp = NULL, *rptmp = NULL;
661     XDbgPixmap *dp = NULL;
662
663     xorg_list_for_each_entry_safe (dd, ddtmp, &xdbgDrawables, link)
664     {
665         XDBG_REPLY ("[%d] XID:0x%x type:%s %dx%d+%d+%d\n",
666                                 CLIENT_ID(dd->pDraw->id),
667                                 (unsigned int)dd->pDraw->id,
668                                 (dd->pDraw->type == DRAWABLE_WINDOW ? "window":"pixmap"),
669                                 dd->pDraw->width, dd->pDraw->height, dd->pDraw->x, dd->pDraw->y);
670
671         xorg_list_for_each_entry_safe (rp, rptmp, &dd->refPixmaps, link)
672         {
673             dp = _findXDbgPixmap (rp->pPixmap);
674             if(!dp)
675             {
676                 XDBG_REPLY ("\t***[REF_Pixmap] unknown pixmap(%p)\n", rp->pPixmap);
677                 continue;
678             }
679
680             XDBG_REPLY ("\t[REF_Pixmap] %p, hint:%s, size:%d\n",
681                                      dp->pPixmap, dp->hint, (unsigned int)dp->size/1024);
682         }
683     }
684     XDBG_REPLY ("\n");
685
686
687     XDBG_REPLY ( "== PIXMAPS ==\n");
688     XDbgPixmap *cur = NULL, *tmp = NULL;
689     int client_id;
690     int i;
691
692     if (pPixRoot)
693     {
694         cur = _findXDbgPixmap (pPixRoot);
695         XDBG_RETURN_IF_FAIL (cur != NULL);
696         XDBG_REPLY ("ROOT_Pixmap XID:0x%x pixmap(%p) hint:%s(0x%x) size:%d\n",
697                                 (unsigned int)cur->pPixmap->drawable.id, pPixRoot,
698                                 cur->hint, cur->pPixmap->usage_hint,
699                                 (unsigned int)cur->size/1024);
700     }
701
702     xorg_list_for_each_entry_safe (cur, tmp, &xdbgPixmaps, link)
703     {
704         if (cur->pPixmap == pPixRoot)
705             continue;
706
707         if (cur->pPixmap->drawable.id || cur->refs == 0)
708         {
709             client_id = CLIENT_ID(cur->pPixmap->drawable.id);
710             if (cur->pPixmap->drawable.id)
711             {
712                 XDBG_REPLY ("[%d] XID:0x%x %dx%d hint:%s(0x%x) size:%d refs:%d\n",
713                                         client_id, (unsigned int)cur->pPixmap->drawable.id,
714                                         cur->pPixmap->drawable.width, cur->pPixmap->drawable.height,
715                                         cur->hint, cur->pPixmap->usage_hint,
716                                         (unsigned int)cur->size/1024, cur->refs);
717             }
718             else
719             {
720                 XDBG_REPLY ("[%d] Pixmap:%p %dx%d hint:%s(0x%x) size:%d refs:%d\n",
721                                         client_id, cur->pPixmap,
722                                         cur->pPixmap->drawable.width, cur->pPixmap->drawable.height,
723                                         cur->hint, cur->pPixmap->usage_hint,
724                                         (unsigned int)cur->size/1024, cur->refs);
725             }
726
727             if (cur->numHistory)
728             {
729                 XDBG_REPLY ("\t[RefHistory] ");
730                 for (i = 0; i < cur->numHistory; i++)
731                 {
732                     XDBG_REPLY ("0x%x ", (unsigned int)cur->refHistorys[i]);
733                 }
734                 XDBG_REPLY ("\n");
735             }
736         }
737     }
738     XDBG_REPLY ("\n");
739 }
740