[weston,v2,12/20] compositor: Add a function to test if images transformed by a matrix should be bilinearly filtered

Submitted by Derek Foreman on Oct. 16, 2014, 3:55 p.m.

Details

Message ID 1413474938-2407-13-git-send-email-derekf@osg.samsung.com
State Changes Requested
Headers show

Not browsing as part of any series.

Commit Message

Derek Foreman Oct. 16, 2014, 3:55 p.m.
If a transformation matrix causes a scale, a rotation not a multiple of 90
degrees or a non-integer translation then textures rendered with
it would benefit from bilinear filtering.

This test is done in a lazy fashion by examining elements of the matrix
to check for a simple pattern that indicates these conditions are met.
---
 src/compositor.c | 35 +++++++++++++++++++++++++++++++++++
 src/compositor.h |  4 ++++
 2 files changed, 39 insertions(+)

Patch hide | download patch | download mbox

diff --git a/src/compositor.c b/src/compositor.c
index 68fbd71..00d404d 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -799,6 +799,41 @@  weston_matrix_transform_region(pixman_region32_t *dest,
 	free(dest_rects);
 }
 
+static bool near_zero(float a)
+{
+	if (fabs(a) > 0.0001)
+		return false;
+
+	return true;
+}
+
+WL_EXPORT bool
+weston_matrix_needs_filtering(struct weston_matrix *matrix)
+{
+	/* check for non-integral x/y translation */
+	if ((nearbyintf(matrix->d[12]) != matrix->d[12]) ||
+	    (nearbyintf(matrix->d[13]) != matrix->d[13]))
+		return true;
+
+	if (!near_zero(matrix->d[3]) || !near_zero(matrix->d[7]) ||
+	    !near_zero(matrix->d[15] - 1.0))
+		return true;
+
+	if (near_zero(matrix->d[0])) {
+		if (!near_zero(matrix->d[5]) ||
+		    !near_zero(fabsf(matrix->d[1]) - 1.0) ||
+		    !near_zero(fabsf(matrix->d[4]) - 1.0))
+			return true;
+	} else {
+		if (!near_zero(matrix->d[1]) || !near_zero(matrix->d[4]) ||
+		    !near_zero(fabsf(matrix->d[0]) - 1.0) ||
+		    !near_zero(fabsf(matrix->d[5]) - 1.0))
+			return true;
+	}
+
+	return false;
+}
+
 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 4fdf4dc..bc22026 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -28,6 +28,7 @@ 
 extern "C" {
 #endif
 
+#include <stdbool.h>
 #include <time.h>
 #include <pixman.h>
 #include <xkbcommon/xkbcommon.h>
@@ -987,6 +988,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);
 
+bool
+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);