Xext: vidmode: ProcVidModeGetMonitor(): write reply payload at once.
Collect up the puzzle piezes of the reply payload into to a temporary buffer, so we can send it as one block. This allows for further simplifications by subsequent commits, as well as packet based transports and message based compression. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
parent
09588278e3
commit
92ba36008e
107
Xext/vidmode.c
107
Xext/vidmode.c
|
@ -1197,14 +1197,20 @@ ProcVidModeLockModeSwitch(ClientPtr client)
|
||||||
return Success;
|
return Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline CARD32 _combine_f(vidMonitorValue a, vidMonitorValue b, Bool swapped)
|
||||||
|
{
|
||||||
|
CARD32 buf =
|
||||||
|
((unsigned short) a.f) |
|
||||||
|
((unsigned short) b.f << 16);
|
||||||
|
if (swapped)
|
||||||
|
swapl(&buf);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ProcVidModeGetMonitor(ClientPtr client)
|
ProcVidModeGetMonitor(ClientPtr client)
|
||||||
{
|
{
|
||||||
REQUEST(xXF86VidModeGetMonitorReq);
|
REQUEST(xXF86VidModeGetMonitorReq);
|
||||||
CARD32 *hsyncdata, *vsyncdata;
|
|
||||||
ScreenPtr pScreen;
|
|
||||||
VidModePtr pVidMode;
|
|
||||||
int i, nHsync, nVrefresh, vendorLength = 0, modelLength = 0;
|
|
||||||
|
|
||||||
DEBUG_P("XF86VidModeGetMonitor");
|
DEBUG_P("XF86VidModeGetMonitor");
|
||||||
|
|
||||||
|
@ -1212,24 +1218,23 @@ ProcVidModeGetMonitor(ClientPtr client)
|
||||||
|
|
||||||
if (stuff->screen >= screenInfo.numScreens)
|
if (stuff->screen >= screenInfo.numScreens)
|
||||||
return BadValue;
|
return BadValue;
|
||||||
pScreen = screenInfo.screens[stuff->screen];
|
ScreenPtr pScreen = screenInfo.screens[stuff->screen];
|
||||||
|
|
||||||
pVidMode = VidModeGetPtr(pScreen);
|
VidModePtr pVidMode = VidModeGetPtr(pScreen);
|
||||||
if (pVidMode == NULL)
|
if (pVidMode == NULL)
|
||||||
return BadImplementation;
|
return BadImplementation;
|
||||||
|
|
||||||
nHsync = pVidMode->GetMonitorValue(pScreen, VIDMODE_MON_NHSYNC, 0).i;
|
const int nHsync = pVidMode->GetMonitorValue(pScreen, VIDMODE_MON_NHSYNC, 0).i;
|
||||||
nVrefresh = pVidMode->GetMonitorValue(pScreen, VIDMODE_MON_NVREFRESH, 0).i;
|
const int nVrefresh = pVidMode->GetMonitorValue(pScreen, VIDMODE_MON_NVREFRESH, 0).i;
|
||||||
|
|
||||||
if ((char *) (pVidMode->GetMonitorValue(pScreen, VIDMODE_MON_VENDOR, 0)).ptr)
|
const char *vendorStr = (const char*)pVidMode->GetMonitorValue(pScreen, VIDMODE_MON_VENDOR, 0).ptr;
|
||||||
vendorLength = strlen((char *) (pVidMode->GetMonitorValue(pScreen,
|
const char *modelStr = (const char*)pVidMode->GetMonitorValue(pScreen, VIDMODE_MON_MODEL, 0).ptr;
|
||||||
VIDMODE_MON_VENDOR,
|
|
||||||
0)).ptr);
|
|
||||||
|
|
||||||
if ((char *) (pVidMode->GetMonitorValue(pScreen, VIDMODE_MON_MODEL, 0)).ptr)
|
const int vendorLength = (vendorStr ? strlen(vendorStr) : 0);
|
||||||
modelLength = strlen((char *) (pVidMode->GetMonitorValue(pScreen,
|
const int modelLength = (modelStr ? strlen(modelStr) : 0);
|
||||||
VIDMODE_MON_MODEL,
|
|
||||||
0)).ptr);
|
const int nVendorItems = bytes_to_int32(pad_to_int32(vendorLength));
|
||||||
|
const int nModelItems = bytes_to_int32(pad_to_int32(modelLength));
|
||||||
|
|
||||||
xXF86VidModeGetMonitorReply rep = {
|
xXF86VidModeGetMonitorReply rep = {
|
||||||
.type = X_Reply,
|
.type = X_Reply,
|
||||||
|
@ -1239,59 +1244,51 @@ ProcVidModeGetMonitor(ClientPtr client)
|
||||||
.vendorLength = vendorLength,
|
.vendorLength = vendorLength,
|
||||||
.modelLength = modelLength,
|
.modelLength = modelLength,
|
||||||
.length = bytes_to_int32(sizeof(xXF86VidModeGetMonitorReply) -
|
.length = bytes_to_int32(sizeof(xXF86VidModeGetMonitorReply) -
|
||||||
sizeof(xGenericReply) +
|
sizeof(xGenericReply))
|
||||||
(nHsync + nVrefresh) * sizeof(CARD32) +
|
+ nHsync + nVrefresh + nVendorItems + nModelItems
|
||||||
pad_to_int32(vendorLength) +
|
|
||||||
pad_to_int32(modelLength)),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
hsyncdata = calloc(nHsync, sizeof(CARD32));
|
const int buflen = nHsync * nVrefresh + nVendorItems + nModelItems;
|
||||||
if (!hsyncdata) {
|
|
||||||
return BadAlloc;
|
|
||||||
}
|
|
||||||
vsyncdata = calloc(nVrefresh, sizeof(CARD32));
|
|
||||||
|
|
||||||
if (!vsyncdata) {
|
CARD32 *sendbuf = calloc(buflen, sizeof(CARD32));
|
||||||
free(hsyncdata);
|
if (!sendbuf)
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
|
|
||||||
|
CARD32 *bufwalk = sendbuf;
|
||||||
|
|
||||||
|
for (int i = 0; i < nHsync; i++) {
|
||||||
|
*bufwalk = _combine_f(pVidMode->GetMonitorValue(pScreen, VIDMODE_MON_HSYNC_LO, i),
|
||||||
|
pVidMode->GetMonitorValue(pScreen, VIDMODE_MON_HSYNC_HI, i),
|
||||||
|
client->swapped);
|
||||||
|
bufwalk++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < nHsync; i++) {
|
for (int i = 0; i < nVrefresh; i++) {
|
||||||
hsyncdata[i] = (unsigned short) (pVidMode->GetMonitorValue(pScreen,
|
*bufwalk = _combine_f(pVidMode->GetMonitorValue(pScreen, VIDMODE_MON_VREFRESH_LO, i),
|
||||||
VIDMODE_MON_HSYNC_LO,
|
pVidMode->GetMonitorValue(pScreen, VIDMODE_MON_VREFRESH_HI, i),
|
||||||
i)).f |
|
client->swapped);
|
||||||
(unsigned
|
bufwalk++;
|
||||||
short) (pVidMode->GetMonitorValue(pScreen, VIDMODE_MON_HSYNC_HI,
|
|
||||||
i)).f << 16;
|
|
||||||
}
|
|
||||||
for (i = 0; i < nVrefresh; i++) {
|
|
||||||
vsyncdata[i] = (unsigned short) (pVidMode->GetMonitorValue(pScreen,
|
|
||||||
VIDMODE_MON_VREFRESH_LO,
|
|
||||||
i)).f |
|
|
||||||
(unsigned
|
|
||||||
short) (pVidMode->GetMonitorValue(pScreen, VIDMODE_MON_VREFRESH_HI,
|
|
||||||
i)).f << 16;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memcpy(sendbuf,
|
||||||
|
pVidMode->GetMonitorValue(pScreen, VIDMODE_MON_VENDOR, 0).ptr,
|
||||||
|
vendorLength);
|
||||||
|
sendbuf += nVendorItems;
|
||||||
|
|
||||||
|
memcpy(sendbuf,
|
||||||
|
pVidMode->GetMonitorValue(pScreen, VIDMODE_MON_MODEL, 0).ptr,
|
||||||
|
modelLength);
|
||||||
|
sendbuf += nModelItems;
|
||||||
|
|
||||||
if (client->swapped) {
|
if (client->swapped) {
|
||||||
swaps(&rep.sequenceNumber);
|
swaps(&rep.sequenceNumber);
|
||||||
swapl(&rep.length);
|
swapl(&rep.length);
|
||||||
SwapLongs(hsyncdata, sizeof(hsyncdata));
|
|
||||||
SwapLongs(vsyncdata, sizeof(vsyncdata));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteToClient(client, SIZEOF(xXF86VidModeGetMonitorReply), &rep);
|
WriteToClient(client, SIZEOF(xXF86VidModeGetMonitorReply), &rep);
|
||||||
WriteToClient(client, sizeof(hsyncdata), hsyncdata);
|
WriteToClient(client, buflen * sizeof(CARD32), sendbuf);
|
||||||
WriteToClient(client, sizeof(vsyncdata), vsyncdata);
|
|
||||||
if (rep.vendorLength)
|
|
||||||
WriteToClient(client, rep.vendorLength,
|
|
||||||
(pVidMode->GetMonitorValue(pScreen, VIDMODE_MON_VENDOR, 0)).ptr);
|
|
||||||
if (rep.modelLength)
|
|
||||||
WriteToClient(client, rep.modelLength,
|
|
||||||
(pVidMode->GetMonitorValue(pScreen, VIDMODE_MON_MODEL, 0)).ptr);
|
|
||||||
|
|
||||||
free(hsyncdata);
|
|
||||||
free(vsyncdata);
|
|
||||||
|
|
||||||
|
free(sendbuf);
|
||||||
return Success;
|
return Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue