[PATCH weston v2 17/20] compositor: Add weston_matrix_to_transform function
Derek Foreman
derekf at osg.samsung.com
Thu Oct 16 08:55:35 PDT 2014
This function examines a matrix to see if it can be built with simple
scale + translate + wl_output_transform enum.
---
src/compositor.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/compositor.h | 5 +++++
2 files changed, 62 insertions(+)
diff --git a/src/compositor.c b/src/compositor.c
index ba9f886..d629bd7 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -754,6 +754,63 @@ weston_matrix_needs_filtering(struct weston_matrix *matrix)
return false;
}
+WL_EXPORT bool
+weston_matrix_to_transform(const struct weston_matrix *mat,
+ enum wl_output_transform *transform,
+ float *sx, float *sy,
+ float *tx, float *ty)
+{
+ if (!near_zero(mat->d[2]) || !near_zero(mat->d[3]) ||
+ !near_zero(mat->d[6]) || !near_zero(mat->d[7]) ||
+ !near_zero(mat->d[8]) || !near_zero(mat->d[9]) ||
+ !near_zero(mat->d[11]))
+ return false;
+
+ if (!near_zero(mat->d[10] - 1.0) || !near_zero(mat->d[15] - 1.0))
+ return false;
+
+ if (near_zero(mat->d[0])) {
+ if (!near_zero(mat->d[5]))
+ return false;
+
+ if (mat->d[4] > 0) {
+ if (mat->d[1] > 0)
+ *transform = WL_OUTPUT_TRANSFORM_FLIPPED_270;
+ else
+ *transform = WL_OUTPUT_TRANSFORM_270;
+ } else {
+ if (mat->d[1] > 0)
+ *transform = WL_OUTPUT_TRANSFORM_90;
+ else
+ *transform = WL_OUTPUT_TRANSFORM_FLIPPED_90;
+ }
+ *sx = fabs(mat->d[1]);
+ *sy = fabs(mat->d[4]);
+ } else if (near_zero(mat->d[1])) {
+ if (!near_zero(mat->d[4]))
+ return false;
+
+ if (mat->d[0] > 0) {
+ if (mat->d[5] > 0)
+ *transform = WL_OUTPUT_TRANSFORM_NORMAL;
+ else
+ *transform = WL_OUTPUT_TRANSFORM_FLIPPED_180;
+ } else {
+ if (mat->d[5] > 0)
+ *transform = WL_OUTPUT_TRANSFORM_FLIPPED;
+ else
+ *transform = WL_OUTPUT_TRANSFORM_180;
+ }
+ *sx = fabs(mat->d[0]);
+ *sy = fabs(mat->d[5]);
+ } else return false;
+
+ *tx = mat->d[12];
+ *ty = mat->d[13];
+
+ return true;
+}
+
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 8d98306..8e2cf47 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -991,6 +991,11 @@ weston_view_from_global_fixed(struct weston_view *view,
bool
weston_matrix_needs_filtering(struct weston_matrix *matrix);
+bool
+weston_matrix_to_transform(const struct weston_matrix *mat,
+ enum wl_output_transform *transform,
+ float *sx, float *sy,
+ float *tx, float *ty);
void
weston_surface_to_buffer_float(struct weston_surface *surface,
float x, float y, float *bx, float *by);
--
2.1.1
More information about the wayland-devel
mailing list