From cd713b4bebbb5a2e3200fa18790ad5b7ed3a6eb6 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 1 Nov 2011 03:11:46 +0100 Subject: [PATCH] vo_direct3d: reduce number of lock calls in OSD rendering The code locked the texture once for each OSD object that was rendered. But there doesn't seem to be any good reason to do that, so lock it only once during OSD rendering. --- libvo/vo_direct3d.c | 50 +++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/libvo/vo_direct3d.c b/libvo/vo_direct3d.c index c48dabbac9..a1124f5412 100644 --- a/libvo/vo_direct3d.c +++ b/libvo/vo_direct3d.c @@ -1138,29 +1138,21 @@ static void vo_draw_alpha_l8a8(int w, int h, unsigned char* src, } } +struct draw_osd_closure { + D3DLOCKED_RECT locked_rect; +}; + /** @brief Callback function to render the OSD to the texture */ -static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, - unsigned char *srca, int stride) +static void draw_alpha(void *pctx, int x0, int y0, int w, int h, + unsigned char *src, unsigned char *srca, int stride) { - D3DLOCKED_RECT locked_rect; /**< Offscreen surface we lock in order - to copy MPlayer's frame inside it.*/ - - if (FAILED(IDirect3DTexture9_LockRect(priv->texture_osd.system, 0, - &locked_rect, NULL, 0))) { - mp_msg(MSGT_VO,MSGL_ERR,"OSD texture lock failed.\n"); - return; - } + struct draw_osd_closure *ctx = pctx; + D3DLOCKED_RECT locked_rect = ctx->locked_rect; vo_draw_alpha_l8a8(w, h, src, srca, stride, (unsigned char *)locked_rect.pBits + locked_rect.Pitch*y0 + 2*x0, locked_rect.Pitch); - /* this unlock is used for both slice_draw path and D3DRenderFrame path */ - if (FAILED(IDirect3DTexture9_UnlockRect(priv->texture_osd.system, 0))) { - mp_msg(MSGT_VO,MSGL_ERR,"OSD texture unlock failed.\n"); - return; - } - priv->is_osd_populated = 1; } @@ -1173,32 +1165,32 @@ static void draw_osd(void) return; if (vo_osd_changed(0)) { - D3DLOCKED_RECT locked_rect; /**< Offscreen surface we lock in order - to copy MPlayer's frame inside it.*/ + struct draw_osd_closure ctx; /* clear the OSD */ if (FAILED(IDirect3DTexture9_LockRect(priv->texture_osd.system, 0, - &locked_rect, NULL, 0))) { + &ctx.locked_rect, NULL, 0))) { mp_msg(MSGT_VO,MSGL_ERR, "OSD texture lock failed.\n"); return; } /* clear the whole texture to avoid issues due to interpolation */ - memset(locked_rect.pBits, 0, locked_rect.Pitch * priv->texture_osd.tex_h); - - if (FAILED(IDirect3DTexture9_UnlockRect(priv->texture_osd.system, 0))) { - mp_msg(MSGT_VO,MSGL_ERR, "OSD texture unlock failed.\n"); - return; - } + memset(ctx.locked_rect.pBits, 0, + ctx.locked_rect.Pitch * priv->texture_osd.tex_h); priv->is_osd_populated = 0; /* required for if subs are in the boarder region */ priv->is_clear_needed = 1; - vo_draw_text_ext(priv->texture_osd.w, priv->texture_osd.h, - priv->border_x, priv->border_y, - priv->border_x, priv->border_y, - priv->src_width, priv->src_height, draw_alpha); + osd_draw_text_ext(global_osd, priv->texture_osd.w, priv->texture_osd.h, + priv->border_x, priv->border_y, + priv->border_x, priv->border_y, + priv->src_width, priv->src_height, draw_alpha, &ctx); + + if (FAILED(IDirect3DTexture9_UnlockRect(priv->texture_osd.system, 0))) { + mp_msg(MSGT_VO,MSGL_ERR, "OSD texture unlock failed.\n"); + return; + } d3dtex_update(&priv->texture_osd); }