[PATCH weston 4/4] zoom: Implement animated transitions for zoom in/out.

Kristian Høgsberg hoegsberg at gmail.com
Thu Jun 7 14:20:59 PDT 2012


On Thu, Jun 07, 2012 at 09:12:32AM -0600, Scott Moreau wrote:
> ---
>  src/compositor.c |   82 ++++++++++++++++++++++++++++++++++++++++++++---------
>  src/compositor.h |   63 +++++++++++++++++++++++------------------
>  src/shell.c      |   18 +++++------
>  3 files changed, 112 insertions(+), 51 deletions(-)

Looks fine on a quick read-through, but depends on changes in the
previous patches.

Kristian

> diff --git a/src/compositor.c b/src/compositor.c
> index 7cd1927..e1fae62 100644
> --- a/src/compositor.c
> +++ b/src/compositor.c
> @@ -1675,7 +1675,7 @@ notify_motion(struct wl_seat *seat, uint32_t time, wl_fixed_t x, wl_fixed_t y)
>  		if (output->zoom.active &&
>  		    pixman_region32_contains_point(&output->region,
>  						   ix, iy, NULL))
> -			weston_output_update_zoom(output, x, y, ZOOM_POINTER);
> +			weston_output_update_zoom(output, x, y, ZOOM_FOCUS_POINTER);
>  
>  	weston_device_repick(seat);
>  	interface = seat->pointer->grab->interface;
> @@ -2766,7 +2766,43 @@ weston_text_cursor_position_notify(struct weston_surface *surface,
>  						wl_fixed_to_int(global_y),
>  						NULL))
>  			weston_output_update_zoom(output, global_x, global_y,
> -							  ZOOM_TEXT_CURSOR);
> +							  ZOOM_FOCUS_TEXT);
> +}
> +
> +static void
> +weston_zoom_frame_z(struct weston_animation *animation,
> +		struct weston_output *output, uint32_t msecs)
> +{
> +	weston_spring_update(&output->zoom.spring.z, msecs);
> +
> +	if (output->zoom.spring.z.current > output->zoom.max_level)
> +		output->zoom.spring.z.current = output->zoom.max_level;
> +	else if (output->zoom.spring.z.current < 0.0)
> +		output->zoom.spring.z.current = 0.0;
> +
> +	if (weston_spring_done(&output->zoom.spring.z)) {
> +		if (output->zoom.level <= 0.0)
> +			output->zoom.active = 0;
> +		output->zoom.spring.z.current = output->zoom.level;
> +		weston_animation_stop(&output->zoom.animation.z);
> +	} else {
> +		output->dirty = 1;
> +		weston_output_damage(output);
> +	}
> +}
> +
> +static void
> +weston_zoom_transition(struct weston_output *output)
> +{
> +	if (!weston_animation_exists(&output->zoom.animation.z)) {
> +		output->zoom.spring.z.target = output->zoom.level;
> +		output->zoom.spring.z.timestamp = weston_compositor_get_time();
> +		weston_animation_run(output->compositor, output,
> +						&output->zoom.animation.z);
> +	}
> +
> +	output->dirty = 1;
> +	weston_output_damage(output);
>  }
>  
>  WL_EXPORT void
> @@ -2777,25 +2813,35 @@ weston_output_update_zoom(struct weston_output *output,
>  {
>  	float global_x, global_y;
>  	float trans_min, trans_max;
> +	float ratio, level;
> +
> +	level = output->zoom.spring.z.current;
>  
> -	if (output->zoom.level >= 1.0)
> +	if (!output->zoom.active || level > output->zoom.max_level)
>  		return;
>  
> +	output->zoom.type = type;
> +
> +	output->zoom.fx = x;
> +	output->zoom.fy = y;
> +
>  	global_x = wl_fixed_to_double(x);
>  	global_y = wl_fixed_to_double(y);
>  
>  	output->zoom.trans_x =
>  		(((global_x - output->x) / output->current->width) *
> -		(output->zoom.level * 2)) - output->zoom.level;
> +		(level * 2)) - level;
>  	output->zoom.trans_y =
>  		(((global_y - output->y) / output->current->height) *
> -		(output->zoom.level * 2)) - output->zoom.level;
> +		(level * 2)) - level;
> +
> +	if (type == ZOOM_FOCUS_TEXT) {
> +		ratio = 1 / level;
>  
> -	if (type == ZOOM_TEXT_CURSOR) {
> -		output->zoom.trans_x *= 1 / output->zoom.level;
> -		output->zoom.trans_y *= 1 / output->zoom.level;
> +		output->zoom.trans_x *= ratio;
> +		output->zoom.trans_y *= ratio;
>  
> -		trans_max = output->zoom.level * 2 - output->zoom.level;
> +		trans_max = level * 2 - level;
>  		trans_min = -trans_max;
>  
>  		if (output->zoom.trans_x > trans_max)
> @@ -2808,8 +2854,7 @@ weston_output_update_zoom(struct weston_output *output,
>  			output->zoom.trans_y = trans_min;
>  	}
>  
> -	output->dirty = 1;
> -	weston_output_damage(output);
> +	weston_zoom_transition(output);
>  }
>  
>  WL_EXPORT void
> @@ -2831,10 +2876,14 @@ weston_output_update_matrix(struct weston_output *output)
>  			    flip * 2.0 / (output->current->height + output->border.top + output->border.bottom), 1);
>  
>  	if (output->zoom.active) {
> -		magnification = 1 / (1 - output->zoom.level);
> +		magnification = 1 / (1 - output->zoom.spring.z.current);
>  		weston_matrix_init(&camera);
>  		weston_matrix_init(&modelview);
> -		weston_matrix_translate(&camera, output->zoom.trans_x, flip * output->zoom.trans_y, 0);
> +		weston_output_update_zoom(output, output->zoom.fx,
> +						  output->zoom.fy,
> +						  output->zoom.type);
> +		weston_matrix_translate(&camera, output->zoom.trans_x,
> +					  flip * output->zoom.trans_y, 0);
>  		weston_matrix_invert(&modelview, &camera);
>  		weston_matrix_scale(&modelview, magnification, magnification, 1.0);
>  		weston_matrix_multiply(&output->matrix, &modelview);
> @@ -2872,10 +2921,15 @@ weston_output_init(struct weston_output *output, struct weston_compositor *c,
>  	wl_list_init(&output->read_pixels_list);
>  
>  	output->zoom.active = 0;
> -	output->zoom.increment = 0.05;
> +	output->zoom.increment = 0.07;
> +	output->zoom.max_level = 0.95;
>  	output->zoom.level = 0.0;
>  	output->zoom.trans_x = 0.0;
>  	output->zoom.trans_y = 0.0;
> +	weston_spring_init(&output->zoom.spring.z, 250.0, 0.0, 0.0);
> +	output->zoom.spring.z.friction = 1000;
> +	output->zoom.animation.z.frame = weston_zoom_frame_z;
> +	wl_list_init(&output->zoom.animation.z.link);
>  
>  	output->flags = flags;
>  	weston_output_move(output, x, y);
> diff --git a/src/compositor.h b/src/compositor.h
> index 69bbbc4..963fa11 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 */
> diff --git a/src/shell.c b/src/shell.c
> index e25bf71..9b7471b 100644
> --- a/src/shell.c
> +++ b/src/shell.c
> @@ -1702,7 +1702,7 @@ do_zoom(struct wl_seat *seat, uint32_t time, uint32_t key, uint32_t axis,
>  	struct weston_seat *ws = (struct weston_seat *) seat;
>  	struct weston_compositor *compositor = ws->compositor;
>  	struct weston_output *output;
> -	float maximum_level, increment;
> +	float increment;
>  
>  	wl_list_for_each(output, &compositor->output_list, link) {
>  		if (pixman_region32_contains_point(&output->region,
> @@ -1719,23 +1719,21 @@ do_zoom(struct wl_seat *seat, uint32_t time, uint32_t key, uint32_t axis,
>  			else
>  				increment = 0;
>  
> -			output->zoom.active = 1;
>  			output->zoom.level += increment;
>  
> -			if (output->zoom.level <= 0.0) {
> -				output->zoom.active = 0;
> +			if (output->zoom.level < 0.0)
>  				output->zoom.level = 0.0;
> -			}
> -
> -			maximum_level = 1 - output->zoom.increment;
> +			else if (output->zoom.level > output->zoom.max_level)
> +				output->zoom.level = output->zoom.max_level;
> +			else
> +				output->zoom.active = 1;
>  
> -			if (output->zoom.level > maximum_level)
> -				output->zoom.level = maximum_level;
> +			output->zoom.spring.z.target = output->zoom.level;
>  
>  			weston_output_update_zoom(output,
>  			                          seat->pointer->x,
>  						  seat->pointer->y,
> -						  ZOOM_POINTER);
> +						  ZOOM_FOCUS_POINTER);
>  		}
>  	}
>  }
> -- 
> 1.7.7.6
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list