FlutterView: Use default backing layer (flutter/engine#25523)

This commit is contained in:
Matej Knopp
2021-04-13 19:09:03 +02:00
committed by GitHub
parent ffc1eedbd4
commit cfe9c0fbbd
8 changed files with 12 additions and 64 deletions

View File

@@ -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<MTLDevice> device = MTLCreateSystemDefaultDevice();
id<MTLCommandQueue> commandQueue = [device newCommandQueue];
TestMetalView* metalView = [[TestMetalView alloc] init];
CAMetalLayer* layer = reinterpret_cast<CAMetalLayer*>(metalView.layer);
CALayer* layer = reinterpret_cast<CALayer*>(metalView.layer);
return [[FlutterMetalSurfaceManager alloc] initWithDevice:device
commandQueue:commandQueue
metalLayer:layer];
layer:layer];
}
TEST(FlutterMetalSurfaceManager, EnsureSizeUpdatesSize) {

View File

@@ -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

View File

@@ -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

View File

@@ -53,6 +53,6 @@
*/
- (nonnull instancetype)initWithDevice:(nonnull id<MTLDevice>)device
commandQueue:(nonnull id<MTLCommandQueue>)commandQueue
metalLayer:(nonnull CAMetalLayer*)layer;
layer:(nonnull CALayer*)layer;
@end

View File

@@ -57,14 +57,14 @@
- (instancetype)initWithDevice:(id<MTLDevice>)device
commandQueue:(id<MTLCommandQueue>)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;
}

View File

@@ -100,6 +100,6 @@
*/
- (nullable instancetype)initWithDevice:(nonnull id<MTLDevice>)device
commandQueue:(nonnull id<MTLCommandQueue>)commandQueue
metalLayer:(nonnull CAMetalLayer*)layer;
layer:(nonnull CALayer*)containingLayer;
@end

View File

@@ -121,8 +121,8 @@ enum {
- (nullable instancetype)initWithDevice:(nonnull id<MTLDevice>)device
commandQueue:(nonnull id<MTLCommandQueue>)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;

View File

@@ -30,24 +30,16 @@
[self setWantsLayer:YES];
[self setLayerContentsRedrawPolicy:NSViewLayerContentsRedrawDuringViewResize];
_reshapeListener = reshapeListener;
_resizableBackingStoreProvider = [[FlutterMetalResizableBackingStoreProvider alloc]
initWithDevice:device
commandQueue:commandQueue
metalLayer:reinterpret_cast<CAMetalLayer*>(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<FlutterViewReshapeListener>)reshapeListener {
return [self initWithFrame:NSZeroRect mainContext:mainContext reshapeListener:reshapeListener];