From 6e657b2ca5423318f1539a2bcc966c11108c75f3 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Fri, 4 Apr 2025 14:42:30 +0200 Subject: [PATCH] dix: write out X_AllocColorPlanes reply directly No need for using a complex callback machinery, if we just move the little pieces of byte-swapping directly into the request handler. Signed-off-by: Enrico Weigelt, metux IT consult --- dix/dispatch.c | 26 ++++++++++++++++++-------- dix/swaprep.c | 13 ------------- dix/tables.c | 2 +- include/swaprep.h | 5 ----- 4 files changed, 19 insertions(+), 27 deletions(-) diff --git a/dix/dispatch.c b/dix/dispatch.c index 81508a6b2..2a477274c 100644 --- a/dix/dispatch.c +++ b/dix/dispatch.c @@ -2795,7 +2795,6 @@ ProcAllocColorPlanes(ClientPtr client) rc = dixLookupResourceByType((void **) &pcmp, stuff->cmap, X11_RESTYPE_COLORMAP, client, DixAddAccess); if (rc == Success) { - xAllocColorPlanesReply acpr; int npixels; long length; @@ -2808,7 +2807,8 @@ ProcAllocColorPlanes(ClientPtr client) client->errorValue = stuff->contiguous; return BadValue; } - acpr = (xAllocColorPlanesReply) { + + xAllocColorPlanesReply rep = { .type = X_Reply, .sequenceNumber = client->sequence, .nPixels = npixels @@ -2821,19 +2821,29 @@ ProcAllocColorPlanes(ClientPtr client) if ((rc = AllocColorPlanes(client->index, pcmp, npixels, (int) stuff->red, (int) stuff->green, (int) stuff->blue, (Bool) stuff->contiguous, - ppixels, &acpr.redMask, &acpr.greenMask, - &acpr.blueMask))) { + ppixels, &rep.redMask, &rep.greenMask, + &rep.blueMask))) { free(ppixels); return rc; } - acpr.length = bytes_to_int32(length); + rep.length = bytes_to_int32(length); + + if (client->swapped) { + SwapLongs(ppixels, rep.length); + swaps(&rep.sequenceNumber); + swapl(&rep.length); + swaps(&rep.nPixels); + swapl(&rep.redMask); + swapl(&rep.greenMask); + swapl(&rep.blueMask); + } + #ifdef XINERAMA if (noPanoramiXExtension || !pcmp->pScreen->myNum) #endif /* XINERAMA */ { - WriteReplyToClient(client, sizeof(xAllocColorPlanesReply), &acpr); - client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write; - WriteSwappedDataToClient(client, length, ppixels); + WriteToClient(client, sizeof(rep), &rep); + WriteToClient(client, length, ppixels); } free(ppixels); return Success; diff --git a/dix/swaprep.c b/dix/swaprep.c index 88256721b..2e0690a80 100644 --- a/dix/swaprep.c +++ b/dix/swaprep.c @@ -310,19 +310,6 @@ SGetFontPathReply(ClientPtr pClient, int size, xGetFontPathReply * pRep) WriteToClient(pClient, size, pRep); } -void _X_COLD -SAllocColorPlanesReply(ClientPtr pClient, int size, - xAllocColorPlanesReply * pRep) -{ - swaps(&pRep->sequenceNumber); - swapl(&pRep->length); - swaps(&pRep->nPixels); - swapl(&pRep->redMask); - swapl(&pRep->greenMask); - swapl(&pRep->blueMask); - WriteToClient(pClient, size, pRep); -} - static void _X_COLD SwapRGB(xrgb * prgb) { diff --git a/dix/tables.c b/dix/tables.c index 7871d3957..ec538feee 100644 --- a/dix/tables.c +++ b/dix/tables.c @@ -802,7 +802,7 @@ ReplySwapPtr ReplySwapVector[256] = { ReplyNotSwappd, ReplyNotSwappd, /* 85 */ ReplyNotSwappd, - (ReplySwapPtr) SAllocColorPlanesReply, + ReplyNotSwappd, ReplyNotSwappd, ReplyNotSwappd, ReplyNotSwappd, /* 90 */ diff --git a/include/swaprep.h b/include/swaprep.h index 08501e239..eb29b4e34 100644 --- a/include/swaprep.h +++ b/include/swaprep.h @@ -68,11 +68,6 @@ extern void SGetFontPathReply(ClientPtr /* pClient */ , int /* size */ , xGetFontPathReply * /* pRep */ ); -extern void SAllocColorPlanesReply(ClientPtr /* pClient */ , - int /* size */ , - xAllocColorPlanesReply * /* pRep */ - ); - extern void SQColorsExtend(ClientPtr /* pClient */ , int /* size */ , xrgb * /* prgb */ );