[macOS] Do not block main thread during resizing if there is no content (flutter/engine#35409)
* [macOS] Do not block main thread during resizing if there is no content Fixes: https://github.com/flutter/flutter/issues/92673
This commit is contained in:
@@ -439,11 +439,12 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi
|
||||
_macOSCompositor = std::make_unique<flutter::FlutterMetalCompositor>(
|
||||
_viewController, _platformViewController, metalRenderer.device);
|
||||
_macOSCompositor->SetPresentCallback([weakSelf](bool has_flutter_content) {
|
||||
FlutterMetalRenderer* metalRenderer =
|
||||
reinterpret_cast<FlutterMetalRenderer*>(weakSelf.renderer);
|
||||
if (has_flutter_content) {
|
||||
FlutterMetalRenderer* metalRenderer =
|
||||
reinterpret_cast<FlutterMetalRenderer*>(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<FlutterOpenGLRenderer*>(weakSelf.renderer);
|
||||
if (has_flutter_content) {
|
||||
FlutterOpenGLRenderer* openGLRenderer =
|
||||
reinterpret_cast<FlutterOpenGLRenderer*>(weakSelf.renderer);
|
||||
return [openGLRenderer glPresent] == YES;
|
||||
} else {
|
||||
[openGLRenderer presentWithoutContent];
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -107,6 +107,10 @@ static bool OnAcquireExternalTexture(FlutterEngine* engine,
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)presentWithoutContent {
|
||||
[_flutterView presentWithoutContent];
|
||||
}
|
||||
|
||||
#pragma mark - FlutterTextureRegistrar methods.
|
||||
|
||||
- (BOOL)populateTextureWithIdentifier:(int64_t)textureID
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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<std::mutex> lock(_mutex);
|
||||
|
||||
if (!_receivedFirstFrame) {
|
||||
if (!_hasFlutterContent) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
@@ -107,11 +107,12 @@
|
||||
|
||||
- (void)requestCommit {
|
||||
std::unique_lock<std::mutex> 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<std::mutex> lock(_mutex);
|
||||
_hasFlutterContent = NO;
|
||||
_acceptingCommit = YES;
|
||||
_condBlockBeginResize.notify_all();
|
||||
}
|
||||
|
||||
- (void)shutdown {
|
||||
std::unique_lock<std::mutex> lock(_mutex);
|
||||
_shuttingDown = YES;
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -72,6 +72,10 @@
|
||||
[_resizeSynchronizer requestCommit];
|
||||
}
|
||||
|
||||
- (void)presentWithoutContent {
|
||||
[_resizeSynchronizer noFlutterContent];
|
||||
}
|
||||
|
||||
- (void)reshaped {
|
||||
CGSize scaledSize = [self convertSizeToBacking:self.bounds.size];
|
||||
[_resizeSynchronizer beginResize:scaledSize
|
||||
|
||||
Reference in New Issue
Block a user