diff options
author | Carsten Haitzler (Rasterman) <raster@rasterman.com> | 2021-02-01 13:05:11 +0000 |
---|---|---|
committer | Carsten Haitzler (Rasterman) <raster@rasterman.com> | 2021-02-01 18:06:43 +0000 |
commit | 6f803ad233e397709a97a585aede4a8c3c8f0094 (patch) | |
tree | 92c68bc0b3e7c685403e5f79882fdbdfaca9d245 /src | |
parent | 77c9adf1fd5030f5e07e678df9680ded5d93f501 (diff) |
ecore x - allow vsync animator to delay by some fraction of a frame
@feat
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/ecore_x/Ecore_X.h | 1 | ||||
-rw-r--r-- | src/lib/ecore_x/ecore_x_vsync.c | 41 |
2 files changed, 42 insertions, 0 deletions
diff --git a/src/lib/ecore_x/Ecore_X.h b/src/lib/ecore_x/Ecore_X.h index ae82a549ce..8eb235b5fb 100644 --- a/src/lib/ecore_x/Ecore_X.h +++ b/src/lib/ecore_x/Ecore_X.h | |||
@@ -2610,6 +2610,7 @@ EAPI void *ecore_x_input_device_property_get(int slot, const char *prop | |||
2610 | EAPI void ecore_x_input_device_property_set(int slot, const char *prop, void *data, int num, Ecore_X_Atom format, int unit_size); /**< @since 1.24 */ | 2610 | EAPI void ecore_x_input_device_property_set(int slot, const char *prop, void *data, int num, Ecore_X_Atom format, int unit_size); /**< @since 1.24 */ |
2611 | 2611 | ||
2612 | EAPI Eina_Bool ecore_x_vsync_animator_tick_source_set(Ecore_X_Window win); | 2612 | EAPI Eina_Bool ecore_x_vsync_animator_tick_source_set(Ecore_X_Window win); |
2613 | EAPI void ecore_x_vsync_animator_tick_delay_set(double delay); /** < @since 1.26 */ | ||
2613 | 2614 | ||
2614 | typedef enum _Ecore_X_Gesture_Event_Mask | 2615 | typedef enum _Ecore_X_Gesture_Event_Mask |
2615 | { | 2616 | { |
diff --git a/src/lib/ecore_x/ecore_x_vsync.c b/src/lib/ecore_x/ecore_x_vsync.c index ff72d9f270..07abbabcca 100644 --- a/src/lib/ecore_x/ecore_x_vsync.c +++ b/src/lib/ecore_x/ecore_x_vsync.c | |||
@@ -29,6 +29,8 @@ int _ecore_x_image_shm_check(void); | |||
29 | 29 | ||
30 | static int _vsync_log_dom = -1; | 30 | static int _vsync_log_dom = -1; |
31 | 31 | ||
32 | static double _ecore_x_vsync_animator_tick_delay = 0.0; | ||
33 | |||
32 | #undef ERR | 34 | #undef ERR |
33 | #define ERR(...) EINA_LOG_DOM_ERR(_vsync_log_dom, __VA_ARGS__) | 35 | #define ERR(...) EINA_LOG_DOM_ERR(_vsync_log_dom, __VA_ARGS__) |
34 | 36 | ||
@@ -293,6 +295,39 @@ _drm_send_time(double t) | |||
293 | { | 295 | { |
294 | *tim = t; | 296 | *tim = t; |
295 | DBG(" ... send %1.8f", t); | 297 | DBG(" ... send %1.8f", t); |
298 | // if we are the wm/compositor we need to offset out vsync by 1/2 | ||
299 | // a frame ... we should never offset by more than | ||
300 | // frame_time - render_time though ... but we don't know what | ||
301 | // this is and this varies... so for now this will do.a | ||
302 | if (_ecore_x_vsync_animator_tick_delay > 0.0) | ||
303 | { | ||
304 | static double t_last = 0.0; | ||
305 | static double t_delta_hist[10] = { 0.0 }; | ||
306 | double t_delta = t - t_last; | ||
307 | double t_delta_min = 0.0; | ||
308 | double t_sleep = 0.0; | ||
309 | |||
310 | // if time delta is sane like 1/20th of a sec or less.. | ||
311 | if (t_delta < (1.0 / 20.0)) | ||
312 | { | ||
313 | int i; | ||
314 | |||
315 | for (i = 0; i < 9; i++) | ||
316 | t_delta_hist[i] = t_delta_hist[i + 1]; | ||
317 | t_delta_hist[9] = t_delta; | ||
318 | t_delta_min = t_delta_hist[0]; | ||
319 | for (i = 1; i < 10; i++) | ||
320 | { | ||
321 | if (t_delta_hist[i] < t_delta_min) | ||
322 | t_delta_min = t_delta_hist[i]; | ||
323 | } | ||
324 | t_sleep = t_delta_min * _ecore_x_vsync_animator_tick_delay; | ||
325 | // if w'ere sleeping too long - don't sleep at all. | ||
326 | if (t_sleep > (1.0 / 20.0)) t_sleep = 0.0; | ||
327 | } | ||
328 | usleep(t_sleep * 1000000.0); | ||
329 | t_last = t; | ||
330 | } | ||
296 | D(" @%1.5f ... send %1.8f\n", ecore_time_get(), t); | 331 | D(" @%1.5f ... send %1.8f\n", ecore_time_get(), t); |
297 | eina_spinlock_take(&tick_queue_lock); | 332 | eina_spinlock_take(&tick_queue_lock); |
298 | tick_queue_count++; | 333 | tick_queue_count++; |
@@ -929,3 +964,9 @@ ecore_x_vsync_animator_tick_source_set(Ecore_X_Window win) | |||
929 | } | 964 | } |
930 | return EINA_TRUE; | 965 | return EINA_TRUE; |
931 | } | 966 | } |
967 | |||
968 | EAPI void | ||
969 | ecore_x_vsync_animator_tick_delay_set(double delay) | ||
970 | { | ||
971 | _ecore_x_vsync_animator_tick_delay = delay; | ||
972 | } | ||