[vlc-commits] vout: win32: avoid calling D3D11 specific code in common

Steve Lhomme git at videolan.org
Thu Feb 2 17:01:10 CET 2017


vlc | branch: master | Steve Lhomme <robUx4 at videolabs.io> | Thu Feb  2 14:54:05 2017 +0100| [490c24c3a67a4764b014bcabcf9abdae398ab716] | committer: Jean-Baptiste Kempf

vout: win32: avoid calling D3D11 specific code in common

Use a callback to get the window rectangle instead

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 modules/video_output/win32/common.c     | 28 +++++--------------
 modules/video_output/win32/common.h     |  7 ++---
 modules/video_output/win32/direct3d11.c | 48 +++++++++++++++++++++++----------
 3 files changed, 43 insertions(+), 40 deletions(-)

diff --git a/modules/video_output/win32/common.c b/modules/video_output/win32/common.c
index 45830a3..f2b97b8 100644
--- a/modules/video_output/win32/common.c
+++ b/modules/video_output/win32/common.c
@@ -56,6 +56,11 @@ static int  CommonControlSetFullscreen(vout_display_t *, bool is_fullscreen);
 
 static void DisableScreensaver(vout_display_t *);
 static void RestoreScreensaver(vout_display_t *);
+
+static bool GetRect(const vout_display_sys_t *sys, RECT *out)
+{
+    return GetClientRect(sys->hwnd, out);
+}
 #endif
 
 /* */
@@ -72,6 +77,7 @@ int CommonInit(vout_display_t *vd)
     sys->is_on_top        = false;
 
 #if !VLC_WINSTORE_APP
+    sys->pf_GetRect = GetRect;
     SetRectEmpty(&sys->rect_display);
     SetRectEmpty(&sys->rect_parent);
 
@@ -157,28 +163,8 @@ void UpdateRects(vout_display_t *vd,
         source = &vd->source;
 
     /* Retrieve the window size */
-#if VLC_WINSTORE_APP && MODULE_NAME_IS_direct3d11
-    rect.left   = 0;
-    rect.top    = 0;
-    uint32_t i_width;
-    uint32_t i_height;
-    UINT dataSize = sizeof(i_width);
-    HRESULT hr = IDXGISwapChain_GetPrivateData(sys->dxgiswapChain, &GUID_SWAPCHAIN_WIDTH, &dataSize, &i_width);
-    if (FAILED(hr)) {
-        msg_Err(vd, "Can't get swapchain width, size %d. (hr=0x%lX)", hr, dataSize);
-        return;
-    }
-    dataSize = sizeof(i_height);
-    hr = IDXGISwapChain_GetPrivateData(sys->dxgiswapChain, &GUID_SWAPCHAIN_HEIGHT, &dataSize, &i_height);
-    if (FAILED(hr)) {
-        msg_Err(vd, "Can't get swapchain height, size %d. (hr=0x%lX)", hr, dataSize);
+    if (!sys->pf_GetRect(sys, &rect))
         return;
-    }
-    rect.right  = i_width;
-    rect.bottom = i_height;
-#else
-    GetClientRect(sys->hwnd, &rect);
-#endif
 
     /* Retrieve the window position */
     point.x = point.y = 0;
diff --git a/modules/video_output/win32/common.h b/modules/video_output/win32/common.h
index 32474c7..a957048 100644
--- a/modules/video_output/win32/common.h
+++ b/modules/video_output/win32/common.h
@@ -28,11 +28,6 @@
  *****************************************************************************/
 #include "events.h"
 
-#if VLC_WINSTORE_APP
-extern const GUID GUID_SWAPCHAIN_WIDTH;
-extern const GUID GUID_SWAPCHAIN_HEIGHT;
-#endif
-
 /*****************************************************************************
  * vout_sys_t: video output method descriptor
  *****************************************************************************
@@ -86,6 +81,8 @@ typedef struct vout_display_sys_win32_t
     int  i_align_src_size;
     int  i_align_dest_boundary;
     int  i_align_dest_size;
+
+    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 28f2bfb..fa826f5 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -476,6 +476,30 @@ static bool is_d3d11_opaque(vlc_fourcc_t chroma)
     }
 }
 
+#if VLC_WINSTORE_APP
+static bool GetRect(const vout_display_sys_win32_t *p_sys, RECT *out)
+{
+    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);
+    HRESULT hr = IDXGISwapChain_GetPrivateData(sys->dxgiswapChain, &GUID_SWAPCHAIN_WIDTH, &dataSize, &i_width);
+    if (FAILED(hr)) {
+        return false;
+    }
+    dataSize = sizeof(i_height);
+    hr = IDXGISwapChain_GetPrivateData(sys->dxgiswapChain, &GUID_SWAPCHAIN_HEIGHT, &dataSize, &i_height);
+    if (FAILED(hr)) {
+        return false;
+    }
+    out->right  = i_width;
+    out->bottom = i_height;
+    return true;
+}
+#endif
+
 static int Open(vlc_object_t *object)
 {
     vout_display_t *vd = (vout_display_t *)object;
@@ -492,6 +516,10 @@ static int Open(vlc_object_t *object)
     if (CommonInit(vd))
         goto error;
 
+#if VLC_WINSTORE_APP
+    vd->sys->sys.pf_GetRect = GetRect;
+#endif
+
     video_format_t fmt;
     if (Direct3D11Open(vd, &fmt)) {
         msg_Err(vd, "Direct3D11 could not be opened");
@@ -674,22 +702,13 @@ static HRESULT UpdateBackBuffer(vout_display_t *vd)
     HRESULT hr;
     ID3D11Texture2D* pDepthStencil;
     ID3D11Texture2D* pBackBuffer;
-    uint32_t i_width  = RECTWidth(sys->sys.rect_dest_clipped);
-    uint32_t i_height = RECTHeight(sys->sys.rect_dest_clipped);
+    RECT rect;
 #if VLC_WINSTORE_APP
-    UINT dataSize = sizeof(i_width);
-    hr = IDXGISwapChain_GetPrivateData(sys->dxgiswapChain, &GUID_SWAPCHAIN_WIDTH, &dataSize, &i_width);
-    if (FAILED(hr)) {
-        msg_Err(vd, "Can't get swapchain width, size %d. (hr=0x%lX)", hr, dataSize);
-        return hr;
-    }
-    dataSize = sizeof(i_height);
-    hr = IDXGISwapChain_GetPrivateData(sys->dxgiswapChain, &GUID_SWAPCHAIN_HEIGHT, &dataSize, &i_height);
-    if (FAILED(hr)) {
-        msg_Err(vd, "Can't get swapchain height, size %d. (hr=0x%lX)", hr, dataSize);
-        return hr;
-    }
+    if (!GetRect(&sys->sys, &rect))
 #endif
+        rect = sys->sys.rect_dest_clipped;
+    uint32_t i_width = RECTWidth(rect);
+    uint32_t i_height = RECTHeight(rect);
 
     if (sys->d3drenderTargetView) {
         ID3D11RenderTargetView_Release(sys->d3drenderTargetView);
@@ -700,6 +719,7 @@ static HRESULT UpdateBackBuffer(vout_display_t *vd)
         sys->d3ddepthStencilView = NULL;
     }
 
+    /* TODO detect is the size is the same as the output and switch to fullscreen mode */
     hr = IDXGISwapChain_ResizeBuffers(sys->dxgiswapChain, 0, i_width, i_height,
         DXGI_FORMAT_UNKNOWN, 0);
     if (FAILED(hr)) {



More information about the vlc-commits mailing list