libweston: Use struct timespec for compositor time

Change weston_compositor_get_time to return the current compositor time
as a struct timespec. Also, use clock_gettime (with CLOCK_REALTIME) to
get the time, since it's equivalent to the currently used gettimeofday
call, but returns the data directly in a struct timespec.

This commit is part of a larger effort to transition the Weston codebase
to struct timespec.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
dev
Alexandros Frantzis 7 years ago committed by Pekka Paalanen
parent 7d2abcf6c8
commit 409b01fd6d
  1. 11
      compositor/text-backend.c
  2. 8
      desktop-shell/shell.c
  3. 2
      desktop-shell/shell.h
  4. 10
      libweston/compositor-rdp.c
  5. 21
      libweston/compositor-x11.c
  6. 10
      libweston/compositor.c
  7. 4
      libweston/compositor.h

@ -106,7 +106,7 @@ struct text_backend {
struct wl_client *client;
unsigned deathcount;
uint32_t deathstamp;
struct timespec deathstamp;
} input_method;
struct wl_listener client_listener;
@ -938,11 +938,14 @@ static void launch_input_method(struct text_backend *text_backend);
static void
respawn_input_method_process(struct text_backend *text_backend)
{
uint32_t time;
struct timespec time;
int64_t tdiff;
/* if input_method dies more than 5 times in 10 seconds, give up */
time = weston_compositor_get_time();
if (time - text_backend->input_method.deathstamp > 10000) {
weston_compositor_get_time(&time);
tdiff = timespec_sub_to_msec(&time,
&text_backend->input_method.deathstamp);
if (tdiff > 10000) {
text_backend->input_method.deathstamp = time;
text_backend->input_method.deathcount = 0;
}

@ -4209,11 +4209,11 @@ static void launch_desktop_shell_process(void *data);
static void
respawn_desktop_shell_process(struct desktop_shell *shell)
{
uint32_t time;
struct timespec time;
/* if desktop-shell dies more than 5 times in 30 seconds, give up */
time = weston_compositor_get_time();
if (time - shell->child.deathstamp > 30000) {
weston_compositor_get_time(&time);
if (timespec_sub_to_msec(&time, &shell->child.deathstamp) > 30000) {
shell->child.deathstamp = time;
shell->child.deathcount = 0;
}
@ -5043,7 +5043,7 @@ wet_shell_init(struct weston_compositor *ec,
shell, bind_desktop_shell) == NULL)
return -1;
shell->child.deathstamp = weston_compositor_get_time();
weston_compositor_get_time(&shell->child.deathstamp);
shell->panel_position = WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP;

@ -161,7 +161,7 @@ struct desktop_shell {
struct wl_listener client_destroy_listener;
unsigned deathcount;
uint32_t deathstamp;
struct timespec deathstamp;
} child;
bool locked;

@ -1035,7 +1035,7 @@ xf_mouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y)
if (flags & PTR_FLAGS_MOVE) {
output = peerContext->rdpBackend->output;
if (x < output->base.width && y < output->base.height) {
timespec_from_msec(&time, weston_compositor_get_time());
weston_compositor_get_time(&time);
notify_motion_absolute(peerContext->item.seat, &time,
x, y);
need_frame = true;
@ -1050,7 +1050,7 @@ xf_mouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y)
button = BTN_MIDDLE;
if (button) {
timespec_from_msec(&time, weston_compositor_get_time());
weston_compositor_get_time(&time);
notify_button(peerContext->item.seat, &time, button,
(flags & PTR_FLAGS_DOWN) ? WL_POINTER_BUTTON_STATE_PRESSED : WL_POINTER_BUTTON_STATE_RELEASED
);
@ -1076,7 +1076,7 @@ xf_mouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y)
weston_event.discrete = (int)value;
weston_event.has_discrete = true;
timespec_from_msec(&time, weston_compositor_get_time());
weston_compositor_get_time(&time);
notify_axis(peerContext->item.seat, &time, &weston_event);
need_frame = true;
@ -1097,7 +1097,7 @@ xf_extendedMouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y)
output = peerContext->rdpBackend->output;
if (x < output->base.width && y < output->base.height) {
timespec_from_msec(&time, weston_compositor_get_time());
weston_compositor_get_time(&time);
notify_motion_absolute(peerContext->item.seat, &time, x, y);
}
@ -1161,7 +1161,7 @@ xf_input_keyboard_event(rdpInput *input, UINT16 flags, UINT16 code)
/*weston_log("code=%x ext=%d vk_code=%x scan_code=%x\n", code, (flags & KBD_FLAGS_EXTENDED) ? 1 : 0,
vk_code, scan_code);*/
timespec_from_msec(&time, weston_compositor_get_time());
weston_compositor_get_time(&time);
notify_key(peerContext->item.seat, &time,
scan_code - 8, keyState, STATE_UPDATE_AUTOMATIC);
}

@ -1178,7 +1178,7 @@ x11_backend_deliver_button_event(struct x11_backend *b,
weston_event.has_discrete = true;
weston_event.axis =
WL_POINTER_AXIS_VERTICAL_SCROLL;
timespec_from_msec(&time, weston_compositor_get_time());
weston_compositor_get_time(&time);
notify_axis(&b->core_seat, &time, &weston_event);
notify_pointer_frame(&b->core_seat);
}
@ -1190,7 +1190,7 @@ x11_backend_deliver_button_event(struct x11_backend *b,
weston_event.has_discrete = true;
weston_event.axis =
WL_POINTER_AXIS_VERTICAL_SCROLL;
timespec_from_msec(&time, weston_compositor_get_time());
weston_compositor_get_time(&time);
notify_axis(&b->core_seat, &time, &weston_event);
notify_pointer_frame(&b->core_seat);
}
@ -1202,7 +1202,7 @@ x11_backend_deliver_button_event(struct x11_backend *b,
weston_event.has_discrete = true;
weston_event.axis =
WL_POINTER_AXIS_HORIZONTAL_SCROLL;
timespec_from_msec(&time, weston_compositor_get_time());
weston_compositor_get_time(&time);
notify_axis(&b->core_seat, &time, &weston_event);
notify_pointer_frame(&b->core_seat);
}
@ -1214,7 +1214,7 @@ x11_backend_deliver_button_event(struct x11_backend *b,
weston_event.has_discrete = true;
weston_event.axis =
WL_POINTER_AXIS_HORIZONTAL_SCROLL;
timespec_from_msec(&time, weston_compositor_get_time());
weston_compositor_get_time(&time);
notify_axis(&b->core_seat, &time, &weston_event);
notify_pointer_frame(&b->core_seat);
}
@ -1224,7 +1224,7 @@ x11_backend_deliver_button_event(struct x11_backend *b,
break;
}
timespec_from_msec(&time, weston_compositor_get_time());
weston_compositor_get_time(&time);
notify_button(&b->core_seat, &time, button,
is_button_pressed ? WL_POINTER_BUTTON_STATE_PRESSED :
@ -1260,7 +1260,7 @@ x11_backend_deliver_motion_event(struct x11_backend *b,
.dy = y - b->prev_y
};
timespec_from_msec(&time, weston_compositor_get_time());
weston_compositor_get_time(&time);
notify_motion(&b->core_seat, &time, &motion_event);
notify_pointer_frame(&b->core_seat);
@ -1352,8 +1352,7 @@ x11_backend_handle_event(int fd, uint32_t mask, void *data)
* and fall through and handle the new
* event below. */
update_xkb_state_from_core(b, key_release->state);
timespec_from_msec(&time,
weston_compositor_get_time());
weston_compositor_get_time(&time);
notify_key(&b->core_seat,
&time,
key_release->detail - 8,
@ -1398,7 +1397,7 @@ x11_backend_handle_event(int fd, uint32_t mask, void *data)
key_press = (xcb_key_press_event_t *) event;
if (!b->has_xkb)
update_xkb_state_from_core(b, key_press->state);
timespec_from_msec(&time, weston_compositor_get_time());
weston_compositor_get_time(&time);
notify_key(&b->core_seat,
&time,
key_press->detail - 8,
@ -1414,7 +1413,7 @@ x11_backend_handle_event(int fd, uint32_t mask, void *data)
break;
}
key_release = (xcb_key_press_event_t *) event;
timespec_from_msec(&time, weston_compositor_get_time());
weston_compositor_get_time(&time);
notify_key(&b->core_seat,
&time,
key_release->detail - 8,
@ -1522,7 +1521,7 @@ x11_backend_handle_event(int fd, uint32_t mask, void *data)
case XCB_KEY_RELEASE:
key_release = (xcb_key_press_event_t *) prev;
update_xkb_state_from_core(b, key_release->state);
timespec_from_msec(&time, weston_compositor_get_time());
weston_compositor_get_time(&time);
notify_key(&b->core_seat,
&time,
key_release->detail - 8,

@ -1721,14 +1721,10 @@ weston_surface_update_size(struct weston_surface *surface)
surface_set_size(surface, width, height);
}
WL_EXPORT uint32_t
weston_compositor_get_time(void)
WL_EXPORT void
weston_compositor_get_time(struct timespec *time)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
clock_gettime(CLOCK_REALTIME, time);
}
WL_EXPORT struct weston_view *

@ -1674,8 +1674,8 @@ void
weston_buffer_reference(struct weston_buffer_reference *ref,
struct weston_buffer *buffer);
uint32_t
weston_compositor_get_time(void);
void
weston_compositor_get_time(struct timespec *time);
void
weston_compositor_destroy(struct weston_compositor *ec);

Loading…
Cancel
Save