From 48918f28d9b4e7f36258743035e940aa704a831f Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 24 Jul 2024 17:37:57 +0200 Subject: [PATCH] Xext: panoramiX: PanoramiXGetImage() reply payload in one block Simplify writing reply payload into just one block. This also makes further simplifications by subsequent patches easier. Signed-off-by: Enrico Weigelt, metux IT consult --- Xext/panoramiXprocs.c | 49 ++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/Xext/panoramiXprocs.c b/Xext/panoramiXprocs.c index 2cff60990..72982919a 100644 --- a/Xext/panoramiXprocs.c +++ b/Xext/panoramiXprocs.c @@ -1960,7 +1960,6 @@ PanoramiXGetImage(ClientPtr client) DrawablePtr pDraw; PanoramiXRes *draw; Bool isRoot; - char *pBuf; int i, x, y, w, h, format, rc; Mask plane = 0, planemask; int linesDone, nlines, linesPerBuf; @@ -2032,7 +2031,6 @@ PanoramiXGetImage(ClientPtr client) IncludeInferiors); } - if (format == ZPixmap) { widthBytesLine = PixmapBytePad(w, pDraw->depth); length = widthBytesLine * h; @@ -2046,14 +2044,6 @@ PanoramiXGetImage(ClientPtr client) } - 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; else if (widthBytesLine >= XINERAMA_IMAGE_BUFSIZE) @@ -2063,15 +2053,9 @@ PanoramiXGetImage(ClientPtr client) if (linesPerBuf > h) linesPerBuf = h; } - if (!(pBuf = calloc(linesPerBuf, widthBytesLine))) - return BadAlloc; - if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); - swapl(&rep.visual); - } - WriteToClient(client, sizeof(rep), &rep); + char *payload = calloc(1, length); + char *walk = payload; if (linesPerBuf == 0) { /* nothing to do */ @@ -2081,14 +2065,11 @@ PanoramiXGetImage(ClientPtr client) while (h - linesDone > 0) { nlines = min(linesPerBuf, h - linesDone); - if (pDraw->depth == 1) - memset(pBuf, 0, nlines * widthBytesLine); - XineramaGetImageData(drawables, x, y + linesDone, w, nlines, - format, planemask, pBuf, widthBytesLine, + format, planemask, walk, widthBytesLine, isRoot); - WriteToClient(client, (int) (nlines * widthBytesLine), pBuf); + walk += nlines * widthBytesLine; linesDone += nlines; } } @@ -2099,20 +2080,30 @@ PanoramiXGetImage(ClientPtr client) while (h - linesDone > 0) { nlines = min(linesPerBuf, h - linesDone); - memset(pBuf, 0, nlines * widthBytesLine); - XineramaGetImageData(drawables, x, y + linesDone, w, - nlines, format, plane, pBuf, + nlines, format, plane, walk, widthBytesLine, isRoot); - WriteToClient(client, (int)(nlines * widthBytesLine), pBuf); - + walk += nlines * widthBytesLine; linesDone += nlines; } } } } - free(pBuf); + + xGetImageReply xgi = { + .type = X_Reply, + .sequenceNumber = client->sequence, + .visual = wVisual(((WindowPtr) pDraw)), + .depth = pDraw->depth, + .length = bytes_to_int32(length), + }; + + WriteReplyToClient(client, sizeof(xGetImageReply), &xgi); + + if (length) + WriteToClient(client, length, payload); + return Success; }