randr: use explicit case statement instead of ProcRandrVector table
No need to go indirectly through a vector table, since everything's fixed
anyways. It's not a pretty robust programming style: any changes need great
care, in order to not mix up things.
Replacing this by direct switch/case statement, which is using the defines
from the xrandr protocol headers. Also adding a little bit more protection
against subtle programming errors and reducing cognitive load (source size)
on understanding the code by using a tiny macro for deducing define name and
function name from the request's name.
This approach actually uncovered some subtle bug that had been waiting in the
dark for over 15 years (see commit b87314c876
)
As collateral benefit, getting a tiny bit better performance.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1794>
This commit is contained in:
parent
ed17224403
commit
42677ae1e3
|
@ -50,7 +50,6 @@ static int RRNScreens;
|
||||||
real->mem = priv->mem; \
|
real->mem = priv->mem; \
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ProcRRDispatch(ClientPtr pClient);
|
|
||||||
static int SProcRRDispatch(ClientPtr pClient);
|
static int SProcRRDispatch(ClientPtr pClient);
|
||||||
|
|
||||||
int RREventBase;
|
int RREventBase;
|
||||||
|
@ -738,16 +737,6 @@ RRVerticalRefresh(xRRModeInfo * mode)
|
||||||
return (CARD16) refresh;
|
return (CARD16) refresh;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
ProcRRDispatch(ClientPtr client)
|
|
||||||
{
|
|
||||||
REQUEST(xReq);
|
|
||||||
if (stuff->data >= RRNumberRequests || !ProcRandrVector[stuff->data])
|
|
||||||
return BadRequest;
|
|
||||||
UpdateCurrentTimeIf();
|
|
||||||
return (*ProcRandrVector[stuff->data]) (client);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int _X_COLD
|
static int _X_COLD
|
||||||
SProcRRDispatch(ClientPtr client)
|
SProcRRDispatch(ClientPtr client)
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,7 +33,6 @@
|
||||||
|
|
||||||
extern int RREventBase, RRErrorBase;
|
extern int RREventBase, RRErrorBase;
|
||||||
|
|
||||||
extern int (*ProcRandrVector[RRNumberRequests]) (ClientPtr);
|
|
||||||
extern int (*SProcRandrVector[RRNumberRequests]) (ClientPtr);
|
extern int (*SProcRandrVector[RRNumberRequests]) (ClientPtr);
|
||||||
|
|
||||||
extern RESTYPE RRClientType, RREventType; /* resource types for event masks */
|
extern RESTYPE RRClientType, RREventType; /* resource types for event masks */
|
||||||
|
@ -140,4 +139,6 @@ int ProcRRQueryVersion(ClientPtr client);
|
||||||
|
|
||||||
int ProcRRSelectInput(ClientPtr client);
|
int ProcRRSelectInput(ClientPtr client);
|
||||||
|
|
||||||
|
int ProcRRDispatch(ClientPtr client);
|
||||||
|
|
||||||
#endif /* _XSERVER_RANDRSTR_PRIV_H_ */
|
#endif /* _XSERVER_RANDRSTR_PRIV_H_ */
|
||||||
|
|
|
@ -211,60 +211,69 @@ ProcRRSelectInput(ClientPtr client)
|
||||||
return Success;
|
return Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
int (*ProcRandrVector[RRNumberRequests]) (ClientPtr) = {
|
int
|
||||||
ProcRRQueryVersion, /* 0 */
|
ProcRRDispatch(ClientPtr client)
|
||||||
/* we skip 1 to make old clients fail pretty immediately */
|
{
|
||||||
NULL, /* 1 ProcRandrOldGetScreenInfo */
|
REQUEST(xReq);
|
||||||
/* V1.0 apps share the same set screen config request id */
|
UpdateCurrentTimeIf();
|
||||||
ProcRRSetScreenConfig, /* 2 */
|
|
||||||
NULL, /* 3 ProcRandrOldScreenChangeSelectInput */
|
switch (stuff->data) {
|
||||||
/* 3 used to be ScreenChangeSelectInput; deprecated */
|
case X_RRQueryVersion: return ProcRRQueryVersion(client);
|
||||||
ProcRRSelectInput, /* 4 */
|
case X_RRSetScreenConfig: return ProcRRSetScreenConfig(client);
|
||||||
ProcRRGetScreenInfo, /* 5 */
|
case X_RRSelectInput: return ProcRRSelectInput(client);
|
||||||
|
case X_RRGetScreenInfo: return ProcRRGetScreenInfo(client);
|
||||||
|
|
||||||
/* V1.2 additions */
|
/* V1.2 additions */
|
||||||
ProcRRGetScreenSizeRange, /* 6 */
|
case X_RRGetScreenSizeRange: return ProcRRGetScreenSizeRange(client);
|
||||||
ProcRRSetScreenSize, /* 7 */
|
case X_RRSetScreenSize: return ProcRRSetScreenSize(client);
|
||||||
ProcRRGetScreenResources, /* 8 */
|
case X_RRGetScreenResources: return ProcRRGetScreenResources(client);
|
||||||
ProcRRGetOutputInfo, /* 9 */
|
case X_RRGetOutputInfo: return ProcRRGetOutputInfo(client);
|
||||||
ProcRRListOutputProperties, /* 10 */
|
case X_RRListOutputProperties: return ProcRRListOutputProperties(client);
|
||||||
ProcRRQueryOutputProperty, /* 11 */
|
case X_RRQueryOutputProperty: return ProcRRQueryOutputProperty(client);
|
||||||
ProcRRConfigureOutputProperty, /* 12 */
|
case X_RRConfigureOutputProperty: return ProcRRConfigureOutputProperty(client);
|
||||||
ProcRRChangeOutputProperty, /* 13 */
|
case X_RRChangeOutputProperty: return ProcRRChangeOutputProperty(client);
|
||||||
ProcRRDeleteOutputProperty, /* 14 */
|
case X_RRDeleteOutputProperty: return ProcRRDeleteOutputProperty(client);
|
||||||
ProcRRGetOutputProperty, /* 15 */
|
case X_RRGetOutputProperty: return ProcRRGetOutputProperty(client);
|
||||||
ProcRRCreateMode, /* 16 */
|
case X_RRCreateMode: return ProcRRCreateMode(client);
|
||||||
ProcRRDestroyMode, /* 17 */
|
case X_RRDestroyMode: return ProcRRDestroyMode(client);
|
||||||
ProcRRAddOutputMode, /* 18 */
|
case X_RRAddOutputMode: return ProcRRAddOutputMode(client);
|
||||||
ProcRRDeleteOutputMode, /* 19 */
|
case X_RRDeleteOutputMode: return ProcRRDeleteOutputMode(client);
|
||||||
ProcRRGetCrtcInfo, /* 20 */
|
case X_RRGetCrtcInfo: return ProcRRGetCrtcInfo(client);
|
||||||
ProcRRSetCrtcConfig, /* 21 */
|
case X_RRSetCrtcConfig: return ProcRRSetCrtcConfig(client);
|
||||||
ProcRRGetCrtcGammaSize, /* 22 */
|
case X_RRGetCrtcGammaSize: return ProcRRGetCrtcGammaSize(client);
|
||||||
ProcRRGetCrtcGamma, /* 23 */
|
case X_RRGetCrtcGamma: return ProcRRGetCrtcGamma(client);
|
||||||
ProcRRSetCrtcGamma, /* 24 */
|
case X_RRSetCrtcGamma: return ProcRRSetCrtcGamma(client);
|
||||||
|
|
||||||
/* V1.3 additions */
|
/* V1.3 additions */
|
||||||
ProcRRGetScreenResourcesCurrent, /* 25 */
|
case X_RRGetScreenResourcesCurrent: return ProcRRGetScreenResourcesCurrent(client);
|
||||||
ProcRRSetCrtcTransform, /* 26 */
|
case X_RRSetCrtcTransform: return ProcRRSetCrtcTransform(client);
|
||||||
ProcRRGetCrtcTransform, /* 27 */
|
case X_RRGetCrtcTransform: return ProcRRGetCrtcTransform(client);
|
||||||
ProcRRGetPanning, /* 28 */
|
case X_RRGetPanning: return ProcRRGetPanning(client);
|
||||||
ProcRRSetPanning, /* 29 */
|
case X_RRSetPanning: return ProcRRSetPanning(client);
|
||||||
ProcRRSetOutputPrimary, /* 30 */
|
case X_RRSetOutputPrimary: return ProcRRSetOutputPrimary(client);
|
||||||
ProcRRGetOutputPrimary, /* 31 */
|
case X_RRGetOutputPrimary: return ProcRRGetOutputPrimary(client);
|
||||||
|
|
||||||
/* V1.4 additions */
|
/* V1.4 additions */
|
||||||
ProcRRGetProviders, /* 32 */
|
case X_RRGetProviders: return ProcRRGetProviders(client);
|
||||||
ProcRRGetProviderInfo, /* 33 */
|
case X_RRGetProviderInfo: return ProcRRGetProviderInfo(client);
|
||||||
ProcRRSetProviderOffloadSink, /* 34 */
|
case X_RRSetProviderOffloadSink: return ProcRRSetProviderOffloadSink(client);
|
||||||
ProcRRSetProviderOutputSource, /* 35 */
|
case X_RRSetProviderOutputSource: return ProcRRSetProviderOutputSource(client);
|
||||||
ProcRRListProviderProperties, /* 36 */
|
case X_RRListProviderProperties: return ProcRRListProviderProperties(client);
|
||||||
ProcRRQueryProviderProperty, /* 37 */
|
case X_RRQueryProviderProperty: return ProcRRQueryProviderProperty(client);
|
||||||
ProcRRConfigureProviderProperty, /* 38 */
|
case X_RRConfigureProviderProperty: return ProcRRConfigureProviderProperty(client);
|
||||||
ProcRRChangeProviderProperty, /* 39 */
|
case X_RRChangeProviderProperty: return ProcRRChangeProviderProperty(client);
|
||||||
ProcRRDeleteProviderProperty, /* 40 */
|
case X_RRDeleteProviderProperty: return ProcRRDeleteProviderProperty(client);
|
||||||
ProcRRGetProviderProperty, /* 41 */
|
case X_RRGetProviderProperty: return ProcRRGetProviderProperty(client);
|
||||||
|
|
||||||
/* V1.5 additions */
|
/* V1.5 additions */
|
||||||
ProcRRGetMonitors, /* 42 */
|
case X_RRGetMonitors: return ProcRRGetMonitors(client);
|
||||||
ProcRRSetMonitor, /* 43 */
|
case X_RRSetMonitor: return ProcRRSetMonitor(client);
|
||||||
ProcRRDeleteMonitor, /* 44 */
|
case X_RRDeleteMonitor: return ProcRRDeleteMonitor(client);
|
||||||
|
|
||||||
/* V1.6 additions */
|
/* V1.6 additions */
|
||||||
ProcRRCreateLease, /* 45 */
|
case X_RRCreateLease: return ProcRRCreateLease(client);
|
||||||
ProcRRFreeLease, /* 46 */
|
case X_RRFreeLease: return ProcRRFreeLease(client);
|
||||||
};
|
}
|
||||||
|
|
||||||
|
return BadRequest;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue