[PATCH weston v3 07/17] compositor: refactor into convert_size_by_transform_scale()

Bryce Harrington bryce at osg.samsung.com
Thu May 5 00:45:33 UTC 2016


On Tue, Apr 26, 2016 at 03:50:59PM +0300, Pekka Paalanen wrote:
> From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
> 
> There were two copies of code applying transform and scale to size.
> Refactor the code to use just one copy in a new function.
> 
> Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>

Nice refactoring.  I would probably use error returns rather than
asserts, but that's probably down to personal preference and anyway I'm
not sure how the error situation should be handled better than
termination.  Presumably invalid scale and transforms never happen in
practice anyway, so assert may be the better choice.

Reviewed-by: Bryce Harrington <bryce at osg.samsung.com>

Weston patches 6 and 7 would be fine to land now pre-beta; they don't
depend on the protocol changes and are straightforward refactors.

Bryce

> ---
>  src/compositor.c | 80 ++++++++++++++++++++++++++++----------------------------
>  1 file changed, 40 insertions(+), 40 deletions(-)
> 
> diff --git a/src/compositor.c b/src/compositor.c
> index 491b333..75c8c78 100644
> --- a/src/compositor.c
> +++ b/src/compositor.c
> @@ -1725,33 +1725,50 @@ fixed_round_up_to_int(wl_fixed_t f)
>  }
>  
>  static void
> -weston_surface_calculate_size_from_buffer(struct weston_surface *surface)
> +convert_size_by_transform_scale(int32_t *width_out, int32_t *height_out,
> +				int32_t width, int32_t height,
> +				uint32_t transform,
> +				int32_t scale)
>  {
> -	struct weston_buffer_viewport *vp = &surface->buffer_viewport;
> -	int32_t width, height;
> -
> -	if (!surface->buffer_ref.buffer) {
> -		surface->width_from_buffer = 0;
> -		surface->height_from_buffer = 0;
> -		return;
> -	}
> +	assert(scale > 0);
>  
> -	switch (vp->buffer.transform) {
> +	switch (transform) {
> +	case WL_OUTPUT_TRANSFORM_NORMAL:
> +	case WL_OUTPUT_TRANSFORM_180:
> +	case WL_OUTPUT_TRANSFORM_FLIPPED:
> +	case WL_OUTPUT_TRANSFORM_FLIPPED_180:
> +		*width_out = width / scale;
> +		*height_out = height / scale;
> +		break;
>  	case WL_OUTPUT_TRANSFORM_90:
>  	case WL_OUTPUT_TRANSFORM_270:
>  	case WL_OUTPUT_TRANSFORM_FLIPPED_90:
>  	case WL_OUTPUT_TRANSFORM_FLIPPED_270:
> -		width = surface->buffer_ref.buffer->height / vp->buffer.scale;
> -		height = surface->buffer_ref.buffer->width / vp->buffer.scale;
> +		*width_out = height / scale;
> +		*height_out = width / scale;
>  		break;
>  	default:
> -		width = surface->buffer_ref.buffer->width / vp->buffer.scale;
> -		height = surface->buffer_ref.buffer->height / vp->buffer.scale;
> -		break;
> +		assert(0 && "invalid transform");
> +	}
> +}
> +
> +static void
> +weston_surface_calculate_size_from_buffer(struct weston_surface *surface)
> +{
> +	struct weston_buffer_viewport *vp = &surface->buffer_viewport;
> +
> +	if (!surface->buffer_ref.buffer) {
> +		surface->width_from_buffer = 0;
> +		surface->height_from_buffer = 0;
> +		return;
>  	}
>  
> -	surface->width_from_buffer = width;
> -	surface->height_from_buffer = height;
> +	convert_size_by_transform_scale(&surface->width_from_buffer,
> +					&surface->height_from_buffer,
> +					surface->buffer_ref.buffer->width,
> +					surface->buffer_ref.buffer->height,
> +					vp->buffer.transform,
> +					vp->buffer.scale);
>  }
>  
>  static void
> @@ -4168,30 +4185,13 @@ static void
>  weston_output_transform_scale_init(struct weston_output *output, uint32_t transform, uint32_t scale)
>  {
>  	output->transform = transform;
> +	output->native_scale = scale;
> +	output->current_scale = scale;
>  
> -	switch (transform) {
> -	case WL_OUTPUT_TRANSFORM_90:
> -	case WL_OUTPUT_TRANSFORM_270:
> -	case WL_OUTPUT_TRANSFORM_FLIPPED_90:
> -	case WL_OUTPUT_TRANSFORM_FLIPPED_270:
> -		/* Swap width and height */
> -		output->width = output->current_mode->height;
> -		output->height = output->current_mode->width;
> -		break;
> -	case WL_OUTPUT_TRANSFORM_NORMAL:
> -	case WL_OUTPUT_TRANSFORM_180:
> -	case WL_OUTPUT_TRANSFORM_FLIPPED:
> -	case WL_OUTPUT_TRANSFORM_FLIPPED_180:
> -		output->width = output->current_mode->width;
> -		output->height = output->current_mode->height;
> -		break;
> -	default:
> -		break;
> -	}
> -
> -	output->native_scale = output->current_scale = scale;
> -	output->width /= scale;
> -	output->height /= scale;
> +	convert_size_by_transform_scale(&output->width, &output->height,
> +					output->current_mode->width,
> +					output->current_mode->height,
> +					transform, scale);
>  }
>  
>  static void
> -- 
> 2.7.3
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list