From 6afef5839f009654bded01dfc0e5874a09058a19 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 1 Jul 2015 23:55:10 +0200 Subject: x11: move GCs and background clearing to vo_xv vo_xv.c is the only place where these things are used. --- video/out/vo_xv.c | 54 +++++++++++++++++++++++++++++++++++++++++++++----- video/out/x11_common.c | 40 ------------------------------------- video/out/x11_common.h | 3 --- 3 files changed, 49 insertions(+), 48 deletions(-) (limited to 'video') diff --git a/video/out/vo_xv.c b/video/out/vo_xv.c index 0d2c632cc8..c2f9c9da76 100644 --- a/video/out/vo_xv.c +++ b/video/out/vo_xv.c @@ -90,6 +90,8 @@ struct xvctx { struct mp_rect src_rect; struct mp_rect dst_rect; uint32_t max_width, max_height; // zero means: not set + GC f_gc; // used to paint background + GC vo_gc; // used to paint video int Shmem_Flag; #if HAVE_SHM && HAVE_XEXT XShmSegmentInfo Shminfo[MAX_BUFFERS]; @@ -381,11 +383,11 @@ static void xv_draw_colorkey(struct vo *vo, const struct mp_rect *rc) if (ctx->xv_ck_info.method == CK_METHOD_MANUALFILL || ctx->xv_ck_info.method == CK_METHOD_BACKGROUND) { - if (!x11->vo_gc) + if (!ctx->vo_gc) return; //less tearing than XClearWindow() - XSetForeground(x11->display, x11->vo_gc, ctx->xv_colorkey); - XFillRectangle(x11->display, x11->window, x11->vo_gc, rc->x0, rc->y0, + XSetForeground(x11->display, ctx->vo_gc, ctx->xv_colorkey); + XFillRectangle(x11->display, x11->window, ctx->vo_gc, rc->x0, rc->y0, rc->x1 - rc->x0, rc->y1 - rc->y0); } } @@ -399,6 +401,38 @@ static void read_xv_csp(struct vo *vo) ctx->cached_csp = bt709_enabled == 100 ? MP_CSP_BT_709 : MP_CSP_BT_601; } + +static void fill_rect(struct vo *vo, GC gc, int x0, int y0, int x1, int y1) +{ + struct vo_x11_state *x11 = vo->x11; + + x0 = MPMAX(x0, 0); + y0 = MPMAX(y0, 0); + x1 = MPMIN(x1, vo->dwidth); + y1 = MPMIN(y1, vo->dheight); + + if (x11->window && x1 > x0 && y1 > y0) + XFillRectangle(x11->display, x11->window, gc, x0, y0, x1 - x0, y1 - y0); +} + +// Clear everything outside of rc with the background color +static void vo_x11_clear_background(struct vo *vo, const struct mp_rect *rc) +{ + struct vo_x11_state *x11 = vo->x11; + struct xvctx *ctx = vo->priv; + GC gc = ctx->f_gc; + + int w = vo->dwidth; + int h = vo->dheight; + + fill_rect(vo, gc, 0, 0, w, rc->y0); // top + fill_rect(vo, gc, 0, rc->y1, w, h); // bottom + fill_rect(vo, gc, 0, rc->y0, rc->x0, rc->y1); // left + fill_rect(vo, gc, rc->x1, rc->y0, w, rc->y1); // right + + XFlush(x11->display); +} + static void resize(struct vo *vo) { struct xvctx *ctx = vo->priv; @@ -457,6 +491,12 @@ static int reconfig(struct vo *vo, struct mp_image_params *params, int flags) vo_x11_config_vo_window(vo, NULL, flags, "xv"); + if (!ctx->f_gc && !ctx->vo_gc) { + ctx->f_gc = XCreateGC(x11->display, x11->window, 0, 0); + ctx->vo_gc = XCreateGC(x11->display, x11->window, 0, NULL); + XSetForeground(x11->display, ctx->f_gc, 0); + } + if (ctx->xv_ck_info.method == CK_METHOD_BACKGROUND) XSetWindowBackground(x11->display, x11->window, ctx->xv_colorkey); @@ -577,7 +617,7 @@ static inline void put_xvimage(struct vo *vo, XvImage *xvi) int sw = src->x1 - src->x0, sh = src->y1 - src->y0; #if HAVE_SHM && HAVE_XEXT if (ctx->Shmem_Flag) { - XvShmPutImage(x11->display, ctx->xv_port, x11->window, x11->vo_gc, xvi, + XvShmPutImage(x11->display, ctx->xv_port, x11->window, ctx->vo_gc, xvi, src->x0, src->y0, sw, sh, dst->x0, dst->y0, dw, dh, True); @@ -585,7 +625,7 @@ static inline void put_xvimage(struct vo *vo, XvImage *xvi) } else #endif { - XvPutImage(x11->display, ctx->xv_port, x11->window, x11->vo_gc, xvi, + XvPutImage(x11->display, ctx->xv_port, x11->window, ctx->vo_gc, xvi, src->x0, src->y0, sw, sh, dst->x0, dst->y0, dw, dh); } @@ -702,6 +742,10 @@ static void uninit(struct vo *vo) } for (i = 0; i < ctx->num_buffers; i++) deallocate_xvimage(vo, i); + if (ctx->f_gc != None) + XFreeGC(vo->x11->display, ctx->f_gc); + if (ctx->vo_gc != None) + XFreeGC(vo->x11->display, ctx->vo_gc); // uninit() shouldn't get called unless initialization went past vo_init() vo_x11_uninit(vo); } diff --git a/video/out/x11_common.c b/video/out/x11_common.c index 026662404b..9ed57bdc4f 100644 --- a/video/out/x11_common.c +++ b/video/out/x11_common.c @@ -710,10 +710,6 @@ void vo_x11_uninit(struct vo *vo) if (x11->window != None) vo_set_cursor_hidden(vo, false); - if (x11->f_gc != None) - XFreeGC(vo->x11->display, x11->f_gc); - if (x11->vo_gc != None) - XFreeGC(vo->x11->display, x11->vo_gc); if (x11->window != None && x11->window != x11->rootwin) { XUnmapWindow(x11->display, x11->window); XDestroyWindow(x11->display, x11->window); @@ -1516,12 +1512,6 @@ void vo_x11_config_vo_window(struct vo *vo, XVisualInfo *vis, int flags, x11->winrc = geo.win; } - if (!x11->f_gc && !x11->vo_gc) { - x11->f_gc = XCreateGC(x11->display, x11->window, 0, 0); - x11->vo_gc = XCreateGC(x11->display, x11->window, 0, NULL); - XSetForeground(x11->display, x11->f_gc, 0); - } - if (flags & VOFLAG_HIDDEN) return; @@ -1547,36 +1537,6 @@ void vo_x11_config_vo_window(struct vo *vo, XVisualInfo *vis, int flags, x11->pending_vo_events &= ~VO_EVENT_RESIZE; // implicitly done by the VO } -static void fill_rect(struct vo *vo, GC gc, int x0, int y0, int x1, int y1) -{ - struct vo_x11_state *x11 = vo->x11; - - x0 = MPMAX(x0, 0); - y0 = MPMAX(y0, 0); - x1 = MPMIN(x1, RC_W(x11->winrc)); - y1 = MPMIN(y1, RC_H(x11->winrc)); - - if (x11->window && x1 > x0 && y1 > y0) - XFillRectangle(x11->display, x11->window, gc, x0, y0, x1 - x0, y1 - y0); -} - -// Clear everything outside of rc with the background color -void vo_x11_clear_background(struct vo *vo, const struct mp_rect *rc) -{ - struct vo_x11_state *x11 = vo->x11; - GC gc = x11->f_gc; - - int w = RC_W(x11->winrc); - int h = RC_H(x11->winrc); - - fill_rect(vo, gc, 0, 0, w, rc->y0); // top - fill_rect(vo, gc, 0, rc->y1, w, h); // bottom - fill_rect(vo, gc, 0, rc->y0, rc->x0, rc->y1); // left - fill_rect(vo, gc, rc->x1, rc->y0, w, rc->y1); // right - - XFlush(x11->display); -} - static void vo_x11_setlayer(struct vo *vo, bool ontop) { struct vo_x11_state *x11 = vo->x11; diff --git a/video/out/x11_common.h b/video/out/x11_common.h index 6dfcbf52f7..5c99013ced 100644 --- a/video/out/x11_common.h +++ b/video/out/x11_common.h @@ -70,8 +70,6 @@ struct vo_x11_state { XIC xic; bool no_autorepeat; - GC f_gc; // used to paint background - GC vo_gc; // used to paint video Colormap colormap; int wm_type; @@ -128,7 +126,6 @@ int vo_x11_check_events(struct vo *vo); bool vo_x11_screen_is_composited(struct vo *vo); void vo_x11_config_vo_window(struct vo *vo, XVisualInfo *vis, int flags, const char *classname); -void vo_x11_clear_background(struct vo *vo, const struct mp_rect *rc); int vo_x11_control(struct vo *vo, int *events, int request, void *arg); #endif /* MPLAYER_X11_COMMON_H */ -- cgit v1.2.3