1313#include " flutter/shell/common/platform_view.h"
1414#include " flutter/shell/common/rasterizer.h"
1515#include " flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h"
16+ #include " flutter/shell/platform/darwin/ios/ios_gl_context.h"
1617#include " flutter/shell/platform/darwin/ios/ios_surface_gl.h"
1718#include " flutter/shell/platform/darwin/ios/ios_surface_software.h"
1819#include " third_party/skia/include/utils/mac/SkCGUtils.h"
2122#include " flutter/shell/platform/darwin/ios/ios_surface_metal.h"
2223#endif // FLUTTER_SHELL_ENABLE_METAL
2324
24- @implementation FlutterView
25-
26- id <FlutterViewEngineDelegate> _delegate;
25+ @implementation FlutterView {
26+ id <FlutterViewEngineDelegate> _delegate;
27+ std::unique_ptr<flutter::IOSGLContext> _onscreenGLContext;
28+ }
2729
2830- (instancetype )init {
2931 @throw ([NSException exceptionWithName: @" FlutterView must initWithDelegate"
@@ -93,8 +95,14 @@ + (Class)layerClass {
9395#endif // TARGET_IPHONE_SIMULATOR
9496}
9597
96- - (std::unique_ptr<flutter::IOSSurface>)createSurface :
97- (std::shared_ptr<flutter::IOSGLContext>)context {
98+ - (std::unique_ptr<flutter::IOSSurface>)createSurfaceWithResourceGLContext :
99+ (fml::WeakPtr<flutter::IOSGLContext>)resourceGLContext {
100+ #if !TARGET_IPHONE_SIMULATOR
101+ if (!_onscreenGLContext) {
102+ _onscreenGLContext = resourceGLContext->MakeSharedContext ();
103+ }
104+ #endif // !TARGET_IPHONE_SIMULATOR
105+
98106 if ([self .layer isKindOfClass: [CAEAGLLayer class ]]) {
99107 fml::scoped_nsobject<CAEAGLLayer> eagl_layer (
100108 reinterpret_cast <CAEAGLLayer*>([self .layer retain ]));
@@ -105,8 +113,9 @@ + (Class)layerClass {
105113 eagl_layer.get ().presentsWithTransaction = YES ;
106114 }
107115 }
108- return std::make_unique<flutter::IOSSurfaceGL>(context, std::move (eagl_layer),
109- [_delegate platformViewsController ]);
116+ return std::make_unique<flutter::IOSSurfaceGL>(
117+ _onscreenGLContext->GetWeakPtr (), std::move (resourceGLContext), std::move (eagl_layer),
118+ [_delegate platformViewsController ]);
110119#if FLUTTER_SHELL_ENABLE_METAL
111120 } else if ([self .layer isKindOfClass: [CAMetalLayer class ]]) {
112121 fml::scoped_nsobject<CAMetalLayer > metalLayer (
0 commit comments