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

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


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Thu Nov 15 11:25:52 2018 +0100| [f19bef67c35ff978c0694ff59f23d4adf9fc6789] | committer: Steve Lhomme

direct3d9: move some of the rendering calls into callbacks

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

 modules/video_output/win32/direct3d9.c | 86 +++++++++++++++++++++++++---------
 1 file changed, 64 insertions(+), 22 deletions(-)

diff --git a/modules/video_output/win32/direct3d9.c b/modules/video_output/win32/direct3d9.c
index 1c859b6805..639e5ddd96 100644
--- a/modules/video_output/win32/direct3d9.c
+++ b/modules/video_output/win32/direct3d9.c
@@ -166,6 +166,12 @@ struct vout_display_sys_t
     vlc_mutex_t    lock;
     bool           ch_desktop;
     bool           desktop_requested;
+
+    /* outside rendering */
+    void *outside_opaque;
+    void (*swapCb)(void* opaque);
+    void (*endRenderCb)(void* opaque);
+    bool (*starRenderCb)(void* opaque);
 };
 
 /* */
@@ -1137,17 +1143,9 @@ static int Direct3D9RenderRegion(vout_display_t *vd,
     return 0;
 }
 
-/**
- * It renders the scene.
- *
- * This function is intented for higher end 3D cards, with pixel shader support
- * and at least 64 MiB of video RAM.
- */
-static void Direct3D9RenderScene(vout_display_t *vd,
-                                d3d_region_t *picture,
-                                size_t subpicture_count,
-                                d3d_region_t *subpicture)
+static bool StartRendering(void *opaque)
 {
+    vout_display_t *vd = opaque;
     vout_display_sys_t *sys = vd->sys;
     IDirect3DDevice9 *d3ddev = sys->d3d_dev.dev;
     HRESULT hr;
@@ -1158,7 +1156,7 @@ static void Direct3D9RenderScene(vout_display_t *vd,
                                   D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
         if (FAILED(hr)) {
             msg_Dbg(vd, "Failed Clear: 0x%0lx", hr);
-            return;
+            return false;
         }
         sys->clear_scene = false;
     }
@@ -1167,8 +1165,40 @@ static void Direct3D9RenderScene(vout_display_t *vd,
     hr = IDirect3DDevice9_BeginScene(d3ddev);
     if (FAILED(hr)) {
         msg_Dbg(vd, "Failed BeginScene: 0x%0lx", hr);
-        return;
+        return false;
     }
+    return true;
+}
+
+static void EndRendering(void *opaque)
+{
+    vout_display_t *vd = opaque;
+    vout_display_sys_t *sys = vd->sys;
+    IDirect3DDevice9 *d3ddev = sys->d3d_dev.dev;
+    HRESULT hr;
+
+    // End the scene
+    hr = IDirect3DDevice9_EndScene(d3ddev);
+    if (FAILED(hr))
+        msg_Dbg(vd, "Failed EndScene: 0x%0lx", hr);
+}
+
+/**
+ * It renders the scene.
+ *
+ * This function is intented for higher end 3D cards, with pixel shader support
+ * and at least 64 MiB of video RAM.
+ */
+static void Direct3D9RenderScene(vout_display_t *vd,
+                                d3d_region_t *picture,
+                                size_t subpicture_count,
+                                d3d_region_t *subpicture)
+{
+    vout_display_sys_t *sys = vd->sys;
+    IDirect3DDevice9 *d3ddev = sys->d3d_dev.dev;
+
+    if (!sys->starRenderCb(sys->outside_opaque))
+        return;
 
     Direct3D9RenderRegion(vd, picture, true);
 
@@ -1183,12 +1213,7 @@ static void Direct3D9RenderScene(vout_display_t *vd,
         IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHABLENDENABLE, FALSE);
     }
 
-    // End the scene
-    hr = IDirect3DDevice9_EndScene(d3ddev);
-    if (FAILED(hr)) {
-        msg_Dbg(vd, "Failed EndScene: 0x%0lx", hr);
-        return;
-    }
+    sys->endRenderCb(sys->outside_opaque);
 }
 
 static void Prepare(vout_display_t *vd, picture_t *picture,
@@ -1270,14 +1295,12 @@ static void Prepare(vout_display_t *vd, picture_t *picture,
     }
 }
 
-static void Display(vout_display_t *vd, picture_t *picture)
+static void Swap(void *opaque)
 {
+    vout_display_t *vd = opaque;
     vout_display_sys_t *sys = vd->sys;
     const d3d9_device_t *p_d3d9_dev = &sys->d3d_dev;
 
-    if (sys->lost_not_ready)
-        return;
-
     // Present the back buffer contents to the display
     // No stretching should happen here !
     const RECT src = sys->sys.rect_dest_clipped;
@@ -1292,6 +1315,16 @@ static void Display(vout_display_t *vd, picture_t *picture)
     if (FAILED(hr)) {
         msg_Dbg(vd, "Failed Present: 0x%0lx", hr);
     }
+}
+
+static void Display(vout_display_t *vd, picture_t *picture)
+{
+    vout_display_sys_t *sys = vd->sys;
+
+    if (sys->lost_not_ready)
+        return;
+
+    sys->swapCb(sys->outside_opaque);
 
     /* XXX See Prepare() */
     if ( !is_d3d9_opaque(picture->format.i_chroma) )
@@ -1674,6 +1707,15 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
         return VLC_EGENERIC;
     }
 
+    if (!sys->swapCb || !sys->starRenderCb || !sys->endRenderCb)
+    {
+        /* use our own callbacks, since there isn't any external ones */
+        sys->outside_opaque = vd;
+        sys->swapCb         = Swap;
+        sys->starRenderCb   = StartRendering;
+        sys->endRenderCb    = EndRendering;
+    }
+
     sys->hxdll = Direct3D9LoadShaderLibrary();
     if (!sys->hxdll)
         msg_Warn(vd, "cannot load Direct3D9 Shader Library; HLSL pixel shading will be disabled.");



More information about the vlc-commits mailing list