Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
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"
23
25
26namespace 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 */
40class PlatformViewIOS final : public PlatformView {
41 public:
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<const fml::SyncSwitch>& is_gpu_disabled_sync_switch);
53
54 ~PlatformViewIOS() override;
55
56 /**
57 * Returns the `FlutterViewController` currently attached to the `FlutterEngine` owning
58 * this PlatformViewIOS.
59 */
60 FlutterViewController* GetOwnerViewController() const __attribute__((cf_audited_transfer));
61
62 /**
63 * Updates the `FlutterViewController` currently attached to the `FlutterEngine` owning
64 * this PlatformViewIOS. This should be updated when the `FlutterEngine`
65 * is given a new `FlutterViewController`.
66 */
67 void SetOwnerViewController(__weak FlutterViewController* owner_controller);
68
69 /**
70 * Called one time per `FlutterViewController` when the `FlutterViewController`'s
71 * UIView is first loaded.
72 *
73 * Can be used to perform late initialization after `FlutterViewController`'s
74 * init.
75 */
76 void attachView();
77
78 /**
79 * Called through when an external texture such as video or camera is
80 * given to the `FlutterEngine` or `FlutterViewController`.
81 */
82 void RegisterExternalTexture(int64_t id, NSObject<FlutterTexture>* texture);
83
84 // |PlatformView|
86
87 // |PlatformView|
88 void SetSemanticsTreeEnabled(bool enabled) override;
89
90 // |PlatformView|
91 void HandlePlatformMessage(std::unique_ptr<flutter::PlatformMessage> message) override;
92
93 // |PlatformView|
94 std::unique_ptr<Surface> CreateRenderingSurface() override;
95
96 // |PlatformView|
98
99 // |PlatformView|
100 std::shared_ptr<impeller::Context> GetImpellerContext() const override;
101
102 // |PlatformView|
103 void UpdateSemantics(int64_t view_id,
105 flutter::CustomAccessibilityActionUpdates actions) override;
106
107 // |PlatformView|
108 void SetApplicationLocale(std::string locale) override;
109
110 // |PlatformView|
111 std::unique_ptr<VsyncWaiter> CreateVSyncWaiter() override;
112
113 // |PlatformView|
114 void OnPreEngineRestart() const override;
115
116 // |PlatformView|
117 std::unique_ptr<std::vector<std::string>> ComputePlatformResolvedLocales(
118 const std::vector<std::string>& supported_locale_data) override;
119
120 /** Accessor for the `IOSContext` associated with the platform view. */
121 const std::shared_ptr<IOSContext>& GetIosContext() { return ios_context_; }
122
123 std::shared_ptr<PlatformMessageHandlerIos> GetPlatformMessageHandlerIos() const {
124 return platform_message_handler_;
125 }
126
127 std::shared_ptr<PlatformMessageHandler> GetPlatformMessageHandler() const override {
128 return platform_message_handler_;
129 }
130
131 /**
132 * Gets the accessibility bridge created in this platform view.
133 */
134 AccessibilityBridge* GetAccessibilityBridge() { return accessibility_bridge_.get(); }
135
136 private:
137 void ApplyLocaleToOwnerController();
138 /// Smart pointer for use with objective-c observers.
139 /// This guarantees we remove the observer.
140 class ScopedObserver {
141 public:
142 ScopedObserver();
143 ~ScopedObserver();
144 void reset(id<NSObject> observer);
145 ScopedObserver(const ScopedObserver&) = delete;
146 ScopedObserver& operator=(const ScopedObserver&) = delete;
147
148 private:
149 id<NSObject> observer_ = nil;
150 };
151
152 __weak FlutterViewController* owner_controller_;
153 std::string application_locale_;
154 // Since the `ios_surface_` is created on the platform thread but
155 // used on the raster thread we need to protect it with a mutex.
156 std::mutex ios_surface_mutex_;
157 std::unique_ptr<IOSSurface> ios_surface_;
158 std::shared_ptr<IOSContext> ios_context_;
159 __weak FlutterPlatformViewsController* platform_views_controller_;
160 std::unique_ptr<AccessibilityBridge> accessibility_bridge_;
161 ScopedObserver dealloc_view_controller_observer_;
162 std::vector<std::string> platform_resolved_locale_;
163 std::shared_ptr<PlatformMessageHandlerIos> platform_message_handler_;
164
165 FML_DISALLOW_COPY_AND_ASSIGN(PlatformViewIOS);
166};
167
168} // namespace flutter
169
170#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_PLATFORM_VIEW_IOS_H_
Manages the lifetime of the on-screen and off-screen rendering contexts on iOS. On-screen contexts ar...
Definition ios_context.h:39
Used to forward events from the platform view to interested subsystems. This forwarding is done by th...
Platform views are created by the shell on the platform task runner. Unless explicitly specified,...
std::unique_ptr< Surface > CreateRenderingSurface() override
PointerDataDispatcherMaker GetDispatcherMaker() override
Returns a platform-specific PointerDataDispatcherMaker so the Engine can construct the PointerDataPac...
std::shared_ptr< PlatformMessageHandlerIos > GetPlatformMessageHandlerIos() const
std::shared_ptr< impeller::Context > GetImpellerContext() const override
void UpdateSemantics(int64_t view_id, flutter::SemanticsNodeUpdates update, flutter::CustomAccessibilityActionUpdates actions) override
Used by the framework to tell the embedder to apply the specified semantics node updates....
std::unique_ptr< VsyncWaiter > CreateVSyncWaiter() override
Invoked by the shell to obtain a platform specific vsync waiter. It is optional for platforms to over...
const std::shared_ptr< IOSContext > & GetIosContext()
std::shared_ptr< ExternalViewEmbedder > CreateExternalViewEmbedder() override
void HandlePlatformMessage(std::unique_ptr< flutter::PlatformMessage > message) override
FlutterViewController * GetOwnerViewController() const __attribute__((cf_audited_transfer))
void SetSemanticsTreeEnabled(bool enabled) override
Used by the framework to tell the embedder to prepare or clear resoruce for accepting semantics tree.
void OnPreEngineRestart() const override
Gives embedders a chance to react to a "cold restart" of the running isolate. The default implementat...
void SetOwnerViewController(__weak FlutterViewController *owner_controller)
AccessibilityBridge * GetAccessibilityBridge()
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)
void SetApplicationLocale(std::string locale) override
Used by the framework to set application locale in the embedding.
std::unique_ptr< std::vector< std::string > > ComputePlatformResolvedLocales(const std::vector< std::string > &supported_locale_data) override
Directly invokes platform-specific APIs to compute the locale the platform would have natively resolv...
Abstract Base Class that represents where we will be rendering content.
Definition surface.h:26
To do anything rendering related with Impeller, you need a context.
Definition context.h:70
const char * message
G_BEGIN_DECLS FlutterViewId view_id
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
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.
struct flutter::ImageMetaData __attribute__((packed))
Definition ref_ptr.h:261
std::shared_ptr< ContextGLES > context