[gtk+/wip/ebassi/gsk-renderer: 473/545] gsk: Tie render nodes to renderers
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/ebassi/gsk-renderer: 473/545] gsk: Tie render nodes to renderers
- Date: Mon, 17 Oct 2016 13:50:57 +0000 (UTC)
commit 9f3de762989b74036ed9ecb3f2bcac2d5ec3b677
Author: Emmanuele Bassi <ebassi gnome org>
Date: Wed Jul 27 16:23:44 2016 +0100
gsk: Tie render nodes to renderers
Render nodes need access to rendering information like scaling factors.
If we keep render nodes separate from renderers until we submit a nodes
tree for rendering we're going to have to duplicate all that information
in a way that makes the API more complicated and fuzzier on its
semantics.
By having GskRenderer create GskRenderNode instances we can tie nodes
and renderers together; since higher layers will also have access to
the renderer instance, this does not add any burden to callers.
Additionally, if memory measurements indicate that we are spending too
much time in the allocation of new render nodes, we can now easily
implement a free-list or a renderer-specific allocator without breaking
the API.
gsk/gskrenderer.c | 19 +++++++++++++++++++
gsk/gskrenderer.h | 4 ++++
gsk/gskrendernode.c | 15 +++++++++------
gsk/gskrendernode.h | 2 --
gsk/gskrendernodeprivate.h | 6 ++++++
gtk/gtkwidget.c | 4 ++--
gtk/gtkwindow.c | 2 +-
7 files changed, 41 insertions(+), 11 deletions(-)
---
diff --git a/gsk/gskrenderer.c b/gsk/gskrenderer.c
index 8a9068f..a1b9e3f 100644
--- a/gsk/gskrenderer.c
+++ b/gsk/gskrenderer.c
@@ -921,6 +921,7 @@ gsk_renderer_render (GskRenderer *renderer,
g_return_if_fail (GDK_IS_DRAWING_CONTEXT (context));
g_return_if_fail (priv->drawing_context == NULL);
g_return_if_fail (priv->root_node == NULL);
+ g_return_if_fail (root->renderer == renderer);
priv->drawing_context = g_object_ref (context);
priv->root_node = gsk_render_node_ref (root);
@@ -1035,6 +1036,24 @@ gsk_renderer_get_use_alpha (GskRenderer *renderer)
}
/**
+ * gsk_renderer_create_render_node:
+ * @renderer: a #GskRenderer
+ *
+ * Creates a new #GskRenderNode instance tied to the given @renderer.
+ *
+ * Returns: (transfer full): the new #GskRenderNode
+ *
+ * Since: 3.22
+ */
+GskRenderNode *
+gsk_renderer_create_render_node (GskRenderer *renderer)
+{
+ g_return_val_if_fail (GSK_IS_RENDERER (renderer), NULL);
+
+ return gsk_render_node_new (renderer);
+}
+
+/**
* gsk_renderer_get_for_display:
* @display: a #GdkDisplay
*
diff --git a/gsk/gskrenderer.h b/gsk/gskrenderer.h
index ec1d3aa..7928917 100644
--- a/gsk/gskrenderer.h
+++ b/gsk/gskrenderer.h
@@ -96,6 +96,10 @@ GDK_AVAILABLE_IN_3_22
gboolean gsk_renderer_realize (GskRenderer *renderer);
GDK_AVAILABLE_IN_3_22
void gsk_renderer_unrealize (GskRenderer *renderer);
+
+GDK_AVAILABLE_IN_3_22
+GskRenderNode * gsk_renderer_create_render_node (GskRenderer *renderer);
+
GDK_AVAILABLE_IN_3_22
void gsk_renderer_render (GskRenderer *renderer,
GskRenderNode *root,
diff --git a/gsk/gskrendernode.c b/gsk/gskrendernode.c
index 93bd2dd..70aeb4c 100644
--- a/gsk/gskrendernode.c
+++ b/gsk/gskrendernode.c
@@ -233,19 +233,22 @@ gsk_render_node_get_type (void)
return gsk_render_node_type__volatile;
}
-/**
+/*< private >
* gsk_render_node_new:
+ * @renderer: a #GskRenderer
*
- * Creates a new #GskRenderNode, to be used with #GskRenderer.
+ * Creates a new #GskRenderNode, to be used with a #GskRenderer.
*
* Returns: (transfer full): the newly created #GskRenderNode
- *
- * Since: 3.22
*/
GskRenderNode *
-gsk_render_node_new (void)
+gsk_render_node_new (GskRenderer *renderer)
{
- return (GskRenderNode *) g_type_create_instance (GSK_TYPE_RENDER_NODE);
+ GskRenderNode *res = (GskRenderNode *) g_type_create_instance (GSK_TYPE_RENDER_NODE);
+
+ res->renderer = renderer;
+
+ return res;
}
/**
diff --git a/gsk/gskrendernode.h b/gsk/gskrendernode.h
index a4709ff..8cbd243 100644
--- a/gsk/gskrendernode.h
+++ b/gsk/gskrendernode.h
@@ -39,8 +39,6 @@ GDK_AVAILABLE_IN_3_22
GType gsk_render_node_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_3_22
-GskRenderNode * gsk_render_node_new (void);
-GDK_AVAILABLE_IN_3_22
GskRenderNode * gsk_render_node_ref (GskRenderNode *node);
GDK_AVAILABLE_IN_3_22
void gsk_render_node_unref (GskRenderNode *node);
diff --git a/gsk/gskrendernodeprivate.h b/gsk/gskrendernodeprivate.h
index 9893f96..8e6bca8 100644
--- a/gsk/gskrendernodeprivate.h
+++ b/gsk/gskrendernodeprivate.h
@@ -2,6 +2,7 @@
#define __GSK_RENDER_NODE_PRIVATE_H__
#include "gskrendernode.h"
+#include "gskrenderer.h"
#include <cairo.h>
G_BEGIN_DECLS
@@ -16,6 +17,9 @@ struct _GskRenderNode
volatile int ref_count;
+ /* Back pointer to the renderer that created the node */
+ GskRenderer *renderer;
+
/* The graph */
GskRenderNode *parent;
GskRenderNode *first_child;
@@ -68,6 +72,8 @@ struct _GskRenderNodeClass
void (* finalize) (GskRenderNode *node);
};
+GskRenderNode *gsk_render_node_new (GskRenderer *renderer);
+
void gsk_render_node_make_immutable (GskRenderNode *node);
void gsk_render_node_get_bounds (GskRenderNode *node,
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 78ac097..ad17fd6 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -16084,7 +16084,7 @@ gtk_widget_get_render_node (GtkWidget *widget,
GskRenderNode *tmp;
cairo_t *cr;
- tmp = gsk_render_node_new ();
+ tmp = gsk_renderer_create_render_node (renderer);
gsk_render_node_set_name (tmp, "Draw Fallback");
gsk_render_node_set_bounds (tmp, &bounds);
gsk_render_node_set_transform (tmp, &m);
@@ -16107,7 +16107,7 @@ gtk_widget_get_render_node (GtkWidget *widget,
gboolean result;
cairo_t *cr;
- tmp = gsk_render_node_new ();
+ tmp = gsk_renderer_create_render_node (renderer);
gsk_render_node_set_name (tmp, "Draw Signal Handler");
gsk_render_node_set_bounds (tmp, &bounds);
gsk_render_node_set_transform (tmp, &m);
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 847e920..d7498af 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -9673,7 +9673,7 @@ gtk_window_get_render_node (GtkWidget *widget,
graphene_rect_init (&bounds, allocation.x, allocation.y, allocation.width, allocation.height);
graphene_matrix_init_translate (&m, graphene_point3d_init (&p, allocation.x, allocation.y, 0.));
- node = gsk_render_node_new ();
+ node = gsk_renderer_create_render_node (renderer);
gsk_render_node_set_name (node, "Window Decoration");
gsk_render_node_set_bounds (node, &bounds);
gsk_render_node_set_transform (node, &m);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]