From d99f91f5fd4df3b1de2f04582cfa29b2289796fd Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 26 Apr 2016 14:23:12 +0100 Subject: [PATCH] gsk: Flush the GL render items cache Whenever the render tree changes we want to drop the RenderItem arrays, as each item contains a pointer to the GskRenderNode which becomes dangling once the root node changed. --- gsk/gskglrenderer.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/gsk/gskglrenderer.c b/gsk/gskglrenderer.c index 53945ee7a4..40febcad43 100644 --- a/gsk/gskglrenderer.c +++ b/gsk/gskglrenderer.c @@ -952,6 +952,30 @@ out: self->transparent_render_items->len)); } +static void +gsk_gl_renderer_clear_tree (GskRenderer *renderer, + GskRenderNode *root_node) +{ + GskGLRenderer *self = GSK_GL_RENDERER (renderer); + + if (self->context == NULL) + return; + + gdk_gl_context_make_current (self->context); + + g_clear_pointer (&self->opaque_render_items, g_array_unref); + g_clear_pointer (&self->transparent_render_items, g_array_unref); + + if (gsk_renderer_is_realized (renderer)) + { + self->opaque_render_items = g_array_sized_new (FALSE, FALSE, sizeof (RenderItem), 16); + g_array_set_clear_func (self->opaque_render_items, render_item_clear); + + self->transparent_render_items = g_array_sized_new (FALSE, FALSE, sizeof (RenderItem), 16); + g_array_set_clear_func (self->opaque_render_items, render_item_clear); + } +} + static void gsk_gl_renderer_clear (GskRenderer *renderer) { @@ -1051,6 +1075,7 @@ gsk_gl_renderer_class_init (GskGLRendererClass *klass) renderer_class->update = gsk_gl_renderer_update; renderer_class->clear = gsk_gl_renderer_clear; renderer_class->validate_tree = gsk_gl_renderer_validate_tree; + renderer_class->clear_tree = gsk_gl_renderer_clear_tree; renderer_class->render = gsk_gl_renderer_render; }