summaryrefslogtreecommitdiff
path: root/src/backends/meta-monitor-manager.c
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2014-12-11 18:14:00 +0100
committerJasper St. Pierre <jstpierre@mecheye.net>2015-01-18 13:32:28 -0800
commit71c4138933af72302f256c7dc7552ba86c36b23b (patch)
tree7cce5a0fbba5e0166a787a3950bdee99bd7509b3 /src/backends/meta-monitor-manager.c
parent9d73b4efbb91f122ed664889ed23c60710705f8e (diff)
monitor-manager: Add method to find an output matrix
This will be useful to determine input device matrices for touchscreens and tablets. https://bugzilla.gnome.org/show_bug.cgi?id=739397
Diffstat (limited to 'src/backends/meta-monitor-manager.c')
-rw-r--r--src/backends/meta-monitor-manager.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c
index 3e6207f1..3f117166 100644
--- a/src/backends/meta-monitor-manager.c
+++ b/src/backends/meta-monitor-manager.c
@@ -45,6 +45,18 @@ enum {
SIGNALS_LAST
};
+/* Array index matches MetaMonitorTransform */
+static gfloat transform_matrices[][6] = {
+ { 1, 0, 0, 0, 1, 0 }, /* normal */
+ { 0, -1, 1, 1, 0, 0 }, /* 90° */
+ { -1, 0, 1, 0, -1, 1 }, /* 180° */
+ { 0, 1, 0, -1, 0, 1 }, /* 270° */
+ { -1, 0, 1, 0, 1, 0 }, /* normal flipped */
+ { 0, 1, 0, 1, 0, 0 }, /* 90° flipped */
+ { 1, 0, 0, 0, -1, 1 }, /* 180° flipped */
+ { 0, -1, 1, -1, 0, 1 }, /* 270° flipped */
+};
+
static int signals[SIGNALS_LAST];
static void meta_monitor_manager_display_config_init (MetaDBusDisplayConfigIface *iface);
@@ -1262,3 +1274,56 @@ meta_monitor_manager_on_hotplug (MetaMonitorManager *manager)
if (!applied_config)
meta_monitor_config_make_default (manager->config, manager);
}
+
+static gboolean
+calculate_viewport_matrix (MetaMonitorManager *manager,
+ MetaOutput *output,
+ gfloat viewport[6])
+{
+ gfloat x, y, width, height;
+
+ if (!output->crtc)
+ return FALSE;
+
+ x = (float) output->crtc->rect.x / manager->screen_width;
+ y = (float) output->crtc->rect.y / manager->screen_height;
+ width = (float) output->crtc->rect.width / manager->screen_width;
+ height = (float) output->crtc->rect.height / manager->screen_height;
+
+ viewport[0] = width;
+ viewport[1] = 0.0f;
+ viewport[2] = x;
+ viewport[3] = 0.0f;
+ viewport[4] = height;
+ viewport[5] = y;
+
+ return TRUE;
+}
+
+static inline void
+multiply_matrix (float a[6],
+ float b[6],
+ float res[6])
+{
+ res[0] = a[0] * b[0] + a[1] * b[3];
+ res[1] = a[0] * b[1] + a[1] * b[4];
+ res[2] = a[0] * b[2] + a[1] * b[5] + a[2];
+ res[3] = a[3] * b[0] + a[4] * b[3];
+ res[4] = a[3] * b[1] + a[4] * b[4];
+ res[5] = a[3] * b[2] + a[4] * b[5] + a[5];
+}
+
+gboolean
+meta_monitor_manager_get_monitor_matrix (MetaMonitorManager *manager,
+ MetaOutput *output,
+ gfloat matrix[6])
+{
+ gfloat viewport[9];
+
+ if (!calculate_viewport_matrix (manager, output, viewport))
+ return FALSE;
+
+ multiply_matrix (viewport, transform_matrices[output->crtc->transform],
+ matrix);
+ return TRUE;
+}