From 23c1baae8e888c25c6ed002ec5900f5d9ec1d479 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sun, 29 Mar 2020 20:21:58 -0400 Subject: [PATCH] Defer image surface destruction until next paint Fixes #4043 (cherry picked from commit dbf786e456f2792476791caf9dadfeb43e9ab383) --- common/gal/cairo/cairo_gal.cpp | 12 +++++++++++- include/gal/cairo/cairo_gal.h | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/common/gal/cairo/cairo_gal.cpp b/common/gal/cairo/cairo_gal.cpp index 1ed1d37c23..69ee7f2a86 100644 --- a/common/gal/cairo/cairo_gal.cpp +++ b/common/gal/cairo/cairo_gal.cpp @@ -83,6 +83,9 @@ CAIRO_GAL_BASE::~CAIRO_GAL_BASE() if( context ) cairo_destroy( context ); + + for( auto imageSurface : imageSurfaces ) + cairo_surface_destroy( imageSurface ); } @@ -508,7 +511,9 @@ void CAIRO_GAL_BASE::DrawBitmap( const BITMAP_BASE& aBitmap ) cairo_surface_mark_dirty( image ); cairo_set_source_surface( currentContext, image, 0, 0 ); cairo_paint( currentContext ); - cairo_surface_destroy( image ); + + // store the image handle so it can be destroyed later + imageSurfaces.push_back( image ); isElementAdded = true; @@ -929,6 +934,11 @@ void CAIRO_GAL_BASE::EnableDepthTest( bool aEnabled ) void CAIRO_GAL_BASE::resetContext() { + for( auto imageSurface : imageSurfaces ) + cairo_surface_destroy( imageSurface ); + + imageSurfaces.clear(); + ClearScreen(); // Compute the world <-> screen transformations diff --git a/include/gal/cairo/cairo_gal.h b/include/gal/cairo/cairo_gal.h index ef8a0fb125..1f46e85c4b 100644 --- a/include/gal/cairo/cairo_gal.h +++ b/include/gal/cairo/cairo_gal.h @@ -304,6 +304,9 @@ protected: cairo_t* context; ///< Cairo image cairo_surface_t* surface; ///< Cairo surface + /// List of surfaces that were created by painting images, to be cleaned up later + std::vector imageSurfaces; + std::vector xformStack; void flushPath();