[PATCH weston 2/4 v2] Add animation helper functions for consistency.
Scott Moreau
oreaus at gmail.com
Thu Jun 7 10:03:31 PDT 2012
This patch introduces two additional functions:
weston_animation_init() - Initializes an animation and sets the frame handler.
weston_animation_exists() - Checks if an animation is in any list.
---
The animation should be initialized consistently so weston_animation_exists()
always works.
src/compositor.c | 20 +++++++++++++--
src/compositor.h | 69 ++++++++++++++++++++++++++++++++---------------------
src/util.c | 4 +-
3 files changed, 61 insertions(+), 32 deletions(-)
diff --git a/src/compositor.c b/src/compositor.c
index 9110d4c..323ff83 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -981,6 +981,21 @@ fade_frame(struct weston_animation *animation,
}
WL_EXPORT void
+weston_animation_init(struct weston_animation *animation,
+ void (*frame)(struct weston_animation *animation,
+ struct weston_output *output, uint32_t msecs))
+{
+ animation->frame = frame;
+ wl_list_init(&animation->link);
+}
+
+WL_EXPORT int
+weston_animation_exists(struct weston_animation *animation)
+{
+ return wl_list_empty(&animation->link) ? 0 : 1;
+}
+
+WL_EXPORT void
weston_animation_run(struct weston_compositor *compositor,
struct weston_output *output,
struct weston_animation *animation)
@@ -1204,7 +1219,7 @@ weston_compositor_fade(struct weston_compositor *compositor, float tint)
}
weston_surface_damage(compositor->fade.surface);
- if (wl_list_empty(&compositor->fade.animation.link))
+ if (!weston_animation_exists(&compositor->fade.animation))
weston_animation_run(compositor, NULL,
&compositor->fade.animation);
}
@@ -3004,8 +3019,7 @@ weston_compositor_init(struct weston_compositor *ec,
wl_list_init(&ec->button_binding_list);
wl_list_init(&ec->axis_binding_list);
weston_spring_init(&ec->fade.spring, 30.0, 1.0, 1.0);
- ec->fade.animation.frame = fade_frame;
- wl_list_init(&ec->fade.animation.link);
+ weston_animation_init(&ec->fade.animation, fade_frame);
weston_layer_init(&ec->fade_layer, &ec->layer_list);
weston_layer_init(&ec->cursor_layer, &ec->fade_layer.link);
diff --git a/src/compositor.h b/src/compositor.h
index 30cb7bb..9c5e79f 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -94,18 +94,6 @@ struct weston_border {
int32_t left, right, top, bottom;
};
-enum {
- ZOOM_POINTER,
- ZOOM_TEXT_CURSOR
-};
-
-struct weston_output_zoom {
- int active;
- float increment;
- float level;
- float trans_x, trans_y;
-};
-
/* bit compatible with drm definitions. */
enum dpms_enum {
WESTON_DPMS_ON,
@@ -122,6 +110,42 @@ struct weston_read_pixels {
struct wl_list link;
};
+struct weston_animation {
+ void (*frame)(struct weston_animation *animation,
+ struct weston_output *output, uint32_t msecs);
+ struct wl_list link;
+};
+
+struct weston_spring {
+ double k;
+ double friction;
+ double current;
+ double target;
+ double previous;
+ uint32_t timestamp;
+};
+
+enum {
+ ZOOM_FOCUS_POINTER,
+ ZOOM_FOCUS_TEXT
+};
+
+struct weston_output_zoom {
+ int active;
+ uint32_t type;
+ float increment;
+ float level;
+ float max_level;
+ wl_fixed_t fx, fy;
+ float trans_x, trans_y;
+ struct {
+ struct weston_animation z;
+ } animation;
+ struct {
+ struct weston_spring z;
+ } spring;
+};
+
struct weston_output {
uint32_t id;
@@ -231,21 +255,6 @@ struct weston_shader {
GLint opaque_uniform;
};
-struct weston_animation {
- void (*frame)(struct weston_animation *animation,
- struct weston_output *output, uint32_t msecs);
- struct wl_list link;
-};
-
-struct weston_spring {
- double k;
- double friction;
- double current;
- double target;
- double previous;
- uint32_t timestamp;
-};
-
enum {
WESTON_COMPOSITOR_ACTIVE,
WESTON_COMPOSITOR_IDLE, /* shell->unlock called on activity */
@@ -535,6 +544,12 @@ void
weston_compositor_update_drag_surfaces(struct weston_compositor *compositor);
void
+weston_animation_init(struct weston_animation *animation,
+ void (*frame)(struct weston_animation *animation,
+ struct weston_output *output, uint32_t msecs));
+int
+weston_animation_exists(struct weston_animation *animation);
+void
weston_animation_run(struct weston_compositor *compositor,
struct weston_output *output,
struct weston_animation *animation);
diff --git a/src/util.c b/src/util.c
index 23cf222..c93a0f5 100644
--- a/src/util.c
+++ b/src/util.c
@@ -181,7 +181,7 @@ weston_zoom_run(struct weston_surface *surface, GLfloat start, GLfloat stop,
weston_spring_init(&zoom->spring, 200.0, 0.0, 1.0);
zoom->spring.friction = 700;
zoom->spring.timestamp = weston_compositor_get_time();
- zoom->animation.frame = weston_zoom_frame;
+ weston_animation_init(&zoom->animation, weston_zoom_frame);
weston_zoom_frame(&zoom->animation, NULL, zoom->spring.timestamp);
zoom->listener.notify = handle_zoom_surface_destroy;
@@ -502,7 +502,7 @@ weston_fade_run(struct weston_surface *surface,
weston_spring_init(&fade->spring, 200.0, 0, 1.0);
fade->spring.friction = 700;
fade->spring.timestamp = weston_compositor_get_time();
- fade->animation.frame = weston_fade_frame;
+ weston_animation_init(&fade->animation, weston_fade_frame);
weston_fade_frame(&fade->animation, NULL, fade->spring.timestamp);
fade->listener.notify = handle_fade_surface_destroy;
--
1.7.7.6
More information about the wayland-devel
mailing list