Flutter iOS Embedder
FlutterPlatformViewsController.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERPLATFORMVIEWSCONTROLLER_H_
6 #define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERPLATFORMVIEWSCONTROLLER_H_
7 
8 #include <Metal/Metal.h>
9 #include <memory>
10 #include <unordered_map>
11 #include <unordered_set>
12 
13 #include "flutter/flow/surface.h"
14 #include "flutter/fml/task_runner.h"
15 #include "flutter/fml/trace_event.h"
16 #include "impeller/base/thread_safety.h"
17 #include "third_party/skia/include/core/SkRect.h"
18 
25 
27 
30 
31 @interface FlutterPlatformViewsController : NSObject
32 
33 - (instancetype)init NS_DESIGNATED_INITIALIZER;
34 
35 /// The task runner used to post rendering tasks to the platform thread.
36 @property(nonatomic, assign) const fml::RefPtr<fml::TaskRunner>& taskRunner;
37 
38 /// The flutter view.
39 @property(nonatomic, weak) UIView* _Nullable flutterView;
40 
41 /// @brief The flutter view controller.
42 @property(nonatomic, weak) UIViewController<FlutterViewResponder>* _Nullable flutterViewController;
43 
44 /// @brief set the factory used to construct embedded UI Views.
45 - (void)registerViewFactory:(NSObject<FlutterPlatformViewFactory>*)factory
46  withId:(NSString*)factoryId
47  gestureRecognizersBlockingPolicy:
48  (FlutterPlatformViewGestureRecognizersBlockingPolicy)gestureRecognizerBlockingPolicy;
49 
50 /// @brief Mark the beginning of a frame and record the size of the onscreen.
51 - (void)beginFrameWithSize:(SkISize)frameSize;
52 
53 /// @brief Cancel the current frame, indicating that no platform views are composited.
54 ///
55 /// Additionally, reverts the composition order to its original state at the beginning of the
56 /// frame.
57 - (void)cancelFrame;
58 
59 /// @brief Record a platform view in the layer tree to be rendered, along with the positioning and
60 /// mutator parameters.
61 ///
62 /// Called from the raster thread.
63 - (void)prerollCompositeEmbeddedView:(int64_t)viewId
64  withParams:(std::unique_ptr<flutter::EmbeddedViewParams>)params;
65 
66 /// @brief Returns the`FlutterTouchInterceptingView` with the provided view_id.
67 ///
68 /// Returns nil if there is no platform view with the provided id. Called
69 /// from the platform thread.
70 - (FlutterTouchInterceptingView*)flutterTouchInterceptingViewForId:(int64_t)viewId;
71 
72 /// @brief Determine if thread merging is required after prerolling platform views.
73 ///
74 /// Called from the raster thread.
75 - (flutter::PostPrerollResult)postPrerollActionWithThreadMerger:
76  (const fml::RefPtr<fml::RasterThreadMerger>&)rasterThreadMerger
77  impellerEnabled:(BOOL)impellerEnabled;
78 
79 /// @brief Mark the end of a compositor frame.
80 ///
81 /// May determine changes are required to the thread merging state.
82 /// Called from the raster thread.
83 - (void)endFrameWithResubmit:(BOOL)shouldResubmitFrame
84  threadMerger:(const fml::RefPtr<fml::RasterThreadMerger>&)rasterThreadMerger
85  impellerEnabled:(BOOL)impellerEnabled;
86 
87 /// @brief Returns the Canvas for the overlay slice for the given platform view.
88 ///
89 /// Called from the raster thread.
90 - (flutter::DlCanvas*)compositeEmbeddedViewWithId:(int64_t)viewId;
91 
92 /// @brief Discards all platform views instances and auxiliary resources.
93 ///
94 /// Called from the raster thread.
95 - (void)reset;
96 
97 /// @brief Encode rendering for the Flutter overlay views and queue up perform platform view
98 /// mutations.
99 ///
100 /// Called from the raster thread.
101 - (BOOL)submitFrame:(std::unique_ptr<flutter::SurfaceFrame>)frame
102  withIosContext:(const std::shared_ptr<flutter::IOSContext>&)iosContext
103  grContext:(GrDirectContext* _Nullable)grContext;
104 
105 /// @brief Handler for platform view message channels.
106 - (void)onMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result;
107 
108 /// @brief Returns the platform view id if the platform view (or any of its descendant view) is
109 /// the first responder.
110 ///
111 /// Returns -1 if no such platform view is found.
113 
114 /// @brief Pushes backdrop filter mutation to the mutator stack of each visited platform view.
115 - (void)pushFilterToVisitedPlatformViews:(const std::shared_ptr<flutter::DlImageFilter>&)filter
116  withRect:(const SkRect&)filterRect;
117 
118 /// @brief Pushes the view id of a visted platform view to the list of visied platform views.
119 - (void)pushVisitedPlatformViewId:(int64_t)viewId;
120 
121 @end
122 
124 
125 - (size_t)embeddedViewCount;
126 
127 // Returns the `FlutterPlatformView`'s `view` object associated with the view_id.
128 //
129 // If the `PlatformViewsController` does not contain any `FlutterPlatformView` object or
130 // a `FlutterPlatformView` object associated with the view_id cannot be found, the method
131 // returns nil.
132 - (UIView* _Nullable)platformViewForId:(int64_t)viewId;
133 
134 // Composite the PlatformView with `viewId`.
135 //
136 // Every frame, during the paint traversal of the layer tree, this method is called for all
137 // the PlatformViews in `_viewsToRecomposite`.
138 //
139 // Note that `_viewsToRecomposite` does not represent all the views in the view hierarchy,
140 // if a PlatformView does not change its composition parameter from last frame, it is not
141 // included in the `views_to_recomposite_`.
142 - (void)compositeView:(int64_t)viewId withParams:(const flutter::EmbeddedViewParams&)params;
143 
144 - (const flutter::EmbeddedViewParams&)compositionParamsForView:(int64_t)viewId;
145 
146 @end
147 
149 
150 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERPLATFORMVIEWSCONTROLLER_H_
FlutterPlatformViews.h
-[FlutterPlatformViewsController cancelFrame]
void cancelFrame()
Cancel the current frame, indicating that no platform views are composited.
Definition: FlutterPlatformViewsController.mm:452
NS_ASSUME_NONNULL_END
#define NS_ASSUME_NONNULL_END
Definition: FlutterMacros.h:20
FlutterChannels.h
NS_ASSUME_NONNULL_BEGIN
#define NS_ASSUME_NONNULL_BEGIN
Definition: FlutterMacros.h:19
FlutterPlugin.h
FlutterClippingMaskViewPool
Definition: FlutterPlatformViews.mm:464
-[FlutterPlatformViewsController NS_DESIGNATED_INITIALIZER]
instancetype NS_DESIGNATED_INITIALIZER()
FlutterViewResponder.h
FlutterMethodCall
Definition: FlutterCodecs.h:220
FlutterPlatformViewsController(Testing)
Definition: FlutterPlatformViewsController.h:123
flutter
Definition: accessibility_bridge.h:27
-[FlutterPlatformViewsController reset]
void reset()
Discards all platform views instances and auxiliary resources.
Definition: FlutterPlatformViewsController.mm:712
FlutterPlatformViewsController::flutterView
UIView *_Nullable flutterView
The flutter view.
Definition: FlutterPlatformViewsController.h:39
FlutterResult
void(^ FlutterResult)(id _Nullable result)
Definition: FlutterChannels.h:194
fml
Definition: profiler_metrics_ios.mm:41
FlutterPlatformViewGestureRecognizersBlockingPolicy
FlutterPlatformViewGestureRecognizersBlockingPolicy
Definition: FlutterPlugin.h:252
FlutterPlatformViewFactory-p
Definition: FlutterPlatformViews.h:26
overlay_layer_pool.h
FlutterPlatformViewsController
Definition: FlutterPlatformViewsController.h:31
FlutterPlatformViewsController::flutterViewController
UIViewController< FlutterViewResponder > *_Nullable flutterViewController
The flutter view controller.
Definition: FlutterPlatformViewsController.h:42
FlutterTouchInterceptingView
Definition: FlutterPlatformViews.mm:521
ios_context.h
-[FlutterPlatformViewsController firstResponderPlatformViewId]
long firstResponderPlatformViewId()
Returns the platform view id if the platform view (or any of its descendant view) is the first respon...
Definition: FlutterPlatformViewsController.mm:546
FlutterPlatformViewsController::taskRunner
const fml::RefPtr< fml::TaskRunner > & taskRunner
The task runner used to post rendering tasks to the platform thread.
Definition: FlutterPlatformViewsController.h:36