| Flutter iOS Embedder |

Instance Methods | Properties | List of all members
FlutterPlatformViewsController Class Reference

`#import <FlutterPlatformViewsController.h>`

Inheritance diagram for FlutterPlatformViewsController:

## Instance Methods
(instancetype) | - NS_DESIGNATED_INITIALIZER
(void) | - registerViewFactory:withId:gestureRecognizersBlockingPolicy:
| set the factory used to construct embedded UI Views. More...
(void) | - beginFrameWithSize:
| Mark the beginning of a frame and record the size of the onscreen. More...
(void) | - cancelFrame
| Cancel the current frame, indicating that no platform views are composited. More...
(void) | - prerollCompositeEmbeddedView:withParams:
| Record a platform view in the layer tree to be rendered, along with the positioning and mutator parameters. More...
(FlutterTouchInterceptingView *) | - flutterTouchInterceptingViewForId:
| Returns the`FlutterTouchInterceptingView` with the provided view_id. More...
(flutter::PostPrerollResult) | - postPrerollActionWithThreadMerger:impellerEnabled:
| Determine if thread merging is required after prerolling platform views. More...
(void) | - endFrameWithResubmit:threadMerger:impellerEnabled:
| Mark the end of a compositor frame. More...
(flutter::DlCanvas *) | - compositeEmbeddedViewWithId:
| Returns the Canvas for the overlay slice for the given platform view. More...
(void) | - reset
| Discards all platform views instances and auxiliary resources. More...
(BOOL) | - submitFrame:withIosContext:grContext:
| Encode rendering for the Flutter overlay views and queue up perform platform view mutations. More...
(void) | - onMethodCall:result:
| Handler for platform view message channels. More...
(long) | - firstResponderPlatformViewId
| Returns the platform view id if the platform view (or any of its descendant view) is the first responder. More...
(void) | - pushFilterToVisitedPlatformViews:withRect:
| Pushes backdrop filter mutation to the mutator stack of each visited platform view. More...
(void) | - pushVisitedPlatformViewId:
| Pushes the view id of a visted platform view to the list of visied platform views. More...
(size_t) | - embeddedViewCount
(UIView *_Nullable) | - platformViewForId:
(void) | - compositeView:withParams:
(const flutter::EmbeddedViewParams &) | - compositionParamsForView:

## Properties
const fml::RefPtr< fml::TaskRunner > & | taskRunner
| The task runner used to post rendering tasks to the platform thread. More...
UIView *_Nullable | flutterView
| The flutter view. More...
UIViewController< FlutterViewResponder > *_Nullable | flutterViewController
| The flutter view controller. More...

## Detailed Description

Definition at line 31 of file FlutterPlatformViewsController.h.

## Method Documentation

## ◆ beginFrameWithSize:

- (void) beginFrameWithSize: |  | (SkISize) | frameSize |

Mark the beginning of a frame and record the size of the onscreen.

Definition at line 447 of file FlutterPlatformViewsController.mm.

447 :(SkISize)frameSize {
448 [self resetFrameState];
449 self.frameSize = frameSize;
450 }

## ◆ cancelFrame

- (void) cancelFrame |  |  |

Cancel the current frame, indicating that no platform views are composited.

Additionally, reverts the composition order to its original state at the beginning of the frame.

Definition at line 452 of file FlutterPlatformViewsController.mm.

452 {
453 [self resetFrameState];
454 }

Referenced by postPrerollActionWithThreadMerger:impellerEnabled:.

## ◆ compositeEmbeddedViewWithId:

- (DlCanvas *) FlutterPlatformViewsController: |  | (int64_t) | viewId |

Returns the Canvas for the overlay slice for the given platform view.

Called from the raster thread.

Definition at line 707 of file FlutterPlatformViewsController.mm.

707 :(int64_t)viewId {
708 FML_DCHECK(self.slices.find(viewId) != self.slices.end());
709 return self.slices[viewId]->canvas();
710 }

## ◆ compositeView:withParams:

- (void) compositeView: |  | (int64_t) | viewId
withParams: |  | (const flutter::EmbeddedViewParams &) | params

Provided by category FlutterPlatformViewsController(Testing).

## ◆ compositionParamsForView:

- (const EmbeddedViewParams& FlutterPlatformViewsController(Testing)): |  | (int64_t) | viewId |

Provided by category FlutterPlatformViewsController(Testing).

## ◆ embeddedViewCount

- (size_t) embeddedViewCount |  |  |

Provided by category FlutterPlatformViewsController(Testing).

## ◆ endFrameWithResubmit:threadMerger:impellerEnabled:

- (void) endFrameWithResubmit: |  | (BOOL) | shouldResubmitFrame
threadMerger: |  | (const fml::RefPtr<fml::RasterThreadMerger>&) | rasterThreadMerger
impellerEnabled: |  | (BOOL) | impellerEnabled

Mark the end of a compositor frame.

May determine changes are required to the thread merging state. Called from the raster thread.

Definition at line 491 of file FlutterPlatformViewsController.mm.

491 :(BOOL)shouldResubmitFrame
492 threadMerger:(const fml::RefPtr<fml::RasterThreadMerger>&)rasterThreadMerger
493 impellerEnabled:(BOOL)impellerEnabled {
494 #if FML_OS_IOS_SIMULATOR
495 BOOL runCheck = YES;
496 #else
497 BOOL runCheck = !impellerEnabled;
498 #endif // FML_OS_IOS_SIMULATOR
499 if (runCheck && shouldResubmitFrame) {
500 rasterThreadMerger->MergeWithLease(kDefaultMergedLeaseDuration);
501 }
502 }

References kDefaultMergedLeaseDuration.

## ◆ firstResponderPlatformViewId

- (long) firstResponderPlatformViewId |  |  |

Returns the platform view id if the platform view (or any of its descendant view) is the first responder.

Returns -1 if no such platform view is found.

Definition at line 546 of file FlutterPlatformViewsController.mm.

546 {
547 for (auto const& [id, platformViewData] : self.platformViews) {
548 UIView* rootView = platformViewData.root_view;
549 if (rootView.flt_hasFirstResponderInViewHierarchySubtree) {
550 return id;
551 }
552 }
553 return -1;
554 }

## ◆ flutterTouchInterceptingViewForId:

- (FlutterTouchInterceptingView *) flutterTouchInterceptingViewForId: |  | (int64_t) | viewId |

Returns the`FlutterTouchInterceptingView` with the provided view_id.

Returns nil if there is no platform view with the provided id. Called from the platform thread.

Definition at line 539 of file FlutterPlatformViewsController.mm.

539 :(int64_t)viewId {
540 if (self.platformViews.empty()) {
541 return nil;
542 }
543 return self.platformViews[viewId].touch_interceptor;
544 }

## ◆ NS_DESIGNATED_INITIALIZER

- (instancetype) NS_DESIGNATED_INITIALIZER |  |  |

## ◆ onMethodCall:result:

- (void) onMethodCall: |  | (FlutterMethodCall*) | call
result: |  | (FlutterResult) | result

Handler for platform view message channels.

Definition at line 310 of file FlutterPlatformViewsController.mm.

310 :(FlutterMethodCall*)call result:(FlutterResult)result {
311 if ([[call method] isEqualToString:@"create"]) {
312 [self onCreate:call result:result];
313 } else if ([[call method] isEqualToString:@"dispose"]) {
314 [self onDispose:call result:result];
315 } else if ([[call method] isEqualToString:@"acceptGesture"]) {
316 [self onAcceptGesture:call result:result];
317 } else if ([[call method] isEqualToString:@"rejectGesture"]) {
318 [self onRejectGesture:call result:result];
319 } else {
320 result(FlutterMethodNotImplemented);
321 }
322 }

References FlutterMethodNotImplemented.

## ◆ platformViewForId:

- (UIView* _Nullable) platformViewForId: |  | (int64_t) | viewId |

Provided by category FlutterPlatformViewsController(Testing).

## ◆ postPrerollActionWithThreadMerger:impellerEnabled:

- (PostPrerollResult) FlutterPlatformViewsController: |  | (const fml::RefPtr<fml::RasterThreadMerger>&) | rasterThreadMerger
impellerEnabled: |  | (BOOL) | impellerEnabled

Determine if thread merging is required after prerolling platform views.

Called from the raster thread.

Definition at line 456 of file FlutterPlatformViewsController.mm.

456 :
457 (const fml::RefPtr<fml::RasterThreadMerger>&)rasterThreadMerger
458 impellerEnabled:(BOOL)impellerEnabled {
459 // TODO(jonahwilliams): remove this once Software backend is removed for iOS Sim.
460 #ifdef FML_OS_IOS_SIMULATOR
461 const bool mergeThreads = true;
462 #else
463 const bool mergeThreads = !impellerEnabled;
464 #endif // FML_OS_IOS_SIMULATOR
465
466 if (mergeThreads) {
467 if (self.compositionOrder.empty()) {
468 return flutter::PostPrerollResult::kSuccess;
469 }
470 if (!rasterThreadMerger->IsMerged()) {
471 // The raster thread merger may be disabled if the rasterizer is being
472 // created or teared down.
473 //
474 // In such cases, the current frame is dropped, and a new frame is attempted
475 // with the same layer tree.
476 //
477 // Eventually, the frame is submitted once this method returns `kSuccess`.
478 // At that point, the raster tasks are handled on the platform thread.
479 [self cancelFrame];
480 return flutter::PostPrerollResult::kSkipAndRetryFrame;
481 }
482 // If the post preroll action is successful, we will display platform views in the current
483 // frame. In order to sync the rendering of the platform views (quartz) with skia's rendering,
484 // We need to begin an explicit CATransaction. This transaction needs to be submitted
485 // after the current frame is submitted.
486 rasterThreadMerger->ExtendLeaseTo(kDefaultMergedLeaseDuration);
487 }
488 return flutter::PostPrerollResult::kSuccess;
489 }

References cancelFrame, and kDefaultMergedLeaseDuration.

## ◆ prerollCompositeEmbeddedView:withParams:

- (void) prerollCompositeEmbeddedView: |  | (int64_t) | viewId
withParams: |  | (std::unique_ptr<flutter::EmbeddedViewParams>) | params

Record a platform view in the layer tree to be rendered, along with the positioning and mutator parameters.

Called from the raster thread.

Definition at line 513 of file FlutterPlatformViewsController.mm.

513 :(int64_t)viewId
514 withParams:(std::unique_ptr<flutter::EmbeddedViewParams>)params {
515 SkRect viewBounds = SkRect::Make(self.frameSize);
516 std::unique_ptr<flutter::EmbedderViewSlice> view;
517 view = std::make_unique<flutter::DisplayListEmbedderViewSlice>(viewBounds);
518 self.slices.insert_or_assign(viewId, std::move(view));
519
520 self.compositionOrder.push_back(viewId);
521
522 if (self.currentCompositionParams.count(viewId) == 1 &&
523 self.currentCompositionParams[viewId] == *params.get()) {
524 // Do nothing if the params didn't change.
525 return;
526 }
527 self.currentCompositionParams[viewId] = flutter::EmbeddedViewParams(*params.get());
528 self.viewsToRecomposite.insert(viewId);
529 }

## ◆ pushFilterToVisitedPlatformViews:withRect:

- (void) pushFilterToVisitedPlatformViews: |  | (const std::shared_ptr<flutter::DlImageFilter>&) | filter
withRect: |  | (const SkRect&) | filterRect

Pushes backdrop filter mutation to the mutator stack of each visited platform view.

Definition at line 504 of file FlutterPlatformViewsController.mm.

504 :(const std::shared_ptr<flutter::DlImageFilter>&)filter
505 withRect:(const SkRect&)filterRect {
506 for (int64_t id : self.visitedPlatformViews) {
507 flutter::EmbeddedViewParams params = self.currentCompositionParams[id];
508 params.PushImageFilter(filter, filterRect);
509 self.currentCompositionParams[id] = params;
510 }
511 }

## ◆ pushVisitedPlatformViewId:

- (void) pushVisitedPlatformViewId: |  | (int64_t) | viewId |

Pushes the view id of a visted platform view to the list of visied platform views.

Definition at line 1021 of file FlutterPlatformViewsController.mm.

1021 :(int64_t)viewId {
1022 self.visitedPlatformViews.push_back(viewId);
1023 }

## ◆ registerViewFactory:withId:gestureRecognizersBlockingPolicy:

- (void) registerViewFactory: |  | (NSObject<FlutterPlatformViewFactory>*) | factory
withId: |  | (NSString*) | factoryId
gestureRecognizersBlockingPolicy: |  | (FlutterPlatformViewGestureRecognizersBlockingPolicy) | gestureRecognizerBlockingPolicy

set the factory used to construct embedded UI Views.

Definition at line 437 of file FlutterPlatformViewsController.mm.

437 :(NSObject<FlutterPlatformViewFactory>*)factory
438 withId:(NSString*)factoryId
439 gestureRecognizersBlockingPolicy:
440 (FlutterPlatformViewGestureRecognizersBlockingPolicy)gestureRecognizerBlockingPolicy {
441 std::string idString([factoryId UTF8String]);
442 FML_CHECK(self.factories.count(idString) == 0);
443 self.factories[idString] = factory;
444 self.gestureRecognizersBlockingPolicies[idString] = gestureRecognizerBlockingPolicy;
445 }

## ◆ reset

- (void) reset |  |  |

Discards all platform views instances and auxiliary resources.

Called from the raster thread.

Definition at line 712 of file FlutterPlatformViewsController.mm.

712 {
713 // Reset will only be called from the raster thread or a merged raster/platform thread.
714 // _platformViews must only be modified on the platform thread, and any operations that
715 // read or modify platform views should occur there.
716 fml::TaskRunner::RunNowOrPostTask(self.platformTaskRunner, [self]() {
717 for (int64_t viewId : self.compositionOrder) {
718 [self.platformViews[viewId].root_view removeFromSuperview];
719 }
720 self.platformViews.clear();
721 });
722
723 self.compositionOrder.clear();
724 self.slices.clear();
725 self.currentCompositionParams.clear();
726 self.viewsToRecomposite.clear();
727 self.layerPool->RecycleLayers();
728 self.visitedPlatformViews.clear();
729 }

## ◆ submitFrame:withIosContext:grContext:

- (BOOL) submitFrame: |  | (std::unique_ptr< flutter::SurfaceFrame >) | frame
withIosContext: |  | (const std::shared_ptr< flutter::IOSContext > &) | iosContext
grContext: |  | (GrDirectContext *_Nullable) | grContext

Encode rendering for the Flutter overlay views and queue up perform platform view mutations.

Called from the raster thread.

## Property Documentation

## ◆ flutterView

- (UIView* _Nullable) flutterView
| read write nonatomic weak

The flutter view.

Definition at line 39 of file FlutterPlatformViewsController.h.

## ◆ flutterViewController

- (UIViewController<FlutterViewResponder>* _Nullable) flutterViewController
| read write nonatomic weak

The flutter view controller.

Definition at line 42 of file FlutterPlatformViewsController.h.

## ◆ taskRunner

- (const RefPtr<) fml:
| read write nonatomic assign

The task runner used to post rendering tasks to the platform thread.

Definition at line 36 of file FlutterPlatformViewsController.h.

The documentation for this class was generated from the following files:

- shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsController.h
- shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsController.mm

FlutterMethodNotImplemented
FLUTTER_DARWIN_EXPORT NSObject const * FlutterMethodNotImplemented
kDefaultMergedLeaseDuration
static constexpr int kDefaultMergedLeaseDuration
Definition: FlutterPlatformViewsController.mm:21
FlutterMethodCall
Definition: FlutterCodecs.h:220
FlutterResult
void(^ FlutterResult)(id _Nullable result)
Definition: FlutterChannels.h:194
FlutterPlatformViewGestureRecognizersBlockingPolicy
FlutterPlatformViewGestureRecognizersBlockingPolicy
Definition: FlutterPlugin.h:252