mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[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:
parent
ef4f5a8577
commit
790af8a5b0
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user