From 165e48e28643892c0d3908927931cb0e2a17130c Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 24 Jul 2024 18:35:24 +0200 Subject: [PATCH] (submit/cleanup-xv-dispatch) Xext: xv: ProcXvQueryAdaptors(): write reply payload at once. Collect up the puzzle piezes of the reply payload into to a temporary struct, so we can send it as one block. This allows for further simplifications by subsequent commits. Signed-off-by: Enrico Weigelt, metux IT consult --- Xext/xvdisp.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/Xext/xvdisp.c b/Xext/xvdisp.c index 483a97b95..63d0ed2c1 100644 --- a/Xext/xvdisp.c +++ b/Xext/xvdisp.c @@ -82,8 +82,6 @@ ProcXvQueryExtension(ClientPtr client) static int ProcXvQueryAdaptors(ClientPtr client) { - xvFormat format; - xvAdaptorInfo ainfo; int totalSize, na, nf, rc; int nameSize; XvAdaptorPtr pa; @@ -129,43 +127,47 @@ ProcXvQueryAdaptors(ClientPtr client) pa++; } + char payload[totalSize]; + memset(payload, 0, totalSize); + char *walk = payload; + rep.length = bytes_to_int32(totalSize); if (client->swapped) { swaps(&rep.sequenceNumber); swapl(&rep.length); swaps(&rep.num_adaptors); - WriteToClient(client, sizeof(rep), &rep); } na = pxvs->nAdaptors; pa = pxvs->pAdaptors; while (na--) { + xvAdaptorInfo *ainfo = (xvAdaptorInfo*)walk; - ainfo.base_id = pa->base_id; - ainfo.num_ports = pa->nPorts; - ainfo.type = pa->type; - ainfo.name_size = nameSize = strlen(pa->name); - ainfo.num_formats = pa->nFormats; + ainfo->base_id = pa->base_id; + ainfo->num_ports = pa->nPorts; + ainfo->type = pa->type; + ainfo->name_size = nameSize = strlen(pa->name); + ainfo->num_formats = pa->nFormats; if (client->swapped) { - swapl(&ainfo.base_id); - swaps(&ainfo.name_size); - swaps(&ainfo.num_ports); - swaps(&ainfo.num_formats); + swapl(&ainfo->base_id); + swaps(&ainfo->name_size); + swaps(&ainfo->num_ports); + swaps(&ainfo->num_formats); } - WriteToClient(client, sizeof(ainfo), &ainfo); - - WriteToClient(client, nameSize, pa->name); + walk += sizeof(ainfo); + memcpy(walk, pa->name, nameSize); + walk += pad_to_int32(nameSize); nf = pa->nFormats; pf = pa->pFormats; while (nf--) { - format.depth = pf->depth; - format.visual = pf->visual; - if (client->swapped) swapl(&format.visual); - WriteToClient(client, sizeof(format), &format); + xvFormat *format = (xvFormat *)walk; + format->depth = pf->depth; + format->visual = pf->visual; + if (client->swapped) swapl(&format->visual); pf++; } @@ -173,6 +175,9 @@ ProcXvQueryAdaptors(ClientPtr client) } + WriteToClient(client, sizeof(rep), &rep); + WriteToClient(client, sizeof(payload), payload); + return Success; }