From 92f23c4ea3acabe6c61d427a7f52b9a0a092ef02 Mon Sep 17 00:00:00 2001 From: cyanglaz Date: Fri, 8 May 2020 16:20:10 -0700 Subject: [PATCH 1/5] merge thread when there are platform views --- .../framework/Source/FlutterPlatformViews.mm | 21 ++++++++++++++++--- .../Source/FlutterPlatformViews_Internal.h | 6 ++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index 168a463123a8c..94971b0be2ee2 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -252,6 +252,9 @@ } bool FlutterPlatformViewsController::HasPendingViewOperations() { + // TODO(cyanglaz): https://github.com/flutter/flutter/issues/56474 + // This method also needs to consider if there are pending changes in overlays. Details in the + // above issue. if (!views_to_dispose_.empty()) { return true; } @@ -261,12 +264,21 @@ return active_composition_order_ != composition_order_; } +// TODO(cyanglaz): https://github.com/flutter/flutter/issues/56474 +// Remove this method is the issue above is resloved. +bool FlutterPlatformViewsController::HasPlatformViewThisOrNextFrame() { + return composition_order_.size() > 0 || active_composition_order_.size() > 0; +} + const int FlutterPlatformViewsController::kDefaultMergedLeaseDuration; PostPrerollResult FlutterPlatformViewsController::PostPrerollAction( fml::RefPtr raster_thread_merger) { - const bool uiviews_mutated = HasPendingViewOperations(); - if (uiviews_mutated) { + // TODO(cyanglaz): https://github.com/flutter/flutter/issues/56474 + // Switch `HasPlatformViewThisOrNextFrame` to `HasPendingViewOperations` when the issue above is + // resolved. + const bool has_platform_view = HasPlatformViewThisOrNextFrame(); + if (has_platform_view) { if (raster_thread_merger->IsMerged()) { raster_thread_merger->ExtendLeaseTo(kDefaultMergedLeaseDuration); } else { @@ -485,7 +497,10 @@ // Any UIKit related code has to run on main thread. // When on a non-main thread, we only allow the rest of the method to run if there is no // Pending UIView operations. - FML_DCHECK([[NSThread currentThread] isMainThread] || !HasPendingViewOperations()); + // TODO(cyanglaz): https://github.com/flutter/flutter/issues/56474 + // Switch `HasPlatformViewThisOrNextFrame` to `HasPendingViewOperations` when the issue above is + // resolved. + FML_DCHECK([[NSThread currentThread] isMainThread] || !HasPlatformViewThisOrNextFrame()); DisposeViews(); diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h index 0dcb793b00f03..ff8143f33605d 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h @@ -246,6 +246,12 @@ class FlutterPlatformViewsController { // have mutated for last layer tree. bool HasPendingViewOperations(); + // Returns true if there are embedded in the scene at current frame + // Or there will be embedded in the next frame. + // TODO(cyanglaz): https://github.com/flutter/flutter/issues/56474 + // Remove this method is the issue above is resloved. + bool HasPlatformViewThisOrNextFrame(); + // Traverse the `mutators_stack` and return the number of clip operations. int CountClips(const MutatorsStack& mutators_stack); From 54b02435412e1ab2d602643d8df4dc66c80159bd Mon Sep 17 00:00:00 2001 From: cyanglaz Date: Fri, 8 May 2020 16:34:52 -0700 Subject: [PATCH 2/5] remove unused method --- .../framework/Source/FlutterPlatformViews.mm | 22 +++---------------- .../Source/FlutterPlatformViews_Internal.h | 7 ++---- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index 94971b0be2ee2..d88f366e0113d 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -251,21 +251,9 @@ composition_order_ = active_composition_order_; } -bool FlutterPlatformViewsController::HasPendingViewOperations() { - // TODO(cyanglaz): https://github.com/flutter/flutter/issues/56474 - // This method also needs to consider if there are pending changes in overlays. Details in the - // above issue. - if (!views_to_dispose_.empty()) { - return true; - } - if (!views_to_recomposite_.empty()) { - return true; - } - return active_composition_order_ != composition_order_; -} - // TODO(cyanglaz): https://github.com/flutter/flutter/issues/56474 -// Remove this method is the issue above is resloved. +// Make this method check if there are pending view operations instead. +// Also rename it to `HasPendingViewOperations`. bool FlutterPlatformViewsController::HasPlatformViewThisOrNextFrame() { return composition_order_.size() > 0 || active_composition_order_.size() > 0; } @@ -275,8 +263,7 @@ PostPrerollResult FlutterPlatformViewsController::PostPrerollAction( fml::RefPtr raster_thread_merger) { // TODO(cyanglaz): https://github.com/flutter/flutter/issues/56474 - // Switch `HasPlatformViewThisOrNextFrame` to `HasPendingViewOperations` when the issue above is - // resolved. + // Rename `has_platform_view` to `view_mutated` when the above issue is resolved. const bool has_platform_view = HasPlatformViewThisOrNextFrame(); if (has_platform_view) { if (raster_thread_merger->IsMerged()) { @@ -497,9 +484,6 @@ // Any UIKit related code has to run on main thread. // When on a non-main thread, we only allow the rest of the method to run if there is no // Pending UIView operations. - // TODO(cyanglaz): https://github.com/flutter/flutter/issues/56474 - // Switch `HasPlatformViewThisOrNextFrame` to `HasPendingViewOperations` when the issue above is - // resolved. FML_DCHECK([[NSThread currentThread] isMainThread] || !HasPlatformViewThisOrNextFrame()); DisposeViews(); diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h index ff8143f33605d..1017cbc892bd4 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h @@ -242,14 +242,11 @@ class FlutterPlatformViewsController { // Dispose the views in `views_to_dispose_`. void DisposeViews(); - // This will return true after pre-roll if any of the embedded views - // have mutated for last layer tree. - bool HasPendingViewOperations(); - // Returns true if there are embedded in the scene at current frame // Or there will be embedded in the next frame. // TODO(cyanglaz): https://github.com/flutter/flutter/issues/56474 - // Remove this method is the issue above is resloved. + // Make this method check if there are pending view operations instead. + // Also rename it to `HasPendingViewOperations`. bool HasPlatformViewThisOrNextFrame(); // Traverse the `mutators_stack` and return the number of clip operations. From d08ef6363ac8ecda525fe124a031fca19e63fe0a Mon Sep 17 00:00:00 2001 From: cyanglaz Date: Fri, 8 May 2020 16:36:35 -0700 Subject: [PATCH 3/5] fix comment --- .../ios/framework/Source/FlutterPlatformViews_Internal.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h index 1017cbc892bd4..822d6402d8388 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h @@ -242,8 +242,8 @@ class FlutterPlatformViewsController { // Dispose the views in `views_to_dispose_`. void DisposeViews(); - // Returns true if there are embedded in the scene at current frame - // Or there will be embedded in the next frame. + // Returns true if there are embedded views in the scene at current frame + // Or there will be embedded views in the next frame. // TODO(cyanglaz): https://github.com/flutter/flutter/issues/56474 // Make this method check if there are pending view operations instead. // Also rename it to `HasPendingViewOperations`. From a97334db4bc576157435e7ff6b7e012875b3cb64 Mon Sep 17 00:00:00 2001 From: cyanglaz Date: Mon, 11 May 2020 12:09:20 -0700 Subject: [PATCH 4/5] rerun ci From fcbb1c4b33fd2689cb9baa55005e385edf0211ca Mon Sep 17 00:00:00 2001 From: cyanglaz Date: Mon, 11 May 2020 16:08:45 -0700 Subject: [PATCH 5/5] rerun ci