Flutter iOS Embedder
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
 
FlutterViewControllerGetOwnerViewController () 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 SetSemanticsTreeEnabled (bool enabled) override
 
void HandlePlatformMessage (std::unique_ptr< flutter::PlatformMessage > message) override
 
std::unique_ptr< Surface > CreateRenderingSurface () override
 
std::shared_ptr< ExternalViewEmbedder > CreateExternalViewEmbedder () override
 
std::shared_ptr< impeller::Context > GetImpellerContext () const override
 
void SetAccessibilityFeatures (int32_t flags) override
 
void UpdateSemantics (int64_t view_id, flutter::SemanticsNodeUpdates update, flutter::CustomAccessibilityActionUpdates actions) override
 
void SetApplicationLocale (std::string locale) 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< PlatformMessageHandlerIosGetPlatformMessageHandlerIos () const
 
std::shared_ptr< PlatformMessageHandler > GetPlatformMessageHandler () const override
 
AccessibilityBridgeGetAccessibilityBridge ()
 

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 Impeller AiksContext 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 FlutterViewControllers and FlutterViews.

Definition at line 40 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 22 of file platform_view_ios.mm.

26  : PlatformView(delegate, task_runners),
27  ios_context_(context),
28  platform_views_controller_(platform_views_controller),
29  platform_message_handler_(
30  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 32 of file platform_view_ios.mm.

39  : PlatformViewIOS(delegate,
40  IOSContext::Create(rendering_api,
41  delegate.OnPlatformViewGetSettings().enable_impeller
44  is_gpu_disabled_sync_switch,
45  delegate.OnPlatformViewGetSettings()),
46  platform_views_controller,
47  task_runners) {}
static std::unique_ptr< IOSContext > Create(IOSRenderingAPI api, IOSRenderingBackend backend, const std::shared_ptr< const fml::SyncSwitch > &is_gpu_disabled_sync_switch, const Settings &settings)
Create an iOS context object capable of creating the on-screen and off-screen GPU context for use by ...
Definition: ios_context.mm:23
PlatformViewIOS(PlatformView::Delegate &delegate, const std::shared_ptr< IOSContext > &context, __weak FlutterPlatformViewsController *platform_views_controller, const flutter::TaskRunners &task_runners)

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

◆ ~PlatformViewIOS()

flutter::PlatformViewIOS::~PlatformViewIOS ( )
overridedefault

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 92 of file platform_view_ios.mm.

92  {
93  FML_DCHECK(owner_controller_);
94  FML_DCHECK(owner_controller_.isViewLoaded) << "FlutterViewController's view should be loaded "
95  "before attaching to PlatformViewIOS.";
96  FlutterView* flutter_view = static_cast<FlutterView*>(owner_controller_.view);
97  CALayer* ca_layer = flutter_view.layer;
98  ios_surface_ = IOSSurface::Create(ios_context_, ca_layer);
99  FML_DCHECK(ios_surface_ != nullptr);
100 
101  if (accessibility_bridge_) {
102  accessibility_bridge_ = std::make_unique<AccessibilityBridge>(
103  owner_controller_, this, owner_controller_.platformViewsController);
104  }
105 }
static std::unique_ptr< IOSSurface > Create(std::shared_ptr< IOSContext > context, CALayer *layer)
Definition: ios_surface.mm:18

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 201 of file platform_view_ios.mm.

202  {
203  size_t localeDataLength = 3;
204  NSMutableArray<NSString*>* supported_locale_identifiers =
205  [NSMutableArray arrayWithCapacity:supported_locale_data.size() / localeDataLength];
206  for (size_t i = 0; i < supported_locale_data.size(); i += localeDataLength) {
207  NSDictionary<NSString*, NSString*>* dict = @{
208  NSLocaleLanguageCode : [NSString stringWithUTF8String:supported_locale_data[i].c_str()]
209  ?: @"",
210  NSLocaleCountryCode : [NSString stringWithUTF8String:supported_locale_data[i + 1].c_str()]
211  ?: @"",
212  NSLocaleScriptCode : [NSString stringWithUTF8String:supported_locale_data[i + 2].c_str()]
213  ?: @""
214  };
215  [supported_locale_identifiers addObject:[NSLocale localeIdentifierFromComponents:dict]];
216  }
217  NSArray<NSString*>* result =
218  [NSBundle preferredLocalizationsFromArray:supported_locale_identifiers];
219 
220  // Output format should be either empty or 3 strings for language, country, and script.
221  std::unique_ptr<std::vector<std::string>> out = std::make_unique<std::vector<std::string>>();
222 
223  if (result != nullptr && [result count] > 0) {
224  NSLocale* locale = [NSLocale localeWithLocaleIdentifier:[result firstObject]];
225  NSString* languageCode = [locale languageCode];
226  out->emplace_back(languageCode == nullptr ? "" : languageCode.UTF8String);
227  NSString* countryCode = [locale countryCode];
228  out->emplace_back(countryCode == nullptr ? "" : countryCode.UTF8String);
229  NSString* scriptCode = [locale scriptCode];
230  out->emplace_back(scriptCode == nullptr ? "" : scriptCode.UTF8String);
231  }
232  return out;
233 }

◆ CreateExternalViewEmbedder()

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

Definition at line 131 of file platform_view_ios.mm.

131  {
132  return std::make_shared<IOSExternalViewEmbedder>(platform_views_controller_, ios_context_);
133 }

◆ CreateRenderingSurface()

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

Definition at line 119 of file platform_view_ios.mm.

119  {
120  FML_DCHECK(task_runners_.GetRasterTaskRunner()->RunsTasksOnCurrentThread());
121  std::lock_guard<std::mutex> guard(ios_surface_mutex_);
122  if (!ios_surface_) {
123  FML_DLOG(INFO) << "Could not CreateRenderingSurface, this PlatformViewIOS "
124  "has no ViewController.";
125  return nullptr;
126  }
127  return ios_surface_->CreateGPUSurface();
128 }

◆ CreateVSyncWaiter()

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

Definition at line 183 of file platform_view_ios.mm.

183  {
184  return std::make_unique<VsyncWaiterIOS>(task_runners_);
185 }

◆ GetAccessibilityBridge()

AccessibilityBridge* flutter::PlatformViewIOS::GetAccessibilityBridge ( )
inline

Gets the accessibility bridge created in this platform view.

Definition at line 141 of file platform_view_ios.h.

141 { return accessibility_bridge_.get(); }

◆ GetDispatcherMaker()

PointerDataDispatcherMaker flutter::PlatformViewIOS::GetDispatcherMaker ( )
override

Definition at line 107 of file platform_view_ios.mm.

107  {
108  return [](DefaultPointerDataDispatcher::Delegate& delegate) {
109  return std::make_unique<SmoothPointerDataDispatcher>(delegate);
110  };
111 }

◆ GetImpellerContext()

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

Definition at line 136 of file platform_view_ios.mm.

136  {
137  return ios_context_->GetImpellerContext();
138 }

◆ GetIosContext()

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

Accessor for the IOSContext associated with the platform view.

Definition at line 128 of file platform_view_ios.h.

128 { return ios_context_; }

◆ GetOwnerViewController()

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

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

Definition at line 56 of file platform_view_ios.mm.

56  {
57  return owner_controller_;
58 }

◆ GetPlatformMessageHandler()

std::shared_ptr<PlatformMessageHandler> flutter::PlatformViewIOS::GetPlatformMessageHandler ( ) const
inlineoverride

Definition at line 134 of file platform_view_ios.h.

134  {
135  return platform_message_handler_;
136  }

◆ GetPlatformMessageHandlerIos()

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

Definition at line 130 of file platform_view_ios.h.

130  {
131  return platform_message_handler_;
132  }

◆ HandlePlatformMessage()

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

Definition at line 52 of file platform_view_ios.mm.

52  {
53  platform_message_handler_->HandlePlatformMessage(std::move(message));
54 }

◆ OnPreEngineRestart()

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

Definition at line 188 of file platform_view_ios.mm.

188  {
189  if (accessibility_bridge_) {
190  accessibility_bridge_.get()->clearState();
191  }
192  if (!owner_controller_) {
193  return;
194  }
195  [owner_controller_.platformViewsController reset];
196  [owner_controller_.restorationPlugin reset];
197  [owner_controller_.textInputPlugin reset];
198 }

◆ 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 113 of file platform_view_ios.mm.

114  {
115  RegisterTexture(ios_context_->CreateExternalTexture(texture_id, texture));
116 }
int64_t texture_id

References texture_id.

◆ SetAccessibilityFeatures()

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

Definition at line 146 of file platform_view_ios.mm.

146  {
147  PlatformView::SetAccessibilityFeatures(flags);
148 }

◆ SetApplicationLocale()

void flutter::PlatformViewIOS::SetApplicationLocale ( std::string  locale)
override

Definition at line 163 of file platform_view_ios.mm.

163  {
164  application_locale_ = std::move(locale);
165  ApplyLocaleToOwnerController();
166 }

◆ 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 60 of file platform_view_ios.mm.

60  {
61  FML_DCHECK(task_runners_.GetPlatformTaskRunner()->RunsTasksOnCurrentThread());
62  std::lock_guard<std::mutex> guard(ios_surface_mutex_);
63  if (ios_surface_ || !owner_controller) {
64  NotifyDestroyed();
65  ios_surface_.reset();
66  accessibility_bridge_.reset();
67  }
68  owner_controller_ = owner_controller;
69  ApplyLocaleToOwnerController();
70 
71  // Add an observer that will clear out the owner_controller_ ivar and
72  // the accessibility_bridge_ in case the view controller is deleted.
73  dealloc_view_controller_observer_.reset([[NSNotificationCenter defaultCenter]
74  addObserverForName:FlutterViewControllerWillDealloc
75  object:owner_controller_
76  queue:[NSOperationQueue mainQueue]
77  usingBlock:^(NSNotification* note) {
78  // Implicit copy of 'this' is fine.
79  accessibility_bridge_.reset();
80  owner_controller_ = nil;
81  }]);
82 
83  if (owner_controller_ && owner_controller_.isViewLoaded) {
84  this->attachView();
85  }
86  // Do not call `NotifyCreated()` here - let FlutterViewController take care
87  // of that when its Viewport is sized. If `NotifyCreated()` is called here,
88  // it can occasionally get invoked before the viewport is sized resulting in
89  // a framebuffer that will not be able to completely attach.
90 }
NSNotificationName const FlutterViewControllerWillDealloc

References attachView(), and FlutterViewControllerWillDealloc.

◆ SetSemanticsEnabled()

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

Definition at line 141 of file platform_view_ios.mm.

141  {
142  PlatformView::SetSemanticsEnabled(enabled);
143 }

◆ SetSemanticsTreeEnabled()

void flutter::PlatformViewIOS::SetSemanticsTreeEnabled ( bool  enabled)
override

Definition at line 169 of file platform_view_ios.mm.

169  {
170  FML_DCHECK(owner_controller_);
171  if (enabled) {
172  if (accessibility_bridge_) {
173  return;
174  }
175  accessibility_bridge_ =
176  std::make_unique<AccessibilityBridge>(owner_controller_, this, platform_views_controller_);
177  } else {
178  accessibility_bridge_.reset();
179  }
180 }

◆ UpdateSemantics()

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

Definition at line 151 of file platform_view_ios.mm.

153  {
154  FML_DCHECK(owner_controller_);
155  if (accessibility_bridge_) {
156  accessibility_bridge_.get()->UpdateSemantics(std::move(update), actions);
157  [[NSNotificationCenter defaultCenter] postNotificationName:FlutterSemanticsUpdateNotification
158  object:owner_controller_];
159  }
160 }
FLUTTER_DARWIN_EXPORT NSNotificationName const FlutterSemanticsUpdateNotification

References FlutterSemanticsUpdateNotification.


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