History

x11: avoid XPresent API calls when it's not needed

This commit kind of mixes several related things together. The main thing is to avoid calling any XPresent functions or internal functions related to presentation when the feature is not auto-whitelisted or enabled by the user. Internally rework this so it all works off of a use_present bool (have_present is eliminated because having a non-zero present_code covers exactly the same thing) and make sure it updates on runtime. Finally, put some actual logging in here whenever XPresent is enabled/disabled. Fixes #10326.

Dudemanguy committed 4 years ago

Commit 652f09a1 parent 1ffdb917 files · +52 −23Browse files

Unified · Split

7 files
  1. video/out/opengl/context_glx.c +6 −3
  2. video/out/opengl/context_x11egl.c +6 −3
  3. video/out/vo_x11.c +6 −3
  4. video/out/vo_xv.c +6 −3
  5. video/out/vulkan/context_xlib.c +6 −3
  6. video/out/x11_common.c +21 −7
  7. video/out/x11_common.h +1 −1
video/out/opengl/context_glx.c+6−3
@@ -206,14 +206,17 @@ static bool glx_check_visible(struct ra_ctx *ctx) · 205 unmodified lines
206static void glx_swap_buffers(struct ra_ctx *ctx)206static void glx_swap_buffers(struct ra_ctx *ctx)
207{207{
208 glXSwapBuffers(ctx->vo->x11->display, ctx->vo->x11->window);208 glXSwapBuffers(ctx->vo->x11->display, ctx->vo->x11->window);
209 vo_x11_present(ctx->vo);209 if (ctx->vo->x11->use_present) {
210 present_sync_swap(ctx->vo->x11->present);210 vo_x11_present(ctx->vo);
211 present_sync_swap(ctx->vo->x11->present);
212 }
211}213}
212 214
213static void glx_get_vsync(struct ra_ctx *ctx, struct vo_vsync_info *info)215static void glx_get_vsync(struct ra_ctx *ctx, struct vo_vsync_info *info)
214{216{
215 struct vo_x11_state *x11 = ctx->vo->x11;217 struct vo_x11_state *x11 = ctx->vo->x11;
216 present_sync_get_info(x11->present, info);218 if (ctx->vo->x11->use_present)
219 present_sync_get_info(x11->present, info);
217}220}
218 221
219static bool glx_init(struct ra_ctx *ctx)222static bool glx_init(struct ra_ctx *ctx)
video/out/opengl/context_x11egl.c+6−3
@@ -82,14 +82,17 @@ static void mpegl_swap_buffers(struct ra_ctx *ctx) · 81 unmodified lines
82 struct priv *p = ctx->priv;82 struct priv *p = ctx->priv;
83 83
84 eglSwapBuffers(p->egl_display, p->egl_surface);84 eglSwapBuffers(p->egl_display, p->egl_surface);
85 vo_x11_present(ctx->vo);85 if (ctx->vo->x11->use_present) {
86 present_sync_swap(ctx->vo->x11->present);86 vo_x11_present(ctx->vo);
87 present_sync_swap(ctx->vo->x11->present);
88 }
87}89}
88 90
89static void mpegl_get_vsync(struct ra_ctx *ctx, struct vo_vsync_info *info)91static void mpegl_get_vsync(struct ra_ctx *ctx, struct vo_vsync_info *info)
90{92{
91 struct vo_x11_state *x11 = ctx->vo->x11;93 struct vo_x11_state *x11 = ctx->vo->x11;
92 present_sync_get_info(x11->present, info);94 if (ctx->vo->x11->use_present)
95 present_sync_get_info(x11->present, info);
93}96}
94 97
95static bool mpegl_init(struct ra_ctx *ctx)98static bool mpegl_init(struct ra_ctx *ctx)
video/out/vo_x11.c+6−3
@@ -308,14 +308,17 @@ static void flip_page(struct vo *vo) · 307 unmodified lines
308 struct priv *p = vo->priv;308 struct priv *p = vo->priv;
309 Display_Image(p, p->myximage[p->current_buf]);309 Display_Image(p, p->myximage[p->current_buf]);
310 p->current_buf = (p->current_buf + 1) % 2;310 p->current_buf = (p->current_buf + 1) % 2;
311 vo_x11_present(vo);311 if (vo->x11->use_present) {
312 present_sync_swap(vo->x11->present);312 vo_x11_present(vo);
313 present_sync_swap(vo->x11->present);
314 }
313}315}
314 316
315static void get_vsync(struct vo *vo, struct vo_vsync_info *info)317static void get_vsync(struct vo *vo, struct vo_vsync_info *info)
316{318{
317 struct vo_x11_state *x11 = vo->x11;319 struct vo_x11_state *x11 = vo->x11;
318 present_sync_get_info(x11->present, info);320 if (x11->use_present)
321 present_sync_get_info(x11->present, info);
319}322}
320 323
321// Note: REDRAW_FRAME can call this with NULL.324// Note: REDRAW_FRAME can call this with NULL.
video/out/vo_xv.c+6−3
@@ -691,14 +691,17 @@ static void flip_page(struct vo *vo) · 690 unmodified lines
691 if (!ctx->Shmem_Flag)691 if (!ctx->Shmem_Flag)
692 XSync(vo->x11->display, False);692 XSync(vo->x11->display, False);
693 693
694 vo_x11_present(vo);694 if (vo->x11->use_present) {
695 present_sync_swap(vo->x11->present);695 vo_x11_present(vo);
696 present_sync_swap(vo->x11->present);
697 }
696}698}
697 699
698static void get_vsync(struct vo *vo, struct vo_vsync_info *info)700static void get_vsync(struct vo *vo, struct vo_vsync_info *info)
699{701{
700 struct vo_x11_state *x11 = vo->x11;702 struct vo_x11_state *x11 = vo->x11;
701 present_sync_get_info(x11->present, info);703 if (x11->use_present)
704 present_sync_get_info(x11->present, info);
702}705}
703 706
704// Note: REDRAW_FRAME can call this with NULL.707// Note: REDRAW_FRAME can call this with NULL.
video/out/vulkan/context_xlib.c+6−3
@@ -34,14 +34,17 @@ static bool xlib_check_visible(struct ra_ctx *ctx) · 33 unmodified lines
34 34
35static void xlib_vk_swap_buffers(struct ra_ctx *ctx)35static void xlib_vk_swap_buffers(struct ra_ctx *ctx)
36{36{
37 vo_x11_present(ctx->vo);37 if (ctx->vo->x11->use_present) {
38 present_sync_swap(ctx->vo->x11->present);38 vo_x11_present(ctx->vo);
39 present_sync_swap(ctx->vo->x11->present);
40 }
39}41}
40 42
41static void xlib_vk_get_vsync(struct ra_ctx *ctx, struct vo_vsync_info *info)43static void xlib_vk_get_vsync(struct ra_ctx *ctx, struct vo_vsync_info *info)
42{44{
43 struct vo_x11_state *x11 = ctx->vo->x11;45 struct vo_x11_state *x11 = ctx->vo->x11;
44 present_sync_get_info(x11->present, info);46 if (ctx->vo->x11->use_present)
47 present_sync_get_info(x11->present, info);
45}48}
46 49
47static void xlib_uninit(struct ra_ctx *ctx)50static void xlib_uninit(struct ra_ctx *ctx)
video/out/x11_common.c+21−7
@@ -377,6 +377,19 @@ static int vo_wm_detect(struct vo *vo) · 376 unmodified lines
377 return wm;377 return wm;
378}378}
379 379
380static void xpresent_set(struct vo_x11_state *x11)
381{
382 int present = x11->opts->x11_present;
383 x11->use_present = x11->present_code &&
384 ((x11->has_mesa && !x11->has_nvidia && present) ||
385 present == 2);
386 if (x11->use_present) {
387 MP_VERBOSE(x11, "XPresent enabled.\n");
388 } else {
389 MP_VERBOSE(x11, "XPresent disabled.\n");
390 }
391}
392
380static void xrandr_read(struct vo_x11_state *x11)393static void xrandr_read(struct vo_x11_state *x11)
381{394{
382 for(int i = 0; i < x11->num_displays; i++)395 for(int i = 0; i < x11->num_displays; i++)
@@ -427,6 +440,8 @@ static void xrandr_read(struct vo_x11_state *x11) · 44 unmodified lines
427 nouveau >= 0 || radeon >= 0;440 nouveau >= 0 || radeon >= 0;
428 x11->has_nvidia = x11->has_nvidia || nvidia >= 0;441 x11->has_nvidia = x11->has_nvidia || nvidia >= 0;
429 }442 }
443 if (x11->present_code)
444 xpresent_set(x11);
430 XRRFreeProviderResources(pr);445 XRRFreeProviderResources(pr);
431 }446 }
432 447
@@ -1286,13 +1301,10 @@ void vo_x11_check_events(struct vo *vo) · 853 unmodified lines
1286 break;1301 break;
1287 case GenericEvent: {1302 case GenericEvent: {
1288 XGenericEventCookie *cookie = (XGenericEventCookie *)&Event.xcookie;1303 XGenericEventCookie *cookie = (XGenericEventCookie *)&Event.xcookie;
1289 if (cookie->extension == x11->present_code && x11->have_present)1304 if (cookie->extension == x11->present_code && x11->use_present)
1290 {1305 {
1291 int present = x11->opts->x11_present;
1292 bool use_present = (x11->has_mesa && !x11->has_nvidia &&
1293 present) || present == 2;
1294 XGetEventData(x11->display, cookie);1306 XGetEventData(x11->display, cookie);
1295 if (cookie->evtype == PresentCompleteNotify && use_present) {1307 if (cookie->evtype == PresentCompleteNotify) {
1296 XPresentCompleteNotifyEvent *present_event;1308 XPresentCompleteNotifyEvent *present_event;
1297 present_event = (XPresentCompleteNotifyEvent *)cookie->data;1309 present_event = (XPresentCompleteNotifyEvent *)cookie->data;
1298 present_update_sync_values(x11->present, present_event->ust,1310 present_update_sync_values(x11->present, present_event->ust,
@@ -1530,11 +1542,11 @@ static void vo_x11_create_window(struct vo *vo, XVisualInfo *vis, · 231 unmodified lines
1530 1542
1531 if (!XPresentQueryExtension(x11->display, &x11->present_code, NULL, NULL)) {1543 if (!XPresentQueryExtension(x11->display, &x11->present_code, NULL, NULL)) {
1532 MP_VERBOSE(x11, "The XPresent extension is not supported.\n");1544 MP_VERBOSE(x11, "The XPresent extension is not supported.\n");
1533 x11->have_present = false;
1534 } else {1545 } else {
1535 x11->have_present = true;1546 MP_VERBOSE(x11, "The XPresent extension was found.\n");
1536 XPresentSelectInput(x11->display, x11->window, PresentCompleteNotifyMask);1547 XPresentSelectInput(x11->display, x11->window, PresentCompleteNotifyMask);
1537 }1548 }
1549 xpresent_set(x11);
1538 1550
1539 x11->mouse_cursor_set = false;1551 x11->mouse_cursor_set = false;
1540 x11->mouse_cursor_visible = true;1552 x11->mouse_cursor_visible = true;
@@ -1962,6 +1974,8 @@ int vo_x11_control(struct vo *vo, int *events, int request, void *arg) · 421 unmodified lines
1962 vo_x11_minimize(vo);1974 vo_x11_minimize(vo);
1963 if (opt == &opts->window_maximized)1975 if (opt == &opts->window_maximized)
1964 vo_x11_maximize(vo);1976 vo_x11_maximize(vo);
1977 if (opt == &opts->x11_present)
1978 xpresent_set(x11);
1965 if (opt == &opts->geometry || opt == &opts->autofit ||1979 if (opt == &opts->geometry || opt == &opts->autofit ||
1966 opt == &opts->autofit_smaller || opt == &opts->autofit_larger)1980 opt == &opts->autofit_smaller || opt == &opts->autofit_larger)
1967 {1981 {
video/out/x11_common.h+1−1
@@ -76,7 +76,7 @@ struct vo_x11_state { · 75 unmodified lines
76 double screensaver_time_last;76 double screensaver_time_last;
77 77
78 struct mp_present *present;78 struct mp_present *present;
79 bool have_present;79 bool use_present;
80 int present_code;80 int present_code;
81 81
82 XIM xim;82 XIM xim;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t