From c9c31f803eaebf69481d24ac9355cd1f8d3111d9 Mon Sep 17 00:00:00 2001 From: Tudor Brindus Date: Fri, 5 Jun 2020 17:50:00 -0400 Subject: [PATCH] util/time: de-duplicate `timespec_to_msec` --- include/util/time.h | 7 +++++++ types/tablet_v2/wlr_tablet_v2_tool.c | 9 ++------- types/wlr_surface.c | 5 +---- util/time.c | 6 +++++- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/include/util/time.h b/include/util/time.h index a24656a92..d4b5cca78 100644 --- a/include/util/time.h +++ b/include/util/time.h @@ -1,9 +1,16 @@ #ifndef UTIL_TIME_H #define UTIL_TIME_H +#include + /** * Get the current time, in milliseconds. */ uint32_t get_current_time_msec(void); +/** + * Convert a timespec to milliseconds. + */ +int64_t timespec_to_msec(const struct timespec *a); + #endif diff --git a/types/tablet_v2/wlr_tablet_v2_tool.c b/types/tablet_v2/wlr_tablet_v2_tool.c index 041139b54..30a3bfaed 100644 --- a/types/tablet_v2/wlr_tablet_v2_tool.c +++ b/types/tablet_v2/wlr_tablet_v2_tool.c @@ -4,6 +4,7 @@ #include "tablet-unstable-v2-protocol.h" #include "util/array.h" +#include "util/time.h" #include #include #include @@ -301,16 +302,10 @@ static ssize_t tablet_tool_button_update(struct wlr_tablet_v2_tablet_tool *tool, return i; } -static inline int64_t timespec_to_msec(const struct timespec *a) { - return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; -} - static void send_tool_frame(void *data) { struct wlr_tablet_tool_client_v2 *tool = data; - struct timespec now; - clock_gettime(CLOCK_MONOTONIC, &now); - zwp_tablet_tool_v2_send_frame(tool->resource, timespec_to_msec(&now)); + zwp_tablet_tool_v2_send_frame(tool->resource, get_current_time_msec()); tool->frame_source = NULL; } diff --git a/types/wlr_surface.c b/types/wlr_surface.c index 5cf119a86..d741d119e 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -11,6 +11,7 @@ #include #include #include "util/signal.h" +#include "util/time.h" #define CALLBACK_VERSION 1 #define SURFACE_VERSION 4 @@ -1062,10 +1063,6 @@ void wlr_surface_send_leave(struct wlr_surface *surface, } } -static inline int64_t timespec_to_msec(const struct timespec *a) { - return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; -} - void wlr_surface_send_frame_done(struct wlr_surface *surface, const struct timespec *when) { struct wl_resource *resource, *tmp; diff --git a/util/time.c b/util/time.c index b23339210..a47fc613a 100644 --- a/util/time.c +++ b/util/time.c @@ -4,8 +4,12 @@ #include "util/time.h" +int64_t timespec_to_msec(const struct timespec *a) { + return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; +} + uint32_t get_current_time_msec(void) { struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now); - return now.tv_sec * 1000 + now.tv_nsec / 1000000; + return timespec_to_msec(&now); }