summaryrefslogtreecommitdiff
path: root/Xext/xres.c
diff options
context:
space:
mode:
Diffstat (limited to 'Xext/xres.c')
-rw-r--r--Xext/xres.c66
1 files changed, 63 insertions, 3 deletions
diff --git a/Xext/xres.c b/Xext/xres.c
index 9f3624ba5..1617337bf 100644
--- a/Xext/xres.c
+++ b/Xext/xres.c
@@ -1,8 +1,6 @@
/*
Copyright (c) 2002 XFree86 Inc
*/
-/* $XFree86: xc/programs/Xserver/Xext/xres.c,v 1.7tsi Exp $ */
-/* $XdotOrg: xserver/xorg/Xext/xres.c,v 1.8 2006/02/11 19:16:50 alanc Exp $ */
#define NEED_EVENTS
#define NEED_REPLIES
@@ -21,6 +19,8 @@
#include "swaprep.h"
#include <X11/extensions/XResproto.h>
#include "pixmapstr.h"
+#include "windowstr.h"
+#include "gcstruct.h"
#include "modinit.h"
static int
@@ -156,6 +156,7 @@ ProcXResQueryClientResources (ClientPtr client)
swapl (&rep.length, n);
swapl (&rep.num_types, n);
}
+
WriteToClient (client,sizeof(xXResQueryClientResourcesReply),(char*)&rep);
if(num_types) {
@@ -187,13 +188,54 @@ ProcXResQueryClientResources (ClientPtr client)
return (client->noClientException);
}
+static unsigned long
+ResGetApproxPixmapBytes (PixmapPtr pix)
+{
+ unsigned long nPixels;
+ int bytesPerPixel;
+
+ bytesPerPixel = pix->drawable.bitsPerPixel>>3;
+ nPixels = pix->drawable.width * pix->drawable.height;
+
+ /* Divide by refcnt as pixmap could be shared between clients,
+ * so total pixmap mem is shared between these.
+ */
+ return ( nPixels * bytesPerPixel ) / pix->refcnt;
+}
+
static void
ResFindPixmaps (pointer value, XID id, pointer cdata)
{
unsigned long *bytes = (unsigned long *)cdata;
PixmapPtr pix = (PixmapPtr)value;
- *bytes += (pix->devKind * pix->drawable.height);
+ *bytes += ResGetApproxPixmapBytes(pix);
+}
+
+static void
+ResFindWindowPixmaps (pointer value, XID id, pointer cdata)
+{
+ unsigned long *bytes = (unsigned long *)cdata;
+ WindowPtr pWin = (WindowPtr)value;
+
+ if (pWin->backgroundState == BackgroundPixmap)
+ *bytes += ResGetApproxPixmapBytes(pWin->background.pixmap);
+
+ if (pWin->border.pixmap != NULL && !pWin->borderIsPixel)
+ *bytes += ResGetApproxPixmapBytes(pWin->border.pixmap);
+}
+
+static void
+ResFindGCPixmaps (pointer value, XID id, pointer cdata)
+{
+ unsigned long *bytes = (unsigned long *)cdata;
+ GCPtr pGC = (GCPtr)value;
+
+ if (pGC->stipple != NULL)
+ *bytes += ResGetApproxPixmapBytes(pGC->stipple);
+
+ if (pGC->tile.pixmap != NULL && !pGC->tileIsPixel)
+ *bytes += ResGetApproxPixmapBytes(pGC->tile.pixmap);
}
static int
@@ -220,6 +262,24 @@ ProcXResQueryClientPixmapBytes (ClientPtr client)
FindClientResourcesByType(clients[clientID], RT_PIXMAP, ResFindPixmaps,
(pointer)(&bytes));
+ /*
+ * Make sure win background pixmaps also held to account.
+ */
+ FindClientResourcesByType(clients[clientID], RT_WINDOW,
+ ResFindWindowPixmaps,
+ (pointer)(&bytes));
+
+ /*
+ * GC Tile & Stipple pixmaps too.
+ */
+ FindClientResourcesByType(clients[clientID], RT_GC,
+ ResFindGCPixmaps,
+ (pointer)(&bytes));
+
+#ifdef COMPOSITE
+ /* FIXME: include composite pixmaps too */
+#endif
+
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
rep.length = 0;