1
mirror of https://github.com/mpv-player/mpv synced 2024-11-14 22:48:35 +01:00
mpv/video/out/opengl/hwdec_dxva2.c
wm4 b0b01aa250 vo_opengl: refactor how hwdec interop exports textures
Rename gl_hwdec_driver.map_image to map_frame, and let it fill out a
struct gl_hwdec_frame describing the exact texture layout. This gives
more flexibility to what the hwdec interop can export. In particular, it
can export strange component orders/permutations and textures with
padded size. (The latter originating from cropped video.)

The way gl_hwdec_frame works is in the spirit of the rest of the
vo_opengl video processing code, which tends to put as much information
in immediate state (as part of the dataflow), instead of declaring it
globally. To some degree this duplicates the texplane and img_tex
structs, but until we somehow unify those, it's better to give the hwdec
state its own struct. The fact that changing the hwdec struct would
require changes and testing on at least 4 platform/GPU combinations
makes duplicating it almost a requirement to avoid pain later.

Make gl_hwdec_driver.reinit set the new image format and remove the
gl_hwdec.converted_imgfmt field.

Likewise, gl_hwdec.gl_texture_target is replaced with
gl_hwdec_plane.gl_target.

Split out a init_image_desc function from init_format. The latter is not
called in the hwdec case at all anymore. Setting up most of struct
texplane is also completely separate in the hwdec and normal cases.

video.c does not check whether the hwdec "mapped" image format is
supported. This should not really happen anyway, and if it does, the
hwdec interop backend must fail at creation time, so this is not an
issue.
2016-05-10 18:42:42 +02:00

69 lines
1.5 KiB
C

#include <d3d9.h>
#include "common/common.h"
#include "hwdec.h"
#include "utils.h"
#include "video/hwdec.h"
// This does not provide real (zero-copy) interop - it merely exists for
// making sure the same D3D device is used for decoding and display, which
// may help with OpenGL fullscreen mode.
struct priv {
struct mp_hwdec_ctx hwctx;
};
static void destroy(struct gl_hwdec *hw)
{
struct priv *p = hw->priv;
hwdec_devices_remove(hw->devs, &p->hwctx);
if (p->hwctx.ctx)
IDirect3DDevice9_Release((IDirect3DDevice9 *)p->hwctx.ctx);
}
static int create(struct gl_hwdec *hw)
{
GL *gl = hw->gl;
if (!gl->MPGetNativeDisplay)
return -1;
struct priv *p = talloc_zero(hw, struct priv);
hw->priv = p;
IDirect3DDevice9 *d3d = gl->MPGetNativeDisplay("IDirect3DDevice9");
if (!d3d)
return -1;
MP_VERBOSE(hw, "Using libmpv supplied device %p.\n", d3d);
p->hwctx = (struct mp_hwdec_ctx){
.type = HWDEC_DXVA2_COPY,
.driver_name = hw->driver->name,
.ctx = d3d,
};
hwdec_devices_add(hw->devs, &p->hwctx);
return 0;
}
static int reinit(struct gl_hwdec *hw, struct mp_image_params *params)
{
return -1;
}
static int map_frame(struct gl_hwdec *hw, struct mp_image *hw_image,
struct gl_hwdec_frame *out_frame)
{
return -1;
}
const struct gl_hwdec_driver gl_hwdec_dxva2 = {
.name = "dxva2-dummy",
.api = HWDEC_DXVA2_COPY,
.imgfmt = -1,
.create = create,
.reinit = reinit,
.map_frame = map_frame,
.destroy = destroy,
};