| 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
18 #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h"
19 #import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlatformViews.h"
20 #import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h"
21 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewResponder.h"
22 #import "flutter/shell/platform/darwin/ios/framework/Source/overlay_layer_pool.h"
23 #import "flutter/shell/platform/darwin/ios/ios_context.h"
24
25 NS_ASSUME_NONNULL_BEGIN
26
27 @class FlutterTouchInterceptingView;
28 @class FlutterClippingMaskViewPool;
29
30 @interface FlutterPlatformViewsController : NSObject
31
32 - (instancetype)init NS_DESIGNATED_INITIALIZER;
33
34 /// The task runner used to post rendering tasks to the platform thread.
35 @property(nonatomic, assign) const fml::RefPtr<fml::TaskRunner>& taskRunner;
36
37 /// The flutter view.
38 @property(nonatomic, weak) UIView* _Nullable flutterView;
39
40 /// @brief The flutter view controller.
41 @property(nonatomic, weak) UIViewController<FlutterViewResponder>* _Nullable flutterViewController;
42
43 /// @brief set the factory used to construct embedded UI Views.
44 - (void)registerViewFactory:(NSObject<FlutterPlatformViewFactory>*)factory
45 withId:(NSString*)factoryId
46 gestureRecognizersBlockingPolicy:
47 (FlutterPlatformViewGestureRecognizersBlockingPolicy)gestureRecognizerBlockingPolicy;
48
49 /// @brief Mark the beginning of a frame and record the size of the onscreen.
50 - (void)beginFrameWithSize:(flutter::DlISize)frameSize;
51
52 /// @brief Cancel the current frame, indicating that no platform views are composited.
53 ///
54 /// Additionally, reverts the composition order to its original state at the beginning of the
55 /// frame.
56 - (void)cancelFrame;
57
58 /// @brief Record a platform view in the layer tree to be rendered, along with the positioning and
59 /// mutator parameters.
60 ///
61 /// Called from the raster thread.
62 - (void)prerollCompositeEmbeddedView:(int64_t)viewId
63 withParams:(std::unique_ptr<flutter::EmbeddedViewParams>)params;
64
65 /// @brief Returns the`FlutterTouchInterceptingView` with the provided view_id.
66 ///
67 /// Returns nil if there is no platform view with the provided id. Called
68 /// from the platform thread.
69 - (FlutterTouchInterceptingView*)flutterTouchInterceptingViewForId:(int64_t)viewId;
70
71 /// @brief Determine if thread merging is required after prerolling platform views.
72 ///
73 /// Called from the raster thread.
74 - (flutter::PostPrerollResult)postPrerollActionWithThreadMerger:
75 (const fml::RefPtr<fml::RasterThreadMerger>&)rasterThreadMerger;
76
77 /// @brief Mark the end of a compositor frame.
78 ///
79 /// May determine changes are required to the thread merging state.
80 /// Called from the raster thread.
81 - (void)endFrameWithResubmit:(BOOL)shouldResubmitFrame
82 threadMerger:(const fml::RefPtr<fml::RasterThreadMerger>&)rasterThreadMerger;
83
84 /// @brief Returns the Canvas for the overlay slice for the given platform view.
85 ///
86 /// Called from the raster thread.
87 - (flutter::DlCanvas*)compositeEmbeddedViewWithId:(int64_t)viewId;
88
89 /// @brief Discards all platform views instances and auxiliary resources.
90 ///
91 /// Called from the raster thread.
92 - (void)reset;
93
94 /// @brief Encode rendering for the Flutter overlay views and queue up perform platform view
95 /// mutations.
96 ///
97 /// Called from the raster thread.
98 - (BOOL)submitFrame:(std::unique_ptr<flutter::SurfaceFrame>)frame
99 withIosContext:(const std::shared_ptr<flutter::IOSContext>&)iosContext;
100
101 /// @brief Handler for platform view message channels.
102 - (void)onMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result;
103
104 /// @brief Returns the platform view id if the platform view (or any of its descendant view) is
105 /// the first responder.
106 ///
107 /// Returns -1 if no such platform view is found.
108 - (long)firstResponderPlatformViewId;
109
110 /// @brief Pushes backdrop filter mutation to the mutator stack of each visited platform view.
111 - (void)pushFilterToVisitedPlatformViews:(const std::shared_ptr<flutter::DlImageFilter>&)filter
112 withRect:(const flutter::DlRect&)filterRect;
113
114 /// @brief Pushes the view id of a visted platform view to the list of visied platform views.
115 - (void)pushVisitedPlatformViewId:(int64_t)viewId;
116
117 /// @brief Pushes the outstanding rectangular clips to the mutator stack of each visited platform
118 /// view
119 - (void)pushClipRectToVisitedPlatformViews:(const flutter::DlRect&)clipRect;
120
121 /// @brief Pushes the outstanding rounded rectangular clips to the mutator stack of each visited
122 /// platform view
123 - (void)pushClipRRectToVisitedPlatformViews:(const flutter::DlRoundRect&)clipRRect;
124
125 /// @brief Pushes the outstanding round super elliptical clips to the mutator stack of each visited
126 /// platform view
127 - (void)pushClipRSuperellipseToVisitedPlatformViews:(const flutter::DlRoundSuperellipse&)clipRse;
128
129 /// @brief Pushes the outstanding path clips to the mutator stack of each visited platform
130 /// view
131 - (void)pushClipPathToVisitedPlatformViews:(const flutter::DlPath&)clipPath;
132
133 @end
134
135 @interface FlutterPlatformViewsController (Testing)
136
137 - (size_t)embeddedViewCount;
138
139 // Returns the `FlutterPlatformView`'s `view` object associated with the view_id.
140 //
141 // If the `PlatformViewsController` does not contain any `FlutterPlatformView` object or
142 // a `FlutterPlatformView` object associated with the view_id cannot be found, the method
143 // returns nil.
144 - (UIView* _Nullable)platformViewForId:(int64_t)viewId;
145
146 // Composite the PlatformView with `viewId`.
147 //
148 // Every frame, during the paint traversal of the layer tree, this method is called for all
149 // the PlatformViews in `_viewsToRecomposite`.
150 //
151 // Note that `_viewsToRecomposite` does not represent all the views in the view hierarchy,
152 // if a PlatformView does not change its composition parameter from last frame, it is not
153 // included in the `views_to_recomposite_`.
154 - (void)compositeView:(int64_t)viewId withParams:(const flutter::EmbeddedViewParams&)params;
155
156 - (const flutter::EmbeddedViewParams&)compositionParamsForView:(int64_t)viewId;
157
158 - (std::vector<int64_t>&)previousCompositionOrder;
159
160 @end
161
162 NS_ASSUME_NONNULL_END
163
164 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERPLATFORMVIEWSCONTROLLER_H_
FlutterChannels.h
FlutterResult
void(^ FlutterResult)(id _Nullable result)
Definition: FlutterChannels.h:194
NS_ASSUME_NONNULL_BEGIN
#define NS_ASSUME_NONNULL_BEGIN
Definition: FlutterMacros.h:19
NS_ASSUME_NONNULL_END
#define NS_ASSUME_NONNULL_END
Definition: FlutterMacros.h:20
FlutterPlatformViews.h
FlutterPlugin.h
FlutterPlatformViewGestureRecognizersBlockingPolicy
FlutterPlatformViewGestureRecognizersBlockingPolicy
Definition: FlutterPlugin.h:253
FlutterViewResponder.h
FlutterPlatformViewsController(Testing)
Definition: FlutterPlatformViewsController.h:135
FlutterClippingMaskViewPool
Definition: FlutterPlatformViews.mm:461
FlutterTouchInterceptingView
Definition: FlutterPlatformViews.mm:518
FlutterMethodCall
Definition: FlutterCodecs.h:221
FlutterPlatformViewsController
Definition: FlutterPlatformViewsController.h:31
-[FlutterPlatformViewsController reset]
void reset()
Discards all platform views instances and auxiliary resources.
Definition: FlutterPlatformViewsController.mm:685
-[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:468
-[FlutterPlatformViewsController NS_DESIGNATED_INITIALIZER]
instancetype NS_DESIGNATED_INITIALIZER()
FlutterPlatformViewsController::taskRunner
const fml::RefPtr< fml::TaskRunner > & taskRunner
The task runner used to post rendering tasks to the platform thread.
Definition: FlutterPlatformViewsController.h:35
FlutterPlatformViewsController::flutterViewController
UIViewController< FlutterViewResponder > *_Nullable flutterViewController
The flutter view controller.
Definition: FlutterPlatformViewsController.h:41
-[FlutterPlatformViewsController cancelFrame]
void cancelFrame()
Cancel the current frame, indicating that no platform views are composited.
Definition: FlutterPlatformViewsController.mm:413
FlutterPlatformViewsController::flutterView
UIView *_Nullable flutterView
The flutter view.
Definition: FlutterPlatformViewsController.h:38
ios_context.h
flutter
Definition: accessibility_bridge.h:26
fml
Definition: profiler_metrics_ios.mm:41
overlay_layer_pool.h
FlutterPlatformViewFactory-p
Definition: FlutterPlatformViews.h:26