[vlc-commits] vout:win32: rework the callback to get the display dimensions

Steve Lhomme git at videolan.org
Mon Apr 1 16:50:05 CEST 2019


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Fri Mar 22 15:33:58 2019 +0100| [7c5cc90b11f2a8ca4ced10d6fed4ca36d0f14723] | committer: Steve Lhomme

vout:win32: rework the callback to get the display dimensions

We don't need a rect for that.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7c5cc90b11f2a8ca4ced10d6fed4ca36d0f14723
---

 modules/video_output/win32/common.c     | 62 +++++++++++++++++++++------------
 modules/video_output/win32/common.h     |  3 +-
 modules/video_output/win32/direct3d11.c | 23 +++++-------
 3 files changed, 51 insertions(+), 37 deletions(-)

diff --git a/modules/video_output/win32/common.c b/modules/video_output/win32/common.c
index 8777deabb8..52b2ed0c7a 100644
--- a/modules/video_output/win32/common.c
+++ b/modules/video_output/win32/common.c
@@ -46,11 +46,16 @@
 #if !VLC_WINSTORE_APP
 static void CommonChangeThumbnailClip(vlc_object_t *, vout_display_sys_win32_t *, bool show);
 
-static bool GetRect(const vout_display_sys_win32_t *sys, RECT *out)
+static bool GetWindowDimensions(void *opaque, UINT *width, UINT *height)
 {
-    if (sys->b_windowless)
+    const vout_display_sys_win32_t *sys = opaque;
+    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)
@@ -60,6 +65,14 @@ static inline BOOL EqualRect(const RECT *r1, const RECT *r2)
 }
 #endif /* VLC_WINSTORE_APP */
 
+static bool GetExternalDimensions(void *opaque, UINT *width, UINT *height)
+{
+    const vout_display_t *vd = opaque;
+    *width  = vd->source.i_visible_width;
+    *height = vd->source.i_visible_height;
+    return true;
+}
+
 /* */
 int CommonInit(vout_display_t *vd, vout_display_sys_win32_t *sys, bool b_windowless, const vout_display_cfg_t *vdcfg)
 {
@@ -72,13 +85,20 @@ int CommonInit(vout_display_t *vd, vout_display_sys_win32_t *sys, bool b_windowl
     sys->is_first_placement = true;
     sys->is_on_top        = false;
 
+    sys->pf_GetDisplayDimensions = GetExternalDimensions;
+    sys->opaque_dimensions = vd;
+
 #if !defined(NDEBUG) && defined(HAVE_DXGIDEBUG_H)
     sys->dxgidebug_dll = LoadLibrary(TEXT("DXGIDEBUG.DLL"));
 #endif
 #if VLC_WINSTORE_APP
     memset(&sys->rect_display, 0, sizeof(sys->rect_display));
 #else /* !VLC_WINSTORE_APP */
-    sys->pf_GetRect = GetRect;
+    if (!b_windowless)
+    {
+        sys->pf_GetDisplayDimensions = GetWindowDimensions;
+        sys->opaque_dimensions = sys;
+    }
     SetRectEmpty(&sys->rect_parent);
 
     var_Create(vd, "disable-screensaver", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
@@ -131,32 +151,26 @@ void UpdateRects(vout_display_t *vd, vout_display_sys_win32_t *sys, bool is_forc
 {
     const video_format_t *source = &vd->source;
 
-    RECT  rect;
+    UINT  display_width, display_height;
     POINT point = { 0 };
 
     /* */
     const vout_display_cfg_t *cfg = &sys->vdcfg;
 
     /* Retrieve the window size */
-    if (sys->b_windowless)
-    {
-        rect.left   = 0;
-        rect.top    = 0;
-        rect.right  = vd->source.i_visible_width;
-        rect.bottom = vd->source.i_visible_height;
-    }
-    else
+    if (!sys->pf_GetDisplayDimensions(sys->opaque_dimensions, &display_width, &display_height))
     {
-        if (!sys->pf_GetRect(sys, &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(rect)  != RECTWidth(sys->rect_display) ||
-                       RECTHeight(rect) != RECTHeight(sys->rect_display);
-    sys->rect_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)
     {
@@ -167,8 +181,12 @@ void UpdateRects(vout_display_t *vd, vout_display_sys_win32_t *sys, bool is_forc
         /* Retrieve the window position */
         ClientToScreen(sys->hwnd, &point);
 
-        OffsetRect(&rect, point.x, point.y);
-
+        RECT rect = {
+            .left   = point.x,
+            .right  = point.x + display_width,
+            .top    = point.y,
+            .bottom = point.y + display_height,
+        };
         moved_or_resized = EventThreadUpdateWindowPosition(sys->event, &rect);
     }
 #endif
@@ -177,8 +195,8 @@ void UpdateRects(vout_display_t *vd, vout_display_sys_win32_t *sys, bool is_forc
 
     /* Update the window position and size */
     vout_display_cfg_t place_cfg = *cfg;
-    place_cfg.display.width = RECTWidth(rect);
-    place_cfg.display.height = RECTHeight(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 31863fb115..ee850c3d7e 100644
--- a/modules/video_output/win32/common.h
+++ b/modules/video_output/win32/common.h
@@ -75,7 +75,8 @@ typedef struct vout_display_sys_win32_t
 
     bool use_desktop;     /* show video on desktop window ? */
 
-    bool (*pf_GetRect)(const struct vout_display_sys_win32_t *p_sys, RECT *out);
+    bool (*pf_GetDisplayDimensions)(void *opaque, UINT *w, UINT *h);
+    void *opaque_dimensions;
 } vout_display_sys_win32_t;
 
 
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 8575524790..ac12897a06 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -157,11 +157,9 @@ 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(void *opaque, UINT *width, UINT *height)
 {
-    const vout_display_sys_t *sys = (const vout_display_sys_t *)p_sys;
-    out->left   = 0;
-    out->top    = 0;
+    const vout_display_sys_t *sys = opaque;
     uint32_t i_width;
     uint32_t i_height;
     UINT dataSize = sizeof(i_width);
@@ -174,8 +172,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
@@ -189,13 +187,9 @@ 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.rect_dest;
-    uint32_t i_width = RECTWidth(rect);
-    uint32_t i_height = RECTHeight(rect);
+    UINT i_width, i_height;
+    i_width  = RECTWidth(sys->sys.rect_dest);
+    i_height = RECTHeight(sys->sys.rect_dest);
 
     if (!sys->resizeCb(sys->outside_opaque, i_width, i_height))
         return E_FAIL;
@@ -483,7 +477,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 (vd->source.projection_mode != PROJECTION_MODE_RECTANGULAR && sys->sys.hvideownd)



More information about the vlc-commits mailing list