[vlc-devel] [PATCH 04/24] vout: x11: refactor for next changes

Thomas Guillem thomas at gllm.fr
Wed Oct 31 17:49:59 CET 2018


vd->fmt and vd->cfg will be removed.
fmt and cfg will be passed by Open() and controls.
---
 modules/hw/vdpau/display.c        | 35 +++++++++-------
 modules/video_output/xcb/events.c |  5 ++-
 modules/video_output/xcb/events.h |  1 +
 modules/video_output/xcb/window.c |  1 -
 modules/video_output/xcb/x11.c    | 68 ++++++++++++++++---------------
 modules/video_output/xcb/xvideo.c | 55 +++++++++----------------
 6 files changed, 80 insertions(+), 85 deletions(-)

diff --git a/modules/hw/vdpau/display.c b/modules/hw/vdpau/display.c
index 9b0a31a2f9..7e5548ffc5 100644
--- a/modules/hw/vdpau/display.c
+++ b/modules/hw/vdpau/display.c
@@ -65,6 +65,8 @@ struct vout_display_sys_t
     VdpRGBAFormat rgb_fmt; /**< Output surface format */
 
     picture_pool_t *pool; /**< pictures pool */
+    unsigned width;
+    unsigned height;
 };
 
 static void pictureSys_DestroyVDPAU(picture_sys_t *psys)
@@ -203,13 +205,13 @@ static void RenderRegion(vout_display_t *vd, VdpOutputSurface target,
 
     /* Render onto main surface */
     VdpRect area = {
-        reg->i_x * vd->fmt.i_visible_width
+        reg->i_x * sys->width
             / subpic->i_original_picture_width,
-        reg->i_y * vd->fmt.i_visible_height
+        reg->i_y * sys->height
             / subpic->i_original_picture_height,
-        (reg->i_x + reg->fmt.i_visible_width) * vd->fmt.i_visible_width
+        (reg->i_x + reg->fmt.i_visible_width) * sys->width
             / subpic->i_original_picture_width,
-        (reg->i_y + reg->fmt.i_visible_height) * vd->fmt.i_visible_height
+        (reg->i_y + reg->fmt.i_visible_height) * sys->height
             / subpic->i_original_picture_height,
     };
     VdpColor color = { 1.f, 1.f, 1.f,
@@ -330,6 +332,8 @@ static int Control(vout_display_t *vd, int query, va_list ap)
     {
     case VOUT_DISPLAY_RESET_PICTURES:
     {
+        const vout_display_cfg_t *cfg = va_arg(ap, const vout_display_cfg_t *);
+        video_format_t *fmt = va_arg(ap, video_format_t *);
         msg_Dbg(vd, "resetting pictures");
         if (sys->pool != NULL)
         {
@@ -338,15 +342,14 @@ static int Control(vout_display_t *vd, int query, va_list ap)
         }
 
         const video_format_t *src= &vd->source;
-        video_format_t *fmt = &vd->fmt;
         vout_display_place_t place;
 
-        vout_display_PlacePicture(&place, src, vd->cfg, false);
+        vout_display_PlacePicture(&place, src, cfg, false);
 
         fmt->i_width = src->i_width * place.width / src->i_visible_width;
         fmt->i_height = src->i_height * place.height / src->i_visible_height;
-        fmt->i_visible_width  = place.width;
-        fmt->i_visible_height = place.height;
+        sys->width = fmt->i_visible_width = place.width;
+        sys->height = fmt->i_visible_height = place.height;
         fmt->i_x_offset = src->i_x_offset * place.width / src->i_visible_width;
         fmt->i_y_offset = src->i_y_offset * place.height / src->i_visible_height;
 
@@ -414,19 +417,21 @@ static int Open(vlc_object_t *obj)
         return VLC_EGENERIC;
 
     vout_display_t *vd = (vout_display_t *)obj;
+    const vout_display_cfg_t *cfg = vd->cfg;
+    video_format_t *fmtp = &vd->fmt;
     vout_display_sys_t *sys = malloc(sizeof (*sys));
     if (unlikely(sys == NULL))
         return VLC_ENOMEM;
 
     const xcb_screen_t *screen;
-    if (vlc_xcb_parent_Create(vd, &sys->conn, &screen) == NULL)
+    if (vlc_xcb_parent_Create(vd, cfg, &sys->conn, &screen) == NULL)
     {
         free(sys);
         return VLC_EGENERIC;
     }
 
     /* Load the VDPAU back-end and create a device instance */
-    VdpStatus err = vdp_get_x11(vd->cfg->window->display.x11,
+    VdpStatus err = vdp_get_x11(cfg->window->display.x11,
                                 xcb_screen_num(sys->conn, screen),
                                 &sys->vdp, &sys->device);
     if (err != VDP_STATUS_OK)
@@ -446,7 +451,7 @@ static int Open(vlc_object_t *obj)
     VdpChromaType chroma;
     VdpYCbCrFormat format;
 
-    video_format_ApplyRotation(&fmt, &vd->fmt);
+    video_format_ApplyRotation(&fmt, fmtp);
 
     if (fmt.i_chroma == VLC_CODEC_VDPAU_VIDEO_420
      || fmt.i_chroma == VLC_CODEC_VDPAU_VIDEO_422
@@ -561,6 +566,8 @@ static int Open(vlc_object_t *obj)
         goto error;
     }
 
+    sys->width = fmtp->i_visible_width;
+    sys->height = fmtp->i_visible_height;
     /* VDPAU-X11 requires a window dedicated to the back-end */
     {
         xcb_pixmap_t pix = xcb_generate_id(sys->conn);
@@ -577,12 +584,12 @@ static int Open(vlc_object_t *obj)
         };
         vout_display_place_t place;
 
-        vout_display_PlacePicture (&place, &vd->source, vd->cfg, false);
+        vout_display_PlacePicture (&place, &vd->source, cfg, false);
         sys->window = xcb_generate_id(sys->conn);
 
         xcb_void_cookie_t c =
             xcb_create_window_checked(sys->conn, screen->root_depth,
-                sys->window, vd->cfg->window->handle.xid, place.x, place.y,
+                sys->window, cfg->window->handle.xid, place.x, place.y,
                 place.width, place.height, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
                 screen->root_visual, mask, values);
         if (vlc_xcb_error_Check(vd, sys->conn, "window creation failure", c))
@@ -640,7 +647,7 @@ static int Open(vlc_object_t *obj)
     vd->sys = sys;
     vd->info.has_pictures_invalid = true;
     vd->info.subpicture_chromas = spu_chromas;
-    vd->fmt = fmt;
+    *fmtp = fmt;
 
     vd->pool = Pool;
     vd->prepare = Queue;
diff --git a/modules/video_output/xcb/events.c b/modules/video_output/xcb/events.c
index 907414572a..19137fceca 100644
--- a/modules/video_output/xcb/events.c
+++ b/modules/video_output/xcb/events.c
@@ -102,15 +102,16 @@ static const xcb_screen_t *FindScreen (vlc_object_t *obj,
 }
 
 vout_window_t *vlc_xcb_parent_Create(vout_display_t *vd,
+                                     const vout_display_cfg_t *cfg,
                                      xcb_connection_t **restrict pconn,
                                      const xcb_screen_t **restrict pscreen)
 {
-    vout_window_t *wnd = vout_display_NewWindow (vd, VOUT_WINDOW_TYPE_XID);
-    if (wnd == NULL)
+    if (cfg->window->type != VOUT_WINDOW_TYPE_XID)
     {
         msg_Err (vd, "window not available");
         return NULL;
     }
+    vout_window_t *wnd = cfg->window;
 
     xcb_connection_t *conn = Connect (VLC_OBJECT(vd), wnd->display.x11);
     if (conn == NULL)
diff --git a/modules/video_output/xcb/events.h b/modules/video_output/xcb/events.h
index 91f4595061..885aa5acca 100644
--- a/modules/video_output/xcb/events.h
+++ b/modules/video_output/xcb/events.h
@@ -41,6 +41,7 @@ int vlc_xcb_error_Check(vout_display_t *, xcb_connection_t *conn,
  * finds the corresponding X server screen.
  */
 struct vout_window_t *vlc_xcb_parent_Create(vout_display_t *obj,
+                                            const vout_display_cfg_t *cfg,
                                             xcb_connection_t **connp,
                                             const xcb_screen_t **screenp);
 /**
diff --git a/modules/video_output/xcb/window.c b/modules/video_output/xcb/window.c
index 6152d420ce..e7cb3510bd 100644
--- a/modules/video_output/xcb/window.c
+++ b/modules/video_output/xcb/window.c
@@ -224,7 +224,6 @@ static xcb_cursor_t CursorCreate(xcb_connection_t *conn, xcb_window_t root)
 
 static int ProcessEvent(vout_window_t *wnd, xcb_generic_event_t *ev)
 {
-    vout_window_sys_t *sys = wnd->sys;
     int ret = 0;
 
     switch (ev->response_type & 0x7f)
diff --git a/modules/video_output/xcb/x11.c b/modules/video_output/xcb/x11.c
index fecf7f0856..c49758bad8 100644
--- a/modules/video_output/xcb/x11.c
+++ b/modules/video_output/xcb/x11.c
@@ -72,6 +72,8 @@ struct vout_display_sys_t
     uint8_t depth; /* useful bits per pixel */
 
     picture_pool_t *pool; /* picture pool */
+    vout_display_place_t place;
+    video_format_t fmt;
 };
 
 static picture_pool_t *Pool (vout_display_t *, unsigned);
@@ -102,6 +104,8 @@ static const xcb_depth_t *FindDepth (const xcb_screen_t *scr,
 static int Open (vlc_object_t *obj)
 {
     vout_display_t *vd = (vout_display_t *)obj;
+    const vout_display_cfg_t *cfg = vd->cfg;
+    video_format_t *fmtp = &vd->fmt;
     vout_display_sys_t *sys = malloc (sizeof (*sys));
     if (unlikely(sys == NULL))
         return VLC_ENOMEM;
@@ -112,7 +116,7 @@ static int Open (vlc_object_t *obj)
     /* Get window, connect to X server */
     xcb_connection_t *conn;
     const xcb_screen_t *scr;
-    if (vlc_xcb_parent_Create(vd, &conn, &scr) == NULL)
+    if (vlc_xcb_parent_Create(vd, cfg, &conn, &scr) == NULL)
     {
         free (sys);
         return VLC_EGENERIC;
@@ -134,7 +138,7 @@ static int Open (vlc_object_t *obj)
         if (fmt->depth <= sys->depth)
             continue; /* no better than earlier format */
 
-        video_format_ApplyRotation(&fmt_pic, &vd->fmt);
+        video_format_ApplyRotation(&fmt_pic, fmtp);
 
         /* Check that the pixmap format is supported by VLC. */
         switch (fmt->depth)
@@ -269,9 +273,9 @@ found_format:;
 
         xcb_create_pixmap (conn, sys->depth, pixmap, scr->root, 1, 1);
         c = xcb_create_window_checked (conn, sys->depth, sys->window,
-                                       vd->cfg->window->handle.xid, 0, 0,
-                                       vd->cfg->display.width,
-                                       vd->cfg->display.height, 0,
+                                       cfg->window->handle.xid, 0, 0,
+                                       cfg->display.width,
+                                       cfg->display.height, 0,
                                        XCB_WINDOW_CLASS_INPUT_OUTPUT,
                                        vid, mask, values);
         xcb_map_window (conn, sys->window);
@@ -294,10 +298,12 @@ found_format:;
     else
         sys->seg_base = 0;
 
+    vout_display_PlacePicture (&sys->place, &vd->source, cfg, false);
+
+    sys->fmt = *fmtp = fmt_pic;
     /* Setup vout_display_t once everything is fine */
     vd->info.has_pictures_invalid = true;
 
-    vd->fmt = fmt_pic;
     vd->pool = Pool;
     vd->prepare = NULL;
     vd->display = Display;
@@ -337,12 +343,8 @@ static picture_pool_t *Pool (vout_display_t *vd, unsigned requested_count)
     if (sys->pool)
         return sys->pool;
 
-    vout_display_place_t place;
-
-    vout_display_PlacePicture (&place, &vd->source, vd->cfg, false);
-
     /* */
-    const uint32_t values[] = { place.x, place.y, place.width, place.height };
+    const uint32_t values[] = { sys->place.x, sys->place.y, sys->place.width, sys->place.height };
     xcb_configure_window (sys->conn, sys->window,
                           XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
                           XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
@@ -407,21 +409,21 @@ static void Display (vout_display_t *vd, picture_t *pic)
         ck = xcb_shm_put_image_checked (sys->conn, sys->window, sys->gc,
           /* real width */ pic->p->i_pitch / pic->p->i_pixel_pitch,
          /* real height */ pic->p->i_lines,
-                   /* x */ vd->fmt.i_x_offset,
-                   /* y */ vd->fmt.i_y_offset,
-               /* width */ vd->fmt.i_visible_width,
-              /* height */ vd->fmt.i_visible_height,
+                   /* x */ sys->fmt.i_x_offset,
+                   /* y */ sys->fmt.i_y_offset,
+               /* width */ sys->fmt.i_visible_width,
+              /* height */ sys->fmt.i_visible_height,
                            0, 0, sys->depth, XCB_IMAGE_FORMAT_Z_PIXMAP,
                            0, segment, 0);
     else
     {
-        const size_t offset = vd->fmt.i_y_offset * pic->p->i_pitch;
-        const unsigned lines = pic->p->i_lines - vd->fmt.i_y_offset;
+        const size_t offset = sys->fmt.i_y_offset * pic->p->i_pitch;
+        const unsigned lines = pic->p->i_lines - sys->fmt.i_y_offset;
 
         ck = xcb_put_image_checked (sys->conn, XCB_IMAGE_FORMAT_Z_PIXMAP,
                        sys->window, sys->gc,
                        pic->p->i_pitch / pic->p->i_pixel_pitch,
-                       lines, -vd->fmt.i_x_offset, 0, 0, sys->depth,
+                       lines, -sys->fmt.i_x_offset, 0, 0, sys->depth,
                        pic->p->i_pitch * lines, pic->p->p_pixels + offset);
     }
 
@@ -451,19 +453,17 @@ static int Control (vout_display_t *vd, int query, va_list ap)
     {
         const vout_display_cfg_t *p_cfg =
             va_arg (ap, const vout_display_cfg_t *);
-        vout_display_place_t place;
-
-        vout_display_PlacePicture (&place, &vd->source, p_cfg, false);
+        vout_display_PlacePicture (&sys->place, &vd->source, p_cfg, false);
 
-        if (place.width  != vd->fmt.i_visible_width ||
-            place.height != vd->fmt.i_visible_height)
+        if (sys->place.width  != sys->fmt.i_visible_width ||
+            sys->place.height != sys->fmt.i_visible_height)
         {
             vout_display_SendEventPicturesInvalid (vd);
             return VLC_SUCCESS;
         }
 
         /* Move the picture within the window */
-        const uint32_t values[] = { place.x, place.y };
+        const uint32_t values[] = { sys->place.x, sys->place.y };
         xcb_configure_window (sys->conn, sys->window,
                               XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
                               values);
@@ -480,22 +480,24 @@ static int Control (vout_display_t *vd, int query, va_list ap)
 
     case VOUT_DISPLAY_RESET_PICTURES:
     {
-        ResetPictures (vd);
+        const vout_display_cfg_t *cfg = va_arg(ap, const vout_display_cfg_t *);
+        video_format_t *fmt = va_arg(ap, video_format_t *);
 
-        vout_display_place_t place;
-        vout_display_PlacePicture (&place, &vd->source, vd->cfg, false);
+        ResetPictures (vd);
 
         video_format_t src;
         video_format_ApplyRotation(&src, &vd->source);
 
-        vd->fmt.i_width  = src.i_width  * place.width / src.i_visible_width;
-        vd->fmt.i_height = src.i_height * place.height / src.i_visible_height;
+        fmt->i_width  = src.i_width  * sys->place.width / src.i_visible_width;
+        fmt->i_height = src.i_height * sys->place.height / src.i_visible_height;
 
-        vd->fmt.i_visible_width  = place.width;
-        vd->fmt.i_visible_height = place.height;
-        vd->fmt.i_x_offset = src.i_x_offset * place.width / src.i_visible_width;
-        vd->fmt.i_y_offset = src.i_y_offset * place.height / src.i_visible_height;
+        fmt->i_visible_width  = sys->place.width;
+        fmt->i_visible_height = sys->place.height;
+        fmt->i_x_offset = src.i_x_offset * sys->place.width / src.i_visible_width;
+        fmt->i_y_offset = src.i_y_offset * sys->place.height / src.i_visible_height;
+        sys->fmt = *fmt;
         return VLC_SUCCESS;
+        (void) cfg;
     }
 
     default:
diff --git a/modules/video_output/xcb/xvideo.c b/modules/video_output/xcb/xvideo.c
index 394144cb20..4e220c8f0d 100644
--- a/modules/video_output/xcb/xvideo.c
+++ b/modules/video_output/xcb/xvideo.c
@@ -85,8 +85,6 @@ struct vout_display_sys_t
     xcb_gcontext_t gc;   /* context to put images */
     xcb_xv_port_t port;  /* XVideo port */
     uint32_t id;         /* XVideo format */
-    uint16_t width;      /* display width */
-    uint16_t height;     /* display height */
     uint32_t data_size;  /* picture byte size (for non-SHM) */
     bool     swap_uv;    /* U/V pointer must be swapped in a picture */
     bool shm;            /* whether to use MIT-SHM */
@@ -94,6 +92,7 @@ struct vout_display_sys_t
 
     xcb_xv_query_image_attributes_reply_t *att;
     picture_pool_t *pool; /* picture pool */
+    vout_display_place_t place;
 };
 
 static picture_pool_t *Pool (vout_display_t *, unsigned);
@@ -350,6 +349,8 @@ FindFormat (vlc_object_t *obj, xcb_connection_t *conn, video_format_t *fmt,
 static int Open (vlc_object_t *obj)
 {
     vout_display_t *vd = (vout_display_t *)obj;
+    const vout_display_cfg_t *cfg = vd->cfg;
+    video_format_t *fmtp = &vd->fmt;
     vout_display_sys_t *p_sys;
 
     {   /* NOTE: Reject hardware surface formats. Blending would break. */
@@ -368,7 +369,7 @@ static int Open (vlc_object_t *obj)
     /* Connect to X */
     xcb_connection_t *conn;
     const xcb_screen_t *screen;
-    if (vlc_xcb_parent_Create(vd, &conn, &screen) == NULL)
+    if (vlc_xcb_parent_Create(vd, cfg, &conn, &screen) == NULL)
     {
         free (p_sys);
         return VLC_EGENERIC;
@@ -390,7 +391,7 @@ static int Open (vlc_object_t *obj)
     /* Cache adaptors infos */
     xcb_xv_query_adaptors_reply_t *adaptors =
         xcb_xv_query_adaptors_reply (conn,
-            xcb_xv_query_adaptors (conn, vd->cfg->window->handle.xid), NULL);
+            xcb_xv_query_adaptors (conn, cfg->window->handle.xid), NULL);
     if (adaptors == NULL)
         goto error;
 
@@ -399,12 +400,9 @@ static int Open (vlc_object_t *obj)
 
     /* */
     video_format_t fmt;
-    vout_display_place_t place;
 
     p_sys->port = 0;
-    vout_display_PlacePicture (&place, &vd->source, vd->cfg, false);
-    p_sys->width  = place.width;
-    p_sys->height = place.height;
+    vout_display_PlacePicture (&p_sys->place, &vd->source, cfg, false);
 
     xcb_xv_adaptor_info_iterator_t it;
     for (it = xcb_xv_query_adaptors_info_iterator (adaptors);
@@ -421,7 +419,7 @@ static int Open (vlc_object_t *obj)
             continue;
 
         /* Look for an image format */
-        video_format_ApplyRotation(&fmt, &vd->fmt);
+        video_format_ApplyRotation(&fmt, fmtp);
         free (p_sys->att);
         p_sys->att = FindFormat (obj, conn, &fmt, a, &p_sys->id);
         if (p_sys->att == NULL) /* No acceptable image formats */
@@ -486,9 +484,9 @@ static int Open (vlc_object_t *obj)
 
             xcb_create_pixmap (conn, f->depth, pixmap, screen->root, 1, 1);
             c = xcb_create_window_checked (conn, f->depth, p_sys->window,
-                 vd->cfg->window->handle.xid, place.x, place.y,
-                 place.width, place.height, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
-                 f->visual, mask, list);
+                 cfg->window->handle.xid, p_sys->place.x, p_sys->place.y,
+                 p_sys->place.width, p_sys->place.height, 0,
+                 XCB_WINDOW_CLASS_INPUT_OUTPUT, f->visual, mask, list);
             xcb_map_window (conn, p_sys->window);
 
             if (!vlc_xcb_error_Check(vd, conn, "cannot create X11 window", c))
@@ -554,10 +552,10 @@ static int Open (vlc_object_t *obj)
 
     /* Setup vout_display_t once everything is fine */
     p_sys->swap_uv = vlc_fourcc_AreUVPlanesSwapped (fmt.i_chroma,
-                                                    vd->fmt.i_chroma);
+                                                    fmtp->i_chroma);
     if (p_sys->swap_uv)
-        fmt.i_chroma = vd->fmt.i_chroma;
-    vd->fmt = fmt;
+        fmt.i_chroma = fmtp->i_chroma;
+    *fmtp = fmt;
     vd->info = info;
 
     vd->pool = Pool;
@@ -679,7 +677,7 @@ static void Display (vout_display_t *vd, picture_t *pic)
                               p_sys->window, p_sys->gc, segment, p_sys->id, 0,
                    /* Src: */ fmt.i_x_offset, fmt.i_y_offset,
                               fmt.i_visible_width, fmt.i_visible_height,
-                   /* Dst: */ 0, 0, p_sys->width, p_sys->height,
+                   /* Dst: */ 0, 0, p_sys->place.width, p_sys->place.height,
                 /* Memory: */ pic->p->i_pitch / pic->p->i_pixel_pitch,
                               pic->p->i_lines, false);
     else
@@ -687,7 +685,7 @@ static void Display (vout_display_t *vd, picture_t *pic)
                           p_sys->gc, p_sys->id,
                           fmt.i_x_offset, fmt.i_y_offset,
                           fmt.i_visible_width, fmt.i_visible_height,
-                          0, 0, p_sys->width, p_sys->height,
+                          0, 0, p_sys->place.width, p_sys->place.height,
                           pic->p->i_pitch / pic->p->i_pixel_pitch,
                           pic->p->i_lines,
                           p_sys->data_size, pic->p->p_pixels);
@@ -713,26 +711,13 @@ static int Control (vout_display_t *vd, int query, va_list ap)
     case VOUT_DISPLAY_CHANGE_SOURCE_ASPECT:
     case VOUT_DISPLAY_CHANGE_SOURCE_CROP:
     {
-        const vout_display_cfg_t *cfg;
-
-        if (query == VOUT_DISPLAY_CHANGE_SOURCE_ASPECT
-         || query == VOUT_DISPLAY_CHANGE_SOURCE_CROP)
-        {
-            cfg = vd->cfg;
-        }
-        else
-        {
-            cfg = va_arg(ap, const vout_display_cfg_t *);
-        }
-
-        vout_display_place_t place;
-        vout_display_PlacePicture (&place, &vd->source, cfg, false);
-        p_sys->width  = place.width;
-        p_sys->height = place.height;
+        vout_display_PlacePicture (&p_sys->place, &vd->source,
+                                   va_arg(ap, const vout_display_cfg_t *),
+                                   false);
 
         /* Move the picture within the window */
-        const uint32_t values[] = { place.x, place.y,
-                                    place.width, place.height, };
+        const uint32_t values[] = { p_sys->place.x, p_sys->place.y,
+                                    p_sys->place.width, p_sys->place.height, };
         xcb_configure_window (p_sys->conn, p_sys->window,
                               XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y
                             | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
-- 
2.19.1



More information about the vlc-devel mailing list