From 9547c285837e80af059f7676e8af856fb55d1c14 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Fri, 29 Jul 2022 20:54:30 +0800 Subject: [PATCH] Fix handling of extended frame resize synchronization * src/xterm.c (x_sync_wait_for_frame_drawn_event): Don't wait if the frame is invisible. If it is mapped again the compositing manager is obliged to send us another event, so we can wait in that case. (x_sync_update_begin, x_sync_update_finish): Handle extended resize synchronization here. (XTframe_up_to_date, handle_one_xevent): Save stuff here. * src/xterm.h (struct x_output): New field `resize_counter_value'. --- src/xterm.c | 67 ++++++++++++++++++++++------------------------------- src/xterm.h | 3 +++ 2 files changed, 31 insertions(+), 39 deletions(-) diff --git a/src/xterm.c b/src/xterm.c index 7399ec3e42d..60eab0f9b0d 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -6625,7 +6625,10 @@ x_sync_wait_for_frame_drawn_event (struct frame *f) { XEvent event; - if (!FRAME_X_WAITING_FOR_DRAW (f)) + if (!FRAME_X_WAITING_FOR_DRAW (f) + /* The compositing manager can't draw a frame if it is + unmapped. */ + || !FRAME_VISIBLE_P (f)) return; /* Wait for the frame drawn message to arrive. */ @@ -6648,6 +6651,25 @@ x_sync_update_begin (struct frame *f) value = FRAME_X_COUNTER_VALUE (f); + if (FRAME_X_OUTPUT (f)->ext_sync_end_pending_p) + { + FRAME_X_COUNTER_VALUE (f) + = FRAME_X_OUTPUT (f)->resize_counter_value; + + value = FRAME_X_COUNTER_VALUE (f); + + if (XSyncValueLow32 (value) % 2) + { + XSyncIntToValue (&add, 1); + XSyncValueAdd (&value, value, add, &overflow); + + if (overflow) + XSyncIntToValue (&value, 0); + } + + FRAME_X_OUTPUT (f)->ext_sync_end_pending_p = false; + } + /* Since a frame is already in progress, there is no point in continuing. */ if (XSyncValueLow32 (value) % 2) @@ -6688,9 +6710,6 @@ x_sync_update_finish (struct frame *f) if (FRAME_X_EXTENDED_COUNTER (f) == None) return; - if (FRAME_X_OUTPUT (f)->ext_sync_end_pending_p) - return; - value = FRAME_X_COUNTER_VALUE (f); if (!(XSyncValueLow32 (value) % 2)) @@ -6824,11 +6843,12 @@ x_draw_window_divider (struct window *w, int x0, int x1, int y0, int y1) } } +#ifdef HAVE_XDBE + /* Show the frame back buffer. If frame is double-buffered, atomically publish to the user's screen graphics updates made since the last call to show_back_buffer. */ -#ifdef HAVE_XDBE static void show_back_buffer (struct frame *f) { @@ -6870,6 +6890,7 @@ show_back_buffer (struct frame *f) unblock_input (); } + #endif /* Updates back buffer and flushes changes to display. Called from @@ -6927,11 +6948,7 @@ x_update_end (struct frame *f) static void XTframe_up_to_date (struct frame *f) { -#if defined HAVE_XSYNC && !defined HAVE_GTK3 - XSyncValue add; - XSyncValue current; - Bool overflow_p; -#elif defined HAVE_XSYNC +#if defined HAVE_XSYNC && defined HAVE_GTK3 GtkWidget *widget; GdkWindow *window; GdkFrameClock *clock; @@ -6957,34 +6974,6 @@ XTframe_up_to_date (struct frame *f) FRAME_X_OUTPUT (f)->pending_basic_counter_value); FRAME_X_OUTPUT (f)->sync_end_pending_p = false; } - - if (FRAME_X_OUTPUT (f)->ext_sync_end_pending_p - && FRAME_X_EXTENDED_COUNTER (f) != None) - { - current = FRAME_X_COUNTER_VALUE (f); - - if (XSyncValueLow32 (current) % 2) - XSyncIntToValue (&add, 1); - else - XSyncIntToValue (&add, 2); - - XSyncValueAdd (&FRAME_X_COUNTER_VALUE (f), - current, add, &overflow_p); - - if (overflow_p) - emacs_abort (); - - XSyncSetCounter (FRAME_X_DISPLAY (f), - FRAME_X_EXTENDED_COUNTER (f), - FRAME_X_COUNTER_VALUE (f)); - - FRAME_X_OUTPUT (f)->ext_sync_end_pending_p = false; - -#ifndef USE_GTK - if (FRAME_OUTPUT_DATA (f)->use_vsync_p) - FRAME_X_WAITING_FOR_DRAW (f) = true; -#endif - } #else if (FRAME_X_OUTPUT (f)->xg_sync_end_pending_p) { @@ -17023,7 +17012,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, } else if (event->xclient.data.l[4] == 1) { - XSyncIntsToValue (&FRAME_X_COUNTER_VALUE (f), + XSyncIntsToValue (&FRAME_X_OUTPUT (f)->resize_counter_value, event->xclient.data.l[2], event->xclient.data.l[3]); diff --git a/src/xterm.h b/src/xterm.h index 1163dd5cd1e..2e3d0950d91 100644 --- a/src/xterm.h +++ b/src/xterm.h @@ -1038,6 +1038,9 @@ struct x_output /* The current value of the extended counter. */ XSyncValue current_extended_counter_value; + /* The configure event value of the extended counter. */ + XSyncValue resize_counter_value; + /* Whether or not basic resize synchronization is in progress. */ bool_bf sync_end_pending_p : 1; -- 2.39.5