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:
@@ -322,7 +322,6 @@ static bool OnAcquireExternalTexture(FlutterEngine* engine,
|
|||||||
[self sendUserLocales];
|
[self sendUserLocales];
|
||||||
[self updateWindowMetrics];
|
[self updateWindowMetrics];
|
||||||
[self updateDisplayConfig];
|
[self updateDisplayConfig];
|
||||||
self.viewController.flutterView.synchronousResizing = YES;
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,9 +358,6 @@ static bool OnAcquireExternalTexture(FlutterEngine* engine,
|
|||||||
[self shutDownEngine];
|
[self shutDownEngine];
|
||||||
_resourceContext = nil;
|
_resourceContext = nil;
|
||||||
}
|
}
|
||||||
if (_engine) {
|
|
||||||
self.viewController.flutterView.synchronousResizing = YES;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id<FlutterBinaryMessenger>)binaryMessenger {
|
- (id<FlutterBinaryMessenger>)binaryMessenger {
|
||||||
|
|||||||
@@ -17,6 +17,10 @@
|
|||||||
// Used to block [requestCommit].
|
// Used to block [requestCommit].
|
||||||
std::condition_variable _condBlockRequestCommit;
|
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
|
// If NO, requestCommit calls are ignored until shouldEnsureSurfaceForSize is called with
|
||||||
// proper size.
|
// proper size.
|
||||||
BOOL _acceptingCommit;
|
BOOL _acceptingCommit;
|
||||||
@@ -50,6 +54,12 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!_receivedFirstFrame) {
|
||||||
|
// No blocking until framework produces at least one frame
|
||||||
|
notify();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
++_cookie;
|
++_cookie;
|
||||||
|
|
||||||
// from now on, ignore all incoming commits until the block below gets
|
// from now on, ignore all incoming commits until the block below gets
|
||||||
@@ -79,6 +89,11 @@
|
|||||||
|
|
||||||
- (BOOL)shouldEnsureSurfaceForSize:(CGSize)size {
|
- (BOOL)shouldEnsureSurfaceForSize:(CGSize)size {
|
||||||
std::unique_lock<std::mutex> lock(_mutex);
|
std::unique_lock<std::mutex> lock(_mutex);
|
||||||
|
|
||||||
|
if (!_receivedFirstFrame) {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
if (!_acceptingCommit) {
|
if (!_acceptingCommit) {
|
||||||
if (CGSizeEqualToSize(_newSize, size)) {
|
if (CGSizeEqualToSize(_newSize, size)) {
|
||||||
_acceptingCommit = YES;
|
_acceptingCommit = YES;
|
||||||
@@ -93,6 +108,8 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_receivedFirstFrame = YES;
|
||||||
|
|
||||||
_pendingCommit = YES;
|
_pendingCommit = YES;
|
||||||
if (_waiting) { // BeginResize is in progress, interrupt it and schedule commit call
|
if (_waiting) { // BeginResize is in progress, interrupt it and schedule commit call
|
||||||
_condBlockRequestCommit.notify_all();
|
_condBlockRequestCommit.notify_all();
|
||||||
|
|||||||
@@ -25,13 +25,6 @@
|
|||||||
*/
|
*/
|
||||||
@property(readwrite, nonatomic, nonnull) NSOpenGLContext* openGLContext;
|
@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
|
- (nullable instancetype)initWithFrame:(NSRect)frame
|
||||||
shareContext:(nonnull NSOpenGLContext*)shareContext
|
shareContext:(nonnull NSOpenGLContext*)shareContext
|
||||||
reshapeListener:(nonnull id<FlutterViewReshapeListener>)reshapeListener
|
reshapeListener:(nonnull id<FlutterViewReshapeListener>)reshapeListener
|
||||||
|
|||||||
@@ -71,15 +71,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)reshaped {
|
- (void)reshaped {
|
||||||
if (self.synchronousResizing) {
|
CGSize scaledSize = [self convertSizeToBacking:self.bounds.size];
|
||||||
CGSize scaledSize = [self convertSizeToBacking:self.bounds.size];
|
[_resizeSynchronizer beginResize:scaledSize
|
||||||
[_resizeSynchronizer beginResize:scaledSize
|
notify:^{
|
||||||
notify:^{
|
[_reshapeListener viewDidReshape:self];
|
||||||
[_reshapeListener viewDidReshape:self];
|
}];
|
||||||
}];
|
|
||||||
} else {
|
|
||||||
[_reshapeListener viewDidReshape:self];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - NSView overrides
|
#pragma mark - NSView overrides
|
||||||
|
|||||||
Reference in New Issue
Block a user