[macOS] Merge FlutterRenderer and implementation (flutter/engine#37696)
This commit is contained in:
@@ -2643,9 +2643,6 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterMenuP
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterMenuPlugin.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterMenuPluginTest.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterMenuPlugin_Internal.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterMetalRenderer.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterMetalRenderer.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterMetalRendererTest.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterMetalSurfaceManagerTest.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterMouseCursorPlugin.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterMouseCursorPlugin.mm
|
||||
@@ -2656,6 +2653,8 @@ FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterPlatf
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterPlatformViewController.mm
|
||||
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/FlutterResizableBackingStoreProvider.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterResizableBackingStoreProvider.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h
|
||||
|
||||
@@ -82,8 +82,6 @@ source_set("flutter_framework_source") {
|
||||
"framework/Source/FlutterMenuPlugin.h",
|
||||
"framework/Source/FlutterMenuPlugin.mm",
|
||||
"framework/Source/FlutterMenuPlugin_Internal.h",
|
||||
"framework/Source/FlutterMetalRenderer.h",
|
||||
"framework/Source/FlutterMetalRenderer.mm",
|
||||
"framework/Source/FlutterMouseCursorPlugin.h",
|
||||
"framework/Source/FlutterMouseCursorPlugin.mm",
|
||||
"framework/Source/FlutterPlatformNodeDelegateMac.h",
|
||||
@@ -91,6 +89,7 @@ source_set("flutter_framework_source") {
|
||||
"framework/Source/FlutterPlatformViewController.h",
|
||||
"framework/Source/FlutterPlatformViewController.mm",
|
||||
"framework/Source/FlutterRenderer.h",
|
||||
"framework/Source/FlutterRenderer.mm",
|
||||
"framework/Source/FlutterResizableBackingStoreProvider.h",
|
||||
"framework/Source/FlutterResizableBackingStoreProvider.mm",
|
||||
"framework/Source/FlutterResizeSynchronizer.h",
|
||||
@@ -177,10 +176,10 @@ executable("flutter_desktop_darwin_unittests") {
|
||||
"framework/Source/FlutterEngineTestUtils.mm",
|
||||
"framework/Source/FlutterKeyboardManagerUnittests.mm",
|
||||
"framework/Source/FlutterMenuPluginTest.mm",
|
||||
"framework/Source/FlutterMetalRendererTest.mm",
|
||||
"framework/Source/FlutterMetalSurfaceManagerTest.mm",
|
||||
"framework/Source/FlutterPlatformNodeDelegateMacTest.mm",
|
||||
"framework/Source/FlutterPlatformViewControllerTest.mm",
|
||||
"framework/Source/FlutterRendererTest.mm",
|
||||
"framework/Source/FlutterTextInputPluginTest.mm",
|
||||
"framework/Source/FlutterTextInputSemanticsObjectTest.mm",
|
||||
"framework/Source/FlutterViewControllerTest.mm",
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterCompositor.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterMenuPlugin.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterMetalRenderer.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterMouseCursorPlugin.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterPlatformViewController.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterRenderer.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewEngineProvider.h"
|
||||
#include "flutter/shell/platform/embedder/embedder.h"
|
||||
@@ -246,7 +246,7 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi
|
||||
_embedderAPI.struct_size = sizeof(FlutterEngineProcTable);
|
||||
FlutterEngineGetProcAddresses(&_embedderAPI);
|
||||
|
||||
_renderer = [[FlutterMetalRenderer alloc] initWithFlutterEngine:self];
|
||||
_renderer = [[FlutterRenderer alloc] initWithFlutterEngine:self];
|
||||
|
||||
NSNotificationCenter* notificationCenter = [NSNotificationCenter defaultCenter];
|
||||
[notificationCenter addObserver:self
|
||||
@@ -422,9 +422,8 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi
|
||||
|
||||
__weak FlutterEngine* weakSelf = self;
|
||||
|
||||
FlutterMetalRenderer* metalRenderer = reinterpret_cast<FlutterMetalRenderer*>(_renderer);
|
||||
_macOSCompositor = std::make_unique<flutter::FlutterCompositor>(
|
||||
_viewProvider, _platformViewController, metalRenderer.device);
|
||||
_viewProvider, _platformViewController, _renderer.device);
|
||||
_macOSCompositor->SetPresentCallback([weakSelf](bool has_flutter_content) {
|
||||
if (has_flutter_content) {
|
||||
return [weakSelf.renderer present] == YES;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* Provides the renderer config needed to initialize the engine and also handles external
|
||||
* texture management.
|
||||
*/
|
||||
@property(nonatomic, readonly, nullable) id<FlutterRenderer> renderer;
|
||||
@property(nonatomic, readonly, nullable) FlutterRenderer* renderer;
|
||||
|
||||
/**
|
||||
* Function pointers for interacting with the embedder.h API.
|
||||
|
||||
@@ -1,38 +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 <Cocoa/Cocoa.h>
|
||||
#import <Metal/Metal.h>
|
||||
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterRenderer.h"
|
||||
|
||||
/**
|
||||
* Provides the renderer config needed to initialize the embedder engine. This is initialized during
|
||||
* FlutterEngine creation and then attached to the FlutterView once the FlutterViewController is
|
||||
* initialized.
|
||||
*/
|
||||
@interface FlutterMetalRenderer : FlutterTextureRegistrar <FlutterRenderer>
|
||||
|
||||
/**
|
||||
* Interface to the system GPU. Used to issue all the rendering commands.
|
||||
*/
|
||||
@property(nonatomic, readonly, nonnull) id<MTLDevice> device;
|
||||
|
||||
/**
|
||||
* Used to get the command buffers for the MTLDevice to render to.
|
||||
*/
|
||||
@property(nonatomic, readonly, nonnull) id<MTLCommandQueue> commandQueue;
|
||||
|
||||
/**
|
||||
* Creates a Metal texture for the given size.
|
||||
*/
|
||||
- (FlutterMetalTexture)createTextureForSize:(CGSize)size;
|
||||
|
||||
/**
|
||||
* Populates the texture registry with the provided metalTexture.
|
||||
*/
|
||||
- (BOOL)populateTextureWithIdentifier:(int64_t)textureID
|
||||
metalTexture:(nonnull FlutterMetalExternalTexture*)metalTexture;
|
||||
|
||||
@end
|
||||
@@ -12,7 +12,18 @@
|
||||
/**
|
||||
* Rendering backend agnostic FlutterRendererConfig provider to be used by the embedder API.
|
||||
*/
|
||||
@protocol FlutterRenderer <FlutterTextureRegistry, FlutterTextureRegistrarDelegate>
|
||||
@interface FlutterRenderer
|
||||
: FlutterTextureRegistrar <FlutterTextureRegistry, FlutterTextureRegistrarDelegate>
|
||||
|
||||
/**
|
||||
* Interface to the system GPU. Used to issue all the rendering commands.
|
||||
*/
|
||||
@property(nonatomic, readonly, nonnull) id<MTLDevice> device;
|
||||
|
||||
/**
|
||||
* Used to get the command buffers for the MTLDevice to render to.
|
||||
*/
|
||||
@property(nonatomic, readonly, nonnull) id<MTLCommandQueue> commandQueue;
|
||||
|
||||
/**
|
||||
* Intializes the renderer with the given FlutterEngine.
|
||||
@@ -39,4 +50,15 @@
|
||||
*/
|
||||
- (void)presentWithoutContent;
|
||||
|
||||
/**
|
||||
* Creates a Metal texture for the given size.
|
||||
*/
|
||||
- (FlutterMetalTexture)createTextureForSize:(CGSize)size;
|
||||
|
||||
/**
|
||||
* Populates the texture registry with the provided metalTexture.
|
||||
*/
|
||||
- (BOOL)populateTextureWithIdentifier:(int64_t)textureID
|
||||
metalTexture:(nonnull FlutterMetalExternalTexture*)metalTexture;
|
||||
|
||||
@end
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
|
||||
// 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 "flutter/shell/platform/darwin/macos/framework/Source/FlutterMetalRenderer.h"
|
||||
#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"
|
||||
@@ -15,8 +14,7 @@
|
||||
static FlutterMetalTexture OnGetNextDrawable(FlutterEngine* engine,
|
||||
const FlutterFrameInfo* frameInfo) {
|
||||
CGSize size = CGSizeMake(frameInfo->size.width, frameInfo->size.height);
|
||||
FlutterMetalRenderer* metalRenderer = reinterpret_cast<FlutterMetalRenderer*>(engine.renderer);
|
||||
return [metalRenderer createTextureForSize:size];
|
||||
return [engine.renderer createTextureForSize:size];
|
||||
}
|
||||
|
||||
static bool OnPresentDrawable(FlutterEngine* engine, const FlutterMetalTexture* texture) {
|
||||
@@ -28,13 +26,13 @@ static bool OnAcquireExternalTexture(FlutterEngine* engine,
|
||||
size_t width,
|
||||
size_t height,
|
||||
FlutterMetalExternalTexture* metalTexture) {
|
||||
FlutterMetalRenderer* metalRenderer = reinterpret_cast<FlutterMetalRenderer*>(engine.renderer);
|
||||
return [metalRenderer populateTextureWithIdentifier:textureIdentifier metalTexture:metalTexture];
|
||||
return [engine.renderer populateTextureWithIdentifier:textureIdentifier
|
||||
metalTexture:metalTexture];
|
||||
}
|
||||
|
||||
#pragma mark - FlutterMetalRenderer implementation
|
||||
#pragma mark - FlutterRenderer implementation
|
||||
|
||||
@implementation FlutterMetalRenderer {
|
||||
@implementation FlutterRenderer {
|
||||
FlutterView* _flutterView;
|
||||
|
||||
FlutterDarwinContextMetalSkia* _darwinMetalContext;
|
||||
@@ -7,7 +7,7 @@
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Headers/FlutterEngine.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterMetalRenderer.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterRenderer.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h"
|
||||
#include "flutter/shell/platform/embedder/embedder.h"
|
||||
#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
|
||||
@@ -26,18 +26,18 @@ FlutterEngine* CreateTestEngine() {
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST(FlutterMetalRenderer, PresentDelegatesToFlutterView) {
|
||||
TEST(FlutterRenderer, PresentDelegatesToFlutterView) {
|
||||
FlutterEngine* engine = CreateTestEngine();
|
||||
FlutterMetalRenderer* renderer = [[FlutterMetalRenderer alloc] initWithFlutterEngine:engine];
|
||||
FlutterRenderer* renderer = [[FlutterRenderer alloc] initWithFlutterEngine:engine];
|
||||
id mockFlutterView = OCMClassMock([FlutterView class]);
|
||||
[(FlutterView*)[mockFlutterView expect] present];
|
||||
[renderer setFlutterView:mockFlutterView];
|
||||
[renderer present];
|
||||
}
|
||||
|
||||
TEST(FlutterMetalRenderer, TextureReturnedByFlutterView) {
|
||||
TEST(FlutterRenderer, TextureReturnedByFlutterView) {
|
||||
FlutterEngine* engine = CreateTestEngine();
|
||||
FlutterMetalRenderer* renderer = [[FlutterMetalRenderer alloc] initWithFlutterEngine:engine];
|
||||
FlutterRenderer* renderer = [[FlutterRenderer alloc] initWithFlutterEngine:engine];
|
||||
id mockFlutterView = OCMClassMock([FlutterView class]);
|
||||
FlutterFrameInfo frameInfo;
|
||||
frameInfo.struct_size = sizeof(FlutterFrameInfo);
|
||||
@@ -14,7 +14,7 @@
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterKeyPrimaryResponder.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterKeyboardManager.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterMetalRenderer.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterRenderer.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputSemanticsObject.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h"
|
||||
#import "flutter/shell/platform/embedder/embedder.h"
|
||||
@@ -364,9 +364,8 @@ static void CommonInit(FlutterViewController* controller) {
|
||||
|
||||
- (void)loadView {
|
||||
FlutterView* flutterView;
|
||||
FlutterMetalRenderer* metalRenderer = reinterpret_cast<FlutterMetalRenderer*>(_engine.renderer);
|
||||
id<MTLDevice> device = metalRenderer.device;
|
||||
id<MTLCommandQueue> commandQueue = metalRenderer.commandQueue;
|
||||
id<MTLDevice> device = _engine.renderer.device;
|
||||
id<MTLCommandQueue> commandQueue = _engine.renderer.commandQueue;
|
||||
if (!device || !commandQueue) {
|
||||
NSLog(@"Unable to create FlutterView; no MTLDevice or MTLCommandQueue available.");
|
||||
return;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Headers/FlutterEngine.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterMetalRenderer.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterRenderer.h"
|
||||
#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewControllerTestUtils.h"
|
||||
#import "flutter/testing/testing.h"
|
||||
|
||||
@@ -269,7 +269,7 @@ TEST(FlutterViewControllerTest, testFlutterViewIsConfigured) {
|
||||
- (bool)testFlutterViewIsConfigured {
|
||||
id engineMock = OCMClassMock([FlutterEngine class]);
|
||||
|
||||
id renderer_ = [[FlutterMetalRenderer alloc] initWithFlutterEngine:engineMock];
|
||||
FlutterRenderer* renderer_ = [[FlutterRenderer alloc] initWithFlutterEngine:engineMock];
|
||||
OCMStub([engineMock renderer]).andReturn(renderer_);
|
||||
|
||||
FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engineMock
|
||||
@@ -460,7 +460,7 @@ TEST(FlutterViewControllerTest, testFlutterViewIsConfigured) {
|
||||
- (bool)testTrackpadGesturesAreSentToFramework {
|
||||
id engineMock = OCMClassMock([FlutterEngine class]);
|
||||
// Need to return a real renderer to allow view controller to load.
|
||||
id renderer_ = [[FlutterMetalRenderer alloc] initWithFlutterEngine:engineMock];
|
||||
FlutterRenderer* renderer_ = [[FlutterRenderer alloc] initWithFlutterEngine:engineMock];
|
||||
OCMStub([engineMock renderer]).andReturn(renderer_);
|
||||
__block bool called = false;
|
||||
__block FlutterPointerEvent last_event;
|
||||
|
||||
Reference in New Issue
Block a user