diff --git a/engine/src/flutter/flow/layers/picture_layer.cc b/engine/src/flutter/flow/layers/picture_layer.cc index 2f8eb67979..f4d1088cf2 100644 --- a/engine/src/flutter/flow/layers/picture_layer.cc +++ b/engine/src/flutter/flow/layers/picture_layer.cc @@ -13,16 +13,13 @@ namespace flow { // TODO(abarth): Make this configurable by developers. const bool kDebugCheckerboardRasterizedLayers = false; -PictureLayer::PictureLayer() { -} +PictureLayer::PictureLayer() {} -PictureLayer::~PictureLayer() { -} +PictureLayer::~PictureLayer() {} -void PictureLayer::Preroll(PrerollContext* context, - const SkMatrix& matrix) { +void PictureLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { image_ = context->raster_cache.GetPrerolledImage( - context->gr_context, picture_.get(), matrix); + context->gr_context, picture_.get(), matrix, is_complex_, will_change_); context->child_paint_bounds = picture_->cullRect().makeOffset(offset_.x(), offset_.y()); } diff --git a/engine/src/flutter/flow/layers/picture_layer.h b/engine/src/flutter/flow/layers/picture_layer.h index a025d2dacf..a499a1c23d 100644 --- a/engine/src/flutter/flow/layers/picture_layer.h +++ b/engine/src/flutter/flow/layers/picture_layer.h @@ -15,9 +15,11 @@ class PictureLayer : public Layer { ~PictureLayer() override; void set_offset(const SkPoint& offset) { offset_ = offset; } - void set_picture(sk_sp picture) { picture_ = std::move(picture); } + void set_is_complex(bool value) { is_complex_ = value; } + void set_will_change(bool value) { will_change_ = value; } + SkPicture* picture() const { return picture_.get(); } void Preroll(PrerollContext* frame, const SkMatrix& matrix) override; @@ -26,6 +28,8 @@ class PictureLayer : public Layer { private: SkPoint offset_; sk_sp picture_; + bool is_complex_ = false; + bool will_change_ = false; // If we rasterized the picture separately, image_ holds the pixels. sk_sp image_; diff --git a/engine/src/flutter/flow/raster_cache.cc b/engine/src/flutter/flow/raster_cache.cc index 59dc8c4239..d1f9293bf7 100644 --- a/engine/src/flutter/flow/raster_cache.cc +++ b/engine/src/flutter/flow/raster_cache.cc @@ -27,30 +27,29 @@ static bool isWorthRasterizing(SkPicture* picture) { #endif -RasterCache::RasterCache() { -} +RasterCache::RasterCache() {} -RasterCache::~RasterCache() { -} +RasterCache::~RasterCache() {} RasterCache::Entry::Entry() { physical_size.setEmpty(); } -RasterCache::Entry::~Entry() { -} +RasterCache::Entry::~Entry() {} sk_sp RasterCache::GetPrerolledImage(GrContext* context, - SkPicture* picture, - const SkMatrix& ctm) { + SkPicture* picture, + const SkMatrix& ctm, + bool is_complex, + bool will_change) { #if ENABLE_RASTER_CACHE SkScalar scaleX = ctm.getScaleX(); SkScalar scaleY = ctm.getScaleY(); SkRect rect = picture->cullRect(); - SkISize physical_size = SkISize::Make(rect.width() * scaleX, - rect.height() * scaleY); + SkISize physical_size = + SkISize::Make(rect.width() * scaleX, rect.height() * scaleY); if (physical_size.isEmpty()) return nullptr; @@ -74,10 +73,10 @@ sk_sp RasterCache::GetPrerolledImage(GrContext* context, // Saturate at the threshhold. entry.access_count = kRasterThreshold; - if (!entry.image && isWorthRasterizing(picture)) { - TRACE_EVENT2("flutter", "Rasterize picture layer", - "width", physical_size.width(), - "height", physical_size.height()); + if (!entry.image && !will_change && + (is_complex || isWorthRasterizing(picture))) { + TRACE_EVENT2("flutter", "Rasterize picture layer", "width", + physical_size.width(), "height", physical_size.height()); SkImageInfo info = SkImageInfo::MakeN32Premul(physical_size); sk_sp surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info); diff --git a/engine/src/flutter/flow/raster_cache.h b/engine/src/flutter/flow/raster_cache.h index a7bc439194..bcf9908a1a 100644 --- a/engine/src/flutter/flow/raster_cache.h +++ b/engine/src/flutter/flow/raster_cache.h @@ -21,8 +21,11 @@ class RasterCache { RasterCache(); ~RasterCache(); - sk_sp GetPrerolledImage( - GrContext* context, SkPicture* picture, const SkMatrix& ctm); + sk_sp GetPrerolledImage(GrContext* context, + SkPicture* picture, + const SkMatrix& ctm, + bool is_complex, + bool will_change); void SweepAfterFrame(); void Clear();