diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h index 73f597f5cfa..ee7110446c2 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h @@ -33,7 +33,7 @@ - (instancetype)initWithDelegate:(id)delegate opaque:(BOOL)opaque NS_DESIGNATED_INITIALIZER; -- (std::unique_ptr)createSurface; +- (std::unique_ptr)createSurface:(std::shared_ptr)context; @end diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm index f60f114f2ea..5cddc9708bd 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm @@ -75,7 +75,7 @@ id _delegate; #endif // TARGET_IPHONE_SIMULATOR } -- (std::unique_ptr)createSurface { +- (std::unique_ptr)createSurface:(std::shared_ptr)context { if ([self.layer isKindOfClass:[CAEAGLLayer class]]) { fml::scoped_nsobject eagl_layer( reinterpret_cast([self.layer retain])); @@ -88,7 +88,7 @@ id _delegate; eagl_layer.get().presentsWithTransaction = YES; } } - return std::make_unique(std::move(eagl_layer), + return std::make_unique(context, std::move(eagl_layer), [_delegate platformViewsController]); } else { fml::scoped_nsobject layer(reinterpret_cast([self.layer retain])); diff --git a/engine/src/flutter/shell/platform/darwin/ios/ios_gl_context.mm b/engine/src/flutter/shell/platform/darwin/ios/ios_gl_context.mm index c80919a7cab..74e98b223aa 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/ios_gl_context.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/ios_gl_context.mm @@ -13,14 +13,14 @@ namespace shell { IOSGLContext::IOSGLContext() { - context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]); - if (context_ != nullptr) { - resource_context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3 - sharegroup:context_.get().sharegroup]); + resource_context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]); + if (resource_context_ != nullptr) { + context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3 + sharegroup:resource_context_.get().sharegroup]); } else { - context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]); - resource_context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 - sharegroup:context_.get().sharegroup]); + resource_context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]); + context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 + sharegroup:resource_context_.get().sharegroup]); } // TODO: diff --git a/engine/src/flutter/shell/platform/darwin/ios/ios_surface_gl.h b/engine/src/flutter/shell/platform/darwin/ios/ios_surface_gl.h index 93fcc0f5106..7de1e00a31e 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/ios_surface_gl.h +++ b/engine/src/flutter/shell/platform/darwin/ios/ios_surface_gl.h @@ -20,7 +20,8 @@ class IOSSurfaceGL : public IOSSurface, public GPUSurfaceGLDelegate, public flow::ExternalViewEmbedder { public: - IOSSurfaceGL(fml::scoped_nsobject layer, + IOSSurfaceGL(std::shared_ptr context, + fml::scoped_nsobject layer, FlutterPlatformViewsController* platform_views_controller); IOSSurfaceGL(fml::scoped_nsobject layer, std::shared_ptr context); diff --git a/engine/src/flutter/shell/platform/darwin/ios/ios_surface_gl.mm b/engine/src/flutter/shell/platform/darwin/ios/ios_surface_gl.mm index cd0bb093d87..2c7ab3a2d13 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/ios_surface_gl.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/ios_surface_gl.mm @@ -9,10 +9,10 @@ namespace shell { -IOSSurfaceGL::IOSSurfaceGL(fml::scoped_nsobject layer, +IOSSurfaceGL::IOSSurfaceGL(std::shared_ptr context, + fml::scoped_nsobject layer, FlutterPlatformViewsController* platform_views_controller) - : IOSSurface(platform_views_controller) { - context_ = std::make_shared(); + : IOSSurface(platform_views_controller), context_(context) { render_target_ = context_->CreateRenderTarget(std::move(layer)); } @@ -29,7 +29,7 @@ bool IOSSurfaceGL::IsValid() const { } bool IOSSurfaceGL::ResourceContextMakeCurrent() { - return render_target_->IsValid() ? context_->ResourceMakeCurrent() : false; + return context_->ResourceMakeCurrent(); } void IOSSurfaceGL::UpdateStorageSizeIfNecessary() { diff --git a/engine/src/flutter/shell/platform/darwin/ios/platform_view_ios.h b/engine/src/flutter/shell/platform/darwin/ios/platform_view_ios.h index b7495b90fec..b38a72b653d 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/platform_view_ios.h +++ b/engine/src/flutter/shell/platform/darwin/ios/platform_view_ios.h @@ -17,6 +17,7 @@ #include "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h" #include "flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h" #include "flutter/shell/platform/darwin/ios/framework/Source/platform_message_router.h" +#include "flutter/shell/platform/darwin/ios/ios_gl_context.h" #include "flutter/shell/platform/darwin/ios/ios_surface.h" @class FlutterViewController; @@ -46,6 +47,7 @@ class PlatformViewIOS final : public PlatformView { private: fml::WeakPtr owner_controller_; std::unique_ptr ios_surface_; + std::shared_ptr gl_context_; PlatformMessageRouter platform_message_router_; std::unique_ptr accessibility_bridge_; fml::scoped_nsprotocol text_input_plugin_; diff --git a/engine/src/flutter/shell/platform/darwin/ios/platform_view_ios.mm b/engine/src/flutter/shell/platform/darwin/ios/platform_view_ios.mm index c0b988be882..b6e94649e3c 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/platform_view_ios.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/platform_view_ios.mm @@ -20,7 +20,11 @@ namespace shell { PlatformViewIOS::PlatformViewIOS(PlatformView::Delegate& delegate, blink::TaskRunners task_runners) - : PlatformView(delegate, std::move(task_runners)) {} + : PlatformView(delegate, std::move(task_runners)) { +#if !TARGET_IPHONE_SIMULATOR + gl_context_ = std::make_shared(); +#endif // !TARGET_IPHONE_SIMULATOR +} PlatformViewIOS::~PlatformViewIOS() = default; @@ -45,7 +49,8 @@ void PlatformViewIOS::SetOwnerViewController(fml::WeakPtr } owner_controller_ = owner_controller; if (owner_controller_) { - ios_surface_ = static_cast(owner_controller.get().view).createSurface; + ios_surface_ = + [static_cast(owner_controller.get().view) createSurface:gl_context_]; FML_DCHECK(ios_surface_ != nullptr); if (accessibility_bridge_) { @@ -77,10 +82,10 @@ std::unique_ptr PlatformViewIOS::CreateRenderingSurface() { // |shell::PlatformView| sk_sp PlatformViewIOS::CreateResourceContext() const { - if (!ios_surface_ || !ios_surface_->ResourceContextMakeCurrent()) { + if (!gl_context_ || !gl_context_->ResourceMakeCurrent()) { FML_DLOG(INFO) << "Could not make resource context current on IO thread. " - "Async texture uploads " - "will be disabled."; + "Async texture uploads will be disabled. On Simulators, " + "this is expected."; return nullptr; }