[vlc-devel] [PATCH 01/41] vout:win32: isolate the window placement fields in a structure

Steve Lhomme robux4 at ycbcr.xyz
Fri Mar 22 16:13:39 CET 2019


These fields are needed even when there's no window to handle. For example if
the display dimensions/position are used for external rendering.
---
 modules/video_output/win32/common.c     | 36 ++++++++---------
 modules/video_output/win32/common.h     | 34 +++++++++-------
 modules/video_output/win32/direct3d11.c | 54 ++++++++++++-------------
 modules/video_output/win32/direct3d9.c  | 22 +++++-----
 modules/video_output/win32/glwin32.c    |  4 +-
 modules/video_output/win32/wingdi.c     | 10 ++---
 6 files changed, 83 insertions(+), 77 deletions(-)

diff --git a/modules/video_output/win32/common.c b/modules/video_output/win32/common.c
index 68f0ca93d4..18b1ffdfbf 100644
--- a/modules/video_output/win32/common.c
+++ b/modules/video_output/win32/common.c
@@ -76,25 +76,25 @@ int CommonInit(vout_display_t *vd, bool b_windowless, const vout_display_cfg_t *
     sys->hvideownd = NULL;
     sys->hparent   = NULL;
     sys->hfswnd    = NULL;
-    sys->changes   = 0;
+    sys->area.changes   = 0;
     sys->b_windowless = b_windowless;
     sys->is_first_display = true;
     sys->is_on_top        = false;
 
-    sys->pf_GetPictureWidth  = GetPictureWidth;
-    sys->pf_GetPictureHeight = GetPictureHeight;
+    sys->area.pf_GetPictureWidth  = GetPictureWidth;
+    sys->area.pf_GetPictureHeight = GetPictureHeight;
 
 #if !defined(NDEBUG) && defined(HAVE_DXGIDEBUG_H)
     sys->dxgidebug_dll = LoadLibrary(TEXT("DXGIDEBUG.DLL"));
 #endif
 #if !VLC_WINSTORE_APP
     sys->pf_GetRect = GetRect;
-    SetRectEmpty(&sys->rect_display);
+    SetRectEmpty(&sys->area.rect_display);
     SetRectEmpty(&sys->rect_parent);
 
     var_Create(vd, "disable-screensaver", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
 
-    sys->vdcfg = *vdcfg;
+    sys->area.vdcfg = *vdcfg;
 
     if (b_windowless)
         return VLC_SUCCESS;
@@ -142,16 +142,16 @@ void UpdateRects(vout_display_t *vd, bool is_forced)
 {
     vout_display_sys_t *sys = vd->sys;
     const video_format_t *source = &vd->source;
-#define rect_src sys->rect_src
-#define rect_src_clipped sys->rect_src_clipped
-#define rect_dest sys->rect_dest
-#define rect_dest_clipped sys->rect_dest_clipped
+#define rect_src sys->area.rect_src
+#define rect_src_clipped sys->area.rect_src_clipped
+#define rect_dest sys->area.rect_dest
+#define rect_dest_clipped sys->area.rect_dest_clipped
 
     RECT  rect;
     POINT point = { 0 };
 
     /* */
-    const vout_display_cfg_t *cfg = &sys->vdcfg;
+    const vout_display_cfg_t *cfg = &sys->area.vdcfg;
 
     /* Retrieve the window size */
     if (sys->b_windowless)
@@ -177,9 +177,9 @@ void UpdateRects(vout_display_t *vd, bool is_forced)
     bool is_resized;
 #if VLC_WINSTORE_APP
     has_moved = false;
-    is_resized = rect.right != (sys->rect_display.right - sys->rect_display.left) ||
-        rect.bottom != (sys->rect_display.bottom - sys->rect_display.top);
-    sys->rect_display = rect;
+    is_resized = rect.right != (sys->sys.rect_display.right - sys->sys.rect_display.left) ||
+        rect.bottom != (sys->sys.rect_display.bottom - sys->sys.rect_display.top);
+    sys->sys.rect_display = rect;
 #else
     if (sys->b_windowless)
     {
@@ -249,8 +249,8 @@ void UpdateRects(vout_display_t *vd, bool is_forced)
     /* src image dimensions */
     rect_src.left = 0;
     rect_src.top = 0;
-    rect_src.right = sys->pf_GetPictureWidth(vd);
-    rect_src.bottom = sys->pf_GetPictureHeight(vd);
+    rect_src.right = sys->area.pf_GetPictureWidth(vd);
+    rect_src.bottom = sys->area.pf_GetPictureHeight(vd);
 
     /* Clip the source image */
     rect_src_clipped.left = source->i_x_offset +
@@ -295,7 +295,7 @@ void UpdateRects(vout_display_t *vd, bool is_forced)
 
 exit:
     /* Signal the change in size/position */
-    sys->changes |= DX_POSITION_CHANGE;
+    sys->area.changes |= DX_POSITION_CHANGE;
 
 #undef rect_src
 #undef rect_src_clipped
@@ -546,7 +546,7 @@ int CommonControl(vout_display_t *vd, int query, va_list args)
     case VOUT_DISPLAY_CHANGE_SOURCE_ASPECT:
     case VOUT_DISPLAY_CHANGE_SOURCE_CROP: {
         const vout_display_cfg_t *cfg = va_arg(args, const vout_display_cfg_t *);
-        sys->vdcfg = *cfg;
+        sys->area.vdcfg = *cfg;
         UpdateRects(vd, true);
         return VLC_SUCCESS;
     }
@@ -567,7 +567,7 @@ int CommonControl(vout_display_t *vd, int query, va_list args)
                          rect_window.right - rect_window.left,
                          rect_window.bottom - rect_window.top, SWP_NOMOVE);
         }
-        sys->vdcfg = *cfg;
+        sys->area.vdcfg = *cfg;
         UpdateRects(vd, false);
         return VLC_SUCCESS;
     }
diff --git a/modules/video_output/win32/common.h b/modules/video_output/win32/common.h
index ae22061ac4..d6befddfef 100644
--- a/modules/video_output/win32/common.h
+++ b/modules/video_output/win32/common.h
@@ -27,6 +27,25 @@
  *****************************************************************************/
 #include "events.h"
 
+typedef struct display_win32_area_t
+{
+    /* size of the display */
+    RECT         rect_display;
+
+    unsigned changes;        /* changes made to the video display */
+
+    /* Coordinates of src and dest images (used when blitting to display) */
+    RECT         rect_src;
+    RECT         rect_src_clipped;
+    RECT         rect_dest;
+    RECT         rect_dest_clipped;
+
+    vout_display_cfg_t vdcfg;
+
+    unsigned int (*pf_GetPictureWidth) (const vout_display_t *);
+    unsigned int (*pf_GetPictureHeight)(const vout_display_t *);
+} display_win32_area_t;
+
 /*****************************************************************************
  * vout_sys_t: video output method descriptor
  *****************************************************************************
@@ -47,9 +66,6 @@ typedef struct vout_display_sys_win32_t
     HWND                 hparent;             /* Handle of the parent window */
     HWND                 hfswnd;          /* Handle of the fullscreen window */
 
-    /* size of the display */
-    RECT         rect_display;
-
     /* size of the overall window (including black bands) */
     RECT         rect_parent;
 
@@ -57,25 +73,15 @@ typedef struct vout_display_sys_win32_t
     HINSTANCE     dxgidebug_dll;
 # endif
 
-    unsigned changes;        /* changes made to the video display */
-
     /* Misc */
     bool is_first_display;
     bool is_on_top;
 
-    /* Coordinates of src and dest images (used when blitting to display) */
-    RECT         rect_src;
-    RECT         rect_src_clipped;
-    RECT         rect_dest;
-    RECT         rect_dest_clipped;
-
-    vout_display_cfg_t vdcfg;
+    display_win32_area_t   area;
 
     bool use_desktop;     /* show video on desktop window ? */
 
     bool (*pf_GetRect)(const struct vout_display_sys_win32_t *p_sys, RECT *out);
-    unsigned int (*pf_GetPictureWidth) (const vout_display_t *);
-    unsigned int (*pf_GetPictureHeight)(const vout_display_t *);
 } vout_display_sys_win32_t;
 
 
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index f2e28dd8d1..23a641c615 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -193,7 +193,7 @@ static HRESULT UpdateBackBuffer(vout_display_t *vd)
 #if VLC_WINSTORE_APP
     if (!GetRect(&sys->sys, &rect))
 #endif
-        rect = sys->sys.rect_dest_clipped;
+        rect = sys->sys.area.rect_dest_clipped;
     uint32_t i_width = RECTWidth(rect);
     uint32_t i_height = RECTHeight(rect);
 
@@ -206,8 +206,8 @@ static HRESULT UpdateBackBuffer(vout_display_t *vd)
 static void UpdateSize(vout_display_t *vd)
 {
     vout_display_sys_t *sys = vd->sys;
-    msg_Dbg(vd, "Detected size change %dx%d", RECTWidth(sys->sys.rect_dest_clipped),
-            RECTHeight(sys->sys.rect_dest_clipped));
+    msg_Dbg(vd, "Detected size change %dx%d", RECTWidth(sys->sys.area.rect_dest_clipped),
+            RECTHeight(sys->sys.area.rect_dest_clipped));
 
     UpdateBackBuffer(vd);
 
@@ -215,7 +215,7 @@ static void UpdateSize(vout_display_t *vd)
 
     UpdatePicQuadPosition(vd);
 
-    D3D11_UpdateQuadPosition(vd, &sys->d3d_dev, &sys->picQuad, &sys->sys.rect_src_clipped,
+    D3D11_UpdateQuadPosition(vd, &sys->d3d_dev, &sys->picQuad, &sys->sys.area.rect_src_clipped,
                              vd->source.orientation);
 
     d3d11_device_unlock( &sys->d3d_dev );
@@ -224,15 +224,15 @@ static void UpdateSize(vout_display_t *vd)
 static void Manage(vout_display_t *vd)
 {
     vout_display_sys_t *sys = vd->sys;
-    RECT before_src_clipped  = sys->sys.rect_src_clipped;
-    RECT before_dest_clipped = sys->sys.rect_dest_clipped;
-    RECT before_dest         = sys->sys.rect_dest;
+    RECT before_src_clipped  = sys->sys.area.rect_src_clipped;
+    RECT before_dest_clipped = sys->sys.area.rect_dest_clipped;
+    RECT before_dest         = sys->sys.area.rect_dest;
 
     CommonManage(vd);
 
-    if (!RectEquals(&before_src_clipped, &sys->sys.rect_src_clipped) ||
-        !RectEquals(&before_dest_clipped, &sys->sys.rect_dest_clipped) ||
-        !RectEquals(&before_dest, &sys->sys.rect_dest))
+    if (!RectEquals(&before_src_clipped, &sys->sys.area.rect_src_clipped) ||
+        !RectEquals(&before_dest_clipped, &sys->sys.area.rect_dest_clipped) ||
+        !RectEquals(&before_dest, &sys->sys.area.rect_dest))
     {
         UpdateSize(vd);
     }
@@ -500,8 +500,8 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
 #if VLC_WINSTORE_APP
     sys->sys.pf_GetRect = GetRect;
 #endif
-    sys->sys.pf_GetPictureWidth  = GetPictureWidth;
-    sys->sys.pf_GetPictureHeight = GetPictureHeight;
+    sys->sys.area.pf_GetPictureWidth  = GetPictureWidth;
+    sys->sys.area.pf_GetPictureHeight = GetPictureHeight;
 
     if (!sys->swapCb || !sys->starRenderCb || !sys->endRenderCb || !sys->resizeCb)
     {
@@ -732,7 +732,7 @@ static void SetQuadVSProjection(vout_display_t *vd, d3d_quad_t *quad, const vlc_
          f_fovx < -0.001f )
         return;
 
-    float f_sar = (float) sys->sys.vdcfg.display.width / sys->sys.vdcfg.display.height;
+    float f_sar = (float) sys->sys.area.vdcfg.display.width / sys->sys.area.vdcfg.display.height;
     float f_fovy = UpdateFOVy(f_fovx, f_sar);
     float f_z = UpdateZ(f_fovx, f_fovy);
 
@@ -754,9 +754,9 @@ static void SetQuadVSProjection(vout_display_t *vd, d3d_quad_t *quad, const vlc_
 static int Control(vout_display_t *vd, int query, va_list args)
 {
     vout_display_sys_t *sys = vd->sys;
-    RECT before_src_clipped  = sys->sys.rect_src_clipped;
-    RECT before_dest_clipped = sys->sys.rect_dest_clipped;
-    RECT before_dest         = sys->sys.rect_dest;
+    RECT before_src_clipped  = sys->sys.area.rect_src_clipped;
+    RECT before_dest_clipped = sys->sys.area.rect_dest_clipped;
+    RECT before_dest         = sys->sys.area.rect_dest;
 
     int res = CommonControl( vd, query, args );
 
@@ -770,9 +770,9 @@ static int Control(vout_display_t *vd, int query, va_list args)
         }
     }
 
-    if (!RectEquals(&before_src_clipped,  &sys->sys.rect_src_clipped) ||
-        !RectEquals(&before_dest_clipped, &sys->sys.rect_dest_clipped) ||
-        !RectEquals(&before_dest,         &sys->sys.rect_dest) )
+    if (!RectEquals(&before_src_clipped,  &sys->sys.area.rect_src_clipped) ||
+        !RectEquals(&before_dest_clipped, &sys->sys.area.rect_dest_clipped) ||
+        !RectEquals(&before_dest,         &sys->sys.area.rect_dest) )
     {
         UpdateSize(vd);
     }
@@ -1380,9 +1380,9 @@ static void UpdatePicQuadPosition(vout_display_t *vd)
 {
     vout_display_sys_t *sys = vd->sys;
 
-    D3D11_UpdateViewport( &sys->picQuad, &sys->sys.rect_dest_clipped, sys->display.pixelFormat );
+    D3D11_UpdateViewport( &sys->picQuad, &sys->sys.area.rect_dest_clipped, sys->display.pixelFormat );
 
-    SetQuadVSProjection(vd, &sys->picQuad, &sys->sys.vdcfg.viewpoint);
+    SetQuadVSProjection(vd, &sys->picQuad, &sys->sys.area.vdcfg.viewpoint);
 
 #ifndef NDEBUG
     msg_Dbg( vd, "picQuad position (%.02f,%.02f) %.02fx%.02f",
@@ -1485,7 +1485,7 @@ static int Direct3D11CreateFormatResources(vout_display_t *vd, const video_forma
        return VLC_EGENERIC;
     }
 
-    if (D3D11_SetupQuad( vd, &sys->d3d_dev, &surface_fmt, &sys->picQuad, &sys->display, &sys->sys.rect_src_clipped,
+    if (D3D11_SetupQuad( vd, &sys->d3d_dev, &surface_fmt, &sys->picQuad, &sys->display, &sys->sys.area.rect_src_clipped,
                    vd->source.orientation ) != VLC_SUCCESS) {
         msg_Err(vd, "Could not Create the main quad picture.");
         return VLC_EGENERIC;
@@ -1493,7 +1493,7 @@ static int Direct3D11CreateFormatResources(vout_display_t *vd, const video_forma
 
     if ( vd->source.projection_mode == PROJECTION_MODE_EQUIRECTANGULAR ||
          vd->source.projection_mode == PROJECTION_MODE_CUBEMAP_LAYOUT_STANDARD )
-        SetQuadVSProjection( vd, &sys->picQuad, &sys->sys.vdcfg.viewpoint );
+        SetQuadVSProjection( vd, &sys->picQuad, &sys->sys.area.vdcfg.viewpoint );
 
     if (is_d3d11_opaque(fmt->i_chroma)) {
         ID3D10Multithread *pMultithread;
@@ -1815,10 +1815,10 @@ static int Direct3D11MapSubpicture(vout_display_t *vd, int *subpicture_region_co
         d3d_quad_t *quad = (d3d_quad_t *) quad_picture->p_sys;
 
         RECT spuViewport;
-        spuViewport.left   = sys->sys.rect_dest.left + (FLOAT) r->i_x * RECTWidth(sys->sys.rect_dest)  / subpicture->i_original_picture_width;
-        spuViewport.top    = sys->sys.rect_dest.top  + (FLOAT) r->i_y * RECTHeight(sys->sys.rect_dest) / subpicture->i_original_picture_height;
-        spuViewport.right  = sys->sys.rect_dest.left + (FLOAT) (r->i_x + r->fmt.i_visible_width)  * RECTWidth(sys->sys.rect_dest)  / subpicture->i_original_picture_width;
-        spuViewport.bottom = sys->sys.rect_dest.top  + (FLOAT) (r->i_y + r->fmt.i_visible_height) * RECTHeight(sys->sys.rect_dest) / subpicture->i_original_picture_height;
+        spuViewport.left   = sys->sys.area.rect_dest.left + (FLOAT) r->i_x * RECTWidth(sys->sys.area.rect_dest)  / subpicture->i_original_picture_width;
+        spuViewport.top    = sys->sys.area.rect_dest.top  + (FLOAT) r->i_y * RECTHeight(sys->sys.area.rect_dest) / subpicture->i_original_picture_height;
+        spuViewport.right  = sys->sys.area.rect_dest.left + (FLOAT) (r->i_x + r->fmt.i_visible_width)  * RECTWidth(sys->sys.area.rect_dest)  / subpicture->i_original_picture_width;
+        spuViewport.bottom = sys->sys.area.rect_dest.top  + (FLOAT) (r->i_y + r->fmt.i_visible_height) * RECTHeight(sys->sys.area.rect_dest) / subpicture->i_original_picture_height;
 
         if (r->zoom_h.num != 0 && r->zoom_h.den != 0)
         {
diff --git a/modules/video_output/win32/direct3d9.c b/modules/video_output/win32/direct3d9.c
index 89c36038bd..b730a5abef 100644
--- a/modules/video_output/win32/direct3d9.c
+++ b/modules/video_output/win32/direct3d9.c
@@ -448,7 +448,7 @@ static int Direct3D9ImportPicture(vout_display_t *vd,
 
     /* Copy picture surface into texture surface
      * color space conversion happen here */
-    RECT copy_rect = sys->sys.rect_src_clipped;
+    RECT copy_rect = sys->sys.area.rect_src_clipped;
     // On nVidia & AMD, StretchRect will fail if the visible size isn't even.
     // When copying the entire buffer, the margin end up being blended in the actual picture
     // on nVidia (regardless of even/odd dimensions)
@@ -467,8 +467,8 @@ static int Direct3D9ImportPicture(vout_display_t *vd,
 
     /* */
     region->texture = sys->sceneTexture;
-    Direct3D9SetupVertices(region->vertex, &vd->sys->sys.rect_src, &vd->sys->sys.rect_src_clipped,
-                           &vd->sys->sys.rect_dest_clipped, 255, vd->source.orientation);
+    Direct3D9SetupVertices(region->vertex, &vd->sys->sys.area.rect_src, &vd->sys->sys.area.rect_src_clipped,
+                           &vd->sys->sys.area.rect_dest_clipped, 255, vd->source.orientation);
     return VLC_SUCCESS;
 }
 
@@ -893,7 +893,7 @@ static void UpdateDesktopMode(vout_display_t *vd)
 
     if (sys->sys.use_desktop) {
         /* Save non-desktop state */
-        sys->desktop_save.is_fullscreen = sys->sys.vdcfg.is_fullscreen;
+        sys->desktop_save.is_fullscreen = sys->sys.area.vdcfg.is_fullscreen;
         sys->desktop_save.is_on_top     = sys->sys.is_on_top;
 
         /* Disable fullscreen/on_top while using desktop */
@@ -923,7 +923,7 @@ static void Manage (vout_display_t *vd)
         UpdateDesktopMode(vd);
 
     /* Position Change */
-    if (sys->sys.changes & DX_POSITION_CHANGE) {
+    if (sys->sys.area.changes & DX_POSITION_CHANGE) {
 #if 0 /* need that when bicubic filter is available */
         RECT rect;
         UINT width, height;
@@ -941,7 +941,7 @@ static void Manage (vout_display_t *vd)
         }
 #endif
         sys->clear_scene = true;
-        sys->sys.changes &= ~DX_POSITION_CHANGE;
+        sys->sys.area.changes &= ~DX_POSITION_CHANGE;
     }
 }
 
@@ -1038,8 +1038,8 @@ static void Direct3D9ImportSubpicture(vout_display_t *vd,
             msg_Err(vd, "Failed to lock the texture");
         }
 
-        /* Map the subpicture to sys->sys.rect_dest */
-        const RECT video = sys->sys.rect_dest;
+        /* Map the subpicture to sys->sys.sys.rect_dest */
+        const RECT video = sys->sys.area.rect_dest;
         const float scale_w = (float)(video.right  - video.left) / subpicture->i_original_picture_width;
         const float scale_h = (float)(video.bottom - video.top)  / subpicture->i_original_picture_height;
 
@@ -1315,8 +1315,8 @@ static void Swap(void *opaque)
 
     // Present the back buffer contents to the display
     // No stretching should happen here !
-    const RECT src = sys->sys.rect_dest_clipped;
-    const RECT dst = sys->sys.rect_dest_clipped;
+    const RECT src = sys->sys.area.rect_dest_clipped;
+    const RECT dst = sys->sys.area.rect_dest_clipped;
 
     HRESULT hr;
     if (sys->hd3d.use_ex) {
@@ -1470,7 +1470,7 @@ static int Direct3D9Open(vout_display_t *vd, video_format_t *fmt,
 
     const d3d9_device_t *p_d3d9_dev = &sys->d3d_dev;
     /* */
-    RECT *display = &vd->sys->sys.rect_display;
+    RECT *display = &vd->sys->sys.area.rect_display;
     display->left   = 0;
     display->top    = 0;
     display->right  = p_d3d9_dev->pp.BackBufferWidth;
diff --git a/modules/video_output/win32/glwin32.c b/modules/video_output/win32/glwin32.c
index 7d5cc3a080..ddeb814118 100644
--- a/modules/video_output/win32/glwin32.c
+++ b/modules/video_output/win32/glwin32.c
@@ -245,8 +245,8 @@ static void Manage (vout_display_t *vd)
 
     CommonManage(vd);
 
-    const int width  = sys->sys.rect_dest.right  - sys->sys.rect_dest.left;
-    const int height = sys->sys.rect_dest.bottom - sys->sys.rect_dest.top;
+    const int width  = sys->sys.area.rect_dest.right  - sys->sys.area.rect_dest.left;
+    const int height = sys->sys.area.rect_dest.bottom - sys->sys.area.rect_dest.top;
     vlc_gl_Resize (sys->gl, width, height);
     if (vlc_gl_MakeCurrent (sys->gl) != VLC_SUCCESS)
         return;
diff --git a/modules/video_output/win32/wingdi.c b/modules/video_output/win32/wingdi.c
index 30a4657344..cd04e30b09 100644
--- a/modules/video_output/win32/wingdi.c
+++ b/modules/video_output/win32/wingdi.c
@@ -145,10 +145,10 @@ static void Display(vout_display_t *vd, picture_t *picture)
     vout_display_sys_t *sys = vd->sys;
     VLC_UNUSED(picture);
 
-#define rect_src vd->sys->rect_src
-#define rect_src_clipped vd->sys->sys.rect_src_clipped
-#define rect_dest vd->sys->sys.rect_dest
-#define rect_dest_clipped vd->sys->sys.rect_dest_clipped
+#define rect_src sys->area.rect_src
+#define rect_src_clipped sys->sys.area.rect_src_clipped
+#define rect_dest sys->sys.area.rect_dest
+#define rect_dest_clipped sys->sys.area.rect_dest_clipped
     RECT rect_dst = rect_dest_clipped;
     HDC hdc = GetDC(sys->sys.hvideownd);
 
@@ -188,7 +188,7 @@ static int Init(vout_display_t *vd, video_format_t *fmt)
     vout_display_sys_t *sys = vd->sys;
 
     /* */
-    RECT *display = &sys->sys.rect_display;
+    RECT *display = &sys->sys.area.rect_display;
     display->left   = 0;
     display->top    = 0;
     display->right  = GetSystemMetrics(SM_CXSCREEN);;
-- 
2.17.1



More information about the vlc-devel mailing list