Defer image surface destruction until next paint

Fixes #4043

(cherry picked from commit dbf786e456f2792476791caf9dadfeb43e9ab383)
This commit is contained in:
Jon Evans 2020-03-29 20:21:58 -04:00
parent 161b73e55b
commit 23c1baae8e
2 changed files with 14 additions and 1 deletions

View File

@ -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

View File

@ -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<cairo_surface_t*> imageSurfaces;
std::vector<cairo_matrix_t> xformStack;
void flushPath();