From 8e8258129176a56a877d7f5c3a890d722bfeb71d Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 2 Apr 2025 20:26:03 +0200 Subject: [PATCH] dix: write out xGetImageReply directly Signed-off-by: Enrico Weigelt, metux IT consult --- Xext/panoramiXprocs.c | 23 ++++++++++++++--------- dix/dispatch.c | 25 +++++++++++++++---------- dix/swaprep.c | 10 ---------- dix/tables.c | 2 +- include/swaprep.h | 4 ---- 5 files changed, 30 insertions(+), 34 deletions(-) diff --git a/Xext/panoramiXprocs.c b/Xext/panoramiXprocs.c index dc4da31ed..889866a79 100644 --- a/Xext/panoramiXprocs.c +++ b/Xext/panoramiXprocs.c @@ -1967,7 +1967,6 @@ PanoramiXGetImage(ClientPtr client) DrawablePtr drawables[MAXSCREENS]; DrawablePtr pDraw; PanoramiXRes *draw; - xGetImageReply xgi; Bool isRoot; char *pBuf; int i, x, y, w, h, format, rc; @@ -2041,12 +2040,7 @@ PanoramiXGetImage(ClientPtr client) IncludeInferiors); } - xgi = (xGetImageReply) { - .type = X_Reply, - .sequenceNumber = client->sequence, - .visual = wVisual(((WindowPtr) pDraw)), - .depth = pDraw->depth - }; + if (format == ZPixmap) { widthBytesLine = PixmapBytePad(w, pDraw->depth); length = widthBytesLine * h; @@ -2060,7 +2054,13 @@ PanoramiXGetImage(ClientPtr client) } - xgi.length = bytes_to_int32(length); + xGetImageReply rep = { + .type = X_Reply, + .sequenceNumber = client->sequence, + .visual = wVisual(((WindowPtr) pDraw)), + .depth = pDraw->depth, + .length = bytes_to_int32(length), + }; if (widthBytesLine == 0 || h == 0) linesPerBuf = 0; @@ -2074,7 +2074,12 @@ PanoramiXGetImage(ClientPtr client) if (!(pBuf = calloc(linesPerBuf, widthBytesLine))) return BadAlloc; - WriteReplyToClient(client, sizeof(xGetImageReply), &xgi); + if (client->swapped) { + swaps(&rep.sequenceNumber); + swapl(&rep.length); + swapl(&rep.visual); + } + WriteToClient(client, sizeof(rep), &rep); if (linesPerBuf == 0) { /* nothing to do */ diff --git a/dix/dispatch.c b/dix/dispatch.c index 4d2dcdf57..f2e1e718f 100644 --- a/dix/dispatch.c +++ b/dix/dispatch.c @@ -2160,7 +2160,6 @@ DoGetImage(ClientPtr client, int format, Drawable drawable, long widthBytesLine, length; Mask plane = 0; char *pBuf; - xGetImageReply xgi; RegionPtr pVisibleRegion = NULL; if ((format != XYPixmap) && (format != ZPixmap)) { @@ -2171,7 +2170,10 @@ DoGetImage(ClientPtr client, int format, Drawable drawable, if (rc != Success) return rc; - memset(&xgi, 0, sizeof(xGetImageReply)); + xGetImageReply rep = { + .type = X_Reply, + .sequenceNumber = client->sequence, + }; relx = x; rely = y; @@ -2208,11 +2210,11 @@ DoGetImage(ClientPtr client, int format, Drawable drawable, pBoundingDraw = (DrawablePtr) pDraw->pScreen->root; } - xgi.visual = wVisual(pWin); + rep.visual = wVisual(pWin); } else { pBoundingDraw = pDraw; - xgi.visual = None; + rep.visual = None; } /* "If the drawable is a pixmap, the given rectangle must be wholly @@ -2230,9 +2232,7 @@ DoGetImage(ClientPtr client, int format, Drawable drawable, rely < 0 || rely + height > (int) pBoundingDraw->height) return BadMatch; - xgi.type = X_Reply; - xgi.sequenceNumber = client->sequence; - xgi.depth = pDraw->depth; + rep.depth = pDraw->depth; if (format == ZPixmap) { widthBytesLine = PixmapBytePad(width, pDraw->depth); length = widthBytesLine * height; @@ -2247,9 +2247,8 @@ DoGetImage(ClientPtr client, int format, Drawable drawable, } - xgi.length = length; + rep.length = bytes_to_int32(length); - xgi.length = bytes_to_int32(xgi.length); if (widthBytesLine == 0 || height == 0) linesPerBuf = 0; else if (widthBytesLine >= IMAGE_BUFSIZE) @@ -2274,7 +2273,13 @@ DoGetImage(ClientPtr client, int format, Drawable drawable, } if (!(pBuf = calloc(1, length))) return BadAlloc; - WriteReplyToClient(client, sizeof(xGetImageReply), &xgi); + + if (client->swapped) { + swaps(&rep.sequenceNumber); + swapl(&rep.length); + swapl(&rep.visual); + } + WriteToClient(client, sizeof(rep), &rep); if (pDraw->type == DRAWABLE_WINDOW) { pVisibleRegion = &((WindowPtr) pDraw)->borderClip; diff --git a/dix/swaprep.c b/dix/swaprep.c index a3ac6054d..ef7b2bf5b 100644 --- a/dix/swaprep.c +++ b/dix/swaprep.c @@ -424,16 +424,6 @@ SGetFontPathReply(ClientPtr pClient, int size, xGetFontPathReply * pRep) WriteToClient(pClient, size, pRep); } -void _X_COLD -SGetImageReply(ClientPtr pClient, int size, xGetImageReply * pRep) -{ - swaps(&pRep->sequenceNumber); - swapl(&pRep->length); - swapl(&pRep->visual); - WriteToClient(pClient, size, pRep); - /* Fortunately, image doesn't need swapping */ -} - void _X_COLD SListInstalledColormapsReply(ClientPtr pClient, int size, xListInstalledColormapsReply * pRep) diff --git a/dix/tables.c b/dix/tables.c index 86e1484e2..d0eb83b51 100644 --- a/dix/tables.c +++ b/dix/tables.c @@ -789,7 +789,7 @@ ReplySwapPtr ReplySwapVector[256] = { ReplyNotSwappd, /* 70 */ ReplyNotSwappd, ReplyNotSwappd, - (ReplySwapPtr) SGetImageReply, + ReplyNotSwappd, ReplyNotSwappd, ReplyNotSwappd, /* 75 */ ReplyNotSwappd, diff --git a/include/swaprep.h b/include/swaprep.h index 03e17fa47..133b022c7 100644 --- a/include/swaprep.h +++ b/include/swaprep.h @@ -115,10 +115,6 @@ extern void SGetFontPathReply(ClientPtr /* pClient */ , int /* size */ , xGetFontPathReply * /* pRep */ ); -extern void SGetImageReply(ClientPtr /* pClient */ , - int /* size */ , - xGetImageReply * /* pRep */ ); - extern void SListInstalledColormapsReply(ClientPtr /* pClient */ , int /* size */ , xListInstalledColormapsReply