Commit 22110ef5 authored by Alexander Larsson's avatar Alexander Larsson

gsk: Add bounds member to RenderNode

Instead of constantly recalculating this (especially recursively for
parents!) we do it only on construction, because everything is
immutable anyway. Also, most nodes had a bounds already and can
use the new parent member instead.

We also do direct access to the node bounds rather than calling
gsk_render_node_get_bounds in various places, which means
we do less copying.
parent 2d4b46f4
......@@ -604,7 +604,6 @@ gsk_gl_renderer_add_render_item (GskGLRenderer *self,
RenderItem *parent)
{
graphene_rect_t viewport;
graphene_rect_t bounds;
RenderItem item;
RenderItem *ritem = NULL;
int program_id;
......@@ -618,24 +617,22 @@ gsk_gl_renderer_add_render_item (GskGLRenderer *self,
if (scale_factor < 1)
scale_factor = 1;
gsk_render_node_get_bounds (node, &bounds);
item.node = node;
item.name = node->name != NULL ? node->name : "unnamed";
/* The texture size */
item.size.width = bounds.size.width * scale_factor;
item.size.height = bounds.size.height * scale_factor;
item.size.width = node->bounds.size.width * scale_factor;
item.size.height = node->bounds.size.height * scale_factor;
/* Each render item is an axis-aligned bounding box that we
* transform using the given transformation matrix
*/
item.min.x = bounds.origin.x;
item.min.y = bounds.origin.y;
item.min.x = node->bounds.origin.x;
item.min.y = node->bounds.origin.y;
item.min.z = 0.f;
item.max.x = item.min.x + bounds.size.width;
item.max.y = item.min.y + bounds.size.height;
item.max.x = item.min.x + node->bounds.size.width;
item.max.y = item.min.y + node->bounds.size.height;
item.max.z = 0.f;
/* The location of the item, in normalized world coordinates */
......@@ -763,17 +760,14 @@ gsk_gl_renderer_add_render_item (GskGLRenderer *self,
default:
{
graphene_rect_t bounds;
cairo_surface_t *surface;
cairo_t *cr;
gsk_render_node_get_bounds (node, &bounds);
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
ceil (bounds.size.width),
ceil (bounds.size.height));
ceil (node->bounds.size.width),
ceil (node->bounds.size.height));
cr = cairo_create (surface);
cairo_translate (cr, -bounds.origin.x, -bounds.origin.y);
cairo_translate (cr, -node->bounds.origin.x, -node->bounds.origin.y);
gsk_render_node_draw (node, cr);
......
......@@ -176,7 +176,7 @@ gsk_render_node_get_bounds (GskRenderNode *node,
g_return_if_fail (GSK_IS_RENDER_NODE (node));
g_return_if_fail (bounds != NULL);
node->node_class->get_bounds (node, bounds);
graphene_rect_init_from_rect (bounds, &node->bounds);
}
void
......@@ -258,14 +258,11 @@ gsk_render_node_draw (GskRenderNode *node,
if (!GSK_RENDER_MODE_CHECK (GEOMETRY))
{
graphene_rect_t frame;
gsk_render_node_get_bounds (node, &frame);
GSK_NOTE (CAIRO, g_print ("CLIP = { .x = %g, .y = %g, .width = %g, .height = %g }\n",
frame.origin.x, frame.origin.y,
frame.size.width, frame.size.height));
node->bounds.origin.x, node->bounds.origin.y,
node->bounds.size.width, node->bounds.size.height));
cairo_rectangle (cr, frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
cairo_rectangle (cr, node->bounds.origin.x, node->bounds.origin.y, node->bounds.size.width, node->bounds.size.height);
cairo_clip (cr);
}
......@@ -277,12 +274,9 @@ gsk_render_node_draw (GskRenderNode *node,
if (GSK_RENDER_MODE_CHECK (GEOMETRY))
{
graphene_rect_t frame;
gsk_render_node_get_bounds (node, &frame);
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
cairo_rectangle (cr, frame.origin.x - 1, frame.origin.y - 1, frame.size.width + 2, frame.size.height + 2);
cairo_rectangle (cr, node->bounds.origin.x - 1, node->bounds.origin.y - 1,
node->bounds.size.width + 2, node->bounds.size.height + 2);
cairo_set_line_width (cr, 2);
cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
cairo_stroke (cr);
......
This diff is collapsed.
......@@ -22,6 +22,8 @@ struct _GskRenderNode
/* Scaling filters */
GskScalingFilter min_filter;
GskScalingFilter mag_filter;
graphene_rect_t bounds;
};
struct _GskRenderNodeClass
......@@ -32,8 +34,6 @@ struct _GskRenderNodeClass
void (* finalize) (GskRenderNode *node);
void (* draw) (GskRenderNode *node,
cairo_t *cr);
void (* get_bounds) (GskRenderNode *node,
graphene_rect_t *bounds);
};
GskRenderNode *gsk_render_node_new (const GskRenderNodeClass *node_class);
......
......@@ -171,20 +171,20 @@ gsk_vulkan_render_pass_upload_fallback (GskVulkanRenderPass *self,
GskVulkanRender *render,
GskVulkanUploader *uploader)
{
graphene_rect_t bounds;
GskRenderNode *node;
cairo_surface_t *surface;
cairo_t *cr;
gsk_render_node_get_bounds (op->node, &bounds);
node = op->node;
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
ceil (bounds.size.width),
ceil (bounds.size.height));
ceil (node->bounds.size.width),
ceil (node->bounds.size.height));
cr = cairo_create (surface);
cairo_translate (cr, -bounds.origin.x, -bounds.origin.y);
cairo_translate (cr, -node->bounds.origin.x, -node->bounds.origin.y);
gsk_render_node_draw (node, cr);
gsk_render_node_draw (op->node, cr);
cairo_destroy (cr);
op->source = gsk_vulkan_image_new_from_data (uploader,
......@@ -303,26 +303,20 @@ gsk_vulkan_render_pass_collect_vertex_data (GskVulkanRenderPass *self,
case GSK_VULKAN_OP_SURFACE:
case GSK_VULKAN_OP_TEXTURE:
{
graphene_rect_t bounds;
gsk_render_node_get_bounds (op->render.node, &bounds);
op->render.vertex_offset = offset + n_bytes;
gsk_vulkan_blend_pipeline_collect_vertex_data (GSK_VULKAN_BLEND_PIPELINE (op->render.pipeline),
data + n_bytes + offset,
&bounds);
&op->render.node.bounds);
n_bytes += op->render.vertex_count;
}
break;
case GSK_VULKAN_OP_COLOR:
{
graphene_rect_t bounds;
gsk_render_node_get_bounds (op->render.node, &bounds);
op->render.vertex_offset = offset + n_bytes;
gsk_vulkan_color_pipeline_collect_vertex_data (GSK_VULKAN_COLOR_PIPELINE (op->render.pipeline),
data + n_bytes + offset,
&bounds,
&op->render.node.bounds,
gsk_color_node_peek_color (op->render.node));
n_bytes += op->render.vertex_count;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment