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, const std::shared_ptr< FlutterPlatformViewsController > &platform_views_controller, const flutter::TaskRunners &task_runners)
 
 PlatformViewIOS (PlatformView::Delegate &delegate, IOSRenderingAPI rendering_api, const std::shared_ptr< 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
 
fml::WeakNSObject< FlutterViewControllerGetOwnerViewController () const
 
void SetOwnerViewController (const fml::WeakNSObject< FlutterViewController > &owner_controller)
 
void attachView ()
 
void RegisterExternalTexture (int64_t id, NSObject< FlutterTexture > *texture)
 
PointerDataDispatcherMaker GetDispatcherMaker () override
 
void SetSemanticsEnabled (bool enabled) 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 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 FlutterViewControllers and FlutterViews.

Definition at line 41 of file platform_view_ios.h.

Constructor & Destructor Documentation

◆ PlatformViewIOS() [1/2]

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

Definition at line 42 of file platform_view_ios.mm.

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

◆ PlatformViewIOS() [2/2]

flutter::PlatformViewIOS::PlatformViewIOS ( PlatformView::Delegate &  delegate,
IOSRenderingAPI  rendering_api,
const std::shared_ptr< 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 54 of file platform_view_ios.mm.

62  delegate,
64  rendering_api,
65  delegate.OnPlatformViewGetSettings().enable_impeller ? IOSRenderingBackend::kImpeller
67  static_cast<MsaaSampleCount>(delegate.OnPlatformViewGetSettings().msaa_samples),
68  is_gpu_disabled_sync_switch),
69  platform_views_controller,
70  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_.get().isViewLoaded)
118  << "FlutterViewController's view should be loaded "
119  "before attaching to PlatformViewIOS.";
120  auto flutter_view = static_cast<FlutterView*>(owner_controller_.get().view);
121  auto ca_layer = fml::scoped_nsobject<CALayer>{[[flutter_view layer] retain]};
122  ios_surface_ = IOSSurface::Create(ios_context_, ca_layer);
123  FML_DCHECK(ios_surface_ != nullptr);
124 
125  if (accessibility_bridge_) {
126  accessibility_bridge_.Set(std::make_unique<AccessibilityBridge>(
127  owner_controller_.get(), this, [owner_controller_.get() platformViewsController]));
128  }
129 }

References flutter::IOSSurface::Create().

Referenced by SetOwnerViewController().

◆ GetDispatcherMaker()

PointerDataDispatcherMaker flutter::PlatformViewIOS::GetDispatcherMaker ( )
override

Definition at line 131 of file platform_view_ios.mm.

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

◆ GetIosContext()

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

Accessor for the IOSContext associated with the platform view.

Definition at line 93 of file platform_view_ios.h.

93 { return ios_context_; }

◆ GetOwnerViewController()

fml::WeakNSObject< 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 99 of file platform_view_ios.h.

99  {
100  return platform_message_handler_;
101  }

◆ GetPlatformMessageHandlerIos()

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

Definition at line 95 of file platform_view_ios.h.

95  {
96  return platform_message_handler_;
97  }

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

138  {
139  RegisterTexture(ios_context_->CreateExternalTexture(
140  texture_id, fml::scoped_nsobject<NSObject<FlutterTexture>>{[texture retain]}));
141 }

References texture_id.

◆ SetOwnerViewController()

void flutter::PlatformViewIOS::SetOwnerViewController ( const fml::WeakNSObject< 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.

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(
97  [[[NSNotificationCenter defaultCenter] addObserverForName:FlutterViewControllerWillDealloc
98  object:owner_controller_.get()
99  queue:[NSOperationQueue mainQueue]
100  usingBlock:^(NSNotification* note) {
101  // Implicit copy of 'this' is fine.
102  accessibility_bridge_.Clear();
103  owner_controller_.reset();
104  }] retain]);
105 
106  if (owner_controller_ && [owner_controller_.get() 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 }

References attachView(), and FlutterViewControllerWillDealloc.

◆ SetSemanticsEnabled()

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

Definition at line 171 of file platform_view_ios.mm.

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

The documentation for this class was generated from the following files:
flutter::IOSRenderingBackend::kSkia
@ kSkia
flutter::IOSContext::Create
static std::unique_ptr< IOSContext > Create(IOSRenderingAPI api, IOSRenderingBackend backend, MsaaSampleCount msaa_samples, 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:22
flutter::IOSRenderingBackend::kImpeller
@ kImpeller
flutter::PlatformViewIOS::attachView
void attachView()
Definition: platform_view_ios.mm:115
FlutterViewControllerWillDealloc
const NSNotificationName FlutterViewControllerWillDealloc
Definition: FlutterViewController.mm:43
flutter::PlatformViewIOS::PlatformViewIOS
PlatformViewIOS(PlatformView::Delegate &delegate, const std::shared_ptr< IOSContext > &context, const std::shared_ptr< FlutterPlatformViewsController > &platform_views_controller, const flutter::TaskRunners &task_runners)
Definition: platform_view_ios.mm:42
flutter::IOSSurface::Create
static std::unique_ptr< IOSSurface > Create(std::shared_ptr< IOSContext > context, const fml::scoped_nsobject< CALayer > &layer)
Definition: ios_surface.mm:18
FlutterView
Definition: FlutterView.h:39
texture_id
int64_t texture_id
Definition: texture_registrar_unittests.cc:24