started sharing GPU contexts between spawned engines (flutter/engine#23435)
* Lightweight flutter engines - started sharing GPU contexts between spawned engines * responded to feedback
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -941,11 +941,21 @@ static void SetEntryPoint(flutter::Settings* settings, NSString* entrypoint, NSS
|
||||
flutter::Settings settings = _shell->GetSettings();
|
||||
SetEntryPoint(&settings, entrypoint, libraryURI);
|
||||
|
||||
fml::WeakPtr<flutter::PlatformView> 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<flutter::PlatformViewIOS*>(platform_view.get());
|
||||
std::shared_ptr<flutter::IOSContext> 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<flutter::PlatformView> on_create_platform_view =
|
||||
[result](flutter::Shell& shell) {
|
||||
[result, context](flutter::Shell& shell) {
|
||||
[result recreatePlatformViewController];
|
||||
return std::make_unique<flutter::PlatformViewIOS>(
|
||||
shell, result->_renderingApi, result->_platformViewsController, shell.GetTaskRunners());
|
||||
shell, context, result->_platformViewsController, shell.GetTaskRunners());
|
||||
};
|
||||
|
||||
flutter::Shell::CreateCallback<flutter::Rasterizer> on_create_rasterizer =
|
||||
|
||||
@@ -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 <OCMock/OCMock.h>
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#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
|
||||
@@ -40,6 +40,11 @@ namespace flutter {
|
||||
*/
|
||||
class PlatformViewIOS final : public PlatformView {
|
||||
public:
|
||||
PlatformViewIOS(PlatformView::Delegate& delegate,
|
||||
const std::shared_ptr<IOSContext>& context,
|
||||
const std::shared_ptr<FlutterPlatformViewsController>& 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<IOSContext>& GetIosContext() { return ios_context_; }
|
||||
|
||||
private:
|
||||
/// Smart pointer for use with objective-c observers.
|
||||
/// This guarentees we remove the observer.
|
||||
|
||||
@@ -47,14 +47,24 @@ void PlatformViewIOS::AccessibilityBridgePtr::reset(AccessibilityBridge* bridge)
|
||||
|
||||
PlatformViewIOS::PlatformViewIOS(
|
||||
PlatformView::Delegate& delegate,
|
||||
IOSRenderingAPI rendering_api,
|
||||
const std::shared_ptr<IOSContext>& context,
|
||||
const std::shared_ptr<FlutterPlatformViewsController>& 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<FlutterPlatformViewsController>& platform_views_controller,
|
||||
flutter::TaskRunners task_runners)
|
||||
: PlatformViewIOS(delegate,
|
||||
IOSContext::Create(rendering_api),
|
||||
platform_views_controller,
|
||||
task_runners) {}
|
||||
|
||||
PlatformViewIOS::~PlatformViewIOS() = default;
|
||||
|
||||
PlatformMessageRouter& PlatformViewIOS::GetPlatformMessageRouter() {
|
||||
|
||||
Reference in New Issue
Block a user