[gtk+/wip/ebassi/gsk-renderer: 178/194] gsk: Drop modelview/projection from GskRenderer API



commit 45b1727ab34e0ee77c7f29cf7a25abd47457f04a
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Wed Aug 10 17:50:03 2016 +0100

    gsk: Drop modelview/projection from GskRenderer API
    
    The details of the modelview and projection matrices are only useful for
    the GL renderer; there's really no point in having those details
    available in the generic API — especially as the Cairo fallback renderer
    cannot really set up a complex modelview or a projection matrix.

 gsk/gskglrenderer.c |   43 ++++++++-----
 gsk/gskrenderer.c   |  172 ---------------------------------------------------
 gsk/gskrenderer.h   |   12 ----
 gtk/gtkwindow.c     |   17 -----
 4 files changed, 26 insertions(+), 218 deletions(-)
---
diff --git a/gsk/gskglrenderer.c b/gsk/gskglrenderer.c
index dfb995a..c343f4c 100644
--- a/gsk/gskglrenderer.c
+++ b/gsk/gskglrenderer.c
@@ -595,15 +595,16 @@ render_node_needs_render_target (GskRenderNode *node)
 }
 
 static void
-gsk_gl_renderer_add_render_item (GskGLRenderer *self,
-                                 GArray        *render_items,
-                                 GskRenderNode *node,
-                                 RenderItem    *parent)
+gsk_gl_renderer_add_render_item (GskGLRenderer           *self,
+                                 const graphene_matrix_t *projection,
+                                 GArray                  *render_items,
+                                 GskRenderNode           *node,
+                                 RenderItem              *parent)
 {
   graphene_rect_t viewport;
   cairo_surface_t *surface;
   GskRenderNodeIter iter;
-  graphene_matrix_t mv, projection;
+  graphene_matrix_t mv;
   graphene_rect_t bounds;
   GskRenderNode *child;
   RenderItem item;
@@ -650,6 +651,7 @@ gsk_gl_renderer_add_render_item (GskGLRenderer *self,
   /* The location of the item, in normalized world coordinates */
   gsk_render_node_get_world_matrix (node, &mv);
   graphene_matrix_multiply (&mv, &self->mvp, &item.mvp);
+  item.z = project_item (projection, &mv);
 
   item.opaque = gsk_render_node_is_opaque (node);
   item.opacity = gsk_render_node_get_opacity (node);
@@ -740,9 +742,6 @@ gsk_gl_renderer_add_render_item (GskGLRenderer *self,
                                          vertex_data);
   }
 
-  gsk_renderer_get_projection (GSK_RENDERER (self), &projection);
-  item.z = project_item (&projection, &mv);
-
   GSK_NOTE (OPENGL, g_print ("%*sAdding node <%s>[%p] to render items\n",
                              2 * node_depth (node), "",
                              node->name != NULL ? node->name : "unnamed",
@@ -756,12 +755,13 @@ gsk_gl_renderer_add_render_item (GskGLRenderer *self,
 out:
   gsk_render_node_iter_init (&iter, node);
   while (gsk_render_node_iter_next (&iter, &child))
-    gsk_gl_renderer_add_render_item (self, render_items, child, ritem);
+    gsk_gl_renderer_add_render_item (self, projection, render_items, child, ritem);
 }
 
 static gboolean
-gsk_gl_renderer_validate_tree (GskGLRenderer *self,
-                               GskRenderNode *root)
+gsk_gl_renderer_validate_tree (GskGLRenderer           *self,
+                               GskRenderNode           *root,
+                               const graphene_matrix_t *projection)
 {
   int n_nodes;
 
@@ -780,7 +780,7 @@ gsk_gl_renderer_validate_tree (GskGLRenderer *self,
   gsk_gl_driver_begin_frame (self->gl_driver);
 
   GSK_NOTE (OPENGL, g_print ("RenderNode -> RenderItem\n"));
-  gsk_gl_renderer_add_render_item (self, self->render_items, root, NULL);
+  gsk_gl_renderer_add_render_item (self, projection, self->render_items, root, NULL);
 
   GSK_NOTE (OPENGL, g_print ("Total render items: %d of max:%d\n",
                              self->render_items->len,
@@ -819,9 +819,12 @@ gsk_gl_renderer_clear (GskGLRenderer *self)
   glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
 }
 
+#define ORTHO_NEAR_PLANE        -10000
+#define ORTHO_FAR_PLANE          10000
+
 static void
-gsk_gl_renderer_render (GskRenderer *renderer,
-                        GskRenderNode *root,
+gsk_gl_renderer_render (GskRenderer       *renderer,
+                        GskRenderNode     *root,
                         GdkDrawingContext *context)
 {
   GskGLRenderer *self = GSK_GL_RENDERER (renderer);
@@ -848,14 +851,20 @@ gsk_gl_renderer_render (GskRenderer *renderer,
   gsk_gl_renderer_create_buffers (self, viewport.size.width, viewport.size.height, scale_factor);
   gsk_gl_driver_end_frame (self->gl_driver);
 
-  gsk_renderer_get_modelview (renderer, &modelview);
-  gsk_renderer_get_projection (renderer, &projection);
+  /* Set up the modelview and projection matrices to fit our viewport */
+  graphene_matrix_init_scale (&modelview, scale_factor, scale_factor, 1.0);
+  graphene_matrix_init_ortho (&projection,
+                              0, viewport.size.width * scale_factor,
+                              viewport.size.height * scale_factor, 0,
+                              ORTHO_NEAR_PLANE,
+                              ORTHO_FAR_PLANE);
+
   gsk_gl_renderer_update_frustum (self, &modelview, &projection);
 
   get_gl_scaling_filters (GSK_RENDERER (self),
                           &self->gl_min_filter,
                           &self->gl_mag_filter);
-  if (!gsk_gl_renderer_validate_tree (self, root))
+  if (!gsk_gl_renderer_validate_tree (self, root, &projection))
     goto out;
 
   gsk_gl_driver_begin_frame (self->gl_driver);
diff --git a/gsk/gskrenderer.c b/gsk/gskrenderer.c
index 926ad03..5d97d85 100644
--- a/gsk/gskrenderer.c
+++ b/gsk/gskrenderer.c
@@ -60,8 +60,6 @@ typedef struct
   GObject parent_instance;
 
   graphene_rect_t viewport;
-  graphene_matrix_t modelview;
-  graphene_matrix_t projection;
 
   GskScalingFilter min_filter;
   GskScalingFilter mag_filter;
@@ -84,8 +82,6 @@ G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GskRenderer, gsk_renderer, G_TYPE_OBJECT)
 
 enum {
   PROP_VIEWPORT = 1,
-  PROP_MODELVIEW,
-  PROP_PROJECTION,
   PROP_MINIFICATION_FILTER,
   PROP_MAGNIFICATION_FILTER,
   PROP_AUTO_CLEAR,
@@ -153,14 +149,6 @@ gsk_renderer_set_property (GObject      *gobject,
       gsk_renderer_set_viewport (self, g_value_get_boxed (value));
       break;
 
-    case PROP_MODELVIEW:
-      gsk_renderer_set_modelview (self, g_value_get_boxed (value));
-      break;
-
-    case PROP_PROJECTION:
-      gsk_renderer_set_projection (self, g_value_get_boxed (value));
-      break;
-
     case PROP_MINIFICATION_FILTER:
       gsk_renderer_set_scaling_filters (self, g_value_get_enum (value), priv->mag_filter);
       break;
@@ -207,14 +195,6 @@ gsk_renderer_get_property (GObject    *gobject,
       g_value_set_boxed (value, &priv->viewport);
       break;
 
-    case PROP_MODELVIEW:
-      g_value_set_boxed (value, &priv->modelview);
-      break;
-
-    case PROP_PROJECTION:
-      g_value_set_boxed (value, &priv->projection);
-      break;
-
     case PROP_MINIFICATION_FILTER:
       g_value_set_enum (value, priv->min_filter);
       break;
@@ -297,60 +277,6 @@ gsk_renderer_class_init (GskRendererClass *klass)
                        G_PARAM_EXPLICIT_NOTIFY);
 
   /**
-   * GskRenderer:modelview:
-   *
-   * The initial modelview matrix used by the #GskRenderer.
-   *
-   * If set to %NULL, the identity matrix:
-   *
-   * |[<!-- language="plain"
-   *   | 1.0, 0.0, 0.0, 0.0 |
-   *   | 0.0, 1.0, 0.0, 0.0 |
-   *   | 0.0, 0.0, 1.0, 0.0 |
-   *   | 0.0, 0.0, 0.0, 1.0 |
-   * ]|
-   *
-   * Is used instead.
-   *
-   * Since: 3.22
-   */
-  gsk_renderer_properties[PROP_MODELVIEW] =
-    g_param_spec_boxed ("modelview",
-                       "Modelview",
-                       "The modelview matrix used by the renderer",
-                       GRAPHENE_TYPE_MATRIX,
-                       G_PARAM_READWRITE |
-                       G_PARAM_STATIC_STRINGS |
-                       G_PARAM_EXPLICIT_NOTIFY);
-
-  /**
-   * GskRenderer:projection:
-   *
-   * The projection matrix used by the #GskRenderer.
-   *
-   * If set to %NULL, the identity matrix:
-   *
-   * |[<!-- language="plain"
-   *   | 1.0, 0.0, 0.0, 0.0 |
-   *   | 0.0, 1.0, 0.0, 0.0 |
-   *   | 0.0, 0.0, 1.0, 0.0 |
-   *   | 0.0, 0.0, 0.0, 1.0 |
-   * ]|
-   *
-   * Is used instead.
-   *
-   * Since: 3.22
-   */
-  gsk_renderer_properties[PROP_PROJECTION] =
-    g_param_spec_boxed ("projection",
-                       "Projection",
-                       "The projection matrix used by the renderer",
-                       GRAPHENE_TYPE_MATRIX,
-                       G_PARAM_READWRITE |
-                       G_PARAM_STATIC_STRINGS |
-                       G_PARAM_EXPLICIT_NOTIFY);
-
-  /**
    * GskRenderer:minification-filter:
    *
    * The filter to be used when scaling textures down.
@@ -489,9 +415,6 @@ gsk_renderer_init (GskRenderer *self)
 {
   GskRendererPrivate *priv = gsk_renderer_get_instance_private (self);
 
-  graphene_matrix_init_identity (&priv->modelview);
-  graphene_matrix_init_identity (&priv->projection);
-
   priv->profiler = gsk_profiler_new ();
 
   priv->auto_clear = TRUE;
@@ -556,101 +479,6 @@ gsk_renderer_get_viewport (GskRenderer     *renderer,
 }
 
 /**
- * gsk_renderer_set_modelview:
- * @renderer: a #GskRenderer
- * @modelview: the modelview matrix used by the @renderer
- *
- * Sets the initial modelview matrix used by the #GskRenderer.
- *
- * A modelview matrix defines the initial transformation imposed
- * on the scene graph.
- *
- * Since: 3.22
- */
-void
-gsk_renderer_set_modelview (GskRenderer             *renderer,
-                            const graphene_matrix_t *modelview)
-{
-  GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
-
-  g_return_if_fail (GSK_IS_RENDERER (renderer));
-
-  if (modelview == NULL)
-    graphene_matrix_init_identity (&priv->modelview);
-  else
-    graphene_matrix_init_from_matrix (&priv->modelview, modelview);
-
-  g_object_notify_by_pspec (G_OBJECT (renderer), gsk_renderer_properties[PROP_MODELVIEW]);
-}
-
-/**
- * gsk_renderer_get_modelview:
- * @renderer: a #GskRenderer
- * @modelview: (out caller-allocates): return location for the modelview matrix
- *
- * Retrieves the modelview matrix used by the #GskRenderer.
- *
- * Since: 3.22
- */
-void
-gsk_renderer_get_modelview (GskRenderer       *renderer,
-                            graphene_matrix_t *modelview)
-{
-  GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
-
-  g_return_if_fail (GSK_IS_RENDERER (renderer));
-  g_return_if_fail (modelview != NULL);
-
-  graphene_matrix_init_from_matrix (modelview, &priv->modelview);
-}
-
-/**
- * gsk_renderer_set_projection:
- * @renderer: a #GskRenderer
- * @projection: the projection matrix used by the @renderer
- *
- * Sets the projection matrix used by the #GskRenderer.
- *
- * Since: 3.22
- */
-void
-gsk_renderer_set_projection (GskRenderer             *renderer,
-                             const graphene_matrix_t *projection)
-{
-  GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
-
-  g_return_if_fail (GSK_IS_RENDERER (renderer));
-
-  if (projection == NULL)
-    graphene_matrix_init_identity (&priv->projection);
-  else
-    graphene_matrix_init_from_matrix (&priv->projection, projection);
-
-  g_object_notify_by_pspec (G_OBJECT (renderer), gsk_renderer_properties[PROP_PROJECTION]);
-}
-
-/**
- * gsk_renderer_get_projection:
- * @renderer: a #GskRenderer
- * @projection: (out caller-allocates): return location for the projection matrix
- *
- * Retrieves the projection matrix used by the #GskRenderer.
- *
- * Since: 3.22
- */
-void
-gsk_renderer_get_projection (GskRenderer       *renderer,
-                             graphene_matrix_t *projection)
-{
-  GskRendererPrivate *priv = gsk_renderer_get_instance_private (renderer);
-
-  g_return_if_fail (GSK_IS_RENDERER (renderer));
-  g_return_if_fail (projection != NULL);
-
-  graphene_matrix_init_from_matrix (projection, &priv->projection);
-}
-
-/**
  * gsk_renderer_set_scaling_filters:
  * @renderer: a #GskRenderer
  * @min_filter: the minification scaling filter
diff --git a/gsk/gskrenderer.h b/gsk/gskrenderer.h
index 7928917..28c587a 100644
--- a/gsk/gskrenderer.h
+++ b/gsk/gskrenderer.h
@@ -49,18 +49,6 @@ GDK_AVAILABLE_IN_3_22
 void                    gsk_renderer_get_viewport               (GskRenderer             *renderer,
                                                                  graphene_rect_t         *viewport);
 GDK_AVAILABLE_IN_3_22
-void                    gsk_renderer_set_projection             (GskRenderer             *renderer,
-                                                                 const graphene_matrix_t *projection);
-GDK_AVAILABLE_IN_3_22
-void                    gsk_renderer_get_projection             (GskRenderer             *renderer,
-                                                                 graphene_matrix_t       *projection);
-GDK_AVAILABLE_IN_3_22
-void                    gsk_renderer_set_modelview              (GskRenderer             *renderer,
-                                                                 const graphene_matrix_t *modelview);
-GDK_AVAILABLE_IN_3_22
-void                    gsk_renderer_get_modelview              (GskRenderer             *renderer,
-                                                                 graphene_matrix_t       *modelview);
-GDK_AVAILABLE_IN_3_22
 void                    gsk_renderer_set_scaling_filters        (GskRenderer             *renderer,
                                                                  GskScalingFilter         min_filter,
                                                                  GskScalingFilter         mag_filter);
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 07dbf94..f833c4e 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -160,9 +160,6 @@
  * instead.
  */
 
-#define ORTHO_NEAR_PLANE        -10000
-#define ORTHO_FAR_PLANE          10000
-
 typedef struct _GtkWindowPopover GtkWindowPopover;
 
 struct _GtkWindowPopover
@@ -7596,9 +7593,6 @@ _gtk_window_set_allocation (GtkWindow           *window,
   if (priv->renderer != NULL)
     {
       graphene_rect_t viewport;
-      graphene_matrix_t projection;
-      graphene_matrix_t modelview;
-      graphene_point3d_t tmp;
       int scale;
 
       scale = gtk_widget_get_scale_factor (widget);
@@ -7606,17 +7600,6 @@ _gtk_window_set_allocation (GtkWindow           *window,
 
       graphene_rect_init (&viewport, 0, 0, allocation->width, allocation->height);
       gsk_renderer_set_viewport (priv->renderer, &viewport);
-
-      graphene_matrix_init_ortho (&projection,
-                                  0, allocation->width * scale,
-                                  allocation->height * scale, 0,
-                                  ORTHO_NEAR_PLANE,
-                                  ORTHO_FAR_PLANE);
-      gsk_renderer_set_projection (priv->renderer, &projection);
-
-      graphene_matrix_init_translate (&modelview,
-                                      graphene_point3d_init (&tmp, 0.f, 0.f, 0.f));
-      gsk_renderer_set_modelview (priv->renderer, &modelview);
     }
 
   get_shadow_width (window, &window_border);


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