Skip to content

[flutter/engine] PlatformViewIOS::attachVIew() is called multiple times during flutter engine startup on iOS #106283

@gordon-ljl

Description

@gordon-ljl
void PlatformViewIOS::attachView() {

 auto flutter_view = static_cast<FlutterView*>(owner_controller_.get().view);
 auto ca_layer = fml::scoped_nsobject<CALayer>{[[flutter_view layer] retain]};
 ios_surface_ = IOSSurface::Create(ios_context_, ca_layer);
 FML_DCHECK(ios_surface_ != nullptr);
...
}

During the startup process of the flutter engine, this function(PlatformViewIOS::attachView()) will be called multiple times, which will result in unnecessary creation and deletion of ios_surface_ (ios_surface_ = IOSSurface::Create(ios_context_, ca_layer))many times.

First time: shell/platform/darwin/ios/platform_view_ios.mm

void PlatformViewIOS::SetOwnerViewController(fml::WeakPtr<FlutterViewController> owner_controller) {

 // line 101-103
 if (owner_controller_ && [owner_controller_.get() isViewLoaded]) {
   this->attachView();
 }
 ...
}

second time: /shell/platform/darwin/ios/framework/Source/FlutterEngine.mm
// line 391-394

- (void)attachView {
  self.iosPlatformView->attachView();
  [_textInputPlugin.get() setupIndirectScribbleInteraction:self.viewController];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: performanceRelates to speed or footprint issues (see "perf:" labels)engineflutter/engine related. See also e: labels.platform-iosiOS applications specificallyr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions