From 490c24c3a67a4764b014bcabcf9abdae398ab716 Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Thu, 2 Feb 2017 14:54:05 +0100 Subject: [PATCH] vout: win32: avoid calling D3D11 specific code in common Use a callback to get the window rectangle instead Signed-off-by: Jean-Baptiste Kempf --- 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 45830a3360..f2b97b88e3 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 32474c74f7..a957048541 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 28f2bfb5f5..fa826f5ccc 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)) { -- 2.11.4.GIT