From ba7649b3889c823cdc16983c7552956bc655fa8a Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 18 Oct 2019 09:33:45 -0500 Subject: [PATCH] inspector: Fix node recording When attaching renderer-specific data, we need to make sure that we key it off the renderer that is in use, and cope with the absence of render data. This fixes recording nodes in the inspector. --- gsk/gl/gskglrenderer.c | 26 ++++++++++++++++++++------ gsk/gskrendernodeimpl.c | 18 ++++++++++++++++-- gsk/gskrendernodeprivate.h | 6 ++++-- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/gsk/gl/gskglrenderer.c b/gsk/gl/gskglrenderer.c index b39edcca4f..5c6d8b3ad1 100644 --- a/gsk/gl/gskglrenderer.c +++ b/gsk/gl/gskglrenderer.c @@ -537,18 +537,19 @@ render_fallback_node (GskGLRenderer *self, typedef struct { int timestamp; + int stored; GskGLCachedGlyph *glyphs[]; } TextRenderData; static inline TextRenderData * -ensure_render_data (GskRenderNode *node, - GskGLGlyphCache *cache) +get_render_data (GskRenderNode *node, + GskGLGlyphCache *cache) { TextRenderData *data; int num_glyphs; num_glyphs = gsk_text_node_get_num_glyphs (node); - data = gsk_text_node_get_render_data (node); + data = gsk_text_node_get_render_data (node, cache); if (data) { if (data->timestamp < cache->atlas_timestamp) @@ -561,13 +562,24 @@ ensure_render_data (GskRenderNode *node, { data = g_new0 (TextRenderData, sizeof (TextRenderData) + sizeof (gpointer) * num_glyphs); data->timestamp = cache->atlas_timestamp; - - gsk_text_node_set_render_data (node, data); } return data; } +static inline void +set_render_data (GskRenderNode *node, + GskGLGlyphCache *cache, + TextRenderData *data) +{ + if (!data->stored) + { + data->stored = 1; + if (!gsk_text_node_set_render_data (node, cache, data)) + g_free (data); + } +} + static inline void render_text_node (GskGLRenderer *self, GskRenderNode *node, @@ -598,7 +610,7 @@ render_text_node (GskGLRenderer *self, ops_set_color (builder, color); } - render_data = ensure_render_data (node, self->glyph_cache); + render_data = get_render_data (node, self->glyph_cache); memset (&lookup, 0, sizeof (CacheKeyData)); lookup.data.font = (PangoFont *)font; @@ -663,6 +675,8 @@ render_text_node (GskGLRenderer *self, next: x_position += gi->geometry.width; } + + set_render_data (node, self->glyph_cache, render_data); } static inline void diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c index c362a6fa53..7625c68071 100644 --- a/gsk/gskrendernodeimpl.c +++ b/gsk/gskrendernodeimpl.c @@ -3414,7 +3414,9 @@ struct _GskTextNode GdkRGBA color; graphene_point_t offset; + gpointer render_key; gpointer render_data; + guint num_glyphs; PangoGlyphInfo glyphs[]; }; @@ -3547,6 +3549,7 @@ gsk_text_node_new (PangoFont *font, self->has_color_glyphs = font_has_color_glyphs (font); self->color = *color; self->offset = *offset; + self->render_key = NULL; self->render_data = NULL; self->num_glyphs = glyphs->num_glyphs; memcpy (self->glyphs, glyphs->glyphs, sizeof (PangoGlyphInfo) * glyphs->num_glyphs); @@ -3628,20 +3631,31 @@ gsk_text_node_get_offset (GskRenderNode *node) return &self->offset; } -void +gboolean gsk_text_node_set_render_data (GskRenderNode *node, + gpointer key, gpointer data) { GskTextNode *self = (GskTextNode *) node; + if (self->render_key != NULL) + return FALSE; + + self->render_key = key; self->render_data = data; + + return TRUE; } gpointer -gsk_text_node_get_render_data (GskRenderNode *node) +gsk_text_node_get_render_data (GskRenderNode *node, + gpointer key) { GskTextNode *self = (GskTextNode *) node; + if (self->render_key != key) + return NULL; + return self->render_data; } diff --git a/gsk/gskrendernodeprivate.h b/gsk/gskrendernodeprivate.h index f2fe034444..9ab3358393 100644 --- a/gsk/gskrendernodeprivate.h +++ b/gsk/gskrendernodeprivate.h @@ -46,9 +46,11 @@ void gsk_render_node_diff (GskRenderNode *nod void gsk_render_node_diff_impossible (GskRenderNode *node1, GskRenderNode *node2, cairo_region_t *region); -void gsk_text_node_set_render_data (GskRenderNode *node, +gboolean gsk_text_node_set_render_data (GskRenderNode *node, + gpointer key, gpointer data); -gpointer gsk_text_node_get_render_data (GskRenderNode *node); +gpointer gsk_text_node_get_render_data (GskRenderNode *node, + gpointer key);