Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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/fml/platform/darwin/scoped_nsobject.h"
13#include "flutter/fml/platform/darwin/weak_nsobject.h"
14#include "flutter/shell/common/platform_view.h"
15#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterTexture.h"
16#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"
17#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h"
18#import "flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h"
19#import "flutter/shell/platform/darwin/ios/ios_context.h"
20#import "flutter/shell/platform/darwin/ios/ios_external_view_embedder.h"
21#import "flutter/shell/platform/darwin/ios/ios_surface.h"
22#import "flutter/shell/platform/darwin/ios/platform_message_handler_ios.h"
23#import "flutter/shell/platform/darwin/ios/rendering_api_selection.h"
24
26
27namespace flutter {
28
29/**
30 * A bridge connecting the platform agnostic shell and the iOS embedding.
31 *
32 * The shell provides and requests for UI related data and this PlatformView subclass fulfills
33 * it with iOS specific capabilities. As an example, the iOS embedding (the `FlutterEngine` and the
34 * `FlutterViewController`) sends pointer data to the shell and receives the shell's request for a
35 * Skia GrDirectContext and supplies it.
36 *
37 * Despite the name "view", this class is unrelated to UIViews on iOS and doesn't have the same
38 * lifecycle. It's a long lived bridge owned by the `FlutterEngine` and can be attached and
39 * detached sequentially to multiple `FlutterViewController`s and `FlutterView`s.
40 */
41class PlatformViewIOS final : public PlatformView {
42 public:
44 const std::shared_ptr<IOSContext>& context,
45 const std::shared_ptr<FlutterPlatformViewsController>& platform_views_controller,
46 const flutter::TaskRunners& task_runners);
47
48 explicit PlatformViewIOS(
49 PlatformView::Delegate& delegate,
50 IOSRenderingAPI rendering_api,
51 const std::shared_ptr<FlutterPlatformViewsController>& platform_views_controller,
52 const flutter::TaskRunners& task_runners,
53 const std::shared_ptr<fml::ConcurrentTaskRunner>& worker_task_runner,
54 const std::shared_ptr<const fml::SyncSwitch>& is_gpu_disabled_sync_switch);
55
56 ~PlatformViewIOS() override;
57
58 /**
59 * Returns the `FlutterViewController` currently attached to the `FlutterEngine` owning
60 * this PlatformViewIOS.
61 */
63
64 /**
65 * Updates the `FlutterViewController` currently attached to the `FlutterEngine` owning
66 * this PlatformViewIOS. This should be updated when the `FlutterEngine`
67 * is given a new `FlutterViewController`.
68 */
70
71 /**
72 * Called one time per `FlutterViewController` when the `FlutterViewController`'s
73 * UIView is first loaded.
74 *
75 * Can be used to perform late initialization after `FlutterViewController`'s
76 * init.
77 */
78 void attachView();
79
80 /**
81 * Called through when an external texture such as video or camera is
82 * given to the `FlutterEngine` or `FlutterViewController`.
83 */
84 void RegisterExternalTexture(int64_t id, NSObject<FlutterTexture>* texture);
85
86 // |PlatformView|
88
89 // |PlatformView|
90 void SetSemanticsEnabled(bool enabled) override;
91
92 /** Accessor for the `IOSContext` associated with the platform view. */
93 const std::shared_ptr<IOSContext>& GetIosContext() { return ios_context_; }
94
95 std::shared_ptr<PlatformMessageHandlerIos> GetPlatformMessageHandlerIos() const {
96 return platform_message_handler_;
97 }
98
99 std::shared_ptr<PlatformMessageHandler> GetPlatformMessageHandler() const override {
100 return platform_message_handler_;
101 }
102
103 private:
104 /// Smart pointer for use with objective-c observers.
105 /// This guarantees we remove the observer.
106 class ScopedObserver {
107 public:
108 ScopedObserver();
109 ~ScopedObserver();
110 void reset(id<NSObject> observer);
111 ScopedObserver(const ScopedObserver&) = delete;
112 ScopedObserver& operator=(const ScopedObserver&) = delete;
113
114 private:
115 id<NSObject> observer_ = nil;
116 };
117
118 /// Wrapper that guarantees we communicate clearing Accessibility
119 /// information to Dart.
120 class AccessibilityBridgeManager {
121 public:
122 explicit AccessibilityBridgeManager(const std::function<void(bool)>& set_semantics_enabled);
123 AccessibilityBridgeManager(const std::function<void(bool)>& set_semantics_enabled,
124 AccessibilityBridge* bridge);
125 explicit operator bool() const noexcept { return static_cast<bool>(accessibility_bridge_); }
126 AccessibilityBridge* get() const noexcept { return accessibility_bridge_.get(); }
127 void Set(std::unique_ptr<AccessibilityBridge> bridge);
128 void Clear();
129
130 private:
131 FML_DISALLOW_COPY_AND_ASSIGN(AccessibilityBridgeManager);
132 std::unique_ptr<AccessibilityBridge> accessibility_bridge_;
133 std::function<void(bool)> set_semantics_enabled_;
134 };
135
137 // Since the `ios_surface_` is created on the platform thread but
138 // used on the raster thread we need to protect it with a mutex.
139 std::mutex ios_surface_mutex_;
140 std::unique_ptr<IOSSurface> ios_surface_;
141 std::shared_ptr<IOSContext> ios_context_;
142 const std::shared_ptr<FlutterPlatformViewsController>& platform_views_controller_;
143 AccessibilityBridgeManager accessibility_bridge_;
145 ScopedObserver dealloc_view_controller_observer_;
146 std::vector<std::string> platform_resolved_locale_;
147 std::shared_ptr<PlatformMessageHandlerIos> platform_message_handler_;
148
149 // |PlatformView|
150 void HandlePlatformMessage(std::unique_ptr<flutter::PlatformMessage> message) override;
151
152 // |PlatformView|
153 std::unique_ptr<Surface> CreateRenderingSurface() override;
154
155 // |PlatformView|
156 std::shared_ptr<ExternalViewEmbedder> CreateExternalViewEmbedder() override;
157
158 // |PlatformView|
159 sk_sp<GrDirectContext> CreateResourceContext() const override;
160
161 // |PlatformView|
162 std::shared_ptr<impeller::Context> GetImpellerContext() const override;
163
164 // |PlatformView|
165 void SetAccessibilityFeatures(int32_t flags) override;
166
167 // |PlatformView|
168 void UpdateSemantics(flutter::SemanticsNodeUpdates update,
170
171 // |PlatformView|
172 std::unique_ptr<VsyncWaiter> CreateVSyncWaiter() override;
173
174 // |PlatformView|
175 void OnPreEngineRestart() const override;
176
177 // |PlatformView|
178 std::unique_ptr<std::vector<std::string>> ComputePlatformResolvedLocales(
179 const std::vector<std::string>& supported_locale_data) override;
180
181 FML_DISALLOW_COPY_AND_ASSIGN(PlatformViewIOS);
182};
183
184} // namespace flutter
185
186#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_PLATFORM_VIEW_IOS_H_
m reset()
PointerDataDispatcherMaker GetDispatcherMaker() override
Returns a platform-specific PointerDataDispatcherMaker so the Engine can construct the PointerDataPac...
std::shared_ptr< PlatformMessageHandlerIos > GetPlatformMessageHandlerIos() const
void SetOwnerViewController(const fml::WeakNSObject< FlutterViewController > &owner_controller)
PlatformViewIOS(PlatformView::Delegate &delegate, const std::shared_ptr< IOSContext > &context, const std::shared_ptr< FlutterPlatformViewsController > &platform_views_controller, const flutter::TaskRunners &task_runners)
const std::shared_ptr< IOSContext > & GetIosContext()
void SetSemanticsEnabled(bool enabled) override
Used by embedder to notify the running isolate hosted by the engine on the UI thread that the accessi...
fml::WeakNSObject< FlutterViewController > GetOwnerViewController() const
std::shared_ptr< PlatformMessageHandler > GetPlatformMessageHandler() const override
Specifies a delegate that will receive PlatformMessages from Flutter to the host platform.
void RegisterExternalTexture(int64_t id, NSObject< FlutterTexture > *texture)
Used to forward events from the platform view to interested subsystems. This forwarding is done by th...
Definition: platform_view.h:60
Platform views are created by the shell on the platform task runner. Unless explicitly specified,...
Definition: platform_view.h:51
FlutterSemanticsFlag flags
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: macros.h:27
Dart_NativeFunction function
Definition: fuchsia.cc:51
Win32Message message
FlTexture * texture
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
std::function< std::unique_ptr< PointerDataDispatcher >(PointerDataDispatcher::Delegate &)> PointerDataDispatcherMaker
Signature for constructing PointerDataDispatcher.
const myers::Point & get(const myers::Segment &)
Definition: update.py:1