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
206206 static void glx_swap_buffers(struct ra_ctx *ctx)
207207 {
208208 glXSwapBuffers(ctx->vo->x11->display, ctx->vo->x11->window);
209− vo_x11_present(ctx->vo);
210− present_sync_swap(ctx->vo->x11->present);
209+ if (ctx->vo->x11->use_present) {
210+ vo_x11_present(ctx->vo);
211+ present_sync_swap(ctx->vo->x11->present);
212+ }
211213 }
212214
213215 static void glx_get_vsync(struct ra_ctx *ctx, struct vo_vsync_info *info)
214216 {
215217 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);
217220 }
218221
219222 static 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
8282 struct priv *p = ctx->priv;
8383
8484 eglSwapBuffers(p->egl_display, p->egl_surface);
85− vo_x11_present(ctx->vo);
86− present_sync_swap(ctx->vo->x11->present);
85+ if (ctx->vo->x11->use_present) {
86+ vo_x11_present(ctx->vo);
87+ present_sync_swap(ctx->vo->x11->present);
88+ }
8789 }
8890
8991 static void mpegl_get_vsync(struct ra_ctx *ctx, struct vo_vsync_info *info)
9092 {
9193 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);
9396 }
9497
9598 static 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
308308 struct priv *p = vo->priv;
309309 Display_Image(p, p->myximage[p->current_buf]);
310310 p->current_buf = (p->current_buf + 1) % 2;
311− vo_x11_present(vo);
312− present_sync_swap(vo->x11->present);
311+ if (vo->x11->use_present) {
312+ vo_x11_present(vo);
313+ present_sync_swap(vo->x11->present);
314+ }
313315 }
314316
315317 static void get_vsync(struct vo *vo, struct vo_vsync_info *info)
316318 {
317319 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);
319322 }
320323
321324 // 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
691691 if (!ctx->Shmem_Flag)
692692 XSync(vo->x11->display, False);
693693
694− vo_x11_present(vo);
695− present_sync_swap(vo->x11->present);
694+ if (vo->x11->use_present) {
695+ vo_x11_present(vo);
696+ present_sync_swap(vo->x11->present);
697+ }
696698 }
697699
698700 static void get_vsync(struct vo *vo, struct vo_vsync_info *info)
699701 {
700702 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);
702705 }
703706
704707 // 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
3434
3535 static void xlib_vk_swap_buffers(struct ra_ctx *ctx)
3636 {
37− vo_x11_present(ctx->vo);
38− present_sync_swap(ctx->vo->x11->present);
37+ if (ctx->vo->x11->use_present) {
38+ vo_x11_present(ctx->vo);
39+ present_sync_swap(ctx->vo->x11->present);
40+ }
3941 }
4042
4143 static void xlib_vk_get_vsync(struct ra_ctx *ctx, struct vo_vsync_info *info)
4244 {
4345 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);
4548 }
4649
4750 static 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
377377 return wm;
378378 }
379379
380+static 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+
380393 static void xrandr_read(struct vo_x11_state *x11)
381394 {
382395 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
427440 nouveau >= 0 || radeon >= 0;
428441 x11->has_nvidia = x11->has_nvidia || nvidia >= 0;
429442 }
443+ if (x11->present_code)
444+ xpresent_set(x11);
430445 XRRFreeProviderResources(pr);
431446 }
432447
@@ -1286,13 +1301,10 @@ void vo_x11_check_events(struct vo *vo) · 853 unmodified lines
12861301 break;
12871302 case GenericEvent: {
12881303 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)
12901305 {
1291− int present = x11->opts->x11_present;
1292− bool use_present = (x11->has_mesa && !x11->has_nvidia &&
1293− present) || present == 2;
12941306 XGetEventData(x11->display, cookie);
1295− if (cookie->evtype == PresentCompleteNotify && use_present) {
1307+ if (cookie->evtype == PresentCompleteNotify) {
12961308 XPresentCompleteNotifyEvent *present_event;
12971309 present_event = (XPresentCompleteNotifyEvent *)cookie->data;
12981310 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
15301542
15311543 if (!XPresentQueryExtension(x11->display, &x11->present_code, NULL, NULL)) {
15321544 MP_VERBOSE(x11, "The XPresent extension is not supported.\n");
1533− x11->have_present = false;
15341545 } else {
1535− x11->have_present = true;
1546+ MP_VERBOSE(x11, "The XPresent extension was found.\n");
15361547 XPresentSelectInput(x11->display, x11->window, PresentCompleteNotifyMask);
15371548 }
1549+ xpresent_set(x11);
15381550
15391551 x11->mouse_cursor_set = false;
15401552 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
19621974 vo_x11_minimize(vo);
19631975 if (opt == &opts->window_maximized)
19641976 vo_x11_maximize(vo);
1977+ if (opt == &opts->x11_present)
1978+ xpresent_set(x11);
19651979 if (opt == &opts->geometry || opt == &opts->autofit ||
19661980 opt == &opts->autofit_smaller || opt == &opts->autofit_larger)
19671981 {
video/out/x11_common.h+1−1
@@ -76,7 +76,7 @@ struct vo_x11_state { · 75 unmodified lines
7676 double screensaver_time_last;
7777
7878 struct mp_present *present;
79− bool have_present;
79+ bool use_present;
8080 int present_code;
8181
8282 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