[PATCH 07/17] ephyr: Refactor XV adaptor feature detection.

Eric Anholt eric at anholt.net
Mon Aug 26 13:26:13 PDT 2013


This obviously wanted a helper function beforehand, but even more so
now that we have XCB.
---
 hw/kdrive/ephyr/ephyrhostvideo.c | 68 ----------------------------------------
 hw/kdrive/ephyr/ephyrhostvideo.h | 11 -------
 hw/kdrive/ephyr/ephyrvideo.c     | 48 ++++++++++------------------
 3 files changed, 17 insertions(+), 110 deletions(-)

diff --git a/hw/kdrive/ephyr/ephyrhostvideo.c b/hw/kdrive/ephyr/ephyrhostvideo.c
index 9a5a3ba..5c3eb05 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.c
+++ b/hw/kdrive/ephyr/ephyrhostvideo.c
@@ -138,74 +138,6 @@ ephyrHostXVAdaptorGetVideoFormats (const xcb_xv_adaptor_info_t *a_this,
 }
 
 Bool
-ephyrHostXVAdaptorHasPutVideo (const xcb_xv_adaptor_info_t *a_this,
-                               Bool *a_result)
-{
-    EPHYR_RETURN_VAL_IF_FAIL(a_this && a_result, FALSE);
-
-    if ((a_this->type & (XCB_XV_TYPE_VIDEO_MASK | XCB_XV_TYPE_INPUT_MASK)) ==
-        (XCB_XV_TYPE_VIDEO_MASK | XCB_XV_TYPE_INPUT_MASK))
-        *a_result = TRUE;
-    else
-        *a_result = FALSE;
-    return TRUE;
-}
-
-Bool
-ephyrHostXVAdaptorHasGetVideo(const xcb_xv_adaptor_info_t *a_this,
-                              Bool *a_result)
-{
-    if ((a_this->type & (XCB_XV_TYPE_VIDEO_MASK | XCB_XV_TYPE_OUTPUT_MASK)) ==
-        (XCB_XV_TYPE_VIDEO_MASK | XCB_XV_TYPE_OUTPUT_MASK))
-        *a_result = TRUE;
-    else
-        *a_result = FALSE;
-    return TRUE;
-}
-
-Bool
-ephyrHostXVAdaptorHasPutStill(const xcb_xv_adaptor_info_t *a_this,
-                              Bool *a_result)
-{
-    EPHYR_RETURN_VAL_IF_FAIL(a_this && a_result, FALSE);
-
-    if ((a_this->type & (XCB_XV_TYPE_STILL_MASK | XCB_XV_TYPE_INPUT_MASK)) ==
-        (XCB_XV_TYPE_STILL_MASK | XCB_XV_TYPE_INPUT_MASK))
-        *a_result = TRUE;
-    else
-        *a_result = FALSE;
-    return TRUE;
-}
-
-Bool
-ephyrHostXVAdaptorHasGetStill(const xcb_xv_adaptor_info_t *a_this,
-                              Bool *a_result)
-{
-    EPHYR_RETURN_VAL_IF_FAIL(a_this && a_result, FALSE);
-
-    if ((a_this->type & (XCB_XV_TYPE_STILL_MASK | XCB_XV_TYPE_OUTPUT_MASK)) ==
-        (XCB_XV_TYPE_STILL_MASK | XCB_XV_TYPE_OUTPUT_MASK))
-        *a_result = TRUE;
-    else
-        *a_result = FALSE;
-    return TRUE;
-}
-
-Bool
-ephyrHostXVAdaptorHasPutImage(const xcb_xv_adaptor_info_t *a_this,
-                              Bool *a_result)
-{
-    EPHYR_RETURN_VAL_IF_FAIL(a_this && a_result, FALSE);
-
-    if ((a_this->type & (XCB_XV_TYPE_IMAGE_MASK | XCB_XV_TYPE_INPUT_MASK)) ==
-        (XCB_XV_TYPE_IMAGE_MASK | XCB_XV_TYPE_INPUT_MASK))
-        *a_result = TRUE;
-    else
-        *a_result = FALSE;
-    return TRUE;
-}
-
-Bool
 ephyrHostXVQueryEncodings(int a_port_id,
                           EphyrHostEncoding ** a_encodings,
                           unsigned int *a_num_encodings)
diff --git a/hw/kdrive/ephyr/ephyrhostvideo.h b/hw/kdrive/ephyr/ephyrhostvideo.h
index 56a7359..40a12ac 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.h
+++ b/hw/kdrive/ephyr/ephyrhostvideo.h
@@ -98,17 +98,6 @@ char* ephyrHostXVAdaptorGetName(const xcb_xv_adaptor_info_t *a_this);
 EphyrHostVideoFormat *ephyrHostXVAdaptorGetVideoFormats
     (const xcb_xv_adaptor_info_t *a_this, int *a_nb_formats);
 
-Bool ephyrHostXVAdaptorHasPutVideo(const xcb_xv_adaptor_info_t *a_this,
-                                   Bool *a_result);
-Bool ephyrHostXVAdaptorHasGetVideo(const xcb_xv_adaptor_info_t *a_this,
-                                   Bool *a_result);
-Bool ephyrHostXVAdaptorHasPutStill(const xcb_xv_adaptor_info_t *a_this,
-                                   Bool *a_result);
-Bool ephyrHostXVAdaptorHasGetStill(const xcb_xv_adaptor_info_t *a_this,
-                                   Bool *a_result);
-Bool ephyrHostXVAdaptorHasPutImage(const xcb_xv_adaptor_info_t *a_this,
-                                   Bool *a_result);
-
 /*
  * encoding
  */
diff --git a/hw/kdrive/ephyr/ephyrvideo.c b/hw/kdrive/ephyr/ephyrvideo.c
index 7d249d2..bf00694 100644
--- a/hw/kdrive/ephyr/ephyrvideo.c
+++ b/hw/kdrive/ephyr/ephyrvideo.c
@@ -170,6 +170,12 @@ static int s_base_port_id;
  * ************/
 
 static Bool
+adaptor_has_flags(const xcb_xv_adaptor_info_t *adaptor, uint32_t flags)
+{
+    return (adaptor->type & flags) == flags;
+}
+
+static Bool
 DoSimpleClip(BoxPtr a_dst_box, BoxPtr a_clipper, BoxPtr a_result)
 {
     BoxRec dstClippedBox;
@@ -508,7 +514,6 @@ static Bool
 ephyrXVPrivSetAdaptorsHooks(EphyrXVPriv * a_this)
 {
     int i = 0;
-    Bool has_it = FALSE;
     xcb_xv_adaptor_info_t *cur_host_adaptor = NULL;
 
     EPHYR_RETURN_VAL_IF_FAIL(a_this, FALSE);
@@ -528,45 +533,26 @@ ephyrXVPrivSetAdaptorsHooks(EphyrXVPriv * a_this)
             EPHYR_LOG_ERROR("failed to get host adaptor at index %d\n", i);
             continue;
         }
-        has_it = FALSE;
-        if (!ephyrHostXVAdaptorHasPutImage(cur_host_adaptor, &has_it)) {
-            EPHYR_LOG_ERROR("error\n");
-        }
-        if (has_it) {
+
+        if (adaptor_has_flags(cur_host_adaptor,
+                              XCB_XV_TYPE_IMAGE_MASK | XCB_XV_TYPE_INPUT_MASK))
             a_this->adaptors[i].PutImage = ephyrPutImage;
-        }
 
-        has_it = FALSE;
-        if (!ephyrHostXVAdaptorHasPutVideo(cur_host_adaptor, &has_it)) {
-            EPHYR_LOG_ERROR("error\n");
-        }
-        if (has_it) {
+        if (adaptor_has_flags(cur_host_adaptor,
+                              XCB_XV_TYPE_VIDEO_MASK | XCB_XV_TYPE_INPUT_MASK))
             a_this->adaptors[i].PutVideo = ephyrPutVideo;
-        }
 
-        has_it = FALSE;
-        if (!ephyrHostXVAdaptorHasGetVideo(cur_host_adaptor, &has_it)) {
-            EPHYR_LOG_ERROR("error\n");
-        }
-        if (has_it) {
+        if (adaptor_has_flags(cur_host_adaptor,
+                              XCB_XV_TYPE_VIDEO_MASK | XCB_XV_TYPE_OUTPUT_MASK))
             a_this->adaptors[i].GetVideo = ephyrGetVideo;
-        }
 
-        has_it = FALSE;
-        if (!ephyrHostXVAdaptorHasPutStill(cur_host_adaptor, &has_it)) {
-            EPHYR_LOG_ERROR("error\n");
-        }
-        if (has_it) {
+        if (adaptor_has_flags(cur_host_adaptor,
+                              XCB_XV_TYPE_STILL_MASK | XCB_XV_TYPE_INPUT_MASK))
             a_this->adaptors[i].PutStill = ephyrPutStill;
-        }
 
-        has_it = FALSE;
-        if (!ephyrHostXVAdaptorHasGetStill(cur_host_adaptor, &has_it)) {
-            EPHYR_LOG_ERROR("error\n");
-        }
-        if (has_it) {
+        if (adaptor_has_flags(cur_host_adaptor,
+                              XCB_XV_TYPE_STILL_MASK | XCB_XV_TYPE_OUTPUT_MASK))
             a_this->adaptors[i].GetStill = ephyrGetStill;
-        }
     }
     EPHYR_LOG("leave\n");
     return TRUE;
-- 
1.8.4.rc3



More information about the xorg-devel mailing list