[gnome-flashback] display-config: add method to find an output matrix



commit f57c55b922781bef7ea9a0806b94fe0837bf1943
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Dec 11 18:14:00 2014 +0100

    display-config: 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

 .../libdisplay-config/flashback-monitor-manager.c  |   65 ++++++++++++++++++++
 .../libdisplay-config/flashback-monitor-manager.h  |    4 +
 2 files changed, 69 insertions(+), 0 deletions(-)
---
diff --git a/gnome-flashback/libdisplay-config/flashback-monitor-manager.c 
b/gnome-flashback/libdisplay-config/flashback-monitor-manager.c
index 561020c..687662f 100644
--- a/gnome-flashback/libdisplay-config/flashback-monitor-manager.c
+++ b/gnome-flashback/libdisplay-config/flashback-monitor-manager.c
@@ -47,6 +47,18 @@
  * for the reasoning */
 #define DPI_FALLBACK 96.0
 
+/* 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 */
+};
+
 struct _FlashbackMonitorManagerPrivate
 {
   Display               *xdisplay;
@@ -73,6 +85,44 @@ enum
 
 static GParamSpec *object_properties[N_PROPERTIES] = { NULL, };
 
+static gboolean
+calculate_viewport_matrix (FlashbackMonitorManager *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];
+}
+
 static void
 add_monitor (FlashbackMonitorManager *manager,
              MetaMonitorInfo         *monitor)
@@ -2096,6 +2146,21 @@ flashback_monitor_manager_on_hotplug (FlashbackMonitorManager *manager)
     flashback_monitor_config_make_default (manager->monitor_config);
 }
 
+gboolean
+flashback_monitor_manager_get_monitor_matrix (FlashbackMonitorManager *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;
+}
+
 MetaOutput *
 flashback_monitor_manager_get_outputs (FlashbackMonitorManager *manager,
                                        unsigned int            *n_outputs)
diff --git a/gnome-flashback/libdisplay-config/flashback-monitor-manager.h 
b/gnome-flashback/libdisplay-config/flashback-monitor-manager.h
index 774034c..4f70261 100644
--- a/gnome-flashback/libdisplay-config/flashback-monitor-manager.h
+++ b/gnome-flashback/libdisplay-config/flashback-monitor-manager.h
@@ -332,6 +332,10 @@ gboolean                 flashback_monitor_manager_has_hotplug_mode_update (Flas
 void                     flashback_monitor_manager_read_current_config     (FlashbackMonitorManager  
*manager);
 void                     flashback_monitor_manager_on_hotplug              (FlashbackMonitorManager  
*manager);
 
+gboolean                 flashback_monitor_manager_get_monitor_matrix      (FlashbackMonitorManager  
*manager,
+                                                                            MetaOutput               *output,
+                                                                            gfloat                    
matrix[6]);
+
 MetaOutput              *flashback_monitor_manager_get_outputs             (FlashbackMonitorManager  
*manager,
                                                                             unsigned int             
*n_outputs);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]