[vlc-devel] [PATCH 02/14] d3d9: move the device creation in libd3d9_common
Steve Lhomme
robux4 at videolabs.io
Sat Nov 18 14:26:35 CET 2017
---
modules/codec/Makefile.am | 11 ++-
modules/video_chroma/Makefile.am | 5 +-
modules/video_chroma/d3d9_fmt.c | 139 +++++++++++++++++++++++++++++++++
modules/video_chroma/d3d9_fmt.h | 19 +++--
modules/video_output/Makefile.am | 12 ++-
modules/video_output/win32/direct3d9.c | 115 ++-------------------------
6 files changed, 173 insertions(+), 128 deletions(-)
create mode 100644 modules/video_chroma/d3d9_fmt.c
diff --git a/modules/codec/Makefile.am b/modules/codec/Makefile.am
index c3188ce24e..c032a17830 100644
--- a/modules/codec/Makefile.am
+++ b/modules/codec/Makefile.am
@@ -422,11 +422,16 @@ endif
codec_LTLIBRARIES += libvaapi_plugin.la
endif
+libd3d9_common_la_SOURCES = video_chroma/d3d9_fmt.c video_chroma/d3d9_fmt.h
+libd3d9_common_la_LDFLAGS = -static
+if HAVE_WIN32_DESKTOP
+noinst_LTLIBRARIES += libd3d9_common.la
+endif
+
libdxva2_plugin_la_SOURCES = \
codec/avcodec/dxva2.c codec/avcodec/directx_va.c codec/avcodec/directx_va.h \
- codec/avcodec/va_surface.c codec/avcodec/va_surface.h codec/avcodec/va_surface_internal.h \
- video_chroma/d3d9_fmt.h
-libdxva2_plugin_la_LIBADD = libhxxx.la $(LIBCOM) -lshlwapi -luuid
+ codec/avcodec/va_surface.c codec/avcodec/va_surface.h codec/avcodec/va_surface_internal.h
+libdxva2_plugin_la_LIBADD = libhxxx.la libd3d9_common.la $(LIBCOM) -lshlwapi -luuid
if HAVE_AVCODEC_DXVA2
codec_LTLIBRARIES += libdxva2_plugin.la
endif
diff --git a/modules/video_chroma/Makefile.am b/modules/video_chroma/Makefile.am
index 27b472f363..c026d58b6b 100644
--- a/modules/video_chroma/Makefile.am
+++ b/modules/video_chroma/Makefile.am
@@ -118,9 +118,8 @@ chroma_LTLIBRARIES += \
endif
# DXVA2
-libdxa9_plugin_la_SOURCES = video_chroma/dxa9.c \
- video_chroma/d3d9_fmt.h
-libdxa9_plugin_la_LIBADD = libchroma_copy.la
+libdxa9_plugin_la_SOURCES = video_chroma/dxa9.c
+libdxa9_plugin_la_LIBADD = libd3d9_common.la libchroma_copy.la
if HAVE_AVCODEC_DXVA2
chroma_LTLIBRARIES += \
diff --git a/modules/video_chroma/d3d9_fmt.c b/modules/video_chroma/d3d9_fmt.c
new file mode 100644
index 0000000000..beae3c1066
--- /dev/null
+++ b/modules/video_chroma/d3d9_fmt.c
@@ -0,0 +1,139 @@
+/*****************************************************************************
+ * d3d9_fmt.c : D3D9 helper calls
+ *****************************************************************************
+ * Copyright © 2017 VLC authors, VideoLAN and VideoLabs
+ *
+ * Authors: Steve Lhomme <robux4 at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <assert.h>
+
+#include "d3d9_fmt.h"
+
+#include "../codec/avcodec/va_surface.h"
+
+picture_sys_t *ActivePictureSys(picture_t *p_pic)
+{
+ struct va_pic_context *pic_ctx = (struct va_pic_context*)p_pic->context;
+ return pic_ctx ? &pic_ctx->picsys : p_pic->p_sys;
+}
+
+#undef D3D9_CreateDevice
+HRESULT D3D9_CreateDevice(vlc_object_t *o, d3d9_handle_t *hd3d, HWND hwnd,
+ const video_format_t *source, const D3DCAPS9 *caps,
+ d3d9_device_t *out)
+{
+ HRESULT hr;
+
+ UINT AdapterToUse = D3DADAPTER_DEFAULT;
+ D3DDEVTYPE DeviceType = D3DDEVTYPE_HAL;
+
+#ifndef NDEBUG
+ // Look for 'NVIDIA PerfHUD' adapter
+ // If it is present, override default settings
+ for (UINT Adapter=0; Adapter< IDirect3D9_GetAdapterCount(hd3d->obj); ++Adapter) {
+ D3DADAPTER_IDENTIFIER9 Identifier;
+ hr = IDirect3D9_GetAdapterIdentifier(hd3d->obj,Adapter,0,&Identifier);
+ if (SUCCEEDED(hr) && strstr(Identifier.Description,"PerfHUD") != 0) {
+ AdapterToUse = Adapter;
+ DeviceType = D3DDEVTYPE_REF;
+ break;
+ }
+ }
+#endif
+
+ if (D3D9_FillPresentationParameters(o, hd3d, AdapterToUse, hwnd, source, out))
+ return E_INVALIDARG;
+
+ /* */
+ D3DADAPTER_IDENTIFIER9 d3dai;
+ if (FAILED(IDirect3D9_GetAdapterIdentifier(hd3d->obj, AdapterToUse,0, &d3dai))) {
+ msg_Warn(o, "IDirect3D9_GetAdapterIdentifier failed");
+ } else {
+ msg_Dbg(o, "Direct3d9 Device: %s %lu %lu %lu", d3dai.Description,
+ d3dai.VendorId, d3dai.DeviceId, d3dai.Revision );
+ }
+
+ DWORD creationFlags = D3DCREATE_MULTITHREADED;
+ if ( (caps->DevCaps & D3DDEVCAPS_DRAWPRIMTLVERTEX) &&
+ (caps->DevCaps & D3DDEVCAPS_HWRASTERIZATION) ) {
+ creationFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
+ } else if (caps->DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) {
+ creationFlags |= D3DCREATE_MIXED_VERTEXPROCESSING;
+ } else {
+ creationFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
+ }
+
+ if (hd3d->use_ex)
+ hr = IDirect3D9Ex_CreateDeviceEx(hd3d->objex, AdapterToUse,
+ DeviceType, hwnd,
+ creationFlags,
+ &out->pp, NULL, &out->devex);
+ else
+ hr = IDirect3D9_CreateDevice(hd3d->obj, AdapterToUse,
+ DeviceType, hwnd,
+ creationFlags,
+ &out->pp, &out->dev);
+
+ if (SUCCEEDED(hr))
+ {
+ out->owner = true;
+ out->adapterId = AdapterToUse;
+ }
+ return hr;
+}
+
+/**
+ * It setup vout_display_sys_t::d3dpp and vout_display_sys_t::rect_display
+ * from the default adapter.
+ */
+int D3D9_FillPresentationParameters(vlc_object_t *o, d3d9_handle_t *hd3d, UINT AdapterToUse, HWND hwnd,
+ const video_format_t *source, d3d9_device_t *out)
+{
+ /*
+ ** Get the current desktop display mode, so we can set up a back
+ ** buffer of the same format
+ */
+ D3DDISPLAYMODE d3ddm;
+ HRESULT hr = IDirect3D9_GetAdapterDisplayMode(hd3d->obj, AdapterToUse, &d3ddm);
+ if (FAILED(hr)) {
+ msg_Err(o, "Could not read adapter display mode. (hr=0x%0lx)", hr);
+ return VLC_EGENERIC;
+ }
+
+ /* Set up the structure used to create the D3DDevice. */
+ D3DPRESENT_PARAMETERS *d3dpp = &out->pp;
+ ZeroMemory(d3dpp, sizeof(D3DPRESENT_PARAMETERS));
+ d3dpp->Flags = D3DPRESENTFLAG_VIDEO;
+ d3dpp->Windowed = TRUE;
+ d3dpp->hDeviceWindow = hwnd;
+ d3dpp->BackBufferWidth = __MAX((unsigned int)GetSystemMetrics(SM_CXVIRTUALSCREEN),
+ source->i_width);
+ d3dpp->BackBufferHeight = __MAX((unsigned int)GetSystemMetrics(SM_CYVIRTUALSCREEN),
+ source->i_height);
+ d3dpp->SwapEffect = D3DSWAPEFFECT_COPY;
+ d3dpp->MultiSampleType = D3DMULTISAMPLE_NONE;
+ d3dpp->PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
+ d3dpp->BackBufferFormat = d3ddm.Format;
+ d3dpp->BackBufferCount = 1;
+ d3dpp->EnableAutoDepthStencil = FALSE;
+
+ return VLC_SUCCESS;
+}
diff --git a/modules/video_chroma/d3d9_fmt.h b/modules/video_chroma/d3d9_fmt.h
index f4aed6b808..644c2b7de2 100644
--- a/modules/video_chroma/d3d9_fmt.h
+++ b/modules/video_chroma/d3d9_fmt.h
@@ -25,6 +25,8 @@
#include <vlc_picture.h>
+#include <d3d9.h>
+
/* owned by the vout for VLC_CODEC_D3D9_OPAQUE */
struct picture_sys_t
{
@@ -48,17 +50,16 @@ typedef struct
LPDIRECT3DDEVICE9 dev;
LPDIRECT3DDEVICE9EX devex;
};
+ bool owner;
+
+ /* creation parameters */
D3DPRESENT_PARAMETERS pp;
UINT adapterId;
} d3d9_device_t;
#include "../codec/avcodec/va_surface.h"
-static inline picture_sys_t *ActivePictureSys(picture_t *p_pic)
-{
- struct va_pic_context *pic_ctx = (struct va_pic_context*)p_pic->context;
- return pic_ctx ? &pic_ctx->picsys : p_pic->p_sys;
-}
+picture_sys_t *ActivePictureSys(picture_t *p_pic);
static inline void AcquirePictureSys(picture_sys_t *p_sys)
{
@@ -70,4 +71,12 @@ static inline void ReleasePictureSys(picture_sys_t *p_sys)
IDirect3DSurface9_Release(p_sys->surface);
}
+HRESULT D3D9_CreateDevice(vlc_object_t *, d3d9_handle_t *, HWND,
+ const video_format_t *, const D3DCAPS9 *,
+ d3d9_device_t *out);
+#define D3D9_CreateDevice(a,b,c,d,e,f) D3D9_CreateDevice(VLC_OBJECT(a),b,c,d,e,f)
+
+int D3D9_FillPresentationParameters(vlc_object_t *, d3d9_handle_t *, UINT AdapterToUse, HWND,
+ const video_format_t *, d3d9_device_t *out);
+
#endif /* VLC_VIDEOCHROMA_D3D9_FMT_H_ */
diff --git a/modules/video_output/Makefile.am b/modules/video_output/Makefile.am
index 279d4a5d87..5d96243698 100644
--- a/modules/video_output/Makefile.am
+++ b/modules/video_output/Makefile.am
@@ -253,19 +253,17 @@ libdirect3d9_plugin_la_SOURCES = video_output/win32/direct3d9.c \
video_output/win32/events.c video_output/win32/events.h \
video_output/win32/sensors.cpp \
video_output/win32/builtin_shaders.h \
- video_output/win32/win32touch.c video_output/win32/win32touch.h \
- video_chroma/d3d9_fmt.h
+ video_output/win32/win32touch.c video_output/win32/win32touch.h
libdirect3d9_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) \
-DMODULE_NAME_IS_direct3d9
-libdirect3d9_plugin_la_LIBADD = libchroma_copy.la -lgdi32 $(LIBCOM) -luuid
+libdirect3d9_plugin_la_LIBADD = libchroma_copy.la libd3d9_common.la -lgdi32 $(LIBCOM) -luuid
libdirect3d9_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(voutdir)'
-libdirect3d9_deinterlace_plugin_la_SOURCES = video_output/win32/dxva2_deinterlace.c \
- video_chroma/d3d9_fmt.h
-libdirect3d9_deinterlace_plugin_la_LIBADD = $(LIBCOM) libdeinterlace_common.la
+libdirect3d9_deinterlace_plugin_la_SOURCES = video_output/win32/dxva2_deinterlace.c
+libdirect3d9_deinterlace_plugin_la_LIBADD = libd3d9_common.la $(LIBCOM) libdeinterlace_common.la
libdirect3d9_deinterlace_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(voutdir)'
libdirect3d9_adjust_plugin_la_SOURCES = video_output/win32/d3d9_adjust.c
libdirect3d9_adjust_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(voutdir)'
-libdirect3d9_adjust_plugin_la_LIBADD = $(LIBCOM)
+libdirect3d9_adjust_plugin_la_LIBADD = libd3d9_common.la $(LIBCOM)
if HAVE_WIN32_DESKTOP
vout_LTLIBRARIES += $(LTLIBdirect3d9)
video_filter_LTLIBRARIES += $(LTLIBdirect3d9_deinterlace) $(LTLIBdirect3d9_adjust)
diff --git a/modules/video_output/win32/direct3d9.c b/modules/video_output/win32/direct3d9.c
index 6adcdb584c..9d0dee1b91 100644
--- a/modules/video_output/win32/direct3d9.c
+++ b/modules/video_output/win32/direct3d9.c
@@ -190,9 +190,6 @@ static int Direct3D9Create (vlc_object_t *, struct d3dctx *, const video_format
static int Direct3D9Reset (vout_display_t *);
static void Direct3D9Destroy(vlc_object_t *, struct d3dctx *);
-static int Direct3D9CreateDevice(vlc_object_t *, struct d3dctx *, const video_format_t *);
-static void Direct3D9DestroyDevice(vlc_object_t *, struct d3dctx *);
-
static int Direct3D9Open (vout_display_t *, video_format_t *);
static void Direct3D9Close(vout_display_t *);
@@ -831,114 +828,10 @@ static void Direct3D9Destroy(vlc_object_t *o, struct d3dctx *d3dctx)
d3dctx->hxdll = NULL;
}
-
-/**
- * It setup vout_display_sys_t::d3dpp and vout_display_sys_t::rect_display
- * from the default adapter.
- */
-static int Direct3D9FillPresentationParameters(vlc_object_t *o, d3d9_handle_t *hd3d, UINT AdapterToUse, HWND hwnd,
- const video_format_t *source, d3d9_device_t *out)
-{
- /*
- ** Get the current desktop display mode, so we can set up a back
- ** buffer of the same format
- */
- D3DDISPLAYMODE d3ddm;
- HRESULT hr = IDirect3D9_GetAdapterDisplayMode(hd3d->obj, AdapterToUse, &d3ddm);
- if (FAILED(hr)) {
- msg_Err(o, "Could not read adapter display mode. (hr=0x%0lx)", hr);
- return VLC_EGENERIC;
- }
-
- /* Set up the structure used to create the D3DDevice. */
- D3DPRESENT_PARAMETERS *d3dpp = &out->pp;
- ZeroMemory(d3dpp, sizeof(D3DPRESENT_PARAMETERS));
- d3dpp->Flags = D3DPRESENTFLAG_VIDEO;
- d3dpp->Windowed = TRUE;
- d3dpp->hDeviceWindow = hwnd;
- d3dpp->BackBufferWidth = __MAX((unsigned int)GetSystemMetrics(SM_CXVIRTUALSCREEN),
- source->i_width);
- d3dpp->BackBufferHeight = __MAX((unsigned int)GetSystemMetrics(SM_CYVIRTUALSCREEN),
- source->i_height);
- d3dpp->SwapEffect = D3DSWAPEFFECT_COPY;
- d3dpp->MultiSampleType = D3DMULTISAMPLE_NONE;
- d3dpp->PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
- d3dpp->BackBufferFormat = d3ddm.Format;
- d3dpp->BackBufferCount = 1;
- d3dpp->EnableAutoDepthStencil = FALSE;
-
- return VLC_SUCCESS;
-}
-
/* */
static int Direct3D9CreateResources (vout_display_t *, video_format_t *);
static void Direct3D9DestroyResources(vout_display_t *);
-static HRESULT D3D9_CreateDevice(vlc_object_t *o, d3d9_handle_t *hd3d, HWND hwnd,
- const video_format_t *source, const D3DCAPS9 *caps,
- d3d9_device_t *out)
-{
- HRESULT hr;
-
- UINT AdapterToUse = D3DADAPTER_DEFAULT;
- D3DDEVTYPE DeviceType = D3DDEVTYPE_HAL;
-
-#ifndef NDEBUG
- // Look for 'NVIDIA PerfHUD' adapter
- // If it is present, override default settings
- for (UINT Adapter=0; Adapter< IDirect3D9_GetAdapterCount(hd3d->obj); ++Adapter) {
- D3DADAPTER_IDENTIFIER9 Identifier;
- HRESULT Res = IDirect3D9_GetAdapterIdentifier(hd3d->obj,Adapter,0,&Identifier);
- if (SUCCEEDED(Res) && strstr(Identifier.Description,"PerfHUD") != 0) {
- AdapterToUse = Adapter;
- DeviceType = D3DDEVTYPE_REF;
- break;
- }
- }
-#endif
-
- if (Direct3D9FillPresentationParameters(o, hd3d, AdapterToUse, hwnd, source, out))
- return E_INVALIDARG;
-
- /* */
- D3DADAPTER_IDENTIFIER9 d3dai;
- if (FAILED(IDirect3D9_GetAdapterIdentifier(hd3d->obj, AdapterToUse,0, &d3dai))) {
- msg_Warn(o, "IDirect3D9_GetAdapterIdentifier failed");
- } else {
- msg_Dbg(o, "Direct3d9 Device: %s %lu %lu %lu", d3dai.Description,
- d3dai.VendorId, d3dai.DeviceId, d3dai.Revision );
- }
-
- DWORD creationFlags = D3DCREATE_MULTITHREADED;
- if ( (caps->DevCaps & D3DDEVCAPS_DRAWPRIMTLVERTEX) &&
- (caps->DevCaps & D3DDEVCAPS_HWRASTERIZATION) ) {
- creationFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
- } else if (caps->DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) {
- creationFlags |= D3DCREATE_MIXED_VERTEXPROCESSING;
- } else {
- creationFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
- }
-
- if (hd3d->use_ex)
- hr = IDirect3D9Ex_CreateDeviceEx(hd3d->objex, AdapterToUse,
- DeviceType, hwnd,
- creationFlags,
- &out->pp, NULL, &out->devex);
- else
- hr = IDirect3D9_CreateDevice(hd3d->obj, AdapterToUse,
- DeviceType, hwnd,
- creationFlags,
- &out->pp, &out->dev);
- return hr;
-}
-
-static int Direct3D9CreateDevice(vlc_object_t *o, struct d3dctx *d3dctx, const video_format_t *source)
-{
- // Create the D3DDevice
- HRESULT hr = D3D9_CreateDevice(o, &d3dctx->hd3d, d3dctx->hwnd, source, &d3dctx->caps, &d3dctx->d3d_dev);
- return FAILED(hr) ? VLC_EGENERIC : VLC_SUCCESS;
-}
-
static void Direct3D9DestroyDevice(vlc_object_t *o, struct d3dctx *d3dctx)
{
VLC_UNUSED(o);
@@ -957,7 +850,8 @@ static int Direct3D9Open(vout_display_t *vd, video_format_t *fmt)
sys->d3dctx.hwnd = sys->sys.hvideownd;
- if (Direct3D9CreateDevice(VLC_OBJECT(vd), &sys->d3dctx, &vd->source) != VLC_SUCCESS)
+ if (FAILED(D3D9_CreateDevice(vd, &sys->d3dctx.hd3d, sys->d3dctx.hwnd,
+ &vd->source, &sys->d3dctx.caps, &sys->d3dctx.d3d_dev)))
return VLC_EGENERIC;
const d3d9_device_t *p_d3d9_dev = &sys->d3dctx.d3d_dev;
@@ -1022,7 +916,7 @@ static int Direct3D9Reset(vout_display_t *vd)
struct d3dctx *d3dctx = &sys->d3dctx;
d3d9_device_t *p_d3d9_dev = &d3dctx->d3d_dev;
- if (Direct3D9FillPresentationParameters(VLC_OBJECT(vd), &d3dctx->hd3d, p_d3d9_dev->adapterId, d3dctx->hwnd, &vd->source, &d3dctx->d3d_dev))
+ if (D3D9_FillPresentationParameters(VLC_OBJECT(vd), &d3dctx->hd3d, p_d3d9_dev->adapterId, d3dctx->hwnd, &vd->source, &d3dctx->d3d_dev))
return VLC_EGENERIC;
/* release all D3D objects */
@@ -2164,7 +2058,8 @@ GLConvOpen(vlc_object_t *obj)
goto error;
}
- if (Direct3D9CreateDevice(obj, &priv->d3dctx, &tc->fmt) != VLC_SUCCESS)
+ if (FAILED(D3D9_CreateDevice(obj, &priv->d3dctx.hd3d, priv->d3dctx.hwnd,
+ &tc->fmt, &priv->d3dctx.caps, &priv->d3dctx.d3d_dev)))
goto error;
HRESULT hr;
--
2.14.2
More information about the vlc-devel
mailing list