From 939fe89d4cd8fcf1679fc31d801bee2ab1ed9a80 Mon Sep 17 00:00:00 2001 From: Matej Knopp Date: Tue, 3 Nov 2020 17:45:02 +0100 Subject: [PATCH 1/6] Fix code-style issues --- .../macos/framework/Source/FlutterEngine.mm | 13 ++- .../Source/FlutterResizeSynchronizer.h | 95 ++++++++------- .../Source/FlutterResizeSynchronizer.mm | 108 ++++++++++-------- .../framework/Source/FlutterSurfaceManager.h | 3 +- .../framework/Source/FlutterSurfaceManager.mm | 35 +++--- .../macos/framework/Source/FlutterView.h | 19 ++- .../macos/framework/Source/FlutterView.mm | 31 ++--- 7 files changed, 179 insertions(+), 125 deletions(-) diff --git a/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm b/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm index 0ef5ad9654ef6..45c6a003f7958 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm @@ -62,6 +62,11 @@ - (bool)engineCallbackOnClearCurrent; */ - (bool)engineCallbackOnPresent; +/** + * Called by the engine when framebuffer object ID is requested. + */ +- (uint32_t)engineCallbackOnFBO:(const FlutterFrameInfo*)info; + /** * Makes the resource context the current context. */ @@ -155,8 +160,7 @@ static bool OnPresent(FlutterEngine* engine) { } static uint32_t OnFBO(FlutterEngine* engine, const FlutterFrameInfo* info) { - CGSize size = CGSizeMake(info->size.width, info->size.height); - return [engine.viewController.flutterView getFrameBufferIdForSize:size]; + return [engine engineCallbackOnFBO:info]; } static bool OnMakeResourceCurrent(FlutterEngine* engine) { @@ -473,6 +477,11 @@ - (bool)engineCallbackOnMakeCurrent { return true; } +- (uint32_t)engineCallbackOnFBO:(const FlutterFrameInfo*)info { + CGSize size = CGSizeMake(info->size.width, info->size.height); + return [_viewController.flutterView frameBufferIDForSize:size]; +} + - (bool)engineCallbackOnClearCurrent { [NSOpenGLContext clearCurrentContext]; return true; diff --git a/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h b/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h index fe9a0bde6f1f5..b2189ac88e880 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h @@ -2,58 +2,73 @@ @class FlutterResizeSynchronizer; +/** + * Implemented by FlutterView. + */ @protocol FlutterResizeSynchronizerDelegate -// Invoked on raster thread; Delegate should flush the OpenGL context -- (void)resizeSynchronizerFlush:(FlutterResizeSynchronizer*)synchronizer; +/** + * Invoked on raster thread; Delegate should flush the OpenGL context. + */ +- (void)resizeSynchronizerFlush:(nonnull FlutterResizeSynchronizer*)synchronizer; -// Invoked on platform thread; Delegate should flip the surfaces -- (void)resizeSynchronizerCommit:(FlutterResizeSynchronizer*)synchronizer; +/** + * Invoked on platform thread; Delegate should flip the surfaces. + */ +- (void)resizeSynchronizerCommit:(nonnull FlutterResizeSynchronizer*)synchronizer; @end -// Encapsulates the logic for blocking platform thread during window resize as -// well as synchronizing the raster and platform thread during commit (presenting frame) -// -// Flow during window resize -// -// 1. Platform thread calls [synchronizer beginResize:notify:] -// This will hold the platform thread until we're ready to display contents. -// 2. Raster thread calls [synchronizer shouldEnsureSurfaceForSize:] with target size -// This will return false for any size other than target size -// 3. Raster thread calls [synchronizer requestCommit] -// Any commit calls before shouldEnsureSurfaceForSize: is called with the right -// size are simply ignored; There's no point rasterizing and displaying frames -// with wrong size. -// Both delegate methods (flush/commit) will be invoked before beginResize returns -// -// Flow during regular operation (no resizing) -// -// 1. Raster thread calls [synchronizer requestCommit] -// This will invoke [delegate flush:] on raster thread and -// [delegate commit:] on platform thread. The requestCommit call will be blocked -// until this is done. This is necessary to ensure that rasterizer won't start -// rasterizing next frame before we flipped the surface, which must be performed -// on platform thread +/** + * Encapsulates the logic for blocking platform thread during window resize as + * well as synchronizing the raster and platform thread during commit (presenting frame). + * + * Flow during window resize + * + * 1. Platform thread calls [synchronizer beginResize:notify:] + * This will hold the platform thread until we're ready to display contents. + * 2. Raster thread calls [synchronizer shouldEnsureSurfaceForSize:] with target size + * This will return false for any size other than target size + * 3. Raster thread calls [synchronizer requestCommit] + * Any commit calls before shouldEnsureSurfaceForSize: is called with the right + * size are simply ignored; There's no point rasterizing and displaying frames + * with wrong size. + * Both delegate methods (flush/commit) will be invoked before beginResize returns + * + * Flow during regular operation (no resizing) + * + * 1. Raster thread calls [synchronizer requestCommit] + * This will invoke [delegate flush:] on raster thread and + * [delegate commit:] on platform thread. The requestCommit call will be blocked + * until this is done. This is necessary to ensure that rasterizer won't start + * rasterizing next frame before we flipped the surface, which must be performed + * on platform thread + */ @interface FlutterResizeSynchronizer : NSObject -- (instancetype)initWithDelegate:(id)delegate; +- (nullable instancetype)initWithDelegate:(nonnull id)delegate; -// Blocks the platform thread until -// - shouldEnsureSurfaceForSize is called with proper size and -// - requestCommit is called -// All requestCommit calls before `shouldEnsureSurfaceForSize` is called with -// expected size are ignored; -// The notify block is invoked immediately after synchronizer mutex is acquired -- (void)beginResize:(CGSize)size notify:(dispatch_block_t)notify; +/** + * Blocks the platform thread until + * - shouldEnsureSurfaceForSize is called with proper size and + * - requestCommit is called + * All requestCommit calls before `shouldEnsureSurfaceForSize` is called with + * expected size are ignored; + * The notify block is invoked immediately after synchronizer mutex is acquired. + */ +- (void)beginResize:(CGSize)size notify:(nonnull dispatch_block_t)notify; -// Returns whether the view should ensure surfaces with given size; -// This will be false during resizing for any size other than size specified -// during beginResize +/** + * Returns whether the view should ensure surfaces with given size; + * This will be false during resizing for any size other than size specified + * during beginResize. + */ - (bool)shouldEnsureSurfaceForSize:(CGSize)size; -// Called from rasterizer thread, will block until delegate resizeSynchronizerCommit: -// method is called (on platform thread) +/** + * Called from rasterizer thread, will block until delegate resizeSynchronizerCommit: + * method is called (on platform thread). + */ - (void)requestCommit; @end diff --git a/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.mm b/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.mm index 2e1eef3eff389..0e7c3b2522317 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.mm @@ -1,103 +1,113 @@ #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h" -#import +#include @interface FlutterResizeSynchronizer () { - uint32_t cookie; // counter to detect stale callbacks + // counter to detect stale callbacks + uint32_t _cookie; - std::mutex mutex; - std::condition_variable condBlockBeginResize; // used to block [beginResize:] - std::condition_variable condBlockRequestCommit; // used to block [requestCommit] + std::mutex _mutex; - bool acceptingCommit; // if false, requestCommit calls are ignored until - // shouldEnsureSurfaceForSize is called with proper size - bool waiting; // waiting for resize to finish - bool pendingCommit; // requestCommit was called and [delegate commit:] must be performed on - // platform thread - CGSize newSize; // target size for resizing + // used to block [beginResize:] + std::condition_variable _condBlockBeginResize; + // used to block [requestCommit] + std::condition_variable _condBlockRequestCommit; - __weak id delegate; + // if NO, requestCommit calls are ignored until shouldEnsureSurfaceForSize is called with + // proper size + BOOL _acceptingCommit; + + // waiting for resize to finish + BOOL _waiting; + + // requestCommit was called and [delegate commit:] must be performed on platform thread + BOOL _pendingCommit; + + // target size for resizing + CGSize _newSize; + + __weak id _delegate; } @end @implementation FlutterResizeSynchronizer -- (instancetype)initWithDelegate:(id)delegate_ { +- (instancetype)initWithDelegate:(id)delegate { if (self = [super init]) { - acceptingCommit = true; - delegate = delegate_; + _acceptingCommit = YES; + _delegate = delegate; } return self; } - (void)beginResize:(CGSize)size notify:(dispatch_block_t)notify { - std::unique_lock lock(mutex); - if (!delegate) { + std::unique_lock lock(_mutex); + if (!_delegate) { return; } - ++cookie; + ++_cookie; // from now on, ignore all incoming commits until the block below gets // scheduled on raster thread - acceptingCommit = false; + _acceptingCommit = NO; // let pending commits finish to unblock the raster thread - pendingCommit = false; - condBlockBeginResize.notify_all(); + _pendingCommit = NO; + _condBlockBeginResize.notify_all(); // let the engine send resize notification notify(); - newSize = size; + _newSize = size; - waiting = true; + _waiting = YES; - condBlockRequestCommit.wait(lock, [&] { return pendingCommit; }); + _condBlockRequestCommit.wait(lock, [&] { return _pendingCommit; }); - [delegate resizeSynchronizerFlush:self]; - [delegate resizeSynchronizerCommit:self]; - pendingCommit = false; - condBlockBeginResize.notify_all(); + [_delegate resizeSynchronizerFlush:self]; + [_delegate resizeSynchronizerCommit:self]; + _pendingCommit = NO; + _condBlockBeginResize.notify_all(); - waiting = false; + _waiting = NO; } - (bool)shouldEnsureSurfaceForSize:(CGSize)size { - std::unique_lock lock(mutex); - if (!acceptingCommit) { - if (CGSizeEqualToSize(newSize, size)) { - acceptingCommit = true; + std::unique_lock lock(_mutex); + if (!_acceptingCommit) { + if (CGSizeEqualToSize(_newSize, size)) { + _acceptingCommit = YES; } } - return acceptingCommit; + return _acceptingCommit; } - (void)requestCommit { - std::unique_lock lock(mutex); - if (!acceptingCommit) { + std::unique_lock lock(_mutex); + if (!_acceptingCommit) { return; } - pendingCommit = true; - if (waiting) { // BeginResize is in progress, interrupt it and schedule commit call - condBlockRequestCommit.notify_all(); - condBlockBeginResize.wait(lock, [&]() { return !pendingCommit; }); + _pendingCommit = YES; + if (_waiting) { // BeginResize is in progress, interrupt it and schedule commit call + _condBlockRequestCommit.notify_all(); + _condBlockBeginResize.wait(lock, [&]() { return !_pendingCommit; }); } else { // No resize, schedule commit on platform thread and wait until either done // or interrupted by incoming BeginResize - [delegate resizeSynchronizerFlush:self]; - dispatch_async(dispatch_get_main_queue(), [self, cookie_ = cookie] { - std::unique_lock lock(mutex); - if (cookie_ == cookie) { - if (delegate) { - [delegate resizeSynchronizerCommit:self]; + [_delegate resizeSynchronizerFlush:self]; + dispatch_async(dispatch_get_main_queue(), [self, cookie = _cookie] { + std::unique_lock lock(_mutex); + if (cookie == _cookie) { + if (_delegate) { + [_delegate resizeSynchronizerCommit:self]; } - pendingCommit = false; - condBlockBeginResize.notify_all(); + _pendingCommit = NO; + _condBlockBeginResize.notify_all(); } }); - condBlockBeginResize.wait(lock, [&]() { return !pendingCommit; }); + _condBlockBeginResize.wait(lock, [&]() { return !_pendingCommit; }); } } diff --git a/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h b/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h index 470f4f9400fda..54cc687d42e20 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h @@ -3,7 +3,8 @@ // Manages the IOSurfaces for FlutterView @interface FlutterSurfaceManager : NSObject -- (instancetype)initWithLayer:(CALayer*)layer openGLContext:(NSOpenGLContext*)opengLContext; +- (instancetype)initWithLayer:(CALayer*)containingLayer + openGLContext:(NSOpenGLContext*)opengLContext; - (void)ensureSurfaceSize:(CGSize)size; - (void)swapBuffers; diff --git a/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm b/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm index 2ddb190139670..73efc9352e028 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm @@ -1,5 +1,5 @@ #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h" -#import "flutter/fml/logging.h" + #import "flutter/shell/platform/darwin/macos/framework/Source/MacOSSwitchableGLContext.h" #include @@ -11,11 +11,11 @@ }; @interface FlutterSurfaceManager () { - CGSize surfaceSize; - CALayer* layer; // provided (parent layer) - CALayer* contentLayer; + CGSize _surfaceSize; + CALayer* _containingLayer; // provided (parent layer) + CALayer* _contentLayer; - NSOpenGLContext* openGLContext; + NSOpenGLContext* _openGLContext; uint32_t _frameBufferId[kBufferCount]; uint32_t _backingTexture[kBufferCount]; IOSurfaceRef _ioSurface[kBufferCount]; @@ -24,18 +24,19 @@ @interface FlutterSurfaceManager () { @implementation FlutterSurfaceManager -- (instancetype)initWithLayer:(CALayer*)layer_ openGLContext:(NSOpenGLContext*)opengLContext_ { +- (instancetype)initWithLayer:(CALayer*)containingLayer + openGLContext:(NSOpenGLContext*)openGLContext { if (self = [super init]) { - layer = layer_; - openGLContext = opengLContext_; + _containingLayer = containingLayer; + _openGLContext = openGLContext; // Layer for content. This is separate from provided layer, because it needs to be flipped // vertically if we render to OpenGL texture - contentLayer = [[CALayer alloc] init]; - [layer_ addSublayer:contentLayer]; + _contentLayer = [[CALayer alloc] init]; + [_containingLayer addSublayer:_contentLayer]; flutter::GLContextSwitch context_switch( - std::make_unique(opengLContext_)); + std::make_unique(opengLContext)); glGenFramebuffers(2, _frameBufferId); glGenTextures(2, _backingTexture); @@ -57,13 +58,13 @@ - (void)createFramebuffer:(uint32_t)fbo withBackingTexture:(uint32_t)texture { } - (void)ensureSurfaceSize:(CGSize)size { - if (CGSizeEqualToSize(size, surfaceSize)) { + if (CGSizeEqualToSize(size, _surfaceSize)) { return; } - surfaceSize = size; + _surfaceSize = size; flutter::GLContextSwitch context_switch( - std::make_unique(openGLContext)); + std::make_unique(_openGLContext)); for (int i = 0; i < kBufferCount; ++i) { if (_ioSurface[i]) { @@ -101,12 +102,12 @@ - (void)ensureSurfaceSize:(CGSize)size { } - (void)swapBuffers { - contentLayer.frame = layer.bounds; + _contentLayer.frame = _containingLayer.bounds; // The surface is an OpenGL texture, which means it has origin in bottom left corner // and needs to be flipped vertically - contentLayer.transform = CATransform3DMakeScale(1, -1, 1); - [contentLayer setContents:(__bridge id)_ioSurface[kBack]]; + _contentLayer.transform = CATransform3DMakeScale(1, -1, 1); + [_contentLayer setContents:(__bridge id)_ioSurface[kBack]]; std::swap(_ioSurface[kBack], _ioSurface[kFront]); std::swap(_frameBufferId[kBack], _frameBufferId[kFront]); diff --git a/shell/platform/darwin/macos/framework/Source/FlutterView.h b/shell/platform/darwin/macos/framework/Source/FlutterView.h index 1e4358e11ce98..de4a3bfb70b90 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterView.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterView.h @@ -20,7 +20,16 @@ */ @interface FlutterView : NSView +/** + * Returns the OpenGL context of backing surface. + */ @property(readwrite, nonatomic, nonnull) NSOpenGLContext* openGLContext; + +/** + * Controls whether view resizing synchronously updates contents. This can only be enabled + * after the engine is running and producing frames, because during synchronous view resizing the + * platform thread is blocked until engine produces frame with requested size. + */ @property(readwrite, nonatomic) BOOL synchronousResizing; - (nullable instancetype)initWithFrame:(NSRect)frame @@ -38,7 +47,15 @@ - (nullable instancetype)initWithCoder:(nonnull NSCoder*)coder NS_UNAVAILABLE; - (nonnull instancetype)init NS_UNAVAILABLE; +/** + * Flushes the OpenGL context and flips the surfaces. Expected to be called on raster thread. + */ - (void)present; -- (int)getFrameBufferIdForSize:(CGSize)size; + +/** + * Ensures that framebuffer with requested size exists and returns the ID. Expected to be called on + * raster thread. + */ +- (int)frameBufferIDForSize:(CGSize)size; @end diff --git a/shell/platform/darwin/macos/framework/Source/FlutterView.mm b/shell/platform/darwin/macos/framework/Source/FlutterView.mm index 6839640b1ebca..a5b10c8c5aa8a 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterView.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterView.mm @@ -3,6 +3,7 @@ // found in the LICENSE file. #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h" + #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h" #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h" #import "flutter/shell/platform/darwin/macos/framework/Source/MacOSSwitchableGLContext.h" @@ -12,8 +13,8 @@ @interface FlutterView () { __weak id _reshapeListener; - FlutterResizeSynchronizer* resizeSynchronizer; - FlutterSurfaceManager* surfaceManager; + FlutterResizeSynchronizer* _resizeSynchronizer; + FlutterSurfaceManager* _surfaceManager; } @end @@ -35,9 +36,9 @@ - (instancetype)initWithFrame:(NSRect)frame [self setWantsLayer:YES]; - resizeSynchronizer = [[FlutterResizeSynchronizer alloc] initWithDelegate:self]; - surfaceManager = [[FlutterSurfaceManager alloc] initWithLayer:self.layer - openGLContext:self.openGLContext]; + _resizeSynchronizer = [[FlutterResizeSynchronizer alloc] initWithDelegate:self]; + _surfaceManager = [[FlutterSurfaceManager alloc] initWithLayer:self.layer + openGLContext:self.openGLContext]; _reshapeListener = reshapeListener; } @@ -54,29 +55,29 @@ - (void)resizeSynchronizerCommit:(FlutterResizeSynchronizer*)synchronizer { [CATransaction begin]; [CATransaction setDisableActions:YES]; - [surfaceManager swapBuffers]; + [_surfaceManager swapBuffers]; [CATransaction commit]; } -- (int)getFrameBufferIdForSize:(CGSize)size { - if ([resizeSynchronizer shouldEnsureSurfaceForSize:size]) { - [surfaceManager ensureSurfaceSize:size]; +- (int)frameBufferIDForSize:(CGSize)size { + if ([_resizeSynchronizer shouldEnsureSurfaceForSize:size]) { + [_surfaceManager ensureSurfaceSize:size]; } - return [surfaceManager glFrameBufferId]; + return [_surfaceManager glFrameBufferId]; } - (void)present { - [resizeSynchronizer requestCommit]; + [_resizeSynchronizer requestCommit]; } - (void)reshaped { if (self.synchronousResizing) { CGSize scaledSize = [self convertSizeToBacking:self.bounds.size]; - [resizeSynchronizer beginResize:scaledSize - notify:^{ - [_reshapeListener viewDidReshape:self]; - }]; + [_resizeSynchronizer beginResize:scaledSize + notify:^{ + [_reshapeListener viewDidReshape:self]; + }]; } else { [_reshapeListener viewDidReshape:self]; } From dc2e5ab67a1ccacece59c3fe9c38784a1586597c Mon Sep 17 00:00:00 2001 From: Matej Knopp Date: Tue, 3 Nov 2020 18:18:23 +0100 Subject: [PATCH 2/6] Removes dependency on flow --- ci/licenses_golden/licenses_flutter | 4 ++-- shell/platform/darwin/macos/BUILD.gn | 5 ++--- .../framework/Source/FlutterSurfaceManager.mm | 10 ++++----- .../macos/framework/Source/FlutterView.mm | 5 ++--- .../framework/Source/MacOSGLContextSwitch.h | 17 +++++++++++++++ .../framework/Source/MacOSGLContextSwitch.mm | 14 +++++++++++++ .../Source/MacOSSwitchableGLContext.h | 21 ------------------- .../Source/MacOSSwitchableGLContext.mm | 19 ----------------- 8 files changed, 41 insertions(+), 54 deletions(-) create mode 100644 shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h create mode 100644 shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.mm delete mode 100644 shell/platform/darwin/macos/framework/Source/MacOSSwitchableGLContext.h delete mode 100644 shell/platform/darwin/macos/framework/Source/MacOSSwitchableGLContext.mm diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index f13271aa91373..d8bdf38254fde 100755 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -1067,8 +1067,8 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterView. FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewControllerTest.mm FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h -FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/MacOSSwitchableGLContext.h -FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/MacOSSwitchableGLContext.mm +FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h +FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.mm FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/fixtures/flutter_desktop_test.dart FILE: ../../../flutter/shell/platform/darwin/macos/framework/module.modulemap FILE: ../../../flutter/shell/platform/embedder/assets/EmbedderInfo.plist diff --git a/shell/platform/darwin/macos/BUILD.gn b/shell/platform/darwin/macos/BUILD.gn index c844d92413f3c..2c6c35dd552e9 100644 --- a/shell/platform/darwin/macos/BUILD.gn +++ b/shell/platform/darwin/macos/BUILD.gn @@ -66,14 +66,13 @@ source_set("flutter_framework_source") { "framework/Source/FlutterView.mm", "framework/Source/FlutterViewController.mm", "framework/Source/FlutterViewController_Internal.h", - "framework/Source/MacOSSwitchableGLContext.h", - "framework/Source/MacOSSwitchableGLContext.mm", + "framework/Source/MacOSGLContextSwitch.h", + "framework/Source/MacOSGLContextSwitch.mm", ] sources += _flutter_framework_headers deps = [ - "//flutter/flow:flow", "//flutter/fml:fml", "//flutter/shell/platform/common/cpp:common_cpp_switches", "//flutter/shell/platform/darwin/common:framework_shared", diff --git a/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm b/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm index 73efc9352e028..bbf52fe3fa341 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm @@ -1,8 +1,8 @@ #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h" -#import "flutter/shell/platform/darwin/macos/framework/Source/MacOSSwitchableGLContext.h" - #include +#import "flutter/fml/logging.h" +#import "flutter/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h" enum { kFront = 0, @@ -35,8 +35,7 @@ - (instancetype)initWithLayer:(CALayer*)containingLayer _contentLayer = [[CALayer alloc] init]; [_containingLayer addSublayer:_contentLayer]; - flutter::GLContextSwitch context_switch( - std::make_unique(opengLContext)); + MacOSGLContextSwitch context_switch(openGLContext); glGenFramebuffers(2, _frameBufferId); glGenTextures(2, _backingTexture); @@ -63,8 +62,7 @@ - (void)ensureSurfaceSize:(CGSize)size { } _surfaceSize = size; - flutter::GLContextSwitch context_switch( - std::make_unique(_openGLContext)); + MacOSGLContextSwitch context_switch(_openGLContext); for (int i = 0; i < kBufferCount; ++i) { if (_ioSurface[i]) { diff --git a/shell/platform/darwin/macos/framework/Source/FlutterView.mm b/shell/platform/darwin/macos/framework/Source/FlutterView.mm index a5b10c8c5aa8a..4dcfcf0bd13b3 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterView.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterView.mm @@ -6,7 +6,7 @@ #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h" #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h" -#import "flutter/shell/platform/darwin/macos/framework/Source/MacOSSwitchableGLContext.h" +#import "flutter/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h" #import #import @@ -46,8 +46,7 @@ - (instancetype)initWithFrame:(NSRect)frame } - (void)resizeSynchronizerFlush:(FlutterResizeSynchronizer*)synchronizer { - flutter::GLContextSwitch context_switch( - std::make_unique(self.openGLContext)); + MacOSGLContextSwitch context_switch(self.openGLContext); glFlush(); } diff --git a/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h b/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h new file mode 100644 index 0000000000000..6b029c3b1b0eb --- /dev/null +++ b/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h @@ -0,0 +1,17 @@ +#import + +/** + * RAII wrapper that sets provided NSOpenGLContext as current and restores + * original context on scope exit. + */ +class MacOSGLContextSwitch { + public: + explicit MacOSGLContextSwitch(NSOpenGLContext* context); + ~MacOSGLContextSwitch(); + + MacOSGLContextSwitch(const MacOSGLContextSwitch&) = delete; + MacOSGLContextSwitch(MacOSGLContextSwitch&&) = delete; + + private: + NSOpenGLContext* prev_; +}; diff --git a/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.mm b/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.mm new file mode 100644 index 0000000000000..9ecaa19ef91ca --- /dev/null +++ b/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.mm @@ -0,0 +1,14 @@ +#import "flutter/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h" + +MacOSGLContextSwitch::MacOSGLContextSwitch(NSOpenGLContext* context) { + prev_ = [NSOpenGLContext currentContext]; + [context makeCurrentContext]; +} + +MacOSGLContextSwitch::~MacOSGLContextSwitch() { + if (prev_) { + [prev_ makeCurrentContext]; + } else { + [NSOpenGLContext clearCurrentContext]; + } +} diff --git a/shell/platform/darwin/macos/framework/Source/MacOSSwitchableGLContext.h b/shell/platform/darwin/macos/framework/Source/MacOSSwitchableGLContext.h deleted file mode 100644 index 0ff951fca1e6a..0000000000000 --- a/shell/platform/darwin/macos/framework/Source/MacOSSwitchableGLContext.h +++ /dev/null @@ -1,21 +0,0 @@ -#include "flutter/flow/gl_context_switch.h" -#include "flutter/fml/memory/thread_checker.h" - -#import - -class MacOSSwitchableGLContext final : public flutter::SwitchableGLContext { - public: - explicit MacOSSwitchableGLContext(NSOpenGLContext* context); - - bool SetCurrent() override; - - bool RemoveCurrent() override; - - private: - NSOpenGLContext* context_; - NSOpenGLContext* previous_context_; - - FML_DECLARE_THREAD_CHECKER(checker); - - FML_DISALLOW_COPY_AND_ASSIGN(MacOSSwitchableGLContext); -}; diff --git a/shell/platform/darwin/macos/framework/Source/MacOSSwitchableGLContext.mm b/shell/platform/darwin/macos/framework/Source/MacOSSwitchableGLContext.mm deleted file mode 100644 index d68d8dfcfc585..0000000000000 --- a/shell/platform/darwin/macos/framework/Source/MacOSSwitchableGLContext.mm +++ /dev/null @@ -1,19 +0,0 @@ -#import "flutter/shell/platform/darwin/macos/framework/Source/MacOSSwitchableGLContext.h" - -MacOSSwitchableGLContext::MacOSSwitchableGLContext(NSOpenGLContext* context) : context_(context) {} - -bool MacOSSwitchableGLContext::SetCurrent() { - FML_DCHECK_CREATION_THREAD_IS_CURRENT(checker); - previous_context_ = [NSOpenGLContext currentContext]; - [context_ makeCurrentContext]; - return true; -} - -bool MacOSSwitchableGLContext::RemoveCurrent() { - if (previous_context_) { - [previous_context_ makeCurrentContext]; - } else { - [NSOpenGLContext clearCurrentContext]; - } - return true; -} From 5c6cf0cc4d2fa8fdeb63e24f76cd190af1c493f3 Mon Sep 17 00:00:00 2001 From: Matej Knopp Date: Tue, 3 Nov 2020 18:19:23 +0100 Subject: [PATCH 3/6] Add missing licenses --- .../darwin/macos/framework/Source/FlutterResizeSynchronizer.h | 4 ++++ .../macos/framework/Source/FlutterResizeSynchronizer.mm | 4 ++++ .../darwin/macos/framework/Source/FlutterSurfaceManager.h | 4 ++++ .../darwin/macos/framework/Source/FlutterSurfaceManager.mm | 4 ++++ .../darwin/macos/framework/Source/MacOSGLContextSwitch.h | 4 ++++ .../darwin/macos/framework/Source/MacOSGLContextSwitch.mm | 4 ++++ 6 files changed, 24 insertions(+) diff --git a/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h b/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h index b2189ac88e880..c085764604aba 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h @@ -1,3 +1,7 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + #import @class FlutterResizeSynchronizer; diff --git a/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.mm b/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.mm index 0e7c3b2522317..06e51119d92f5 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.mm @@ -1,3 +1,7 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h" #include diff --git a/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h b/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h index 54cc687d42e20..47e311291b5b4 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h @@ -1,3 +1,7 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + #import // Manages the IOSurfaces for FlutterView diff --git a/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm b/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm index bbf52fe3fa341..27c5f4a438ce0 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm @@ -1,3 +1,7 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h" #include diff --git a/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h b/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h index 6b029c3b1b0eb..f6356e02a5620 100644 --- a/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h +++ b/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h @@ -1,3 +1,7 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + #import /** diff --git a/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.mm b/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.mm index 9ecaa19ef91ca..e3c7bdbc8f637 100644 --- a/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.mm +++ b/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.mm @@ -1,3 +1,7 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + #import "flutter/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h" MacOSGLContextSwitch::MacOSGLContextSwitch(NSOpenGLContext* context) { From bc34af83112169f074339a747a344f309983628f Mon Sep 17 00:00:00 2001 From: Matej Knopp Date: Tue, 3 Nov 2020 18:39:07 +0100 Subject: [PATCH 4/6] Remove dependency on fml --- shell/platform/darwin/macos/BUILD.gn | 1 - .../darwin/macos/framework/Source/FlutterSurfaceManager.mm | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/shell/platform/darwin/macos/BUILD.gn b/shell/platform/darwin/macos/BUILD.gn index 2c6c35dd552e9..746e81bf642ba 100644 --- a/shell/platform/darwin/macos/BUILD.gn +++ b/shell/platform/darwin/macos/BUILD.gn @@ -73,7 +73,6 @@ source_set("flutter_framework_source") { sources += _flutter_framework_headers deps = [ - "//flutter/fml:fml", "//flutter/shell/platform/common/cpp:common_cpp_switches", "//flutter/shell/platform/darwin/common:framework_shared", "//flutter/shell/platform/embedder:embedder_as_internal_library", diff --git a/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm b/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm index 27c5f4a438ce0..e47f995609b11 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm @@ -5,7 +5,6 @@ #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h" #include -#import "flutter/fml/logging.h" #import "flutter/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h" enum { @@ -99,7 +98,8 @@ - (void)ensureSurfaceSize:(CGSize)size { glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ARB, _backingTexture[i], 0); - FML_DCHECK(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE); + NSAssert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE, + @"Framebuffer status check failed"); } } From 1b6ca208f7371ad698e9d75d61378a7a2cb49588 Mon Sep 17 00:00:00 2001 From: Matej Knopp Date: Tue, 3 Nov 2020 19:54:16 +0100 Subject: [PATCH 5/6] Rename constants --- .../framework/Source/FlutterSurfaceManager.mm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm b/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm index e47f995609b11..c8815d82e2067 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm @@ -8,8 +8,8 @@ #import "flutter/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h" enum { - kFront = 0, - kBack = 1, + kFrontBuffer = 0, + kBackBuffer = 1, kBufferCount, }; @@ -109,15 +109,15 @@ - (void)swapBuffers { // The surface is an OpenGL texture, which means it has origin in bottom left corner // and needs to be flipped vertically _contentLayer.transform = CATransform3DMakeScale(1, -1, 1); - [_contentLayer setContents:(__bridge id)_ioSurface[kBack]]; + [_contentLayer setContents:(__bridge id)_ioSurface[kBackBuffer]]; - std::swap(_ioSurface[kBack], _ioSurface[kFront]); - std::swap(_frameBufferId[kBack], _frameBufferId[kFront]); - std::swap(_backingTexture[kBack], _backingTexture[kFront]); + std::swap(_ioSurface[kBackBuffer], _ioSurface[kFrontBuffer]); + std::swap(_frameBufferId[kBackBuffer], _frameBufferId[kFrontBuffer]); + std::swap(_backingTexture[kBackBuffer], _backingTexture[kFrontBuffer]); } - (uint32_t)glFrameBufferId { - return _frameBufferId[kBack]; + return _frameBufferId[kBackBuffer]; } - (void)dealloc { From cfbe14bc67039537f18f2c14152729437f006d29 Mon Sep 17 00:00:00 2001 From: Matej Knopp Date: Tue, 3 Nov 2020 23:59:20 +0100 Subject: [PATCH 6/6] More style fixes --- .../Source/FlutterResizeSynchronizer.h | 2 +- .../Source/FlutterResizeSynchronizer.mm | 18 +++++------ .../framework/Source/FlutterSurfaceManager.h | 4 +-- .../framework/Source/FlutterSurfaceManager.mm | 32 +++++++++++-------- .../macos/framework/Source/FlutterView.h | 2 +- .../framework/Source/MacOSGLContextSwitch.h | 2 +- .../framework/Source/MacOSGLContextSwitch.mm | 6 ++-- 7 files changed, 35 insertions(+), 31 deletions(-) diff --git a/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h b/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h index c085764604aba..72e2a29bbac0b 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h @@ -67,7 +67,7 @@ * This will be false during resizing for any size other than size specified * during beginResize. */ -- (bool)shouldEnsureSurfaceForSize:(CGSize)size; +- (BOOL)shouldEnsureSurfaceForSize:(CGSize)size; /** * Called from rasterizer thread, will block until delegate resizeSynchronizerCommit: diff --git a/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.mm b/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.mm index 06e51119d92f5..8f2eaac98cc40 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.mm @@ -7,27 +7,27 @@ #include @interface FlutterResizeSynchronizer () { - // counter to detect stale callbacks + // Counter to detect stale callbacks. uint32_t _cookie; std::mutex _mutex; - // used to block [beginResize:] + // Used to block [beginResize:]. std::condition_variable _condBlockBeginResize; - // used to block [requestCommit] + // Used to block [requestCommit]. std::condition_variable _condBlockRequestCommit; - // if NO, requestCommit calls are ignored until shouldEnsureSurfaceForSize is called with - // proper size + // If NO, requestCommit calls are ignored until shouldEnsureSurfaceForSize is called with + // proper size. BOOL _acceptingCommit; - // waiting for resize to finish + // Waiting for resize to finish. BOOL _waiting; - // requestCommit was called and [delegate commit:] must be performed on platform thread + // RequestCommit was called and [delegate commit:] must be performed on platform thread. BOOL _pendingCommit; - // target size for resizing + // Target size for resizing. CGSize _newSize; __weak id _delegate; @@ -77,7 +77,7 @@ - (void)beginResize:(CGSize)size notify:(dispatch_block_t)notify { _waiting = NO; } -- (bool)shouldEnsureSurfaceForSize:(CGSize)size { +- (BOOL)shouldEnsureSurfaceForSize:(CGSize)size { std::unique_lock lock(_mutex); if (!_acceptingCommit) { if (CGSizeEqualToSize(_newSize, size)) { diff --git a/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h b/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h index 47e311291b5b4..afaeebb3ba8a3 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h @@ -7,8 +7,8 @@ // Manages the IOSurfaces for FlutterView @interface FlutterSurfaceManager : NSObject -- (instancetype)initWithLayer:(CALayer*)containingLayer - openGLContext:(NSOpenGLContext*)opengLContext; +- (nullable instancetype)initWithLayer:(nonnull CALayer*)containingLayer + openGLContext:(nonnull NSOpenGLContext*)opengLContext; - (void)ensureSurfaceSize:(CGSize)size; - (void)swapBuffers; diff --git a/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm b/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm index c8815d82e2067..c316d7359245f 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm @@ -5,12 +5,13 @@ #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h" #include + #import "flutter/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h" enum { - kFrontBuffer = 0, - kBackBuffer = 1, - kBufferCount, + kFlutterSurfaceManagerFrontBuffer = 0, + kFlutterSurfaceManagerBackBuffer = 1, + kFlutterSurfaceManagerBufferCount, }; @interface FlutterSurfaceManager () { @@ -19,9 +20,9 @@ @interface FlutterSurfaceManager () { CALayer* _contentLayer; NSOpenGLContext* _openGLContext; - uint32_t _frameBufferId[kBufferCount]; - uint32_t _backingTexture[kBufferCount]; - IOSurfaceRef _ioSurface[kBufferCount]; + uint32_t _frameBufferId[kFlutterSurfaceManagerBufferCount]; + uint32_t _backingTexture[kFlutterSurfaceManagerBufferCount]; + IOSurfaceRef _ioSurface[kFlutterSurfaceManagerBufferCount]; } @end @@ -67,7 +68,7 @@ - (void)ensureSurfaceSize:(CGSize)size { MacOSGLContextSwitch context_switch(_openGLContext); - for (int i = 0; i < kBufferCount; ++i) { + for (int i = 0; i < kFlutterSurfaceManagerBufferCount; ++i) { if (_ioSurface[i]) { CFRelease(_ioSurface[i]); } @@ -109,19 +110,22 @@ - (void)swapBuffers { // The surface is an OpenGL texture, which means it has origin in bottom left corner // and needs to be flipped vertically _contentLayer.transform = CATransform3DMakeScale(1, -1, 1); - [_contentLayer setContents:(__bridge id)_ioSurface[kBackBuffer]]; - - std::swap(_ioSurface[kBackBuffer], _ioSurface[kFrontBuffer]); - std::swap(_frameBufferId[kBackBuffer], _frameBufferId[kFrontBuffer]); - std::swap(_backingTexture[kBackBuffer], _backingTexture[kFrontBuffer]); + [_contentLayer setContents:(__bridge id)_ioSurface[kFlutterSurfaceManagerBackBuffer]]; + + std::swap(_ioSurface[kFlutterSurfaceManagerBackBuffer], + _ioSurface[kFlutterSurfaceManagerFrontBuffer]); + std::swap(_frameBufferId[kFlutterSurfaceManagerBackBuffer], + _frameBufferId[kFlutterSurfaceManagerFrontBuffer]); + std::swap(_backingTexture[kFlutterSurfaceManagerBackBuffer], + _backingTexture[kFlutterSurfaceManagerFrontBuffer]); } - (uint32_t)glFrameBufferId { - return _frameBufferId[kBackBuffer]; + return _frameBufferId[kFlutterSurfaceManagerBackBuffer]; } - (void)dealloc { - for (int i = 0; i < kBufferCount; ++i) { + for (int i = 0; i < kFlutterSurfaceManagerBufferCount; ++i) { if (_ioSurface[i]) { CFRelease(_ioSurface[i]); } diff --git a/shell/platform/darwin/macos/framework/Source/FlutterView.h b/shell/platform/darwin/macos/framework/Source/FlutterView.h index de4a3bfb70b90..4d5cd3780f10e 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterView.h +++ b/shell/platform/darwin/macos/framework/Source/FlutterView.h @@ -21,7 +21,7 @@ @interface FlutterView : NSView /** - * Returns the OpenGL context of backing surface. + * The OpenGL context of backing surface. */ @property(readwrite, nonatomic, nonnull) NSOpenGLContext* openGLContext; diff --git a/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h b/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h index f6356e02a5620..a1957e4553c5e 100644 --- a/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h +++ b/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h @@ -17,5 +17,5 @@ class MacOSGLContextSwitch { MacOSGLContextSwitch(MacOSGLContextSwitch&&) = delete; private: - NSOpenGLContext* prev_; + NSOpenGLContext* previous_; }; diff --git a/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.mm b/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.mm index e3c7bdbc8f637..fd53920c7898a 100644 --- a/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.mm +++ b/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.mm @@ -5,13 +5,13 @@ #import "flutter/shell/platform/darwin/macos/framework/Source/MacOSGLContextSwitch.h" MacOSGLContextSwitch::MacOSGLContextSwitch(NSOpenGLContext* context) { - prev_ = [NSOpenGLContext currentContext]; + previous_ = [NSOpenGLContext currentContext]; [context makeCurrentContext]; } MacOSGLContextSwitch::~MacOSGLContextSwitch() { - if (prev_) { - [prev_ makeCurrentContext]; + if (previous_) { + [previous_ makeCurrentContext]; } else { [NSOpenGLContext clearCurrentContext]; }