[macOS] Merge FlutterBackingStore implementations (flutter/engine#37730)
Now that OpenGL support has been removed from the macOS embedder, we merge FlutterRenderBackingStore and its only implementing subclass, FlutterMetalRenderBackingStore, and similarly FlutterRenderBackingStoreProvider and its only implementing subclass FlutterMetalRenderBackingStoreProvider. Issue: https://github.com/flutter/flutter/issues/108304 Issue: https://github.com/flutter/flutter/issues/114445
This commit is contained in:
@@ -11,13 +11,6 @@
|
||||
*/
|
||||
@interface FlutterRenderBackingStore : NSObject
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
* Wraps a Metal texture.
|
||||
*/
|
||||
@interface FlutterMetalRenderBackingStore : FlutterRenderBackingStore
|
||||
|
||||
/**
|
||||
* MTLTexture referenced by this backing store instance.
|
||||
*/
|
||||
|
||||
@@ -5,9 +5,6 @@
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterBackingStore.h"
|
||||
|
||||
@implementation FlutterRenderBackingStore
|
||||
@end
|
||||
|
||||
@implementation FlutterMetalRenderBackingStore
|
||||
|
||||
- (instancetype)initWithTexture:(id<MTLTexture>)texture {
|
||||
self = [super init];
|
||||
|
||||
@@ -37,8 +37,7 @@ bool FlutterCompositor::CreateBackingStore(const FlutterBackingStoreConfig* conf
|
||||
StartFrame();
|
||||
// If the backing store is for the first layer, return the MTLTexture for the
|
||||
// FlutterView.
|
||||
FlutterMetalRenderBackingStore* backingStore =
|
||||
reinterpret_cast<FlutterMetalRenderBackingStore*>([view backingStoreForSize:size]);
|
||||
FlutterRenderBackingStore* backingStore = [view backingStoreForSize:size];
|
||||
backing_store_out->metal.texture.texture =
|
||||
(__bridge FlutterMetalTextureHandle)backingStore.texture;
|
||||
} else {
|
||||
|
||||
@@ -43,8 +43,7 @@ namespace {
|
||||
|
||||
id<FlutterViewProvider> MockViewProvider() {
|
||||
FlutterView* viewMock = OCMClassMock([FlutterView class]);
|
||||
FlutterMetalRenderBackingStore* backingStoreMock =
|
||||
OCMClassMock([FlutterMetalRenderBackingStore class]);
|
||||
FlutterRenderBackingStore* backingStoreMock = OCMClassMock([FlutterRenderBackingStore class]);
|
||||
__block id<MTLTexture> textureMock = OCMProtocolMock(@protocol(MTLTexture));
|
||||
OCMStub([backingStoreMock texture]).andReturn(textureMock);
|
||||
|
||||
|
||||
@@ -95,8 +95,7 @@ static bool OnAcquireExternalTexture(FlutterEngine* engine,
|
||||
// FlutterMetalTexture has texture `null`, therefore is discarded.
|
||||
return FlutterMetalTexture{};
|
||||
}
|
||||
FlutterMetalRenderBackingStore* backingStore =
|
||||
(FlutterMetalRenderBackingStore*)[view backingStoreForSize:size];
|
||||
FlutterRenderBackingStore* backingStore = [view backingStoreForSize:size];
|
||||
id<MTLTexture> texture = backingStore.texture;
|
||||
FlutterMetalTexture embedderTexture;
|
||||
embedderTexture.struct_size = sizeof(FlutterMetalTexture);
|
||||
|
||||
@@ -10,10 +10,16 @@
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h"
|
||||
|
||||
/**
|
||||
* Represents a buffer that can be resized.
|
||||
* Provides resizable buffers backed by a MTLTexture.
|
||||
*/
|
||||
@protocol FlutterResizableBackingStoreProvider <FlutterResizeSynchronizerDelegate>
|
||||
@interface FlutterResizableBackingStoreProvider : NSObject <FlutterResizeSynchronizerDelegate>
|
||||
|
||||
/**
|
||||
* Creates a resizable backing store provider for the given CAMetalLayer.
|
||||
*/
|
||||
- (nonnull instancetype)initWithDevice:(nonnull id<MTLDevice>)device
|
||||
commandQueue:(nonnull id<MTLCommandQueue>)commandQueue
|
||||
layer:(nonnull CALayer*)layer;
|
||||
/**
|
||||
* Notify of the required backing store size updates. Called during window resize.
|
||||
*/
|
||||
@@ -25,19 +31,3 @@
|
||||
- (nonnull FlutterRenderBackingStore*)backingStore;
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
* Metal-backed FlutterResizableBackingStoreProvider. Backing store in this context implies a
|
||||
* MTLTexture.
|
||||
*/
|
||||
@interface FlutterMetalResizableBackingStoreProvider
|
||||
: NSObject <FlutterResizableBackingStoreProvider>
|
||||
|
||||
/**
|
||||
* Creates a resizable backing store provider for the given CAMetalLayer.
|
||||
*/
|
||||
- (nonnull instancetype)initWithDevice:(nonnull id<MTLDevice>)device
|
||||
commandQueue:(nonnull id<MTLCommandQueue>)commandQueue
|
||||
layer:(nonnull CALayer*)layer;
|
||||
|
||||
@end
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h"
|
||||
|
||||
@implementation FlutterMetalResizableBackingStoreProvider {
|
||||
@implementation FlutterResizableBackingStoreProvider {
|
||||
id<MTLDevice> _device;
|
||||
id<MTLCommandQueue> _commandQueue;
|
||||
FlutterSurfaceManager* _surfaceManager;
|
||||
|
||||
@@ -143,7 +143,7 @@ static const double kIdleDelay = 1.0;
|
||||
- (nonnull FlutterRenderBackingStore*)renderBuffer {
|
||||
[self ensureBackBuffer];
|
||||
id<MTLTexture> texture = _textures[kFlutterSurfaceManagerBackBuffer];
|
||||
return [[FlutterMetalRenderBackingStore alloc] initWithTexture:texture];
|
||||
return [[FlutterRenderBackingStore alloc] initWithTexture:texture];
|
||||
}
|
||||
|
||||
- (id<MTLTexture>)createTextureForSurface:(FlutterIOSurfaceHolder*)surface size:(CGSize)size {
|
||||
|
||||
@@ -43,8 +43,7 @@ TEST(FlutterSurfaceManager, EnsureSizeUpdatesSize) {
|
||||
FlutterSurfaceManager* surfaceManager = CreateSurfaceManager();
|
||||
CGSize size = CGSizeMake(100, 50);
|
||||
[surfaceManager ensureSurfaceSize:size];
|
||||
id<MTLTexture> texture =
|
||||
(reinterpret_cast<FlutterMetalRenderBackingStore*>([surfaceManager renderBuffer])).texture;
|
||||
id<MTLTexture> texture = [surfaceManager renderBuffer].texture;
|
||||
CGSize textureSize = CGSizeMake(texture.width, texture.height);
|
||||
ASSERT_TRUE(CGSizeEqualToSize(size, textureSize));
|
||||
}
|
||||
@@ -55,8 +54,7 @@ TEST(FlutterSurfaceManager, EnsureSizeUpdatesSizeForBackBuffer) {
|
||||
[surfaceManager ensureSurfaceSize:size];
|
||||
[surfaceManager renderBuffer]; // make sure we have back buffer
|
||||
[surfaceManager swapBuffers];
|
||||
id<MTLTexture> texture =
|
||||
(reinterpret_cast<FlutterMetalRenderBackingStore*>([surfaceManager renderBuffer])).texture;
|
||||
id<MTLTexture> texture = [surfaceManager renderBuffer].texture;
|
||||
CGSize textureSize = CGSizeMake(texture.width, texture.height);
|
||||
ASSERT_TRUE(CGSizeEqualToSize(size, textureSize));
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
@interface FlutterView () {
|
||||
__weak id<FlutterViewReshapeListener> _reshapeListener;
|
||||
FlutterResizeSynchronizer* _resizeSynchronizer;
|
||||
id<FlutterResizableBackingStoreProvider> _resizableBackingStoreProvider;
|
||||
FlutterResizableBackingStoreProvider* _resizableBackingStoreProvider;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -29,9 +29,9 @@
|
||||
[self setLayerContentsRedrawPolicy:NSViewLayerContentsRedrawDuringViewResize];
|
||||
_reshapeListener = reshapeListener;
|
||||
_resizableBackingStoreProvider =
|
||||
[[FlutterMetalResizableBackingStoreProvider alloc] initWithDevice:device
|
||||
commandQueue:commandQueue
|
||||
layer:self.layer];
|
||||
[[FlutterResizableBackingStoreProvider alloc] initWithDevice:device
|
||||
commandQueue:commandQueue
|
||||
layer:self.layer];
|
||||
_resizeSynchronizer =
|
||||
[[FlutterResizeSynchronizer alloc] initWithDelegate:_resizableBackingStoreProvider];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user