[gtk+/wip/otte/rendernode: 37/110] gsk: Remove gsk_render_node_set_bounds()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/otte/rendernode: 37/110] gsk: Remove gsk_render_node_set_bounds()
- Date: Mon, 19 Dec 2016 04:47:19 +0000 (UTC)
commit c4f760c0271122985802c6ee6cd8d3dba92dbb74
Author: Benjamin Otte <otte redhat com>
Date: Mon Dec 12 06:29:04 2016 +0100
gsk: Remove gsk_render_node_set_bounds()
gsk_render_node_get_bounds() still exists and is computed via vfunc
call:
- containers dynamically compute the bounds from their children
- surface and texture nodes get bounds passed on construction
docs/reference/gsk/gsk4-sections.txt | 1 -
gsk/gskrendernode.c | 31 +----------
gsk/gskrendernode.h | 3 -
gsk/gskrendernodeimpl.c | 95 +++++++++++++++++++++++++--------
gsk/gskrendernodeprivate.h | 5 +-
gtk/gtksnapshot.c | 3 -
gtk/gtksnapshot.h | 3 +-
7 files changed, 78 insertions(+), 63 deletions(-)
---
diff --git a/docs/reference/gsk/gsk4-sections.txt b/docs/reference/gsk/gsk4-sections.txt
index 5daa4f4..7d1f884 100644
--- a/docs/reference/gsk/gsk4-sections.txt
+++ b/docs/reference/gsk/gsk4-sections.txt
@@ -36,7 +36,6 @@ gsk_render_node_get_previous_sibling
gsk_render_node_append_child
gsk_render_node_get_n_children
gsk_render_node_contains
-gsk_render_node_set_bounds
gsk_render_node_set_transform
gsk_render_node_set_opacity
GskBlendMode
diff --git a/gsk/gskrendernode.c b/gsk/gskrendernode.c
index 0a93c33..888fca6 100644
--- a/gsk/gskrendernode.c
+++ b/gsk/gskrendernode.c
@@ -104,8 +104,6 @@ gsk_render_node_new (const GskRenderNodeClass *node_class)
self->ref_count = 1;
- graphene_rect_init_from_rect (&self->bounds, graphene_rect_zero ());
-
graphene_matrix_init_identity (&self->transform);
self->opacity = 1.0;
@@ -480,35 +478,12 @@ gsk_render_node_get_n_children (GskRenderNode *node)
}
/**
- * gsk_render_node_set_bounds:
- * @node: a #GskRenderNode
- * @bounds: (nullable): the boundaries of @node
- *
- * Sets the boundaries of @node, which describe the geometry of the
- * render node, and are used to clip the surface associated to it
- * when rendering.
- *
- * Since: 3.90
- */
-void
-gsk_render_node_set_bounds (GskRenderNode *node,
- const graphene_rect_t *bounds)
-{
- g_return_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_CONTAINER_NODE));
- g_return_if_fail (node->is_mutable);
-
- if (bounds == NULL)
- graphene_rect_init_from_rect (&node->bounds, graphene_rect_zero ());
- else
- graphene_rect_init_from_rect (&node->bounds, bounds);
-}
-
-/**
* gsk_render_node_get_bounds:
* @node: a #GskRenderNode
* @bounds: (out caller-allocates): return location for the boundaries
*
- * Retrieves the boundaries set using gsk_render_node_set_bounds().
+ * Retrieves the boundaries of the @node. The node will not draw outside
+ * of its boundaries.
*
* Since: 3.90
*/
@@ -519,7 +494,7 @@ gsk_render_node_get_bounds (GskRenderNode *node,
g_return_if_fail (GSK_IS_RENDER_NODE (node));
g_return_if_fail (bounds != NULL);
- *bounds = node->bounds;
+ node->node_class->get_bounds (node, bounds);
}
/**
diff --git a/gsk/gskrendernode.h b/gsk/gskrendernode.h
index 32cbdb8..6e2c49c 100644
--- a/gsk/gskrendernode.h
+++ b/gsk/gskrendernode.h
@@ -79,9 +79,6 @@ gboolean gsk_render_node_contains (GskRenderNode *
GskRenderNode *descendant);
GDK_AVAILABLE_IN_3_90
-void gsk_render_node_set_bounds (GskRenderNode *node,
- const graphene_rect_t *bounds);
-GDK_AVAILABLE_IN_3_90
void gsk_render_node_set_transform (GskRenderNode *node,
const graphene_matrix_t *transform);
GDK_AVAILABLE_IN_3_90
diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c
index 288bacf..267a812 100644
--- a/gsk/gskrendernodeimpl.c
+++ b/gsk/gskrendernodeimpl.c
@@ -31,6 +31,7 @@ struct _GskTextureNode
GskRenderNode render_node;
GskTexture *texture;
+ graphene_rect_t bounds;
};
static void
@@ -46,12 +47,22 @@ gsk_texture_node_make_immutable (GskRenderNode *node)
{
}
+static void
+gsk_texture_node_get_bounds (GskRenderNode *node,
+ graphene_rect_t *bounds)
+{
+ GskTextureNode *self = (GskTextureNode *) node;
+
+ graphene_rect_init_from_rect (bounds, &self->bounds);
+}
+
static const GskRenderNodeClass GSK_TEXTURE_NODE_CLASS = {
GSK_TEXTURE_NODE,
sizeof (GskTextureNode),
"GskTextureNode",
gsk_texture_node_finalize,
- gsk_texture_node_make_immutable
+ gsk_texture_node_make_immutable,
+ gsk_texture_node_get_bounds
};
GskTexture *
@@ -81,18 +92,16 @@ gsk_texture_node_new (GskTexture *texture,
const graphene_rect_t *bounds)
{
GskTextureNode *self;
- GskRenderNode *node;
g_return_val_if_fail (GSK_IS_TEXTURE (texture), NULL);
g_return_val_if_fail (bounds != NULL, NULL);
- node = gsk_render_node_new (&GSK_TEXTURE_NODE_CLASS);
- self = (GskTextureNode *) node;
+ self = (GskTextureNode *) gsk_render_node_new (&GSK_TEXTURE_NODE_CLASS);
self->texture = gsk_texture_ref (texture);
- graphene_rect_init_from_rect (&node->bounds, bounds);
+ graphene_rect_init_from_rect (&self->bounds, bounds);
- return node;
+ return &self->render_node;
}
/*** GSK_CAIRO_NODE ***/
@@ -104,6 +113,7 @@ struct _GskCairoNode
GskRenderNode render_node;
cairo_surface_t *surface;
+ graphene_rect_t bounds;
};
static void
@@ -120,12 +130,22 @@ gsk_cairo_node_make_immutable (GskRenderNode *node)
{
}
+static void
+gsk_cairo_node_get_bounds (GskRenderNode *node,
+ graphene_rect_t *bounds)
+{
+ GskCairoNode *self = (GskCairoNode *) node;
+
+ graphene_rect_init_from_rect (bounds, &self->bounds);
+}
+
static const GskRenderNodeClass GSK_CAIRO_NODE_CLASS = {
GSK_CAIRO_NODE,
sizeof (GskCairoNode),
"GskCairoNode",
gsk_cairo_node_finalize,
- gsk_cairo_node_make_immutable
+ gsk_cairo_node_make_immutable,
+ gsk_cairo_node_get_bounds
};
/*< private >
@@ -161,15 +181,15 @@ gsk_cairo_node_get_surface (GskRenderNode *node)
GskRenderNode *
gsk_cairo_node_new (const graphene_rect_t *bounds)
{
- GskRenderNode *node;
+ GskCairoNode *self;
g_return_val_if_fail (bounds != NULL, NULL);
- node = gsk_render_node_new (&GSK_CAIRO_NODE_CLASS);
+ self = (GskCairoNode *) gsk_render_node_new (&GSK_CAIRO_NODE_CLASS);
- graphene_rect_init_from_rect (&node->bounds, bounds);
+ graphene_rect_init_from_rect (&self->bounds, bounds);
- return node;
+ return &self->render_node;
}
/**
@@ -199,8 +219,8 @@ gsk_cairo_node_get_draw_context (GskRenderNode *node,
g_return_val_if_fail (node->is_mutable, NULL);
g_return_val_if_fail (renderer == NULL || GSK_IS_RENDERER (renderer), NULL);
- width = ceilf (node->bounds.size.width);
- height = ceilf (node->bounds.size.height);
+ width = ceilf (self->bounds.size.width);
+ height = ceilf (self->bounds.size.height);
if (width <= 0 || height <= 0)
{
@@ -214,14 +234,14 @@ gsk_cairo_node_get_draw_context (GskRenderNode *node,
{
self->surface = gsk_renderer_create_cairo_surface (renderer,
CAIRO_FORMAT_ARGB32,
- ceilf (node->bounds.size.width),
- ceilf (node->bounds.size.height));
+ ceilf (self->bounds.size.width),
+ ceilf (self->bounds.size.height));
}
else
{
self->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
- ceilf (node->bounds.size.width),
- ceilf (node->bounds.size.height));
+ ceilf (self->bounds.size.width),
+ ceilf (self->bounds.size.height));
}
res = cairo_create (self->surface);
}
@@ -230,11 +250,11 @@ gsk_cairo_node_get_draw_context (GskRenderNode *node,
res = cairo_create (self->surface);
}
- cairo_translate (res, -node->bounds.origin.x, -node->bounds.origin.y);
+ cairo_translate (res, -self->bounds.origin.x, -self->bounds.origin.y);
cairo_rectangle (res,
- node->bounds.origin.x, node->bounds.origin.y,
- node->bounds.size.width, node->bounds.size.height);
+ self->bounds.origin.x, self->bounds.origin.y,
+ self->bounds.size.width, self->bounds.size.height);
cairo_clip (res);
if (GSK_DEBUG_CHECK (SURFACE))
@@ -245,8 +265,8 @@ gsk_cairo_node_get_draw_context (GskRenderNode *node,
{
cairo_save (res);
cairo_rectangle (res,
- node->bounds.origin.x + 1, node->bounds.origin.y + 1,
- node->bounds.size.width - 2, node->bounds.size.height - 2);
+ self->bounds.origin.x + 1, self->bounds.origin.y + 1,
+ self->bounds.size.width - 2, self->bounds.size.height - 2);
cairo_set_line_width (res, 2);
cairo_set_source_rgb (res, 1, 0, 0);
cairo_stroke (res);
@@ -277,12 +297,41 @@ gsk_container_node_make_immutable (GskRenderNode *node)
}
}
+static void
+gsk_container_node_get_bounds (GskRenderNode *node,
+ graphene_rect_t *bounds)
+{
+ GskRenderNode *child;
+
+ child = gsk_render_node_get_first_child (node);
+
+ if (child == NULL)
+ {
+ graphene_rect_init_from_rect (bounds, graphene_rect_zero());
+ return;
+ }
+
+ gsk_render_node_get_bounds (child, bounds);
+
+ for (child = gsk_render_node_get_next_sibling (child);
+ child;
+ child = gsk_render_node_get_next_sibling (child))
+ {
+ graphene_rect_t child_bounds, union_bounds;
+
+ gsk_render_node_get_bounds (child, &child_bounds);
+ graphene_rect_union (bounds, &child_bounds, &union_bounds);
+ graphene_rect_init_from_rect (bounds, &union_bounds);
+ }
+}
+
static const GskRenderNodeClass GSK_CONTAINER_NODE_CLASS = {
GSK_CONTAINER_NODE,
sizeof (GskRenderNode),
"GskContainerNode",
gsk_container_node_finalize,
- gsk_container_node_make_immutable
+ gsk_container_node_make_immutable,
+ gsk_container_node_get_bounds
};
/**
diff --git a/gsk/gskrendernodeprivate.h b/gsk/gskrendernodeprivate.h
index 31653d4..2576771 100644
--- a/gsk/gskrendernodeprivate.h
+++ b/gsk/gskrendernodeprivate.h
@@ -41,9 +41,6 @@ struct _GskRenderNode
GskScalingFilter min_filter;
GskScalingFilter mag_filter;
- /* Clip rectangle */
- graphene_rect_t bounds;
-
/* Transformations relative to the root of the scene */
graphene_matrix_t world_matrix;
@@ -63,6 +60,8 @@ struct _GskRenderNodeClass
const char *type_name;
void (* finalize) (GskRenderNode *node);
void (* make_immutable) (GskRenderNode *node);
+ void (* get_bounds) (GskRenderNode *node,
+ graphene_rect_t *bounds);
};
GskRenderNode *gsk_render_node_new (const GskRenderNodeClass *node_class);
diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c
index cad6cbd..3f3192a 100644
--- a/gtk/gtksnapshot.c
+++ b/gtk/gtksnapshot.c
@@ -111,7 +111,6 @@ gtk_snapshot_init (GtkSnapshot *snapshot,
snapshot->renderer = renderer;
snapshot->clip_region = clip;
snapshot->root = gsk_container_node_new ();
- gsk_render_node_set_bounds (snapshot->root, &GRAPHENE_RECT_INIT (extents.x, extents.y, extents.width,
extents.height));
if (name)
{
@@ -176,14 +175,12 @@ gtk_snapshot_push_node (GtkSnapshot *snapshot,
*/
void
gtk_snapshot_push (GtkSnapshot *snapshot,
- const graphene_rect_t *bounds,
const char *name,
...)
{
GskRenderNode *node;
node = gsk_container_node_new ();
- gsk_render_node_set_bounds (node, bounds);
if (name)
{
diff --git a/gtk/gtksnapshot.h b/gtk/gtksnapshot.h
index d520106..e79d713 100644
--- a/gtk/gtksnapshot.h
+++ b/gtk/gtksnapshot.h
@@ -41,9 +41,8 @@ GskRenderer * gtk_snapshot_get_renderer (const GtkSnapshot
GDK_AVAILABLE_IN_3_90
void gtk_snapshot_push (GtkSnapshot *snapshot,
- const graphene_rect_t *bounds,
const char *name,
- ...) G_GNUC_PRINTF(3, 4);
+ ...) G_GNUC_PRINTF(2, 3);
GDK_AVAILABLE_IN_3_90
void gtk_snapshot_push_node (GtkSnapshot *snapshot,
GskRenderNode *node);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]