Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ - (instancetype)initWithFlutterEngine:(FLUTTER_API_SYMBOL(FlutterEngine))engine

- (void)attachToFlutterView:(FlutterView*)view {
_flutterView = view;
_openGLContext = view.openGLContext;
}

- (bool)makeCurrent {
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 4 additions & 9 deletions shell/platform/darwin/macos/framework/Source/FlutterView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<FlutterViewReshapeListener>)reshapeListener
NS_DESIGNATED_INITIALIZER;

- (nullable instancetype)initWithShareContext:(nonnull NSOpenGLContext*)shareContext
reshapeListener:
(nonnull id<FlutterViewReshapeListener>)reshapeListener;
- (nullable instancetype)initWithMainContext:(nonnull NSOpenGLContext*)mainContext
reshapeListener:
(nonnull id<FlutterViewReshapeListener>)reshapeListener;

- (nullable instancetype)initWithFrame:(NSRect)frameRect
pixelFormat:(nullable NSOpenGLPixelFormat*)format NS_UNAVAILABLE;
Expand Down
17 changes: 8 additions & 9 deletions shell/platform/darwin/macos/framework/Source/FlutterView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,37 @@ @interface FlutterView () <FlutterResizeSynchronizerDelegate> {
__weak id<FlutterViewReshapeListener> _reshapeListener;
FlutterResizeSynchronizer* _resizeSynchronizer;
FlutterSurfaceManager* _surfaceManager;
NSOpenGLContext* _openGLContext;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm probably missing something but what's the main purpose of this refactor if FlutterView still owns the openGLContext? @iskakaushik

}

@end

@implementation FlutterView

- (instancetype)initWithShareContext:(NSOpenGLContext*)shareContext
reshapeListener:(id<FlutterViewReshapeListener>)reshapeListener {
return [self initWithFrame:NSZeroRect shareContext:shareContext reshapeListener:reshapeListener];
- (instancetype)initWithMainContext:(NSOpenGLContext*)mainContext
reshapeListener:(id<FlutterViewReshapeListener>)reshapeListener {
return [self initWithFrame:NSZeroRect mainContext:mainContext reshapeListener:reshapeListener];
}

- (instancetype)initWithFrame:(NSRect)frame
shareContext:(NSOpenGLContext*)shareContext
mainContext:(NSOpenGLContext*)mainContext
reshapeListener:(id<FlutterViewReshapeListener>)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;
}
return self;
}

- (void)resizeSynchronizerFlush:(FlutterResizeSynchronizer*)synchronizer {
MacOSGLContextSwitch context_switch(self.openGLContext);
MacOSGLContextSwitch context_switch(_openGLContext);
glFlush();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down