Disable synchronous resizing until a frame is produced (flutter/engine#22457)

Instead of synchronousResizing flag which in some cases seems to be set too early, synchronous resizing is postponed until framework produces a frame so ResizeSynchronizer knows for sure that the engine is up and running.
This commit is contained in:
Matej Knopp 2020-11-12 20:50:31 +01:00 committed by GitHub
parent 07032ba889
commit 7fd7ae2252
4 changed files with 22 additions and 20 deletions

View File

@ -322,7 +322,6 @@ static bool OnAcquireExternalTexture(FlutterEngine* engine,
[self sendUserLocales];
[self updateWindowMetrics];
[self updateDisplayConfig];
self.viewController.flutterView.synchronousResizing = YES;
return YES;
}
@ -359,9 +358,6 @@ static bool OnAcquireExternalTexture(FlutterEngine* engine,
[self shutDownEngine];
_resourceContext = nil;
}
if (_engine) {
self.viewController.flutterView.synchronousResizing = YES;
}
}
- (id<FlutterBinaryMessenger>)binaryMessenger {

View File

@ -17,6 +17,10 @@
// Used to block [requestCommit].
std::condition_variable _condBlockRequestCommit;
// Whether a frame was received; We don't block platform thread during resize
// until we know that framework is running and producing frames
BOOL _receivedFirstFrame;
// If NO, requestCommit calls are ignored until shouldEnsureSurfaceForSize is called with
// proper size.
BOOL _acceptingCommit;
@ -50,6 +54,12 @@
return;
}
if (!_receivedFirstFrame) {
// No blocking until framework produces at least one frame
notify();
return;
}
++_cookie;
// from now on, ignore all incoming commits until the block below gets
@ -79,6 +89,11 @@
- (BOOL)shouldEnsureSurfaceForSize:(CGSize)size {
std::unique_lock<std::mutex> lock(_mutex);
if (!_receivedFirstFrame) {
return YES;
}
if (!_acceptingCommit) {
if (CGSizeEqualToSize(_newSize, size)) {
_acceptingCommit = YES;
@ -93,6 +108,8 @@
return;
}
_receivedFirstFrame = YES;
_pendingCommit = YES;
if (_waiting) { // BeginResize is in progress, interrupt it and schedule commit call
_condBlockRequestCommit.notify_all();

View File

@ -25,13 +25,6 @@
*/
@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
shareContext:(nonnull NSOpenGLContext*)shareContext
reshapeListener:(nonnull id<FlutterViewReshapeListener>)reshapeListener

View File

@ -71,15 +71,11 @@
}
- (void)reshaped {
if (self.synchronousResizing) {
CGSize scaledSize = [self convertSizeToBacking:self.bounds.size];
[_resizeSynchronizer beginResize:scaledSize
notify:^{
[_reshapeListener viewDidReshape:self];
}];
} else {
[_reshapeListener viewDidReshape:self];
}
CGSize scaledSize = [self convertSizeToBacking:self.bounds.size];
[_resizeSynchronizer beginResize:scaledSize
notify:^{
[_reshapeListener viewDidReshape:self];
}];
}
#pragma mark - NSView overrides