summaryrefslogtreecommitdiffstats
path: root/video/out/opengl/hwdec_dxva2gldx.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-08-10 17:48:33 +0200
committerwm4 <wm4@nowhere>2017-08-10 21:24:31 +0200
commitc6fafbffaca16959dfa2b4bf1eb97861ad66b5ef (patch)
treedecef889171128c27f3a8cb2fcfb552f1b7297be /video/out/opengl/hwdec_dxva2gldx.c
parentb2fb3f1340ed7ceb9b3fc8ba4ddec107e3a41a13 (diff)
downloadmpv-c6fafbffaca16959dfa2b4bf1eb97861ad66b5ef.tar.bz2
mpv-c6fafbffaca16959dfa2b4bf1eb97861ad66b5ef.tar.xz
vo_opengl: separate hwdec context and mapping, port it to use ra
This does two separate rather intrusive things: 1. Make the hwdec context (which does initialization, provides the device to the decoder, and other basic state) and frame mapping (getting textures from a mp_image) separate. This is more flexible, and you could map multiple images at once. It will help removing some hwdec special-casing from video.c. 2. Switch all hwdec API use to ra. Of course all code is still GL specific, but in theory it would be possible to support other backends. The most important change is that the hwdec interop returns ra objects, instead of anything GL specific. This removes the last dependency on GL-specific header files from video.c. I'm mixing these separate changes because both requires essentially rewriting all the glue code, so better do them at once. For the same reason, this change isn't done incrementally. hwdec_ios.m is untested, since I can't test it. Apart from superficial mistakes, this also requires dealing with Apple's texture format fuckups: they force you to use GL_LUMINANCE[_ALPHA] instead of GL_RED and GL_RG. We also need to report the correct format via ra_tex to the renderer, which is done by find_la_variant(). It's unknown whether this works correctly. hwdec_rpi.c as well as vo_rpi.c are still broken. (I need to pull my RPI out of a dusty pile of devices and cables, so, later.)
Diffstat (limited to 'video/out/opengl/hwdec_dxva2gldx.c')
-rw-r--r--video/out/opengl/hwdec_dxva2gldx.c187
1 files changed, 102 insertions, 85 deletions
diff --git a/video/out/opengl/hwdec_dxva2gldx.c b/video/out/opengl/hwdec_dxva2gldx.c
index 7e0ea88b51..fd9c80b7a2 100644
--- a/video/out/opengl/hwdec_dxva2gldx.c
+++ b/video/out/opengl/hwdec_dxva2gldx.c
@@ -21,6 +21,7 @@
#include "common/common.h"
#include "osdep/windows_utils.h"
#include "hwdec.h"
+#include "ra_gl.h"
#include "video/hwdec.h"
#include "video/decode/d3d.h"
@@ -28,67 +29,42 @@
#include <GL/wglext.h>
#define SHARED_SURFACE_D3DFMT D3DFMT_X8R8G8B8
-#define SHARED_SURFACE_MPFMT IMGFMT_RGB0
-struct priv {
+
+struct priv_owner {
struct mp_hwdec_ctx hwctx;
IDirect3DDevice9Ex *device;
HANDLE device_h;
+};
+struct priv {
+ IDirect3DDevice9Ex *device;
+ HANDLE device_h;
IDirect3DSurface9 *rtarget;
HANDLE rtarget_h;
GLuint texture;
};
-static void destroy_objects(struct gl_hwdec *hw)
+static void uninit(struct ra_hwdec *hw)
{
- struct priv *p = hw->priv;
- GL *gl = hw->gl;
+ struct priv_owner *p = hw->priv;
- if (p->rtarget_h && p->device_h) {
- if (!gl->DXUnlockObjectsNV(p->device_h, 1, &p->rtarget_h)) {
- MP_ERR(hw, "Failed unlocking texture for access by OpenGL: %s\n",
- mp_LastError_to_str());
- }
- }
-
- if (p->rtarget_h) {
- if (!gl->DXUnregisterObjectNV(p->device_h, p->rtarget_h)) {
- MP_ERR(hw, "Failed to unregister Direct3D surface with OpenGL: %s\n",
- mp_LastError_to_str());
- } else {
- p->rtarget_h = 0;
- }
- }
-
- gl->DeleteTextures(1, &p->texture);
- p->texture = 0;
-
- if (p->rtarget) {
- IDirect3DSurface9_Release(p->rtarget);
- p->rtarget = NULL;
- }
-}
-
-static void destroy(struct gl_hwdec *hw)
-{
- struct priv *p = hw->priv;
- destroy_objects(hw);
-
- hwdec_devices_remove(hw->devs, &p->hwctx);
+ if (p->hwctx.ctx)
+ hwdec_devices_remove(hw->devs, &p->hwctx);
if (p->device)
IDirect3DDevice9Ex_Release(p->device);
}
-static int create(struct gl_hwdec *hw)
+static int init(struct ra_hwdec *hw)
{
- GL *gl = hw->gl;
+ struct priv_owner *p = hw->priv;
+
+ if (!ra_is_gl(hw->ra))
+ return -1;
+ GL *gl = ra_gl_get(hw->ra);
if (!(gl->mpgl_caps & MPGL_CAP_DXINTEROP))
return -1;
- struct priv *p = talloc_zero(hw, struct priv);
- hw->priv = p;
-
// AMD drivers won't open multiple dxinterop HANDLES on the same D3D device,
// so we request the one already in use by context_dxinterop
p->device_h = mpgl_get_native_display(gl, "dxinterop_device_HANDLE");
@@ -111,31 +87,65 @@ static int create(struct gl_hwdec *hw)
return 0;
}
-static int reinit(struct gl_hwdec *hw, struct mp_image_params *params)
+static void mapper_uninit(struct ra_hwdec_mapper *mapper)
+{
+ struct priv *p = mapper->priv;
+ GL *gl = ra_gl_get(mapper->ra);
+
+ if (p->rtarget_h && p->device_h) {
+ if (!gl->DXUnlockObjectsNV(p->device_h, 1, &p->rtarget_h)) {
+ MP_ERR(mapper, "Failed unlocking texture for access by OpenGL: %s\n",
+ mp_LastError_to_str());
+ }
+ }
+
+ if (p->rtarget_h) {
+ if (!gl->DXUnregisterObjectNV(p->device_h, p->rtarget_h)) {
+ MP_ERR(mapper, "Failed to unregister Direct3D surface with OpenGL: %s\n",
+ mp_LastError_to_str());
+ } else {
+ p->rtarget_h = 0;
+ }
+ }
+
+ gl->DeleteTextures(1, &p->texture);
+ p->texture = 0;
+
+ if (p->rtarget) {
+ IDirect3DSurface9_Release(p->rtarget);
+ p->rtarget = NULL;
+ }
+
+ ra_tex_free(mapper->ra, &mapper->tex[0]);
+}
+
+static int mapper_init(struct ra_hwdec_mapper *mapper)
{
- struct priv *p = hw->priv;
- GL *gl = hw->gl;
+ struct priv_owner *p_owner = mapper->owner->priv;
+ struct priv *p = mapper->priv;
+ GL *gl = ra_gl_get(mapper->ra);
HRESULT hr;
- destroy_objects(hw);
+ p->device = p_owner->device;
+ p->device_h = p_owner->device_h;
HANDLE share_handle = NULL;
hr = IDirect3DDevice9Ex_CreateRenderTarget(
p->device,
- params->w, params->h,
+ mapper->src_params.w, mapper->src_params.h,
SHARED_SURFACE_D3DFMT, D3DMULTISAMPLE_NONE, 0, FALSE,
&p->rtarget, &share_handle);
if (FAILED(hr)) {
- MP_ERR(hw, "Failed creating offscreen Direct3D surface: %s\n",
+ MP_ERR(mapper, "Failed creating offscreen Direct3D surface: %s\n",
mp_HRESULT_to_str(hr));
- goto fail;
+ return -1;
}
if (share_handle &&
!gl->DXSetResourceShareHandleNV(p->rtarget, share_handle)) {
- MP_ERR(hw, "Failed setting Direct3D/OpenGL share handle for surface: %s\n",
+ MP_ERR(mapper, "Failed setting Direct3D/OpenGL share handle for surface: %s\n",
mp_LastError_to_str());
- goto fail;
+ return -1;
}
gl->GenTextures(1, &p->texture);
@@ -150,76 +160,83 @@ static int reinit(struct gl_hwdec *hw, struct mp_image_params *params)
GL_TEXTURE_2D,
WGL_ACCESS_READ_ONLY_NV);
if (!p->rtarget_h) {
- MP_ERR(hw, "Failed to register Direct3D surface with OpenGL: %s\n",
+ MP_ERR(mapper, "Failed to register Direct3D surface with OpenGL: %s\n",
mp_LastError_to_str());
- goto fail;
+ return -1;
}
if (!gl->DXLockObjectsNV(p->device_h, 1, &p->rtarget_h)) {
- MP_ERR(hw, "Failed locking texture for access by OpenGL %s\n",
+ MP_ERR(mapper, "Failed locking texture for access by OpenGL %s\n",
mp_LastError_to_str());
- goto fail;
+ return -1;
}
- params->imgfmt = SHARED_SURFACE_MPFMT;
- params->hw_subfmt = 0;
+ struct ra_tex_params params = {
+ .dimensions = 2,
+ .w = mapper->src_params.w,
+ .h = mapper->src_params.h,
+ .d = 1,
+ .format = ra_find_unorm_format(mapper->ra, 1, 4),
+ .render_src = true,
+ .src_linear = true,
+ };
+ if (!params.format)
+ return -1;
+
+ mapper->tex[0] = ra_create_wrapped_tex(mapper->ra, &params, p->texture);
+ if (!mapper->tex[0])
+ return -1;
+
+ mapper->dst_params = mapper->src_params;
+ mapper->dst_params.imgfmt = IMGFMT_RGB0;
+ mapper->dst_params.hw_subfmt = 0;
return 0;
-fail:
- destroy_objects(hw);
- return -1;
}
-static int map_frame(struct gl_hwdec *hw, struct mp_image *hw_image,
- struct gl_hwdec_frame *out_frame)
+static int mapper_map(struct ra_hwdec_mapper *mapper)
{
- assert(hw_image && hw_image->imgfmt == hw->driver->imgfmt);
- GL *gl = hw->gl;
- struct priv *p = hw->priv;
+ struct priv *p = mapper->priv;
+ GL *gl = ra_gl_get(mapper->ra);
HRESULT hr;
if (!gl->DXUnlockObjectsNV(p->device_h, 1, &p->rtarget_h)) {
- MP_ERR(hw, "Failed unlocking texture for access by OpenGL: %s\n",
+ MP_ERR(mapper, "Failed unlocking texture for access by OpenGL: %s\n",
mp_LastError_to_str());
return -1;
}
- IDirect3DSurface9* hw_surface = (IDirect3DSurface9 *)hw_image->planes[3];
- RECT rc = {0, 0, hw_image->w, hw_image->h};
+ IDirect3DSurface9* hw_surface = (IDirect3DSurface9 *)mapper->src->planes[3];
+ RECT rc = {0, 0, mapper->src->w, mapper->src->h};
hr = IDirect3DDevice9Ex_StretchRect(p->device,
hw_surface, &rc,
p->rtarget, &rc,
D3DTEXF_NONE);
if (FAILED(hr)) {
- MP_ERR(hw, "Direct3D RGB conversion failed: %s", mp_HRESULT_to_str(hr));
+ MP_ERR(mapper, "Direct3D RGB conversion failed: %s", mp_HRESULT_to_str(hr));
return -1;
}
if (!gl->DXLockObjectsNV(p->device_h, 1, &p->rtarget_h)) {
- MP_ERR(hw, "Failed locking texture for access by OpenGL: %s\n",
+ MP_ERR(mapper, "Failed locking texture for access by OpenGL: %s\n",
mp_LastError_to_str());
return -1;
}
- *out_frame = (struct gl_hwdec_frame){
- .planes = {
- {
- .gl_texture = p->texture,
- .gl_target = GL_TEXTURE_2D,
- .tex_w = hw_image->w,
- .tex_h = hw_image->h,
- },
- },
- };
return 0;
}
-const struct gl_hwdec_driver gl_hwdec_dxva2gldx = {
+const struct ra_hwdec_driver ra_hwdec_dxva2gldx = {
.name = "dxva2-dxinterop",
+ .priv_size = sizeof(struct priv_owner),
.api = HWDEC_DXVA2,
- .imgfmt = IMGFMT_DXVA2,
- .create = create,
- .reinit = reinit,
- .map_frame = map_frame,
- .destroy = destroy,
+ .imgfmts = {IMGFMT_DXVA2, 0},
+ .init = init,
+ .uninit = uninit,
+ .mapper = &(const struct ra_hwdec_mapper_driver){
+ .priv_size = sizeof(struct priv),
+ .init = mapper_init,
+ .uninit = mapper_uninit,
+ .map = mapper_map,
+ },
};