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
#define UTIL_TIME_H
#include <time.h>
/**
* 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

View file

@ -4,6 +4,7 @@
#include "tablet-unstable-v2-protocol.h"
#include "util/array.h"
#include "util/time.h"
#include <assert.h>
#include <stdlib.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;
}
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;
}

View file

@ -11,6 +11,7 @@
#include <wlr/util/log.h>
#include <wlr/util/region.h>
#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;

View file

@ -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);
}