[mutter/wip/garnacho/wayland-emulated-output-transform: 6/13] backends: Add MetaStageView::transform property



commit 1fe715123f1be454e5bcfcac03234759349f51fc
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Aug 1 03:05:44 2016 +0200

    backends: Add MetaStageView::transform property
    
    This property updates the ClutterStageView pipeline, so the texture is applied
    with the corresponding transform.

 src/backends/meta-renderer-view.c |   85 +++++++++++++++++++++++++++++++++++++
 1 files changed, 85 insertions(+), 0 deletions(-)
---
diff --git a/src/backends/meta-renderer-view.c b/src/backends/meta-renderer-view.c
index 6c90c16..83ccd4c 100644
--- a/src/backends/meta-renderer-view.c
+++ b/src/backends/meta-renderer-view.c
@@ -27,6 +27,7 @@ enum
   PROP_0,
 
   PROP_MONITOR_INFO,
+  PROP_TRANSFORM,
 
   PROP_LAST
 };
@@ -37,6 +38,7 @@ struct _MetaRendererView
 {
   ClutterStageView parent;
 
+  MetaMonitorTransform transform;
   MetaMonitorInfo *monitor_info;
 };
 
@@ -50,6 +52,71 @@ meta_renderer_view_get_monitor_info (MetaRendererView *view)
 }
 
 static void
+meta_renderer_view_get_transform_matrix (MetaRendererView *view,
+                                         CoglMatrix       *matrix)
+{
+  cogl_matrix_init_identity (matrix);
+
+  switch (view->transform)
+    {
+    case META_MONITOR_TRANSFORM_NORMAL:
+      break;
+    case META_MONITOR_TRANSFORM_90:
+      cogl_matrix_rotate (matrix, 90, 0, 0, 1);
+      cogl_matrix_translate (matrix, 0, -1, 0);
+      break;
+    case META_MONITOR_TRANSFORM_180:
+      cogl_matrix_rotate (matrix, 180, 0, 0, 1);
+      cogl_matrix_translate (matrix, -1, -1, 0);
+      break;
+    case META_MONITOR_TRANSFORM_270:
+      cogl_matrix_rotate (matrix, 270, 0, 0, 1);
+      cogl_matrix_translate (matrix, -1, 0, 0);
+      break;
+    case META_MONITOR_TRANSFORM_FLIPPED:
+      cogl_matrix_scale (matrix, -1, 1, 1);
+      cogl_matrix_translate (matrix, -1, 0, 0);
+      break;
+    case META_MONITOR_TRANSFORM_FLIPPED_90:
+      cogl_matrix_scale (matrix, -1, 1, 1);
+      cogl_matrix_rotate (matrix, 90, 0, 0, 1);
+      break;
+    case META_MONITOR_TRANSFORM_FLIPPED_180:
+      cogl_matrix_scale (matrix, -1, 1, 1);
+      cogl_matrix_rotate (matrix, 180, 0, 0, 1);
+      cogl_matrix_translate (matrix, 0, -1, 0);
+      break;
+    case META_MONITOR_TRANSFORM_FLIPPED_270:
+      cogl_matrix_scale (matrix, -1, 1, 1);
+      cogl_matrix_rotate (matrix, 270, 0, 0, 1);
+      cogl_matrix_translate (matrix, -1, -1, 0);
+      break;
+    }
+}
+
+static void
+meta_renderer_view_setup_pipeline (ClutterStageView *view,
+                                   CoglPipeline     *pipeline)
+{
+  MetaRendererView *renderer_view = META_RENDERER_VIEW (view);
+  CoglMatrix matrix;
+
+  meta_renderer_view_get_transform_matrix (renderer_view, &matrix);
+  cogl_pipeline_set_layer_matrix (pipeline, 0, &matrix);
+}
+
+static void
+meta_renderer_view_set_transform (MetaRendererView     *view,
+                                  MetaMonitorTransform  transform)
+{
+  if (view->transform == transform)
+    return;
+
+  view->transform = transform;
+  clutter_stage_view_invalidate_pipeline (CLUTTER_STAGE_VIEW (view));
+}
+
+static void
 meta_renderer_view_get_property (GObject    *object,
                                  guint       prop_id,
                                  GValue     *value,
@@ -62,6 +129,9 @@ meta_renderer_view_get_property (GObject    *object,
     case PROP_MONITOR_INFO:
       g_value_set_pointer (value, view->monitor_info);
       break;
+    case PROP_TRANSFORM:
+      g_value_set_uint (value, view->transform);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -81,6 +151,9 @@ meta_renderer_view_set_property (GObject      *object,
     case PROP_MONITOR_INFO:
       view->monitor_info = g_value_get_pointer (value);
       break;
+    case PROP_TRANSFORM:
+      meta_renderer_view_set_transform (view, g_value_get_uint (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -96,6 +169,9 @@ static void
 meta_renderer_view_class_init (MetaRendererViewClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  ClutterStageViewClass *view_class = CLUTTER_STAGE_VIEW_CLASS (klass);
+
+  view_class->setup_pipeline = meta_renderer_view_setup_pipeline;
 
   object_class->get_property = meta_renderer_view_get_property;
   object_class->set_property = meta_renderer_view_set_property;
@@ -106,6 +182,15 @@ meta_renderer_view_class_init (MetaRendererViewClass *klass)
                           "The monitor info of the view",
                           G_PARAM_READWRITE |
                           G_PARAM_CONSTRUCT_ONLY);
+  obj_props[PROP_TRANSFORM] =
+    g_param_spec_uint ("transform",
+                       "Transform",
+                       "Transform to apply to the view",
+                       META_MONITOR_TRANSFORM_NORMAL,
+                       META_MONITOR_TRANSFORM_FLIPPED_270,
+                       META_MONITOR_TRANSFORM_NORMAL,
+                       G_PARAM_READWRITE |
+                       G_PARAM_STATIC_STRINGS);
 
   g_object_class_install_properties (object_class, PROP_LAST, obj_props);
 }


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