[vlc-devel] [PATCH 41/41] vout:win32: rework the callback to get the display dimensions

Steve Lhomme robux4 at ycbcr.xyz
Fri Mar 22 16:14:19 CET 2019


We don't need a rect for that.
---
 modules/video_output/win32/common.c     | 63 ++++++++++++++++---------
 modules/video_output/win32/common.h     |  5 +-
 modules/video_output/win32/direct3d11.c | 23 ++++-----
 3 files changed, 53 insertions(+), 38 deletions(-)

diff --git a/modules/video_output/win32/common.c b/modules/video_output/win32/common.c
index e59a1f95f6..26e818fd13 100644
--- a/modules/video_output/win32/common.c
+++ b/modules/video_output/win32/common.c
@@ -47,11 +47,15 @@
 static void CommonChangeThumbnailClip(vlc_object_t *, vout_display_sys_win32_t *, bool show);
 static int  CommonControlSetFullscreen(vlc_object_t *, vout_display_sys_win32_t *, bool is_fullscreen);
 
-static bool GetRect(const vout_display_sys_win32_t *sys, RECT *out)
+static bool GetWindowDimensions(const vout_display_sys_win32_t *sys, UINT *width, UINT *height)
 {
-    if (sys->b_windowless)
+    assert(!sys->b_windowless);
+    RECT out;
+    if (!GetClientRect(sys->hwnd, &out))
         return false;
-    return GetClientRect(sys->hwnd, out);
+    *width  = RECTWidth(out);
+    *height = RECTHeight(out);
+    return true;
 }
 #else /* VLC_WINSTORE_APP */
 static inline BOOL EqualRect(const RECT *r1, const RECT *r2)
@@ -67,17 +71,25 @@ static inline BOOL SetRectEmpty(RECT *rect)
 }
 #endif /* VLC_WINSTORE_APP */
 
-static void InitArea(display_win32_area_t *sys, const vout_display_cfg_t *vdcfg)
+static bool GetExternalDimensions(const vout_display_t *vd, UINT *width, UINT *height)
+{
+    *width  = vd->source.i_visible_width;
+    *height = vd->source.i_visible_height;
+}
+
+static void InitArea(vout_display_t *vd, display_win32_area_t *sys, const vout_display_cfg_t *vdcfg)
 {
     sys->rect_dest_changed = false;
     SetRectEmpty(&sys->rect_display);
     sys->vdcfg = *vdcfg;
+    sys->pf_GetDisplayDimensions = GetExternalDimensions;
+    sys->opaque_dimensions = vd;
 }
 
 /* */
 int CommonInit(vout_display_t *vd, vout_display_sys_win32_t *sys, bool b_windowless, const vout_display_cfg_t *vdcfg)
 {
-    InitArea(&sys->area, vdcfg);
+    InitArea(vd, &sys->area, vdcfg);
 
     sys->hwnd      = NULL;
     sys->hvideownd = NULL;
@@ -91,7 +103,11 @@ int CommonInit(vout_display_t *vd, vout_display_sys_win32_t *sys, bool b_windowl
     sys->dxgidebug_dll = LoadLibrary(TEXT("DXGIDEBUG.DLL"));
 #endif
 #if !VLC_WINSTORE_APP
-    sys->pf_GetRect = GetRect;
+    if (!b_windowless)
+    {
+        sys->area.pf_GetDisplayDimensions = GetWindowDimensions;
+        sys->area.opaque_dimensions = sys;
+    }
     SetRectEmpty(&sys->rect_parent);
 
     var_Create(vd, "disable-screensaver", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
@@ -142,32 +158,31 @@ static void UpdateRectsInternal(vout_display_t *vd, vout_display_sys_win32_t *sy
 {
     const video_format_t *source = &vd->source;
 
-    RECT  new_display_rect;
+    UINT  display_width, display_height;
     POINT window_pos = { 0 };
 
     /* */
     const vout_display_cfg_t *cfg = &sys->area.vdcfg;
 
     /* Retrieve the window size */
-    if (sys->b_windowless)
+    if (sys->area.pf_GetDisplayDimensions == NULL)
     {
-        new_display_rect.left   = 0;
-        new_display_rect.top    = 0;
-        new_display_rect.right  = vd->source.i_visible_width;
-        new_display_rect.bottom = vd->source.i_visible_height;
+        display_width  = vd->source.i_visible_width;
+        display_height = vd->source.i_visible_height;
     }
-    else
+    else if (!sys->area.pf_GetDisplayDimensions(sys, &display_width, &display_height))
     {
-        if (!sys->pf_GetRect(sys, &new_display_rect))
-            return;
+        msg_Err(vd, "could not get the window dimensions");
+        return;
     }
 
     /* If nothing changed, we can return */
     bool moved_or_resized;
 #if VLC_WINSTORE_APP
-    moved_or_resized = RECTWidth(new_display_rect) != RECTWidth(sys->sys.rect_display) ||
-                       RECTHeight(new_display_rect) != RECTHeight(sys->sys.rect_display);
-    sys->sys.rect_display = new_display_rect;
+    moved_or_resized = display_width  != RECTWidth(sys->sys.rect_display) ||
+                       display_height != RECTHeight(sys->sys.rect_display);
+    sys->sys.display_width = display_width;
+    sys->sys.display_height = display_height;
 #else
     if (sys->b_windowless)
     {
@@ -178,8 +193,12 @@ static void UpdateRectsInternal(vout_display_t *vd, vout_display_sys_win32_t *sy
         /* Retrieve the window position */
         ClientToScreen(sys->hwnd, &window_pos);
 
-        OffsetRect(&new_display_rect, window_pos.x, window_pos.y);
-
+        RECT new_display_rect = {
+            .left   = window_pos.x,
+            .right  = window_pos.x + display_width,
+            .top    = window_pos.y,
+            .bottom = window_pos.y + display_height,
+        };
         moved_or_resized = EventThreadUpdateWindowPosition(sys->event, &new_display_rect);
     }
 #endif
@@ -188,8 +207,8 @@ static void UpdateRectsInternal(vout_display_t *vd, vout_display_sys_win32_t *sy
 
     /* Update the window position and size */
     vout_display_cfg_t place_cfg = *cfg;
-    place_cfg.display.width = RECTWidth(new_display_rect);
-    place_cfg.display.height = RECTHeight(new_display_rect);
+    place_cfg.display.width = display_width;
+    place_cfg.display.height = display_height;
 
 #if (defined(MODULE_NAME_IS_glwin32))
     /* Reverse vertical alignment as the GL tex are Y inverted */
diff --git a/modules/video_output/win32/common.h b/modules/video_output/win32/common.h
index 964637ab2e..c0f5852c1e 100644
--- a/modules/video_output/win32/common.h
+++ b/modules/video_output/win32/common.h
@@ -38,6 +38,9 @@ typedef struct display_win32_area_t
     RECT         rect_dest;
 
     vout_display_cfg_t vdcfg;
+
+    bool (*pf_GetDisplayDimensions)(const struct vout_display_sys_win32_t *p_sys, UINT *w, UINT *h);
+    void *opaque_dimensions;
 } display_win32_area_t;
 
 #define RECTWidth(r)   (LONG)((r).right - (r).left)
@@ -77,8 +80,6 @@ typedef struct vout_display_sys_win32_t
     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);
 } vout_display_sys_win32_t;
 
 
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 55a08696d3..0d8746f63b 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -154,11 +154,8 @@ static void UpdatePicQuadPosition(vout_display_t *);
 static int Control(vout_display_t *, int, va_list);
 
 #if VLC_WINSTORE_APP
-static bool GetRect(const vout_display_sys_win32_t *p_sys, RECT *out)
+static bool GetExtenalSwapchainDimensions(const vout_display_sys_t *sys, UINT *width, UINT *height)
 {
-    const vout_display_sys_t *sys = (const vout_display_sys_t *)p_sys;
-    out->left   = 0;
-    out->top    = 0;
     uint32_t i_width;
     uint32_t i_height;
     UINT dataSize = sizeof(i_width);
@@ -171,8 +168,8 @@ static bool GetRect(const vout_display_sys_win32_t *p_sys, RECT *out)
     if (FAILED(hr)) {
         return false;
     }
-    out->right  = i_width;
-    out->bottom = i_height;
+    *width  = i_width;
+    *height = i_height;
     return true;
 }
 #endif
@@ -186,13 +183,10 @@ static inline bool RectEquals(const RECT *r1, const RECT *r2)
 static HRESULT UpdateBackBuffer(vout_display_t *vd)
 {
     vout_display_sys_t *sys = vd->sys;
-    RECT rect;
-#if VLC_WINSTORE_APP
-    if (!GetRect(&sys->sys, &rect))
-#endif
-        rect = sys->sys.area.rect_dest;
-    uint32_t i_width = RECTWidth(rect);
-    uint32_t i_height = RECTHeight(rect);
+    UINT i_width, i_height;
+    //sys->sys.area.pf_GetDisplayDimensions(sys->sys.area.opaque_dimensions, &i_width, &i_height);
+    i_width  = RECTWidth(sys->sys.area.rect_dest);
+    i_height = RECTHeight(sys->sys.area.rect_dest);
 
     if (!sys->resizeCb(sys->outside_opaque, i_width, i_height))
         return E_FAIL;
@@ -480,7 +474,8 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
         goto error;
 
 #if VLC_WINSTORE_APP
-    sys->sys.pf_GetRect = GetRect;
+    sys->sys.area.pf_GetDisplayDimensions = GetExtenalSwapchainDimensions;
+    sys->sys.area.opaque_dimensions = sys;
 #endif
 
     if (!sys->swapCb || !sys->starRenderCb || !sys->endRenderCb || !sys->resizeCb)
-- 
2.17.1



More information about the vlc-devel mailing list