Flutter Engine
flutter::PlatformViewIOS Class Referencefinal

#include <platform_view_ios.h>

Inheritance diagram for flutter::PlatformViewIOS:
flutter::PlatformView

Public Member Functions

 PlatformViewIOS (PlatformView::Delegate &delegate, IOSRenderingAPI rendering_api, flutter::TaskRunners task_runners)
 
 ~PlatformViewIOS () override
 
PlatformMessageRouterGetPlatformMessageRouter ()
 
fml::WeakPtr< FlutterViewControllerGetOwnerViewController () const
 
void SetOwnerViewController (fml::WeakPtr< FlutterViewController > owner_controller)
 
void attachView ()
 
void RegisterExternalTexture (int64_t id, NSObject< FlutterTexture > *texture)
 
PointerDataDispatcherMaker GetDispatcherMaker () override
 Returns a platform-specific PointerDataDispatcherMaker so the Engine can construct the PointerDataPacketDispatcher based on platforms. More...
 
void SetSemanticsEnabled (bool enabled) override
 Used by embedder to notify the running isolate hosted by the engine on the UI thread that the accessibility tree needs to be generated. More...
 
- Public Member Functions inherited from flutter::PlatformView
 PlatformView (Delegate &delegate, TaskRunners task_runners)
 Creates a platform view with the specified delegate and task runner. The base class by itself does not do much but is suitable for use in test environments where full platform integration may not be necessary. The platform view may only be created, accessed and destroyed on the platform task runner. More...
 
virtual ~PlatformView ()
 Destroys the platform view. The platform view is owned by the shell and will be destroyed by the same on the platform tasks runner. More...
 
void DispatchPlatformMessage (fml::RefPtr< PlatformMessage > message)
 Used by embedders to dispatch a platform message to a running root isolate hosted by the engine. If an isolate is not running, the message is dropped. If there is no one on the other side listening on the channel, the message is dropped. When a platform message is dropped, any response handles associated with that message will be dropped as well. All users of platform messages must assume that message may not be delivered and/or their response handles may not be invoked. Platform messages are not buffered. More...
 
void DispatchSemanticsAction (int32_t id, SemanticsAction action, std::vector< uint8_t > args)
 Used by embedders to dispatch an accessibility action to a running isolate hosted by the engine. More...
 
void SetViewportMetrics (const ViewportMetrics &metrics)
 Used by embedders to specify the updated viewport metrics. In response to this call, on the raster thread, the rasterizer may need to be reconfigured to the updated viewport dimensions. On the UI thread, the framework may need to start generating a new frame for the updated viewport metrics as well. More...
 
void NotifyCreated ()
 Used by embedders to notify the shell that a platform view has been created. This notification is used to create a rendering surface and pick the client rendering API to use to render into this surface. No frames will be scheduled or rendered before this call. The surface must remain valid till the corresponding call to NotifyDestroyed. More...
 
virtual void NotifyDestroyed ()
 Used by embedders to notify the shell that the platform view has been destroyed. This notification used to collect the rendering surface and all associated resources. Frame scheduling is also suspended. More...
 
virtual void ReleaseResourceContext () const
 Used by the shell to notify the embedder that the resource context previously obtained via a call to CreateResourceContext() is being collected. The embedder is free to collect an platform specific resources associated with this context. More...
 
fml::WeakPtr< PlatformViewGetWeakPtr () const
 Returns a weak pointer to the platform view. Since the platform view may only be created, accessed and destroyed on the platform thread, any access to the platform view from a non-platform task runner needs a weak pointer to the platform view along with a reference to the platform task runner. A task must be posted to the platform task runner with the weak pointer captured in the same. The platform view method may only be called in the posted task once the weak pointer validity has been checked. This method is used by callers to obtain that weak pointer. More...
 
void SetNextFrameCallback (const fml::closure &closure)
 Sets a callback that gets executed when the rasterizer renders the next frame. Due to the asynchronous nature of rendering in Flutter, embedders usually add a placeholder over the contents in which Flutter is going to render when Flutter is first initialized. This callback may be used as a signal to remove that placeholder. The callback is executed on the render task runner and not the platform task runner. It is the embedder's responsibility to re-thread as necessary. More...
 
void DispatchPointerDataPacket (std::unique_ptr< PointerDataPacket > packet)
 Dispatches pointer events from the embedder to the framework. Each pointer data packet may contain multiple pointer input events. Each call to this method wakes up the UI thread. More...
 
void RegisterTexture (std::shared_ptr< flutter::Texture > texture)
 Used by the embedder to specify a texture that it wants the rasterizer to composite within the Flutter layer tree. All textures must have a unique identifier. When the rasterizer encounters an external texture within its hierarchy, it gives the embedder a chance to update that texture on the raster thread before it composites the same on-screen. More...
 
void UnregisterTexture (int64_t texture_id)
 Used by the embedder to notify the rasterizer that it will no longer attempt to composite the specified texture within the layer tree. This allows the rasterizer to collect associated resources. More...
 
void MarkTextureFrameAvailable (int64_t texture_id)
 Used by the embedder to notify the rasterizer that the context of the previously registered texture have been updated. Typically, Flutter will only render a frame if there is an updated layer tree. However, in cases where the layer tree is static but one of the externally composited textures has been updated by the embedder, the embedder needs to notify the rasterizer to render a new frame. In such cases, the existing layer tree may be reused with the frame re-composited with all updated external textures. Unlike the calls to register and unregister the texture, this call must be made each time a new texture frame is available. More...
 

Additional Inherited Members

- Protected Attributes inherited from flutter::PlatformView
PlatformView::Delegatedelegate_
 
const TaskRunners task_runners_
 
PointerDataPacketConverter pointer_data_packet_converter_
 
SkISize size_
 
fml::WeakPtrFactory< PlatformViewweak_factory_
 

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 40 of file platform_view_ios.h.

Constructor & Destructor Documentation

◆ PlatformViewIOS()

flutter::PlatformViewIOS::PlatformViewIOS ( PlatformView::Delegate delegate,
IOSRenderingAPI  rendering_api,
flutter::TaskRunners  task_runners 
)
explicit

Definition at line 47 of file platform_view_ios.mm.

References flutter::PlatformView::SetSemanticsEnabled(), and ~PlatformViewIOS().

50  : PlatformView(delegate, std::move(task_runners)),
51  ios_context_(IOSContext::Create(rendering_api)),
52  accessibility_bridge_([this](bool enabled) { PlatformView::SetSemanticsEnabled(enabled); }) {}
PlatformView(Delegate &delegate, TaskRunners task_runners)
Creates a platform view with the specified delegate and task runner. The base class by itself does no...
static std::unique_ptr< IOSContext > Create(IOSRenderingAPI rendering_api)
Create an iOS context object capable of creating the on-screen and off-screen GPU context for use by ...
Definition: ios_context.mm:21
virtual void SetSemanticsEnabled(bool enabled)
Used by embedder to notify the running isolate hosted by the engine on the UI thread that the accessi...

◆ ~PlatformViewIOS()

flutter::PlatformViewIOS::~PlatformViewIOS ( )
overridedefault

Referenced by PlatformViewIOS().

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

References FML_DCHECK.

Referenced by SetOwnerViewController().

100  {
101  FML_DCHECK(owner_controller_);
102  FML_DCHECK(owner_controller_.get().isViewLoaded)
103  << "FlutterViewController's view should be loaded "
104  "before attaching to PlatformViewIOS.";
105  ios_surface_ =
106  [static_cast<FlutterView*>(owner_controller_.get().view) createSurface:ios_context_];
107  FML_DCHECK(ios_surface_ != nullptr);
108 
109  if (accessibility_bridge_) {
110  accessibility_bridge_.reset(new AccessibilityBridge(
111  owner_controller_.get(), this, [owner_controller_.get() platformViewsController]));
112  }
113 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ GetDispatcherMaker()

PointerDataDispatcherMaker flutter::PlatformViewIOS::GetDispatcherMaker ( )
overridevirtual

Returns a platform-specific PointerDataDispatcherMaker so the Engine can construct the PointerDataPacketDispatcher based on platforms.

Reimplemented from flutter::PlatformView.

Definition at line 115 of file platform_view_ios.mm.

115  {
116  return [](DefaultPointerDataDispatcher::Delegate& delegate) {
117  return std::make_unique<SmoothPointerDataDispatcher>(delegate);
118  };
119 }

◆ GetOwnerViewController()

fml::WeakPtr< FlutterViewController > flutter::PlatformViewIOS::GetOwnerViewController ( ) const

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

Definition at line 65 of file platform_view_ios.mm.

Referenced by flutter::AccessibilityBridge::textInputView().

65  {
66  return owner_controller_;
67 }

◆ GetPlatformMessageRouter()

PlatformMessageRouter & flutter::PlatformViewIOS::GetPlatformMessageRouter ( )

The PlatformMessageRouter is the iOS bridge connecting the shell's platform agnostic PlatformMessage to iOS's channel message handler.

Definition at line 56 of file platform_view_ios.mm.

References flutter::PlatformMessageRouter::HandlePlatformMessage().

56  {
57  return platform_message_router_;
58 }

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

References FML_DCHECK, FML_DLOG, flutter::TaskRunners::GetRasterTaskRunner(), flutter::PlatformView::RegisterTexture(), fml::TaskRunner::RunsTasksOnCurrentThread(), and flutter::PlatformView::task_runners_.

122  {
123  RegisterTexture(ios_context_->CreateExternalTexture(
124  texture_id, fml::scoped_nsobject<NSObject<FlutterTexture>>{[texture retain]}));
125 }
void RegisterTexture(std::shared_ptr< flutter::Texture > texture)
Used by the embedder to specify a texture that it wants the rasterizer to composite within the Flutte...

◆ SetOwnerViewController()

void flutter::PlatformViewIOS::SetOwnerViewController ( fml::WeakPtr< 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 69 of file platform_view_ios.mm.

References attachView(), FlutterViewControllerWillDealloc, FML_DCHECK, flutter::TaskRunners::GetPlatformTaskRunner(), flutter::PlatformView::NotifyDestroyed(), fml::TaskRunner::RunsTasksOnCurrentThread(), and flutter::PlatformView::task_runners_.

Referenced by FlutterEngine::ensureSemanticsEnabled.

69  {
71  std::lock_guard<std::mutex> guard(ios_surface_mutex_);
72  if (ios_surface_ || !owner_controller) {
74  ios_surface_.reset();
75  accessibility_bridge_.reset();
76  }
77  owner_controller_ = owner_controller;
78 
79  // Add an observer that will clear out the owner_controller_ ivar and
80  // the accessibility_bridge_ in case the view controller is deleted.
81  dealloc_view_controller_observer_.reset(
82  [[[NSNotificationCenter defaultCenter] addObserverForName:FlutterViewControllerWillDealloc
83  object:owner_controller_.get()
84  queue:[NSOperationQueue mainQueue]
85  usingBlock:^(NSNotification* note) {
86  // Implicit copy of 'this' is fine.
87  accessibility_bridge_.reset();
88  owner_controller_.reset();
89  }] retain]);
90 
91  if (owner_controller_ && [owner_controller_.get() isViewLoaded]) {
92  this->attachView();
93  }
94  // Do not call `NotifyCreated()` here - let FlutterViewController take care
95  // of that when its Viewport is sized. If `NotifyCreated()` is called here,
96  // it can occasionally get invoked before the viewport is sized resulting in
97  // a framebuffer that will not be able to completely attach.
98 }
#define FML_DCHECK(condition)
Definition: logging.h:86
const TaskRunners task_runners_
fml::RefPtr< fml::TaskRunner > GetPlatformTaskRunner() const
Definition: task_runners.cc:30
virtual void NotifyDestroyed()
Used by embedders to notify the shell that the platform view has been destroyed. This notification us...
NSNotificationName const FlutterViewControllerWillDealloc
virtual bool RunsTasksOnCurrentThread()
Definition: task_runner.cc:43

◆ SetSemanticsEnabled()

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

Used by embedder to notify the running isolate hosted by the engine on the UI thread that the accessibility tree needs to be generated.

Attention
Subclasses may choose to override this method to perform platform specific functions. However, they must call the base class method at some point in their implementation.
Parameters
[in]enabledWhether the accessibility tree needs to be generated.

Reimplemented from flutter::PlatformView.

Definition at line 145 of file platform_view_ios.mm.

References flutter::flags, FlutterSemanticsUpdateNotification, FML_DCHECK, FML_LOG, flutter::PlatformView::SetAccessibilityFeatures(), flutter::PlatformView::SetSemanticsEnabled(), and flutter::PlatformView::task_runners_.

145  {
146  if (!owner_controller_) {
147  FML_LOG(WARNING) << "Could not set semantics to enabled, this "
148  "PlatformViewIOS has no ViewController.";
149  return;
150  }
151  if (enabled && !accessibility_bridge_) {
152  accessibility_bridge_.reset(new AccessibilityBridge(
153  owner_controller_.get(), this, [owner_controller_.get() platformViewsController]));
154  } else if (!enabled && accessibility_bridge_) {
155  accessibility_bridge_.reset();
156  } else {
158  }
159 }
#define FML_LOG(severity)
Definition: logging.h:65
virtual void SetSemanticsEnabled(bool enabled)
Used by embedder to notify the running isolate hosted by the engine on the UI thread that the accessi...

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