From ff5a90832814fe583b006d1943fced4dd0fa786d Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 5 Nov 2013 19:08:44 +0100 Subject: vo_opengl: redo aspects of initialization, change hwdec API Instead of checking for resolution and image format changes, always fully reinit on any parameter change. Let init_video do all required initializations, which simplifies things a little bit. Change the gl_video/hardware decoding interop API slightly, so that hwdec initialization gets the full image parameters. Also make some cosmetic changes. --- video/out/gl_common.h | 14 +++++++------- video/out/gl_hwdec_vaglx.c | 14 +++++++------- video/out/gl_video.c | 48 +++++++++++++++++++++++----------------------- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/video/out/gl_common.h b/video/out/gl_common.h index 531cec37fb..995dc441e7 100644 --- a/video/out/gl_common.h +++ b/video/out/gl_common.h @@ -189,15 +189,15 @@ struct gl_hwdec_driver { int (*create)(struct gl_hwdec *hw); // Prepare for rendering video. (E.g. create textures.) // Called on initialization, and every time the video size changes. - int (*reinit)(struct gl_hwdec *hw, int w, int h); + int (*reinit)(struct gl_hwdec *hw, const struct mp_image_params *params); // Return textures that contain the given hw_image. - // Note that the caller keeps a reference to hw_image until unload_image - // is called, so the callee doesn't need to do that. - int (*load_image)(struct gl_hwdec *hw, struct mp_image *hw_image, - GLuint *out_textures); - // Undo load_image(). The user of load_image() calls this when the textures + // Note that the caller keeps a reference to hw_image until unmap_image + // is called, so the hwdec driver doesn't need to do that. + int (*map_image)(struct gl_hwdec *hw, struct mp_image *hw_image, + GLuint *out_textures); + // Undo map_image(). The user of map_image() calls this when the textures // are not needed anymore. - void (*unload_image)(struct gl_hwdec *hw); + void (*unmap_image)(struct gl_hwdec *hw); void (*destroy)(struct gl_hwdec *hw); }; diff --git a/video/out/gl_hwdec_vaglx.c b/video/out/gl_hwdec_vaglx.c index fae066442c..abfc656337 100644 --- a/video/out/gl_hwdec_vaglx.c +++ b/video/out/gl_hwdec_vaglx.c @@ -83,7 +83,7 @@ static int create(struct gl_hwdec *hw) return 0; } -static int reinit(struct gl_hwdec *hw, int w, int h) +static int reinit(struct gl_hwdec *hw, const struct mp_image_params *params) { struct priv *p = hw->priv; GL *gl = hw->mpgl->gl; @@ -97,7 +97,7 @@ static int reinit(struct gl_hwdec *hw, int w, int h) gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); gl->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, + gl->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, params->w, params->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); gl->BindTexture(GL_TEXTURE_2D, 0); @@ -106,8 +106,8 @@ static int reinit(struct gl_hwdec *hw, int w, int h) return check_va_status(status, "vaCreateSurfaceGLX()") ? 0 : -1; } -static int load_image(struct gl_hwdec *hw, struct mp_image *hw_image, - GLuint *out_textures) +static int map_image(struct gl_hwdec *hw, struct mp_image *hw_image, + GLuint *out_textures) { struct priv *p = hw->priv; VAStatus status; @@ -125,7 +125,7 @@ static int load_image(struct gl_hwdec *hw, struct mp_image *hw_image, return 0; } -static void unload_image(struct gl_hwdec *hw) +static void unmap_image(struct gl_hwdec *hw) { } @@ -134,7 +134,7 @@ const struct gl_hwdec_driver gl_hwdec_vaglx = { .query_format = query_format, .create = create, .reinit = reinit, - .load_image = load_image, - .unload_image = unload_image, + .map_image = map_image, + .unmap_image = unmap_image, .destroy = destroy, }; diff --git a/video/out/gl_video.c b/video/out/gl_video.c index 9fd3040d51..0c09f29e58 100644 --- a/video/out/gl_video.c +++ b/video/out/gl_video.c @@ -1210,7 +1210,7 @@ static void set_image_textures(struct gl_video *p, struct video_image *vimg, if (p->hwdec_active) { assert(vimg->hwimage); - p->hwdec->driver->load_image(p->hwdec, vimg->hwimage, imgtex); + p->hwdec->driver->map_image(p->hwdec, vimg->hwimage, imgtex); } else { for (int n = 0; n < p->plane_count; n++) imgtex[n] = vimg->planes[n].gl_texture; @@ -1234,15 +1234,29 @@ static void unset_image_textures(struct gl_video *p) gl->ActiveTexture(GL_TEXTURE0); if (p->hwdec_active) - p->hwdec->driver->unload_image(p->hwdec); + p->hwdec->driver->unmap_image(p->hwdec); } -static void init_video(struct gl_video *p) +static void init_video(struct gl_video *p, const struct mp_image_params *params) { GL *gl = p->gl; check_gl_features(p); + init_format(params->imgfmt, p); + + p->image_w = params->w; + p->image_h = params->h; + p->image_dw = params->d_w; + p->image_dh = params->d_h; + p->image_params = *params; + + struct mp_csp_details csp = MP_CSP_DETAILS_DEFAULTS; + csp.levels_in = params->colorlevels; + csp.levels_out = params->outputlevels; + csp.format = params->colorspace; + p->colorspace = csp; + if (p->is_rgb && (p->opts.srgb || p->use_lut_3d)) { p->is_linear_rgb = true; p->image.planes[0].gl_internal_format = GL_SRGB; @@ -1301,8 +1315,8 @@ static void init_video(struct gl_video *p) debug_check_gl(p, "after video texture creation"); if (p->hwdec_active) { - if (p->hwdec->driver->reinit(p->hwdec, p->image_w, p->image_h) < 0) - MP_ERR(p, "Initializing hardware decoding video texture failed.\n"); + if (p->hwdec->driver->reinit(p->hwdec, &p->image_params) < 0) + MP_ERR(p, "Initializing texture for hardware decoding failed.\n"); } reinit_rendering(p); @@ -2048,27 +2062,13 @@ bool gl_video_check_format(struct gl_video *p, int mp_format) void gl_video_config(struct gl_video *p, struct mp_image_params *params) { - if (p->image_format != params->imgfmt || p->image_w != params->w || - p->image_h != params->h) - { - uninit_video(p); - p->image_w = params->w; - p->image_h = params->h; - init_format(params->imgfmt, p); - init_video(p); - } - p->image_dw = params->d_w; - p->image_dh = params->d_h; - p->image_params = *params; - - struct mp_csp_details csp = MP_CSP_DETAILS_DEFAULTS; - csp.levels_in = params->colorlevels; - csp.levels_out = params->outputlevels; - csp.format = params->colorspace; - p->colorspace = csp; - p->have_image = false; mp_image_unrefp(&p->image.hwimage); + + if (!mp_image_params_equals(&p->image_params, params)) { + uninit_video(p); + init_video(p, params); + } } void gl_video_set_output_depth(struct gl_video *p, int r, int g, int b) -- cgit v1.2.3