[vlc-commits] vout:win32: use a NULL vout_display_sys_win32_t in windowless mode

Steve Lhomme git at videolan.org
Mon Apr 1 16:56:04 CEST 2019


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Mon Mar 25 15:00:03 2019 +0100| [5f14d7dcd25047d74a1f08fd225f4fa34dfba943] | committer: Steve Lhomme

vout:win32: use a NULL vout_display_sys_win32_t in windowless mode

That allows us cleaning the code and avoid calls that don't mean anything.

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

 modules/video_output/win32/common.c     | 75 ++++++++++++++-------------------
 modules/video_output/win32/common.h     |  4 +-
 modules/video_output/win32/direct3d11.c | 26 ++++++------
 modules/video_output/win32/direct3d9.c  | 14 +++---
 modules/video_output/win32/glwin32.c    |  5 +--
 modules/video_output/win32/wingdi.c     |  5 +--
 6 files changed, 57 insertions(+), 72 deletions(-)

diff --git a/modules/video_output/win32/common.c b/modules/video_output/win32/common.c
index 10072047b1..c19eeeb88f 100644
--- a/modules/video_output/win32/common.c
+++ b/modules/video_output/win32/common.c
@@ -43,28 +43,6 @@
 #include "common.h"
 #include "../video_chroma/copy.h"
 
-#if !VLC_WINSTORE_APP
-static void CommonChangeThumbnailClip(vlc_object_t *, vout_display_sys_win32_t *, bool show);
-
-static bool GetWindowDimensions(void *opaque, UINT *width, UINT *height)
-{
-    const vout_display_sys_win32_t *sys = opaque;
-    assert(!sys->b_windowless);
-    RECT out;
-    if (!GetClientRect(sys->hwnd, &out))
-        return false;
-    *width  = RECTWidth(out);
-    *height = RECTHeight(out);
-    return true;
-}
-#else /* VLC_WINSTORE_APP */
-static inline BOOL EqualRect(const RECT *r1, const RECT *r2)
-{
-    return r1->left == r2->left && r1->right == r2->right &&
-            r1->top == r2->top && r1->bottom == r2->bottom;
-}
-#endif /* VLC_WINSTORE_APP */
-
 static bool GetExternalDimensions(void *opaque, UINT *width, UINT *height)
 {
     const vout_display_t *vd = opaque;
@@ -79,36 +57,45 @@ void InitArea(vout_display_t *vd, display_win32_area_t *area, const vout_display
     area->pf_GetDisplayDimensions = GetExternalDimensions;
     area->opaque_dimensions = vd;
     area->vdcfg = *vdcfg;
+
+    var_Create(vd, "disable-screensaver", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
+}
+
+#if !VLC_WINSTORE_APP
+static void CommonChangeThumbnailClip(vlc_object_t *, vout_display_sys_win32_t *, bool show);
+
+static bool GetWindowDimensions(void *opaque, UINT *width, UINT *height)
+{
+    const vout_display_sys_win32_t *sys = opaque;
+    assert(sys != NULL);
+    RECT out;
+    if (!GetClientRect(sys->hwnd, &out))
+        return false;
+    *width  = RECTWidth(out);
+    *height = RECTHeight(out);
+    return true;
 }
 
 /* */
-int CommonInit(vout_display_t *vd, display_win32_area_t *area, vout_display_sys_win32_t *sys,
-               bool b_windowless)
+int CommonInit(vout_display_t *vd, display_win32_area_t *area, vout_display_sys_win32_t *sys)
 {
+#if !defined(NDEBUG) && defined(HAVE_DXGIDEBUG_H)
+    sys->dxgidebug_dll = LoadLibrary(TEXT("DXGIDEBUG.DLL"));
+#endif
     sys->hwnd      = NULL;
     sys->hvideownd = NULL;
     sys->hparent   = NULL;
     sys->hfswnd    = NULL;
-    sys->b_windowless = b_windowless;
     sys->is_first_placement = true;
     sys->is_on_top        = false;
 
-#if !VLC_WINSTORE_APP
 #if !defined(NDEBUG) && defined(HAVE_DXGIDEBUG_H)
     sys->dxgidebug_dll = LoadLibrary(TEXT("DXGIDEBUG.DLL"));
 #endif
-    if (!b_windowless)
-    {
-        area->pf_GetDisplayDimensions = GetWindowDimensions;
-        area->opaque_dimensions = sys;
-    }
+    area->pf_GetDisplayDimensions = GetWindowDimensions;
+    area->opaque_dimensions = sys;
     SetRectEmpty(&sys->rect_parent);
 
-    var_Create(vd, "disable-screensaver", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
-
-    if (b_windowless)
-        return VLC_SUCCESS;
-
     var_Create(vd, "video-deco", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
 
     /* */
@@ -136,10 +123,9 @@ int CommonInit(vout_display_t *vd, display_win32_area_t *area, vout_display_sys_
     sys->hvideownd     = hwnd.hvideownd;
     sys->hfswnd        = hwnd.hfswnd;
 
-#endif /* !VLC_WINSTORE_APP */
-
     return VLC_SUCCESS;
 }
+#endif /* !VLC_WINSTORE_APP */
 
 /*****************************************************************************
 * UpdateRects: update clipping rectangles
@@ -231,7 +217,7 @@ void CommonClean(vlc_object_t *obj, vout_display_sys_win32_t *sys)
 
 void CommonManage(vout_display_t *vd, display_win32_area_t *area, vout_display_sys_win32_t *sys)
 {
-    if (sys->b_windowless)
+    if (sys == NULL)
         return;
 
     if (EventThreadGetAndResetSizeChanged(sys->event))
@@ -295,9 +281,6 @@ static int CommonControlSetFullscreen(vlc_object_t *obj, vout_display_sys_win32_
     if (sys->parent_window)
         return VLC_EGENERIC;
 
-    if(sys->b_windowless)
-        return VLC_SUCCESS;
-
     /* */
     HWND hwnd = sys->hparent && sys->hfswnd ? sys->hfswnd : sys->hwnd;
 
@@ -388,7 +371,7 @@ int CommonControl(vout_display_t *vd, display_win32_area_t *area, vout_display_s
     {   /* Update dimensions */
         area->vdcfg = *va_arg(args, const vout_display_cfg_t *);
 #if !VLC_WINSTORE_APP
-        if (!area->vdcfg.is_fullscreen && !sys->b_windowless) {
+        if (!area->vdcfg.is_fullscreen && sys != NULL) {
             RECT rect_window = {
                 .top    = 0,
                 .left   = 0,
@@ -408,6 +391,8 @@ int CommonControl(vout_display_t *vd, display_win32_area_t *area, vout_display_s
     case VOUT_DISPLAY_CHANGE_WINDOW_STATE: {       /* unsigned state */
         const unsigned state = va_arg(args, unsigned);
         const bool is_on_top = (state & VOUT_WINDOW_STATE_ABOVE) != 0;
+        if (sys != NULL)
+        {
 #ifdef MODULE_NAME_IS_direct3d9
         if (sys->use_desktop && is_on_top)
             return VLC_EGENERIC;
@@ -422,13 +407,17 @@ int CommonControl(vout_display_t *vd, display_win32_area_t *area, vout_display_s
             SetWindowPos(sys->hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
         }
         sys->is_on_top = is_on_top;
+        }
         return VLC_SUCCESS;
     }
     case VOUT_DISPLAY_CHANGE_FULLSCREEN: {
         bool fs = va_arg(args, int);
+        if (sys != NULL)
+        {
         if (CommonControlSetFullscreen(VLC_OBJECT(vd), sys, fs))
             return VLC_EGENERIC;
         UpdateRects(vd, area, sys);
+        }
         return VLC_SUCCESS;
     }
 #endif /* !VLC_WINSTORE_APP */
diff --git a/modules/video_output/win32/common.h b/modules/video_output/win32/common.h
index 97d8d63b60..bcec5ddde8 100644
--- a/modules/video_output/win32/common.h
+++ b/modules/video_output/win32/common.h
@@ -50,8 +50,6 @@ typedef struct display_win32_area_t
  *****************************************************************************/
 typedef struct vout_display_sys_win32_t
 {
-    bool                 b_windowless;    /* the rendering is done offscreen */
-
     /* */
     event_thread_t *event;
 
@@ -80,8 +78,8 @@ typedef struct vout_display_sys_win32_t
 /*****************************************************************************
  * Prototypes from common.c
  *****************************************************************************/
-int  CommonInit(vout_display_t *, display_win32_area_t *, vout_display_sys_win32_t *, bool b_windowless);
 #if !VLC_WINSTORE_APP
+int  CommonInit(vout_display_t *, display_win32_area_t *, vout_display_sys_win32_t *);
 void CommonClean(vlc_object_t *, vout_display_sys_win32_t *);
 #endif /* !VLC_WINSTORE_APP */
 void CommonManage(vout_display_t *, display_win32_area_t *, vout_display_sys_win32_t *);
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 3d480a41ce..9c4925af44 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -89,7 +89,7 @@ vlc_module_end ()
 
 struct vout_display_sys_t
 {
-    vout_display_sys_win32_t sys;
+    vout_display_sys_win32_t sys;       /* only use if sys.event is not NULL */
     display_win32_area_t     area;
 
     /* Sensors */
@@ -288,7 +288,7 @@ static bool StartRendering(void *opaque)
     /* TODO read the swapchain size and call VOUT_DISPLAY_CHANGE_DISPLAY_SIZE */
     UpdateRects(vd, &sys->area, &sys->sys);
 #else /* !VLC_WINSTORE_APP */
-    CommonManage(vd, &sys->area, &sys->sys);
+    CommonManage(vd, &sys->area, sys->sys.event ? &sys->sys : NULL);
 #endif
 
     if ( sys->area.place_changed )
@@ -480,13 +480,13 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
     }
 #endif
     InitArea(vd, &sys->area, cfg);
-    if (CommonInit(vd, &sys->area, &sys->sys, d3d11_ctx != NULL))
+#if !VLC_WINSTORE_APP
+    if (d3d11_ctx == NULL && CommonInit(vd, &sys->area, &sys->sys))
         goto error;
-
-#if VLC_WINSTORE_APP
+#else /* !VLC_WINSTORE_APP */
     sys->area.pf_GetDisplayDimensions = GetExtenalSwapchainDimensions;
     sys->area.opaque_dimensions = sys;
-#endif
+#endif /* !VLC_WINSTORE_APP */
 
     if (vd->source.projection_mode != PROJECTION_MODE_RECTANGULAR && sys->sys.hvideownd)
         sys->p_sensors = HookWindowsSensors(vd, sys->sys.hvideownd);
@@ -506,7 +506,7 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
     }
 
 #if !VLC_WINSTORE_APP
-    if (!sys->sys.b_windowless)
+    if (sys->sys.event != NULL)
         EventThreadUpdateTitle(sys->sys.event, VOUT_TITLE " (Direct3D11 output)");
 #endif
     msg_Dbg(vd, "Direct3D11 device adapter successfully initialized");
@@ -745,7 +745,7 @@ 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;
-    int res = CommonControl( vd, &sys->area, &sys->sys, query, args );
+    int res = CommonControl( vd, &sys->area, sys->sys.event ? &sys->sys : NULL, query, args );
 
     if (query == VOUT_DISPLAY_CHANGE_VIEWPOINT)
     {
@@ -848,7 +848,7 @@ static void PreparePicture(vout_display_t *vd, picture_t *picture, subpicture_t
                 sys->picQuad.i_height = texDesc.Height;
                 sys->picQuad.i_width = texDesc.Width;
 
-                UpdateRects(vd, &sys->area, &sys->sys);
+                UpdateRects(vd, &sys->area, sys->sys.event ? &sys->sys : NULL);
                 UpdateSize(vd);
             }
         }
@@ -1017,7 +1017,7 @@ static void D3D11SetColorSpace(vout_display_t *vd)
     UINT support;
     IDXGISwapChain3 *dxgiswapChain3 = NULL;
     sys->display.colorspace = &color_spaces[0];
-    if (sys->sys.b_windowless)
+    if (sys->sys.event == NULL) /* TODO support external colourspace handling */
         goto done;
 
     hr = IDXGISwapChain_QueryInterface( sys->dxgiswapChain, &IID_IDXGISwapChain3, (void **)&dxgiswapChain3);
@@ -1192,7 +1192,7 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmtp)
        return VLC_EGENERIC;
     }
 
-    if (sys->sys.b_windowless)
+    if (sys->sys.event == NULL)
         ret = SetupWindowLessOutput(vd);
 #if !VLC_WINSTORE_APP
     else
@@ -1464,7 +1464,7 @@ static int Direct3D11CreateFormatResources(vout_display_t *vd, const video_forma
         sys->picQuad.i_height = (sys->picQuad.i_height + 0x01) & ~0x01;
     }
 
-    UpdateRects(vd, &sys->area, &sys->sys);
+    UpdateRects(vd, &sys->area, sys->sys.event ? &sys->sys : NULL);
 
     video_format_t surface_fmt = *fmt;
     surface_fmt.i_width  = sys->picQuad.i_width;
@@ -1574,7 +1574,7 @@ static int Direct3D11CreateGenericResources(vout_display_t *vd)
         ID3D11DepthStencilState_Release(pDepthStencilState);
     }
 
-    UpdateRects(vd, &sys->area, &sys->sys);
+    UpdateRects(vd, &sys->area, sys->sys.event ? &sys->sys : NULL);
 
     hr = UpdateBackBuffer(vd);
     if (FAILED(hr)) {
diff --git a/modules/video_output/win32/direct3d9.c b/modules/video_output/win32/direct3d9.c
index 57d60f4770..28e6938c71 100644
--- a/modules/video_output/win32/direct3d9.c
+++ b/modules/video_output/win32/direct3d9.c
@@ -137,7 +137,7 @@ typedef struct
 
 struct vout_display_sys_t
 {
-    vout_display_sys_win32_t sys;
+    vout_display_sys_win32_t sys;       /* only use if sys.event is not NULL */
     display_win32_area_t     area;
 
     bool allow_hw_yuv;    /* Should we use hardware YUV->RGB conversions */
@@ -900,7 +900,7 @@ static int Direct3D9Reset(vout_display_t *vd, video_format_t *fmtp)
         return VLC_EGENERIC;
     }
 
-    UpdateRects(vd, &sys->area, &sys->sys);
+    UpdateRects(vd, &sys->area, sys->sys.event ? &sys->sys : NULL);
 
     /* re-create them */
     if (Direct3D9CreateResources(vd, fmtp)) {
@@ -1208,7 +1208,7 @@ static void Prepare(vout_display_t *vd, picture_t *picture,
     VLC_UNUSED(date);
     vout_display_sys_t *sys = vd->sys;
 
-    CommonManage(vd, &sys->area, &sys->sys);
+    CommonManage(vd, &sys->area, sys->sys.event ? &sys->sys : NULL);
 
     /* Desktop mode change */
     bool prev_desktop = sys->sys.use_desktop;
@@ -1505,7 +1505,7 @@ static int Direct3D9Open(vout_display_t *vd, video_format_t *fmt,
     fmt->i_bmask  = d3dfmt->bmask;
     sys->sw_texture_fmt = d3dfmt;
 
-    UpdateRects(vd, &sys->area, &sys->sys);
+    UpdateRects(vd, &sys->area, sys->sys.event ? &sys->sys : NULL);
 
     if (Direct3D9CreateResources(vd, fmt)) {
         msg_Err(vd, "Failed to allocate resources");
@@ -1513,7 +1513,7 @@ static int Direct3D9Open(vout_display_t *vd, video_format_t *fmt,
     }
 
     /* Change the window title bar text */
-    if (!sys->sys.b_windowless)
+    if (sys->sys.event != NULL)
         EventThreadUpdateTitle(sys->sys.event, VOUT_TITLE " (Direct3D9 output)");
 
     msg_Dbg(vd, "Direct3D9 device adapter successfully initialized");
@@ -1556,7 +1556,7 @@ static int Control(vout_display_t *vd, int query, va_list args)
         return VLC_SUCCESS;
     }
     default:
-        return CommonControl(vd, &sys->area, &sys->sys, query, args);
+        return CommonControl(vd, &sys->area, sys->sys.event ? &sys->sys : NULL, query, args);
     }
 }
 
@@ -1681,7 +1681,7 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
     sys->desktop_save.is_on_top     = false;
 
     InitArea(vd, &sys->area, cfg);
-    if (CommonInit(vd, &sys->area, &sys->sys, d3d9_device != NULL))
+    if (d3d9_device == NULL && CommonInit(vd, &sys->area, &sys->sys))
         goto error;
 
     /* */
diff --git a/modules/video_output/win32/glwin32.c b/modules/video_output/win32/glwin32.c
index c26dbf0a02..a1a9516839 100644
--- a/modules/video_output/win32/glwin32.c
+++ b/modules/video_output/win32/glwin32.c
@@ -123,14 +123,13 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
 
     /* */
     InitArea(vd, &sys->area, cfg);
-    if (CommonInit(vd, &sys->area, &sys->sys, false))
+    if (CommonInit(vd, &sys->area, &sys->sys))
         goto error;
 
     if (vd->source.projection_mode != PROJECTION_MODE_RECTANGULAR)
         sys->p_sensors = HookWindowsSensors(vd, sys->sys.hvideownd);
 
-    if (!sys->sys.b_windowless)
-        EventThreadUpdateTitle(sys->sys.event, VOUT_TITLE " (OpenGL output)");
+    EventThreadUpdateTitle(sys->sys.event, VOUT_TITLE " (OpenGL output)");
 
     vout_display_cfg_t embed_cfg = *cfg;
     embed_cfg.window = EmbedVideoWindow_Create(vd);
diff --git a/modules/video_output/win32/wingdi.c b/modules/video_output/win32/wingdi.c
index beb2f327ce..c2fad2a092 100644
--- a/modules/video_output/win32/wingdi.c
+++ b/modules/video_output/win32/wingdi.c
@@ -118,7 +118,7 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
         return VLC_ENOMEM;
 
     InitArea(vd, &sys->area, cfg);
-    if (CommonInit(vd, &sys->area, &sys->sys, false))
+    if (CommonInit(vd, &sys->area, &sys->sys))
         goto error;
 
     /* */
@@ -261,8 +261,7 @@ static int Init(vout_display_t *vd, video_format_t *fmt)
     SelectObject(sys->off_dc, sys->off_bitmap);
     ReleaseDC(sys->sys.hvideownd, window_dc);
 
-    if (!sys->sys.b_windowless)
-        EventThreadUpdateTitle(sys->sys.event, VOUT_TITLE " (WinGDI output)");
+    EventThreadUpdateTitle(sys->sys.event, VOUT_TITLE " (WinGDI output)");
 
     UpdateRects(vd, &sys->area, &sys->sys);
 



More information about the vlc-commits mailing list