| Flutter iOS Embedder |

platform_view_ios.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_PLATFORM_VIEW_IOS_H_
6 #define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_PLATFORM_VIEW_IOS_H_
7
8 #include <memory>
9
10 #include "flutter/fml/closure.h"
11 #include "flutter/fml/macros.h"
12 #include "flutter/shell/common/platform_view.h"
13 #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterTexture.h"
14 #import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"
15 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h"
16 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h"
17 #import "flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h"
18 #import "flutter/shell/platform/darwin/ios/ios_context.h"
19 #import "flutter/shell/platform/darwin/ios/ios_external_view_embedder.h"
20 #import "flutter/shell/platform/darwin/ios/ios_surface.h"
21 #import "flutter/shell/platform/darwin/ios/platform_message_handler_ios.h"
22 #import "flutter/shell/platform/darwin/ios/rendering_api_selection.h"
23
24 @class FlutterViewController;
25
26 namespace flutter {
27
28 /**
29 * A bridge connecting the platform agnostic shell and the iOS embedding.
30 *
31 * The shell provides and requests for UI related data and this PlatformView subclass fulfills
32 * it with iOS specific capabilities. As an example, the iOS embedding (the `FlutterEngine` and the
33 * `FlutterViewController`) sends pointer data to the shell and receives the shell's request for a
34 * Impeller AiksContext and supplies it.
35 *
36 * Despite the name "view", this class is unrelated to UIViews on iOS and doesn't have the same
37 * lifecycle. It's a long lived bridge owned by the `FlutterEngine` and can be attached and
38 * detached sequentially to multiple `FlutterViewController`s and `FlutterView`s.
39 */
40 class PlatformViewIOS final : public PlatformView {
41 public:
42 PlatformViewIOS(PlatformView::Delegate& delegate,
43 const std::shared_ptr<IOSContext>& context,
44 __weak FlutterPlatformViewsController* platform_views_controller,
45 const flutter::TaskRunners& task_runners);
46
47 explicit PlatformViewIOS(
48 PlatformView::Delegate& delegate,
49 IOSRenderingAPI rendering_api,
50 __weak FlutterPlatformViewsController* platform_views_controller,
51 const flutter::TaskRunners& task_runners,
52 const std::shared_ptr<fml::ConcurrentTaskRunner>& worker_task_runner,
53 const std::shared_ptr<const fml::SyncSwitch>& is_gpu_disabled_sync_switch);
54
55 ~PlatformViewIOS() override;
56
57 /**
58 * Returns the `FlutterViewController` currently attached to the `FlutterEngine` owning
59 * this PlatformViewIOS.
60 */
61 FlutterViewController* GetOwnerViewController() const __attribute__((cf_audited_transfer));
62
63 /**
64 * Updates the `FlutterViewController` currently attached to the `FlutterEngine` owning
65 * this PlatformViewIOS. This should be updated when the `FlutterEngine`
66 * is given a new `FlutterViewController`.
67 */
68 void SetOwnerViewController(__weak FlutterViewController* owner_controller);
69
70 /**
71 * Called one time per `FlutterViewController` when the `FlutterViewController`'s
72 * UIView is first loaded.
73 *
74 * Can be used to perform late initialization after `FlutterViewController`'s
75 * init.
76 */
77 void attachView();
78
79 /**
80 * Called through when an external texture such as video or camera is
81 * given to the `FlutterEngine` or `FlutterViewController`.
82 */
83 void RegisterExternalTexture(int64_t id, NSObject<FlutterTexture>* texture);
84
85 // |PlatformView|
86 PointerDataDispatcherMaker GetDispatcherMaker() override;
87
88 // |PlatformView|
89 void SetSemanticsEnabled(bool enabled) override;
90
91 // |PlatformView|
92 void SetSemanticsTreeEnabled(bool enabled) override;
93
94 // |PlatformView|
95 void HandlePlatformMessage(std::unique_ptr<flutter::PlatformMessage> message) override;
96
97 // |PlatformView|
98 std::unique_ptr<Surface> CreateRenderingSurface() override;
99
100 // |PlatformView|
101 std::shared_ptr<ExternalViewEmbedder> CreateExternalViewEmbedder() override;
102
103 // |PlatformView|
104 std::shared_ptr<impeller::Context> GetImpellerContext() const override;
105
106 // |PlatformView|
107 void SetAccessibilityFeatures(int32_t flags) override;
108
109 // |PlatformView|
110 void UpdateSemantics(int64_t view_id,
111 flutter::SemanticsNodeUpdates update,
112 flutter::CustomAccessibilityActionUpdates actions) override;
113
114 // |PlatformView|
115 void SetApplicationLocale(std::string locale) override;
116
117 // |PlatformView|
118 std::unique_ptr<VsyncWaiter> CreateVSyncWaiter() override;
119
120 // |PlatformView|
121 void OnPreEngineRestart() const override;
122
123 // |PlatformView|
124 std::unique_ptr<std::vector<std::string>> ComputePlatformResolvedLocales(
125 const std::vector<std::string>& supported_locale_data) override;
126
127 /** Accessor for the `IOSContext` associated with the platform view. */
128 const std::shared_ptr<IOSContext>& GetIosContext() { return ios_context_; }
129
130 std::shared_ptr<PlatformMessageHandlerIos> GetPlatformMessageHandlerIos() const {
131 return platform_message_handler_;
132 }
133
134 std::shared_ptr<PlatformMessageHandler> GetPlatformMessageHandler() const override {
135 return platform_message_handler_;
136 }
137
138 /**
139 * Gets the accessibility bridge created in this platform view.
140 */
141 AccessibilityBridge* GetAccessibilityBridge() { return accessibility_bridge_.get(); }
142
143 private:
144 void ApplyLocaleToOwnerController();
145 /// Smart pointer for use with objective-c observers.
146 /// This guarantees we remove the observer.
147 class ScopedObserver {
148 public:
149 ScopedObserver();
150 ~ScopedObserver();
151 void reset(id<NSObject> observer);
152 ScopedObserver(const ScopedObserver&) = delete;
153 ScopedObserver& operator=(const ScopedObserver&) = delete;
154
155 private:
156 id<NSObject> observer_ = nil;
157 };
158
159 __weak FlutterViewController* owner_controller_;
160 std::string application_locale_;
161 // Since the `ios_surface_` is created on the platform thread but
162 // used on the raster thread we need to protect it with a mutex.
163 std::mutex ios_surface_mutex_;
164 std::unique_ptr<IOSSurface> ios_surface_;
165 std::shared_ptr<IOSContext> ios_context_;
166 __weak FlutterPlatformViewsController* platform_views_controller_;
167 std::unique_ptr<AccessibilityBridge> accessibility_bridge_;
168 ScopedObserver dealloc_view_controller_observer_;
169 std::vector<std::string> platform_resolved_locale_;
170 std::shared_ptr<PlatformMessageHandlerIos> platform_message_handler_;
171
172 FML_DISALLOW_COPY_AND_ASSIGN(PlatformViewIOS);
173 };
174
175 } // namespace flutter
176
177 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_PLATFORM_VIEW_IOS_H_
FlutterTexture.h
FlutterView.h
FlutterViewController.h
FlutterViewController_Internal.h
flutter::AccessibilityBridge
Definition: accessibility_bridge.h:36
flutter::IOSContext
Manages the lifetime of the on-screen and off-screen rendering contexts on iOS. On-screen contexts ar...
Definition: ios_context.h:39
flutter::PlatformViewIOS
Definition: platform_view_ios.h:40
flutter::PlatformViewIOS::attachView
void attachView()
Definition: platform_view_ios.mm:92
flutter::PlatformViewIOS::CreateRenderingSurface
std::unique_ptr< Surface > CreateRenderingSurface() override
Definition: platform_view_ios.mm:119
flutter::PlatformViewIOS::GetPlatformMessageHandler
std::shared_ptr< PlatformMessageHandler > GetPlatformMessageHandler() const override
Definition: platform_view_ios.h:134
flutter::PlatformViewIOS::GetDispatcherMaker
PointerDataDispatcherMaker GetDispatcherMaker() override
Definition: platform_view_ios.mm:107
flutter::PlatformViewIOS::GetIosContext
const std::shared_ptr< IOSContext > & GetIosContext()
Definition: platform_view_ios.h:128
flutter::PlatformViewIOS::GetImpellerContext
std::shared_ptr< impeller::Context > GetImpellerContext() const override
Definition: platform_view_ios.mm:136
flutter::PlatformViewIOS::SetAccessibilityFeatures
void SetAccessibilityFeatures(int32_t flags) override
Definition: platform_view_ios.mm:146
flutter::PlatformViewIOS::UpdateSemantics
void UpdateSemantics(int64_t view_id, flutter::SemanticsNodeUpdates update, flutter::CustomAccessibilityActionUpdates actions) override
Definition: platform_view_ios.mm:151
flutter::PlatformViewIOS::CreateVSyncWaiter
std::unique_ptr< VsyncWaiter > CreateVSyncWaiter() override
Definition: platform_view_ios.mm:183
flutter::PlatformViewIOS::CreateExternalViewEmbedder
std::shared_ptr< ExternalViewEmbedder > CreateExternalViewEmbedder() override
Definition: platform_view_ios.mm:131
flutter::PlatformViewIOS::SetSemanticsEnabled
void SetSemanticsEnabled(bool enabled) override
Definition: platform_view_ios.mm:141
flutter::PlatformViewIOS::HandlePlatformMessage
void HandlePlatformMessage(std::unique_ptr< flutter::PlatformMessage > message) override
Definition: platform_view_ios.mm:52
flutter::PlatformViewIOS::PlatformViewIOS
PlatformViewIOS(PlatformView::Delegate &delegate, const std::shared_ptr< IOSContext > &context, __weak FlutterPlatformViewsController *platform_views_controller, const flutter::TaskRunners &task_runners)
Definition: platform_view_ios.mm:22
flutter::PlatformViewIOS::GetPlatformMessageHandlerIos
std::shared_ptr< PlatformMessageHandlerIos > GetPlatformMessageHandlerIos() const
Definition: platform_view_ios.h:130
flutter::PlatformViewIOS::GetOwnerViewController
FlutterViewController * GetOwnerViewController() const __attribute__((cf_audited_transfer))
Definition: platform_view_ios.mm:56
flutter::PlatformViewIOS::GetAccessibilityBridge
AccessibilityBridge * GetAccessibilityBridge()
Definition: platform_view_ios.h:141
flutter::PlatformViewIOS::SetSemanticsTreeEnabled
void SetSemanticsTreeEnabled(bool enabled) override
Definition: platform_view_ios.mm:169
flutter::PlatformViewIOS::OnPreEngineRestart
void OnPreEngineRestart() const override
Definition: platform_view_ios.mm:188
flutter::PlatformViewIOS::SetOwnerViewController
void SetOwnerViewController(__weak FlutterViewController *owner_controller)
Definition: platform_view_ios.mm:60
flutter::PlatformViewIOS::RegisterExternalTexture
void RegisterExternalTexture(int64_t id, NSObject< FlutterTexture > *texture)
Definition: platform_view_ios.mm:113
flutter::PlatformViewIOS::SetApplicationLocale
void SetApplicationLocale(std::string locale) override
Definition: platform_view_ios.mm:163
flutter::PlatformViewIOS::~PlatformViewIOS
~PlatformViewIOS() override
flutter::PlatformViewIOS::ComputePlatformResolvedLocales
std::unique_ptr< std::vector< std::string > > ComputePlatformResolvedLocales(const std::vector< std::string > &supported_locale_data) override
Definition: platform_view_ios.mm:201
accessibility_bridge.h
FlutterPlatformViewsController
Definition: FlutterPlatformViewsController.h:31
FlutterTexture
Definition: FlutterMetalLayer.mm:61
FlutterViewController
Definition: FlutterViewController.h:57
ios_context.h
ios_external_view_embedder.h
ios_surface.h
flutter
Definition: accessibility_bridge.h:26
flutter::IOSRenderingAPI
IOSRenderingAPI
Definition: rendering_api_selection.h:14
impeller
Definition: ios_context.h:20
platform_message_handler_ios.h
rendering_api_selection.h