Flutter Engine
flutter::IOSContextGL Class Referencefinal

#include <ios_context_gl.h>

Inheritance diagram for flutter::IOSContextGL:
flutter::IOSContext

Public Member Functions

 IOSContextGL ()
 
 ~IOSContextGL () override
 
std::unique_ptr< IOSRenderTargetGLCreateRenderTarget (fml::scoped_nsobject< CAEAGLLayer > layer)
 
void SetMainContext (const sk_sp< GrDirectContext > &main_context)
 
sk_sp< GrDirectContext > CreateResourceContext () override
 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...
 
std::unique_ptr< GLContextResultMakeCurrent () override
 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...
 
std::unique_ptr< TextureCreateExternalTexture (int64_t texture_id, fml::scoped_nsobject< NSObject< FlutterTexture >> texture) override
 Creates an external texture proxy of the appropriate client rendering API. More...
 
sk_sp< GrDirectContext > GetMainContext () const override
 Accessor for the Skia context associated with IOSSurfaces and the raster thread. More...
 
- Public Member Functions inherited from flutter::IOSContext
virtual ~IOSContext ()
 Collects the context object. This must happen on the thread on which this object was created. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from flutter::IOSContext
static std::unique_ptr< IOSContextCreate (IOSRenderingAPI rendering_api)
 Create an iOS context object capable of creating the on-screen and off-screen GPU context for use by Skia. More...
 
- Protected Member Functions inherited from flutter::IOSContext
 IOSContext ()
 

Detailed Description

Definition at line 19 of file ios_context_gl.h.

Constructor & Destructor Documentation

◆ IOSContextGL()

flutter::IOSContextGL::IOSContextGL ( )

Definition at line 16 of file ios_context_gl.mm.

References fml::scoped_nsprotocol< NST >::get(), and fml::scoped_nsprotocol< NST >::reset().

16  {
17  resource_context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]);
18  if (resource_context_ != nullptr) {
19  context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3
20  sharegroup:resource_context_.get().sharegroup]);
21  } else {
22  resource_context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]);
23  context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2
24  sharegroup:resource_context_.get().sharegroup]);
25  }
26 }
void reset(NST object=nil)

◆ ~IOSContextGL()

flutter::IOSContextGL::~IOSContextGL ( )
override

Definition at line 28 of file ios_context_gl.mm.

28  {
29  if (main_context_) {
30  main_context_->releaseResourcesAndAbandonContext();
31  }
32 }

Member Function Documentation

◆ CreateExternalTexture()

std::unique_ptr< Texture > flutter::IOSContextGL::CreateExternalTexture ( int64_t  texture_id,
fml::scoped_nsobject< NSObject< FlutterTexture >>  texture 
)
overridevirtual

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

Parameters
[in]texture_idThe texture identifier
[in]textureThe texture
Returns
The texture proxy if the rendering backend supports embedder provided external textures.

Implements flutter::IOSContext.

Definition at line 67 of file ios_context_gl.mm.

References texture, and texture_id.

69  {
70  return std::make_unique<IOSExternalTextureGL>(texture_id, std::move(texture));
71 }
int64_t texture_id

◆ CreateRenderTarget()

std::unique_ptr< IOSRenderTargetGL > flutter::IOSContextGL::CreateRenderTarget ( fml::scoped_nsobject< CAEAGLLayer >  layer)

Definition at line 34 of file ios_context_gl.mm.

Referenced by flutter::IOSSurfaceGL::IOSSurfaceGL().

35  {
36  return std::make_unique<IOSRenderTargetGL>(std::move(layer), context_);
37 }

◆ CreateResourceContext()

sk_sp< GrDirectContext > flutter::IOSContextGL::CreateResourceContext ( )
overridevirtual

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.

Implements flutter::IOSContext.

Definition at line 40 of file ios_context_gl.mm.

References flutter::ShellIOManager::CreateCompatibleResourceLoadingContext(), FML_DLOG, fml::scoped_nsprotocol< NST >::get(), and flutter::GPUSurfaceGLDelegate::GetDefaultPlatformGLInterface().

40  {
41  if (![EAGLContext setCurrentContext:resource_context_.get()]) {
42  FML_DLOG(INFO) << "Could not make resource context current on IO thread. Async texture uploads "
43  "will be disabled. On Simulators, this is expected.";
44  return nullptr;
45  }
46 
48  GrBackend::kOpenGL_GrBackend, GPUSurfaceGLDelegate::GetDefaultPlatformGLInterface());
49 }
static sk_sp< GrDirectContext > CreateCompatibleResourceLoadingContext(GrBackend backend, sk_sp< const GrGLInterface > gl_interface)
#define FML_DLOG(severity)
Definition: logging.h:85
static sk_sp< const GrGLInterface > GetDefaultPlatformGLInterface()

◆ GetMainContext()

sk_sp< GrDirectContext > flutter::IOSContextGL::GetMainContext ( ) const
overridevirtual

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.

Implements flutter::IOSContext.

Definition at line 52 of file ios_context_gl.mm.

Referenced by flutter::IOSSurfaceGL::CreateGPUSurface().

52  {
53  return main_context_;
54 }

◆ MakeCurrent()

std::unique_ptr< GLContextResult > flutter::IOSContextGL::MakeCurrent ( )
overridevirtual

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.

Implements flutter::IOSContext.

Definition at line 61 of file ios_context_gl.mm.

References fml::scoped_nsprotocol< NST >::get().

61  {
62  return std::make_unique<GLContextSwitch>(
63  std::make_unique<IOSSwitchableGLContext>(context_.get()));
64 }

◆ SetMainContext()

void flutter::IOSContextGL::SetMainContext ( const sk_sp< GrDirectContext > &  main_context)

Definition at line 56 of file ios_context_gl.mm.

Referenced by flutter::IOSSurfaceGL::CreateGPUSurface().

56  {
57  main_context_ = main_context;
58 }

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