[gtk/wip/otte/inspector: 1/6] rendernode: Add GValue functions for render nodes
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/inspector: 1/6] rendernode: Add GValue functions for render nodes
- Date: Fri, 20 Aug 2021 04:30:04 +0000 (UTC)
commit fe98d2f656d59c89af7d986ab04215d9594a6670
Author: Benjamin Otte <otte redhat com>
Date: Thu Aug 19 23:36:16 2021 +0200
rendernode: Add GValue functions for render nodes
This is needed as GskRenderNode is its own fundamental type and has its
own GValue infrastructure. And I want to put render nodes into the
clipboard which uses GValues.
gsk/gskrendernode.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++-
gsk/gskrendernode.h | 20 ++++++++++
2 files changed, 126 insertions(+), 1 deletion(-)
---
diff --git a/gsk/gskrendernode.c b/gsk/gskrendernode.c
index 24678978b8..9c4332fe01 100644
--- a/gsk/gskrendernode.c
+++ b/gsk/gskrendernode.c
@@ -17,7 +17,7 @@
*/
/**
- * GskRenderNode: (ref-func gsk_render_node_ref) (unref-func gsk_render_node_unref)
+ * GskRenderNode: (ref-func gsk_render_node_ref) (unref-func gsk_render_node_unref) (set-value-func
gsk_value_set_render_node) (get-value-func gsk_value_get_render_node)
*
* `GskRenderNode` is the basic block in a scene graph to be
* rendered using `GskRenderer`.
@@ -620,3 +620,108 @@ gsk_render_node_deserialize (GBytes *bytes,
return node;
}
+
+/**
+ * gsk_value_set_render_node:
+ * @value: a `GValue` initialized with type `GSK_TYPE_RENDER_NODE`
+ * @node: a `GskRenderNode`
+ *
+ * Stores the given `GskRenderNode` inside `value`.
+ *
+ * The `GValue` will acquire a reference to the `node`.
+ */
+void
+gsk_value_set_render_node (GValue *value,
+ GskRenderNode *node)
+{
+ GskRenderNode *old_node;
+
+ g_return_if_fail (G_VALUE_HOLDS (value, GSK_TYPE_RENDER_NODE));
+
+ old_node = value->data[0].v_pointer;
+
+ if (node != NULL)
+ {
+ g_return_if_fail (GSK_IS_RENDER_NODE (node));
+
+ value->data[0].v_pointer = gsk_render_node_ref (node);
+ }
+ else
+ {
+ value->data[0].v_pointer = NULL;
+ }
+
+ if (old_node != NULL)
+ gsk_render_node_unref (old_node);
+}
+
+/**
+ * gsk_value_take_render_node:
+ * @value: a `GValue` initialized with type `GSK_TYPE_RENDER_NODE`
+ * @node: (transfer full) (nullable): a `GskRenderNode`
+ *
+ * Stores the given `GskRenderNode` inside `value`.
+ *
+ * This function transfers the ownership of the `node` to the `GValue`.
+ */
+void
+gsk_value_take_render_node (GValue *value,
+ GskRenderNode *node)
+{
+ GskRenderNode *old_node;
+
+ g_return_if_fail (G_VALUE_HOLDS (value, GSK_TYPE_RENDER_NODE));
+
+ old_node = value->data[0].v_pointer;
+
+ if (node != NULL)
+ {
+ g_return_if_fail (GSK_IS_RENDER_NODE (node));
+
+ value->data[0].v_pointer = node;
+ }
+ else
+ {
+ value->data[0].v_pointer = NULL;
+ }
+
+ if (old_node != NULL)
+ gsk_render_node_unref (old_node);
+}
+
+/**
+ * gsk_value_get_render_node:
+ * @value: a `GValue` initialized with type `GSK_TYPE_RENDER_NODE`
+ *
+ * Retrieves the `GskRenderNode` stored inside the given `value`.
+ *
+ * Returns: (transfer none) (nullable): a `GskRenderNode`
+ */
+GskRenderNode *
+gsk_value_get_render_node (const GValue *value)
+{
+ g_return_val_if_fail (G_VALUE_HOLDS (value, GSK_TYPE_RENDER_NODE), NULL);
+
+ return value->data[0].v_pointer;
+}
+
+/**
+ * gsk_value_dup_render_node:
+ * @value: a `GValue` initialized with type `GSK_TYPE_RENDER_NODE`
+ *
+ * Retrieves the `GskRenderNode` stored inside the given `value`, and acquires
+ * a reference to it.
+ *
+ * Returns: (transfer full) (nullable): a `GskRenderNode`
+ */
+GskRenderNode *
+gsk_value_dup_render_node (const GValue *value)
+{
+ g_return_val_if_fail (G_VALUE_HOLDS (value, GSK_TYPE_RENDER_NODE), NULL);
+
+ if (value->data[0].v_pointer == NULL)
+ return NULL;
+
+ return gsk_render_node_ref (value->data[0].v_pointer);
+}
+
diff --git a/gsk/gskrendernode.h b/gsk/gskrendernode.h
index 536d98e2c4..c420633a91 100644
--- a/gsk/gskrendernode.h
+++ b/gsk/gskrendernode.h
@@ -534,6 +534,26 @@ 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;
+/**
+ * GSK_VALUE_HOLDS_RENDER_NODE:
+ * @value: a `GValue`
+ *
+ * Evaluates to %TRUE if @value was initialized with %GSK_TYPE_RENDER_NODE.
+ */
+#define GSK_VALUE_HOLDS_RENDER_NODE(value) (G_VALUE_HOLDS ((value), GSK_TYPE_RENDER_NODE))
+
+GDK_AVAILABLE_IN_4_4
+void gsk_value_set_render_node (GValue *value,
+ GskRenderNode *node);
+GDK_AVAILABLE_IN_4_4
+void gsk_value_take_render_node (GValue *value,
+ GskRenderNode *node);
+GDK_AVAILABLE_IN_4_4
+GskRenderNode * gsk_value_get_render_node (const GValue *value);
+GDK_AVAILABLE_IN_4_4
+GskRenderNode * gsk_value_dup_render_node (const GValue *value);
+
+
G_END_DECLS
#endif /* __GSK_RENDER_NODE_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]