[vlc-commits] d3d9_fmt: move the code to reset the D3D9 device

Steve Lhomme git at videolan.org
Wed Mar 4 16:06:40 CET 2020


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Mon Mar  2 17:05:48 2020 +0100| [5fbc2a6bec6af7ea1b1d5ceb92b72eecda145425] | committer: Steve Lhomme

d3d9_fmt: move the code to reset the D3D9 device

So we don't have to share the D3D9_FillPresentationParameters function.

+ cleaning of the cleaning functions

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

 modules/video_chroma/d3d9_fmt.c        | 92 +++++++++++++++++++++-------------
 modules/video_chroma/d3d9_fmt.h        |  2 +-
 modules/video_output/win32/direct3d9.c | 32 +++---------
 3 files changed, 67 insertions(+), 59 deletions(-)

diff --git a/modules/video_chroma/d3d9_fmt.c b/modules/video_chroma/d3d9_fmt.c
index 730a5b7a00..fed4831757 100644
--- a/modules/video_chroma/d3d9_fmt.c
+++ b/modules/video_chroma/d3d9_fmt.c
@@ -52,6 +52,63 @@ typedef struct {
     d3d9_decoder_device_t           dec_device;
 } d3d9_decoder_device;
 
+/**
+ * It setup vout_display_sys_t::d3dpp and vout_display_sys_t::rect_display
+ * from the default adapter.
+ */
+static HRESULT FillPresentationParameters(const d3d9_decoder_device_t *dec_dev,
+                                    D3DPRESENT_PARAMETERS *d3dpp)
+{
+    /*
+    ** Get the current desktop display mode, so we can set up a back
+    ** buffer of the same format
+    */
+    D3DDISPLAYMODE d3ddm;
+    HRESULT hr = IDirect3D9_GetAdapterDisplayMode(dec_dev->hd3d.obj, dec_dev->d3ddev.adapterId, &d3ddm);
+    if (FAILED(hr))
+        return hr;
+
+    /* Set up the structure used to create the D3DDevice. */
+    ZeroMemory(d3dpp, sizeof(D3DPRESENT_PARAMETERS));
+    d3dpp->Flags                  = D3DPRESENTFLAG_VIDEO;
+    d3dpp->Windowed               = TRUE;
+    d3dpp->MultiSampleType        = D3DMULTISAMPLE_NONE;
+    d3dpp->PresentationInterval   = D3DPRESENT_INTERVAL_DEFAULT;
+    d3dpp->EnableAutoDepthStencil = FALSE;
+    d3dpp->hDeviceWindow          = NULL;
+    d3dpp->SwapEffect             = D3DSWAPEFFECT_COPY;
+    d3dpp->BackBufferFormat       = d3ddm.Format;
+    d3dpp->BackBufferCount        = 1;
+    d3dpp->BackBufferWidth        = GetSystemMetrics(SM_CXVIRTUALSCREEN);
+    d3dpp->BackBufferHeight       = GetSystemMetrics(SM_CYVIRTUALSCREEN);
+
+    return D3D_OK;
+}
+
+int D3D9_ResetDevice(vlc_object_t *o, d3d9_decoder_device_t *dec_dev)
+{
+    D3DPRESENT_PARAMETERS d3dpp;
+    if (FAILED(FillPresentationParameters(dec_dev, &d3dpp)))
+    {
+        msg_Err(o, "Could not get presentation parameters to reset device");
+        return VLC_EGENERIC;
+    }
+
+    /* */
+    HRESULT hr;
+    if (dec_dev->hd3d.use_ex){
+        hr = IDirect3DDevice9Ex_ResetEx(dec_dev->d3ddev.devex, &d3dpp, NULL);
+    } else {
+        hr = IDirect3DDevice9_Reset(dec_dev->d3ddev.dev, &d3dpp);
+    }
+    if (FAILED(hr)) {
+        msg_Err(o, "IDirect3DDevice9_Reset failed! (hr=0x%lX)", hr);
+        return VLC_EGENERIC;
+    }
+    dec_dev->d3ddev.BufferFormat = d3dpp.BackBufferFormat;
+    return VLC_SUCCESS;
+}
+
 static void D3D9_Destroy(d3d9_handle_t *hd3d)
 {
     if (hd3d->obj)
@@ -207,7 +264,7 @@ d3d9_handle_t *hd3d = &sys->dec_device.hd3d;
     out->adapterId = AdapterToUse;
     /* TODO only create a device for the decoder dimensions */
     D3DPRESENT_PARAMETERS d3dpp;
-    if (D3D9_FillPresentationParameters(&sys->dec_device, &d3dpp))
+    if (FAILED(FillPresentationParameters(&sys->dec_device, &d3dpp)))
     {
         msg_Err(o, "Could not get presentation parameters");
         goto error;
@@ -271,39 +328,6 @@ void D3D9_ReleaseDevice(d3d9_decoder_device_t *dec_dev)
         sys->cleanupDeviceCb( sys->opaque );
 }
 
-/**
- * It setup vout_display_sys_t::d3dpp and vout_display_sys_t::rect_display
- * from the default adapter.
- */
-int D3D9_FillPresentationParameters(const d3d9_decoder_device_t *dec_dev,
-                                    D3DPRESENT_PARAMETERS *d3dpp)
-{
-    /*
-    ** Get the current desktop display mode, so we can set up a back
-    ** buffer of the same format
-    */
-    D3DDISPLAYMODE d3ddm;
-    HRESULT hr = IDirect3D9_GetAdapterDisplayMode(dec_dev->hd3d.obj, dec_dev->d3ddev.adapterId, &d3ddm);
-    if (FAILED(hr))
-        return VLC_EGENERIC;
-
-    /* Set up the structure used to create the D3DDevice. */
-    ZeroMemory(d3dpp, sizeof(D3DPRESENT_PARAMETERS));
-    d3dpp->Flags                  = D3DPRESENTFLAG_VIDEO;
-    d3dpp->Windowed               = TRUE;
-    d3dpp->MultiSampleType        = D3DMULTISAMPLE_NONE;
-    d3dpp->PresentationInterval   = D3DPRESENT_INTERVAL_DEFAULT;
-    d3dpp->EnableAutoDepthStencil = FALSE;
-    d3dpp->hDeviceWindow          = NULL;
-    d3dpp->SwapEffect             = D3DSWAPEFFECT_COPY;
-    d3dpp->BackBufferFormat       = d3ddm.Format;
-    d3dpp->BackBufferCount        = 1;
-    d3dpp->BackBufferWidth        = GetSystemMetrics(SM_CXVIRTUALSCREEN);
-    d3dpp->BackBufferHeight       = GetSystemMetrics(SM_CYVIRTUALSCREEN);
-
-    return VLC_SUCCESS;
-}
-
 const struct vlc_video_context_operations d3d9_vctx_ops = {
     NULL,
 };
diff --git a/modules/video_chroma/d3d9_fmt.h b/modules/video_chroma/d3d9_fmt.h
index 396872357f..727b4ac692 100644
--- a/modules/video_chroma/d3d9_fmt.h
+++ b/modules/video_chroma/d3d9_fmt.h
@@ -139,7 +139,7 @@ d3d9_decoder_device_t *D3D9_CreateDevice(vlc_object_t *);
 
 void D3D9_ReleaseDevice(d3d9_decoder_device_t *);
 
-int D3D9_FillPresentationParameters(const d3d9_decoder_device_t *, D3DPRESENT_PARAMETERS *);
+int D3D9_ResetDevice(vlc_object_t *, d3d9_decoder_device_t *);
 
 void d3d9_pic_context_destroy(picture_context_t *);
 picture_context_t *d3d9_pic_context_copy(picture_context_t *);
diff --git a/modules/video_output/win32/direct3d9.c b/modules/video_output/win32/direct3d9.c
index 02a82dd7a9..e724e4af16 100644
--- a/modules/video_output/win32/direct3d9.c
+++ b/modules/video_output/win32/direct3d9.c
@@ -427,6 +427,8 @@ static void Direct3D9DestroyScene(vout_display_t *vd)
     vout_display_sys_t *sys = vd->sys;
 
     Direct3D9DeleteRegions(sys->d3dregion_count, sys->d3dregion);
+    sys->d3dregion_count = 0;
+    sys->d3dregion       = NULL;
 
     if (sys->sceneVertexBuffer)
     {
@@ -440,9 +442,6 @@ static void Direct3D9DestroyScene(vout_display_t *vd)
         sys->sceneTexture = NULL;
     }
 
-    sys->d3dregion_count = 0;
-    sys->d3dregion       = NULL;
-
     msg_Dbg(vd, "Direct3D9 scene released successfully");
 }
 
@@ -451,8 +450,10 @@ static void Direct3D9DestroyShaders(vout_display_t *vd)
     vout_display_sys_t *sys = vd->sys;
 
     if (sys->d3dx_shader)
+    {
         IDirect3DPixelShader9_Release(sys->d3dx_shader);
-    sys->d3dx_shader = NULL;
+        sys->d3dx_shader = NULL;
+    }
 }
 
 /**
@@ -845,31 +846,14 @@ static int Direct3D9CreateResources(vout_display_t *vd, const video_format_t *fm
 static int Direct3D9Reset(vout_display_t *vd, const video_format_t *fmtp)
 {
     vout_display_sys_t *sys = vd->sys;
-    d3d9_device_t *p_d3d9_dev = &sys->d3d9_device->d3ddev;
 
-    D3DPRESENT_PARAMETERS d3dpp;
-    if (D3D9_FillPresentationParameters(sys->d3d9_device, &d3dpp))
-    {
-        msg_Err(vd, "Could not get presentation parameters to reset device");
-        return VLC_EGENERIC;
-    }
+    int res = D3D9_ResetDevice( VLC_OBJECT(vd), sys->d3d9_device );
+    if (res != VLC_SUCCESS)
+        return res;
 
     /* release all D3D objects */
     Direct3D9DestroyResources(vd);
 
-    /* */
-    HRESULT hr;
-    if (sys->d3d9_device->hd3d.use_ex){
-        hr = IDirect3DDevice9Ex_ResetEx(p_d3d9_dev->devex, &d3dpp, NULL);
-    } else {
-        hr = IDirect3DDevice9_Reset(p_d3d9_dev->dev, &d3dpp);
-    }
-    if (FAILED(hr)) {
-        msg_Err(vd, "IDirect3DDevice9_Reset failed! (hr=0x%lX)", hr);
-        return VLC_EGENERIC;
-    }
-    p_d3d9_dev->BufferFormat = d3dpp.BackBufferFormat;
-
     /* re-create them */
     if (Direct3D9CreateResources(vd, fmtp)) {
         msg_Dbg(vd, "Direct3D9CreateResources failed !");



More information about the vlc-commits mailing list