x11: stop using vo.event_fd

Instead let it do its own event loop wakeup handling.
This commit is contained in:
wm4 2016-07-20 20:52:08 +02:00
parent bd9c0a10e5
commit fde784129f
8 changed files with 72 additions and 1 deletions

View File

@ -308,6 +308,16 @@ static void glx_swap_buffers(struct MPGLContext *ctx)
glXSwapBuffers(ctx->vo->x11->display, ctx->vo->x11->window);
}
static void glx_wakeup(struct MPGLContext *ctx)
{
vo_x11_wakeup(ctx->vo);
}
static void glx_wait_events(struct MPGLContext *ctx, int64_t until_time_us)
{
vo_x11_wait_events(ctx->vo, until_time_us);
}
const struct mpgl_driver mpgl_driver_x11 = {
.name = "x11",
.priv_size = sizeof(struct glx_context),
@ -315,6 +325,8 @@ const struct mpgl_driver mpgl_driver_x11 = {
.reconfig = glx_reconfig,
.swap_buffers = glx_swap_buffers,
.control = glx_control,
.wakeup = glx_wakeup,
.wait_events = glx_wait_events,
.uninit = glx_uninit,
};
@ -325,5 +337,7 @@ const struct mpgl_driver mpgl_driver_x11_probe = {
.reconfig = glx_reconfig,
.swap_buffers = glx_swap_buffers,
.control = glx_control,
.wakeup = glx_wakeup,
.wait_events = glx_wait_events,
.uninit = glx_uninit,
};

View File

@ -191,6 +191,16 @@ static void mpegl_swap_buffers(MPGLContext *ctx)
eglSwapBuffers(p->egl_display, p->egl_surface);
}
static void mpegl_wakeup(struct MPGLContext *ctx)
{
vo_x11_wakeup(ctx->vo);
}
static void mpegl_wait_events(struct MPGLContext *ctx, int64_t until_time_us)
{
vo_x11_wait_events(ctx->vo, until_time_us);
}
const struct mpgl_driver mpgl_driver_x11egl = {
.name = "x11egl",
.priv_size = sizeof(struct priv),
@ -198,5 +208,7 @@ const struct mpgl_driver mpgl_driver_x11egl = {
.reconfig = mpegl_reconfig,
.swap_buffers = mpegl_swap_buffers,
.control = mpegl_control,
.wakeup = mpegl_wakeup,
.wait_events = mpegl_wait_events,
.uninit = mpegl_uninit,
};

View File

@ -682,6 +682,8 @@ const struct vo_driver video_out_vaapi = {
.control = control,
.draw_image = draw_image,
.flip_page = flip_page,
.wakeup = vo_x11_wakeup,
.wait_events = vo_x11_wait_events,
.uninit = uninit,
.priv_size = sizeof(struct priv),
.priv_defaults = &(const struct priv) {

View File

@ -1139,6 +1139,8 @@ const struct vo_driver video_out_vdpau = {
.control = control,
.draw_frame = draw_frame,
.flip_page = flip_page,
.wakeup = vo_x11_wakeup,
.wait_events = vo_x11_wait_events,
.uninit = uninit,
.priv_size = sizeof(struct vdpctx),
.options = (const struct m_option []){

View File

@ -449,5 +449,7 @@ const struct vo_driver video_out_x11 = {
.control = control,
.draw_image = draw_image,
.flip_page = flip_page,
.wakeup = vo_x11_wakeup,
.wait_events = vo_x11_wait_events,
.uninit = uninit,
};

View File

@ -905,6 +905,8 @@ const struct vo_driver video_out_xv = {
.control = control,
.draw_image = draw_image,
.flip_page = flip_page,
.wakeup = vo_x11_wakeup,
.wait_events = vo_x11_wait_events,
.uninit = uninit,
.priv_size = sizeof(struct xvctx),
.priv_defaults = &(const struct xvctx) {

View File

@ -20,6 +20,8 @@
#include <math.h>
#include <inttypes.h>
#include <limits.h>
#include <unistd.h>
#include <poll.h>
#include "config.h"
#include "misc/bstr.h"
@ -38,6 +40,7 @@
#include "vo.h"
#include "win_state.h"
#include "osdep/atomics.h"
#include "osdep/io.h"
#include "osdep/timer.h"
#include "osdep/subprocess.h"
@ -593,7 +596,8 @@ int vo_x11_init(struct vo *vo)
x11->wm_type = vo_wm_detect(vo);
vo->event_fd = ConnectionNumber(x11->display);
x11->event_fd = ConnectionNumber(x11->display);
mp_make_wakeup_pipe(x11->wakeup_pipe);
xrandr_read(x11);
@ -761,6 +765,9 @@ void vo_x11_uninit(struct vo *vo)
sem_destroy(&x11->screensaver_sem);
}
for (int n = 0; n < 2; n++)
close(x11->wakeup_pipe[n]);
talloc_free(x11);
vo->x11 = NULL;
}
@ -1907,6 +1914,32 @@ int vo_x11_control(struct vo *vo, int *events, int request, void *arg)
return VO_NOTIMPL;
}
void vo_x11_wakeup(struct vo *vo)
{
struct vo_x11_state *x11 = vo->x11;
(void)write(x11->wakeup_pipe[1], &(char){0}, 1);
}
void vo_x11_wait_events(struct vo *vo, int64_t until_time_us)
{
struct vo_x11_state *x11 = vo->x11;
struct pollfd fds[2] = {
{ .fd = x11->event_fd, .events = POLLIN },
{ .fd = x11->wakeup_pipe[0], .events = POLLIN },
};
int64_t wait_us = until_time_us - mp_time_us();
int timeout_ms = MPCLAMP((wait_us + 500) / 1000, 0, 10000);
poll(fds, 2, timeout_ms);
if (fds[1].revents & POLLIN) {
char buf[100];
(void)read(x11->wakeup_pipe[0], buf, sizeof(buf)); // flush
}
}
static void xscreensaver_heartbeat(struct vo_x11_state *x11)
{
double time = mp_time_sec();

View File

@ -45,6 +45,8 @@ struct vo_x11_state {
struct mp_log *log;
struct input_ctx *input_ctx;
Display *display;
int event_fd;
int wakeup_pipe[2];
Window window;
Window rootwin;
Window parent; // embedded in this foreign window
@ -132,6 +134,8 @@ bool vo_x11_create_vo_window(struct vo *vo, XVisualInfo *vis,
const char *classname);
void vo_x11_config_vo_window(struct vo *vo);
int vo_x11_control(struct vo *vo, int *events, int request, void *arg);
void vo_x11_wakeup(struct vo *vo);
void vo_x11_wait_events(struct vo *vo, int64_t until_time_us);
void vo_x11_silence_xlib(int dir);