Skip to content

Commit

Permalink
[macOS] Merge FlutterBackingStore implementations
Browse files Browse the repository at this point in the history
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: flutter/flutter#108304
Issue: flutter/flutter#114445
  • Loading branch information
cbracken committed Nov 17, 2022
1 parent 80b25a3 commit c18b252
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@
*/
@interface FlutterRenderBackingStore : NSObject

@end

/**
* Wraps a Metal texture.
*/
@interface FlutterMetalRenderBackingStore : FlutterRenderBackingStore

/**
* MTLTexture referenced by this backing store instance.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ - (nullable FlutterView*)getView:(uint64_t)viewId {

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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ - (FlutterMetalTexture)createTextureForView:(uint64_t)viewId size:(CGSize)size {
// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ - (void)cancelIdle {
- (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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ - (instancetype)init {
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));
}
Expand All @@ -55,8 +54,7 @@ - (instancetype)init {
[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));
}
Expand Down
8 changes: 4 additions & 4 deletions shell/platform/darwin/macos/framework/Source/FlutterView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@interface FlutterView () {
__weak id<FlutterViewReshapeListener> _reshapeListener;
FlutterResizeSynchronizer* _resizeSynchronizer;
id<FlutterResizableBackingStoreProvider> _resizableBackingStoreProvider;
FlutterResizableBackingStoreProvider* _resizableBackingStoreProvider;
}

@end
Expand All @@ -29,9 +29,9 @@ - (instancetype)initWithMTLDevice:(id<MTLDevice>)device
[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];
}
Expand Down

0 comments on commit c18b252

Please sign in to comment.