[PATCH 03/16] xv: Move common code for adaptor cleanup to xvmain.c

Eric Anholt eric at anholt.net
Fri Jul 18 10:32:20 PDT 2014


Since any DDX XV screen cleanup would need this same code for freeing
the tree of pointers for xv adaptors, move it to the dix.

Signed-off-by: Eric Anholt <eric at anholt.net>
---
 Xext/xvdix.h               |  1 +
 Xext/xvmain.c              | 41 +++++++++++++++++++++++++++++++++++++++++
 hw/kdrive/src/kxv.c        | 28 +---------------------------
 hw/xfree86/common/xf86xv.c | 31 +------------------------------
 4 files changed, 44 insertions(+), 57 deletions(-)

diff --git a/Xext/xvdix.h b/Xext/xvdix.h
index bb08cf4..f62adf8 100644
--- a/Xext/xvdix.h
+++ b/Xext/xvdix.h
@@ -235,6 +235,7 @@ extern _X_EXPORT int SProcXvDispatch(ClientPtr);
 extern _X_EXPORT int XvScreenInit(ScreenPtr);
 extern _X_EXPORT DevPrivateKey XvGetScreenKey(void);
 extern _X_EXPORT unsigned long XvGetRTPort(void);
+extern _X_EXPORT void XvFreeAdaptor(XvAdaptorPtr pAdaptor);
 extern _X_EXPORT int XvdiSendPortNotify(XvPortPtr, Atom, INT32);
 extern _X_EXPORT int XvdiVideoStopped(XvPortPtr, int);
 
diff --git a/Xext/xvmain.c b/Xext/xvmain.c
index 00b5179..70edc93 100644
--- a/Xext/xvmain.c
+++ b/Xext/xvmain.c
@@ -1091,3 +1091,44 @@ WriteSwappedPortNotifyEvent(xvEvent * from, xvEvent * to)
     cpswapl(from->u.portNotify.value, to->u.portNotify.value);
 
 }
+
+void
+XvFreeAdaptor(XvAdaptorPtr pAdaptor)
+{
+    int i;
+
+    free(pAdaptor->name);
+    pAdaptor->name = NULL;
+
+    if (pAdaptor->pEncodings) {
+        XvEncodingPtr pEncode = pAdaptor->pEncodings;
+
+        for (i = 0; i < pAdaptor->nEncodings; i++, pEncode++)
+            free(pEncode->name);
+        free(pAdaptor->pEncodings);
+        pAdaptor->pEncodings = NULL;
+    }
+
+    free(pAdaptor->pFormats);
+    pAdaptor->pFormats = NULL;
+
+    if (pAdaptor->pPorts) {
+        free(pAdaptor->pPorts);
+        pAdaptor->pPorts = NULL;
+    }
+
+    if (pAdaptor->pAttributes) {
+        XvAttributePtr pAttribute = pAdaptor->pAttributes;
+
+        for (i = 0; i < pAdaptor->nAttributes; i++, pAttribute++)
+            free(pAttribute->name);
+        free(pAdaptor->pAttributes);
+        pAdaptor->pAttributes = NULL;
+    }
+
+    free(pAdaptor->pImages);
+    pAdaptor->pImages = NULL;
+
+    free(pAdaptor->devPriv.ptr);
+    pAdaptor->devPriv.ptr = NULL;
+}
diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c
index 3d63304..5aae8f7 100644
--- a/hw/kdrive/src/kxv.c
+++ b/hw/kdrive/src/kxv.c
@@ -193,19 +193,6 @@ KdXVFreeAdaptor(XvAdaptorPtr pAdaptor)
 {
     int i;
 
-    free(pAdaptor->name);
-
-    if (pAdaptor->pEncodings) {
-        XvEncodingPtr pEncode = pAdaptor->pEncodings;
-
-        for (i = 0; i < pAdaptor->nEncodings; i++, pEncode++) {
-            free(pEncode->name);
-        }
-        free(pAdaptor->pEncodings);
-    }
-
-    free(pAdaptor->pFormats);
-
     if (pAdaptor->pPorts) {
         XvPortPtr pPort = pAdaptor->pPorts;
         XvPortRecPrivatePtr pPriv;
@@ -220,22 +207,9 @@ KdXVFreeAdaptor(XvAdaptorPtr pAdaptor)
                 free(pPriv);
             }
         }
-        free(pAdaptor->pPorts);
     }
 
-    if (pAdaptor->nAttributes) {
-        XvAttributePtr pAttribute = pAdaptor->pAttributes;
-
-        for (i = 0; i < pAdaptor->nAttributes; i++, pAttribute++) {
-            free(pAttribute->name);
-        }
-
-        free(pAdaptor->pAttributes);
-    }
-
-    free(pAdaptor->pImages);
-
-    free(pAdaptor->devPriv.ptr);
+    XvFreeAdaptor(pAdaptor);
 }
 
 static Bool
diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c
index 6302b8d..ae20b58 100644
--- a/hw/xfree86/common/xf86xv.c
+++ b/hw/xfree86/common/xf86xv.c
@@ -297,21 +297,6 @@ xf86XVFreeAdaptor(XvAdaptorPtr pAdaptor)
 {
     int i;
 
-    free(pAdaptor->name);
-    pAdaptor->name = NULL;
-
-    if (pAdaptor->pEncodings) {
-        XvEncodingPtr pEncode = pAdaptor->pEncodings;
-
-        for (i = 0; i < pAdaptor->nEncodings; i++, pEncode++)
-            free(pEncode->name);
-        free(pAdaptor->pEncodings);
-        pAdaptor->pEncodings = NULL;
-    }
-
-    free(pAdaptor->pFormats);
-    pAdaptor->pFormats = NULL;
-
     if (pAdaptor->pPorts) {
         XvPortPtr pPort = pAdaptor->pPorts;
         XvPortRecPrivatePtr pPriv;
@@ -328,23 +313,9 @@ xf86XVFreeAdaptor(XvAdaptorPtr pAdaptor)
                 free(pPriv);
             }
         }
-        free(pAdaptor->pPorts);
-        pAdaptor->pPorts = NULL;
-    }
-
-    if (pAdaptor->pAttributes) {
-        XvAttributePtr pAttribute = pAdaptor->pAttributes;
-
-        for (i = 0; i < pAdaptor->nAttributes; i++, pAttribute++)
-            free(pAttribute->name);
-        free(pAdaptor->pAttributes);
-        pAdaptor->pAttributes = NULL;
     }
 
-    free(pAdaptor->pImages);
-    free(pAdaptor->devPriv.ptr);
-    pAdaptor->pImages = NULL;
-    pAdaptor->devPriv.ptr = NULL;
+    XvFreeAdaptor(pAdaptor);
 }
 
 static Bool
-- 
2.0.1



More information about the xorg-devel mailing list