diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm index ab4b8f4e96..f638e0fe79 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm @@ -439,11 +439,12 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi _macOSCompositor = std::make_unique( _viewController, _platformViewController, metalRenderer.device); _macOSCompositor->SetPresentCallback([weakSelf](bool has_flutter_content) { + FlutterMetalRenderer* metalRenderer = + reinterpret_cast(weakSelf.renderer); if (has_flutter_content) { - FlutterMetalRenderer* metalRenderer = - reinterpret_cast(weakSelf.renderer); return [metalRenderer present:0 /*=textureID*/] == YES; } else { + [metalRenderer presentWithoutContent]; return true; } }); @@ -454,11 +455,12 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi openGLRenderer.openGLContext); _macOSCompositor->SetPresentCallback([weakSelf](bool has_flutter_content) { + FlutterOpenGLRenderer* openGLRenderer = + reinterpret_cast(weakSelf.renderer); if (has_flutter_content) { - FlutterOpenGLRenderer* openGLRenderer = - reinterpret_cast(weakSelf.renderer); return [openGLRenderer glPresent] == YES; } else { + [openGLRenderer presentWithoutContent]; return true; } }); diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterMetalRenderer.h b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterMetalRenderer.h index 6169541b92..d820d7e438 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterMetalRenderer.h +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterMetalRenderer.h @@ -34,6 +34,11 @@ */ - (BOOL)present:(int64_t)textureID; +/** + * Tells the renderer that there is no Flutter content available for this frame. + */ +- (void)presentWithoutContent; + /** * Populates the texture registry with the provided metalTexture. */ diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterMetalRenderer.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterMetalRenderer.mm index b274ed4d60..2347d06fa0 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterMetalRenderer.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterMetalRenderer.mm @@ -107,6 +107,10 @@ static bool OnAcquireExternalTexture(FlutterEngine* engine, return YES; } +- (void)presentWithoutContent { + [_flutterView presentWithoutContent]; +} + #pragma mark - FlutterTextureRegistrar methods. - (BOOL)populateTextureWithIdentifier:(int64_t)textureID diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterOpenGLRenderer.h b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterOpenGLRenderer.h index f1e46c4262..cbc972b48d 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterOpenGLRenderer.h +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterOpenGLRenderer.h @@ -39,6 +39,11 @@ */ - (BOOL)glPresent; +/** + * Tells the renderer that there is no Flutter content available for this frame. + */ +- (void)presentWithoutContent; + /** * Called by the engine when framebuffer object ID is requested. */ diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterOpenGLRenderer.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterOpenGLRenderer.mm index a6abbc4ec5..3c456cf744 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterOpenGLRenderer.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterOpenGLRenderer.mm @@ -96,6 +96,10 @@ static bool OnAcquireExternalTexture(FlutterEngine* engine, return true; } +- (void)presentWithoutContent { + [_flutterView presentWithoutContent]; +} + - (uint32_t)fboForFrameInfo:(const FlutterFrameInfo*)info { CGSize size = CGSizeMake(info->size.width, info->size.height); FlutterOpenGLRenderBackingStore* backingStore = diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h index 88442dcd26..03c837d984 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h @@ -75,6 +75,13 @@ */ - (void)requestCommit; +/** + * Called from view to notify the synchronizer that there are no Flutter frames + * coming. Synchronizer must unblock main thread and not block until another + * frame is available. + */ +- (void)noFlutterContent; + /** * Called when shutting down. Unblocks everything and prevents any further synchronization. */ diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.mm index 6e4873d668..7681aa3385 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.mm @@ -19,7 +19,7 @@ // Whether a frame was received; the synchronizer doesn't block platform thread during resize // until it knows that framework is running and producing frames - BOOL _receivedFirstFrame; + BOOL _hasFlutterContent; // If NO, requestCommit calls are ignored until shouldEnsureSurfaceForSize is called with // proper size. @@ -57,7 +57,7 @@ return; } - if (!_receivedFirstFrame || _shuttingDown) { + if (!_hasFlutterContent || _shuttingDown) { // No blocking until framework produces at least one frame notify(); return; @@ -93,7 +93,7 @@ - (BOOL)shouldEnsureSurfaceForSize:(CGSize)size { std::unique_lock lock(_mutex); - if (!_receivedFirstFrame) { + if (!_hasFlutterContent) { return YES; } @@ -107,11 +107,12 @@ - (void)requestCommit { std::unique_lock lock(_mutex); + if (!_acceptingCommit || _shuttingDown) { return; } - _receivedFirstFrame = YES; + _hasFlutterContent = YES; _pendingCommit = YES; if (_waiting) { // BeginResize is in progress, interrupt it and schedule commit call @@ -135,6 +136,13 @@ } } +- (void)noFlutterContent { + std::unique_lock lock(_mutex); + _hasFlutterContent = NO; + _acceptingCommit = YES; + _condBlockBeginResize.notify_all(); +} + - (void)shutdown { std::unique_lock lock(_mutex); _shuttingDown = YES; diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h index a3283b2f87..8aed110e70 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h @@ -50,6 +50,12 @@ */ - (void)present; +/** + * Called when there is no Flutter content available to render. This must be passed to resize + * synchronizer. + */ +- (void)presentWithoutContent; + /** * Ensures that a backing store with requested size exists and returns the descriptor. Expected to * be called on raster thread. diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterView.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterView.mm index 063e2aab81..6407cb2788 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterView.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterView.mm @@ -72,6 +72,10 @@ [_resizeSynchronizer requestCommit]; } +- (void)presentWithoutContent { + [_resizeSynchronizer noFlutterContent]; +} + - (void)reshaped { CGSize scaledSize = [self convertSizeToBacking:self.bounds.size]; [_resizeSynchronizer beginResize:scaledSize