From 33d335d61efa7486f13c4739cd55f1bea40dbdbd Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Mon, 3 Jun 2019 13:08:29 -0700 Subject: [PATCH] Do nothing if the params didn't change when compositing iOS platform views. (flutter/engine#8999) --- engine/src/flutter/flow/embedded_views.h | 4 ++++ .../ios/framework/Source/FlutterPlatformViews.mm | 11 ++++++++++- .../framework/Source/FlutterPlatformViews_Internal.h | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/flow/embedded_views.h b/engine/src/flutter/flow/embedded_views.h index e7b34f753bc..d37c18f3832 100644 --- a/engine/src/flutter/flow/embedded_views.h +++ b/engine/src/flutter/flow/embedded_views.h @@ -18,6 +18,10 @@ class EmbeddedViewParams { public: SkPoint offsetPixels; SkSize sizePoints; + + bool operator==(const EmbeddedViewParams& other) const { + return offsetPixels == other.offsetPixels && sizePoints == other.sizePoints; + } }; // This is only used on iOS when running in a non headless mode, diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index 0deada0add6..739d1128837 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -187,7 +187,14 @@ SkCanvas* FlutterPlatformViewsController::CompositeEmbeddedView( const flutter::EmbeddedViewParams& params) { // TODO(amirh): assert that this is running on the platform thread once we support the iOS // embedded views thread configuration. - // TODO(amirh): do nothing if the params didn't change. + + // Do nothing if the params didn't change. + if (current_composition_params_.count(view_id) == 1 && + current_composition_params_[view_id] == params) { + return picture_recorders_[view_id]->getRecordingCanvas(); + } + current_composition_params_[view_id] = params; + CGFloat screenScale = [[UIScreen mainScreen] scale]; CGRect rect = CGRectMake(params.offsetPixels.x() / screenScale, params.offsetPixels.y() / screenScale, @@ -209,6 +216,7 @@ void FlutterPlatformViewsController::Reset() { composition_order_.clear(); active_composition_order_.clear(); picture_recorders_.clear(); + current_composition_params_.clear(); } bool FlutterPlatformViewsController::SubmitFrame(bool gl_rendering, @@ -288,6 +296,7 @@ void FlutterPlatformViewsController::DisposeViews() { views_.erase(viewId); touch_interceptors_.erase(viewId); overlays_.erase(viewId); + current_composition_params_.erase(viewId); } views_to_dispose_.clear(); } diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h index 5361fced0cc..8ccda219084 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h @@ -88,6 +88,8 @@ class FlutterPlatformViewsController { std::map>> factories_; std::map>> views_; std::map> touch_interceptors_; + // Mapping a platform view ID to its latest composition params. + std::map current_composition_params_; std::map> overlays_; // The GrContext that is currently used by all of the overlay surfaces. // We track this to know when the GrContext for the Flutter app has changed