Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f27666d

Browse files
authored
[macOS] Merge FlutterBackingStore implementations (#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: flutter/flutter#108304 Issue: flutter/flutter#114445
1 parent e812122 commit f27666d

10 files changed

+19
-44
lines changed

shell/platform/darwin/macos/framework/Source/FlutterBackingStore.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@
1111
*/
1212
@interface FlutterRenderBackingStore : NSObject
1313

14-
@end
15-
16-
/**
17-
* Wraps a Metal texture.
18-
*/
19-
@interface FlutterMetalRenderBackingStore : FlutterRenderBackingStore
20-
2114
/**
2215
* MTLTexture referenced by this backing store instance.
2316
*/

shell/platform/darwin/macos/framework/Source/FlutterBackingStore.mm

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterBackingStore.h"
66

77
@implementation FlutterRenderBackingStore
8-
@end
9-
10-
@implementation FlutterMetalRenderBackingStore
118

129
- (instancetype)initWithTexture:(id<MTLTexture>)texture {
1310
self = [super init];

shell/platform/darwin/macos/framework/Source/FlutterCompositor.mm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@
3737
StartFrame();
3838
// If the backing store is for the first layer, return the MTLTexture for the
3939
// FlutterView.
40-
FlutterMetalRenderBackingStore* backingStore =
41-
reinterpret_cast<FlutterMetalRenderBackingStore*>([view backingStoreForSize:size]);
40+
FlutterRenderBackingStore* backingStore = [view backingStoreForSize:size];
4241
backing_store_out->metal.texture.texture =
4342
(__bridge FlutterMetalTextureHandle)backingStore.texture;
4443
} else {

shell/platform/darwin/macos/framework/Source/FlutterCompositorUnittests.mm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ - (nullable FlutterView*)getView:(uint64_t)viewId {
4343

4444
id<FlutterViewProvider> MockViewProvider() {
4545
FlutterView* viewMock = OCMClassMock([FlutterView class]);
46-
FlutterMetalRenderBackingStore* backingStoreMock =
47-
OCMClassMock([FlutterMetalRenderBackingStore class]);
46+
FlutterRenderBackingStore* backingStoreMock = OCMClassMock([FlutterRenderBackingStore class]);
4847
__block id<MTLTexture> textureMock = OCMProtocolMock(@protocol(MTLTexture));
4948
OCMStub([backingStoreMock texture]).andReturn(textureMock);
5049

shell/platform/darwin/macos/framework/Source/FlutterRenderer.mm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ - (FlutterMetalTexture)createTextureForView:(uint64_t)viewId size:(CGSize)size {
9595
// FlutterMetalTexture has texture `null`, therefore is discarded.
9696
return FlutterMetalTexture{};
9797
}
98-
FlutterMetalRenderBackingStore* backingStore =
99-
(FlutterMetalRenderBackingStore*)[view backingStoreForSize:size];
98+
FlutterRenderBackingStore* backingStore = [view backingStoreForSize:size];
10099
id<MTLTexture> texture = backingStore.texture;
101100
FlutterMetalTexture embedderTexture;
102101
embedderTexture.struct_size = sizeof(FlutterMetalTexture);

shell/platform/darwin/macos/framework/Source/FlutterResizableBackingStoreProvider.h

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@
1010
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h"
1111

1212
/**
13-
* Represents a buffer that can be resized.
13+
* Provides resizable buffers backed by a MTLTexture.
1414
*/
15-
@protocol FlutterResizableBackingStoreProvider <FlutterResizeSynchronizerDelegate>
15+
@interface FlutterResizableBackingStoreProvider : NSObject <FlutterResizeSynchronizerDelegate>
1616

17+
/**
18+
* Creates a resizable backing store provider for the given CAMetalLayer.
19+
*/
20+
- (nonnull instancetype)initWithDevice:(nonnull id<MTLDevice>)device
21+
commandQueue:(nonnull id<MTLCommandQueue>)commandQueue
22+
layer:(nonnull CALayer*)layer;
1723
/**
1824
* Notify of the required backing store size updates. Called during window resize.
1925
*/
@@ -25,19 +31,3 @@
2531
- (nonnull FlutterRenderBackingStore*)backingStore;
2632

2733
@end
28-
29-
/**
30-
* Metal-backed FlutterResizableBackingStoreProvider. Backing store in this context implies a
31-
* MTLTexture.
32-
*/
33-
@interface FlutterMetalResizableBackingStoreProvider
34-
: NSObject <FlutterResizableBackingStoreProvider>
35-
36-
/**
37-
* Creates a resizable backing store provider for the given CAMetalLayer.
38-
*/
39-
- (nonnull instancetype)initWithDevice:(nonnull id<MTLDevice>)device
40-
commandQueue:(nonnull id<MTLCommandQueue>)commandQueue
41-
layer:(nonnull CALayer*)layer;
42-
43-
@end

shell/platform/darwin/macos/framework/Source/FlutterResizableBackingStoreProvider.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h"
1010

11-
@implementation FlutterMetalResizableBackingStoreProvider {
11+
@implementation FlutterResizableBackingStoreProvider {
1212
id<MTLDevice> _device;
1313
id<MTLCommandQueue> _commandQueue;
1414
FlutterSurfaceManager* _surfaceManager;

shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ - (void)cancelIdle {
143143
- (nonnull FlutterRenderBackingStore*)renderBuffer {
144144
[self ensureBackBuffer];
145145
id<MTLTexture> texture = _textures[kFlutterSurfaceManagerBackBuffer];
146-
return [[FlutterMetalRenderBackingStore alloc] initWithTexture:texture];
146+
return [[FlutterRenderBackingStore alloc] initWithTexture:texture];
147147
}
148148

149149
- (id<MTLTexture>)createTextureForSurface:(FlutterIOSurfaceHolder*)surface size:(CGSize)size {

shell/platform/darwin/macos/framework/Source/FlutterSurfaceManagerTest.mm

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ - (instancetype)init {
4343
FlutterSurfaceManager* surfaceManager = CreateSurfaceManager();
4444
CGSize size = CGSizeMake(100, 50);
4545
[surfaceManager ensureSurfaceSize:size];
46-
id<MTLTexture> texture =
47-
(reinterpret_cast<FlutterMetalRenderBackingStore*>([surfaceManager renderBuffer])).texture;
46+
id<MTLTexture> texture = [surfaceManager renderBuffer].texture;
4847
CGSize textureSize = CGSizeMake(texture.width, texture.height);
4948
ASSERT_TRUE(CGSizeEqualToSize(size, textureSize));
5049
}
@@ -55,8 +54,7 @@ - (instancetype)init {
5554
[surfaceManager ensureSurfaceSize:size];
5655
[surfaceManager renderBuffer]; // make sure we have back buffer
5756
[surfaceManager swapBuffers];
58-
id<MTLTexture> texture =
59-
(reinterpret_cast<FlutterMetalRenderBackingStore*>([surfaceManager renderBuffer])).texture;
57+
id<MTLTexture> texture = [surfaceManager renderBuffer].texture;
6058
CGSize textureSize = CGSizeMake(texture.width, texture.height);
6159
ASSERT_TRUE(CGSizeEqualToSize(size, textureSize));
6260
}

shell/platform/darwin/macos/framework/Source/FlutterView.mm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@interface FlutterView () {
1313
__weak id<FlutterViewReshapeListener> _reshapeListener;
1414
FlutterResizeSynchronizer* _resizeSynchronizer;
15-
id<FlutterResizableBackingStoreProvider> _resizableBackingStoreProvider;
15+
FlutterResizableBackingStoreProvider* _resizableBackingStoreProvider;
1616
}
1717

1818
@end
@@ -29,9 +29,9 @@ - (instancetype)initWithMTLDevice:(id<MTLDevice>)device
2929
[self setLayerContentsRedrawPolicy:NSViewLayerContentsRedrawDuringViewResize];
3030
_reshapeListener = reshapeListener;
3131
_resizableBackingStoreProvider =
32-
[[FlutterMetalResizableBackingStoreProvider alloc] initWithDevice:device
33-
commandQueue:commandQueue
34-
layer:self.layer];
32+
[[FlutterResizableBackingStoreProvider alloc] initWithDevice:device
33+
commandQueue:commandQueue
34+
layer:self.layer];
3535
_resizeSynchronizer =
3636
[[FlutterResizeSynchronizer alloc] initWithDelegate:_resizableBackingStoreProvider];
3737
}

0 commit comments

Comments
 (0)