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>
This commit is contained in:
+40
-40
@@ -1724,11 +1724,38 @@ fixed_round_up_to_int(wl_fixed_t f)
|
|||||||
return wl_fixed_to_int(wl_fixed_from_int(1) - 1 + f);
|
return wl_fixed_to_int(wl_fixed_from_int(1) - 1 + f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
assert(scale > 0);
|
||||||
|
|
||||||
|
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_out = height / scale;
|
||||||
|
*height_out = width / scale;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0 && "invalid transform");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
weston_surface_calculate_size_from_buffer(struct weston_surface *surface)
|
weston_surface_calculate_size_from_buffer(struct weston_surface *surface)
|
||||||
{
|
{
|
||||||
struct weston_buffer_viewport *vp = &surface->buffer_viewport;
|
struct weston_buffer_viewport *vp = &surface->buffer_viewport;
|
||||||
int32_t width, height;
|
|
||||||
|
|
||||||
if (!surface->buffer_ref.buffer) {
|
if (!surface->buffer_ref.buffer) {
|
||||||
surface->width_from_buffer = 0;
|
surface->width_from_buffer = 0;
|
||||||
@@ -1736,22 +1763,12 @@ weston_surface_calculate_size_from_buffer(struct weston_surface *surface)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (vp->buffer.transform) {
|
convert_size_by_transform_scale(&surface->width_from_buffer,
|
||||||
case WL_OUTPUT_TRANSFORM_90:
|
&surface->height_from_buffer,
|
||||||
case WL_OUTPUT_TRANSFORM_270:
|
surface->buffer_ref.buffer->width,
|
||||||
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
surface->buffer_ref.buffer->height,
|
||||||
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
|
vp->buffer.transform,
|
||||||
width = surface->buffer_ref.buffer->height / vp->buffer.scale;
|
vp->buffer.scale);
|
||||||
height = surface->buffer_ref.buffer->width / vp->buffer.scale;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
width = surface->buffer_ref.buffer->width / vp->buffer.scale;
|
|
||||||
height = surface->buffer_ref.buffer->height / vp->buffer.scale;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
surface->width_from_buffer = width;
|
|
||||||
surface->height_from_buffer = height;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -4168,30 +4185,13 @@ static void
|
|||||||
weston_output_transform_scale_init(struct weston_output *output, uint32_t transform, uint32_t scale)
|
weston_output_transform_scale_init(struct weston_output *output, uint32_t transform, uint32_t scale)
|
||||||
{
|
{
|
||||||
output->transform = transform;
|
output->transform = transform;
|
||||||
|
output->native_scale = scale;
|
||||||
|
output->current_scale = scale;
|
||||||
|
|
||||||
switch (transform) {
|
convert_size_by_transform_scale(&output->width, &output->height,
|
||||||
case WL_OUTPUT_TRANSFORM_90:
|
output->current_mode->width,
|
||||||
case WL_OUTPUT_TRANSFORM_270:
|
output->current_mode->height,
|
||||||
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
transform, scale);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
Reference in New Issue
Block a user