Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
FlutterPlatformViewsController Class Reference

#include <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.
 
(void) - beginFrameWithSize:
 Mark the beginning of a frame and record the size of the onscreen.
 
(void) - cancelFrame
 Cancel the current frame, indicating that no platform views are composited.
 
(void) - prerollCompositeEmbeddedView:withParams:
 Record a platform view in the layer tree to be rendered, along with the positioning and mutator parameters.
 
(FlutterTouchInterceptingView *) - flutterTouchInterceptingViewForId:
 Returns theFlutterTouchInterceptingView with the provided view_id.
 
(flutter::PostPrerollResult- postPrerollActionWithThreadMerger:
 Determine if thread merging is required after prerolling platform views.
 
(void) - endFrameWithResubmit:threadMerger:
 Mark the end of a compositor frame.
 
(flutter::DlCanvas *) - compositeEmbeddedViewWithId:
 Returns the Canvas for the overlay slice for the given platform view.
 
(void) - reset
 Discards all platform views instances and auxiliary resources.
 
(BOOL- submitFrame:withIosContext:
 Encode rendering for the Flutter overlay views and queue up perform platform view mutations.
 
(void) - onMethodCall:result:
 Handler for platform view message channels.
 
(long) - firstResponderPlatformViewId
 Returns the platform view id if the platform view (or any of its descendant view) is the first responder.
 
(void) - pushFilterToVisitedPlatformViews:withRect:
 Pushes backdrop filter mutation to the mutator stack of each visited platform view.
 
(void) - pushVisitedPlatformViewId:
 Pushes the view id of a visted platform view to the list of visied platform views.
 
(void) - pushClipRectToVisitedPlatformViews:
 Pushes the outstanding rectangular clips to the mutator stack of each visited platform view.
 
(void) - pushClipRRectToVisitedPlatformViews:
 Pushes the outstanding rounded rectangular clips to the mutator stack of each visited platform view.
 
(void) - pushClipRSuperellipseToVisitedPlatformViews:
 Pushes the outstanding round super elliptical clips to the mutator stack of each visited platform view.
 
(void) - pushClipPathToVisitedPlatformViews:
 Pushes the outstanding path clips to the mutator stack of each visited platform view.
 
(size_t) - embeddedViewCount
 
(UIView *_Nullable) - platformViewForId:
 
(void) - compositeView:withParams:
 
(const flutter::EmbeddedViewParams &) - compositionParamsForView:
 
(NSArray< NSNumber * > *) - previousCompositionOrder
 The composition order from the previous frame.
 

Properties

FlutterFMLTaskRunnertaskRunner
 The task runner used to post rendering tasks to the platform thread.
 
UIView *_Nullable flutterView
 The flutter view.
 
UIViewController< FlutterViewResponder > *_Nullable flutterViewController
 The flutter view controller.
 

Detailed Description

Definition at line 31 of file FlutterPlatformViewsController.h.

Method Documentation

◆ beginFrameWithSize:

- (void) beginFrameWithSize: (flutter::DlISize frameSize

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

◆ 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 320 of file FlutterPlatformViewsController.mm.

505 {
506 [self resetFrameState];
507}

◆ 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 320 of file FlutterPlatformViewsController.mm.

791 :(int64_t)viewId {
792 FML_DCHECK(self.slices.find(viewId) != self.slices.end());
793 return self.slices[viewId]->canvas();
794}
#define FML_DCHECK(condition)
Definition logging.h:122

◆ compositeView:withParams:

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

◆ compositionParamsForView:

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

◆ embeddedViewCount

- (size_t) embeddedViewCount

◆ endFrameWithResubmit:threadMerger:

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

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 320 of file FlutterPlatformViewsController.mm.

514 :(BOOL)shouldResubmitFrame
515 threadMerger:(const fml::RefPtr<fml::RasterThreadMerger>&)rasterThreadMerger {
516}
int BOOL

◆ 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 320 of file FlutterPlatformViewsController.mm.

560 {
561 for (auto const& [id, platformViewData] : self.platformViews) {
562 UIView* rootView = platformViewData.root_view;
563 if (rootView.flt_hasFirstResponderInViewHierarchySubtree) {
564 return id;
565 }
566 }
567 return -1;
568}
const uintptr_t id

◆ flutterTouchInterceptingViewForId:

- (FlutterTouchInterceptingView *) flutterTouchInterceptingViewForId: (int64_t)  viewId

Returns theFlutterTouchInterceptingView 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 320 of file FlutterPlatformViewsController.mm.

553 :(int64_t)viewId {
554 if (self.platformViews.empty()) {
555 return nil;
556 }
557 return self.platformViews[viewId].touch_interceptor;
558}

◆ 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 320 of file FlutterPlatformViewsController.mm.

342 :(FlutterMethodCall*)call result:(FlutterResult)result {
343 if ([[call method] isEqualToString:@"create"]) {
344 [self onCreate:call result:result];
345 } else if ([[call method] isEqualToString:@"dispose"]) {
346 [self onDispose:call result:result];
347 } else if ([[call method] isEqualToString:@"acceptGesture"]) {
348 [self onAcceptGesture:call result:result];
349 } else if ([[call method] isEqualToString:@"rejectGesture"]) {
350 [self onRejectGesture:call result:result];
351 } else {
353 }
354}
void(^ FlutterResult)(id _Nullable result)
FLUTTER_DARWIN_EXPORT NSObject const * FlutterMethodNotImplemented
if(engine==nullptr)

◆ platformViewForId:

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

◆ postPrerollActionWithThreadMerger:

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

Determine if thread merging is required after prerolling platform views.

Called from the raster thread.

Definition at line 320 of file FlutterPlatformViewsController.mm.

◆ 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 320 of file FlutterPlatformViewsController.mm.

527 :(int64_t)viewId
528 withParams:(std::unique_ptr<flutter::EmbeddedViewParams>)params {
529 DlRect viewBounds = DlRect::MakeSize(self.frameSize);
530 std::unique_ptr<flutter::EmbedderViewSlice> view;
531 view = std::make_unique<flutter::DisplayListEmbedderViewSlice>(viewBounds);
532 self.slices.insert_or_assign(viewId, std::move(view));
533
534 self.compositionOrder.push_back(viewId);
535
536 if (self.currentCompositionParams.count(viewId) == 1 &&
537 self.currentCompositionParams[viewId] == *params.get()) {
538 // Do nothing if the params didn't change.
539 return;
540 }
541 self.currentCompositionParams[viewId] = flutter::EmbeddedViewParams(*params.get());
542 self.viewsToRecomposite.insert(viewId);
543}
const EmbeddedViewParams * params
FlView * view
impeller::Rect DlRect
Definition ref_ptr.h:261

◆ previousCompositionOrder

- (NSArray< NSNumber * > *) previousCompositionOrder

The composition order from the previous frame.

Only accessed from the platform thread.

Provided by category FlutterPlatformViewsController(Testing).

◆ pushClipPathToVisitedPlatformViews:

- (void) pushClipPathToVisitedPlatformViews: (const flutter::DlPath&)  clipPath

Pushes the outstanding path clips to the mutator stack of each visited platform view.

Definition at line 320 of file FlutterPlatformViewsController.mm.

1164 :(const flutter::DlPath&)clipPath {
1165 for (int64_t id : self.visitedPlatformViews) {
1166 flutter::EmbeddedViewParams params = self.currentCompositionParams[id];
1168 self.currentCompositionParams[id] = params;
1169 }
1170}
void PushPlatformViewClipPath(const DlPath &clip_path)

◆ pushClipRectToVisitedPlatformViews:

- (void) pushClipRectToVisitedPlatformViews: (const flutter::DlRect&)  clipRect

Pushes the outstanding rectangular clips to the mutator stack of each visited platform view.

Definition at line 320 of file FlutterPlatformViewsController.mm.

1140 :(const flutter::DlRect&)clipRect {
1141 for (int64_t id : self.visitedPlatformViews) {
1142 flutter::EmbeddedViewParams params = self.currentCompositionParams[id];
1144 self.currentCompositionParams[id] = params;
1145 }
1146}
void PushPlatformViewClipRect(const DlRect &clip_rect)

◆ pushClipRRectToVisitedPlatformViews:

- (void) pushClipRRectToVisitedPlatformViews: (const flutter::DlRoundRect&)  clipRRect

Pushes the outstanding rounded rectangular clips to the mutator stack of each visited platform view.

Definition at line 320 of file FlutterPlatformViewsController.mm.

1148 :(const flutter::DlRoundRect&)clipRRect {
1149 for (int64_t id : self.visitedPlatformViews) {
1150 flutter::EmbeddedViewParams params = self.currentCompositionParams[id];
1152 self.currentCompositionParams[id] = params;
1153 }
1154}
void PushPlatformViewClipRRect(const DlRoundRect &clip_rrect)

◆ pushClipRSuperellipseToVisitedPlatformViews:

- (void) pushClipRSuperellipseToVisitedPlatformViews: (const flutter::DlRoundSuperellipse&)  clipRse

Pushes the outstanding round super elliptical clips to the mutator stack of each visited platform view.

Definition at line 320 of file FlutterPlatformViewsController.mm.

1156 :(const flutter::DlRoundSuperellipse&)clipRse {
1157 for (int64_t id : self.visitedPlatformViews) {
1158 flutter::EmbeddedViewParams params = self.currentCompositionParams[id];
1160 self.currentCompositionParams[id] = params;
1161 }
1162}
void PushPlatformViewClipRSuperellipse(const DlRoundSuperellipse &clip_rse)

◆ pushFilterToVisitedPlatformViews:withRect:

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

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

Definition at line 320 of file FlutterPlatformViewsController.mm.

518 :(const std::shared_ptr<flutter::DlImageFilter>&)filter
519 withRect:(const flutter::DlRect&)filterRect {
520 for (int64_t id : self.visitedPlatformViews) {
521 flutter::EmbeddedViewParams params = self.currentCompositionParams[id];
522 params.PushImageFilter(filter, filterRect);
523 self.currentCompositionParams[id] = params;
524 }
525}
void PushImageFilter(const std::shared_ptr< DlImageFilter > &filter, const DlRect &filter_rect)

◆ 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 320 of file FlutterPlatformViewsController.mm.

1136 :(int64_t)viewId {
1137 self.visitedPlatformViews.push_back(viewId);
1138}

◆ 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 320 of file FlutterPlatformViewsController.mm.

490 :(NSObject<FlutterPlatformViewFactory>*)factory
491 withId:(NSString*)factoryId
492 gestureRecognizersBlockingPolicy:
493 (FlutterPlatformViewGestureRecognizersBlockingPolicy)gestureRecognizerBlockingPolicy {
494 std::string idString([factoryId UTF8String]);
495 FML_CHECK(self.factories.count(idString) == 0);
496 self.factories[idString] = factory;
497 self.gestureRecognizersBlockingPoliciesByType[idString] = gestureRecognizerBlockingPolicy;
498}
FlutterPlatformViewGestureRecognizersBlockingPolicy
#define FML_CHECK(condition)
Definition logging.h:104

◆ reset

- (void) reset

Discards all platform views instances and auxiliary resources.

Called from the raster thread.

Definition at line 320 of file FlutterPlatformViewsController.mm.

796 {
797 // Reset will only be called from the raster thread or a merged raster/platform thread.
798 // _platformViews must only be modified on the platform thread, and any operations that
799 // read or modify platform views should occur there.
800 std::vector<int64_t> compositionOrder = self.compositionOrder;
801 [self.taskRunner runNowOrPostTask:^{
802 for (int64_t viewId : compositionOrder) {
803 [self.platformViews[viewId].root_view removeFromSuperview];
804 }
805 self.platformViews.clear();
806 _previousCompositionOrder.clear();
807 }];
808
809 self.compositionOrder.clear();
810 self.slices.clear();
811 self.currentCompositionParams.clear();
812 self.viewsToRecomposite.clear();
813 self.layerPool->RecycleLayers();
814 self.visitedPlatformViews.clear();
815}

◆ submitFrame:withIosContext:

- (BOOL) submitFrame: (std::unique_ptr<flutter::SurfaceFrame>)  frame
withIosContext: (const std::shared_ptr<flutter::IOSContext>&)  iosContext 

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

Called from the raster thread.

Definition at line 320 of file FlutterPlatformViewsController.mm.

817 :(std::unique_ptr<flutter::SurfaceFrame>)background_frame
818 withIosContext:(const std::shared_ptr<flutter::IOSContext>&)iosContext {
819 TRACE_EVENT0("flutter", "PlatformViewsController::SubmitFrame");
820
821 // No platform views to render.
822 if (self.flutterView == nil || (self.compositionOrder.empty() && !self.hadPlatformViews)) {
823 // No platform views to render but the FlutterView may need to be resized.
824 __weak FlutterPlatformViewsController* weakSelf = self;
825 if (self.flutterView != nil) {
826 // Pass frameSize by value since self.frameSize is mutated both here (on the platform
827 // thread) and in beginFrameWithSize: (on the raster thread).
828 const flutter::DlISize frameSize = self.frameSize;
829 [self.taskRunner runNowOrPostTask:^{
830 FlutterPlatformViewsController* strongSelf = weakSelf;
831 if (!strongSelf) {
832 return;
833 }
834 [strongSelf performResize:frameSize];
835 }];
836 }
837
838 self.hadPlatformViews = NO;
839 return background_frame->Submit();
840 }
841 self.hadPlatformViews = !self.compositionOrder.empty();
842
843 bool didEncode = true;
844 LayersMap platformViewLayers;
845 std::vector<std::unique_ptr<flutter::SurfaceFrame>> surfaceFrames;
846 surfaceFrames.reserve(self.compositionOrder.size());
847 std::unordered_map<int64_t, DlRect> viewRects;
848 std::unordered_set<int64_t> viewsWithUnderlayPreserved;
849
850 for (int64_t viewId : self.compositionOrder) {
851 const flutter::EmbeddedViewParams& params = self.currentCompositionParams[viewId];
852 viewRects[viewId] = params.finalBoundingRect();
854 viewsWithUnderlayPreserved.insert(viewId);
855 }
856 }
857
858 std::unordered_map<int64_t, DlRect> overlayLayers =
859 SliceViews(background_frame->Canvas(), self.compositionOrder, self.slices, viewRects,
860 viewsWithUnderlayPreserved);
861
862 size_t requiredOverlayLayers = 0;
863 for (int64_t viewId : self.compositionOrder) {
864 std::unordered_map<int64_t, DlRect>::const_iterator overlay = overlayLayers.find(viewId);
865 if (overlay == overlayLayers.end()) {
866 continue;
867 }
868 requiredOverlayLayers++;
869 }
870
871 // If there are not sufficient overlay layers, we must construct them on the platform
872 // thread, at least until we've refactored iOS surface creation to use IOSurfaces
873 // instead of CALayers.
874 [self createMissingOverlays:requiredOverlayLayers withIosContext:iosContext];
875
876 int64_t overlayId = 0;
877 for (int64_t viewId : self.compositionOrder) {
878 std::unordered_map<int64_t, DlRect>::const_iterator overlay = overlayLayers.find(viewId);
879 if (overlay == overlayLayers.end()) {
880 continue;
881 }
882 std::shared_ptr<flutter::OverlayLayer> layer = self.nextLayerInPool;
883 if (!layer) {
884 continue;
885 }
886
887 std::unique_ptr<flutter::SurfaceFrame> frame = layer->surface->AcquireFrame(self.frameSize);
888 // If frame is null, AcquireFrame already printed out an error message.
889 if (!frame) {
890 continue;
891 }
892 flutter::DlCanvas* overlayCanvas = frame->Canvas();
893 int restoreCount = overlayCanvas->GetSaveCount();
894 overlayCanvas->Save();
895 overlayCanvas->ClipRect(overlay->second);
896 if (viewsWithUnderlayPreserved.find(viewId) != viewsWithUnderlayPreserved.end()) {
897 ApplyNonRectClipToOverlayCanvas(overlayCanvas, self.currentCompositionParams[viewId]);
898 }
899 overlayCanvas->Clear(flutter::DlColor::kTransparent());
900 self.slices[viewId]->render_into(overlayCanvas);
901 overlayCanvas->RestoreToCount(restoreCount);
902
903 // This flutter view is never the last in a frame, since we always submit the
904 // underlay view last.
905 frame->set_submit_info({.frame_boundary = false, .present_with_transaction = true});
906 layer->did_submit_last_frame = frame->Encode();
907
908 didEncode &= layer->did_submit_last_frame;
909 platformViewLayers[viewId] = LayerData{
910 .rect = overlay->second, //
911 .view_id = viewId, //
912 .overlay_id = overlayId, //
913 .layer = layer //
914 };
915 surfaceFrames.push_back(std::move(frame));
916 overlayId++;
917 }
918
919 auto previousSubmitInfo = background_frame->submit_info();
920 background_frame->set_submit_info({
921 .frame_damage = previousSubmitInfo.frame_damage,
922 .buffer_damage = previousSubmitInfo.buffer_damage,
923 .present_with_transaction = true,
924 });
925 background_frame->Encode();
926 surfaceFrames.push_back(std::move(background_frame));
927
928 // Mark all layers as available, so they can be used in the next frame.
929 std::vector<std::shared_ptr<flutter::OverlayLayer>> unusedLayers =
930 self.layerPool->RemoveUnusedLayers();
931 self.layerPool->RecycleLayers();
932 auto task = fml::MakeCopyable([self, //
933 platformViewLayers = std::move(platformViewLayers), //
934 currentCompositionParams = self.currentCompositionParams, //
935 viewsToRecomposite = self.viewsToRecomposite, //
936 compositionOrder = self.compositionOrder, //
937 unusedLayers = std::move(unusedLayers), //
938 surfaceFrames = std::move(surfaceFrames)]() mutable {
939 [self performSubmit:platformViewLayers
940 currentCompositionParams:currentCompositionParams
941 viewsToRecomposite:viewsToRecomposite
942 compositionOrder:compositionOrder
943 unusedLayers:unusedLayers
944 surfaceFrames:surfaceFrames];
945 });
946
947 [self.taskRunner runNowOrPostTask:^{
948 task();
949 }];
950 return didEncode;
951}
static bool HasNonRectClipForUnderlayCutout(const flutter::EmbeddedViewParams &params)
std::unordered_map< int64_t, LayerData > LayersMap
static void ApplyNonRectClipToOverlayCanvas(flutter::DlCanvas *overlay_canvas, const flutter::EmbeddedViewParams &params)
Developer-facing API for rendering anything within the engine.
Definition dl_canvas.h:32
virtual void ClipRect(const DlRect &rect, DlClipOp clip_op=DlClipOp::kIntersect, bool is_aa=false)=0
virtual int GetSaveCount() const =0
virtual void RestoreToCount(int restore_count)=0
void Clear(DlColor color)
Definition dl_canvas.h:104
virtual void Save()=0
const DlRect & finalBoundingRect() const
UIView *_Nullable flutterView
The flutter view.
std::unordered_map< int64_t, DlRect > SliceViews(DlCanvas *background_canvas, const std::vector< int64_t > &composition_order, const std::unordered_map< int64_t, std::unique_ptr< EmbedderViewSlice > > &slices, const std::unordered_map< int64_t, DlRect > &view_rects, const std::unordered_set< int64_t > &views_with_underlay_preserved)
Compute the required overlay layers and clip the view slices according to the size and position of th...
internal::CopyableLambda< T > MakeCopyable(T lambda)
static constexpr DlColor kTransparent()
Definition dl_color.h:68
#define TRACE_EVENT0(category_group, name)

Property Documentation

◆ flutterView

- (UIView* _Nullable) flutterView
readwritenonatomicweak

The flutter view.

Definition at line 39 of file FlutterPlatformViewsController.h.

◆ flutterViewController

- (UIViewController<FlutterViewResponder>* _Nullable) flutterViewController
readwritenonatomicweak

The flutter view controller.

Definition at line 42 of file FlutterPlatformViewsController.h.

◆ taskRunner

- (FlutterFMLTaskRunner *) taskRunner
readwritenonatomicstrong

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

Definition at line 36 of file FlutterPlatformViewsController.h.

Referenced by flutter::testing::CreateTestPlatformViewsController().


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