[macOS] Consolidate external texture classes (flutter/engine#37703)
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: https://github.com/flutter/flutter/issues/108304 Issue: https://github.com/flutter/flutter/issues/114445
This commit is contained in:
@@ -2629,8 +2629,8 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEngin
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEngineTestUtils.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEngineTestUtils.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTextureMetal.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTextureMetal.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTexture.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTexture.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterIOSurfaceHolder.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterIOSurfaceHolder.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterKeyPrimaryResponder.h
|
||||
@@ -2638,7 +2638,6 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterKeybo
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterKeyboardManager.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterKeyboardManagerUnittests.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterKeyboardViewDelegate.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterMacOSExternalTexture.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterMenuPlugin.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterMenuPlugin.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterMenuPluginTest.mm
|
||||
|
||||
@@ -69,16 +69,14 @@ source_set("flutter_framework_source") {
|
||||
"framework/Source/FlutterEmbedderKeyResponder.mm",
|
||||
"framework/Source/FlutterEngine.mm",
|
||||
"framework/Source/FlutterEngine_Internal.h",
|
||||
"framework/Source/FlutterExternalTextureMetal.h",
|
||||
"framework/Source/FlutterExternalTextureMetal.mm",
|
||||
"framework/Source/FlutterExternalTexture.h",
|
||||
"framework/Source/FlutterExternalTexture.mm",
|
||||
"framework/Source/FlutterIOSurfaceHolder.h",
|
||||
"framework/Source/FlutterIOSurfaceHolder.mm",
|
||||
"framework/Source/FlutterKeyPrimaryResponder.h",
|
||||
"framework/Source/FlutterKeyboardManager.h",
|
||||
"framework/Source/FlutterKeyboardManager.mm",
|
||||
"framework/Source/FlutterKeyboardViewDelegate.h",
|
||||
"framework/Source/FlutterMacOSExternalTexture.h",
|
||||
"framework/Source/FlutterMacOSExternalTexture.h",
|
||||
"framework/Source/FlutterMenuPlugin.h",
|
||||
"framework/Source/FlutterMenuPlugin.mm",
|
||||
"framework/Source/FlutterMenuPlugin_Internal.h",
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#import "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.h"
|
||||
#import "flutter/shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTextureMetal.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTexture.h"
|
||||
#include "flutter/shell/platform/embedder/embedder.h"
|
||||
#include "flutter/shell/platform/embedder/embedder_external_texture_metal.h"
|
||||
#import "flutter/testing/testing.h"
|
||||
@@ -140,9 +140,9 @@ TEST(FlutterEmbedderExternalTextureUnittests, TestPopulateExternalTexture) {
|
||||
[[TestExternalTexture alloc] initWidth:width
|
||||
height:height
|
||||
pixelFormatType:kCVPixelFormatType_32BGRA];
|
||||
FlutterExternalTextureMetal* textureHolder =
|
||||
[[FlutterExternalTextureMetal alloc] initWithFlutterTexture:testExternalTexture
|
||||
darwinMetalContext:darwinContextMetal];
|
||||
FlutterExternalTexture* textureHolder =
|
||||
[[FlutterExternalTexture alloc] initWithFlutterTexture:testExternalTexture
|
||||
darwinMetalContext:darwinContextMetal];
|
||||
|
||||
// Callback to resolve the texture.
|
||||
EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w,
|
||||
@@ -192,9 +192,9 @@ TEST(FlutterEmbedderExternalTextureUnittests, TestPopulateExternalTextureYUVA) {
|
||||
[[TestExternalTexture alloc] initWidth:width
|
||||
height:height
|
||||
pixelFormatType:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange];
|
||||
FlutterExternalTextureMetal* textureHolder =
|
||||
[[FlutterExternalTextureMetal alloc] initWithFlutterTexture:testExternalTexture
|
||||
darwinMetalContext:darwinContextMetal];
|
||||
FlutterExternalTexture* textureHolder =
|
||||
[[FlutterExternalTexture alloc] initWithFlutterTexture:testExternalTexture
|
||||
darwinMetalContext:darwinContextMetal];
|
||||
|
||||
// Callback to resolve the texture.
|
||||
EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w,
|
||||
@@ -246,9 +246,9 @@ TEST(FlutterEmbedderExternalTextureUnittests, TestPopulateExternalTextureYUVA2)
|
||||
[[TestExternalTexture alloc] initWidth:width
|
||||
height:height
|
||||
pixelFormatType:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange];
|
||||
FlutterExternalTextureMetal* textureHolder =
|
||||
[[FlutterExternalTextureMetal alloc] initWithFlutterTexture:testExternalTexture
|
||||
darwinMetalContext:darwinContextMetal];
|
||||
FlutterExternalTexture* textureHolder =
|
||||
[[FlutterExternalTexture alloc] initWithFlutterTexture:testExternalTexture
|
||||
darwinMetalContext:darwinContextMetal];
|
||||
|
||||
// Callback to resolve the texture.
|
||||
EmbedderExternalTextureMetal::ExternalTextureCallback callback = [&](int64_t texture_id, size_t w,
|
||||
|
||||
@@ -5,13 +5,14 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterMacOSExternalTexture.h"
|
||||
#include "flutter/shell/platform/embedder/embedder.h"
|
||||
|
||||
/**
|
||||
* Embedding side texture wrappers for Metal external textures.
|
||||
* Used to bridge FlutterTexture object and handle the texture copy request the
|
||||
* Flutter engine.
|
||||
*/
|
||||
@interface FlutterExternalTextureMetal : NSObject <FlutterMacOSExternalTexture>
|
||||
@interface FlutterExternalTexture : NSObject
|
||||
|
||||
/**
|
||||
* Initializes a texture adapter with |texture|.
|
||||
@@ -19,6 +20,11 @@
|
||||
- (nonnull instancetype)initWithFlutterTexture:(nonnull id<FlutterTexture>)texture
|
||||
darwinMetalContext:(nonnull FlutterDarwinContextMetalSkia*)context;
|
||||
|
||||
/**
|
||||
* Returns the ID for the FlutterExternalTexture instance.
|
||||
*/
|
||||
- (int64_t)textureID;
|
||||
|
||||
/**
|
||||
* Accepts texture buffer copy request from the Flutter engine.
|
||||
* When the user side marks the textureID as available, the Flutter engine will
|
||||
@@ -2,11 +2,11 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTextureMetal.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTexture.h"
|
||||
|
||||
#include "flutter/fml/platform/darwin/cf_utils.h"
|
||||
|
||||
@implementation FlutterExternalTextureMetal {
|
||||
@implementation FlutterExternalTexture {
|
||||
FlutterDarwinContextMetalSkia* _darwinMetalContext;
|
||||
|
||||
int64_t _textureID;
|
||||
@@ -1,20 +0,0 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterTexture.h"
|
||||
#import "flutter/shell/platform/embedder/embedder.h"
|
||||
|
||||
/*
|
||||
* Embedding side texture wrappers for GL and Metal external textures.
|
||||
*/
|
||||
@protocol FlutterMacOSExternalTexture
|
||||
|
||||
/**
|
||||
* Returns the ID for the FlutterTexture instance.
|
||||
*/
|
||||
- (int64_t)textureID;
|
||||
|
||||
@end
|
||||
@@ -5,7 +5,7 @@
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterRenderer.h"
|
||||
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTextureMetal.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTexture.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h"
|
||||
#include "flutter/shell/platform/embedder/embedder.h"
|
||||
|
||||
@@ -111,15 +111,13 @@ static bool OnAcquireExternalTexture(FlutterEngine* engine,
|
||||
|
||||
- (BOOL)populateTextureWithIdentifier:(int64_t)textureID
|
||||
metalTexture:(FlutterMetalExternalTexture*)textureOut {
|
||||
id<FlutterMacOSExternalTexture> texture = [self getTextureWithID:textureID];
|
||||
FlutterExternalTextureMetal* metalTexture =
|
||||
reinterpret_cast<FlutterExternalTextureMetal*>(texture);
|
||||
return [metalTexture populateTexture:textureOut];
|
||||
FlutterExternalTexture* texture = [self getTextureWithID:textureID];
|
||||
return [texture populateTexture:textureOut];
|
||||
}
|
||||
|
||||
- (id<FlutterMacOSExternalTexture>)onRegisterTexture:(id<FlutterTexture>)texture {
|
||||
return [[FlutterExternalTextureMetal alloc] initWithFlutterTexture:texture
|
||||
darwinMetalContext:_darwinMetalContext];
|
||||
- (FlutterExternalTexture*)onRegisterTexture:(id<FlutterTexture>)texture {
|
||||
return [[FlutterExternalTexture alloc] initWithFlutterTexture:texture
|
||||
darwinMetalContext:_darwinMetalContext];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Headers/FlutterEngine.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterMacOSExternalTexture.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterExternalTexture.h"
|
||||
|
||||
/*
|
||||
* Delegate methods for FlutterTextureRegistrar.
|
||||
@@ -15,7 +15,7 @@
|
||||
/*
|
||||
* Called by the FlutterTextureRegistrar when a texture is registered.
|
||||
*/
|
||||
- (nonnull id<FlutterMacOSExternalTexture>)onRegisterTexture:(nonnull id<FlutterTexture>)texture;
|
||||
- (nonnull FlutterExternalTexture*)onRegisterTexture:(nonnull id<FlutterTexture>)texture;
|
||||
|
||||
@end
|
||||
|
||||
@@ -43,6 +43,6 @@
|
||||
/*
|
||||
* Returns the registered texture with the provided `textureID`.
|
||||
*/
|
||||
- (nullable id<FlutterMacOSExternalTexture>)getTextureWithID:(int64_t)textureID;
|
||||
- (nullable FlutterExternalTexture*)getTextureWithID:(int64_t)textureID;
|
||||
|
||||
@end
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
|
||||
__weak FlutterEngine* _flutterEngine;
|
||||
|
||||
// A mapping of textureID to internal FlutterExternalTextureGL adapter.
|
||||
NSMutableDictionary<NSNumber*, id<FlutterMacOSExternalTexture>>* _textures;
|
||||
// A mapping of textureID to internal FlutterExternalTexture wrapper.
|
||||
NSMutableDictionary<NSNumber*, FlutterExternalTexture*>* _textures;
|
||||
}
|
||||
|
||||
- (instancetype)initWithDelegate:(id<FlutterTextureRegistrarDelegate>)delegate
|
||||
@@ -26,7 +26,7 @@
|
||||
}
|
||||
|
||||
- (int64_t)registerTexture:(id<FlutterTexture>)texture {
|
||||
id<FlutterMacOSExternalTexture> externalTexture = [_delegate onRegisterTexture:texture];
|
||||
FlutterExternalTexture* externalTexture = [_delegate onRegisterTexture:texture];
|
||||
int64_t textureID = [externalTexture textureID];
|
||||
BOOL success = [_flutterEngine registerTextureWithID:textureID];
|
||||
if (success) {
|
||||
@@ -54,7 +54,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (id<FlutterMacOSExternalTexture>)getTextureWithID:(int64_t)textureID {
|
||||
- (FlutterExternalTexture*)getTextureWithID:(int64_t)textureID {
|
||||
return _textures[@(textureID)];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user