From 0d99fd2d1c00c4c6d8ad4edb98adb684d4ac876e Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Thu, 17 Jul 2025 21:13:26 +0200 Subject: [PATCH] Xext: xv: ProcXvQueryExtension() simplify reply header assembly As a prepration for upcoming changes, move assembly of the the reply header further downwards where all values are already known, so we'll have to touch it only once. Also eliminate the separate write path for the case where Xv is disabled. Signed-off-by: Enrico Weigelt, metux IT consult --- Xext/xvdisp.c | 56 ++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/Xext/xvdisp.c b/Xext/xvdisp.c index 1c94b55219..03f726ffbc 100644 --- a/Xext/xvdisp.c +++ b/Xext/xvdisp.c @@ -83,7 +83,7 @@ ProcXvQueryExtension(ClientPtr client) static int ProcXvQueryAdaptors(ClientPtr client) { - int totalSize, na, nf, rc; + int na, nf, rc; int nameSize; XvAdaptorPtr pa; XvFormatPtr pf; @@ -98,37 +98,36 @@ ProcXvQueryAdaptors(ClientPtr client) if (rc != Success) return rc; - xvQueryAdaptorsReply rep = { - .type = X_Reply, - .sequenceNumber = client->sequence, - }; - pScreen = pWin->drawable.pScreen; pxvs = (XvScreenPtr) dixLookupPrivate(&pScreen->devPrivates, XvGetScreenKey()); - if (!pxvs) { - if (client->swapped) swaps(&rep.sequenceNumber); - WriteToClient(client, sizeof(rep), &rep); - return Success; + + size_t totalSize = 0; + size_t numAdaptors = 0; + if (pxvs) { + numAdaptors = pxvs->nAdaptors; + + /* CALCULATE THE TOTAL SIZE OF THE REPLY IN BYTES */ + + totalSize = pxvs->nAdaptors * sz_xvAdaptorInfo; + + /* FOR EACH ADPATOR ADD UP THE BYTES FOR ENCODINGS AND FORMATS */ + + na = pxvs->nAdaptors; + pa = pxvs->pAdaptors; + while (na--) { + totalSize += pad_to_int32(strlen(pa->name)); + totalSize += pa->nFormats * sz_xvFormat; + pa++; + } } - rep.num_adaptors = pxvs->nAdaptors; - - /* CALCULATE THE TOTAL SIZE OF THE REPLY IN BYTES */ - - totalSize = pxvs->nAdaptors * sz_xvAdaptorInfo; - - /* FOR EACH ADPATOR ADD UP THE BYTES FOR ENCODINGS AND FORMATS */ - - na = pxvs->nAdaptors; - pa = pxvs->pAdaptors; - while (na--) { - totalSize += pad_to_int32(strlen(pa->name)); - totalSize += pa->nFormats * sz_xvFormat; - pa++; - } - - rep.length = bytes_to_int32(totalSize); + xvQueryAdaptorsReply rep = { + .type = X_Reply, + .sequenceNumber = client->sequence, + .num_adaptors = numAdaptors, + .length = bytes_to_int32(totalSize) + }; if (client->swapped) { swaps(&rep.sequenceNumber); @@ -137,6 +136,9 @@ ProcXvQueryAdaptors(ClientPtr client) } WriteToClient(client, sizeof(rep), &rep); + if (!pxvs) /* no payload to send, we're done here */ + return Success; + na = pxvs->nAdaptors; pa = pxvs->pAdaptors; while (na--) {