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 
24 
26 
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.
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 
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 
163 
164 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERPLATFORMVIEWSCONTROLLER_H_
void(^ FlutterResult)(id _Nullable result)
#define NS_ASSUME_NONNULL_BEGIN
Definition: FlutterMacros.h:19
#define NS_ASSUME_NONNULL_END
Definition: FlutterMacros.h:20
FlutterPlatformViewGestureRecognizersBlockingPolicy
void reset()
Discards all platform views instances and auxiliary resources.
long firstResponderPlatformViewId()
Returns the platform view id if the platform view (or any of its descendant view) is the first respon...
instancetype NS_DESIGNATED_INITIALIZER()
const fml::RefPtr< fml::TaskRunner > & taskRunner
The task runner used to post rendering tasks to the platform thread.
UIViewController< FlutterViewResponder > *_Nullable flutterViewController
The flutter view controller.
void cancelFrame()
Cancel the current frame, indicating that no platform views are composited.
UIView *_Nullable flutterView
The flutter view.