[vlc-commits] direct3d11: move some of the rendering calls into callbacks

Steve Lhomme git at videolan.org
Wed Jan 16 09:58:58 CET 2019


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Mon Nov 19 14:43:35 2018 +0100| [93240e5e592e749fc3e6cb69c02bf1e8ecbdd80c] | committer: Steve Lhomme

direct3d11: move some of the rendering calls into callbacks

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

 modules/video_output/win32/direct3d11.c | 128 ++++++++++++++++++++++----------
 1 file changed, 89 insertions(+), 39 deletions(-)

diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 539b902b6a..b6298cee4a 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -116,6 +116,13 @@ struct vout_display_sys_t
     d3d_quad_t               regionQuad;
     int                      d3dregion_count;
     picture_t                **d3dregions;
+
+    /* outside rendering */
+    void *outside_opaque;
+    void (*swapCb)(void* opaque);
+    void (*endRenderCb)(void* opaque);
+    bool (*starRenderCb)(void* opaque);
+    bool (*resizeCb)(void* opaque, unsigned, unsigned);
 };
 
 #define RECTWidth(r)   (int)((r).right - (r).left)
@@ -235,8 +242,6 @@ static inline bool RectEquals(const RECT *r1, const RECT *r2)
 static HRESULT UpdateBackBuffer(vout_display_t *vd)
 {
     vout_display_sys_t *sys = vd->sys;
-    HRESULT hr;
-    ID3D11Texture2D* pBackBuffer;
     RECT rect;
 #if VLC_WINSTORE_APP
     if (!GetRect(&sys->sys, &rect))
@@ -244,6 +249,55 @@ static HRESULT UpdateBackBuffer(vout_display_t *vd)
         rect = sys->sys.rect_dest_clipped;
     uint32_t i_width = RECTWidth(rect);
     uint32_t i_height = RECTHeight(rect);
+
+    if (!sys->resizeCb(sys->outside_opaque, i_width, i_height))
+        return E_FAIL;
+
+    return S_OK;
+}
+
+static void UpdateSize(vout_display_t *vd)
+{
+    vout_display_sys_t *sys = vd->sys;
+    msg_Dbg(vd, "Detected size change %dx%d", RECTWidth(sys->sys.rect_dest_clipped),
+            RECTHeight(sys->sys.rect_dest_clipped));
+
+    UpdateBackBuffer(vd);
+
+    d3d11_device_lock( &sys->d3d_dev );
+
+    UpdatePicQuadPosition(vd);
+
+    D3D11_UpdateQuadPosition(vd, &sys->d3d_dev, &sys->picQuad, &sys->sys.rect_src_clipped,
+                             vd->source.orientation);
+
+    d3d11_device_unlock( &sys->d3d_dev );
+}
+
+static void Manage(vout_display_t *vd)
+{
+    vout_display_sys_t *sys = vd->sys;
+    RECT before_src_clipped  = sys->sys.rect_src_clipped;
+    RECT before_dest_clipped = sys->sys.rect_dest_clipped;
+    RECT before_dest         = sys->sys.rect_dest;
+
+    CommonManage(vd);
+
+    if (!RectEquals(&before_src_clipped, &sys->sys.rect_src_clipped) ||
+        !RectEquals(&before_dest_clipped, &sys->sys.rect_dest_clipped) ||
+        !RectEquals(&before_dest, &sys->sys.rect_dest))
+    {
+        UpdateSize(vd);
+    }
+}
+
+static bool Resize(void *opaque, unsigned i_width, unsigned i_height)
+{
+    vout_display_t *vd = opaque;
+    vout_display_sys_t *sys = vd->sys;
+    ID3D11Texture2D* pBackBuffer;
+    HRESULT hr;
+
     D3D11_TEXTURE2D_DESC dsc = { 0 };
 
     if (sys->swapchainTargetView[0]) {
@@ -257,7 +311,7 @@ static HRESULT UpdateBackBuffer(vout_display_t *vd)
     }
 
     if (dsc.Width == i_width && dsc.Height == i_height)
-        return S_OK; /* nothing changed */
+        return true; /* nothing changed */
 
     for (size_t i=0; i < D3D11_MAX_SHADER_VIEW; i++)
     {
@@ -272,13 +326,13 @@ static HRESULT UpdateBackBuffer(vout_display_t *vd)
         DXGI_FORMAT_UNKNOWN, 0);
     if (FAILED(hr)) {
        msg_Err(vd, "Failed to resize the backbuffer. (hr=0x%lX)", hr);
-       return hr;
+       return false;
     }
 
     hr = IDXGISwapChain_GetBuffer(sys->dxgiswapChain, 0, &IID_ID3D11Texture2D, (LPVOID *)&pBackBuffer);
     if (FAILED(hr)) {
        msg_Err(vd, "Could not get the backbuffer for the Swapchain. (hr=0x%lX)", hr);
-       return hr;
+       return false;
     }
 
     hr = D3D11_CreateRenderTargets( &sys->d3d_dev, (ID3D11Resource *)pBackBuffer,
@@ -286,46 +340,37 @@ static HRESULT UpdateBackBuffer(vout_display_t *vd)
     ID3D11Texture2D_Release(pBackBuffer);
     if (FAILED(hr)) {
         msg_Err(vd, "Failed to create the target view. (hr=0x%lX)", hr);
-        return hr;
+        return false;
     }
 
     D3D11_ClearRenderTargets( &sys->d3d_dev, sys->display.pixelFormat, sys->swapchainTargetView );
 
-    return S_OK;
+    return true;
 }
 
-static void UpdateSize(vout_display_t *vd)
+static bool StartRendering(void *opaque)
 {
+    vout_display_t *vd = opaque;
     vout_display_sys_t *sys = vd->sys;
-    msg_Dbg(vd, "Detected size change %dx%d", RECTWidth(sys->sys.rect_dest_clipped),
-            RECTHeight(sys->sys.rect_dest_clipped));
-
-    UpdateBackBuffer(vd);
-
-    d3d11_device_lock( &sys->d3d_dev );
 
-    UpdatePicQuadPosition(vd);
-
-    D3D11_UpdateQuadPosition(vd, &sys->d3d_dev, &sys->picQuad, &sys->sys.rect_src_clipped,
-                             vd->source.orientation);
+    Manage(vd);
 
-    d3d11_device_unlock( &sys->d3d_dev );
+    D3D11_ClearRenderTargets( &sys->d3d_dev, sys->display.pixelFormat, sys->swapchainTargetView );
+    return true;
 }
 
-static void Manage(vout_display_t *vd)
+static void Swap(void *opaque)
 {
+    vout_display_t *vd = opaque;
     vout_display_sys_t *sys = vd->sys;
-    RECT before_src_clipped  = sys->sys.rect_src_clipped;
-    RECT before_dest_clipped = sys->sys.rect_dest_clipped;
-    RECT before_dest         = sys->sys.rect_dest;
 
-    CommonManage(vd);
+    DXGI_PRESENT_PARAMETERS presentParams = { 0 };
 
-    if (!RectEquals(&before_src_clipped, &sys->sys.rect_src_clipped) ||
-        !RectEquals(&before_dest_clipped, &sys->sys.rect_dest_clipped) ||
-        !RectEquals(&before_dest, &sys->sys.rect_dest))
+    HRESULT hr = IDXGISwapChain1_Present1(sys->dxgiswapChain, 0, 0, &presentParams);
+    if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET)
     {
-        UpdateSize(vd);
+        /* TODO device lost */
+        msg_Err(vd, "SwapChain Present failed. (hr=0x%lX)", hr);
     }
 }
 
@@ -377,6 +422,15 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
     sys->sys.pf_GetPictureWidth  = GetPictureWidth;
     sys->sys.pf_GetPictureHeight = GetPictureHeight;
 
+    if (!sys->swapCb || !sys->starRenderCb || !sys->endRenderCb || !sys->resizeCb)
+    {
+        sys->outside_opaque = vd;
+        sys->swapCb       = Swap;
+        sys->starRenderCb = StartRendering;
+        sys->endRenderCb  = NULL;
+        sys->resizeCb     = Resize;
+    }
+
     if (Direct3D11Open(vd, fmtp)) {
         msg_Err(vd, "Direct3D11 could not be opened");
         assert(!vd->info.is_slow); /* vd->info was not modified */
@@ -924,12 +978,15 @@ static void Prepare(vout_display_t *vd, picture_t *picture,
 {
     vout_display_sys_t *sys = vd->sys;
 
-    Manage(vd);
     VLC_UNUSED(date);
 
-    D3D11_ClearRenderTargets( &sys->d3d_dev, sys->display.pixelFormat, sys->swapchainTargetView );
+    if (sys->starRenderCb(sys->outside_opaque))
+    {
+        PreparePicture(vd, picture, subpicture);
 
-    PreparePicture(vd, picture, subpicture);
+        if (sys->endRenderCb)
+            sys->endRenderCb(sys->outside_opaque);
+    }
 }
 
 static void Display(vout_display_t *vd, picture_t *picture)
@@ -937,15 +994,8 @@ static void Display(vout_display_t *vd, picture_t *picture)
     vout_display_sys_t *sys = vd->sys;
     VLC_UNUSED(picture);
 
-    DXGI_PRESENT_PARAMETERS presentParams;
-    memset(&presentParams, 0, sizeof(presentParams));
     d3d11_device_lock( &sys->d3d_dev );
-    HRESULT hr = IDXGISwapChain1_Present1(sys->dxgiswapChain, 0, 0, &presentParams);
-    if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET)
-    {
-        /* TODO device lost */
-        msg_Err(vd, "SwapChain Present failed. (hr=0x%lX)", hr);
-    }
+    sys->swapCb(sys->outside_opaque);
     d3d11_device_unlock( &sys->d3d_dev );
 
     CommonDisplay(vd);



More information about the vlc-commits mailing list