summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-06-05 19:25:25 +0200
committerwm4 <wm4@nowhere>2015-06-05 22:34:16 +0200
commite0f0f6f3e9820150a5c188e4e78f001617449f82 (patch)
tree601f0d698476d2510904864c6a1d5fe01d7a4a8f /video
parent650469d65b6c0b18630ee4f7e7da4fad10c6dfbc (diff)
downloadmpv-e0f0f6f3e9820150a5c188e4e78f001617449f82.tar.bz2
mpv-e0f0f6f3e9820150a5c188e4e78f001617449f82.tar.xz
vo_vdpau: directly get surface size from surface for screenshots
The previous code was not wrong, but I'd claim this makes the code more robust. If a situation could happen in which the passed surface size is incorrect, we could have passed a too small image, and VdpOutputSurfaceGetBitsNative could have randomly overwritten memory.
Diffstat (limited to 'video')
-rw-r--r--video/out/vo_vdpau.c17
-rw-r--r--video/vdpau_functions.inc1
2 files changed, 12 insertions, 6 deletions
diff --git a/video/out/vo_vdpau.c b/video/out/vo_vdpau.c
index 9eaeb4ba17..934fe6c944 100644
--- a/video/out/vo_vdpau.c
+++ b/video/out/vo_vdpau.c
@@ -834,8 +834,7 @@ static void draw_image(struct vo *vo, struct mp_image *mpi)
// warning: the size and pixel format of surface must match that of the
// surfaces in vc->output_surfaces
static struct mp_image *read_output_surface(struct vo *vo,
- VdpOutputSurface surface,
- int width, int height)
+ VdpOutputSurface surface)
{
struct vdpctx *vc = vo->priv;
VdpStatus vdp_st;
@@ -843,7 +842,15 @@ static struct mp_image *read_output_surface(struct vo *vo,
if (!vo->params)
return NULL;
- struct mp_image *image = mp_image_alloc(IMGFMT_BGR0, width, height);
+ VdpRGBAFormat fmt;
+ uint32_t w, h;
+ vdp_st = vdp->output_surface_get_parameters(surface, &fmt, &w, &h);
+ if (vdp_st != VDP_STATUS_OK)
+ return NULL;
+
+ assert(fmt == OUTPUT_RGBA_FORMAT);
+
+ struct mp_image *image = mp_image_alloc(IMGFMT_BGR0, w, h);
if (!image)
return NULL;
@@ -865,9 +872,7 @@ static struct mp_image *get_window_screenshot(struct vo *vo)
struct vdpctx *vc = vo->priv;
int last_surface = WRAP_ADD(vc->surface_num, -1, vc->num_output_surfaces);
VdpOutputSurface screen = vc->output_surfaces[last_surface];
- struct mp_image *image = read_output_surface(vo, screen,
- vc->output_surface_w,
- vc->output_surface_h);
+ struct mp_image *image = read_output_surface(vo, screen);
mp_image_set_size(image, vo->dwidth, vo->dheight);
return image;
}
diff --git a/video/vdpau_functions.inc b/video/vdpau_functions.inc
index a89fe4acd6..22c612c4ce 100644
--- a/video/vdpau_functions.inc
+++ b/video/vdpau_functions.inc
@@ -47,3 +47,4 @@ VDP_FUNCTION(VdpVideoSurfaceGetBitsYCbCr, VDP_FUNC_ID_VIDEO_SURFACE_GET_BITS_Y_C
VDP_FUNCTION(VdpVideoSurfaceGetParameters, VDP_FUNC_ID_VIDEO_SURFACE_GET_PARAMETERS, video_surface_get_parameters)
VDP_FUNCTION(VdpVideoSurfaceQueryCapabilities, VDP_FUNC_ID_VIDEO_SURFACE_QUERY_CAPABILITIES, video_surface_query_capabilities)
VDP_FUNCTION(VdpOutputSurfaceQueryCapabilities, VDP_FUNC_ID_OUTPUT_SURFACE_QUERY_CAPABILITIES, output_surface_query_capabilities)
+VDP_FUNCTION(VdpOutputSurfaceGetParameters, VDP_FUNC_ID_OUTPUT_SURFACE_GET_PARAMETERS, output_surface_get_parameters)