[gtk/nonoverlapping-containers: 1/2] gsk: Track disjointness of container nodes




commit 8fa42e91886645c93cde3cd6772647a69f9b8fd1
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Apr 3 19:28:53 2022 -0400

    gsk: Track disjointness of container nodes
    
    This can be used to optimize some things in the
    GL renderer.

 gsk/gskrendernodeimpl.c    | 21 +++++++++++++++++++++
 gsk/gskrendernodeprivate.h |  2 ++
 2 files changed, 23 insertions(+)
---
diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c
index 384de83bad..53b7d35f9d 100644
--- a/gsk/gskrendernodeimpl.c
+++ b/gsk/gskrendernodeimpl.c
@@ -2576,6 +2576,7 @@ struct _GskContainerNode
 {
   GskRenderNode render_node;
 
+  gboolean disjoint;
   guint n_children;
   GskRenderNode **children;
 };
@@ -2724,6 +2725,7 @@ gsk_container_node_new (GskRenderNode **children,
   self = gsk_render_node_alloc (GSK_CONTAINER_NODE);
   node = (GskRenderNode *) self;
 
+  self->disjoint = TRUE;
   self->n_children = n_children;
 
   if (n_children == 0)
@@ -2743,6 +2745,7 @@ gsk_container_node_new (GskRenderNode **children,
       for (guint i = 1; i < n_children; i++)
         {
           self->children[i] = gsk_render_node_ref (children[i]);
+          self->disjoint &= !graphene_rect_intersection (&bounds, &(children[i]->bounds), NULL);
           graphene_rect_union (&bounds, &(children[i]->bounds), &bounds);
           node->prefers_high_depth |= gsk_render_node_prefers_high_depth (children[i]);
         }
@@ -2801,6 +2804,24 @@ gsk_container_node_get_children (const GskRenderNode *node,
   return self->children;
 }
 
+/*< private>
+ * gsk_container_node_is_disjoint:
+ * @node: a container `GskRenderNode`
+ *
+ * Returns `TRUE` if it is known that the child nodes are not
+ * overlapping. There is no guarantee that they do overlap
+ * if this function return FALSE.
+ *
+ * Returns: `TRUE` if children don't overlap
+ */
+gboolean
+gsk_container_node_is_disjoint (const GskRenderNode *node)
+{
+  const GskContainerNode *self = (const GskContainerNode *) node;
+
+  return self->disjoint;
+}
+
 /*** GSK_TRANSFORM_NODE ***/
 
 /**
diff --git a/gsk/gskrendernodeprivate.h b/gsk/gskrendernodeprivate.h
index cdb75afd2f..637e6cb4fd 100644
--- a/gsk/gskrendernodeprivate.h
+++ b/gsk/gskrendernodeprivate.h
@@ -113,6 +113,8 @@ void             gsk_transform_node_get_translate       (const GskRenderNode *no
                                                          float               *dy);
 gboolean       gsk_render_node_prefers_high_depth       (const GskRenderNode *node);
 
+gboolean       gsk_container_node_is_disjoint           (const GskRenderNode *node);
+
 
 G_END_DECLS
 


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