From 0535a14505c367693fe729a3f1348c4ffd516af3 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 27 Jan 2013 07:21:10 +0100 Subject: x11: reduce VO mode switching code duplication Some parts for initiating mode switches were duplicated in every VO supporting X11 (except vo_opengl/gl_common, which didn't support mode switching). Move this to x11_common.c. Note that this might be slightly risky: is it really guaranteed that no VO needed to do "special" setup that depends on X parameters changing after a mode switch, such as bit depth, visuals etc.? From what I can see, this shouldn't be the case (X probably can't even change depth on the fly). Even if this should be a one-way road, VM switching is in general very useless, and its implementation buggy, so it can just be removed should unfixable problems arise. --- video/out/vo_vdpau.c | 30 +----------------------------- video/out/vo_x11.c | 25 ------------------------- video/out/vo_xv.c | 23 ----------------------- video/out/x11_common.c | 36 +++++++++++++++++++++++++++++++++--- video/out/x11_common.h | 6 +----- 5 files changed, 35 insertions(+), 85 deletions(-) (limited to 'video') diff --git a/video/out/vo_vdpau.c b/video/out/vo_vdpau.c index 0777ec084a..00477716b7 100644 --- a/video/out/vo_vdpau.c +++ b/video/out/vo_vdpau.c @@ -178,9 +178,6 @@ struct vdpctx { // Video equalizer struct mp_csp_equalizer video_eq; - - // These tell what's been initialized and uninit() should free/uninitialize - bool mode_switched; }; static bool status_ok(struct vo *vo); @@ -526,7 +523,7 @@ static int win_x11_init_vdpau_flip_queue(struct vo *vo) "refresh rate of %.3f Hz.\n", vc->user_fps); } else if (vc->user_fps == 0) { #ifdef CONFIG_XF86VM - double fps = vo_vm_get_fps(vo); + double fps = vo_x11_vm_get_fps(vo); if (!fps) mp_msg(MSGT_VO, MSGL_WARN, "[vdpau] Failed to get display FPS\n"); else { @@ -852,10 +849,6 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, XWindowAttributes attribs; unsigned long xswamask; -#ifdef CONFIG_XF86VM - int vm = flags & VOFLAG_MODESWITCHING; -#endif - if (handle_preemption(vo) < 0) return -1; @@ -868,12 +861,6 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, if (IMGFMT_IS_VDPAU(vc->image_format) && !create_vdp_decoder(vo, 2)) return -1; -#ifdef CONFIG_XF86VM - if (vm) { - vo_vm_switch(vo); - vc->mode_switched = true; - } -#endif XGetWindowAttributes(x11->display, DefaultRootWindow(x11->display), &attribs); XMatchVisualInfo(x11->display, x11->screen, attribs.depth, TrueColor, @@ -889,17 +876,6 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, flags, CopyFromParent, "vdpau"); XChangeWindowAttributes(x11->display, x11->window, xswamask, &xswa); -#ifdef CONFIG_XF86VM - if (vm) { - /* Grab the mouse pointer in our window */ - if (vo_grabpointer) - XGrabPointer(x11->display, x11->window, True, 0, - GrabModeAsync, GrabModeAsync, - x11->window, None, CurrentTime); - XSetInputFocus(x11->display, x11->window, RevertToNone, CurrentTime); - } -#endif - if (initialize_vdpau_objects(vo) < 0) return -1; @@ -1485,10 +1461,6 @@ static void uninit(struct vo *vo) /* Destroy all vdpau objects */ destroy_vdpau_objects(vo); -#ifdef CONFIG_XF86VM - if (vc->mode_switched) - vo_vm_close(vo); -#endif vo_x11_uninit(vo); // Free bitstream buffers allocated by FFmpeg diff --git a/video/out/vo_x11.c b/video/out/vo_x11.c index 9b13ae2893..09055a698d 100644 --- a/video/out/vo_x11.c +++ b/video/out/vo_x11.c @@ -330,9 +330,6 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, mp_image_unrefp(&p->original_image); -#ifdef CONFIG_XF86VM - int vm = flags & VOFLAG_MODESWITCHING; -#endif p->Flip_Flag = flags & VOFLAG_FLIPPING; p->zoomFlag = 1; @@ -369,27 +366,10 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, p->image_height = height; { -#ifdef CONFIG_XF86VM - if (vm) - vo_vm_switch(vo); - -#endif theCmap = vo_x11_create_colormap(vo, &p->vinfo); vo_x11_create_vo_window(vo, &p->vinfo, vo->dx, vo->dy, vo->dwidth, vo->dheight, flags, theCmap, "x11"); - -#ifdef CONFIG_XF86VM - if (vm) { - /* Grab the mouse pointer in our window */ - if (vo_grabpointer) - XGrabPointer(vo->x11->display, vo->x11->window, True, 0, - GrabModeAsync, GrabModeAsync, - vo->x11->window, None, CurrentTime); - XSetInputFocus(vo->x11->display, vo->x11->window, RevertToNone, - CurrentTime); - } -#endif } if (WinID > 0) { @@ -721,11 +701,6 @@ static void uninit(struct vo *vo) talloc_free(p->original_image); -#ifdef CONFIG_XF86VM - vo_vm_close(vo); -#endif - - p->zoomFlag = 0; vo_x11_uninit(vo); sws_freeContext(p->swsContext); diff --git a/video/out/vo_xv.c b/video/out/vo_xv.c index 8d52db96fa..58e549ee16 100644 --- a/video/out/vo_xv.c +++ b/video/out/vo_xv.c @@ -97,7 +97,6 @@ struct xvctx { struct mp_rect src_rect; struct mp_rect dst_rect; uint32_t max_width, max_height; // zero means: not set - int mode_switched; int Shmem_Flag; #ifdef HAVE_SHM XShmSegmentInfo Shminfo[2]; @@ -532,13 +531,6 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, return -1; { -#ifdef CONFIG_XF86VM - int vm = flags & VOFLAG_MODESWITCHING; - if (vm) { - vo_vm_switch(vo); - ctx->mode_switched = 1; - } -#endif XGetWindowAttributes(x11->display, DefaultRootWindow(x11->display), &attribs); XMatchVisualInfo(x11->display, x11->screen, attribs.depth, TrueColor, @@ -554,17 +546,6 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, vo_x11_create_vo_window(vo, &vinfo, vo->dx, vo->dy, vo->dwidth, vo->dheight, flags, CopyFromParent, "xv"); XChangeWindowAttributes(x11->display, x11->window, xswamask, &xswa); - -#ifdef CONFIG_XF86VM - if (vm) { - /* Grab the mouse pointer in our window */ - if (vo_grabpointer) - XGrabPointer(x11->display, x11->window, True, 0, GrabModeAsync, - GrabModeAsync, x11->window, None, CurrentTime); - XSetInputFocus(x11->display, x11->window, RevertToNone, - CurrentTime); - } -#endif } mp_msg(MSGT_VO, MSGL_V, "using Xvideo port %d for hw scaling\n", @@ -831,10 +812,6 @@ static void uninit(struct vo *vo) } for (i = 0; i < ctx->total_buffers; i++) deallocate_xvimage(vo, i); -#ifdef CONFIG_XF86VM - if (ctx->mode_switched) - vo_vm_close(vo); -#endif // 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 c6075d79bb..fb4bcd9ac9 100644 --- a/video/out/x11_common.c +++ b/video/out/x11_common.c @@ -132,6 +132,8 @@ static void saver_off(struct vo_x11_state *x11); static void vo_x11_selectinput_witherr(Display *display, Window w, long event_mask); static void vo_x11_setlayer(struct vo *vo, Window vo_window, int layer); +static void vo_x11_vm_switch(struct vo *vo); +static void vo_x11_vm_close(struct vo *vo); /* * Sends the EWMH fullscreen state event. @@ -637,6 +639,7 @@ void vo_x11_uninit(struct vo *vo) struct vo_x11_state *x11 = vo->x11; assert(x11); + vo_x11_vm_close(vo); saver_on(x11); if (x11->window != None) vo_showcursor(x11->display, x11->window); @@ -1047,6 +1050,8 @@ void vo_x11_create_vo_window(struct vo *vo, XVisualInfo *vis, int x, int y, if (flags & VOFLAG_HIDDEN) goto final; if (x11->window_state & VOFLAG_HIDDEN) { + if (flags & VOFLAG_MODESWITCHING) + vo_x11_vm_switch(vo); XSizeHints hint; x11->window_state &= ~VOFLAG_HIDDEN; vo_x11_classhint(vo, x11->window, classname); @@ -1084,6 +1089,15 @@ void vo_x11_create_vo_window(struct vo *vo, XVisualInfo *vis, int x, int y, vo->dwidth = vo->opts->vo_screenwidth; vo->dheight = vo->opts->vo_screenheight; } + if (x11->vm_set) { + /* Grab the mouse pointer in our window */ + if (vo_grabpointer) { + XGrabPointer(x11->display, x11->window, True, 0, GrabModeAsync, + GrabModeAsync, x11->window, None, CurrentTime); + } + XSetInputFocus(x11->display, x11->window, RevertToNone, + CurrentTime); + } final: if (x11->vo_gc != None) XFreeGC(mDisplay, x11->vo_gc); @@ -1516,7 +1530,7 @@ static void vo_x11_selectinput_witherr(Display *display, Window w, } #ifdef CONFIG_XF86VM -void vo_vm_switch(struct vo *vo) +static void vo_x11_vm_switch(struct vo *vo) { struct vo_x11_state *x11 = vo->x11; struct MPOpts *opts = vo->opts; @@ -1581,7 +1595,7 @@ void vo_vm_switch(struct vo *vo) } } -void vo_vm_close(struct vo *vo) +static void vo_x11_vm_close(struct vo *vo) { struct vo_x11_state *x11 = vo->x11; Display *dpy = x11->display; @@ -1609,7 +1623,7 @@ void vo_vm_close(struct vo *vo) } } -double vo_vm_get_fps(struct vo *vo) +double vo_x11_vm_get_fps(struct vo *vo) { struct vo_x11_state *x11 = vo->x11; int clock; @@ -1620,6 +1634,22 @@ double vo_vm_get_fps(struct vo *vo) XFree(modeline.private); return 1e3 * clock / modeline.htotal / modeline.vtotal; } + +#else /* CONFIG_XF86VM */ + +static void vo_x11_vm_switch(struct vo *vo) +{ +} + +static void vo_x11_vm_close(struct vo *vo) +{ +} + +double vo_vm_get_fps(struct vo *vo) +{ + return 0; +} + #endif diff --git a/video/out/x11_common.h b/video/out/x11_common.h index 170418ec56..ab3539b36b 100644 --- a/video/out/x11_common.h +++ b/video/out/x11_common.h @@ -130,11 +130,7 @@ void vo_x11_ontop(struct vo *vo); void vo_x11_border(struct vo *vo); void vo_x11_update_screeninfo(struct vo *vo); -#ifdef CONFIG_XF86VM -void vo_vm_switch(struct vo *vo); -void vo_vm_close(struct vo *vo); -double vo_vm_get_fps(struct vo *vo); -#endif +double vo_x11_vm_get_fps(struct vo *vo); void xscreensaver_heartbeat(struct vo_x11_state *x11); -- cgit v1.2.3