diff --git a/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.mm b/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.mm index b689cfe28ad7b..7348a7741273f 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.mm @@ -5,8 +5,8 @@ @interface FlutterResizeSynchronizer () { uint32_t cookie; // counter to detect stale callbacks std::mutex mutex; - std::condition_variable condRun; - std::condition_variable condBlock; + std::condition_variable condNoPendingCommit; + std::condition_variable condPendingCommit; bool accepting; bool waiting; bool pendingCommit; @@ -38,7 +38,8 @@ - (void)beginResize:(CGSize)size notify:(dispatch_block_t)notify { accepting = false; // let pending commits finish to unblock the raster thread - condRun.notify_all(); + pendingCommit = false; + condNoPendingCommit.notify_all(); // let the engine send resize notification notify(); @@ -47,13 +48,11 @@ - (void)beginResize:(CGSize)size notify:(dispatch_block_t)notify { waiting = true; - condBlock.wait(lock); + condPendingCommit.wait(lock, [&] { return pendingCommit; }); - if (pendingCommit) { - [delegate resizeSynchronizerCommit:self]; - pendingCommit = false; - condRun.notify_all(); - } + [delegate resizeSynchronizerCommit:self]; + pendingCommit = false; + condNoPendingCommit.notify_all(); waiting = false; } @@ -76,21 +75,23 @@ - (void)requestCommit { if (waiting) { // BeginResize is in progress, interrupt it and schedule commit call pendingCommit = true; - condBlock.notify_all(); - condRun.wait(lock); + condPendingCommit.notify_all(); + condNoPendingCommit.wait(lock, [&]() { return !pendingCommit; }); } else { // No resize, schedule commit on platform thread and wait until either done // or interrupted by incoming BeginResize + pendingCommit = true; dispatch_async(dispatch_get_main_queue(), [self, cookie_ = cookie] { std::unique_lock lock(mutex); if (cookie_ == cookie) { if (delegate) { [delegate resizeSynchronizerCommit:self]; } - condRun.notify_all(); + pendingCommit = false; + condNoPendingCommit.notify_all(); } }); - condRun.wait(lock); + condNoPendingCommit.wait(lock, [&]() { return !pendingCommit; }); } }