This is an automated email from the git hooks/post-receive script.
git pushed a commit to reference refs/pull/122/head
in repository efl.
View the commit online.
commit 450adbb36ac85c841e4ca5cb8ba765c7b5640aa9
Author: Cedric BAIL <[email protected]>
AuthorDate: Wed Nov 25 16:56:30 2026 -0600
ecore_evas_x: tick top-level GL windows from X Present
The global ecore_x DRM vsync tick follows CRTC 0 only. A GL window on
another monitor with a lower refresh rate (a 144 Hz laptop panel plus a
30 Hz HDMI screen here) was rendered at the CRTC 0 rate, so Mesa's DRI3
swap throttle (at most 2 presents in flight) blocked the main loop in
eglSwapBuffers for about half of each second. In a two window test both
windows rendered at 30/s and the main loop was blocked about 8 s out of
9.
Tick each top-level GL window from its own vblank instead, using
PresentPixmap completions and NotifyMSC. The same test now gives 144/s
on the panel and 30/s on HDMI, with no blocking. In expedite the overall
score stays within about 3% (opengl_x11 on the panel: 3412 with the
Present tick, 3511 without), and software_x11 is unchanged.
Only windows whose parent is the root are handled. Software windows
never PresentPixmap, and Xorg keeps NotifyMSC on the window's last
PresentPixmap CRTC. Compositor canvases such as Enlightenment's, which
have a non-root parent, keep the legacy path and its tick delay.
A window ticks the legacy way until its first PresentPixmap completion,
so drivers that never send one (NVIDIA GLX, llvmpipe, Xvnc) are
unchanged. There is at most one tick per vblank (msc) so that windows
without vsync do not spin, and a watchdog covers lost events. When the
outputs are blanked, Xorg falls back to a fake 1 Hz vblank; a frame
still in flight is then waited for rather than forced through.
ECORE_EVAS_X_NO_PRESENT_TICK=1 disables it.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/modules/ecore_evas/engines/x/ecore_evas_x.c | 393 +++++++++++++++++++++++-
1 file changed, 391 insertions(+), 2 deletions(-)
diff --git a/src/modules/ecore_evas/engines/x/ecore_evas_x.c b/src/modules/ecore_evas/engines/x/ecore_evas_x.c
index b577a2a840..c992b0d846 100644
--- a/src/modules/ecore_evas/engines/x/ecore_evas_x.c
+++ b/src/modules/ecore_evas/engines/x/ecore_evas_x.c
@@ -52,7 +52,7 @@
static int _ecore_evas_init_count = 0;
-static Ecore_Event_Handler *ecore_evas_event_handlers[14];
+static Ecore_Event_Handler *ecore_evas_event_handlers[15];
static int leader_ref = 0;
static Ecore_X_Window leader_win = 0;
@@ -142,6 +142,21 @@ struct _Ecore_Evas_Engine_Data_X11 {
Eina_Array *xserver_atom_name_during_dnd;
Ecore_Event_Handler *mouse_up_handler;
Ecore_Job *init_job;
+ struct {
+ Ecore_Timer *watchdog;
+ Ecore_Animator *fallback; // ticks while the window is not armed
+ double last_tick; // time of the last vblank reported by a completion, ticking or not
+ double period; // frame period estimated from completions, 0 if unknown
+ unsigned long long last_msc; // msc of the last tick, kept across CRTC moves by Xorg
+ unsigned long long last_vblank_msc; // msc of the completion that set last_tick
+ double last_sent; // ecore_time_get() when the last frame was handed over
+ int frames_pending; // frames handed to the X server without a completion yet
+ unsigned int notify_serial; // serial of the outstanding NotifyMSC
+ Eina_Bool ticking : 1;
+ Eina_Bool armed : 1; // the window did receive a PresentPixmap completion, until it is lost
+ Eina_Bool notify_outstanding : 1;
+ Eina_Bool completed_since_sent : 1;
+ } present;
int skip_clean_event;
Eina_Bool destroyed : 1; // X window has been deleted and cannot be used
Eina_Bool fully_obscured : 1; // X window is fully obscured
@@ -171,6 +186,346 @@ static void _ecore_evas_x_selection_window_init(Ecore_Evas *ee);
#define SWAP_INT(a, b) do { a ^= b; b ^= a; a ^= b; } while (0)
+#define PRESENT_WATCHDOG_DELAY 0.1
+#define PRESENT_LOST_DELAY 3.0
+#define PRESENT_MAX_FRAMES_IN_FLIGHT 2
+#define PRESENT_UST_MAX_AGE 0.1
+/* Our NotifyMSC requests carry this bit so they can not be confused with a
+ * request made by another user of the window (Mesa, ...). */
+#define PRESENT_NOTIFY_SERIAL_FLAG 0x80000000U
+
+static Ecore_Evas_Engine_Func _ecore_x_engine_func_present;
+static Eina_Bool _ecore_evas_x_present_tick_enabled = EINA_FALSE;
+/* Windows on different screens get ust from different CRTCs: keeps the times
+ * of the Present ticks monotonic from one Present window to the next. It does
+ * not constrain the loop time set by anything else. */
+static double _ecore_evas_x_present_loop_time_floor = 0.0;
+
+/* Present's ust is CLOCK_MONOTONIC in microseconds on Linux, the clock
+ * ecore_time_get() uses. Anything that does not look like a recent vblank
+ * is replaced by the current time. */
+static double
+_ecore_evas_x_present_tick_time_get(unsigned long long ust)
+{
+ double now = ecore_time_get();
+
+ if (ust)
+ {
+ double t = (double)ust / 1000000.0;
+
+ if ((t >= now - PRESENT_UST_MAX_AGE) && (t <= now) &&
+ (t >= _ecore_evas_x_present_loop_time_floor))
+ return t;
+ }
+ return now;
+}
+
+/* A window is ticked by Present only once it is armed, that is once it
+ * completed a PresentPixmap: until then (and for the drivers that never
+ * present, like NVIDIA's or swrast) it ticks like a plain X window. */
+static Eina_Bool
+_ecore_evas_x_present_active(Ecore_Evas *ee)
+{
+ Ecore_Evas_Engine_Data_X11 *edata = ee->engine.data;
+
+ return (ee->engine.func == &_ecore_x_engine_func_present) &&
+ edata->present.ticking && edata->present.armed && !edata->destroyed &&
+ ee->prop.window;
+}
+
+static Eina_Bool
+_ecore_evas_x_present_fallback_cb(void *data)
+{
+ ecore_evas_animator_tick(data, NULL, ecore_loop_time_get());
+ return ECORE_CALLBACK_RENEW;
+}
+
+static void
+_ecore_evas_x_present_fallback_stop(Ecore_Evas *ee)
+{
+ Ecore_Evas_Engine_Data_X11 *edata = ee->engine.data;
+
+ if (!edata->present.fallback) return;
+ ecore_animator_del(edata->present.fallback);
+ edata->present.fallback = NULL;
+}
+
+static void _ecore_evas_x_present_watchdog_ensure(Ecore_Evas *ee);
+static void _ecore_evas_x_present_watchdog_stop(Ecore_Evas *ee);
+
+static void
+_ecore_evas_x_present_armed_set(Ecore_Evas *ee, Eina_Bool armed)
+{
+ Ecore_Evas_Engine_Data_X11 *edata = ee->engine.data;
+
+ if (edata->present.armed == armed) return;
+ edata->present.armed = armed;
+ if (!armed) edata->present.last_tick = 0.0;
+ if (!edata->present.ticking) return;
+
+ if (armed)
+ {
+ _ecore_evas_x_present_fallback_stop(ee);
+ _ecore_evas_x_present_watchdog_ensure(ee);
+ }
+ else
+ {
+ _ecore_evas_x_present_watchdog_stop(ee);
+ edata->present.notify_outstanding = EINA_FALSE;
+ if (!edata->destroyed && !edata->present.fallback)
+ edata->present.fallback = ecore_animator_add(_ecore_evas_x_present_fallback_cb, ee);
+ }
+}
+
+/* Records a vblank reported by a completion: its time and the frame period
+ * it implies together with the previous one. */
+static double
+_ecore_evas_x_present_vblank_record(Ecore_Evas *ee, unsigned long long ust, unsigned long long msc)
+{
+ Ecore_Evas_Engine_Data_X11 *edata = ee->engine.data;
+ double t = _ecore_evas_x_present_tick_time_get(ust);
+
+ _ecore_evas_x_present_loop_time_floor = t;
+ if ((edata->present.last_tick > 0.0) && (msc > edata->present.last_vblank_msc) &&
+ (t > edata->present.last_tick))
+ edata->present.period = (t - edata->present.last_tick) /
+ (double)(msc - edata->present.last_vblank_msc);
+ edata->present.last_tick = t;
+ edata->present.last_vblank_msc = msc;
+ return t;
+}
+
+static void
+_ecore_evas_x_present_tick(Ecore_Evas *ee, double t, unsigned long long msc)
+{
+ Ecore_Evas_Engine_Data_X11 *edata = ee->engine.data;
+
+ if (msc > edata->present.last_msc) edata->present.last_msc = msc;
+ edata->present.notify_outstanding = EINA_FALSE;
+ if (edata->present.watchdog) ecore_timer_reset(edata->present.watchdog);
+ else _ecore_evas_x_present_watchdog_ensure(ee);
+ ecore_evas_animator_tick(ee, NULL, t);
+}
+
+static Eina_Bool
+_ecore_evas_x_present_watchdog_cb(void *data)
+{
+ Ecore_Evas *ee = data;
+ Ecore_Evas_Engine_Data_X11 *edata = ee->engine.data;
+ double t;
+
+ edata->present.watchdog = NULL;
+ if (!_ecore_evas_x_present_active(ee)) return ECORE_CALLBACK_CANCEL;
+ if (edata->present.frames_pending > 0)
+ {
+ if (!edata->present.completed_since_sent)
+ {
+ /* A blanked output makes Xorg fake a 1 Hz vblank: rendering now
+ * would queue a second present that Mesa blocks on. */
+ if ((ecore_time_get() - edata->present.last_sent) <
+ PRESENT_LOST_DELAY)
+ {
+ _ecore_evas_x_present_watchdog_ensure(ee);
+ return ECORE_CALLBACK_CANCEL;
+ }
+ edata->present.frames_pending = 0;
+ _ecore_evas_x_present_armed_set(ee, EINA_FALSE);
+ return ECORE_CALLBACK_CANCEL;
+ }
+ edata->present.frames_pending = 0;
+ }
+ t = _ecore_evas_x_present_tick_time_get(0);
+ _ecore_evas_x_present_loop_time_floor = t;
+ _ecore_evas_x_present_tick(ee, t, 0);
+ return ECORE_CALLBACK_CANCEL;
+}
+
+static void
+_ecore_evas_x_present_watchdog_ensure(Ecore_Evas *ee)
+{
+ Ecore_Evas_Engine_Data_X11 *edata = ee->engine.data;
+
+ if (!edata->present.watchdog)
+ edata->present.watchdog = ecore_timer_add(PRESENT_WATCHDOG_DELAY,
+ _ecore_evas_x_present_watchdog_cb, ee);
+}
+
+static void
+_ecore_evas_x_present_watchdog_stop(Ecore_Evas *ee)
+{
+ Ecore_Evas_Engine_Data_X11 *edata = ee->engine.data;
+
+ if (!edata->present.watchdog) return;
+ ecore_timer_del(edata->present.watchdog);
+ edata->present.watchdog = NULL;
+}
+
+/* A request for the next vblank: with a divisor of 1 and a target in the
+ * past, Present delivers the event after the next field, whatever the
+ * current msc of the window's CRTC is (see PresentNotifyMSC in presentproto).
+ * A target derived from the last msc seen could be far in the future if the
+ * window moved to another CRTC. */
+static void
+_ecore_evas_x_present_notify_request(Ecore_Evas *ee)
+{
+ Ecore_Evas_Engine_Data_X11 *edata = ee->engine.data;
+
+ edata->present.notify_serial =
+ (edata->present.notify_serial + 1) | PRESENT_NOTIFY_SERIAL_FLAG;
+ edata->present.notify_outstanding = EINA_TRUE;
+ ecore_x_present_notify_msc(ee->prop.window, edata->present.notify_serial,
+ 0, 1, 0);
+}
+
+/* Makes sure a tick is on its way: the completion of a frame in flight
+ * when the window is paced by Present completions, the next vblank
+ * otherwise. */
+static void
+_ecore_evas_x_present_next_tick_ensure(Ecore_Evas *ee)
+{
+ Ecore_Evas_Engine_Data_X11 *edata = ee->engine.data;
+
+ if (!_ecore_evas_x_present_active(ee)) return;
+ _ecore_evas_x_present_watchdog_ensure(ee);
+ if (edata->present.frames_pending > 0) return;
+ if (!edata->present.notify_outstanding) _ecore_evas_x_present_notify_request(ee);
+}
+
+static void
+_ecore_evas_x_present_frame_sent(Ecore_Evas *ee)
+{
+ Ecore_Evas_Engine_Data_X11 *edata = ee->engine.data;
+
+ if (ee->engine.func != &_ecore_x_engine_func_present) return;
+ edata->present.completed_since_sent = EINA_FALSE;
+ edata->present.last_sent = ecore_time_get();
+ if (++edata->present.frames_pending > PRESENT_MAX_FRAMES_IN_FLIGHT)
+ {
+ edata->present.frames_pending = 0;
+ _ecore_evas_x_present_armed_set(ee, EINA_FALSE);
+ }
+}
+
+static Eina_Bool
+_ecore_evas_x_present_complete_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
+{
+ Ecore_X_Event_Present_Complete *ev = event;
+ Ecore_Evas_Engine_Data_X11 *edata;
+ Ecore_Evas *ee;
+ double t;
+
+ ee = ecore_event_window_match(ev->win);
+ if (!ee || (ee->prop.window != ev->win) ||
+ (ee->engine.func != &_ecore_x_engine_func_present))
+ return ECORE_CALLBACK_PASS_ON;
+ edata = ee->engine.data;
+ if (edata->destroyed) return ECORE_CALLBACK_PASS_ON;
+
+ if (ev->kind)
+ {
+ if (!(ev->serial & PRESENT_NOTIFY_SERIAL_FLAG) ||
+ !edata->present.notify_outstanding ||
+ (ev->serial != edata->present.notify_serial))
+ return ECORE_CALLBACK_PASS_ON;
+ edata->present.notify_outstanding = EINA_FALSE;
+ t = _ecore_evas_x_present_vblank_record(ee, ev->ust, ev->msc);
+ /* NotifyMSC reports the real msc of the window: it may have gone
+ * backwards (modeset, resume, output change). */
+ edata->present.last_msc = ev->msc;
+ if (!_ecore_evas_x_present_active(ee) || (edata->present.frames_pending > 0) ||
+ ee->animator_ticked || ee->animator_ran)
+ return ECORE_CALLBACK_PASS_ON;
+ _ecore_evas_x_present_tick(ee, t, ev->msc);
+ return ECORE_CALLBACK_PASS_ON;
+ }
+
+ t = _ecore_evas_x_present_vblank_record(ee, ev->ust, ev->msc);
+ edata->present.completed_since_sent = EINA_TRUE;
+ if (edata->present.frames_pending > 0) edata->present.frames_pending--;
+ _ecore_evas_x_present_armed_set(ee, EINA_TRUE);
+ if (_ecore_evas_x_present_active(ee) && (edata->present.frames_pending == 0))
+ {
+ edata->present.notify_outstanding = EINA_FALSE;
+ if (ee->animator_ticked || ee->animator_ran) return ECORE_CALLBACK_PASS_ON;
+ /* Without vsync (swap interval 0) completions arrive at once, many
+ * per vblank: wait for the next one instead of spinning. */
+ if (ev->msc > edata->present.last_msc)
+ _ecore_evas_x_present_tick(ee, t, ev->msc);
+ else
+ _ecore_evas_x_present_notify_request(ee);
+ }
+ return ECORE_CALLBACK_PASS_ON;
+}
+
+static void
+_ecore_evas_x_present_animator_register(Ecore_Evas *ee)
+{
+ Ecore_Evas_Engine_Data_X11 *edata = ee->engine.data;
+
+ edata->present.ticking = EINA_TRUE;
+ if (!edata->present.armed)
+ {
+ if (!edata->present.fallback)
+ edata->present.fallback = ecore_animator_add(_ecore_evas_x_present_fallback_cb, ee);
+ return;
+ }
+ if (ee->animator_ticked || ee->animator_ran)
+ {
+ _ecore_evas_x_present_watchdog_ensure(ee);
+ return;
+ }
+ _ecore_evas_x_present_next_tick_ensure(ee);
+}
+
+static void
+_ecore_evas_x_present_animator_unregister(Ecore_Evas *ee)
+{
+ Ecore_Evas_Engine_Data_X11 *edata = ee->engine.data;
+
+ edata->present.ticking = EINA_FALSE;
+ edata->present.notify_outstanding = EINA_FALSE;
+ _ecore_evas_x_present_watchdog_stop(ee);
+ _ecore_evas_x_present_fallback_stop(ee);
+}
+
+static void
+_ecore_evas_x_present_evas_changed(Ecore_Evas *ee, Eina_Bool changed EINA_UNUSED)
+{
+ _ecore_evas_x_present_next_tick_ensure(ee);
+}
+
+/* The time of the last vblank a completion reported for the window when it
+ * is armed and that vblank is less than a frame period old, -1 otherwise. */
+static double
+_ecore_evas_x_present_last_tick_get(Ecore_Evas *ee)
+{
+ Ecore_Evas_Engine_Data_X11 *edata = ee->engine.data;
+
+ if (!edata->present.armed || edata->destroyed) return -1.0;
+ if ((edata->present.last_tick <= 0.0) || (edata->present.period <= 0.0) ||
+ ((ecore_time_get() - edata->present.last_tick) > edata->present.period))
+ return -1.0;
+ return edata->present.last_tick;
+}
+
+/* Called each time ee gets a new X window. Does nothing for an
+ * Ecore_Evas that is not ticked by Present. */
+static void
+_ecore_evas_x_present_window_setup(Ecore_Evas *ee, Ecore_X_Window win)
+{
+ Ecore_Evas_Engine_Data_X11 *edata = ee->engine.data;
+
+ if (ee->engine.func != &_ecore_x_engine_func_present) return;
+ ecore_x_present_select_events(win, ECORE_X_PRESENT_EVENT_MASK_COMPLETE_NOTIFY);
+ edata->present.frames_pending = 0;
+ edata->present.last_msc = 0;
+ edata->present.last_vblank_msc = 0;
+ edata->present.period = 0.0;
+ edata->present.completed_since_sent = EINA_FALSE;
+ edata->present.notify_outstanding = EINA_FALSE;
+ _ecore_evas_x_present_armed_set(ee, EINA_FALSE);
+}
+
static void
_ecore_evas_x_hints_update(Ecore_Evas *ee)
{
@@ -511,6 +866,7 @@ _ecore_evas_x_gl_window_new(Ecore_Evas *ee, Ecore_X_Window parent, int x, int y,
override);
ecore_x_window_pixel_gravity_set(win, ECORE_X_GRAVITY_FORGET);
ecore_x_vsync_animator_tick_source_set(win);
+ _ecore_evas_x_present_window_setup(ee, win);
/* attr.backing_store = NotUseful; */
/* attr.override_redirect = override; */
@@ -755,6 +1111,7 @@ _ecore_evas_x_render(Ecore_Evas *ee)
if (!ee->can_async_render)
{
Eina_List *updates = evas_render_updates(ee->evas);
+ if (updates) _ecore_evas_x_present_frame_sent(ee);
rend = _render_updates_process(ee, updates);
evas_render_updates_free(updates);
}
@@ -1992,6 +2349,14 @@ _ecore_evas_x_init(void)
ecore_evas_event_handlers[13] =
ecore_event_handler_add(ECORE_X_EVENT_WINDOW_CREATE,
_ecore_evas_x_event_window_create, NULL);
+ /* ECORE_EVAS_X_NO_PRESENT_TICK disables the per window ticking from
+ * X Present: OpenGL windows tick like the other X windows. */
+ _ecore_evas_x_present_tick_enabled = ecore_x_present_exists() &&
+ !getenv("ECORE_EVAS_X_NO_PRESENT_TICK") &&
+ !getenv("ECORE_X_VSYNC_PRESENT");
+ ecore_evas_event_handlers[14] = _ecore_evas_x_present_tick_enabled ?
+ ecore_event_handler_add(ECORE_X_EVENT_PRESENT_COMPLETE,
+ _ecore_evas_x_present_complete_cb, NULL) : NULL;
ecore_event_evas_init();
_ecore_evas_x_selection_init();
return _ecore_evas_init_count;
@@ -2022,6 +2387,8 @@ _ecore_evas_x_free(Ecore_Evas *ee)
Ecore_Evas_Engine_Data_X11 *edata = ee->engine.data;
ecore_job_del(edata->init_job);
+ _ecore_evas_x_present_watchdog_stop(ee);
+ _ecore_evas_x_present_fallback_stop(ee);
if (edata->pixmap.back)
ecore_x_pixmap_free(edata->pixmap.back);
if (edata->pixmap.front)
@@ -4632,6 +4999,27 @@ static Ecore_Evas_Engine_Func _ecore_x_engine_func =
_ecore_evas_x_dnd_stop, //fn_dnd_stop
};
+/* Only top-level OpenGL windows are ticked by Present. Software windows draw
+ * with XShm, never PresentPixmap, and Xorg keeps NotifyMSC on the window's
+ * last PresentPixmap CRTC. A window with another parent, such as the canvas
+ * of a compositor, keeps the plain table and so the global animator. */
+static Ecore_Evas_Engine_Func *
+_ecore_evas_x_engine_func_get(Ecore_X_Window parent)
+{
+ if (!_ecore_evas_x_present_tick_enabled ||
+ ((parent != 0) && (ecore_x_window_root_get(parent) != parent)))
+ return &_ecore_x_engine_func;
+ if (!_ecore_x_engine_func_present.fn_animator_register)
+ {
+ _ecore_x_engine_func_present = _ecore_x_engine_func;
+ _ecore_x_engine_func_present.fn_animator_register = _ecore_evas_x_present_animator_register;
+ _ecore_x_engine_func_present.fn_animator_unregister = _ecore_evas_x_present_animator_unregister;
+ _ecore_x_engine_func_present.fn_evas_changed = _ecore_evas_x_present_evas_changed;
+ _ecore_x_engine_func_present.fn_last_tick_get = _ecore_evas_x_present_last_tick_get;
+ }
+ return &_ecore_x_engine_func_present;
+}
+
/*
* FIXME: there are some round trips. Especially, we can split
* ecore_x_init in 2 functions and suppress some round trips.
@@ -5352,7 +5740,8 @@ ecore_evas_gl_x11_options_new_internal(const char *disp_name, Ecore_X_Window par
_ecore_evas_x_init();
- ee->engine.func = (Ecore_Evas_Engine_Func *)&_ecore_x_engine_func;
+ ee->engine.func = _ecore_evas_x_engine_func_get(parent);
+ ee->animator_tick_local = (ee->engine.func == &_ecore_x_engine_func_present);
ee->driver = "opengl_x11";
if (disp_name) ee->name = strdup(disp_name);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.