diff --git a/engine/src/flutter/ci/licenses_golden/licenses_flutter b/engine/src/flutter/ci/licenses_golden/licenses_flutter index cea6312791..1e7141f4de 100755 --- a/engine/src/flutter/ci/licenses_golden/licenses_flutter +++ b/engine/src/flutter/ci/licenses_golden/licenses_flutter @@ -974,6 +974,7 @@ FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterEngineG FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterEngineGroupTest.mm FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterEnginePlatformViewTest.mm FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterEngineTest.mm +FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterEngineTest_mrc.mm FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Test.h FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterHeadlessDartRunner.mm diff --git a/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn b/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn index b964b191d6..e516886474 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn +++ b/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn @@ -181,6 +181,7 @@ source_set("ios_test_flutter_mrc") { ] sources = [ "framework/Source/FlutterEnginePlatformViewTest.mm", + "framework/Source/FlutterEngineTest_mrc.mm", "framework/Source/FlutterPlatformPluginTest.mm", "framework/Source/FlutterPlatformViewsTest.mm", "framework/Source/accessibility_bridge_test.mm", diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index ec9b0a34fe..9c4a259e02 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -941,11 +941,21 @@ static void SetEntryPoint(flutter::Settings* settings, NSString* entrypoint, NSS flutter::Settings settings = _shell->GetSettings(); SetEntryPoint(&settings, entrypoint, libraryURI); + fml::WeakPtr platform_view = _shell->GetPlatformView(); + FML_DCHECK(platform_view); + // Static-cast safe since this class always creates PlatformViewIOS instances. + flutter::PlatformViewIOS* ios_platform_view = + static_cast(platform_view.get()); + std::shared_ptr context = ios_platform_view->GetIosContext(); + FML_DCHECK(context); + + // Lambda captures by pointers to ObjC objects are fine here because the + // create call is synchronous. flutter::Shell::CreateCallback on_create_platform_view = - [result](flutter::Shell& shell) { + [result, context](flutter::Shell& shell) { [result recreatePlatformViewController]; return std::make_unique( - shell, result->_renderingApi, result->_platformViewsController, shell.GetTaskRunners()); + shell, context, result->_platformViewsController, shell.GetTaskRunners()); }; flutter::Shell::CreateCallback on_create_rasterizer = diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngineTest_mrc.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngineTest_mrc.mm new file mode 100644 index 0000000000..cc2f46f9dd --- /dev/null +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngineTest_mrc.mm @@ -0,0 +1,37 @@ +// 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 +#import + +#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h" +#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h" +#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Test.h" +#import "flutter/shell/platform/darwin/ios/platform_view_ios.h" + +FLUTTER_ASSERT_NOT_ARC + +@interface FlutterEngineTest_mrc : XCTestCase +@end + +@implementation FlutterEngineTest_mrc + +- (void)setUp { +} + +- (void)tearDown { +} + +- (void)testSpawnsShareGpuContext { + FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"foobar"]; + [engine run]; + FlutterEngine* spawn = [engine spawnWithEntrypoint:nil libraryURI:nil]; + XCTAssertNotNil(spawn); + XCTAssertTrue([engine iosPlatformView] != nullptr); + XCTAssertTrue([spawn iosPlatformView] != nullptr); + XCTAssertEqual([engine iosPlatformView]->GetIosContext(), + [spawn iosPlatformView]->GetIosContext()); +} + +@end diff --git a/engine/src/flutter/shell/platform/darwin/ios/platform_view_ios.h b/engine/src/flutter/shell/platform/darwin/ios/platform_view_ios.h index ecda3911fa..46cb3e027c 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/platform_view_ios.h +++ b/engine/src/flutter/shell/platform/darwin/ios/platform_view_ios.h @@ -40,6 +40,11 @@ namespace flutter { */ class PlatformViewIOS final : public PlatformView { public: + PlatformViewIOS(PlatformView::Delegate& delegate, + const std::shared_ptr& context, + const std::shared_ptr& platform_views_controller, + flutter::TaskRunners task_runners); + explicit PlatformViewIOS( PlatformView::Delegate& delegate, IOSRenderingAPI rendering_api, @@ -88,6 +93,9 @@ class PlatformViewIOS final : public PlatformView { // |PlatformView| void SetSemanticsEnabled(bool enabled) override; + /** Acessor for the `IOSContext` associated with the platform view. */ + const std::shared_ptr& GetIosContext() { return ios_context_; } + private: /// Smart pointer for use with objective-c observers. /// This guarentees we remove the observer. diff --git a/engine/src/flutter/shell/platform/darwin/ios/platform_view_ios.mm b/engine/src/flutter/shell/platform/darwin/ios/platform_view_ios.mm index 8989d256f0..1b48773517 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/platform_view_ios.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/platform_view_ios.mm @@ -47,14 +47,24 @@ void PlatformViewIOS::AccessibilityBridgePtr::reset(AccessibilityBridge* bridge) PlatformViewIOS::PlatformViewIOS( PlatformView::Delegate& delegate, - IOSRenderingAPI rendering_api, + const std::shared_ptr& context, const std::shared_ptr& platform_views_controller, flutter::TaskRunners task_runners) : PlatformView(delegate, std::move(task_runners)), - ios_context_(IOSContext::Create(rendering_api)), + ios_context_(context), platform_views_controller_(platform_views_controller), accessibility_bridge_([this](bool enabled) { PlatformView::SetSemanticsEnabled(enabled); }) {} +PlatformViewIOS::PlatformViewIOS( + PlatformView::Delegate& delegate, + IOSRenderingAPI rendering_api, + const std::shared_ptr& platform_views_controller, + flutter::TaskRunners task_runners) + : PlatformViewIOS(delegate, + IOSContext::Create(rendering_api), + platform_views_controller, + task_runners) {} + PlatformViewIOS::~PlatformViewIOS() = default; PlatformMessageRouter& PlatformViewIOS::GetPlatformMessageRouter() {