From bd83ff4388c8884cc12fc97a77b5f4f1e8c25b41 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Mon, 1 Feb 2016 10:33:23 -0800 Subject: [PATCH] Clear the Flow raster cache when a GrContext is destroyed After an application is suspended and the GrContext associated with the Flutter view is destroyed, the raster cache still contains images tied to the defunct context. The SkyShell process will crash if these images are used after the application resumes. --- engine/src/flutter/flow/paint_context.cc | 4 ++++ engine/src/flutter/flow/paint_context.h | 2 ++ engine/src/flutter/flow/raster_cache.cc | 4 ++++ engine/src/flutter/flow/raster_cache.h | 2 ++ 4 files changed, 12 insertions(+) diff --git a/engine/src/flutter/flow/paint_context.cc b/engine/src/flutter/flow/paint_context.cc index ffa4b7c5f6..0cc2e99232 100644 --- a/engine/src/flutter/flow/paint_context.cc +++ b/engine/src/flutter/flow/paint_context.cc @@ -49,4 +49,8 @@ PaintContext::ScopedFrame::~ScopedFrame() { PaintContext::~PaintContext() { } +void PaintContext::OnGrContextDestroyed() { + raster_cache_.Clear(); +} + } // namespace flow diff --git a/engine/src/flutter/flow/paint_context.h b/engine/src/flutter/flow/paint_context.h index e0fb8faded..3177050d2c 100644 --- a/engine/src/flutter/flow/paint_context.h +++ b/engine/src/flutter/flow/paint_context.h @@ -51,6 +51,8 @@ class PaintContext { SkCanvas& canvas, bool instrumentation_enabled = true); + void OnGrContextDestroyed(); + RasterCache& raster_cache() { return raster_cache_; } const instrumentation::Counter& frame_count() const { return frame_count_; } const instrumentation::Stopwatch& frame_time() const { return frame_time_; } diff --git a/engine/src/flutter/flow/raster_cache.cc b/engine/src/flutter/flow/raster_cache.cc index 4a2b71f343..0e1f7da0e2 100644 --- a/engine/src/flutter/flow/raster_cache.cc +++ b/engine/src/flutter/flow/raster_cache.cc @@ -112,4 +112,8 @@ void RasterCache::SweepAfterFrame() { cache_.erase(it); } +void RasterCache::Clear() { + cache_.clear(); +} + } // namespace flow diff --git a/engine/src/flutter/flow/raster_cache.h b/engine/src/flutter/flow/raster_cache.h index 884794f981..633339f123 100644 --- a/engine/src/flutter/flow/raster_cache.h +++ b/engine/src/flutter/flow/raster_cache.h @@ -25,6 +25,8 @@ class RasterCache { GrContext* context, SkPicture* picture, const SkMatrix& ctm); void SweepAfterFrame(); + void Clear(); + private: struct Entry { Entry();