dri3: use static reply struct init on declaration

Make the code a bit easier to read by using initialization of the reply
structs, at the point of declaration. Most of them aren't written to later,
just passed into WriteReplyToClient(). Also dropping some useless zero
assignments (struct initializers automatically zero-out unmentioned fields).

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2024-07-15 11:48:03 +02:00
parent fbeee675fc
commit ea78435fdd

View File

@ -64,10 +64,10 @@ static int
proc_dri3_query_version(ClientPtr client) proc_dri3_query_version(ClientPtr client)
{ {
REQUEST(xDRI3QueryVersionReq); REQUEST(xDRI3QueryVersionReq);
xDRI3QueryVersionReply rep = { xDRI3QueryVersionReply rep = {
.type = X_Reply, .type = X_Reply,
.sequenceNumber = client->sequence, .sequenceNumber = client->sequence,
.length = 0,
.majorVersion = SERVER_DRI3_MAJOR_VERSION, .majorVersion = SERVER_DRI3_MAJOR_VERSION,
.minorVersion = SERVER_DRI3_MINOR_VERSION .minorVersion = SERVER_DRI3_MINOR_VERSION
}; };
@ -127,7 +127,6 @@ dri3_send_open_reply(ClientPtr client, int fd)
.type = X_Reply, .type = X_Reply,
.nfd = 1, .nfd = 1,
.sequenceNumber = client->sequence, .sequenceNumber = client->sequence,
.length = 0,
}; };
if (client->swapped) { if (client->swapped) {
@ -257,12 +256,7 @@ static int
proc_dri3_buffer_from_pixmap(ClientPtr client) proc_dri3_buffer_from_pixmap(ClientPtr client)
{ {
REQUEST(xDRI3BufferFromPixmapReq); REQUEST(xDRI3BufferFromPixmapReq);
xDRI3BufferFromPixmapReply rep = {
.type = X_Reply,
.nfd = 1,
.sequenceNumber = client->sequence,
.length = 0,
};
int rc; int rc;
int fd; int fd;
PixmapPtr pixmap; PixmapPtr pixmap;
@ -275,10 +269,15 @@ proc_dri3_buffer_from_pixmap(ClientPtr client)
return rc; return rc;
} }
rep.width = pixmap->drawable.width; xDRI3BufferFromPixmapReply rep = {
rep.height = pixmap->drawable.height; .type = X_Reply,
rep.depth = pixmap->drawable.depth; .nfd = 1,
rep.bpp = pixmap->drawable.bitsPerPixel; .sequenceNumber = client->sequence,
.width = pixmap->drawable.width,
.height = pixmap->drawable.height,
.depth = pixmap->drawable.depth,
.bpp = pixmap->drawable.bitsPerPixel,
};
fd = dri3_fd_from_pixmap(pixmap, &rep.stride, &rep.size); fd = dri3_fd_from_pixmap(pixmap, &rep.stride, &rep.size);
if (fd < 0) if (fd < 0)
@ -336,7 +335,6 @@ proc_dri3_fd_from_fence(ClientPtr client)
.type = X_Reply, .type = X_Reply,
.nfd = 1, .nfd = 1,
.sequenceNumber = client->sequence, .sequenceNumber = client->sequence,
.length = 0,
}; };
DrawablePtr drawable; DrawablePtr drawable;
int fd; int fd;
@ -372,10 +370,6 @@ static int
proc_dri3_get_supported_modifiers(ClientPtr client) proc_dri3_get_supported_modifiers(ClientPtr client)
{ {
REQUEST(xDRI3GetSupportedModifiersReq); REQUEST(xDRI3GetSupportedModifiersReq);
xDRI3GetSupportedModifiersReply rep = {
.type = X_Reply,
.sequenceNumber = client->sequence,
};
WindowPtr window; WindowPtr window;
ScreenPtr pScreen; ScreenPtr pScreen;
CARD64 *window_modifiers = NULL; CARD64 *window_modifiers = NULL;
@ -397,10 +391,14 @@ proc_dri3_get_supported_modifiers(ClientPtr client)
&nwindowmodifiers, &window_modifiers, &nwindowmodifiers, &window_modifiers,
&nscreenmodifiers, &screen_modifiers); &nscreenmodifiers, &screen_modifiers);
rep.numWindowModifiers = nwindowmodifiers; xDRI3GetSupportedModifiersReply rep = {
rep.numScreenModifiers = nscreenmodifiers; .type = X_Reply,
rep.length = bytes_to_int32(rep.numWindowModifiers * sizeof(CARD64)) + .sequenceNumber = client->sequence,
bytes_to_int32(rep.numScreenModifiers * sizeof(CARD64)); .numWindowModifiers = nwindowmodifiers,
.numScreenModifiers = nscreenmodifiers,
.length = bytes_to_int32(nwindowmodifiers * sizeof(CARD64)) +
bytes_to_int32(nscreenmodifiers * sizeof(CARD64)),
};
if (client->swapped) { if (client->swapped) {
swaps(&rep.sequenceNumber); swaps(&rep.sequenceNumber);
@ -521,10 +519,6 @@ static int
proc_dri3_buffers_from_pixmap(ClientPtr client) proc_dri3_buffers_from_pixmap(ClientPtr client)
{ {
REQUEST(xDRI3BuffersFromPixmapReq); REQUEST(xDRI3BuffersFromPixmapReq);
xDRI3BuffersFromPixmapReply rep = {
.type = X_Reply,
.sequenceNumber = client->sequence,
};
int rc; int rc;
int fds[4]; int fds[4];
int num_fds; int num_fds;
@ -545,13 +539,25 @@ proc_dri3_buffers_from_pixmap(ClientPtr client)
if (num_fds == 0) if (num_fds == 0)
return BadPixmap; return BadPixmap;
rep.nfd = num_fds; for (i = 0; i < num_fds; i++) {
rep.length = bytes_to_int32(num_fds * 2 * sizeof(CARD32)); if (WriteFdToClient(client, fds[i], TRUE) < 0) {
rep.width = pixmap->drawable.width; while (i--)
rep.height = pixmap->drawable.height; close(fds[i]);
rep.depth = pixmap->drawable.depth; return BadAlloc;
rep.bpp = pixmap->drawable.bitsPerPixel; }
rep.modifier = modifier; }
xDRI3BuffersFromPixmapReply rep = {
.type = X_Reply,
.sequenceNumber = client->sequence,
.nfd = num_fds,
.length = bytes_to_int32(num_fds * 2 * sizeof(CARD32)),
.width = pixmap->drawable.width,
.height = pixmap->drawable.height,
.depth = pixmap->drawable.depth,
.bpp = pixmap->drawable.bitsPerPixel,
.modifier = modifier,
};
if (client->swapped) { if (client->swapped) {
swaps(&rep.sequenceNumber); swaps(&rep.sequenceNumber);
@ -565,14 +571,6 @@ proc_dri3_buffers_from_pixmap(ClientPtr client)
} }
} }
for (i = 0; i < num_fds; i++) {
if (WriteFdToClient(client, fds[i], TRUE) < 0) {
while (i--)
close(fds[i]);
return BadAlloc;
}
}
WriteToClient(client, sizeof(rep), &rep); WriteToClient(client, sizeof(rep), &rep);
WriteToClient(client, num_fds * sizeof(CARD32), strides); WriteToClient(client, num_fds * sizeof(CARD32), strides);
WriteToClient(client, num_fds * sizeof(CARD32), offsets); WriteToClient(client, num_fds * sizeof(CARD32), offsets);