summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-07-03 15:58:19 +0200
committerwm4 <wm4@nowhere>2015-07-03 16:04:42 +0200
commitb85321d0573ba581694d2e6be1effafee74c11d1 (patch)
treeaabed80d8c8ec801ff358150da9b1ca0b6f615d4 /video
parentb6dc11810b78953d95a75d745d7327a796f0b462 (diff)
downloadmpv-b85321d0573ba581694d2e6be1effafee74c11d1.tar.bz2
mpv-b85321d0573ba581694d2e6be1effafee74c11d1.tar.xz
vo_direct3d, dxva2: use the same D3D device
Since we still read-back (and don't have hard plans on changing this), this doesn't have much of an advantage.
Diffstat (limited to 'video')
-rw-r--r--video/d3d.h13
-rw-r--r--video/decode/dxva2.c10
-rw-r--r--video/hwdec.h1
-rw-r--r--video/out/vo_direct3d.c18
4 files changed, 42 insertions, 0 deletions
diff --git a/video/d3d.h b/video/d3d.h
new file mode 100644
index 0000000000..30bee49adc
--- /dev/null
+++ b/video/d3d.h
@@ -0,0 +1,13 @@
+#ifndef MP_D3D_H_
+#define MP_D3D_H_
+
+#include <d3d9.h>
+
+#include "hwdec.h"
+
+struct mp_d3d_ctx {
+ struct mp_hwdec_ctx hwctx;
+ IDirect3DDevice9 *d3d9_device;
+};
+
+#endif
diff --git a/video/decode/dxva2.c b/video/decode/dxva2.c
index 852319611d..62b27671ef 100644
--- a/video/decode/dxva2.c
+++ b/video/decode/dxva2.c
@@ -36,6 +36,7 @@
#include "video/fmt-conversion.h"
#include "video/mp_image_pool.h"
#include "video/hwdec.h"
+#include "video/d3d.h"
#include "gpu_memcpy_sse4.h"
// A minor evil.
@@ -341,6 +342,15 @@ static int create_device(struct lavc_ctx *s)
D3DDISPLAYMODE d3ddm;
UINT adapter = D3DADAPTER_DEFAULT;
+ if (s->hwdec_info && s->hwdec_info->hwctx && s->hwdec_info->hwctx->d3d_ctx) {
+ ctx->d3d9device = s->hwdec_info->hwctx->d3d_ctx->d3d9_device;
+ if (ctx->d3d9device) {
+ IDirect3D9_AddRef(ctx->d3d9device);
+ MP_VERBOSE(ctx, "Using VO-supplied device %p.\n", ctx->d3d9device);
+ return 0;
+ }
+ }
+
ctx->d3dlib = LoadLibrary(L"d3d9.dll");
if (!ctx->d3dlib) {
MP_ERR(ctx, "Failed to load D3D9 library\n");
diff --git a/video/hwdec.h b/video/hwdec.h
index b04b7c519b..761b8d699b 100644
--- a/video/hwdec.h
+++ b/video/hwdec.h
@@ -23,6 +23,7 @@ struct mp_hwdec_ctx {
// API-specific, not needed by all backends.
struct mp_vdpau_ctx *vdpau_ctx;
struct mp_vaapi_ctx *vaapi_ctx;
+ struct mp_d3d_ctx *d3d_ctx;
// Optional.
// Allocates a software image from the pool, downloads the hw image from
diff --git a/video/out/vo_direct3d.c b/video/out/vo_direct3d.c
index e3b366b5ca..528ccd85de 100644
--- a/video/out/vo_direct3d.c
+++ b/video/out/vo_direct3d.c
@@ -34,6 +34,7 @@
#include "video/csputils.h"
#include "video/mp_image.h"
#include "video/img_format.h"
+#include "video/d3d.h"
#include "common/msg.h"
#include "common/common.h"
#include "w32_common.h"
@@ -191,6 +192,10 @@ typedef struct d3d_priv {
struct mp_csp_equalizer video_eq;
struct osdpart *osd[MAX_OSD_PARTS];
+
+ struct mp_hwdec_info hwdec_info;
+ struct mp_hwdec_ctx hwdec_ctx;
+ struct mp_d3d_ctx hwdec_d3d;
} d3d_priv;
struct fmt_entry {
@@ -739,6 +744,9 @@ static bool change_d3d_backbuffer(d3d_priv *priv)
MP_VERBOSE(priv, "Creating Direct3D device failed.\n");
return 0;
}
+
+ // (race condition if this is called when recovering from a "lost" device)
+ priv->hwdec_d3d.d3d9_device = priv->d3d_device;
} else {
if (FAILED(IDirect3DDevice9_Reset(priv->d3d_device, &present_params))) {
MP_ERR(priv, "Reseting Direct3D device failed.\n");
@@ -772,6 +780,8 @@ static bool change_d3d_backbuffer(d3d_priv *priv)
static void destroy_d3d(d3d_priv *priv)
{
+ priv->hwdec_d3d.d3d9_device = NULL;
+
destroy_d3d_surfaces(priv);
for (int n = 0; n < NUM_SHADERS; n++) {
@@ -1216,6 +1226,9 @@ static int preinit(struct vo *vo)
priv->vo = vo;
priv->log = vo->log;
+ priv->hwdec_info.hwctx = &priv->hwdec_ctx;
+ priv->hwdec_ctx.d3d_ctx = &priv->hwdec_d3d;
+
for (int n = 0; n < MAX_OSD_PARTS; n++) {
struct osdpart *osd = talloc_ptrtype(priv, osd);
*osd = (struct osdpart) {
@@ -1263,6 +1276,11 @@ static int control(struct vo *vo, uint32_t request, void *data)
d3d_priv *priv = vo->priv;
switch (request) {
+ case VOCTRL_GET_HWDEC_INFO: {
+ struct mp_hwdec_info **arg = data;
+ *arg = &priv->hwdec_info;
+ return true;
+ }
case VOCTRL_REDRAW_FRAME:
d3d_draw_frame(priv);
return VO_TRUE;