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

[macOS] Consolidate external texture classes #37703

Merged
merged 1 commit into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -2629,16 +2629,15 @@ 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
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterKeyboardManager.h
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
Expand Down
6 changes: 2 additions & 4 deletions shell/platform/darwin/macos/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -140,9 +140,9 @@ - (CVPixelBufferRef)pixelBuffer {
[[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,
Expand Down Expand Up @@ -192,9 +192,9 @@ - (CVPixelBufferRef)pixelBuffer {
[[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,
Expand Down Expand Up @@ -246,9 +246,9 @@ - (CVPixelBufferRef)pixelBuffer {
[[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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@
#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|.
*/
- (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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

This file was deleted.

14 changes: 6 additions & 8 deletions shell/platform/darwin/macos/framework/Source/FlutterRenderer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -111,15 +111,13 @@ - (void)presentWithoutContent {

- (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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ @implementation FlutterTextureRegistrar {

__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
Expand All @@ -26,7 +26,7 @@ - (instancetype)initWithDelegate:(id<FlutterTextureRegistrarDelegate>)delegate
}

- (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) {
Expand Down Expand Up @@ -54,7 +54,7 @@ - (void)unregisterTexture:(int64_t)textureID {
}
}

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

Expand Down