[gtk+/wip/otte/rendernode: 16/100] gsk: Remove gsk_render_node_is_surface/texture()



commit 6947bf7fd9e93f9b4180d5ef5ebde4b3585cb6b6
Author: Benjamin Otte <otte redhat com>
Date:   Sun Dec 11 02:33:58 2016 +0100

    gsk: Remove gsk_render_node_is_surface/texture()
    
    Use gsk_render_node_get_node_type() instead.

 gsk/gskcairorenderer.c     |   73 ++++++++++++++++++++++++-------------------
 gsk/gskglrenderer.c        |   63 ++++++++++++++++++++-----------------
 gsk/gskrendernode.c        |   16 ---------
 gsk/gskrendernodeprivate.h |    3 --
 gsk/gskvulkanrenderpass.c  |   36 ++++++++++++---------
 gtk/inspector/recorder.c   |    4 +-
 6 files changed, 97 insertions(+), 98 deletions(-)
---
diff --git a/gsk/gskcairorenderer.c b/gsk/gskcairorenderer.c
index 0d3c66e..0482903 100644
--- a/gsk/gskcairorenderer.c
+++ b/gsk/gskcairorenderer.c
@@ -59,10 +59,6 @@ gsk_cairo_renderer_render_node (GskCairoRenderer *self,
 
   cairo_save (cr);
 
-  if (!gsk_render_node_has_surface (node) &&
-      !gsk_render_node_has_texture (node))
-    goto out;
-
   gsk_render_node_get_world_matrix (node, &mvp);
   if (graphene_matrix_to_2d (&mvp, &ctm.xx, &ctm.yx, &ctm.xy, &ctm.yy, &ctm.x0, &ctm.y0))
     {
@@ -98,19 +94,49 @@ gsk_cairo_renderer_render_node (GskCairoRenderer *self,
                             node->name,
                             node,
                             frame.origin.x, frame.origin.y));
-  if (gsk_render_node_has_texture (node))
-    {
-      GskTexture *texture = gsk_texture_node_get_texture (node);
-      cairo_surface_t *surface = gsk_texture_download (texture);
 
-      cairo_set_source_surface (cr, surface, frame.origin.x, frame.origin.y); 
-      cairo_paint (cr);
-      cairo_surface_destroy (surface);
-    }
-  else
+  switch (gsk_render_node_get_node_type (node))
     {
-      cairo_set_source_surface (cr, gsk_cairo_node_get_surface (node), frame.origin.x, frame.origin.y); 
-      cairo_paint (cr);
+    case GSK_NOT_A_RENDER_NODE:
+    default:
+      g_assert_not_reached ();
+      break;
+
+    case GSK_CONTAINER_NODE:
+      if (gsk_render_node_get_n_children (node) != 0)
+        {
+          cairo_matrix_invert (&ctm);
+          cairo_transform (cr, &ctm);
+
+          GSK_NOTE (CAIRO, g_print ("Drawing %d children of node [%p]\n",
+                                    gsk_render_node_get_n_children (node),
+                                    node));
+          for (child = gsk_render_node_get_first_child (node);
+               child != NULL;
+               child = gsk_render_node_get_next_sibling (child))
+            {
+              gsk_cairo_renderer_render_node (self, child, cr);
+            }
+        }
+      break;
+
+    case GSK_TEXTURE_NODE:
+      {
+        GskTexture *texture = gsk_texture_node_get_texture (node);
+        cairo_surface_t *surface = gsk_texture_download (texture);
+
+        cairo_set_source_surface (cr, surface, frame.origin.x, frame.origin.y); 
+        cairo_paint (cr);
+        cairo_surface_destroy (surface);
+      }
+      break;
+
+    case GSK_CAIRO_NODE:
+      {
+        cairo_set_source_surface (cr, gsk_cairo_node_get_surface (node), frame.origin.x, frame.origin.y); 
+        cairo_paint (cr);
+      }
+      break;
     }
 
   if (GSK_RENDER_MODE_CHECK (GEOMETRY))
@@ -124,23 +150,6 @@ gsk_cairo_renderer_render_node (GskCairoRenderer *self,
       cairo_restore (cr);
     }
 
-  cairo_matrix_invert (&ctm);
-  cairo_transform (cr, &ctm);
-
-out:
-  if (gsk_render_node_get_n_children (node) != 0)
-    {
-      GSK_NOTE (CAIRO, g_print ("Drawing %d children of node [%p]\n",
-                                gsk_render_node_get_n_children (node),
-                                node));
-      for (child = gsk_render_node_get_first_child (node);
-           child != NULL;
-           child = gsk_render_node_get_next_sibling (child))
-        {
-          gsk_cairo_renderer_render_node (self, child, cr);
-        }
-    }
-
   if (pop_group)
     {
       cairo_pop_group_to_source (cr);
diff --git a/gsk/gskglrenderer.c b/gsk/gskglrenderer.c
index 5eb3d8a..463cf89 100644
--- a/gsk/gskglrenderer.c
+++ b/gsk/gskglrenderer.c
@@ -719,38 +719,43 @@ gsk_gl_renderer_add_render_item (GskGLRenderer           *self,
       item.children = NULL;
     }
 
-  if (gsk_render_node_has_texture (node))
+  switch (gsk_render_node_get_node_type (node))
     {
-      GskTexture *texture = gsk_texture_node_get_texture (node);
-      int gl_min_filter = GL_NEAREST, gl_mag_filter = GL_NEAREST;
+    case GSK_TEXTURE_NODE:
+      {
+        GskTexture *texture = gsk_texture_node_get_texture (node);
+        int gl_min_filter = GL_NEAREST, gl_mag_filter = GL_NEAREST;
 
-      get_gl_scaling_filters (node, &gl_min_filter, &gl_mag_filter);
+        get_gl_scaling_filters (node, &gl_min_filter, &gl_mag_filter);
 
-      item.render_data.texture_id = gsk_gl_driver_get_texture_for_texture (self->gl_driver,
-                                                                           texture,
-                                                                           gl_min_filter,
-                                                                           gl_mag_filter);
-    }
-  else if (gsk_render_node_has_surface (node))
-    {
-      cairo_surface_t *surface = gsk_cairo_node_get_surface (node);
-      int gl_min_filter = GL_NEAREST, gl_mag_filter = GL_NEAREST;
-
-      get_gl_scaling_filters (node, &gl_min_filter, &gl_mag_filter);
-
-      /* Upload the Cairo surface to a GL texture */
-      item.render_data.texture_id = gsk_gl_driver_create_texture (self->gl_driver,
-                                                                  item.size.width,
-                                                                  item.size.height);
-      gsk_gl_driver_bind_source_texture (self->gl_driver, item.render_data.texture_id);
-      gsk_gl_driver_init_texture_with_surface (self->gl_driver,
-                                               item.render_data.texture_id,
-                                               surface,
-                                               gl_min_filter,
-                                               gl_mag_filter);
-    }
-  else
-    {
+        item.render_data.texture_id = gsk_gl_driver_get_texture_for_texture (self->gl_driver,
+                                                                             texture,
+                                                                             gl_min_filter,
+                                                                             gl_mag_filter);
+      }
+      break;
+
+    case GSK_CAIRO_NODE:
+      {
+        cairo_surface_t *surface = gsk_cairo_node_get_surface (node);
+        int gl_min_filter = GL_NEAREST, gl_mag_filter = GL_NEAREST;
+
+        get_gl_scaling_filters (node, &gl_min_filter, &gl_mag_filter);
+
+        /* Upload the Cairo surface to a GL texture */
+        item.render_data.texture_id = gsk_gl_driver_create_texture (self->gl_driver,
+                                                                    item.size.width,
+                                                                    item.size.height);
+        gsk_gl_driver_bind_source_texture (self->gl_driver, item.render_data.texture_id);
+        gsk_gl_driver_init_texture_with_surface (self->gl_driver,
+                                                 item.render_data.texture_id,
+                                                 surface,
+                                                 gl_min_filter,
+                                                 gl_mag_filter);
+      }
+      break;
+
+    default:
       /* If the node does not draw anything, we skip it */
       if (item.render_data.render_target_id == 0)
         goto out;
diff --git a/gsk/gskrendernode.c b/gsk/gskrendernode.c
index b660fb0..4dc12c3 100644
--- a/gsk/gskrendernode.c
+++ b/gsk/gskrendernode.c
@@ -753,22 +753,6 @@ gsk_render_node_update_world_matrix (GskRenderNode *node,
     }
 }
 
-gboolean
-gsk_render_node_has_surface (GskRenderNode *node)
-{
-  g_return_val_if_fail (GSK_IS_RENDER_NODE (node), FALSE);
-
-  return node->surface != NULL;
-}
-
-gboolean
-gsk_render_node_has_texture (GskRenderNode *node)
-{
-  g_return_val_if_fail (GSK_IS_RENDER_NODE (node), FALSE);
-
-  return node->texture != NULL;
-}
-
 GskTexture *
 gsk_texture_node_get_texture (GskRenderNode *node)
 {
diff --git a/gsk/gskrendernodeprivate.h b/gsk/gskrendernodeprivate.h
index d581af6..f67913a 100644
--- a/gsk/gskrendernodeprivate.h
+++ b/gsk/gskrendernodeprivate.h
@@ -73,9 +73,6 @@ cairo_surface_t *gsk_cairo_node_get_surface (GskRenderNode *node);
 
 GskTexture *gsk_texture_node_get_texture (GskRenderNode *node);
 
-gboolean gsk_render_node_has_surface (GskRenderNode *node);
-gboolean gsk_render_node_has_texture (GskRenderNode *node);
-
 GskBlendMode gsk_render_node_get_blend_mode (GskRenderNode *node);
 
 GskRenderNode *gsk_render_node_get_toplevel (GskRenderNode *node);
diff --git a/gsk/gskvulkanrenderpass.c b/gsk/gskvulkanrenderpass.c
index d4c1862..22709c2 100644
--- a/gsk/gskvulkanrenderpass.c
+++ b/gsk/gskvulkanrenderpass.c
@@ -58,7 +58,6 @@ gsk_vulkan_render_pass_add_node (GskVulkanRenderPass *self,
                                  GskVulkanRender     *render,
                                  GskRenderNode       *node)
 {
-  GskRenderNode *child;
   GskVulkanRenderOp op = {
     .type = GSK_VULKAN_OP_FALLBACK,
     .node = node
@@ -67,26 +66,31 @@ gsk_vulkan_render_pass_add_node (GskVulkanRenderPass *self,
   if (gsk_render_node_get_opacity (node) < 1.0)
     goto fallback;
 
-  if (gsk_render_node_has_surface (node))
+  switch (gsk_render_node_get_node_type (node))
     {
+    case GSK_NOT_A_RENDER_NODE:
+    default:
+      g_assert_not_reached ();
+      break;
+
+    case GSK_CAIRO_NODE:
       op.type = GSK_VULKAN_OP_SURFACE;
       g_array_append_val (self->render_ops, op);
-    }
-  else if (gsk_render_node_has_texture (node))
-    {
+      break;
+
+    case GSK_TEXTURE_NODE:
       op.type = GSK_VULKAN_OP_TEXTURE;
       g_array_append_val (self->render_ops, op);
-    }
-  else
-    {
-      /* nothing to do for nodes without sources */
-    }
+      break;
 
-  for (child = gsk_render_node_get_first_child (node);
-       child;
-       child = gsk_render_node_get_next_sibling (child))
-    {
-      gsk_vulkan_render_pass_add_node (self, render, child);
+    case GSK_CONTAINER_NODE:
+      for (GskRenderNode *child = gsk_render_node_get_first_child (node);
+           child;
+           child = gsk_render_node_get_next_sibling (child))
+        {
+          gsk_vulkan_render_pass_add_node (self, render, child);
+        }
+      break;
     }
 
   return;
diff --git a/gtk/inspector/recorder.c b/gtk/inspector/recorder.c
index 25ddd0a..11a0b10 100644
--- a/gtk/inspector/recorder.c
+++ b/gtk/inspector/recorder.c
@@ -184,12 +184,12 @@ populate_render_node_properties (GtkListStore  *store,
 
   gtk_list_store_insert_with_values (store, NULL, -1,
                                      0, "Has Surface",
-                                     1, gsk_render_node_has_surface (node) ? "TRUE" : "FALSE",
+                                     1, gsk_render_node_get_node_type (node) == GSK_CAIRO_NODE ? "TRUE" : 
"FALSE",
                                      -1);
 
   gtk_list_store_insert_with_values (store, NULL, -1,
                                      0, "Has Texture",
-                                     1, gsk_render_node_has_texture (node) ? "TRUE" : "FALSE",
+                                     1, gsk_render_node_get_node_type (node) == GSK_TEXTURE_NODE ? "TRUE" : 
"FALSE",
                                      -1);
 
   class = g_type_class_ref (gsk_blend_mode_get_type ());


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