| Flutter iOS Embedder |

Classes | Public Member Functions | List of all members
flutter::PlatformViewIOS Class Referencefinal

`#include <platform_view_ios.h>`

Inheritance diagram for flutter::PlatformViewIOS:

## Public Member Functions
| PlatformViewIOS (PlatformView::Delegate &delegate, const std::shared_ptr< IOSContext > &context, __weak FlutterPlatformViewsController *platform_views_controller, const flutter::TaskRunners &task_runners)
| PlatformViewIOS (PlatformView::Delegate &delegate, IOSRenderingAPI rendering_api, __weak FlutterPlatformViewsController *platform_views_controller, const flutter::TaskRunners &task_runners, const std::shared_ptr< fml::ConcurrentTaskRunner > &worker_task_runner, const std::shared_ptr< const fml::SyncSwitch > &is_gpu_disabled_sync_switch)
| ~PlatformViewIOS () override
FlutterViewController * | GetOwnerViewController () const __attribute__((cf_audited_transfer))
void | SetOwnerViewController (__weak FlutterViewController *owner_controller)
void | attachView ()
void | RegisterExternalTexture (int64_t id, NSObject< FlutterTexture > *texture)
PointerDataDispatcherMaker | GetDispatcherMaker () override
void | SetSemanticsEnabled (bool enabled) override
void | HandlePlatformMessage (std::unique_ptr< flutter::PlatformMessage > message) override
std::unique_ptr< Surface > | CreateRenderingSurface () override
std::shared_ptr< ExternalViewEmbedder > | CreateExternalViewEmbedder () override
sk_sp< GrDirectContext > | CreateResourceContext () const override
std::shared_ptr< impeller::Context > | GetImpellerContext () const override
void | SetAccessibilityFeatures (int32_t flags) override
void | UpdateSemantics (flutter::SemanticsNodeUpdates update, flutter::CustomAccessibilityActionUpdates actions) override
std::unique_ptr< VsyncWaiter > | CreateVSyncWaiter () override
void | OnPreEngineRestart () const override
std::unique_ptr< std::vector< std::string > > | ComputePlatformResolvedLocales (const std::vector< std::string > &supported_locale_data) override
const std::shared_ptr< IOSContext > & | GetIosContext ()
std::shared_ptr< PlatformMessageHandlerIos > | GetPlatformMessageHandlerIos () const
std::shared_ptr< PlatformMessageHandler > | GetPlatformMessageHandler () const override

## Detailed Description

A bridge connecting the platform agnostic shell and the iOS embedding.

The shell provides and requests for UI related data and this PlatformView subclass fulfills it with iOS specific capabilities. As an example, the iOS embedding (the `FlutterEngine` and the `FlutterViewController`) sends pointer data to the shell and receives the shell's request for a Skia GrDirectContext and supplies it.

Despite the name "view", this class is unrelated to UIViews on iOS and doesn't have the same lifecycle. It's a long lived bridge owned by the `FlutterEngine` and can be attached and detached sequentially to multiple `FlutterViewController`s and `FlutterView`s.

Definition at line 39 of file platform_view_ios.h.

## Constructor & Destructor Documentation

## ◆ PlatformViewIOS() [1/2]

flutter::PlatformViewIOS::PlatformViewIOS | ( | PlatformView::Delegate & | delegate,
|  | const std::shared_ptr< IOSContext > & | context,
|  | __weak FlutterPlatformViewsController * | platform_views_controller,
|  | const flutter::TaskRunners & | task_runners
| ) |  |

Definition at line 44 of file platform_view_ios.mm.

48 : PlatformView(delegate, task_runners),
49 ios_context_(context),
50 platform_views_controller_(platform_views_controller),
51 accessibility_bridge_([this](bool enabled) { PlatformView::SetSemanticsEnabled(enabled); }),
52 platform_message_handler_(
53 new PlatformMessageHandlerIos(task_runners.GetPlatformTaskRunner())) {}

## ◆ PlatformViewIOS() [2/2]

flutter::PlatformViewIOS::PlatformViewIOS | ( | PlatformView::Delegate & | delegate,
|  | IOSRenderingAPI | rendering_api,
|  | __weak FlutterPlatformViewsController * | platform_views_controller,
|  | const flutter::TaskRunners & | task_runners,
|  | const std::shared_ptr< fml::ConcurrentTaskRunner > & | worker_task_runner,
|  | const std::shared_ptr< const fml::SyncSwitch > & | is_gpu_disabled_sync_switch
| ) |  |
| explicit

Definition at line 55 of file platform_view_ios.mm.

62 : PlatformViewIOS(delegate,
63 IOSContext::Create(rendering_api,
64 delegate.OnPlatformViewGetSettings().enable_impeller
65 ? IOSRenderingBackend::kImpeller
66 : IOSRenderingBackend::kSkia,
67 is_gpu_disabled_sync_switch),
68 platform_views_controller,
69 task_runners) {}

References flutter::kImpeller, and flutter::kSkia.

## ◆ ~PlatformViewIOS()

flutter::PlatformViewIOS::~PlatformViewIOS | ( |  | ) |
| override default

## Member Function Documentation

## ◆ attachView()

void flutter::PlatformViewIOS::attachView | ( |  | ) |

Called one time per `FlutterViewController` when the `FlutterViewController`'s UIView is first loaded.

Can be used to perform late initialization after `FlutterViewController`'s init.

Definition at line 113 of file platform_view_ios.mm.

113 {
114 FML_DCHECK(owner_controller_);
115 FML_DCHECK(owner_controller_.isViewLoaded) << "FlutterViewController's view should be loaded "
116 "before attaching to PlatformViewIOS.";
117 FlutterView* flutter_view = static_cast<FlutterView*>(owner_controller_.view);
118 CALayer* ca_layer = flutter_view.layer;
119 ios_surface_ = IOSSurface::Create(ios_context_, ca_layer);
120 FML_DCHECK(ios_surface_ != nullptr);
121
122 if (accessibility_bridge_) {
123 accessibility_bridge_.Set(std::make_unique<AccessibilityBridge>(
124 owner_controller_, this, owner_controller_.platformViewsController));
125 }
126 }

References flutter::IOSSurface::Create().

Referenced by SetOwnerViewController().

## ◆ ComputePlatformResolvedLocales()

std::unique_ptr< std::vector< std::string > > flutter::PlatformViewIOS::ComputePlatformResolvedLocales | ( | const std::vector< std::string > & | supported_locale_data | ) |
| override

Definition at line 215 of file platform_view_ios.mm.

216 {
217 size_t localeDataLength = 3;
218 NSMutableArray<NSString*>* supported_locale_identifiers =
219 [NSMutableArray arrayWithCapacity:supported_locale_data.size() / localeDataLength];
220 for (size_t i = 0; i < supported_locale_data.size(); i += localeDataLength) {
221 NSDictionary<NSString*, NSString*>* dict = @{
222 NSLocaleLanguageCode : [NSString stringWithUTF8String:supported_locale_data[i].c_str()]
223 ?: @"",
224 NSLocaleCountryCode : [NSString stringWithUTF8String:supported_locale_data[i + 1].c_str()]
225 ?: @"",
226 NSLocaleScriptCode : [NSString stringWithUTF8String:supported_locale_data[i + 2].c_str()]
227 ?: @""
228 };
229 [supported_locale_identifiers addObject:[NSLocale localeIdentifierFromComponents:dict]];
230 }
231 NSArray<NSString*>* result =
232 [NSBundle preferredLocalizationsFromArray:supported_locale_identifiers];
233
234 // Output format should be either empty or 3 strings for language, country, and script.
235 std::unique_ptr<std::vector<std::string>> out = std::make_unique<std::vector<std::string>>();
236
237 if (result != nullptr && [result count] > 0) {
238 NSLocale* locale = [NSLocale localeWithLocaleIdentifier:[result firstObject]];
239 NSString* languageCode = [locale languageCode];
240 out->emplace_back(languageCode == nullptr ? "" : languageCode.UTF8String);
241 NSString* countryCode = [locale countryCode];
242 out->emplace_back(countryCode == nullptr ? "" : countryCode.UTF8String);
243 NSString* scriptCode = [locale scriptCode];
244 out->emplace_back(scriptCode == nullptr ? "" : scriptCode.UTF8String);
245 }
246 return out;
247 }

## ◆ CreateExternalViewEmbedder()

std::shared_ptr< ExternalViewEmbedder > flutter::PlatformViewIOS::CreateExternalViewEmbedder | ( |  | ) |
| override

Definition at line 152 of file platform_view_ios.mm.

152 {
153 return std::make_shared<IOSExternalViewEmbedder>(platform_views_controller_, ios_context_);
154 }

## ◆ CreateRenderingSurface()

std::unique_ptr< Surface > flutter::PlatformViewIOS::CreateRenderingSurface | ( |  | ) |
| override

Definition at line 140 of file platform_view_ios.mm.

140 {
141 FML_DCHECK(task_runners_.GetRasterTaskRunner()->RunsTasksOnCurrentThread());
142 std::lock_guard<std::mutex> guard(ios_surface_mutex_);
143 if (!ios_surface_) {
144 FML_DLOG(INFO) << "Could not CreateRenderingSurface, this PlatformViewIOS "
145 "has no ViewController.";
146 return nullptr;
147 }
148 return ios_surface_->CreateGPUSurface(ios_context_->GetMainContext().get());
149 }

## ◆ CreateResourceContext()

sk_sp< GrDirectContext > flutter::PlatformViewIOS::CreateResourceContext | ( |  | ) | const
| override

Definition at line 157 of file platform_view_ios.mm.

157 {
158 return ios_context_->CreateResourceContext();
159 }

## ◆ CreateVSyncWaiter()

std::unique_ptr< VsyncWaiter > flutter::PlatformViewIOS::CreateVSyncWaiter | ( |  | ) |
| override

Definition at line 200 of file platform_view_ios.mm.

200 {
201 return std::make_unique<VsyncWaiterIOS>(task_runners_);
202 }

## ◆ GetDispatcherMaker()

PointerDataDispatcherMaker flutter::PlatformViewIOS::GetDispatcherMaker | ( |  | ) |
| override

Definition at line 128 of file platform_view_ios.mm.

128 {
129 return [](DefaultPointerDataDispatcher::Delegate& delegate) {
130 return std::make_unique<SmoothPointerDataDispatcher>(delegate);
131 };
132 }

## ◆ GetImpellerContext()

std::shared_ptr< impeller::Context > flutter::PlatformViewIOS::GetImpellerContext | ( |  | ) | const
| override

Definition at line 162 of file platform_view_ios.mm.

162 {
163 return ios_context_->GetImpellerContext();
164 }

## ◆ GetIosContext()

const std::shared_ptr<IOSContext>& flutter::PlatformViewIOS::GetIosContext | ( |  | ) |
| inline

Accessor for the `IOSContext` associated with the platform view.

Definition at line 123 of file platform_view_ios.h.

123 { return ios_context_; }

## ◆ GetOwnerViewController()

FlutterViewController * flutter::PlatformViewIOS::GetOwnerViewController | ( |  | ) | const

Returns the `FlutterViewController` currently attached to the `FlutterEngine` owning this PlatformViewIOS.

Definition at line 78 of file platform_view_ios.mm.

78 {
79 return owner_controller_;
80 }

## ◆ GetPlatformMessageHandler()

std::shared_ptr<PlatformMessageHandler> flutter::PlatformViewIOS::GetPlatformMessageHandler | ( |  | ) | const
| inline override

Definition at line 129 of file platform_view_ios.h.

129 {
130 return platform_message_handler_;
131 }

## ◆ GetPlatformMessageHandlerIos()

std::shared_ptr<PlatformMessageHandlerIos> flutter::PlatformViewIOS::GetPlatformMessageHandlerIos | ( |  | ) | const
| inline

Definition at line 125 of file platform_view_ios.h.

125 {
126 return platform_message_handler_;
127 }

## ◆ HandlePlatformMessage()

void flutter::PlatformViewIOS::HandlePlatformMessage | ( | std::unique_ptr< flutter::PlatformMessage > | message | ) |
| override

Definition at line 74 of file platform_view_ios.mm.

74 {
75 platform_message_handler_->HandlePlatformMessage(std::move(message));
76 }

## ◆ OnPreEngineRestart()

void flutter::PlatformViewIOS::OnPreEngineRestart | ( |  | ) | const
| override

Definition at line 204 of file platform_view_ios.mm.

204 {
205 if (accessibility_bridge_) {
206 accessibility_bridge_.get()->clearState();
207 }
208 if (!owner_controller_) {
209 return;
210 }
211 [owner_controller_.platformViewsController reset];
212 [owner_controller_.restorationPlugin reset];
213 }

## ◆ RegisterExternalTexture()

void flutter::PlatformViewIOS::RegisterExternalTexture | ( | int64_t | id,
|  | NSObject< FlutterTexture > * | texture
| ) |  |

Called through when an external texture such as video or camera is given to the `FlutterEngine` or `FlutterViewController`.

Definition at line 134 of file platform_view_ios.mm.

135 {
136 RegisterTexture(ios_context_->CreateExternalTexture(texture_id, texture));
137 }

References texture_id.

## ◆ SetAccessibilityFeatures()

void flutter::PlatformViewIOS::SetAccessibilityFeatures | ( | int32_t | flags | ) |
| override

Definition at line 184 of file platform_view_ios.mm.

184 {
185 PlatformView::SetAccessibilityFeatures(flags);
186 }

## ◆ SetOwnerViewController()

void flutter::PlatformViewIOS::SetOwnerViewController | ( | __weak FlutterViewController * | owner_controller | ) |

Updates the `FlutterViewController` currently attached to the `FlutterEngine` owning this PlatformViewIOS. This should be updated when the `FlutterEngine` is given a new `FlutterViewController`.

Definition at line 82 of file platform_view_ios.mm.

82 {
83 FML_DCHECK(task_runners_.GetPlatformTaskRunner()->RunsTasksOnCurrentThread());
84 std::lock_guard<std::mutex> guard(ios_surface_mutex_);
85 if (ios_surface_ || !owner_controller) {
86 NotifyDestroyed();
87 ios_surface_.reset();
88 accessibility_bridge_.Clear();
89 }
90 owner_controller_ = owner_controller;
91
92 // Add an observer that will clear out the owner_controller_ ivar and
93 // the accessibility_bridge_ in case the view controller is deleted.
94 dealloc_view_controller_observer_.reset([[NSNotificationCenter defaultCenter]
95 addObserverForName:FlutterViewControllerWillDealloc
96 object:owner_controller_
97 queue:[NSOperationQueue mainQueue]
98 usingBlock:^(NSNotification* note) {
99 // Implicit copy of 'this' is fine.
100 accessibility_bridge_.Clear();
101 owner_controller_ = nil;
102 }]);
103
104 if (owner_controller_ && owner_controller_.isViewLoaded) {
105 this->attachView();
106 }
107 // Do not call `NotifyCreated()` here - let FlutterViewController take care
108 // of that when its Viewport is sized. If `NotifyCreated()` is called here,
109 // it can occasionally get invoked before the viewport is sized resulting in
110 // a framebuffer that will not be able to completely attach.
111 }

References attachView(), and FlutterViewControllerWillDealloc.

## ◆ SetSemanticsEnabled()

void flutter::PlatformViewIOS::SetSemanticsEnabled | ( | bool | enabled | ) |
| override

Definition at line 167 of file platform_view_ios.mm.

167 {
168 if (!owner_controller_) {
169 FML_LOG(WARNING) << "Could not set semantics to enabled, this "
170 "PlatformViewIOS has no ViewController.";
171 return;
172 }
173 if (enabled && !accessibility_bridge_) {
174 accessibility_bridge_.Set(std::make_unique<AccessibilityBridge>(
175 owner_controller_, this, owner_controller_.platformViewsController));
176 } else if (!enabled && accessibility_bridge_) {
177 accessibility_bridge_.Clear();
178 } else {
179 PlatformView::SetSemanticsEnabled(enabled);
180 }
181 }

## ◆ UpdateSemantics()

void flutter::PlatformViewIOS::UpdateSemantics | ( | flutter::SemanticsNodeUpdates | update,
|  | flutter::CustomAccessibilityActionUpdates | actions
| ) |  |
| override

Definition at line 189 of file platform_view_ios.mm.

190 {
191 FML_DCHECK(owner_controller_);
192 if (accessibility_bridge_) {
193 accessibility_bridge_.get()->UpdateSemantics(std::move(update), actions);
194 [[NSNotificationCenter defaultCenter] postNotificationName:FlutterSemanticsUpdateNotification
195 object:owner_controller_];
196 }
197 }

References FlutterSemanticsUpdateNotification.

The documentation for this class was generated from the following files:

- shell/platform/darwin/ios/platform_view_ios.h
- shell/platform/darwin/ios/platform_view_ios.mm

flutter::IOSRenderingBackend::kSkia
@ kSkia
FlutterSemanticsUpdateNotification
FLUTTER_DARWIN_EXPORT const NSNotificationName FlutterSemanticsUpdateNotification
Definition: FlutterViewController.mm:43
flutter::IOSRenderingBackend::kImpeller
@ kImpeller
flutter::IOSSurface::Create
static std::unique_ptr< IOSSurface > Create(std::shared_ptr< IOSContext > context, CALayer *layer)
Definition: ios_surface.mm:19
FlutterViewControllerWillDealloc
const NSNotificationName FlutterViewControllerWillDealloc
Definition: FlutterViewController.mm:44
flutter::PlatformViewIOS::attachView
void attachView()
Definition: platform_view_ios.mm:113
FlutterView
Definition: FlutterView.h:33
texture_id
int64_t texture_id
Definition: texture_registrar_unittests.cc:24
flutter::IOSContext::Create
static std::unique_ptr< IOSContext > Create(IOSRenderingAPI api, IOSRenderingBackend backend, const std::shared_ptr< const fml::SyncSwitch > &is_gpu_disabled_sync_switch)
Create an iOS context object capable of creating the on-screen and off-screen GPU context for use by ...
Definition: ios_context.mm:23
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:44