[platform_view] iOSP platformView composition optimize. (flutter/engine#8202)
Optimize the performance of the platform view composition. When recomposition is required, we previously remove all the platform view related views (intercepting view, platform view) and re-add them for each frame. This is mentioned in flutter/flutter#23793. This PR enhanced the performance by re-arrange the existing UIViews and only add the newly created Views. As a result, it would also fix flutter/flutter#29427
This commit is contained in:
@@ -225,22 +225,24 @@ bool FlutterPlatformViewsController::SubmitFrame(bool gl_rendering,
|
||||
composition_order_.clear();
|
||||
return did_submit;
|
||||
}
|
||||
DetachUnusedLayers();
|
||||
active_composition_order_.clear();
|
||||
UIView* flutter_view = flutter_view_.get();
|
||||
|
||||
// This can be more efficient, instead of removing all views and then re-attaching them,
|
||||
// we should only remove the views that has been completly removed from the layer tree, and
|
||||
// reorder the views using UIView's bringSubviewToFront.
|
||||
// TODO(amirh): make this more efficient.
|
||||
// https://github.com/flutter/flutter/issues/23793
|
||||
for (UIView* sub_view in [flutter_view subviews]) {
|
||||
[sub_view removeFromSuperview];
|
||||
}
|
||||
|
||||
active_composition_order_.clear();
|
||||
for (size_t i = 0; i < composition_order_.size(); i++) {
|
||||
int view_id = composition_order_[i];
|
||||
[flutter_view addSubview:touch_interceptors_[view_id].get()];
|
||||
[flutter_view addSubview:overlays_[view_id]->overlay_view.get()];
|
||||
UIView* intercepter = touch_interceptors_[view_id].get();
|
||||
UIView* overlay = overlays_[view_id]->overlay_view;
|
||||
FML_CHECK(intercepter.superview == overlay.superview);
|
||||
|
||||
if (intercepter.superview == flutter_view) {
|
||||
[flutter_view bringSubviewToFront:intercepter];
|
||||
[flutter_view bringSubviewToFront:overlay];
|
||||
} else {
|
||||
[flutter_view addSubview:intercepter];
|
||||
[flutter_view addSubview:overlay];
|
||||
}
|
||||
|
||||
active_composition_order_.push_back(view_id);
|
||||
}
|
||||
|
||||
@@ -248,6 +250,21 @@ bool FlutterPlatformViewsController::SubmitFrame(bool gl_rendering,
|
||||
return did_submit;
|
||||
}
|
||||
|
||||
void FlutterPlatformViewsController::DetachUnusedLayers() {
|
||||
std::unordered_set<int64_t> composition_order_set;
|
||||
|
||||
for (int64_t view_id : composition_order_) {
|
||||
composition_order_set.insert(view_id);
|
||||
}
|
||||
|
||||
for (int64_t view_id : active_composition_order_) {
|
||||
if (composition_order_set.find(view_id) == composition_order_set.end()) {
|
||||
[touch_interceptors_[view_id].get() removeFromSuperview];
|
||||
[overlays_[view_id]->overlay_view.get() removeFromSuperview];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FlutterPlatformViewsController::EnsureOverlayInitialized(int64_t overlay_id) {
|
||||
if (overlays_.count(overlay_id) != 0) {
|
||||
return;
|
||||
|
||||
@@ -98,6 +98,7 @@ class FlutterPlatformViewsController {
|
||||
void OnAcceptGesture(FlutterMethodCall* call, FlutterResult& result);
|
||||
void OnRejectGesture(FlutterMethodCall* call, FlutterResult& result);
|
||||
|
||||
void DetachUnusedLayers();
|
||||
void EnsureOverlayInitialized(int64_t overlay_id);
|
||||
void EnsureGLOverlayInitialized(int64_t overlay_id,
|
||||
std::shared_ptr<IOSGLContext> gl_context,
|
||||
|
||||
Reference in New Issue
Block a user