From cfe9c0fbbde14f33b6666ed0aacb8e29fb852e87 Mon Sep 17 00:00:00 2001 From: Matej Knopp Date: Tue, 13 Apr 2021 19:09:03 +0200 Subject: [PATCH] FlutterView: Use default backing layer (flutter/engine#25523) --- .../Source/FlutterMetalSurfaceManagerTest.mm | 12 ++------- .../Source/FlutterRenderingBackend.h | 11 -------- .../Source/FlutterRenderingBackend.mm | 25 ------------------- .../FlutterResizableBackingStoreProvider.h | 2 +- .../FlutterResizableBackingStoreProvider.mm | 4 +-- .../framework/Source/FlutterSurfaceManager.h | 2 +- .../framework/Source/FlutterSurfaceManager.mm | 4 +-- .../macos/framework/Source/FlutterView.mm | 16 +++--------- 8 files changed, 12 insertions(+), 64 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterMetalSurfaceManagerTest.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterMetalSurfaceManagerTest.mm index e29aaa3d66..7a739e7535 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterMetalSurfaceManagerTest.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterMetalSurfaceManagerTest.mm @@ -25,14 +25,6 @@ return self; } -- (CALayer*)makeBackingLayer { - return [CAMetalLayer layer]; -} - -+ (Class)layerClass { - return [CAMetalLayer class]; -} - @end namespace flutter::testing { @@ -41,10 +33,10 @@ static FlutterMetalSurfaceManager* CreateSurfaceManager() { id device = MTLCreateSystemDefaultDevice(); id commandQueue = [device newCommandQueue]; TestMetalView* metalView = [[TestMetalView alloc] init]; - CAMetalLayer* layer = reinterpret_cast(metalView.layer); + CALayer* layer = reinterpret_cast(metalView.layer); return [[FlutterMetalSurfaceManager alloc] initWithDevice:device commandQueue:commandQueue - metalLayer:layer]; + layer:layer]; } TEST(FlutterMetalSurfaceManager, EnsureSizeUpdatesSize) { diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterRenderingBackend.h b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterRenderingBackend.h index 28fe3b7e0e..7ee9499cf3 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterRenderingBackend.h +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterRenderingBackend.h @@ -16,15 +16,4 @@ */ + (BOOL)renderUsingMetal; -/** - * CALayer class depending on the rendering backend. - */ -+ (nonnull Class)layerClass; - -/** - * On both Metal and OpenGL rendering backends, `wantsLayer` is set on the `FlutterView`. This - * methos is used by `FlutterView` to provide the said `CALayer`. - */ -+ (nonnull CALayer*)createBackingLayer; - @end diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterRenderingBackend.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterRenderingBackend.mm index 3774dcfffb..b9525187f1 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterRenderingBackend.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterRenderingBackend.mm @@ -19,29 +19,4 @@ return NO; } -+ (Class)layerClass { - BOOL enableMetal = [FlutterRenderingBackend renderUsingMetal]; - if (enableMetal) { - return [CAMetalLayer class]; - } else { - return [CAOpenGLLayer class]; - } -} - -+ (CALayer*)createBackingLayer { - BOOL enableMetal = [FlutterRenderingBackend renderUsingMetal]; - if (enableMetal) { - 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; - } else { - return [CAOpenGLLayer layer]; - } -} - @end diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterResizableBackingStoreProvider.h b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterResizableBackingStoreProvider.h index 716ac68353..e4510284f4 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterResizableBackingStoreProvider.h +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterResizableBackingStoreProvider.h @@ -53,6 +53,6 @@ */ - (nonnull instancetype)initWithDevice:(nonnull id)device commandQueue:(nonnull id)commandQueue - metalLayer:(nonnull CAMetalLayer*)layer; + layer:(nonnull CALayer*)layer; @end diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterResizableBackingStoreProvider.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterResizableBackingStoreProvider.mm index 2297bc91c3..14988a0613 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterResizableBackingStoreProvider.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterResizableBackingStoreProvider.mm @@ -57,14 +57,14 @@ - (instancetype)initWithDevice:(id)device commandQueue:(id)commandQueue - metalLayer:(CAMetalLayer*)layer { + layer:(CALayer*)layer { self = [super init]; if (self) { _device = device; _commandQueue = commandQueue; _surfaceManager = [[FlutterMetalSurfaceManager alloc] initWithDevice:device commandQueue:commandQueue - metalLayer:layer]; + layer:layer]; } return self; } diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h index 99a694c28f..aac50a4298 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h @@ -100,6 +100,6 @@ */ - (nullable instancetype)initWithDevice:(nonnull id)device commandQueue:(nonnull id)commandQueue - metalLayer:(nonnull CAMetalLayer*)layer; + layer:(nonnull CALayer*)containingLayer; @end diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm index e6c2ec1b2b..abfc8eb68e 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm @@ -121,8 +121,8 @@ enum { - (nullable instancetype)initWithDevice:(nonnull id)device commandQueue:(nonnull id)commandQueue - metalLayer:(nonnull CAMetalLayer*)layer { - self = [super initWithLayer:layer contentTransform:CATransform3DIdentity]; + layer:(nonnull CALayer*)containingLayer { + self = [super initWithLayer:containingLayer contentTransform:CATransform3DIdentity]; if (self) { super.delegate = self; _device = device; diff --git a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterView.mm b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterView.mm index be421bd2c3..6d5377350d 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterView.mm +++ b/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterView.mm @@ -30,24 +30,16 @@ [self setWantsLayer:YES]; [self setLayerContentsRedrawPolicy:NSViewLayerContentsRedrawDuringViewResize]; _reshapeListener = reshapeListener; - _resizableBackingStoreProvider = [[FlutterMetalResizableBackingStoreProvider alloc] - initWithDevice:device - commandQueue:commandQueue - metalLayer:reinterpret_cast(self.layer)]; + _resizableBackingStoreProvider = + [[FlutterMetalResizableBackingStoreProvider alloc] initWithDevice:device + commandQueue:commandQueue + layer:self.layer]; _resizeSynchronizer = [[FlutterResizeSynchronizer alloc] initWithDelegate:_resizableBackingStoreProvider]; } return self; } -+ (Class)layerClass { - return [FlutterRenderingBackend layerClass]; -} - -- (CALayer*)makeBackingLayer { - return [FlutterRenderingBackend createBackingLayer]; -} - - (instancetype)initWithMainContext:(NSOpenGLContext*)mainContext reshapeListener:(id)reshapeListener { return [self initWithFrame:NSZeroRect mainContext:mainContext reshapeListener:reshapeListener];