diff --git a/shell/platform/darwin/ios/framework/Source/FlutterView.h b/shell/platform/darwin/ios/framework/Source/FlutterView.h index 73f597f5cfafafd13c0ffcdc4a493a855f676649..ee7110446c2f6d31c4de05d0824f9695a49b9b36 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterView.h +++ b/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/shell/platform/darwin/ios/framework/Source/FlutterView.mm b/shell/platform/darwin/ios/framework/Source/FlutterView.mm index f60f114f2ea1c89bb328357a53f04207c3a39e85..5cddc9708bd23424c03103537385ab005fa2c411 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterView.mm +++ b/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/shell/platform/darwin/ios/ios_gl_context.mm b/shell/platform/darwin/ios/ios_gl_context.mm index c80919a7cab3cde1303b0659f6385dab401d94b6..74e98b223aaf9dae2bf6428f570ed9c677602e19 100644 --- a/shell/platform/darwin/ios/ios_gl_context.mm +++ b/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/shell/platform/darwin/ios/ios_surface_gl.h b/shell/platform/darwin/ios/ios_surface_gl.h index 93fcc0f510624e5f2bcd9716eb56910e5a5fab50..7de1e00a31ee5c2bad8c7b1aa08e6627b252ec19 100644 --- a/shell/platform/darwin/ios/ios_surface_gl.h +++ b/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/shell/platform/darwin/ios/ios_surface_gl.mm b/shell/platform/darwin/ios/ios_surface_gl.mm index cd0bb093d87d491e78f8b1afe0c6cffb7b50e0ad..2c7ab3a2d13bd6ccf6c93506d2b5c55cd2a15dc7 100644 --- a/shell/platform/darwin/ios/ios_surface_gl.mm +++ b/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/shell/platform/darwin/ios/platform_view_ios.h b/shell/platform/darwin/ios/platform_view_ios.h index b7495b90fec515d76c94b892ff2030bb5170af40..b38a72b653d33c1ef40caefeb1257d7f646abc82 100644 --- a/shell/platform/darwin/ios/platform_view_ios.h +++ b/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/shell/platform/darwin/ios/platform_view_ios.mm b/shell/platform/darwin/ios/platform_view_ios.mm index c0b988be882eab1a4cb60d81b3b8ceee035b113c..b6e94649e3cc04bb40c1c30155f6c72d7bec5f60 100644 --- a/shell/platform/darwin/ios/platform_view_ios.mm +++ b/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; }