util/time: de-duplicate `timespec_to_msec`

This commit is contained in:
Tudor Brindus 2020-06-05 17:50:00 -04:00 committed by Simon Ser
parent dc13bb827d
commit c9c31f803e
4 changed files with 15 additions and 12 deletions

View File

@ -1,9 +1,16 @@
#ifndef UTIL_TIME_H #ifndef UTIL_TIME_H
#define UTIL_TIME_H #define UTIL_TIME_H
#include <time.h>
/** /**
* Get the current time, in milliseconds. * Get the current time, in milliseconds.
*/ */
uint32_t get_current_time_msec(void); uint32_t get_current_time_msec(void);
/**
* Convert a timespec to milliseconds.
*/
int64_t timespec_to_msec(const struct timespec *a);
#endif #endif

View File

@ -4,6 +4,7 @@
#include "tablet-unstable-v2-protocol.h" #include "tablet-unstable-v2-protocol.h"
#include "util/array.h" #include "util/array.h"
#include "util/time.h"
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <types/wlr_tablet_v2.h> #include <types/wlr_tablet_v2.h>
@ -301,16 +302,10 @@ static ssize_t tablet_tool_button_update(struct wlr_tablet_v2_tablet_tool *tool,
return i; 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) { static void send_tool_frame(void *data) {
struct wlr_tablet_tool_client_v2 *tool = data; struct wlr_tablet_tool_client_v2 *tool = data;
struct timespec now; zwp_tablet_tool_v2_send_frame(tool->resource, get_current_time_msec());
clock_gettime(CLOCK_MONOTONIC, &now);
zwp_tablet_tool_v2_send_frame(tool->resource, timespec_to_msec(&now));
tool->frame_source = NULL; tool->frame_source = NULL;
} }

View File

@ -11,6 +11,7 @@
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include <wlr/util/region.h> #include <wlr/util/region.h>
#include "util/signal.h" #include "util/signal.h"
#include "util/time.h"
#define CALLBACK_VERSION 1 #define CALLBACK_VERSION 1
#define SURFACE_VERSION 4 #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, void wlr_surface_send_frame_done(struct wlr_surface *surface,
const struct timespec *when) { const struct timespec *when) {
struct wl_resource *resource, *tmp; struct wl_resource *resource, *tmp;

View File

@ -4,8 +4,12 @@
#include "util/time.h" #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) { uint32_t get_current_time_msec(void) {
struct timespec now; struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now); clock_gettime(CLOCK_MONOTONIC, &now);
return now.tv_sec * 1000 + now.tv_nsec / 1000000; return timespec_to_msec(&now);
} }