| 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:(SkISize)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 SkRect&)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 @end
118
119 @interface FlutterPlatformViewsController (Testing)
120
121 - (size_t)embeddedViewCount;
122
123 // Returns the `FlutterPlatformView`'s `view` object associated with the view_id.
124 //
125 // If the `PlatformViewsController` does not contain any `FlutterPlatformView` object or
126 // a `FlutterPlatformView` object associated with the view_id cannot be found, the method
127 // returns nil.
128 - (UIView* _Nullable)platformViewForId:(int64_t)viewId;
129
130 // Composite the PlatformView with `viewId`.
131 //
132 // Every frame, during the paint traversal of the layer tree, this method is called for all
133 // the PlatformViews in `_viewsToRecomposite`.
134 //
135 // Note that `_viewsToRecomposite` does not represent all the views in the view hierarchy,
136 // if a PlatformView does not change its composition parameter from last frame, it is not
137 // included in the `views_to_recomposite_`.
138 - (void)compositeView:(int64_t)viewId withParams:(const flutter::EmbeddedViewParams&)params;
139
140 - (const flutter::EmbeddedViewParams&)compositionParamsForView:(int64_t)viewId;
141
142 - (std::vector<int64_t>&)previousCompositionOrder;
143
144 @end
145
146 NS_ASSUME_NONNULL_END
147
148 #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:252
FlutterViewResponder.h
FlutterPlatformViewsController(Testing)
Definition: FlutterPlatformViewsController.h:119
FlutterClippingMaskViewPool
Definition: FlutterPlatformViews.mm:456
FlutterTouchInterceptingView
Definition: FlutterPlatformViews.mm:513
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:646
-[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:467
-[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:412
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