diff --git a/shell/platform/darwin/macos/framework/Source/FlutterOpenGLRenderer.h b/shell/platform/darwin/macos/framework/Source/FlutterOpenGLRenderer.h index 7d9c19e522b36..86990f1c8a628 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterOpenGLRenderer.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterOpenGLRenderer.h @@ -23,6 +23,11 @@ NS_ASSUME_NONNULL_BEGIN */ @property(nonatomic, readonly, nullable) NSOpenGLContext* resourceContext; +/** + * The main OpenGL which will be used for rendering contents to the FlutterView. + */ +@property(readwrite, nonatomic, nonnull) NSOpenGLContext* openGLContext; + /** * Intializes the renderer with the given FlutterEngine. */ diff --git a/shell/platform/darwin/macos/framework/Source/FlutterOpenGLRenderer.mm b/shell/platform/darwin/macos/framework/Source/FlutterOpenGLRenderer.mm index 8ae9a2f98d977..3893d17562439 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterOpenGLRenderer.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterOpenGLRenderer.mm @@ -72,7 +72,6 @@ - (instancetype)initWithFlutterEngine:(FLUTTER_API_SYMBOL(FlutterEngine))engine - (void)attachToFlutterView:(FlutterView*)view { _flutterView = view; - _openGLContext = view.openGLContext; } - (bool)makeCurrent { @@ -112,6 +111,15 @@ - (NSOpenGLContext*)resourceContext { return _resourceContext; } +- (NSOpenGLContext*)openGLContext { + if (!_openGLContext) { + NSOpenGLContext* shareContext = [self resourceContext]; + _openGLContext = [[NSOpenGLContext alloc] initWithFormat:shareContext.pixelFormat + shareContext:shareContext]; + } + return _openGLContext; +} + - (bool)makeResourceCurrent { [self.resourceContext makeCurrentContext]; return true; diff --git a/shell/platform/darwin/macos/framework/Source/FlutterView.h b/shell/platform/darwin/macos/framework/Source/FlutterView.h index cd96f58a2291c..611c57b11d8f4 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterView.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterView.h @@ -20,19 +20,14 @@ */ @interface FlutterView : NSView -/** - * The OpenGL context of backing surface. - */ -@property(readwrite, nonatomic, nonnull) NSOpenGLContext* openGLContext; - - (nullable instancetype)initWithFrame:(NSRect)frame - shareContext:(nonnull NSOpenGLContext*)shareContext + mainContext:(nonnull NSOpenGLContext*)mainContext reshapeListener:(nonnull id)reshapeListener NS_DESIGNATED_INITIALIZER; -- (nullable instancetype)initWithShareContext:(nonnull NSOpenGLContext*)shareContext - reshapeListener: - (nonnull id)reshapeListener; +- (nullable instancetype)initWithMainContext:(nonnull NSOpenGLContext*)mainContext + reshapeListener: + (nonnull id)reshapeListener; - (nullable instancetype)initWithFrame:(NSRect)frameRect pixelFormat:(nullable NSOpenGLPixelFormat*)format NS_UNAVAILABLE; diff --git a/shell/platform/darwin/macos/framework/Source/FlutterView.mm b/shell/platform/darwin/macos/framework/Source/FlutterView.mm index d6ce889f54e81..978e09a2f1960 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterView.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterView.mm @@ -15,30 +15,29 @@ @interface FlutterView () { __weak id _reshapeListener; FlutterResizeSynchronizer* _resizeSynchronizer; FlutterSurfaceManager* _surfaceManager; + NSOpenGLContext* _openGLContext; } @end @implementation FlutterView -- (instancetype)initWithShareContext:(NSOpenGLContext*)shareContext - reshapeListener:(id)reshapeListener { - return [self initWithFrame:NSZeroRect shareContext:shareContext reshapeListener:reshapeListener]; +- (instancetype)initWithMainContext:(NSOpenGLContext*)mainContext + reshapeListener:(id)reshapeListener { + return [self initWithFrame:NSZeroRect mainContext:mainContext reshapeListener:reshapeListener]; } - (instancetype)initWithFrame:(NSRect)frame - shareContext:(NSOpenGLContext*)shareContext + mainContext:(NSOpenGLContext*)mainContext reshapeListener:(id)reshapeListener { self = [super initWithFrame:frame]; if (self) { - self.openGLContext = [[NSOpenGLContext alloc] initWithFormat:shareContext.pixelFormat - shareContext:shareContext]; - + _openGLContext = mainContext; [self setWantsLayer:YES]; _resizeSynchronizer = [[FlutterResizeSynchronizer alloc] initWithDelegate:self]; _surfaceManager = [[FlutterSurfaceManager alloc] initWithLayer:self.layer - openGLContext:self.openGLContext]; + openGLContext:_openGLContext]; _reshapeListener = reshapeListener; } @@ -46,7 +45,7 @@ - (instancetype)initWithFrame:(NSRect)frame } - (void)resizeSynchronizerFlush:(FlutterResizeSynchronizer*)synchronizer { - MacOSGLContextSwitch context_switch(self.openGLContext); + MacOSGLContextSwitch context_switch(_openGLContext); glFlush(); } diff --git a/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm b/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm index 8fce6403c754e..27f197ee5186a 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm @@ -239,13 +239,13 @@ - (instancetype)initWithProject:(nullable FlutterDartProject*)project { } - (void)loadView { - NSOpenGLContext* resourceContext = _engine.openGLRenderer.resourceContext; - if (!resourceContext) { - NSLog(@"Unable to create FlutterView; no resource context available."); + NSOpenGLContext* mainContext = _engine.openGLRenderer.openGLContext; + if (!mainContext) { + NSLog(@"Unable to create FlutterView; no GL context available."); return; } - FlutterView* flutterView = [[FlutterView alloc] initWithShareContext:resourceContext - reshapeListener:self]; + FlutterView* flutterView = [[FlutterView alloc] initWithMainContext:mainContext + reshapeListener:self]; self.view = flutterView; }