| Flutter iOS Embedder |

Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
flutter::IOSContext Class Referenceabstract

Manages the lifetime of the on-screen and off-screen rendering contexts on iOS. On-screen contexts are used by Flutter for rendering into the surface. The lifecycle of this context may be tied to the lifecycle of the surface. On the other hand, the lifecycle of the off-screen context it tied to that of the platform view. This one object used to manage both context because GPU handles may need to be shared between the two context. To achieve this, context may need references to one another at creation time. This one object manages the creation, use and collection of both contexts in a client rendering API agnostic manner. More...

`#include <ios_context.h>`

Inheritance diagram for flutter::IOSContext:

## Public Member Functions
virtual | ~IOSContext ()
| Collects the context object. This must happen on the thread on which this object was created. More...
virtual IOSRenderingBackend | GetBackend () const
| Get the rendering backend used by this context. More...
virtual sk_sp< GrDirectContext > | CreateResourceContext ()=0
| Create a resource context for use on the IO task runner. This resource context is used by Skia to upload texture to asynchronously and collect resources that are no longer needed on the render task runner. More...
virtual std::unique_ptr< GLContextResult > | MakeCurrent ()=0
| When using client rendering APIs whose contexts need to be bound to a specific thread, the engine will call this method to give the on-screen context a chance to bind to the current thread. More...
virtual std::unique_ptr< Texture > | CreateExternalTexture (int64_t texture_id, fml::scoped_nsobject< NSObject< FlutterTexture >> texture)=0
| Creates an external texture proxy of the appropriate client rendering API. More...
virtual sk_sp< GrDirectContext > | GetMainContext () const =0
| Accessor for the Skia context associated with IOSSurfaces and the raster thread. More...
virtual std::shared_ptr< impeller::Context > | GetImpellerContext () const
MsaaSampleCount | GetMsaaSampleCount () const

## Static Public Member Functions
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 Skia. More...

## Protected Member Functions
| IOSContext (MsaaSampleCount msaa_samples)

## Detailed Description

Manages the lifetime of the on-screen and off-screen rendering contexts on iOS. On-screen contexts are used by Flutter for rendering into the surface. The lifecycle of this context may be tied to the lifecycle of the surface. On the other hand, the lifecycle of the off-screen context it tied to that of the platform view. This one object used to manage both context because GPU handles may need to be shared between the two context. To achieve this, context may need references to one another at creation time. This one object manages the creation, use and collection of both contexts in a client rendering API agnostic manner.

Definition at line 40 of file ios_context.h.

## Constructor & Destructor Documentation

## ◆ ~IOSContext()

flutter::IOSContext::~IOSContext | ( |  | ) |
| virtual default

Collects the context object. This must happen on the thread on which this object was created.

## ◆ IOSContext()

flutter::IOSContext::IOSContext | ( | MsaaSampleCount | msaa_samples | ) |
| explicit protected

Definition at line 18 of file ios_context.mm.

18 : msaa_samples_(msaa_samples) {}

## Member Function Documentation

## ◆ Create()

std::unique_ptr< IOSContext > flutter::IOSContext::Create | ( | IOSRenderingAPI | api,
|  | IOSRenderingBackend | backend,
|  | MsaaSampleCount | msaa_samples,
|  | const std::shared_ptr< const fml::SyncSwitch > & | is_gpu_disabled_sync_switch
| ) |  |
| static

Create an iOS context object capable of creating the on-screen and off-screen GPU context for use by Skia.

In case the engine does not support the specified client rendering API, this a `nullptr` may be returned.

Parameters

  [in] | api | A client rendering API supported by the engine/platform.
  [in] | backend | A client rendering backend supported by the engine/platform.
  [in] | msaa_samples | The number of MSAA samples to use. Only supplied to Skia, must be either 0, 1, 2, 4, or 8.

Returns
  A valid context on success. `nullptr` on failure.

Definition at line 22 of file ios_context.mm.

26 {
27 switch (api) {
28 case IOSRenderingAPI::kSoftware:
29 FML_CHECK(backend != IOSRenderingBackend::kImpeller)
30 << "Software rendering is incompatible with Impeller.\n"
31 "Software rendering may have been automatically selected when running on a simulator "
32 "in an environment that does not support Metal. Enabling GPU pass through in your "
33 "environment may fix this. If that is not possible, then disable Impeller.";
34 return std::make_unique<IOSContextSoftware>();
35 #if SHELL_ENABLE_METAL
36 case IOSRenderingAPI::kMetal:
37 switch (backend) {
38 case IOSRenderingBackend::kSkia:
39 return std::make_unique<IOSContextMetalSkia>(msaa_samples);
40 case IOSRenderingBackend::kImpeller:
41 return std::make_unique<IOSContextMetalImpeller>(is_gpu_disabled_sync_switch);
42 }
43 #endif // SHELL_ENABLE_METAL
44 default:
45 break;
46 }
47 FML_CHECK(false);
48 return nullptr;
49 }

References flutter::kImpeller, flutter::kMetal, flutter::kSkia, and flutter::kSoftware.

## ◆ CreateExternalTexture()

virtual std::unique_ptr<Texture> flutter::IOSContext::CreateExternalTexture | ( | int64_t | texture_id,
|  | fml::scoped_nsobject< NSObject< FlutterTexture >> | texture
| ) |  |
| pure virtual

Creates an external texture proxy of the appropriate client rendering API.

Parameters

  [in] | texture_id | The texture identifier
  [in] | texture | The texture

Returns
  The texture proxy if the rendering backend supports embedder provided external textures.

Implemented in flutter::IOSContextSoftware.

## ◆ CreateResourceContext()

virtual sk_sp<GrDirectContext> flutter::IOSContext::CreateResourceContext | ( |  | ) |
| pure virtual

Create a resource context for use on the IO task runner. This resource context is used by Skia to upload texture to asynchronously and collect resources that are no longer needed on the render task runner.

Attention
  Client rendering APIs for which a GrDirectContext cannot be realized (software rendering), this method will always return null.

Returns
  A non-null Skia context on success. `nullptr` on failure.

Implemented in flutter::IOSContextSoftware.

## ◆ GetBackend()

IOSRenderingBackend flutter::IOSContext::GetBackend | ( |  | ) | const
| virtual

Get the rendering backend used by this context.

Returns
  The rendering backend.

Reimplemented in flutter::IOSContextMetalImpeller, and flutter::IOSContextMetalSkia.

Definition at line 51 of file ios_context.mm.

51 {
52 return IOSRenderingBackend::kSkia;
53 }

References flutter::kSkia.

## ◆ GetImpellerContext()

std::shared_ptr< impeller::Context > flutter::IOSContext::GetImpellerContext | ( |  | ) | const
| virtual

Definition at line 55 of file ios_context.mm.

55 {
56 return nullptr;
57 }

## ◆ GetMainContext()

virtual sk_sp<GrDirectContext> flutter::IOSContext::GetMainContext | ( |  | ) | const
| pure virtual

Accessor for the Skia context associated with IOSSurfaces and the raster thread.

There can be any number of resource contexts but this is the one context that will be used by surfaces to draw to the screen from the raster thread.

Returns
  `nullptr` on failure.

Attention
  The software context doesn't have a Skia context, so this value will be nullptr.

See also
  For contexts which are used for offscreen work like loading textures see IOSContext::CreateResourceContext.

Implemented in flutter::IOSContextMetalImpeller, flutter::IOSContextMetalSkia, and flutter::IOSContextSoftware.

## ◆ GetMsaaSampleCount()

MsaaSampleCount flutter::IOSContext::GetMsaaSampleCount | ( |  | ) | const
| inline

Definition at line 148 of file ios_context.h.

148 { return msaa_samples_; }

## ◆ MakeCurrent()

virtual std::unique_ptr<GLContextResult> flutter::IOSContext::MakeCurrent | ( |  | ) |
| pure virtual

When using client rendering APIs whose contexts need to be bound to a specific thread, the engine will call this method to give the on-screen context a chance to bind to the current thread.

Attention
  Client rendering APIs that have no-concept of thread local bindings (anything that is not OpenGL) will always return `true`.
  Client rendering APIs for which a GrDirectContext cannot be created (software rendering) will always return `false`.
  This binds the on-screen context to the current thread. To bind the off-screen context to the thread, use the `ResoruceMakeCurrent` method instead.
  Only one context may be bound to a thread at any given time. Making a binding on a thread, clears the old binding.

Returns
  A GLContextResult that represents the result of the method. The GetResult() returns a bool that indicates If the on-screen context could be bound to the current thread.

Implemented in flutter::IOSContextSoftware.

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

- shell/platform/darwin/ios/ios_context.h
- shell/platform/darwin/ios/ios_context.mm

flutter::IOSRenderingBackend::kSkia
@ kSkia
flutter::IOSRenderingBackend::kImpeller
@ kImpeller
flutter::IOSRenderingAPI::kMetal
@ kMetal
flutter::IOSRenderingAPI::kSoftware
@ kSoftware