[PATCH 13/17] ephyr: Remove the host/server split of the actual XV video operations.

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


I suspect there's more cleanup possible in ephyrHostXVPutImage() by
sticking a bunch of the args in the port priv earlier.
---
 hw/kdrive/ephyr/ephyrhostvideo.c | 189 ---------------------------------------
 hw/kdrive/ephyr/ephyrhostvideo.h |  47 ----------
 hw/kdrive/ephyr/ephyrvideo.c     | 171 ++++++++++++++++++++++++++++-------
 3 files changed, 137 insertions(+), 270 deletions(-)

diff --git a/hw/kdrive/ephyr/ephyrhostvideo.c b/hw/kdrive/ephyr/ephyrhostvideo.c
index 3735f72..a26c31c 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.c
+++ b/hw/kdrive/ephyr/ephyrhostvideo.c
@@ -128,192 +128,3 @@ ephyrHostGetAtomName(int a_atom)
     free(reply);
     return ret;
 }
-
-Bool
-ephyrHostXVPutImage(int a_screen_num,
-                    int a_port_id,
-                    int a_image_id,
-                    int a_drw_x,
-                    int a_drw_y,
-                    int a_drw_w,
-                    int a_drw_h,
-                    int a_src_x,
-                    int a_src_y,
-                    int a_src_w,
-                    int a_src_h,
-                    int a_image_width,
-                    int a_image_height,
-                    unsigned char *a_buf,
-                    EphyrHostBox * a_clip_rects, int a_clip_rect_nums)
-{
-    Bool is_ok = TRUE;
-    xcb_connection_t *conn = hostx_get_xcbconn ();
-    xcb_gcontext_t gc;
-    xcb_rectangle_t *rects = NULL;
-    int data_len, width, height;
-    xcb_xv_query_image_attributes_cookie_t image_attr_cookie;
-    xcb_xv_query_image_attributes_reply_t *image_attr_reply;
-
-    EPHYR_RETURN_VAL_IF_FAIL(a_buf, FALSE);
-
-    EPHYR_LOG("enter, num_clip_rects: %d\n", a_clip_rect_nums);
-
-    gc = xcb_generate_id(conn);
-    xcb_create_gc(conn, gc, hostx_get_window(a_screen_num), 0, NULL);
-
-    image_attr_cookie = xcb_xv_query_image_attributes(conn,
-                                                      a_port_id,
-                                                      a_image_id,
-                                                      a_image_width,
-                                                      a_image_height);
-    image_attr_reply = xcb_xv_query_image_attributes_reply(conn,
-                                                           image_attr_cookie,
-                                                           NULL);
-    if (!image_attr_reply)
-        goto out;
-    data_len = image_attr_reply->data_size;
-    width = image_attr_reply->width;
-    height = image_attr_reply->height;
-    free(image_attr_reply);
-
-    if (a_clip_rect_nums) {
-        int i = 0;
-        rects = calloc(a_clip_rect_nums, sizeof(xcb_rectangle_t));
-        for (i=0; i < a_clip_rect_nums; i++) {
-            rects[i].x = a_clip_rects[i].x1;
-            rects[i].y = a_clip_rects[i].y1;
-            rects[i].width = a_clip_rects[i].x2 - a_clip_rects[i].x1;
-            rects[i].height = a_clip_rects[i].y2 - a_clip_rects[i].y1;
-            EPHYR_LOG("(x,y,w,h): (%d,%d,%d,%d)\n",
-                      rects[i].x, rects[i].y, rects[i].width, rects[i].height);
-        }
-        xcb_set_clip_rectangles(conn,
-                                XCB_CLIP_ORDERING_YX_BANDED,
-                                gc,
-                                0,
-                                0,
-                                a_clip_rect_nums,
-                                rects);
-	free(rects);
-    }
-    xcb_xv_put_image(conn,
-                     a_port_id,
-                     hostx_get_window (a_screen_num),
-                     gc,
-                     a_image_id,
-                     a_src_x, a_src_y, a_src_w, a_src_h,
-                     a_drw_x, a_drw_y, a_drw_w, a_drw_h,
-                     width, height,
-                     data_len, a_buf);
-    is_ok = TRUE;
-
-out:
-    xcb_free_gc(conn, gc);
-    EPHYR_LOG("leave\n");
-    return is_ok;
-}
-
-Bool
-ephyrHostXVPutVideo(int a_screen_num, int a_port_id,
-                    int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h,
-                    int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h)
-{
-    Bool is_ok = FALSE;
-    xcb_gcontext_t gc;
-    xcb_connection_t *conn = hostx_get_xcbconn();
-
-    EPHYR_RETURN_VAL_IF_FAIL(conn, FALSE);
-
-    gc = xcb_generate_id(conn);
-    xcb_create_gc(conn, gc, hostx_get_window (a_screen_num), 0, NULL);
-    xcb_xv_put_video(conn,
-                     a_port_id,
-                     hostx_get_window (a_screen_num), gc,
-                     a_vid_x, a_vid_y, a_vid_w, a_vid_h,
-                     a_drw_x, a_drw_y, a_drw_w, a_drw_h);
-    is_ok = TRUE;
-
-    xcb_free_gc(conn, gc);
-
-    return is_ok;
-}
-
-Bool
-ephyrHostXVGetVideo(int a_screen_num, int a_port_id,
-                    int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h,
-                    int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h)
-{
-    xcb_gcontext_t gc;
-    xcb_connection_t *conn = hostx_get_xcbconn();
-
-    EPHYR_RETURN_VAL_IF_FAIL(conn, FALSE);
-
-    gc = xcb_generate_id(conn);
-    xcb_create_gc(conn,
-                  gc,
-                  hostx_get_window (a_screen_num),
-                  0, NULL);
-    xcb_xv_get_video(conn,
-                     a_port_id,
-                     hostx_get_window (a_screen_num),
-                     gc,
-                     a_vid_x, a_vid_y, a_vid_w, a_vid_h,
-                     a_drw_x, a_drw_y, a_drw_w, a_drw_h);
-
-    xcb_free_gc(conn, gc);
-
-    return TRUE;
-}
-
-Bool
-ephyrHostXVPutStill(int a_screen_num, int a_port_id,
-                    int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h,
-                    int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h)
-{
-    xcb_connection_t *conn = hostx_get_xcbconn();
-    xcb_gcontext_t gc;
-
-    EPHYR_RETURN_VAL_IF_FAIL(conn, FALSE);
-
-    gc = xcb_generate_id(conn);
-    xcb_create_gc(conn,
-                  gc,
-                  hostx_get_window (a_screen_num),
-                  0, NULL);
-    xcb_xv_put_still(conn,
-                     a_port_id,
-                     hostx_get_window (a_screen_num),
-                     gc,
-                     a_vid_x, a_vid_y, a_vid_w, a_vid_h,
-                     a_drw_x, a_drw_y, a_drw_w, a_drw_h);
-
-    xcb_free_gc(conn, gc);
-
-    return TRUE;
-}
-
-Bool
-ephyrHostXVGetStill(int a_screen_num, int a_port_id,
-                    int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h,
-                    int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h)
-{
-    xcb_gcontext_t gc;
-    xcb_connection_t *conn = hostx_get_xcbconn();
-
-    EPHYR_RETURN_VAL_IF_FAIL(conn, FALSE);
-
-    gc = xcb_generate_id(conn);
-    xcb_create_gc(conn,
-                  gc,
-                  hostx_get_window (a_screen_num),
-                  0, NULL);
-    xcb_xv_get_still(conn,
-                     a_port_id,
-                     hostx_get_window (a_screen_num),
-                     gc,
-                     a_vid_x, a_vid_y, a_vid_w, a_vid_h,
-                     a_drw_x, a_drw_y, a_drw_w, a_drw_h);
-    xcb_free_gc(conn, gc);
-
-    return TRUE;
-}
diff --git a/hw/kdrive/ephyr/ephyrhostvideo.h b/hw/kdrive/ephyr/ephyrhostvideo.h
index 080caa8..9c2cd5a 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.h
+++ b/hw/kdrive/ephyr/ephyrhostvideo.h
@@ -31,10 +31,6 @@
 #include <xcb/xv.h>
 #include <X11/Xdefs.h>
 
-typedef struct {
-    unsigned short x1, y1, x2, y2;
-} EphyrHostBox;
-
 /*
  *size query
  */
@@ -54,47 +50,4 @@ Bool ephyrHostGetAtom(const char *a_name,
                       Bool a_create_if_not_exists, int *a_atom);
 char *ephyrHostGetAtomName(int a_atom);
 
-/*
- *PutImage
- * (ignore clipping for now)
- */
-Bool ephyrHostXVPutImage(int a_screen_num,
-                         int a_port_id,
-                         int a_image_id,
-                         int a_drw_x,
-                         int a_drw_y,
-                         int a_drw_w,
-                         int a_drw_h,
-                         int a_src_x,
-                         int a_src_y,
-                         int a_src_w,
-                         int a_src_h,
-                         int a_image_width,
-                         int a_image_height,
-                         unsigned char *a_buf,
-                         EphyrHostBox * a_clip_rects, int a_clip_rect_nums);
-
-/*
- * Putvideo/PutStill/GetVideo
- */
-Bool ephyrHostXVPutVideo(int a_screen_num,
-                         int a_port_id,
-                         int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h,
-                         int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h);
-
-Bool ephyrHostXVGetVideo(int a_screen_num,
-                         int a_port_id,
-                         int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h,
-                         int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h);
-
-Bool ephyrHostXVPutStill(int a_screen_num,
-                         int a_port_id,
-                         int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h,
-                         int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h);
-
-Bool ephyrHostXVGetStill(int a_screen_num,
-                         int a_port_id,
-                         int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h,
-                         int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h);
-
 #endif /*__EPHYRHOSTVIDEO_H__*/
diff --git a/hw/kdrive/ephyr/ephyrvideo.c b/hw/kdrive/ephyr/ephyrvideo.c
index 0795353..987e8e9 100644
--- a/hw/kdrive/ephyr/ephyrvideo.c
+++ b/hw/kdrive/ephyr/ephyrvideo.c
@@ -915,6 +915,93 @@ ephyrQueryBestSize(KdScreenInfo * a_info,
     EPHYR_LOG("leave\n");
 }
 
+
+static Bool
+ephyrHostXVPutImage(KdScreenInfo * a_info,
+                    EphyrPortPriv *port_priv,
+                    int a_image_id,
+                    int a_drw_x,
+                    int a_drw_y,
+                    int a_drw_w,
+                    int a_drw_h,
+                    int a_src_x,
+                    int a_src_y,
+                    int a_src_w,
+                    int a_src_h,
+                    int a_image_width,
+                    int a_image_height,
+                    unsigned char *a_buf,
+                    BoxPtr a_clip_rects, int a_clip_rect_nums)
+{
+    EphyrScrPriv *scrpriv = a_info->driver;
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_gcontext_t gc;
+    Bool is_ok = TRUE;
+    xcb_rectangle_t *rects = NULL;
+    int data_len, width, height;
+    xcb_xv_query_image_attributes_cookie_t image_attr_cookie;
+    xcb_xv_query_image_attributes_reply_t *image_attr_reply;
+
+    EPHYR_RETURN_VAL_IF_FAIL(a_buf, FALSE);
+
+    EPHYR_LOG("enter, num_clip_rects: %d\n", a_clip_rect_nums);
+
+    image_attr_cookie = xcb_xv_query_image_attributes(conn,
+                                                      port_priv->port_number,
+                                                      a_image_id,
+                                                      a_image_width,
+                                                      a_image_height);
+    image_attr_reply = xcb_xv_query_image_attributes_reply(conn,
+                                                           image_attr_cookie,
+                                                           NULL);
+    if (!image_attr_reply)
+        goto out;
+    data_len = image_attr_reply->data_size;
+    width = image_attr_reply->width;
+    height = image_attr_reply->height;
+    free(image_attr_reply);
+
+    gc = xcb_generate_id(conn);
+    xcb_create_gc(conn, gc, scrpriv->win, 0, NULL);
+
+    if (a_clip_rect_nums) {
+        int i = 0;
+        rects = calloc(a_clip_rect_nums, sizeof(xcb_rectangle_t));
+        for (i=0; i < a_clip_rect_nums; i++) {
+            rects[i].x = a_clip_rects[i].x1;
+            rects[i].y = a_clip_rects[i].y1;
+            rects[i].width = a_clip_rects[i].x2 - a_clip_rects[i].x1;
+            rects[i].height = a_clip_rects[i].y2 - a_clip_rects[i].y1;
+            EPHYR_LOG("(x,y,w,h): (%d,%d,%d,%d)\n",
+                      rects[i].x, rects[i].y, rects[i].width, rects[i].height);
+        }
+        xcb_set_clip_rectangles(conn,
+                                XCB_CLIP_ORDERING_YX_BANDED,
+                                gc,
+                                0,
+                                0,
+                                a_clip_rect_nums,
+                                rects);
+	free(rects);
+    }
+    xcb_xv_put_image(conn,
+                     port_priv->port_number,
+                     scrpriv->win,
+                     gc,
+                     a_image_id,
+                     a_src_x, a_src_y, a_src_w, a_src_h,
+                     a_drw_x, a_drw_y, a_drw_w, a_drw_h,
+                     width, height,
+                     data_len, a_buf);
+    xcb_free_gc(conn, gc);
+
+    is_ok = TRUE;
+
+out:
+    EPHYR_LOG("leave\n");
+    return is_ok;
+}
+
 static int
 ephyrPutImage(KdScreenInfo * a_info,
               DrawablePtr a_drawable,
@@ -941,13 +1028,12 @@ ephyrPutImage(KdScreenInfo * a_info,
 
     EPHYR_LOG("enter\n");
 
-    if (!ephyrHostXVPutImage(a_info->pScreen->myNum,
-                             port_priv->port_number,
+    if (!ephyrHostXVPutImage(a_info, port_priv,
                              a_id,
                              a_drw_x, a_drw_y, a_drw_w, a_drw_h,
                              a_src_x, a_src_y, a_src_w, a_src_h,
                              a_width, a_height, a_buf,
-                             (EphyrHostBox *) RegionRects(a_clipping_region),
+                             RegionRects(a_clipping_region),
                              RegionNumRects(a_clipping_region))) {
         EPHYR_LOG_ERROR("EphyrHostXVPutImage() failed\n");
         goto out;
@@ -1017,8 +1103,8 @@ ephyrReputImage(KdScreenInfo * a_info,
         EPHYR_LOG_ERROR("has null image buf in cache\n");
         goto out;
     }
-    if (!ephyrHostXVPutImage(a_info->pScreen->myNum,
-                             port_priv->port_number,
+    if (!ephyrHostXVPutImage(a_info,
+                             port_priv,
                              port_priv->image_id,
                              a_drw_x, a_drw_y,
                              port_priv->drw_w, port_priv->drw_h,
@@ -1026,7 +1112,7 @@ ephyrReputImage(KdScreenInfo * a_info,
                              port_priv->src_w, port_priv->src_h,
                              port_priv->image_width, port_priv->image_height,
                              port_priv->image_buf,
-                             (EphyrHostBox *) RegionRects(a_clipping_region),
+                             RegionRects(a_clipping_region),
                              RegionNumRects(a_clipping_region))) {
         EPHYR_LOG_ERROR("ephyrHostXVPutImage() failed\n");
         goto out;
@@ -1048,6 +1134,9 @@ ephyrPutVideo(KdScreenInfo * a_info,
               short a_drw_w, short a_drw_h,
               RegionPtr a_clipping_region, pointer a_port_priv)
 {
+    EphyrScrPriv *scrpriv = a_info->driver;
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_gcontext_t gc;
     EphyrPortPriv *port_priv = a_port_priv;
     BoxRec clipped_area, dst_box;
     int result = BadImplementation;
@@ -1068,13 +1157,14 @@ ephyrPutVideo(KdScreenInfo * a_info,
         goto out;
     }
 
-    if (!ephyrHostXVPutVideo(a_info->pScreen->myNum,
-                             port_priv->port_number,
-                             a_vid_x, a_vid_y, a_vid_w, a_vid_h,
-                             a_drw_x, a_drw_y, a_drw_w, a_drw_h)) {
-        EPHYR_LOG_ERROR("ephyrHostXVPutVideo() failed\n");
-        goto out;
-    }
+    gc = xcb_generate_id(conn);
+    xcb_create_gc(conn, gc, scrpriv->win, 0, NULL);
+    xcb_xv_put_video(conn, port_priv->port_number,
+                     scrpriv->win, gc,
+                     a_vid_x, a_vid_y, a_vid_w, a_vid_h,
+                     a_drw_x, a_drw_y, a_drw_w, a_drw_h);
+    xcb_free_gc(conn, gc);
+
     result = Success;
 
  out:
@@ -1091,6 +1181,9 @@ ephyrGetVideo(KdScreenInfo * a_info,
               short a_drw_w, short a_drw_h,
               RegionPtr a_clipping_region, pointer a_port_priv)
 {
+    EphyrScrPriv *scrpriv = a_info->driver;
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_gcontext_t gc;
     EphyrPortPriv *port_priv = a_port_priv;
     BoxRec clipped_area, dst_box;
     int result = BadImplementation;
@@ -1111,13 +1204,15 @@ ephyrGetVideo(KdScreenInfo * a_info,
         goto out;
     }
 
-    if (!ephyrHostXVGetVideo(a_info->pScreen->myNum,
-                             port_priv->port_number,
-                             a_vid_x, a_vid_y, a_vid_w, a_vid_h,
-                             a_drw_x, a_drw_y, a_drw_w, a_drw_h)) {
-        EPHYR_LOG_ERROR("ephyrHostXVGetVideo() failed\n");
-        goto out;
-    }
+    gc = xcb_generate_id(conn);
+    xcb_create_gc(conn, gc, scrpriv->win, 0, NULL);
+    xcb_xv_get_video(conn, port_priv->port_number,
+                     scrpriv->win, gc,
+                     a_vid_x, a_vid_y, a_vid_w, a_vid_h,
+                     a_drw_x, a_drw_y, a_drw_w, a_drw_h);
+
+    xcb_free_gc(conn, gc);
+
     result = Success;
 
  out:
@@ -1134,6 +1229,9 @@ ephyrPutStill(KdScreenInfo * a_info,
               short a_drw_w, short a_drw_h,
               RegionPtr a_clipping_region, pointer a_port_priv)
 {
+    EphyrScrPriv *scrpriv = a_info->driver;
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_gcontext_t gc;
     EphyrPortPriv *port_priv = a_port_priv;
     BoxRec clipped_area, dst_box;
     int result = BadImplementation;
@@ -1154,13 +1252,14 @@ ephyrPutStill(KdScreenInfo * a_info,
         goto out;
     }
 
-    if (!ephyrHostXVPutStill(a_info->pScreen->myNum,
-                             port_priv->port_number,
-                             a_vid_x, a_vid_y, a_vid_w, a_vid_h,
-                             a_drw_x, a_drw_y, a_drw_w, a_drw_h)) {
-        EPHYR_LOG_ERROR("ephyrHostXVPutStill() failed\n");
-        goto out;
-    }
+    gc = xcb_generate_id(conn);
+    xcb_create_gc(conn, gc, scrpriv->win, 0, NULL);
+    xcb_xv_put_still(conn, port_priv->port_number,
+                     scrpriv->win, gc,
+                     a_vid_x, a_vid_y, a_vid_w, a_vid_h,
+                     a_drw_x, a_drw_y, a_drw_w, a_drw_h);
+    xcb_free_gc(conn, gc);
+
     result = Success;
 
  out:
@@ -1177,6 +1276,9 @@ ephyrGetStill(KdScreenInfo * a_info,
               short a_drw_w, short a_drw_h,
               RegionPtr a_clipping_region, pointer a_port_priv)
 {
+    EphyrScrPriv *scrpriv = a_info->driver;
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_gcontext_t gc;
     EphyrPortPriv *port_priv = a_port_priv;
     BoxRec clipped_area, dst_box;
     int result = BadImplementation;
@@ -1197,13 +1299,14 @@ ephyrGetStill(KdScreenInfo * a_info,
         goto out;
     }
 
-    if (!ephyrHostXVGetStill(a_info->pScreen->myNum,
-                             port_priv->port_number,
-                             a_vid_x, a_vid_y, a_vid_w, a_vid_h,
-                             a_drw_x, a_drw_y, a_drw_w, a_drw_h)) {
-        EPHYR_LOG_ERROR("ephyrHostXVGetStill() failed\n");
-        goto out;
-    }
+    gc = xcb_generate_id(conn);
+    xcb_create_gc(conn, gc, scrpriv->win, 0, NULL);
+    xcb_xv_get_still(conn, port_priv->port_number,
+                     scrpriv->win, gc,
+                     a_vid_x, a_vid_y, a_vid_w, a_vid_h,
+                     a_drw_x, a_drw_y, a_drw_w, a_drw_h);
+    xcb_free_gc(conn, gc);
+
     result = Success;
 
  out:
-- 
1.8.4.rc3



More information about the xorg-devel mailing list