compositor: refactor into convert_size_by_transform_scale()

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@collabora.co.uk>
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
dev
Pekka Paalanen 9 years ago
parent 04baea58fe
commit 59987fa172
  1. 80
      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;
assert(scale > 0);
if (!surface->buffer_ref.buffer) {
surface->width_from_buffer = 0;
surface->height_from_buffer = 0;
return;
}
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");
}
}
surface->width_from_buffer = width;
surface->height_from_buffer = height;
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;
}
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

Loading…
Cancel
Save