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.

61  : PlatformViewIOS(delegate,
62  IOSContext::Create(rendering_api,
63  delegate.OnPlatformViewGetSettings().enable_impeller
66  is_gpu_disabled_sync_switch),
67  platform_views_controller,
68  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 113 of file platform_view_ios.mm.

113  {
114  FML_DCHECK(owner_controller_);
115  FML_DCHECK(owner_controller_.get().isViewLoaded)
116  << "FlutterViewController's view should be loaded "
117  "before attaching to PlatformViewIOS.";
118  auto flutter_view = static_cast<FlutterView*>(owner_controller_.get().view);
119  auto ca_layer = fml::scoped_nsobject<CALayer>{[[flutter_view layer] retain]};
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_.get(), this, [owner_controller_.get() platformViewsController]));
126  }
127 }

References flutter::IOSSurface::Create().

Referenced by SetOwnerViewController().

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

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

77  {
78  return owner_controller_;
79 }

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

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

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

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

The documentation for this class was generated from the following files:
flutter::IOSRenderingBackend::kSkia
@ kSkia
flutter::IOSRenderingBackend::kImpeller
@ kImpeller
FlutterViewControllerWillDealloc
const NSNotificationName FlutterViewControllerWillDealloc
Definition: FlutterViewController.mm:43
flutter::PlatformViewIOS::attachView
void attachView()
Definition: platform_view_ios.mm:113
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:16
FlutterView
Definition: FlutterView.h:34
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:21