mirror of
https://github.com/X11Libre/xserver.git
synced 2026-03-24 08:04:30 +00:00
Xext: shape: ProcShapeGetRectangles(): use x_rpcbuf_t
Use x_rpcbuf_t for assembling reply payload and byte-swapping. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
committed by
Enrico Weigelt
parent
b847ecb9a3
commit
ac319a136b
71
Xext/shape.c
71
Xext/shape.c
@@ -33,6 +33,7 @@ in this Software without prior written authorization from The Open Group.
|
||||
|
||||
#include "dix/dix_priv.h"
|
||||
#include "dix/gc_priv.h"
|
||||
#include "dix/rpcbuf_priv.h"
|
||||
#include "dix/window_priv.h"
|
||||
#include "miext/extinit_priv.h"
|
||||
#include "Xext/panoramiX.h"
|
||||
@@ -938,8 +939,7 @@ ProcShapeGetRectangles(ClientPtr client)
|
||||
{
|
||||
REQUEST(xShapeGetRectanglesReq);
|
||||
WindowPtr pWin;
|
||||
xRectangle *rects = NULL;
|
||||
int nrects, i, rc;
|
||||
int nrects, rc;
|
||||
RegionPtr region;
|
||||
|
||||
REQUEST_SIZE_MATCH(xShapeGetRectanglesReq);
|
||||
@@ -960,55 +960,56 @@ ProcShapeGetRectangles(ClientPtr client)
|
||||
client->errorValue = stuff->kind;
|
||||
return BadValue;
|
||||
}
|
||||
|
||||
struct x_rpcbuf rpcbuf = { .swapped = client->swapped, .err_clear = TRUE };
|
||||
|
||||
if (!region) {
|
||||
nrects = 1;
|
||||
rects = calloc(1, sizeof(xRectangle));
|
||||
if (!rects)
|
||||
return BadAlloc;
|
||||
xRectangle rect;
|
||||
switch (stuff->kind) {
|
||||
case ShapeBounding:
|
||||
rects->x = -(int) wBorderWidth(pWin);
|
||||
rects->y = -(int) wBorderWidth(pWin);
|
||||
rects->width = pWin->drawable.width + wBorderWidth(pWin);
|
||||
rects->height = pWin->drawable.height + wBorderWidth(pWin);
|
||||
rect.x = -(int) wBorderWidth(pWin);
|
||||
rect.y = -(int) wBorderWidth(pWin);
|
||||
rect.width = pWin->drawable.width + wBorderWidth(pWin);
|
||||
rect.height = pWin->drawable.height + wBorderWidth(pWin);
|
||||
break;
|
||||
case ShapeClip:
|
||||
rects->x = 0;
|
||||
rects->y = 0;
|
||||
rects->width = pWin->drawable.width;
|
||||
rects->height = pWin->drawable.height;
|
||||
rect.x = 0;
|
||||
rect.y = 0;
|
||||
rect.width = pWin->drawable.width;
|
||||
rect.height = pWin->drawable.height;
|
||||
break;
|
||||
case ShapeInput:
|
||||
rects->x = -(int) wBorderWidth(pWin);
|
||||
rects->y = -(int) wBorderWidth(pWin);
|
||||
rects->width = pWin->drawable.width + wBorderWidth(pWin);
|
||||
rects->height = pWin->drawable.height + wBorderWidth(pWin);
|
||||
rect.x = -(int) wBorderWidth(pWin);
|
||||
rect.y = -(int) wBorderWidth(pWin);
|
||||
rect.width = pWin->drawable.width + wBorderWidth(pWin);
|
||||
rect.height = pWin->drawable.height + wBorderWidth(pWin);
|
||||
break;
|
||||
}
|
||||
nrects = 1;
|
||||
x_rpcbuf_write_CARD16s(&rpcbuf, (CARD16*)&rect, 4);
|
||||
}
|
||||
else {
|
||||
BoxPtr box;
|
||||
|
||||
nrects = RegionNumRects(region);
|
||||
box = RegionRects(region);
|
||||
if (nrects) {
|
||||
rects = calloc(nrects, sizeof(xRectangle));
|
||||
if (!rects)
|
||||
return BadAlloc;
|
||||
for (i = 0; i < nrects; i++, box++) {
|
||||
rects[i].x = box->x1;
|
||||
rects[i].y = box->y1;
|
||||
rects[i].width = box->x2 - box->x1;
|
||||
rects[i].height = box->y2 - box->y1;
|
||||
}
|
||||
}
|
||||
BoxPtr boxes = RegionRects(region);
|
||||
for (int i=0; i < nrects; i++) {
|
||||
xRectangle rect = {
|
||||
.x = boxes[i].x1,
|
||||
.y = boxes[i].y1,
|
||||
.width = boxes[i].x2 - boxes[i].x1,
|
||||
.height = boxes[i].y2 - boxes[i].y1,
|
||||
};
|
||||
x_rpcbuf_write_CARD16s(&rpcbuf, (CARD16*)&rect, 4);
|
||||
};
|
||||
}
|
||||
|
||||
if (rpcbuf.error) /* buffer already cleared */
|
||||
return BadAlloc;
|
||||
|
||||
xShapeGetRectanglesReply rep = {
|
||||
.type = X_Reply,
|
||||
.ordering = YXBanded,
|
||||
.sequenceNumber = client->sequence,
|
||||
.length = bytes_to_int32(nrects * sizeof(xRectangle)),
|
||||
.length = x_rpcbuf_wsize_units(&rpcbuf),
|
||||
.nrects = nrects
|
||||
};
|
||||
|
||||
@@ -1016,11 +1017,9 @@ ProcShapeGetRectangles(ClientPtr client)
|
||||
swaps(&rep.sequenceNumber);
|
||||
swapl(&rep.length);
|
||||
swapl(&rep.nrects);
|
||||
SwapShorts((short *) rects, (unsigned long) nrects * 4);
|
||||
}
|
||||
WriteToClient(client, sizeof(rep), &rep);
|
||||
WriteToClient(client, nrects * sizeof(xRectangle), rects);
|
||||
free(rects);
|
||||
WriteRpcbufToClient(client, &rpcbuf);
|
||||
return Success;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user