gsk: Track disjointness of container nodes
authorMatthias Clasen <mclasen@redhat.com>
Sun, 3 Apr 2022 23:28:53 +0000 (19:28 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 5 Apr 2022 18:57:38 +0000 (14:57 -0400)
This can be used to optimize some things in the
GL renderer.

gsk/gskrendernodeimpl.c
gsk/gskrendernodeprivate.h

index 384de83badbd27ad0aef00b63788b7808d4c4cfd..53b7d35f9d500c388d91b67e92839e60a5a6b92a 100644 (file)
@@ -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 ***/
 
 /**
index cdb75afd2fff95977061e0568e8cf390815ac6c6..637e6cb4fdd80750e713d5cc3b3d6b5aba570b41 100644 (file)
@@ -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