[macos] Support smooth resizing for Metal (#23924)

Coordinate command buffer submission with Core Animation
scheduling to ensure smooth resizing.

Fixes: https://github.com/flutter/flutter/issues/74056
This commit is contained in:
Kaushik Iska 2021-01-25 14:50:21 -06:00 committed by GitHub
parent ef4f5a8577
commit 790af8a5b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -78,14 +78,19 @@
}
- (void)resizeSynchronizerFlush:(nonnull FlutterResizeSynchronizer*)synchronizer {
// TODO (kaushikiska): Support smooth resizing on Metal.
// no-op when using Metal rendering backend.
}
- (void)resizeSynchronizerCommit:(nonnull FlutterResizeSynchronizer*)synchronizer {
[CATransaction begin];
[CATransaction setDisableActions:YES];
id<MTLCommandBuffer> commandBuffer = [_commandQueue commandBuffer];
[commandBuffer commit];
[commandBuffer waitUntilScheduled];
[_surfaceManager swapBuffers];
[CATransaction commit];
}
@end

View File

@ -27,6 +27,7 @@
self = [super initWithFrame:NSZeroRect];
if (self) {
[self setWantsLayer:YES];
[self setLayerContentsRedrawPolicy:NSViewLayerContentsRedrawDuringViewResize];
_reshapeListener = reshapeListener;
_resizableBackingStoreProvider = [[FlutterMetalResizableBackingStoreProvider alloc]
initWithDevice:device
@ -44,7 +45,14 @@
}
- (CALayer*)makeBackingLayer {
return [CAMetalLayer layer];
CAMetalLayer* metalLayer = [CAMetalLayer layer];
// This is set to true to synchronize the presentation of the layer and its contents with Core
// Animation. When presenting the texture see `[FlutterMetalResizableBackingStoreProvider
// resizeSynchronizerCommit:]` we start a CATransaction and wait for the command buffer to be
// scheduled. This ensures that the resizing process is smooth.
metalLayer.presentsWithTransaction = YES;
metalLayer.autoresizingMask = kCALayerHeightSizable | kCALayerWidthSizable;
return metalLayer;
}
#endif