dbe: use REQUEST_HEAD_STRUCT and REQUEST_FIELD_* macros
Use the new macros to make request struct parsing / field swapping much easier. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
parent
0c3d3856cc
commit
2a63c0911f
274
dbe/dbe.c
274
dbe/dbe.c
|
@ -40,6 +40,7 @@
|
||||||
#include <X11/Xproto.h>
|
#include <X11/Xproto.h>
|
||||||
|
|
||||||
#include "dix/dix_priv.h"
|
#include "dix/dix_priv.h"
|
||||||
|
#include "dix/request_priv.h"
|
||||||
#include "dix/screen_hooks_priv.h"
|
#include "dix/screen_hooks_priv.h"
|
||||||
|
|
||||||
#include "scrnintstr.h"
|
#include "scrnintstr.h"
|
||||||
|
@ -111,7 +112,8 @@ DbeStubScreen(DbeScreenPrivPtr pDbeScreenPriv, int *nStubbedScreens)
|
||||||
static int
|
static int
|
||||||
ProcDbeGetVersion(ClientPtr client)
|
ProcDbeGetVersion(ClientPtr client)
|
||||||
{
|
{
|
||||||
/* REQUEST(xDbeGetVersionReq); */
|
REQUEST_HEAD_STRUCT(xDbeGetVersionReq);
|
||||||
|
|
||||||
xDbeGetVersionReply rep = {
|
xDbeGetVersionReply rep = {
|
||||||
.type = X_Reply,
|
.type = X_Reply,
|
||||||
.sequenceNumber = client->sequence,
|
.sequenceNumber = client->sequence,
|
||||||
|
@ -120,8 +122,6 @@ ProcDbeGetVersion(ClientPtr client)
|
||||||
.minorVersion = DBE_MINOR_VERSION
|
.minorVersion = DBE_MINOR_VERSION
|
||||||
};
|
};
|
||||||
|
|
||||||
REQUEST_SIZE_MATCH(xDbeGetVersionReq);
|
|
||||||
|
|
||||||
if (client->swapped) {
|
if (client->swapped) {
|
||||||
swaps(&rep.sequenceNumber);
|
swaps(&rep.sequenceNumber);
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,10 @@ ProcDbeGetVersion(ClientPtr client)
|
||||||
static int
|
static int
|
||||||
ProcDbeAllocateBackBufferName(ClientPtr client)
|
ProcDbeAllocateBackBufferName(ClientPtr client)
|
||||||
{
|
{
|
||||||
REQUEST(xDbeAllocateBackBufferNameReq);
|
REQUEST_HEAD_STRUCT(xDbeAllocateBackBufferNameReq);
|
||||||
|
REQUEST_FIELD_CARD32(window);
|
||||||
|
REQUEST_FIELD_CARD32(buffer);
|
||||||
|
|
||||||
WindowPtr pWin;
|
WindowPtr pWin;
|
||||||
DbeScreenPrivPtr pDbeScreenPriv;
|
DbeScreenPrivPtr pDbeScreenPriv;
|
||||||
DbeWindowPrivPtr pDbeWindowPriv;
|
DbeWindowPrivPtr pDbeWindowPriv;
|
||||||
|
@ -170,8 +173,6 @@ ProcDbeAllocateBackBufferName(ClientPtr client)
|
||||||
int status;
|
int status;
|
||||||
int add_index;
|
int add_index;
|
||||||
|
|
||||||
REQUEST_SIZE_MATCH(xDbeAllocateBackBufferNameReq);
|
|
||||||
|
|
||||||
/* The window must be valid. */
|
/* The window must be valid. */
|
||||||
status = dixLookupWindow(&pWin, stuff->window, client, DixManageAccess);
|
status = dixLookupWindow(&pWin, stuff->window, client, DixManageAccess);
|
||||||
if (status != Success)
|
if (status != Success)
|
||||||
|
@ -370,13 +371,13 @@ ProcDbeAllocateBackBufferName(ClientPtr client)
|
||||||
static int
|
static int
|
||||||
ProcDbeDeallocateBackBufferName(ClientPtr client)
|
ProcDbeDeallocateBackBufferName(ClientPtr client)
|
||||||
{
|
{
|
||||||
REQUEST(xDbeDeallocateBackBufferNameReq);
|
REQUEST_HEAD_STRUCT(xDbeDeallocateBackBufferNameReq);
|
||||||
|
REQUEST_FIELD_CARD32(buffer);
|
||||||
|
|
||||||
DbeWindowPrivPtr pDbeWindowPriv;
|
DbeWindowPrivPtr pDbeWindowPriv;
|
||||||
int rc, i;
|
int rc, i;
|
||||||
void *val;
|
void *val;
|
||||||
|
|
||||||
REQUEST_SIZE_MATCH(xDbeDeallocateBackBufferNameReq);
|
|
||||||
|
|
||||||
/* Buffer name must be valid */
|
/* Buffer name must be valid */
|
||||||
rc = dixLookupResourceByType((void **) &pDbeWindowPriv, stuff->buffer,
|
rc = dixLookupResourceByType((void **) &pDbeWindowPriv, stuff->buffer,
|
||||||
dbeWindowPrivResType, client,
|
dbeWindowPrivResType, client,
|
||||||
|
@ -439,7 +440,24 @@ ProcDbeDeallocateBackBufferName(ClientPtr client)
|
||||||
static int
|
static int
|
||||||
ProcDbeSwapBuffers(ClientPtr client)
|
ProcDbeSwapBuffers(ClientPtr client)
|
||||||
{
|
{
|
||||||
REQUEST(xDbeSwapBuffersReq);
|
REQUEST_HEAD_AT_LEAST(xDbeSwapBuffersReq);
|
||||||
|
REQUEST_FIELD_CARD32(n);
|
||||||
|
|
||||||
|
if (stuff->n > UINT32_MAX / sizeof(DbeSwapInfoRec))
|
||||||
|
return BadLength;
|
||||||
|
REQUEST_FIXED_SIZE(xDbeSwapBuffersReq, stuff->n * sizeof(xDbeSwapInfo));
|
||||||
|
|
||||||
|
if (stuff->n != 0) {
|
||||||
|
xDbeSwapInfo *pSwapInfo = (xDbeSwapInfo *) stuff + 1;
|
||||||
|
/* The swap info following the fix part of this request is a window(32)
|
||||||
|
* followed by a 1 byte swap action and then 3 pad bytes. We only need
|
||||||
|
* to swap the window information.
|
||||||
|
*/
|
||||||
|
for (int i = 0; i < stuff->n; i++, pSwapInfo++) {
|
||||||
|
CLIENT_STRUCT_CARD32_1(pSwapInfo, window);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
WindowPtr pWin;
|
WindowPtr pWin;
|
||||||
DbeScreenPrivPtr pDbeScreenPriv;
|
DbeScreenPrivPtr pDbeScreenPriv;
|
||||||
xDbeSwapInfo *dbeSwapInfo;
|
xDbeSwapInfo *dbeSwapInfo;
|
||||||
|
@ -448,7 +466,6 @@ ProcDbeSwapBuffers(ClientPtr client)
|
||||||
unsigned int nStuff;
|
unsigned int nStuff;
|
||||||
int nStuff_i; /* DDX API requires int for nStuff */
|
int nStuff_i; /* DDX API requires int for nStuff */
|
||||||
|
|
||||||
REQUEST_AT_LEAST_SIZE(xDbeSwapBuffersReq);
|
|
||||||
nStuff = stuff->n; /* use local variable for performance. */
|
nStuff = stuff->n; /* use local variable for performance. */
|
||||||
|
|
||||||
if (nStuff == 0) {
|
if (nStuff == 0) {
|
||||||
|
@ -541,7 +558,10 @@ ProcDbeSwapBuffers(ClientPtr client)
|
||||||
static int
|
static int
|
||||||
ProcDbeGetVisualInfo(ClientPtr client)
|
ProcDbeGetVisualInfo(ClientPtr client)
|
||||||
{
|
{
|
||||||
REQUEST(xDbeGetVisualInfoReq);
|
REQUEST_HEAD_AT_LEAST(xDbeGetVisualInfoReq);
|
||||||
|
REQUEST_FIELD_CARD32(n);
|
||||||
|
REQUEST_REST_CARD32();
|
||||||
|
|
||||||
DbeScreenPrivPtr pDbeScreenPriv;
|
DbeScreenPrivPtr pDbeScreenPriv;
|
||||||
xDbeGetVisualInfoReply rep;
|
xDbeGetVisualInfoReply rep;
|
||||||
register int i, j, rc;
|
register int i, j, rc;
|
||||||
|
@ -549,7 +569,6 @@ ProcDbeGetVisualInfo(ClientPtr client)
|
||||||
register int length; /* length of reply */
|
register int length; /* length of reply */
|
||||||
ScreenPtr pScreen;
|
ScreenPtr pScreen;
|
||||||
|
|
||||||
REQUEST_AT_LEAST_SIZE(xDbeGetVisualInfoReq);
|
|
||||||
if (stuff->n > UINT32_MAX / sizeof(CARD32))
|
if (stuff->n > UINT32_MAX / sizeof(CARD32))
|
||||||
return BadLength;
|
return BadLength;
|
||||||
REQUEST_FIXED_SIZE(xDbeGetVisualInfoReq, stuff->n * sizeof(CARD32));
|
REQUEST_FIXED_SIZE(xDbeGetVisualInfoReq, stuff->n * sizeof(CARD32));
|
||||||
|
@ -685,7 +704,9 @@ ProcDbeGetVisualInfo(ClientPtr client)
|
||||||
static int
|
static int
|
||||||
ProcDbeGetBackBufferAttributes(ClientPtr client)
|
ProcDbeGetBackBufferAttributes(ClientPtr client)
|
||||||
{
|
{
|
||||||
REQUEST(xDbeGetBackBufferAttributesReq);
|
REQUEST_HEAD_STRUCT(xDbeGetBackBufferAttributesReq);
|
||||||
|
REQUEST_FIELD_CARD32(buffer);
|
||||||
|
|
||||||
xDbeGetBackBufferAttributesReply rep = {
|
xDbeGetBackBufferAttributesReply rep = {
|
||||||
.type = X_Reply,
|
.type = X_Reply,
|
||||||
.sequenceNumber = client->sequence,
|
.sequenceNumber = client->sequence,
|
||||||
|
@ -694,8 +715,6 @@ ProcDbeGetBackBufferAttributes(ClientPtr client)
|
||||||
DbeWindowPrivPtr pDbeWindowPriv;
|
DbeWindowPrivPtr pDbeWindowPriv;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
REQUEST_SIZE_MATCH(xDbeGetBackBufferAttributesReq);
|
|
||||||
|
|
||||||
rc = dixLookupResourceByType((void **) &pDbeWindowPriv, stuff->buffer,
|
rc = dixLookupResourceByType((void **) &pDbeWindowPriv, stuff->buffer,
|
||||||
dbeWindowPrivResType, client,
|
dbeWindowPrivResType, client,
|
||||||
DixGetAttrAccess);
|
DixGetAttrAccess);
|
||||||
|
@ -763,227 +782,6 @@ ProcDbeDispatch(ClientPtr client)
|
||||||
|
|
||||||
} /* ProcDbeDispatch() */
|
} /* ProcDbeDispatch() */
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
*
|
|
||||||
* DBE DIX Procedure: SProcDbeAllocateBackBufferName
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
*
|
|
||||||
* This function is for processing a DbeAllocateBackBufferName request on
|
|
||||||
* a swapped server. This request allocates a drawable ID used to refer
|
|
||||||
* to the back buffer of a window.
|
|
||||||
*
|
|
||||||
* Return Values:
|
|
||||||
*
|
|
||||||
* BadAlloc - server can not allocate resources
|
|
||||||
* BadIDChoice - id is out of range for client; id is already in use
|
|
||||||
* BadMatch - window is not an InputOutput window;
|
|
||||||
* visual of window is not on list returned by
|
|
||||||
* DBEGetVisualInfo;
|
|
||||||
* BadValue - invalid swap action is specified
|
|
||||||
* BadWindow - window is not a valid window
|
|
||||||
* Success
|
|
||||||
*
|
|
||||||
*****************************************************************************/
|
|
||||||
|
|
||||||
static int _X_COLD
|
|
||||||
SProcDbeAllocateBackBufferName(ClientPtr client)
|
|
||||||
{
|
|
||||||
REQUEST(xDbeAllocateBackBufferNameReq);
|
|
||||||
REQUEST_SIZE_MATCH(xDbeAllocateBackBufferNameReq);
|
|
||||||
|
|
||||||
swapl(&stuff->window);
|
|
||||||
swapl(&stuff->buffer);
|
|
||||||
/* stuff->swapAction is a byte. We do not need to swap this field. */
|
|
||||||
|
|
||||||
return (ProcDbeAllocateBackBufferName(client));
|
|
||||||
|
|
||||||
} /* SProcDbeAllocateBackBufferName() */
|
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
*
|
|
||||||
* DBE DIX Procedure: SProcDbeDeallocateBackBufferName
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
*
|
|
||||||
* This function is for processing a DbeDeallocateBackBufferName request
|
|
||||||
* on a swapped server. This request frees a drawable ID that was
|
|
||||||
* obtained by a DbeAllocateBackBufferName request.
|
|
||||||
*
|
|
||||||
* Return Values:
|
|
||||||
*
|
|
||||||
* BadBuffer - buffer to deallocate is not associated with a window
|
|
||||||
* Success
|
|
||||||
*
|
|
||||||
*****************************************************************************/
|
|
||||||
|
|
||||||
static int _X_COLD
|
|
||||||
SProcDbeDeallocateBackBufferName(ClientPtr client)
|
|
||||||
{
|
|
||||||
REQUEST(xDbeDeallocateBackBufferNameReq);
|
|
||||||
REQUEST_SIZE_MATCH(xDbeDeallocateBackBufferNameReq);
|
|
||||||
|
|
||||||
swapl(&stuff->buffer);
|
|
||||||
|
|
||||||
return (ProcDbeDeallocateBackBufferName(client));
|
|
||||||
|
|
||||||
} /* SProcDbeDeallocateBackBufferName() */
|
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
*
|
|
||||||
* DBE DIX Procedure: SProcDbeSwapBuffers
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
*
|
|
||||||
* This function is for processing a DbeSwapBuffers request on a swapped
|
|
||||||
* server. This request swaps the buffers for all windows listed,
|
|
||||||
* applying the appropriate swap action for each window.
|
|
||||||
*
|
|
||||||
* Return Values:
|
|
||||||
*
|
|
||||||
* BadMatch - a window in request is not double-buffered; a window in
|
|
||||||
* request is listed more than once; all windows in request do
|
|
||||||
* not have the same root
|
|
||||||
* BadValue - invalid swap action is specified
|
|
||||||
* BadWindow - a window in request is not valid
|
|
||||||
* Success
|
|
||||||
*
|
|
||||||
*****************************************************************************/
|
|
||||||
|
|
||||||
static int _X_COLD
|
|
||||||
SProcDbeSwapBuffers(ClientPtr client)
|
|
||||||
{
|
|
||||||
REQUEST(xDbeSwapBuffersReq);
|
|
||||||
unsigned int i;
|
|
||||||
xDbeSwapInfo *pSwapInfo;
|
|
||||||
|
|
||||||
REQUEST_AT_LEAST_SIZE(xDbeSwapBuffersReq);
|
|
||||||
|
|
||||||
swapl(&stuff->n);
|
|
||||||
if (stuff->n > UINT32_MAX / sizeof(DbeSwapInfoRec))
|
|
||||||
return BadLength;
|
|
||||||
REQUEST_FIXED_SIZE(xDbeSwapBuffersReq, stuff->n * sizeof(xDbeSwapInfo));
|
|
||||||
|
|
||||||
if (stuff->n != 0) {
|
|
||||||
pSwapInfo = (xDbeSwapInfo *) stuff + 1;
|
|
||||||
|
|
||||||
/* The swap info following the fix part of this request is a window(32)
|
|
||||||
* followed by a 1 byte swap action and then 3 pad bytes. We only need
|
|
||||||
* to swap the window information.
|
|
||||||
*/
|
|
||||||
for (i = 0; i < stuff->n; i++, pSwapInfo++) {
|
|
||||||
swapl(&pSwapInfo->window);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (ProcDbeSwapBuffers(client));
|
|
||||||
|
|
||||||
} /* SProcDbeSwapBuffers() */
|
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
*
|
|
||||||
* DBE DIX Procedure: SProcDbeGetVisualInfo
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
*
|
|
||||||
* This function is for processing a ProcDbeGetVisualInfo request on a
|
|
||||||
* swapped server. This request returns information about which visuals
|
|
||||||
* support double buffering.
|
|
||||||
*
|
|
||||||
* Return Values:
|
|
||||||
*
|
|
||||||
* BadDrawable - value in screen specifiers is not a valid drawable
|
|
||||||
* Success
|
|
||||||
*
|
|
||||||
*****************************************************************************/
|
|
||||||
|
|
||||||
static int _X_COLD
|
|
||||||
SProcDbeGetVisualInfo(ClientPtr client)
|
|
||||||
{
|
|
||||||
REQUEST(xDbeGetVisualInfoReq);
|
|
||||||
REQUEST_AT_LEAST_SIZE(xDbeGetVisualInfoReq);
|
|
||||||
|
|
||||||
swapl(&stuff->n);
|
|
||||||
SwapRestL(stuff);
|
|
||||||
|
|
||||||
return (ProcDbeGetVisualInfo(client));
|
|
||||||
|
|
||||||
} /* SProcDbeGetVisualInfo() */
|
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
*
|
|
||||||
* DBE DIX Procedure: SProcDbeGetbackBufferAttributes
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
*
|
|
||||||
* This function is for processing a ProcDbeGetbackBufferAttributes
|
|
||||||
* request on a swapped server. This request returns information about a
|
|
||||||
* back buffer.
|
|
||||||
*
|
|
||||||
* Return Values:
|
|
||||||
*
|
|
||||||
* Success
|
|
||||||
*
|
|
||||||
*****************************************************************************/
|
|
||||||
|
|
||||||
static int _X_COLD
|
|
||||||
SProcDbeGetBackBufferAttributes(ClientPtr client)
|
|
||||||
{
|
|
||||||
REQUEST(xDbeGetBackBufferAttributesReq);
|
|
||||||
REQUEST_SIZE_MATCH(xDbeGetBackBufferAttributesReq);
|
|
||||||
|
|
||||||
swapl(&stuff->buffer);
|
|
||||||
|
|
||||||
return (ProcDbeGetBackBufferAttributes(client));
|
|
||||||
|
|
||||||
} /* SProcDbeGetBackBufferAttributes() */
|
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
*
|
|
||||||
* DBE DIX Procedure: SProcDbeDispatch
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
*
|
|
||||||
* This function dispatches DBE requests on a swapped server.
|
|
||||||
*
|
|
||||||
*****************************************************************************/
|
|
||||||
|
|
||||||
static int _X_COLD
|
|
||||||
SProcDbeDispatch(ClientPtr client)
|
|
||||||
{
|
|
||||||
REQUEST(xReq);
|
|
||||||
|
|
||||||
switch (stuff->data) {
|
|
||||||
case X_DbeGetVersion:
|
|
||||||
return ProcDbeGetVersion(client);
|
|
||||||
|
|
||||||
case X_DbeAllocateBackBufferName:
|
|
||||||
return (SProcDbeAllocateBackBufferName(client));
|
|
||||||
|
|
||||||
case X_DbeDeallocateBackBufferName:
|
|
||||||
return (SProcDbeDeallocateBackBufferName(client));
|
|
||||||
|
|
||||||
case X_DbeSwapBuffers:
|
|
||||||
return (SProcDbeSwapBuffers(client));
|
|
||||||
|
|
||||||
case X_DbeBeginIdiom:
|
|
||||||
return Success;
|
|
||||||
|
|
||||||
case X_DbeEndIdiom:
|
|
||||||
return Success;
|
|
||||||
|
|
||||||
case X_DbeGetVisualInfo:
|
|
||||||
return (SProcDbeGetVisualInfo(client));
|
|
||||||
|
|
||||||
case X_DbeGetBackBufferAttributes:
|
|
||||||
return (SProcDbeGetBackBufferAttributes(client));
|
|
||||||
|
|
||||||
default:
|
|
||||||
return BadRequest;
|
|
||||||
}
|
|
||||||
|
|
||||||
} /* SProcDbeDispatch() */
|
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
*
|
*
|
||||||
* DBE DIX Procedure: DbeSetupBackgroundPainter
|
* DBE DIX Procedure: DbeSetupBackgroundPainter
|
||||||
|
@ -1336,7 +1134,7 @@ DbeExtensionInit(void)
|
||||||
|
|
||||||
/* Now add the extension. */
|
/* Now add the extension. */
|
||||||
extEntry = AddExtension(DBE_PROTOCOL_NAME, DbeNumberEvents,
|
extEntry = AddExtension(DBE_PROTOCOL_NAME, DbeNumberEvents,
|
||||||
DbeNumberErrors, ProcDbeDispatch, SProcDbeDispatch,
|
DbeNumberErrors, ProcDbeDispatch, ProcDbeDispatch,
|
||||||
DbeResetProc, StandardMinorOpcode);
|
DbeResetProc, StandardMinorOpcode);
|
||||||
|
|
||||||
dbeErrorBase = extEntry->errorBase;
|
dbeErrorBase = extEntry->errorBase;
|
||||||
|
|
Loading…
Reference in New Issue