[RFC weston 13/16] compositor: Add a function to test if images transformed by a matrix should be bilinearly filtered

Derek Foreman derekf at osg.samsung.com
Fri Sep 26 14:10:24 PDT 2014


If a transformation matrix causes a scale or a rotation not a multiple of 90
degrees then textures rendered with it would benefit from bilinear filtering.

weston_matrix_needs_filtering() checks for this.
---
 src/compositor.c | 23 +++++++++++++++++++++++
 src/compositor.h |  3 +++
 2 files changed, 26 insertions(+)

diff --git a/src/compositor.c b/src/compositor.c
index bc1b733..2f21a36 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -726,6 +726,29 @@ weston_matrix_transform_region(pixman_region32_t *dest,
 	free(dest_rects);
 }
 
+static int rot_is_90(float radians)
+{
+	radians /= M_PI_2;
+	if (fabs(floor(radians) - radians) > 0.0001)
+		return 0;
+
+	return 1;
+}
+
+WL_EXPORT int
+weston_matrix_needs_filtering(struct weston_matrix *matrix)
+{
+	if (!rot_is_90(weston_matrix_get_rotation_x(matrix))
+	 || !rot_is_90(weston_matrix_get_rotation_y(matrix))
+	 || !rot_is_90(weston_matrix_get_rotation_z(matrix))
+	 || (fabs(weston_matrix_get_scale_x(matrix) - 1.0) > 0.0001)
+	 || (fabs(weston_matrix_get_scale_y(matrix) - 1.0) > 0.0001)
+	 || (fabs(weston_matrix_get_scale_y(matrix) - 1.0) > 0.0001))
+		return 1;
+
+	return 0;
+}
+
 WL_EXPORT void
 weston_surface_to_buffer_float(struct weston_surface *surface,
 			       float sx, float sy, float *bx, float *by)
diff --git a/src/compositor.h b/src/compositor.h
index 2fc42ec..26f81c4 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -969,6 +969,9 @@ weston_view_from_global_fixed(struct weston_view *view,
 			      wl_fixed_t x, wl_fixed_t y,
 			      wl_fixed_t *vx, wl_fixed_t *vy);
 
+int
+weston_matrix_needs_filtering(struct weston_matrix *matrix);
+
 void
 weston_surface_to_buffer_float(struct weston_surface *surface,
 			       float x, float y, float *bx, float *by);
-- 
2.1.0



More information about the wayland-devel mailing list