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::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.

780 :(int64_t)viewId {
781 FML_DCHECK(self.slices.find(viewId) != self.slices.end());
782 return self.slices[viewId]->canvas();
783}
#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

◆ 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.

551 {
552 for (auto const& [id, platformViewData] : self.platformViews) {
553 UIView* rootView = platformViewData.root_view;
554 if (rootView.flt_hasFirstResponderInViewHierarchySubtree) {
555 return id;
556 }
557 }
558 return -1;
559}
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.

544 :(int64_t)viewId {
545 if (self.platformViews.empty()) {
546 return nil;
547 }
548 return self.platformViews[viewId].touch_interceptor;
549}

◆ 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

◆ 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.

518 :(int64_t)viewId
519 withParams:(std::unique_ptr<flutter::EmbeddedViewParams>)params {
520 DlRect viewBounds = DlRect::MakeSize(self.frameSize);
521 std::unique_ptr<flutter::EmbedderViewSlice> view;
522 view = std::make_unique<flutter::DisplayListEmbedderViewSlice>(viewBounds);
523 self.slices.insert_or_assign(viewId, std::move(view));
524
525 self.compositionOrder.push_back(viewId);
526
527 if (self.currentCompositionParams.count(viewId) == 1 &&
528 self.currentCompositionParams[viewId] == *params.get()) {
529 // Do nothing if the params didn't change.
530 return;
531 }
532 self.currentCompositionParams[viewId] = flutter::EmbeddedViewParams(*params.get());
533 self.viewsToRecomposite.insert(viewId);
534}
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.

1153 :(const flutter::DlPath&)clipPath {
1154 for (int64_t id : self.visitedPlatformViews) {
1155 flutter::EmbeddedViewParams params = self.currentCompositionParams[id];
1157 self.currentCompositionParams[id] = params;
1158 }
1159}
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.

1129 :(const flutter::DlRect&)clipRect {
1130 for (int64_t id : self.visitedPlatformViews) {
1131 flutter::EmbeddedViewParams params = self.currentCompositionParams[id];
1133 self.currentCompositionParams[id] = params;
1134 }
1135}
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.

1137 :(const flutter::DlRoundRect&)clipRRect {
1138 for (int64_t id : self.visitedPlatformViews) {
1139 flutter::EmbeddedViewParams params = self.currentCompositionParams[id];
1141 self.currentCompositionParams[id] = params;
1142 }
1143}
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.

1145 :(const flutter::DlRoundSuperellipse&)clipRse {
1146 for (int64_t id : self.visitedPlatformViews) {
1147 flutter::EmbeddedViewParams params = self.currentCompositionParams[id];
1149 self.currentCompositionParams[id] = params;
1150 }
1151}
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.

509 :(const std::shared_ptr<flutter::DlImageFilter>&)filter
510 withRect:(const flutter::DlRect&)filterRect {
511 for (int64_t id : self.visitedPlatformViews) {
512 flutter::EmbeddedViewParams params = self.currentCompositionParams[id];
513 params.PushImageFilter(filter, filterRect);
514 self.currentCompositionParams[id] = params;
515 }
516}
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.

1125 :(int64_t)viewId {
1126 self.visitedPlatformViews.push_back(viewId);
1127}

◆ 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.

785 {
786 // Reset will only be called from the raster thread or a merged raster/platform thread.
787 // _platformViews must only be modified on the platform thread, and any operations that
788 // read or modify platform views should occur there.
789 std::vector<int64_t> compositionOrder = self.compositionOrder;
790 [self.taskRunner runNowOrPostTask:^{
791 for (int64_t viewId : compositionOrder) {
792 [self.platformViews[viewId].root_view removeFromSuperview];
793 }
794 self.platformViews.clear();
795 _previousCompositionOrder.clear();
796 }];
797
798 self.compositionOrder.clear();
799 self.slices.clear();
800 self.currentCompositionParams.clear();
801 self.viewsToRecomposite.clear();
802 self.layerPool->RecycleLayers();
803 self.visitedPlatformViews.clear();
804}

◆ 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.

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