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 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
 
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
 

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 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
67  is_gpu_disabled_sync_switch,
68  delegate.OnPlatformViewGetSettings()),
69  platform_views_controller,
70  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:21
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 114 of file platform_view_ios.mm.

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

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

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

◆ CreateExternalViewEmbedder()

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

Definition at line 153 of file platform_view_ios.mm.

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

◆ CreateRenderingSurface()

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

Definition at line 141 of file platform_view_ios.mm.

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

◆ CreateVSyncWaiter()

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

Definition at line 197 of file platform_view_ios.mm.

197  {
198  return std::make_unique<VsyncWaiterIOS>(task_runners_);
199 }

◆ GetDispatcherMaker()

PointerDataDispatcherMaker flutter::PlatformViewIOS::GetDispatcherMaker ( )
override

Definition at line 129 of file platform_view_ios.mm.

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

◆ GetImpellerContext()

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

Definition at line 158 of file platform_view_ios.mm.

158  {
159  return ios_context_->GetImpellerContext();
160 }

◆ GetIosContext()

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

Accessor for the IOSContext associated with the platform view.

Definition at line 121 of file platform_view_ios.h.

121 { return ios_context_; }

◆ GetOwnerViewController()

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

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

Definition at line 79 of file platform_view_ios.mm.

79  {
80  return owner_controller_;
81 }

◆ GetPlatformMessageHandler()

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

Definition at line 127 of file platform_view_ios.h.

127  {
128  return platform_message_handler_;
129  }

◆ GetPlatformMessageHandlerIos()

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

Definition at line 123 of file platform_view_ios.h.

123  {
124  return platform_message_handler_;
125  }

◆ HandlePlatformMessage()

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

Definition at line 75 of file platform_view_ios.mm.

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

◆ OnPreEngineRestart()

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

Definition at line 201 of file platform_view_ios.mm.

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

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

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

References texture_id.

◆ SetAccessibilityFeatures()

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

Definition at line 180 of file platform_view_ios.mm.

180  {
181  PlatformView::SetAccessibilityFeatures(flags);
182 }

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

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

References attachView(), and FlutterViewControllerWillDealloc.

◆ SetSemanticsEnabled()

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

Definition at line 163 of file platform_view_ios.mm.

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

◆ UpdateSemantics()

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

Definition at line 185 of file platform_view_ios.mm.

187  {
188  FML_DCHECK(owner_controller_);
189  if (accessibility_bridge_) {
190  accessibility_bridge_.get()->UpdateSemantics(std::move(update), actions);
191  [[NSNotificationCenter defaultCenter] postNotificationName:FlutterSemanticsUpdateNotification
192  object:owner_controller_];
193  }
194 }
FLUTTER_DARWIN_EXPORT NSNotificationName const FlutterSemanticsUpdateNotification

References FlutterSemanticsUpdateNotification.


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