Skip to content

Commit 1b099cb

Browse files
committed
[macOS] Consolidate external texture classes
Previously, external textures were modelled in the macOS embedder by a top-level FlutterMacOSExternalTexture protocol with a single textureID getter, and two implementations: FlutterExternalTextureGL and FlutterExternalTextureMetal. With the removal of OpenGL support from the macOS embedder, the only remaining external texture implementation is Metal. This patch squashes this set of types into a single FlutterExternalTexture class. Issue: flutter/flutter#108304 Issue: flutter/flutter#114445
1 parent 11727b4 commit 1b099cb

9 files changed

+37
-56
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,16 +2629,15 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEngin
26292629
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEngineTestUtils.h
26302630
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEngineTestUtils.mm
26312631
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h
2632-
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTextureMetal.h
2633-
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTextureMetal.mm
2632+
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTexture.h
2633+
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTexture.mm
26342634
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterIOSurfaceHolder.h
26352635
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterIOSurfaceHolder.mm
26362636
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterKeyPrimaryResponder.h
26372637
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterKeyboardManager.h
26382638
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterKeyboardManager.mm
26392639
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterKeyboardManagerUnittests.mm
26402640
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterKeyboardViewDelegate.h
2641-
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterMacOSExternalTexture.h
26422641
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterMenuPlugin.h
26432642
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterMenuPlugin.mm
26442643
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterMenuPluginTest.mm

shell/platform/darwin/macos/BUILD.gn

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,14 @@ source_set("flutter_framework_source") {
6969
"framework/Source/FlutterEmbedderKeyResponder.mm",
7070
"framework/Source/FlutterEngine.mm",
7171
"framework/Source/FlutterEngine_Internal.h",
72-
"framework/Source/FlutterExternalTextureMetal.h",
73-
"framework/Source/FlutterExternalTextureMetal.mm",
72+
"framework/Source/FlutterExternalTexture.h",
73+
"framework/Source/FlutterExternalTexture.mm",
7474
"framework/Source/FlutterIOSurfaceHolder.h",
7575
"framework/Source/FlutterIOSurfaceHolder.mm",
7676
"framework/Source/FlutterKeyPrimaryResponder.h",
7777
"framework/Source/FlutterKeyboardManager.h",
7878
"framework/Source/FlutterKeyboardManager.mm",
7979
"framework/Source/FlutterKeyboardViewDelegate.h",
80-
"framework/Source/FlutterMacOSExternalTexture.h",
81-
"framework/Source/FlutterMacOSExternalTexture.h",
8280
"framework/Source/FlutterMenuPlugin.h",
8381
"framework/Source/FlutterMenuPlugin.mm",
8482
"framework/Source/FlutterMenuPlugin_Internal.h",

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#import "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.h"
1212
#import "flutter/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.h"
13-
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTextureMetal.h"
13+
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTexture.h"
1414
#include "flutter/shell/platform/embedder/embedder.h"
1515
#include "flutter/shell/platform/embedder/embedder_external_texture_metal.h"
1616
#import "flutter/testing/testing.h"
@@ -140,9 +140,9 @@ - (CVPixelBufferRef)pixelBuffer {
140140
[[TestExternalTexture alloc] initWidth:width
141141
height:height
142142
pixelFormatType:kCVPixelFormatType_32BGRA];
143-
FlutterExternalTextureMetal* textureHolder =
144-
[[FlutterExternalTextureMetal alloc] initWithFlutterTexture:testExternalTexture
145-
darwinMetalContext:darwinContextMetal];
143+
FlutterExternalTexture* textureHolder =
144+
[[FlutterExternalTexture alloc] initWithFlutterTexture:testExternalTexture
145+
darwinMetalContext:darwinContextMetal];
146146

147147
// Callback to resolve the texture.
148148
EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w,
@@ -192,9 +192,9 @@ - (CVPixelBufferRef)pixelBuffer {
192192
[[TestExternalTexture alloc] initWidth:width
193193
height:height
194194
pixelFormatType:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange];
195-
FlutterExternalTextureMetal* textureHolder =
196-
[[FlutterExternalTextureMetal alloc] initWithFlutterTexture:testExternalTexture
197-
darwinMetalContext:darwinContextMetal];
195+
FlutterExternalTexture* textureHolder =
196+
[[FlutterExternalTexture alloc] initWithFlutterTexture:testExternalTexture
197+
darwinMetalContext:darwinContextMetal];
198198

199199
// Callback to resolve the texture.
200200
EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w,
@@ -246,9 +246,9 @@ - (CVPixelBufferRef)pixelBuffer {
246246
[[TestExternalTexture alloc] initWidth:width
247247
height:height
248248
pixelFormatType:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange];
249-
FlutterExternalTextureMetal* textureHolder =
250-
[[FlutterExternalTextureMetal alloc] initWithFlutterTexture:testExternalTexture
251-
darwinMetalContext:darwinContextMetal];
249+
FlutterExternalTexture* textureHolder =
250+
[[FlutterExternalTexture alloc] initWithFlutterTexture:testExternalTexture
251+
darwinMetalContext:darwinContextMetal];
252252

253253
// Callback to resolve the texture.
254254
EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w,

shell/platform/darwin/macos/framework/Source/FlutterExternalTextureMetal.h renamed to shell/platform/darwin/macos/framework/Source/FlutterExternalTexture.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,26 @@
55
#import <Foundation/Foundation.h>
66

77
#import "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.h"
8-
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterMacOSExternalTexture.h"
8+
#include "flutter/shell/platform/embedder/embedder.h"
99

1010
/**
11+
* Embedding side texture wrappers for Metal external textures.
1112
* Used to bridge FlutterTexture object and handle the texture copy request the
1213
* Flutter engine.
1314
*/
14-
@interface FlutterExternalTextureMetal : NSObject <FlutterMacOSExternalTexture>
15+
@interface FlutterExternalTexture : NSObject
1516

1617
/**
1718
* Initializes a texture adapter with |texture|.
1819
*/
1920
- (nonnull instancetype)initWithFlutterTexture:(nonnull id<FlutterTexture>)texture
2021
darwinMetalContext:(nonnull FlutterDarwinContextMetalSkia*)context;
2122

23+
/**
24+
* Returns the ID for the FlutterExternalTexture instance.
25+
*/
26+
- (int64_t)textureID;
27+
2228
/**
2329
* Accepts texture buffer copy request from the Flutter engine.
2430
* When the user side marks the textureID as available, the Flutter engine will

shell/platform/darwin/macos/framework/Source/FlutterExternalTextureMetal.mm renamed to shell/platform/darwin/macos/framework/Source/FlutterExternalTexture.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTextureMetal.h"
5+
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTexture.h"
66

77
#include "flutter/fml/platform/darwin/cf_utils.h"
88

9-
@implementation FlutterExternalTextureMetal {
9+
@implementation FlutterExternalTexture {
1010
FlutterDarwinContextMetalSkia* _darwinMetalContext;
1111

1212
int64_t _textureID;

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

Lines changed: 0 additions & 20 deletions
This file was deleted.

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

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

77
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h"
8-
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTextureMetal.h"
8+
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTexture.h"
99
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h"
1010
#include "flutter/shell/platform/embedder/embedder.h"
1111

@@ -111,15 +111,13 @@ - (void)presentWithoutContent {
111111

112112
- (BOOL)populateTextureWithIdentifier:(int64_t)textureID
113113
metalTexture:(FlutterMetalExternalTexture*)textureOut {
114-
id<FlutterMacOSExternalTexture> texture = [self getTextureWithID:textureID];
115-
FlutterExternalTextureMetal* metalTexture =
116-
reinterpret_cast<FlutterExternalTextureMetal*>(texture);
117-
return [metalTexture populateTexture:textureOut];
114+
FlutterExternalTexture* texture = [self getTextureWithID:textureID];
115+
return [texture populateTexture:textureOut];
118116
}
119117

120-
- (id<FlutterMacOSExternalTexture>)onRegisterTexture:(id<FlutterTexture>)texture {
121-
return [[FlutterExternalTextureMetal alloc] initWithFlutterTexture:texture
122-
darwinMetalContext:_darwinMetalContext];
118+
- (FlutterExternalTexture*)onRegisterTexture:(id<FlutterTexture>)texture {
119+
return [[FlutterExternalTexture alloc] initWithFlutterTexture:texture
120+
darwinMetalContext:_darwinMetalContext];
123121
}
124122

125123
@end

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#import <Cocoa/Cocoa.h>
66

77
#import "flutter/shell/platform/darwin/macos/framework/Headers/FlutterEngine.h"
8-
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterMacOSExternalTexture.h"
8+
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTexture.h"
99

1010
/*
1111
* Delegate methods for FlutterTextureRegistrar.
@@ -15,7 +15,7 @@
1515
/*
1616
* Called by the FlutterTextureRegistrar when a texture is registered.
1717
*/
18-
- (nonnull id<FlutterMacOSExternalTexture>)onRegisterTexture:(nonnull id<FlutterTexture>)texture;
18+
- (nonnull FlutterExternalTexture*)onRegisterTexture:(nonnull id<FlutterTexture>)texture;
1919

2020
@end
2121

@@ -43,6 +43,6 @@
4343
/*
4444
* Returns the registered texture with the provided `textureID`.
4545
*/
46-
- (nullable id<FlutterMacOSExternalTexture>)getTextureWithID:(int64_t)textureID;
46+
- (nullable FlutterExternalTexture*)getTextureWithID:(int64_t)textureID;
4747

4848
@end

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ @implementation FlutterTextureRegistrar {
1111

1212
__weak FlutterEngine* _flutterEngine;
1313

14-
// A mapping of textureID to internal FlutterExternalTextureGL adapter.
15-
NSMutableDictionary<NSNumber*, id<FlutterMacOSExternalTexture>>* _textures;
14+
// A mapping of textureID to internal FlutterExternalTexture wrapper.
15+
NSMutableDictionary<NSNumber*, FlutterExternalTexture*>* _textures;
1616
}
1717

1818
- (instancetype)initWithDelegate:(id<FlutterTextureRegistrarDelegate>)delegate
@@ -26,7 +26,7 @@ - (instancetype)initWithDelegate:(id<FlutterTextureRegistrarDelegate>)delegate
2626
}
2727

2828
- (int64_t)registerTexture:(id<FlutterTexture>)texture {
29-
id<FlutterMacOSExternalTexture> externalTexture = [_delegate onRegisterTexture:texture];
29+
FlutterExternalTexture* externalTexture = [_delegate onRegisterTexture:texture];
3030
int64_t textureID = [externalTexture textureID];
3131
BOOL success = [_flutterEngine registerTextureWithID:textureID];
3232
if (success) {
@@ -54,7 +54,7 @@ - (void)unregisterTexture:(int64_t)textureID {
5454
}
5555
}
5656

57-
- (id<FlutterMacOSExternalTexture>)getTextureWithID:(int64_t)textureID {
57+
- (FlutterExternalTexture*)getTextureWithID:(int64_t)textureID {
5858
return _textures[@(textureID)];
5959
}
6060

0 commit comments

Comments
 (0)