[gtk/wip/chergert/gskhint] stub out HintNode




commit 305a9cff912744f4d6e15a76e761f06ba37b0622
Author: Christian Hergert <chergert redhat com>
Date:   Mon Mar 21 12:30:16 2022 -0700

    stub out HintNode

 gsk/broadway/gskbroadwayrenderer.c |  10 +++
 gsk/gskenums.h                     |  25 ++++++-
 gsk/gskrendernode.h                |  12 ++++
 gsk/gskrendernodeimpl.c            | 138 +++++++++++++++++++++++++++++++++++++
 gsk/gskrendernodeprivate.h         |   2 +-
 5 files changed, 184 insertions(+), 3 deletions(-)
---
diff --git a/gsk/broadway/gskbroadwayrenderer.c b/gsk/broadway/gskbroadwayrenderer.c
index 5ac62e7ee0..833bfd1337 100644
--- a/gsk/broadway/gskbroadwayrenderer.c
+++ b/gsk/broadway/gskbroadwayrenderer.c
@@ -306,6 +306,11 @@ collect_reused_child_nodes (GskRenderer *renderer,
                            gsk_debug_node_get_child (node));
       break;
 
+    case GSK_HINT_NODE:
+      collect_reused_node (renderer,
+                           gsk_hint_node_get_child (node));
+      break;
+
       /* Generic nodes */
 
     case GSK_CONTAINER_NODE:
@@ -796,6 +801,11 @@ gsk_broadway_renderer_add_node (GskRenderer *renderer,
         }
       return;
 
+    case GSK_HINT_NODE:
+      gsk_broadway_renderer_add_node (renderer,
+                                      gsk_hint_node_get_child (node), offset_x, offset_y, clip_bounds);
+      return;
+
       /* Generic nodes */
 
     case GSK_CONTAINER_NODE:
diff --git a/gsk/gskenums.h b/gsk/gskenums.h
index 0dfeb0a0ea..5199666518 100644
--- a/gsk/gskenums.h
+++ b/gsk/gskenums.h
@@ -50,7 +50,8 @@
  * @GSK_BLUR_NODE: A node that applies a blur
  * @GSK_DEBUG_NODE: Debug information that does not affect the rendering
  * @GSK_GL_SHADER_NODE: A node that uses OpenGL fragment shaders to render
- 
+ * @GSK_HINT_NODE: A node that provides hints to the renderer
+
  * The type of a node determines what the node is rendering.
  */
 typedef enum {
@@ -79,7 +80,8 @@ typedef enum {
   GSK_TEXT_NODE,
   GSK_BLUR_NODE,
   GSK_DEBUG_NODE,
-  GSK_GL_SHADER_NODE
+  GSK_GL_SHADER_NODE,
+  GSK_HINT_NODE
 } GskRenderNodeType;
 
 /**
@@ -251,5 +253,24 @@ typedef enum
   GSK_GL_UNIFORM_TYPE_VEC4,
 } GskGLUniformType;
 
+/**
+ * GskRenderHints:
+ * @GSK_RENDER_HINTS_NEVER_CACHE: Hints to the renderer that it should never
+ *   cache the contents of this or any descendant node.
+ * @GSK_RENDER_HINTS_FORCE_CACHE: Hints to the renderer that it should try
+ *   to cache the conents of the node as it is likely to be reused in future
+ *   render requests.
+ *
+ * This defines the hints that may be provided to renderers to instruct
+ * preferred behavior.
+ *
+ * Since: 4.8
+ */
+typedef enum
+{
+  GSK_RENDER_HINTS_NEVER_CACHE = 1 << 0,
+  GSK_RENDER_HINTS_FORCE_CACHE = 1 << 1,
+} GskRenderHints;
+
 
 #endif /* __GSK_TYPES_H__ */
diff --git a/gsk/gskrendernode.h b/gsk/gskrendernode.h
index ba05d606f9..cb374e7bb7 100644
--- a/gsk/gskrendernode.h
+++ b/gsk/gskrendernode.h
@@ -164,6 +164,7 @@ GskRenderNode *         gsk_render_node_deserialize             (GBytes
 #define GSK_TYPE_TEXT_NODE                      (gsk_text_node_get_type())
 #define GSK_TYPE_BLUR_NODE                      (gsk_blur_node_get_type())
 #define GSK_TYPE_GL_SHADER_NODE                 (gsk_gl_shader_node_get_type())
+#define GSK_TYPE_HINT_NODE                      (gsk_hint_node_get_type())
 
 typedef struct _GskDebugNode                    GskDebugNode;
 typedef struct _GskColorNode                    GskColorNode;
@@ -190,6 +191,7 @@ typedef struct _GskCrossFadeNode                GskCrossFadeNode;
 typedef struct _GskTextNode                     GskTextNode;
 typedef struct _GskBlurNode                     GskBlurNode;
 typedef struct _GskGLShaderNode                 GskGLShaderNode;
+typedef struct _GskHintNode                     GskHintNode;
 
 GDK_AVAILABLE_IN_ALL
 GType                   gsk_debug_node_get_type                 (void) G_GNUC_CONST;
@@ -534,6 +536,16 @@ GBytes *                gsk_gl_shader_node_get_args             (const GskRender
 GDK_AVAILABLE_IN_ALL
 GskGLShader *           gsk_gl_shader_node_get_shader           (const GskRenderNode      *node) G_GNUC_PURE;
 
+GDK_AVAILABLE_IN_4_8
+GType                   gsk_hint_node_get_type                  (void) G_GNUC_CONST;
+GDK_AVAILABLE_IN_4_8
+GskRenderNode *         gsk_hint_node_new                       (GskRenderNode            *child,
+                                                                 GskRenderHints            hints);
+GDK_AVAILABLE_IN_4_8
+GskRenderNode *         gsk_hint_node_get_child                 (const GskRenderNode      *node) G_GNUC_PURE;
+GDK_AVAILABLE_IN_4_8
+GskRenderHints          gsk_hint_node_get_hints                 (const GskRenderNode      *node) G_GNUC_PURE;
+
 /**
  * GSK_VALUE_HOLDS_RENDER_NODE:
  * @value: a `GValue`
diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c
index 384de83bad..09fde39057 100644
--- a/gsk/gskrendernodeimpl.c
+++ b/gsk/gskrendernodeimpl.c
@@ -5056,6 +5056,127 @@ gsk_debug_node_get_message (const GskRenderNode *node)
   return self->message;
 }
 
+/*** GSK_HINT_NODE ***/
+
+/**
+ * GskHintNode:
+ *
+ * A render node that provides hints to the renderer about how a child node
+ * should be processed.
+ */
+struct _GskHintNode
+{
+  GskRenderNode render_node;
+
+  GskRenderNode *child;
+  GskRenderHints hints;
+};
+
+static void
+gsk_hint_node_finalize (GskRenderNode *node)
+{
+  GskHintNode *self = (GskHintNode *) node;
+  GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_HINT_NODE));
+
+  gsk_render_node_unref (self->child);
+
+  parent_class->finalize (node);
+}
+
+static void
+gsk_hint_node_draw (GskRenderNode *node,
+                    cairo_t       *cr)
+{
+  GskHintNode *self = (GskHintNode *) node;
+
+  gsk_render_node_draw (self->child, cr);
+}
+
+static gboolean
+gsk_hint_node_can_diff (const GskRenderNode *node1,
+                        const GskRenderNode *node2)
+{
+  GskHintNode *self1 = (GskHintNode *) node1;
+  GskHintNode *self2 = (GskHintNode *) node2;
+
+  return gsk_render_node_can_diff (self1->child, self2->child);
+}
+
+static void
+gsk_hint_node_diff (GskRenderNode  *node1,
+                    GskRenderNode  *node2,
+                    cairo_region_t *region)
+{
+  GskHintNode *self1 = (GskHintNode *) node1;
+  GskHintNode *self2 = (GskHintNode *) node2;
+
+  gsk_render_node_diff (self1->child, self2->child, region);
+}
+
+/**
+ * gsk_hint_node_new:
+ * @child: The child to add hint info for
+ * @hints: The hints for the child
+ *
+ * Creates a `GskRenderNode` that will add hints about how the child
+ * should be processed by the renderer.
+ *
+ * Returns: (transfer full) (type GskHintNode): A new `GskRenderNode`
+ */
+GskRenderNode *
+gsk_hint_node_new (GskRenderNode  *child,
+                   GskRenderHints  hints)
+{
+  GskHintNode *self;
+  GskRenderNode *node;
+
+  g_return_val_if_fail (GSK_IS_RENDER_NODE (child), NULL);
+
+  self = gsk_render_node_alloc (GSK_HINT_NODE);
+  node = (GskRenderNode *) self;
+
+  self->child = gsk_render_node_ref (child);
+  self->hints = hints;
+
+  graphene_rect_init_from_rect (&node->bounds, &child->bounds);
+
+  node->prefers_high_depth = gsk_render_node_prefers_high_depth (child);
+
+  return node;
+}
+
+/**
+ * gsk_hint_node_get_child:
+ * @node: (type GskHintNode): a hint `GskRenderNode`
+ *
+ * Gets the child node that is getting drawn by the given @node.
+ *
+ * Returns: (transfer none): the child `GskRenderNode`
+ **/
+GskRenderNode *
+gsk_hint_node_get_child (const GskRenderNode *node)
+{
+  const GskHintNode *self = (const GskHintNode *) node;
+
+  return self->child;
+}
+
+/**
+ * gsk_hint_node_get_hints:
+ * @node: (type GskHintNode): a hint `GskRenderNode`
+ *
+ * Gets the hints applied to this node
+ *
+ * Returns: The hints for the node
+ **/
+GskRenderHints
+gsk_hint_node_get_hints (const GskRenderNode *node)
+{
+  const GskHintNode *self = (const GskHintNode *) node;
+
+  return self->hints;
+}
+
 /*** GSK_GL_SHADER_NODE ***/
 
 /**
@@ -5298,6 +5419,7 @@ GSK_DEFINE_RENDER_NODE_TYPE (gsk_cross_fade_node, GSK_CROSS_FADE_NODE)
 GSK_DEFINE_RENDER_NODE_TYPE (gsk_text_node, GSK_TEXT_NODE)
 GSK_DEFINE_RENDER_NODE_TYPE (gsk_blur_node, GSK_BLUR_NODE)
 GSK_DEFINE_RENDER_NODE_TYPE (gsk_gl_shader_node, GSK_GL_SHADER_NODE)
+GSK_DEFINE_RENDER_NODE_TYPE (gsk_hint_node, GSK_HINT_NODE)
 GSK_DEFINE_RENDER_NODE_TYPE (gsk_debug_node, GSK_DEBUG_NODE)
 
 static void
@@ -5687,6 +5809,22 @@ gsk_render_node_init_types_once (void)
     gsk_render_node_types[GSK_GL_SHADER_NODE] = node_type;
   }
 
+  {
+    const GskRenderNodeTypeInfo node_info =
+    {
+      GSK_HINT_NODE,
+      sizeof (GskHintNode),
+      NULL,
+      gsk_hint_node_finalize,
+      gsk_hint_node_draw,
+      gsk_hint_node_can_diff,
+      gsk_hint_node_diff,
+    };
+
+    GType node_type = gsk_render_node_type_register_static (I_("GskHintNode"), &node_info);
+    gsk_render_node_types[GSK_HINT_NODE] = node_type;
+  }
+
   {
     const GskRenderNodeTypeInfo node_info =
     {
diff --git a/gsk/gskrendernodeprivate.h b/gsk/gskrendernodeprivate.h
index cdb75afd2f..ed0557bfb8 100644
--- a/gsk/gskrendernodeprivate.h
+++ b/gsk/gskrendernodeprivate.h
@@ -13,7 +13,7 @@ typedef struct _GskRenderNodeClass GskRenderNodeClass;
  * We don't add an "n-types" value to avoid having to handle
  * it in every single switch.
  */
-#define GSK_RENDER_NODE_TYPE_N_TYPES    (GSK_GL_SHADER_NODE + 1)
+#define GSK_RENDER_NODE_TYPE_N_TYPES    (GSK_HINT_NODE + 1)
 
 extern GType gsk_render_node_types[];
 


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