[vlc-devel] [PATCH 12/14] direct3d9: remove the d3dctx structure

Steve Lhomme robux4 at videolabs.io
Sat Nov 18 14:26:45 CET 2017


Just use d3d9_handle_t and d3d9_device_t
---
 modules/video_output/win32/direct3d9.c | 75 +++++++++++++++-------------------
 1 file changed, 34 insertions(+), 41 deletions(-)

diff --git a/modules/video_output/win32/direct3d9.c b/modules/video_output/win32/direct3d9.c
index 88e40a07c0..7392f17712 100644
--- a/modules/video_output/win32/direct3d9.c
+++ b/modules/video_output/win32/direct3d9.c
@@ -127,12 +127,6 @@ typedef struct
     uint32_t     bmask;
 } d3d_format_t;
 
-struct d3dctx
-{
-    d3d9_handle_t           hd3d;
-    d3d9_device_t           d3d_dev;
-};
-
 struct vout_display_sys_t
 {
     vout_display_sys_win32_t sys;
@@ -146,9 +140,10 @@ struct vout_display_sys_t
     vout_display_cfg_t cfg_saved; /* configuration used before going into desktop mode */
 
     // core objects
-    struct d3dctx           d3dctx;
+    d3d9_handle_t           hd3d;
     HINSTANCE               hxdll;      /* handle of the opened d3d9x dll */
     IDirect3DPixelShader9*  d3dx_shader;
+    d3d9_device_t           d3d_dev;
 
     // scene objects
     LPDIRECT3DTEXTURE9      d3dtex;
@@ -263,7 +258,7 @@ static int Open(vlc_object_t *object)
     if (!sys)
         return VLC_ENOMEM;
 
-    if (D3D9_Create(vd, &sys->d3dctx.hd3d)) {
+    if (D3D9_Create(vd, &sys->hd3d)) {
         msg_Err(vd, "Direct3D9 could not be initialized");
         free(sys);
         return VLC_EGENERIC;
@@ -302,11 +297,11 @@ static int Open(vlc_object_t *object)
     info.has_pictures_invalid = !is_d3d9_opaque(fmt.i_chroma);
     if (var_InheritBool(vd, "direct3d9-hw-blending") &&
         sys->d3dregion_format != D3DFMT_UNKNOWN &&
-        (sys->d3dctx.d3d_dev.caps.SrcBlendCaps  & D3DPBLENDCAPS_SRCALPHA) &&
-        (sys->d3dctx.d3d_dev.caps.DestBlendCaps & D3DPBLENDCAPS_INVSRCALPHA) &&
-        (sys->d3dctx.d3d_dev.caps.TextureCaps   & D3DPTEXTURECAPS_ALPHA) &&
-        (sys->d3dctx.d3d_dev.caps.TextureOpCaps & D3DTEXOPCAPS_SELECTARG1) &&
-        (sys->d3dctx.d3d_dev.caps.TextureOpCaps & D3DTEXOPCAPS_MODULATE))
+        (sys->d3d_dev.caps.SrcBlendCaps  & D3DPBLENDCAPS_SRCALPHA) &&
+        (sys->d3d_dev.caps.DestBlendCaps & D3DPBLENDCAPS_INVSRCALPHA) &&
+        (sys->d3d_dev.caps.TextureCaps   & D3DPTEXTURECAPS_ALPHA) &&
+        (sys->d3d_dev.caps.TextureOpCaps & D3DTEXOPCAPS_SELECTARG1) &&
+        (sys->d3d_dev.caps.TextureOpCaps & D3DTEXOPCAPS_MODULATE))
         info.subpicture_chromas = d3d_subpicture_chromas;
     else
         info.subpicture_chromas = NULL;
@@ -487,7 +482,7 @@ static picture_pool_t *DisplayPool(vout_display_t *vd, unsigned count)
 {
     if ( vd->sys->sys.pool != NULL )
         return vd->sys->sys.pool;
-    vd->sys->sys.pool = Direct3D9CreatePicturePool(VLC_OBJECT(vd), &vd->sys->d3dctx.d3d_dev,
+    vd->sys->sys.pool = Direct3D9CreatePicturePool(VLC_OBJECT(vd), &vd->sys->d3d_dev,
         vd->sys->d3dtexture_format, &vd->fmt, count);
     return vd->sys->sys.pool;
 }
@@ -496,7 +491,7 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic
 {
     vout_display_sys_t *sys = vd->sys;
     LPDIRECT3DSURFACE9 surface = picture->p_sys->surface;
-    d3d9_device_t *p_d3d9_dev = &sys->d3dctx.d3d_dev;
+    d3d9_device_t *p_d3d9_dev = &sys->d3d_dev;
 
     /* FIXME it is a bit ugly, we need the surface to be unlocked for
      * rendering.
@@ -560,7 +555,7 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic
 static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
 {
     vout_display_sys_t *sys = vd->sys;
-    const d3d9_device_t *p_d3d9_dev = &sys->d3dctx.d3d_dev;
+    const d3d9_device_t *p_d3d9_dev = &sys->d3d_dev;
 
     if (sys->lost_not_ready) {
         picture_Release(picture);
@@ -575,7 +570,7 @@ static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpic
     const RECT dst = sys->sys.rect_dest_clipped;
 
     HRESULT hr;
-    if (sys->d3dctx.hd3d.use_ex) {
+    if (sys->hd3d.use_ex) {
         hr = IDirect3DDevice9Ex_PresentEx(p_d3d9_dev->devex, &src, &dst, NULL, NULL, 0);
     } else {
         hr = IDirect3DDevice9_Present(p_d3d9_dev->dev, &src, &dst, NULL, NULL);
@@ -719,7 +714,7 @@ static void Manage (vout_display_t *vd)
         width  = rect.right-rect.left;
         height = rect.bottom-rect.top;
 
-        if (width != p_sys->d3dctx.pp.BackBufferWidth || height != p_sys->d3dctx.pp.BackBufferHeight)
+        if (width != p_sys->pp.BackBufferWidth || height != p_sys->pp.BackBufferHeight)
         {
             msg_Dbg(vd, "resizing device back buffers to (%lux%lu)", width, height);
             // need to reset D3D device to resize back buffer
@@ -737,7 +732,7 @@ static void Manage (vout_display_t *vd)
  */
 static void Direct3D9Destroy(vout_display_sys_t *sys)
 {
-    D3D9_Destroy( &sys->d3dctx.hd3d );
+    D3D9_Destroy( &sys->hd3d );
 
     if (sys->hxdll)
     {
@@ -757,11 +752,11 @@ static int Direct3D9Open(vout_display_t *vd, video_format_t *fmt)
 {
     vout_display_sys_t *sys = vd->sys;
 
-    if (FAILED(D3D9_CreateDevice(vd, &sys->d3dctx.hd3d, sys->sys.hvideownd,
-                                 &vd->source, &sys->d3dctx.d3d_dev)))
+    if (FAILED(D3D9_CreateDevice(vd, &sys->hd3d, sys->sys.hvideownd,
+                                 &vd->source, &sys->d3d_dev)))
         return VLC_EGENERIC;
 
-    const d3d9_device_t *p_d3d9_dev = &sys->d3dctx.d3d_dev;
+    const d3d9_device_t *p_d3d9_dev = &sys->d3d_dev;
     /* */
     RECT *display = &vd->sys->sys.rect_display;
     display->left   = 0;
@@ -799,7 +794,7 @@ static int Direct3D9Open(vout_display_t *vd, video_format_t *fmt)
     return VLC_SUCCESS;
 
 error:
-    D3D9_ReleaseDevice(&sys->d3dctx.d3d_dev);
+    D3D9_ReleaseDevice(&sys->d3d_dev);
     return VLC_EGENERIC;
 }
 
@@ -811,7 +806,7 @@ static void Direct3D9Close(vout_display_t *vd)
     vout_display_sys_t *sys = vd->sys;
 
     Direct3D9DestroyResources(vd);
-    D3D9_ReleaseDevice(&sys->d3dctx.d3d_dev);
+    D3D9_ReleaseDevice(&sys->d3d_dev);
 }
 
 /**
@@ -820,10 +815,9 @@ static void Direct3D9Close(vout_display_t *vd)
 static int Direct3D9Reset(vout_display_t *vd)
 {
     vout_display_sys_t *sys = vd->sys;
-    struct d3dctx *d3dctx = &sys->d3dctx;
-    d3d9_device_t *p_d3d9_dev = &d3dctx->d3d_dev;
+    d3d9_device_t *p_d3d9_dev = &sys->d3d_dev;
 
-    if (D3D9_FillPresentationParameters(VLC_OBJECT(vd), &d3dctx->hd3d, p_d3d9_dev->adapterId, &vd->source, &d3dctx->d3d_dev))
+    if (D3D9_FillPresentationParameters(VLC_OBJECT(vd), &sys->hd3d, p_d3d9_dev->adapterId, &vd->source, p_d3d9_dev))
         return VLC_EGENERIC;
 
     /* release all D3D objects */
@@ -831,7 +825,7 @@ static int Direct3D9Reset(vout_display_t *vd)
 
     /* */
     HRESULT hr;
-    if (d3dctx->hd3d.use_ex){
+    if (sys->hd3d.use_ex){
         hr = IDirect3DDevice9Ex_ResetEx(p_d3d9_dev->devex, &p_d3d9_dev->pp, NULL);
     } else {
         hr = IDirect3DDevice9_Reset(p_d3d9_dev->dev, &p_d3d9_dev->pp);
@@ -864,7 +858,6 @@ static void Direct3D9DestroyShaders(vout_display_t *vd);
 static int Direct3D9CreateResources(vout_display_t *vd, video_format_t *fmt)
 {
     vout_display_sys_t *sys = vd->sys;
-    struct d3dctx *d3dctx = &sys->d3dctx;
 
     if (Direct3D9CreateScene(vd, fmt)) {
         msg_Err(vd, "Direct3D scene initialization failed !");
@@ -878,10 +871,10 @@ static int Direct3D9CreateResources(vout_display_t *vd, video_format_t *fmt)
     sys->d3dregion_format = D3DFMT_UNKNOWN;
     for (int i = 0; i < 2; i++) {
         D3DFORMAT dfmt = i == 0 ? D3DFMT_A8B8G8R8 : D3DFMT_A8R8G8B8;
-        if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3dctx->hd3d.obj,
+        if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(sys->hd3d.obj,
                                                    D3DADAPTER_DEFAULT,
                                                    D3DDEVTYPE_HAL,
-                                                   d3dctx->d3d_dev.pp.BackBufferFormat,
+                                                   sys->d3d_dev.pp.BackBufferFormat,
                                                    D3DUSAGE_DYNAMIC,
                                                    D3DRTYPE_TEXTURE,
                                                    dfmt))) {
@@ -912,7 +905,7 @@ static int Direct3D9CheckConversion(vout_display_t *vd,
                                    D3DFORMAT src, D3DFORMAT dst)
 {
     vout_display_sys_t *sys = vd->sys;
-    LPDIRECT3D9 d3dobj = sys->d3dctx.hd3d.obj;
+    LPDIRECT3D9 d3dobj = sys->hd3d.obj;
     HRESULT hr;
 
     /* test whether device can create a surface of that format */
@@ -1003,7 +996,7 @@ static const d3d_format_t *Direct3DFindFormat(vout_display_t *vd, vlc_fourcc_t c
 static int Direct3D9CreateScene(vout_display_t *vd, const video_format_t *fmt)
 {
     vout_display_sys_t *sys = vd->sys;
-    const d3d9_device_t *p_d3d9_dev = &sys->d3dctx.d3d_dev;
+    const d3d9_device_t *p_d3d9_dev = &sys->d3d_dev;
     LPDIRECT3DDEVICE9       d3ddev = p_d3d9_dev->dev;
     HRESULT hr;
 
@@ -1064,14 +1057,14 @@ static int Direct3D9CreateScene(vout_display_t *vd, const video_format_t *fmt)
     IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
 
     // Set linear filtering quality
-    if (sys->d3dctx.d3d_dev.caps.TextureFilterCaps & D3DPTFILTERCAPS_MINFLINEAR) {
+    if (sys->d3d_dev.caps.TextureFilterCaps & D3DPTFILTERCAPS_MINFLINEAR) {
         //msg_Dbg(vd, "Using D3DTEXF_LINEAR for minification");
         IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
     } else {
         //msg_Dbg(vd, "Using D3DTEXF_POINT for minification");
         IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
     }
-    if (sys->d3dctx.d3d_dev.caps.TextureFilterCaps & D3DPTFILTERCAPS_MAGFLINEAR) {
+    if (sys->d3d_dev.caps.TextureFilterCaps & D3DPTFILTERCAPS_MAGFLINEAR) {
         //msg_Dbg(vd, "Using D3DTEXF_LINEAR for magnification");
         IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
     } else {
@@ -1102,7 +1095,7 @@ static int Direct3D9CreateScene(vout_display_t *vd, const video_format_t *fmt)
     IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
     IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
 
-    if (sys->d3dctx.d3d_dev.caps.AlphaCmpCaps & D3DPCMPCAPS_GREATER) {
+    if (sys->d3d_dev.caps.AlphaCmpCaps & D3DPCMPCAPS_GREATER) {
         IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHATESTENABLE,TRUE);
         IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHAREF, 0x00);
         IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHAFUNC,D3DCMP_GREATER);
@@ -1186,7 +1179,7 @@ static int Direct3D9CompileShader(vout_display_t *vd, const char *shader_source,
         return VLC_EGENERIC;
     }
 
-    hr = IDirect3DDevice9_CreatePixelShader(sys->d3dctx.d3d_dev.dev,
+    hr = IDirect3DDevice9_CreatePixelShader(sys->d3d_dev.dev,
             ID3DXBuffer_GetBufferPointer(compiled_shader),
             &sys->d3dx_shader);
 
@@ -1446,7 +1439,7 @@ static int Direct3D9ImportPicture(vout_display_t *vd,
     if ( copy_rect.left & 1 ) copy_rect.left--;
     if ( copy_rect.bottom & 1 ) copy_rect.bottom++;
     if ( copy_rect.top & 1 ) copy_rect.top--;
-    hr = IDirect3DDevice9_StretchRect(sys->d3dctx.d3d_dev.dev, source, &copy_rect, destination,
+    hr = IDirect3DDevice9_StretchRect(sys->d3d_dev.dev, source, &copy_rect, destination,
                                       &copy_rect, D3DTEXF_NONE);
     IDirect3DSurface9_Release(destination);
     if (FAILED(hr)) {
@@ -1509,7 +1502,7 @@ static void Direct3D9ImportSubpicture(vout_display_t *vd,
             d3dr->format = sys->d3dregion_format;
             d3dr->width  = r->fmt.i_width;
             d3dr->height = r->fmt.i_height;
-            hr = IDirect3DDevice9_CreateTexture(sys->d3dctx.d3d_dev.dev,
+            hr = IDirect3DDevice9_CreateTexture(sys->d3d_dev.dev,
                                                 d3dr->width, d3dr->height,
                                                 1,
                                                 D3DUSAGE_DYNAMIC,
@@ -1598,7 +1591,7 @@ static int Direct3D9RenderRegion(vout_display_t *vd,
 {
     vout_display_sys_t *sys = vd->sys;
 
-    LPDIRECT3DDEVICE9 d3ddev = vd->sys->d3dctx.d3d_dev.dev;
+    LPDIRECT3DDEVICE9 d3ddev = vd->sys->d3d_dev.dev;
 
     LPDIRECT3DVERTEXBUFFER9 d3dvtc = sys->d3dvtc;
     LPDIRECT3DTEXTURE9      d3dtex = region->texture;
@@ -1683,7 +1676,7 @@ static void Direct3D9RenderScene(vout_display_t *vd,
                                 d3d_region_t *subpicture)
 {
     vout_display_sys_t *sys = vd->sys;
-    LPDIRECT3DDEVICE9 d3ddev = sys->d3dctx.d3d_dev.dev;
+    LPDIRECT3DDEVICE9 d3ddev = sys->d3d_dev.dev;
     HRESULT hr;
 
     if (sys->clear_scene) {
-- 
2.14.2



More information about the vlc-devel mailing list