Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macOS] Clean up unused methods in FlutterRenderer #42196

Merged
merged 5 commits into from
May 21, 2023
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
2 changes: 0 additions & 2 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -2705,7 +2705,6 @@ ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterPla
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterPlatformViewControllerTest.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterRenderer.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterRenderer.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterRendererTest.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterSurface.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterSurface.mm + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h + ../../../flutter/LICENSE
Expand Down Expand Up @@ -5344,7 +5343,6 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterPlatf
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterPlatformViewControllerTest.mm
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterRenderer.h
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterRenderer.mm
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterRendererTest.mm
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterSurface.h
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterSurface.mm
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterSurfaceManager.h
Expand Down
1 change: 0 additions & 1 deletion shell/platform/darwin/macos/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ executable("flutter_desktop_darwin_unittests") {
"framework/Source/FlutterMutatorViewTest.mm",
"framework/Source/FlutterPlatformNodeDelegateMacTest.mm",
"framework/Source/FlutterPlatformViewControllerTest.mm",
"framework/Source/FlutterRendererTest.mm",
"framework/Source/FlutterSurfaceManagerTest.mm",
"framework/Source/FlutterTextInputPluginTest.mm",
"framework/Source/FlutterTextInputSemanticsObjectTest.mm",
Expand Down
10 changes: 0 additions & 10 deletions shell/platform/darwin/macos/framework/Source/FlutterRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@
*/
- (FlutterRendererConfig)createRendererConfig;

/**
* Called by the engine when the given view's buffers should be swapped.
*/
- (BOOL)present:(FlutterViewId)viewId texture:(nonnull const FlutterMetalTexture*)texture;

/**
* Creates a Metal texture for the given view with the given size.
*/
- (FlutterMetalTexture)createTextureForView:(FlutterViewId)viewId size:(CGSize)size;

/**
* Populates the texture registry with the provided metalTexture.
*/
Expand Down
58 changes: 11 additions & 47 deletions shell/platform/darwin/macos/framework/Source/FlutterRenderer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,15 @@

#pragma mark - Static callbacks that require the engine.

static FlutterMetalTexture OnGetNextDrawableForDefaultView(FlutterEngine* engine,
const FlutterFrameInfo* frameInfo) {
// TODO(dkwingsmt): This callback only supports single-view, therefore it only
// operates on the default view. To support multi-view, we need a new callback
// that also receives a view ID, or pass the ID via FlutterFrameInfo.
FlutterViewId viewId = kFlutterDefaultViewId;
CGSize size = CGSizeMake(frameInfo->size.width, frameInfo->size.height);
return [engine.renderer createTextureForView:viewId size:size];
static FlutterMetalTexture OnGetNextDrawable(FlutterEngine* engine,
const FlutterFrameInfo* frameInfo) {
NSCAssert(NO, @"The renderer config should not be used to get the next drawable.");
return FlutterMetalTexture{};
}

static bool OnPresentDrawableOfDefaultView(FlutterEngine* engine,
const FlutterMetalTexture* texture) {
// TODO(dkwingsmt): This callback only supports single-view, therefore it only
// operates on the default view. To support multi-view, we need a new callback
// that also receives a view ID.
FlutterViewId viewId = kFlutterDefaultViewId;
return [engine.renderer present:viewId texture:texture];
static bool OnPresentDrawable(FlutterEngine* engine, const FlutterMetalTexture* texture) {
NSCAssert(NO, @"The renderer config should not be used to present drawable.");
return false;
}

static bool OnAcquireExternalTexture(FlutterEngine* engine,
Expand All @@ -43,15 +35,12 @@ static bool OnAcquireExternalTexture(FlutterEngine* engine,
#pragma mark - FlutterRenderer implementation

@implementation FlutterRenderer {
FlutterViewEngineProvider* _viewProvider;

FlutterDarwinContextMetalSkia* _darwinMetalContext;
}

- (instancetype)initWithFlutterEngine:(nonnull FlutterEngine*)flutterEngine {
self = [super initWithDelegate:self engine:flutterEngine];
if (self) {
_viewProvider = [[FlutterViewEngineProvider alloc] initWithEngine:flutterEngine];
_device = MTLCreateSystemDefaultDevice();
if (!_device) {
NSLog(@"Could not acquire Metal device.");
Expand All @@ -77,9 +66,9 @@ - (FlutterRendererConfig)createRendererConfig {
.metal.device = (__bridge FlutterMetalDeviceHandle)_device,
.metal.present_command_queue = (__bridge FlutterMetalCommandQueueHandle)_commandQueue,
.metal.get_next_drawable_callback =
reinterpret_cast<FlutterMetalTextureCallback>(OnGetNextDrawableForDefaultView),
reinterpret_cast<FlutterMetalTextureCallback>(OnGetNextDrawable),
.metal.present_drawable_callback =
reinterpret_cast<FlutterMetalPresentCallback>(OnPresentDrawableOfDefaultView),
reinterpret_cast<FlutterMetalPresentCallback>(OnPresentDrawable),
.metal.external_texture_frame_callback =
reinterpret_cast<FlutterMetalTextureFrameCallback>(OnAcquireExternalTexture),
};
Expand All @@ -88,39 +77,14 @@ - (FlutterRendererConfig)createRendererConfig {

#pragma mark - Embedder callback implementations.

- (FlutterMetalTexture)createTextureForView:(FlutterViewId)viewId size:(CGSize)size {
FlutterView* view = [_viewProvider viewForId:viewId];
NSAssert(view != nil, @"Can't create texture on a non-existent view 0x%llx.", viewId);
if (view == nil) {
// FlutterMetalTexture has texture `null`, therefore is discarded.
return FlutterMetalTexture{};
}
return [view.surfaceManager surfaceForSize:size].asFlutterMetalTexture;
}

- (BOOL)present:(FlutterViewId)viewId texture:(const FlutterMetalTexture*)texture {
FlutterView* view = [_viewProvider viewForId:viewId];
if (view == nil) {
return NO;
}
FlutterSurface* surface = [FlutterSurface fromFlutterMetalTexture:texture];
if (surface == nil) {
return NO;
}
FlutterSurfacePresentInfo* info = [[FlutterSurfacePresentInfo alloc] init];
info.surface = surface;
[view.surfaceManager present:@[ info ] notify:nil];
return YES;
}

#pragma mark - FlutterTextureRegistrar methods.

- (BOOL)populateTextureWithIdentifier:(int64_t)textureID
metalTexture:(FlutterMetalExternalTexture*)textureOut {
FlutterExternalTexture* texture = [self getTextureWithID:textureID];
return [texture populateTexture:textureOut];
}

#pragma mark - FlutterTextureRegistrar methods.

- (FlutterExternalTexture*)onRegisterTexture:(id<FlutterTexture>)texture {
return [[FlutterExternalTexture alloc] initWithFlutterTexture:texture
darwinMetalContext:_darwinMetalContext];
Expand Down
104 changes: 0 additions & 104 deletions shell/platform/darwin/macos/framework/Source/FlutterRendererTest.mm

This file was deleted.

4 changes: 4 additions & 0 deletions shell/platform/embedder/embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -676,9 +676,13 @@ typedef struct {
FlutterMetalCommandQueueHandle present_command_queue;
/// The callback that gets invoked when the engine requests the embedder for a
/// texture to render to.
///
/// Not used if a FlutterCompositor is supplied in FlutterProjectArgs.
FlutterMetalTextureCallback get_next_drawable_callback;
/// The callback presented to the embedder to present a fully populated metal
/// texture to the user.
///
/// Not used if a FlutterCompositor is supplied in FlutterProjectArgs.
FlutterMetalPresentCallback present_drawable_callback;
/// When the embedder specifies that a texture has a frame available, the
/// engine will call this method (on an internal engine managed thread) so
Expand Down