From 219b982ed076d3f0bb9a6199509fb260b8fe8b26 Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Wed, 8 Feb 2012 15:38:37 +0200 Subject: [PATCH] compositor: use floats in computing bounding box In surface_compute_bbox(), call surface_to_global_float() instead of weston_surface_to_global(). This avoids the recursion: weston_surface_update_transform() weston_surface_update_transform_enable() surface_compute_bbox() weston_surface_to_global() weston_surface_update_transform() which might be non-obvious when reading the code. Computing the min and max coordinates in floats, we can have a tight rounding margin by using floor() and ceil(). Signed-off-by: Pekka Paalanen --- src/compositor.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/compositor.c b/src/compositor.c index f631e23..0c62fb0 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -277,18 +277,20 @@ surface_compute_bbox(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height, pixman_region32_t *bbox) { - int min_x = INT_MAX, min_y = INT_MAX, max_x = INT_MIN, max_y = INT_MIN; + GLfloat min_x = HUGE_VALF, min_y = HUGE_VALF; + GLfloat max_x = -HUGE_VALF, max_y = -HUGE_VALF; int32_t s[4][2] = { { sx, sy }, { sx, sy + height }, { sx + width, sy }, { sx + width, sy + height } }; + GLfloat int_x, int_y; int i; for (i = 0; i < 4; ++i) { - int32_t x, y; - weston_surface_to_global(surface, s[i][0], s[i][1], &x, &y); + GLfloat x, y; + surface_to_global_float(surface, s[i][0], s[i][1], &x, &y); if (x < min_x) min_x = x; if (x > max_x) @@ -299,11 +301,10 @@ surface_compute_bbox(struct weston_surface *surface, int32_t sx, int32_t sy, max_y = y; } - /* weston_surface_to_global rounds with floor(), add the - * minimum required safety margin. - */ - pixman_region32_init_rect(bbox, min_x, min_y, - max_x - min_x + 1, max_y - min_y + 1); + int_x = floorf(min_x); + int_y = floorf(min_y); + pixman_region32_init_rect(bbox, int_x, int_y, + ceilf(max_x) - int_x, ceilf(max_y) - int_y); } static void -- 2.7.4