[PATCH] Simplify XineramifyXv.
Jamey Sharp
jamey at minilop.net
Mon Apr 26 15:37:16 PDT 2010
The structure of the adaptor-matching algorithm was obscured by trying
to use "continue" and "break" as the only control-flow primitives. It's
a lot more clear if you add "return" to that set.
In some ways this patch is easier to review with `git diff -w`.
Signed-off-by: Jamey Sharp <jamey at minilop.net>
---
Xext/xvdisp.c | 147 +++++++++++++++++++++++++--------------------------------
1 files changed, 64 insertions(+), 83 deletions(-)
diff --git a/Xext/xvdisp.c b/Xext/xvdisp.c
index b6fc34f..4345672 100644
--- a/Xext/xvdisp.c
+++ b/Xext/xvdisp.c
@@ -1850,110 +1850,91 @@ XineramaXvPutStill(ClientPtr client)
return result;
}
+static Bool
+isImageAdaptor(XvAdaptorPtr pAdapt)
+{
+ return (pAdapt->type & XvImageMask) && (pAdapt->nImages > 0);
+}
+
+static Bool
+hasOverlay(XvAdaptorPtr pAdapt)
+{
+ int i;
+ for(i = 0; i < pAdapt->nAttributes; i++)
+ if(!strcmp(pAdapt->pAttributes[i].name, "XV_COLORKEY"))
+ return TRUE;
+ return FALSE;
+}
+
+static XvAdaptorPtr
+matchAdaptor(ScreenPtr pScreen, XvAdaptorPtr refAdapt, Bool isOverlay)
+{
+ int i;
+ XvScreenPtr xvsp = dixLookupPrivate(&pScreen->devPrivates, XvGetScreenKey());
+ /* Do not try to go on if xv is not supported on this screen */
+ if(xvsp == NULL)
+ return NULL;
+
+ /* if the adaptor has the same name it's a perfect match */
+ for(i = 0; i < xvsp->nAdaptors; i++) {
+ XvAdaptorPtr pAdapt = xvsp->pAdaptors + i;
+ if(!strcmp(refAdapt->name, pAdapt->name))
+ return pAdapt;
+ }
+
+ /* otherwise we only look for XvImage adaptors */
+ if(!isImageAdaptor(refAdapt))
+ return NULL;
+
+ /* prefer overlay/overlay non-overlay/non-overlay pairing */
+ for(i = 0; i < xvsp->nAdaptors; i++) {
+ XvAdaptorPtr pAdapt = xvsp->pAdaptors + i;
+ if(isImageAdaptor(pAdapt) && isOverlay == hasOverlay(pAdapt))
+ return pAdapt;
+ }
+
+ /* but we'll take any XvImage pairing if we can get it */
+ for(i = 0; i < xvsp->nAdaptors; i++) {
+ XvAdaptorPtr pAdapt = xvsp->pAdaptors + i;
+ if(isImageAdaptor(pAdapt))
+ return pAdapt;
+ }
+ return NULL;
+}
+
void XineramifyXv(void)
{
- ScreenPtr pScreen, screen0 = screenInfo.screens[0];
- XvScreenPtr xvsp0 = (XvScreenPtr)dixLookupPrivate(&screen0->devPrivates,
- XvGetScreenKey());
- XvAdaptorPtr refAdapt, pAdapt;
- XvAttributePtr pAttr;
- XvScreenPtr xvsp;
- Bool isOverlay, hasOverlay;
- PanoramiXRes *port;
+ XvScreenPtr xvsp0 = dixLookupPrivate(&screenInfo.screens[0]->devPrivates, XvGetScreenKey());
XvAdaptorPtr MatchingAdaptors[MAXSCREENS];
- int i, j, k, l;
+ int i, j, k;
XvXRTPort = CreateNewResourceType(XineramaDeleteResource, "XvXRTPort");
if (!xvsp0 || !XvXRTPort) return;
for(i = 0; i < xvsp0->nAdaptors; i++) {
- refAdapt = xvsp0->pAdaptors + i;
+ Bool isOverlay;
+ XvAdaptorPtr refAdapt = xvsp0->pAdaptors + i;
+ if(!(refAdapt->type & XvInputMask)) continue;
- bzero(MatchingAdaptors, sizeof(XvAdaptorPtr) * MAXSCREENS);
-
MatchingAdaptors[0] = refAdapt;
-
- if(!(refAdapt->type & XvInputMask)) continue;
-
- isOverlay = FALSE;
- for(j = 0; j < refAdapt->nAttributes; j++) {
- pAttr = refAdapt->pAttributes + j;
- if(!strcmp(pAttr->name, "XV_COLORKEY")) {
- isOverlay = TRUE;
- break;
- }
- }
-
- for(j = 1; j < PanoramiXNumScreens; j++) {
- pScreen = screenInfo.screens[j];
- xvsp = (XvScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
- XvGetScreenKey());
- /* Do not try to go on if xv is not supported on this screen */
- if (xvsp==NULL) continue ;
-
- /* if the adaptor has the same name it's a perfect match */
- for(k = 0; k < xvsp->nAdaptors; k++) {
- pAdapt = xvsp->pAdaptors + k;
- if(!strcmp(refAdapt->name, pAdapt->name)) {
- MatchingAdaptors[j] = pAdapt;
- break;
- }
- }
- if(MatchingAdaptors[j]) continue; /* found it */
-
- /* otherwise we only look for XvImage adaptors */
- if(!(refAdapt->type & XvImageMask)) continue;
- if(refAdapt->nImages <= 0) continue;
-
- /* prefer overlay/overlay non-overlay/non-overlay pairing */
- for(k = 0; k < xvsp->nAdaptors; k++) {
- pAdapt = xvsp->pAdaptors + k;
- if((pAdapt->type & XvImageMask) && (pAdapt->nImages > 0)) {
- hasOverlay = FALSE;
- for(l = 0; l < pAdapt->nAttributes; l++) {
- if(!strcmp(pAdapt->pAttributes[l].name, "XV_COLORKEY")) {
- hasOverlay = TRUE;
- break;
- }
- }
- if(isOverlay && hasOverlay) {
- MatchingAdaptors[j] = pAdapt;
- break;
- }
- else if(!isOverlay && !hasOverlay) {
- MatchingAdaptors[j] = pAdapt;
- break;
- }
- }
- }
-
- if(MatchingAdaptors[j]) continue; /* found it */
-
- /* but we'll take any XvImage pairing if we can get it */
-
- for(k = 0; k < xvsp->nAdaptors; k++) {
- pAdapt = xvsp->pAdaptors + k;
- if((pAdapt->type & XvImageMask) && (pAdapt->nImages > 0)) {
- MatchingAdaptors[j] = pAdapt;
- break;
- }
- }
- }
+ isOverlay = hasOverlay(refAdapt);
+ for(j = 1; j < PanoramiXNumScreens; j++)
+ MatchingAdaptors[j] = matchAdaptor(screenInfo.screens[j], refAdapt, isOverlay);
/* now create a resource for each port */
for(j = 0; j < refAdapt->nPorts; j++) {
- if(!(port = xalloc(sizeof(PanoramiXRes))))
+ PanoramiXRes *port = xalloc(sizeof(PanoramiXRes));
+ if(!port)
break;
- port->info[0].id = MatchingAdaptors[0]->base_id + j;
- AddResource(port->info[0].id, XvXRTPort, port);
- for(k = 1; k < PanoramiXNumScreens; k++) {
+ for(k = 0; k < PanoramiXNumScreens; k++) {
if(MatchingAdaptors[k] && (MatchingAdaptors[k]->nPorts > j))
port->info[k].id = MatchingAdaptors[k]->base_id + j;
else
port->info[k].id = 0;
}
+ AddResource(port->info[0].id, XvXRTPort, port);
}
}
--
1.7.0
More information about the xorg-devel
mailing list