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

49  : PlatformView(delegate, task_runners),
50  ios_context_(context),
51  platform_views_controller_(platform_views_controller),
52  accessibility_bridge_([this](bool enabled) { PlatformView::SetSemanticsEnabled(enabled); }),
53  platform_message_handler_(
54  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 56 of file platform_view_ios.mm.

63  : PlatformViewIOS(delegate,
64  IOSContext::Create(rendering_api,
65  delegate.OnPlatformViewGetSettings().enable_impeller
68  is_gpu_disabled_sync_switch,
69  delegate.OnPlatformViewGetSettings()),
70  platform_views_controller,
71  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 115 of file platform_view_ios.mm.

115  {
116  FML_DCHECK(owner_controller_);
117  FML_DCHECK(owner_controller_.isViewLoaded) << "FlutterViewController's view should be loaded "
118  "before attaching to PlatformViewIOS.";
119  FlutterView* flutter_view = static_cast<FlutterView*>(owner_controller_.view);
120  CALayer* ca_layer = flutter_view.layer;
121  ios_surface_ = IOSSurface::Create(ios_context_, ca_layer);
122  FML_DCHECK(ios_surface_ != nullptr);
123 
124  if (accessibility_bridge_) {
125  accessibility_bridge_.Set(std::make_unique<AccessibilityBridge>(
126  owner_controller_, this, owner_controller_.platformViewsController));
127  }
128 }
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 214 of file platform_view_ios.mm.

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

◆ CreateExternalViewEmbedder()

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

Definition at line 154 of file platform_view_ios.mm.

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

◆ CreateRenderingSurface()

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

Definition at line 142 of file platform_view_ios.mm.

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

◆ CreateVSyncWaiter()

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

Definition at line 198 of file platform_view_ios.mm.

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

◆ GetDispatcherMaker()

PointerDataDispatcherMaker flutter::PlatformViewIOS::GetDispatcherMaker ( )
override

Definition at line 130 of file platform_view_ios.mm.

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

◆ GetImpellerContext()

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

Definition at line 159 of file platform_view_ios.mm.

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

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

80  {
81  return owner_controller_;
82 }

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

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

◆ OnPreEngineRestart()

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

Definition at line 202 of file platform_view_ios.mm.

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

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

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

References texture_id.

◆ SetAccessibilityFeatures()

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

Definition at line 181 of file platform_view_ios.mm.

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

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

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

References attachView(), and FlutterViewControllerWillDealloc.

◆ SetSemanticsEnabled()

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

Definition at line 164 of file platform_view_ios.mm.

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

◆ UpdateSemantics()

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

Definition at line 186 of file platform_view_ios.mm.

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

References FlutterSemanticsUpdateNotification.


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