compositor: split weston_surface_update_transform()

Split two helper functions out of weston_surface_update_transform() to:
- make the code clearer
- update the bounding box properly even if transformation fails
- unify the return point

Also add a comment on what matrix.d[12] is.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
Pekka Paalanen 13 years ago
parent 9abf393bd8
commit 80fb08dc66
  1. 64
      src/compositor.c

@ -280,37 +280,28 @@ surface_compute_bbox(struct weston_surface *surface, int32_t sx, int32_t sy,
max_x - min_x + 1, max_y - min_y + 1);
}
WL_EXPORT void
weston_surface_update_transform(struct weston_surface *surface)
static void
weston_surface_update_transform_disable(struct weston_surface *surface)
{
surface->transform.enabled = 0;
pixman_region32_init_rect(&surface->transform.boundingbox,
surface->geometry.x,
surface->geometry.y,
surface->geometry.width,
surface->geometry.height);
}
static int
weston_surface_update_transform_enable(struct weston_surface *surface)
{
struct weston_matrix *matrix = &surface->transform.matrix;
struct weston_matrix *inverse = &surface->transform.inverse;
struct weston_transform *tform;
if (!surface->geometry.dirty)
return;
surface->geometry.dirty = 0;
pixman_region32_fini(&surface->transform.boundingbox);
/* transform.position is always in transformation_list */
if (surface->geometry.transformation_list.next ==
&surface->transform.position.link &&
surface->geometry.transformation_list.prev ==
&surface->transform.position.link) {
surface->transform.enabled = 0;
pixman_region32_init_rect(&surface->transform.boundingbox,
surface->geometry.x,
surface->geometry.y,
surface->geometry.width,
surface->geometry.height);
return;
}
surface->transform.enabled = 1;
/* Otherwise identity matrix, but with x and y translation. */
surface->transform.position.matrix.d[12] = surface->geometry.x;
surface->transform.position.matrix.d[13] = surface->geometry.y;
@ -320,14 +311,37 @@ weston_surface_update_transform(struct weston_surface *surface)
if (weston_matrix_invert(inverse, matrix) < 0) {
/* Oops, bad total transformation, not invertible */
surface->transform.enabled = 0;
fprintf(stderr, "error: weston_surface %p"
" transformation not invertible.\n", surface);
return -1;
}
surface_compute_bbox(surface, 0, 0, surface->geometry.width,
surface->geometry.height,
&surface->transform.boundingbox);
return 0;
}
WL_EXPORT void
weston_surface_update_transform(struct weston_surface *surface)
{
if (!surface->geometry.dirty)
return;
surface->geometry.dirty = 0;
pixman_region32_fini(&surface->transform.boundingbox);
/* transform.position is always in transformation_list */
if (surface->geometry.transformation_list.next ==
&surface->transform.position.link &&
surface->geometry.transformation_list.prev ==
&surface->transform.position.link) {
weston_surface_update_transform_disable(surface);
} else {
if (weston_surface_update_transform_enable(surface) < 0)
weston_surface_update_transform_disable(surface);
}
}
static void

Loading…
Cancel
Save