summaryrefslogtreecommitdiff
path: root/libweston
diff options
context:
space:
mode:
authorAlexandros Frantzis <alexandros.frantzis@collabora.com>2017-11-16 18:20:52 +0200
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>2017-11-27 11:41:17 +0200
commit8250a61de139a1e3da41bf977ce6e1a657aa69c8 (patch)
tree9c514309d74fcd9f6b2c43d82598fe462b69bfef /libweston
parent6c2752a863becf41a43c1b0af99e1b713698e0b1 (diff)
build,libweston: Use struct timespec for animations
Change code related to animations to use struct timespec to represent time. 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> This bumps the libweston major version due to breakage in the animation ABI. The commits following this one break more ABI in other parts. Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Diffstat (limited to 'libweston')
-rw-r--r--libweston/animation.c29
-rw-r--r--libweston/compositor.c5
-rw-r--r--libweston/compositor.h7
-rw-r--r--libweston/spring-tool.c13
-rw-r--r--libweston/zoom.c7
5 files changed, 38 insertions, 23 deletions
diff --git a/libweston/animation.c b/libweston/animation.c
index 914135a2..c2f8b9ba 100644
--- a/libweston/animation.c
+++ b/libweston/animation.c
@@ -30,12 +30,14 @@
#include <stdint.h>
#include <stdio.h>
#include <math.h>
+#include <inttypes.h>
#include <unistd.h>
#include <fcntl.h>
#include "compositor.h"
#include "shared/helpers.h"
+#include "shared/timespec-util.h"
WL_EXPORT void
weston_spring_init(struct weston_spring *spring,
@@ -52,7 +54,7 @@ weston_spring_init(struct weston_spring *spring,
}
WL_EXPORT void
-weston_spring_update(struct weston_spring *spring, uint32_t msec)
+weston_spring_update(struct weston_spring *spring, const struct timespec *time)
{
double force, v, current, step;
@@ -61,14 +63,16 @@ weston_spring_update(struct weston_spring *spring, uint32_t msec)
* This handles the case where time moves backwards or forwards in
* large jumps.
*/
- if (msec - spring->timestamp > 1000) {
- weston_log("unexpectedly large timestamp jump (from %u to %u)\n",
- spring->timestamp, msec);
- spring->timestamp = msec - 1000;
+ if (timespec_sub_to_msec(time, &spring->timestamp) > 1000) {
+ weston_log("unexpectedly large timestamp jump "
+ "(from %" PRId64 " to %" PRId64 ")\n",
+ timespec_to_msec(&spring->timestamp),
+ timespec_to_msec(time));
+ timespec_add_msec(&spring->timestamp, time, -1000);
}
step = 0.01;
- while (4 < msec - spring->timestamp) {
+ while (4 < timespec_sub_to_msec(time, &spring->timestamp)) {
current = spring->current;
v = current - spring->previous;
force = spring->k * (spring->target - current) / 10.0 +
@@ -108,7 +112,7 @@ weston_spring_update(struct weston_spring *spring, uint32_t msec)
break;
}
- spring->timestamp += 4;
+ timespec_add_msec(&spring->timestamp, &spring->timestamp, 4);
}
}
@@ -161,7 +165,8 @@ handle_animation_view_destroy(struct wl_listener *listener, void *data)
static void
weston_view_animation_frame(struct weston_animation *base,
- struct weston_output *output, uint32_t msecs)
+ struct weston_output *output,
+ const struct timespec *time)
{
struct weston_view_animation *animation =
container_of(base,
@@ -170,9 +175,9 @@ weston_view_animation_frame(struct weston_animation *base,
animation->view->surface->compositor;
if (base->frame_counter <= 1)
- animation->spring.timestamp = msecs;
+ animation->spring.timestamp = *time;
- weston_spring_update(&animation->spring, msecs);
+ weston_spring_update(&animation->spring, time);
if (weston_spring_done(&animation->spring)) {
weston_view_schedule_repaint(animation->view);
@@ -254,8 +259,10 @@ weston_view_animation_create(struct weston_view *view,
static void
weston_view_animation_run(struct weston_view_animation *animation)
{
+ struct timespec zero_time = { 0 };
+
animation->animation.frame_counter = 0;
- weston_view_animation_frame(&animation->animation, NULL, 0);
+ weston_view_animation_frame(&animation->animation, NULL, &zero_time);
}
static void
diff --git a/libweston/compositor.c b/libweston/compositor.c
index 71a9b38c..037b4b5f 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -2292,12 +2292,15 @@ weston_output_repaint(struct weston_output *output, void *repaint_data)
struct wl_list frame_callback_list;
pixman_region32_t output_damage;
int r;
+ struct timespec frame_time;
if (output->destroying)
return 0;
TL_POINT("core_repaint_begin", TLP_OUTPUT(output), TLP_END);
+ timespec_from_msec(&frame_time, output->frame_time);
+
/* Rebuild the surface list and update surface transforms up front. */
weston_compositor_build_view_list(ec);
@@ -2352,7 +2355,7 @@ weston_output_repaint(struct weston_output *output, void *repaint_data)
wl_list_for_each_safe(animation, next, &output->animation_list, link) {
animation->frame_counter++;
- animation->frame(animation, output, output->frame_time);
+ animation->frame(animation, output, &frame_time);
}
TL_POINT("core_repaint_posted", TLP_OUTPUT(output), TLP_END);
diff --git a/libweston/compositor.h b/libweston/compositor.h
index 8b2d2b06..23d709ce 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -101,7 +101,8 @@ struct weston_mode {
struct weston_animation {
void (*frame)(struct weston_animation *animation,
- struct weston_output *output, uint32_t msecs);
+ struct weston_output *output,
+ const struct timespec *time);
int frame_counter;
struct wl_list link;
};
@@ -119,7 +120,7 @@ struct weston_spring {
double target;
double previous;
double min, max;
- uint32_t timestamp;
+ struct timespec timestamp;
uint32_t clip;
};
@@ -1352,7 +1353,7 @@ void
weston_spring_init(struct weston_spring *spring,
double k, double current, double target);
void
-weston_spring_update(struct weston_spring *spring, uint32_t msec);
+weston_spring_update(struct weston_spring *spring, const struct timespec *time);
int
weston_spring_done(struct weston_spring *spring);
diff --git a/libweston/spring-tool.c b/libweston/spring-tool.c
index 9e7c344e..a6ce055d 100644
--- a/libweston/spring-tool.c
+++ b/libweston/spring-tool.c
@@ -24,10 +24,12 @@
*/
#include <stdint.h>
+#include <inttypes.h>
#include "config.h"
#include "compositor.h"
+#include "shared/timespec-util.h"
WL_EXPORT void
weston_view_geometry_dirty(struct weston_view *view)
@@ -59,17 +61,18 @@ main(int argc, char *argv[])
const double friction = 1400;
struct weston_spring spring;
- uint32_t time = 0;
+ struct timespec time = { 0 };
weston_spring_init(&spring, k, current, target);
spring.friction = friction;
spring.previous = 0.48;
- spring.timestamp = 0;
+ spring.timestamp = (struct timespec) { 0 };
while (!weston_spring_done(&spring)) {
- printf("\t%d\t%f\n", time, spring.current);
- weston_spring_update(&spring, time);
- time += 16;
+ printf("\t%" PRId64 "\t%f\n",
+ timespec_to_msec(&time), spring.current);
+ weston_spring_update(&spring, &time);
+ timespec_add_msec(&time, &time, 16);
}
return 0;
diff --git a/libweston/zoom.c b/libweston/zoom.c
index a1a1ab21..84f1a320 100644
--- a/libweston/zoom.c
+++ b/libweston/zoom.c
@@ -36,12 +36,13 @@
static void
weston_zoom_frame_z(struct weston_animation *animation,
- struct weston_output *output, uint32_t msecs)
+ struct weston_output *output,
+ const struct timespec *time)
{
if (animation->frame_counter <= 1)
- output->zoom.spring_z.timestamp = msecs;
+ output->zoom.spring_z.timestamp = *time;
- weston_spring_update(&output->zoom.spring_z, msecs);
+ weston_spring_update(&output->zoom.spring_z, time);
if (output->zoom.spring_z.current > output->zoom.max_level)
output->zoom.spring_z.current = output->zoom.max_level;