Skip to content

Commit f217e5b

Browse files
committed
Revert "[macOS] Move the glContext generation to FlutterOpenGLRenderer (flutter#22572)"
This reverts commit be5cf15.
1 parent cfdcfca commit f217e5b

5 files changed

Lines changed: 24 additions & 31 deletions

File tree

shell/platform/darwin/macos/framework/Source/FlutterOpenGLRenderer.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ NS_ASSUME_NONNULL_BEGIN
2323
*/
2424
@property(nonatomic, readonly, nullable) NSOpenGLContext* resourceContext;
2525

26-
/**
27-
* The main OpenGL which will be used for rendering contents to the FlutterView.
28-
*/
29-
@property(readwrite, nonatomic, nonnull) NSOpenGLContext* openGLContext;
30-
3126
/**
3227
* Intializes the renderer with the given FlutterEngine.
3328
*/

shell/platform/darwin/macos/framework/Source/FlutterOpenGLRenderer.mm

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ - (instancetype)initWithFlutterEngine:(FLUTTER_API_SYMBOL(FlutterEngine))engine
7272

7373
- (void)attachToFlutterView:(FlutterView*)view {
7474
_flutterView = view;
75+
_openGLContext = view.openGLContext;
7576
}
7677

7778
- (bool)makeCurrent {
@@ -111,15 +112,6 @@ - (NSOpenGLContext*)resourceContext {
111112
return _resourceContext;
112113
}
113114

114-
- (NSOpenGLContext*)openGLContext {
115-
if (!_openGLContext) {
116-
NSOpenGLContext* shareContext = [self resourceContext];
117-
_openGLContext = [[NSOpenGLContext alloc] initWithFormat:shareContext.pixelFormat
118-
shareContext:shareContext];
119-
}
120-
return _openGLContext;
121-
}
122-
123115
- (bool)makeResourceCurrent {
124116
[self.resourceContext makeCurrentContext];
125117
return true;

shell/platform/darwin/macos/framework/Source/FlutterView.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,19 @@
2020
*/
2121
@interface FlutterView : NSView
2222

23+
/**
24+
* The OpenGL context of backing surface.
25+
*/
26+
@property(readwrite, nonatomic, nonnull) NSOpenGLContext* openGLContext;
27+
2328
- (nullable instancetype)initWithFrame:(NSRect)frame
24-
mainContext:(nonnull NSOpenGLContext*)mainContext
29+
shareContext:(nonnull NSOpenGLContext*)shareContext
2530
reshapeListener:(nonnull id<FlutterViewReshapeListener>)reshapeListener
2631
NS_DESIGNATED_INITIALIZER;
2732

28-
- (nullable instancetype)initWithMainContext:(nonnull NSOpenGLContext*)mainContext
29-
reshapeListener:
30-
(nonnull id<FlutterViewReshapeListener>)reshapeListener;
33+
- (nullable instancetype)initWithShareContext:(nonnull NSOpenGLContext*)shareContext
34+
reshapeListener:
35+
(nonnull id<FlutterViewReshapeListener>)reshapeListener;
3136

3237
- (nullable instancetype)initWithFrame:(NSRect)frameRect
3338
pixelFormat:(nullable NSOpenGLPixelFormat*)format NS_UNAVAILABLE;

shell/platform/darwin/macos/framework/Source/FlutterView.mm

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,38 @@ @interface FlutterView () <FlutterResizeSynchronizerDelegate> {
1515
__weak id<FlutterViewReshapeListener> _reshapeListener;
1616
FlutterResizeSynchronizer* _resizeSynchronizer;
1717
FlutterSurfaceManager* _surfaceManager;
18-
NSOpenGLContext* _openGLContext;
1918
}
2019

2120
@end
2221

2322
@implementation FlutterView
2423

25-
- (instancetype)initWithMainContext:(NSOpenGLContext*)mainContext
26-
reshapeListener:(id<FlutterViewReshapeListener>)reshapeListener {
27-
return [self initWithFrame:NSZeroRect mainContext:mainContext reshapeListener:reshapeListener];
24+
- (instancetype)initWithShareContext:(NSOpenGLContext*)shareContext
25+
reshapeListener:(id<FlutterViewReshapeListener>)reshapeListener {
26+
return [self initWithFrame:NSZeroRect shareContext:shareContext reshapeListener:reshapeListener];
2827
}
2928

3029
- (instancetype)initWithFrame:(NSRect)frame
31-
mainContext:(NSOpenGLContext*)mainContext
30+
shareContext:(NSOpenGLContext*)shareContext
3231
reshapeListener:(id<FlutterViewReshapeListener>)reshapeListener {
3332
self = [super initWithFrame:frame];
3433
if (self) {
35-
_openGLContext = mainContext;
34+
self.openGLContext = [[NSOpenGLContext alloc] initWithFormat:shareContext.pixelFormat
35+
shareContext:shareContext];
36+
3637
[self setWantsLayer:YES];
3738

3839
_resizeSynchronizer = [[FlutterResizeSynchronizer alloc] initWithDelegate:self];
3940
_surfaceManager = [[FlutterSurfaceManager alloc] initWithLayer:self.layer
40-
openGLContext:_openGLContext];
41+
openGLContext:self.openGLContext];
4142

4243
_reshapeListener = reshapeListener;
4344
}
4445
return self;
4546
}
4647

4748
- (void)resizeSynchronizerFlush:(FlutterResizeSynchronizer*)synchronizer {
48-
MacOSGLContextSwitch context_switch(_openGLContext);
49+
MacOSGLContextSwitch context_switch(self.openGLContext);
4950
glFlush();
5051
}
5152

shell/platform/darwin/macos/framework/Source/FlutterViewController.mm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,13 @@ - (instancetype)initWithProject:(nullable FlutterDartProject*)project {
239239
}
240240

241241
- (void)loadView {
242-
NSOpenGLContext* mainContext = _engine.openGLRenderer.openGLContext;
243-
if (!mainContext) {
244-
NSLog(@"Unable to create FlutterView; no GL context available.");
242+
NSOpenGLContext* resourceContext = _engine.openGLRenderer.resourceContext;
243+
if (!resourceContext) {
244+
NSLog(@"Unable to create FlutterView; no resource context available.");
245245
return;
246246
}
247-
FlutterView* flutterView = [[FlutterView alloc] initWithMainContext:mainContext
248-
reshapeListener:self];
247+
FlutterView* flutterView = [[FlutterView alloc] initWithShareContext:resourceContext
248+
reshapeListener:self];
249249
self.view = flutterView;
250250
}
251251

0 commit comments

Comments
 (0)