diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index b1018822b05e92aa41c4d94c61ff6c3f5b186816..a9d8d5cf719740eacbf5aba220788b23af096ed8 100755 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -1010,6 +1010,8 @@ FILE: ../../../flutter/shell/platform/darwin/ios/ios_render_target_gl.h FILE: ../../../flutter/shell/platform/darwin/ios/ios_render_target_gl.mm FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface.h FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface.mm +FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_factory.h +FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_factory.mm FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_gl.h FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_gl.mm FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_metal.h diff --git a/shell/platform/darwin/ios/BUILD.gn b/shell/platform/darwin/ios/BUILD.gn index 793c97be93701b03bcd5634a5cebe89559f398f7..05c39560e265bd42df51368131f24211eda3db45 100644 --- a/shell/platform/darwin/ios/BUILD.gn +++ b/shell/platform/darwin/ios/BUILD.gn @@ -99,6 +99,8 @@ source_set("flutter_framework_source") { "ios_render_target_gl.mm", "ios_surface.h", "ios_surface.mm", + "ios_surface_factory.h", + "ios_surface_factory.mm", "ios_surface_gl.h", "ios_surface_gl.mm", "ios_surface_software.h", diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 5248f59a98b34592db7979b4ce5d28a3ba7363bb..2c55925a2c4d5d0dd23e5753c1389012504a950d 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -28,7 +28,9 @@ #import "flutter/shell/platform/darwin/ios/framework/Source/platform_message_response_darwin.h" #import "flutter/shell/platform/darwin/ios/framework/Source/profiler_metrics_ios.h" #import "flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h" +#import "flutter/shell/platform/darwin/ios/ios_context.h" #import "flutter/shell/platform/darwin/ios/ios_surface.h" +#import "flutter/shell/platform/darwin/ios/ios_surface_factory.h" #import "flutter/shell/platform/darwin/ios/platform_view_ios.h" #import "flutter/shell/platform/darwin/ios/rendering_api_selection.h" #include "flutter/shell/profiling/sampling_profiler.h" @@ -63,6 +65,7 @@ static constexpr int kNumProfilerSamplesPerSec = 5; fml::WeakPtr _viewController; fml::scoped_nsobject _publisher; + std::shared_ptr _surfaceFactory; std::unique_ptr _platformViewsController; std::unique_ptr _profiler_metrics; std::unique_ptr _profiler; @@ -127,7 +130,7 @@ static constexpr int kNumProfilerSamplesPerSec = 5; _pluginPublications = [NSMutableDictionary new]; _registrars = [[NSMutableDictionary alloc] init]; - _platformViewsController.reset(new flutter::FlutterPlatformViewsController()); + [self ensurePlatformViewController]; _binaryMessenger = [[FlutterBinaryMessengerRelay alloc] initWithParent:self]; _connections.reset(new flutter::ConnectionCollection()); @@ -161,6 +164,16 @@ static constexpr int kNumProfilerSamplesPerSec = 5; return self; } +- (void)ensurePlatformViewController { + if (!_platformViewsController) { + auto renderingApi = flutter::GetRenderingAPIForProcess(FlutterView.forceSoftwareRendering); + _surfaceFactory = flutter::IOSSurfaceFactory::Create(renderingApi); + auto pvc = new flutter::FlutterPlatformViewsController(_surfaceFactory); + _surfaceFactory->SetPlatformViewsController(pvc); + _platformViewsController.reset(pvc); + } +} + - (void)dealloc { /// Notify plugins of dealloc. This should happen first in dealloc since the /// plugins may be talking to things like the binaryMessenger. @@ -510,13 +523,13 @@ static constexpr int kNumProfilerSamplesPerSec = 5; threadHostType}; // Lambda captures by pointers to ObjC objects are fine here because the - // create call is - // synchronous. + // create call is synchronous. flutter::Shell::CreateCallback on_create_platform_view = - [](flutter::Shell& shell) { + [self](flutter::Shell& shell) { + [self ensurePlatformViewController]; return std::make_unique( shell, flutter::GetRenderingAPIForProcess(FlutterView.forceSoftwareRendering), - shell.GetTaskRunners()); + self->_surfaceFactory, shell.GetTaskRunners()); }; flutter::Shell::CreateCallback on_create_rasterizer = @@ -544,9 +557,6 @@ static constexpr int kNumProfilerSamplesPerSec = 5; [self setupChannels]; [self onLocaleUpdated:nil]; [self initializeDisplays]; - if (!_platformViewsController) { - _platformViewsController.reset(new flutter::FlutterPlatformViewsController()); - } _publisher.reset([[FlutterObservatoryPublisher alloc] initWithEnableObservatoryPublication:settings.enable_observatory_publication]); [self maybeSetupPlatformViewChannels]; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEnginePlatformViewTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterEnginePlatformViewTest.mm index a202eba4d8d8d01d3803575e95db2358ace5deb7..3e002e2aa78ee06ab1ef8f733e1defb9b6628da4 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEnginePlatformViewTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEnginePlatformViewTest.mm @@ -67,6 +67,7 @@ class MockDelegate : public PlatformView::Delegate { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), /*task_runners=*/runners); id project = OCMClassMock([FlutterDartProject class]); diff --git a/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h b/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h index cb56163c6c5c2ae4e4de1c2a372c5e8caa43f91e..b77ac7181853f1daed1852623e4ecfe7deecb43a 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h @@ -35,8 +35,6 @@ - (instancetype)init NS_DESIGNATED_INITIALIZER; - (instancetype)initWithContentsScale:(CGFloat)contentsScale; -- (std::unique_ptr)createSurface: - (std::shared_ptr)ios_context; @end diff --git a/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm b/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm index f6a0cd823975675e409decc7d644f6a70ace3c2f..345d3a36798cbe3db13ecf9fb0148d59a6204598 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm @@ -62,14 +62,6 @@ return [FlutterView layerClass]; } -- (std::unique_ptr)createSurface: - (std::shared_ptr)ios_context { - return flutter::IOSSurface::Create(std::move(ios_context), // context - fml::scoped_nsobject{[self.layer retain]}, // layer - nullptr // platform views controller - ); -} - // TODO(amirh): implement drawLayer to support snapshotting. @end diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index c0c185c6ee4b7f0d493cb5b54e87abdf76a91e0b..240134dc4d5b81865e4c3e1d50c3f3b44590798d 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -16,6 +16,7 @@ #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h" #import "flutter/shell/platform/darwin/ios/ios_surface.h" +#import "flutter/shell/platform/darwin/ios/ios_surface_factory.h" #import "flutter/shell/platform/darwin/ios/ios_surface_gl.h" namespace flutter { @@ -32,8 +33,8 @@ std::shared_ptr FlutterPlatformViewLayerPool::GetLayer overlay_view.reset([[FlutterOverlayView alloc] init]); overlay_view_wrapper.reset([[FlutterOverlayView alloc] init]); - std::unique_ptr ios_surface = - [overlay_view.get() createSurface:std::move(ios_context)]; + auto ca_layer = fml::scoped_nsobject{[[overlay_view.get() layer] retain]}; + std::unique_ptr ios_surface = ios_surface_factory_->CreateSurface(ca_layer); std::unique_ptr surface = ios_surface->CreateGPUSurface(); layer = std::make_shared( @@ -44,8 +45,8 @@ std::shared_ptr FlutterPlatformViewLayerPool::GetLayer overlay_view.reset([[FlutterOverlayView alloc] initWithContentsScale:screenScale]); overlay_view_wrapper.reset([[FlutterOverlayView alloc] initWithContentsScale:screenScale]); - std::unique_ptr ios_surface = - [overlay_view.get() createSurface:std::move(ios_context)]; + auto ca_layer = fml::scoped_nsobject{[[overlay_view.get() layer] retain]}; + std::unique_ptr ios_surface = ios_surface_factory_->CreateSurface(ca_layer); std::unique_ptr surface = ios_surface->CreateGPUSurface(gr_context); layer = std::make_shared( diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index 283a86cf2ae463b01cab58ed3c9ebb1fd28a057c..0a890b7e928827986807545bd31e29178b80ec2a 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -121,12 +121,16 @@ fml::RefPtr CreateNewThread(std::string name) { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); + auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware); auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*ios_surface_factory=*/surface_factory, /*task_runners=*/runners); - auto flutterPlatformViewsController = std::make_unique(); + auto flutterPlatformViewsController = + std::make_unique(surface_factory); + surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get()); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; @@ -175,12 +179,16 @@ fml::RefPtr CreateNewThread(std::string name) { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); + auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware); auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*ios_surface_factory=*/surface_factory, /*task_runners=*/runners); - auto flutterPlatformViewsController = std::make_unique(); + auto flutterPlatformViewsController = + std::make_unique(surface_factory); + surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get()); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; @@ -230,12 +238,16 @@ fml::RefPtr CreateNewThread(std::string name) { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); + auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware); auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*ios_surface_factory=*/surface_factory, /*task_runners=*/runners); - auto flutterPlatformViewsController = std::make_unique(); + auto flutterPlatformViewsController = + std::make_unique(surface_factory); + surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get()); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; @@ -301,12 +313,16 @@ fml::RefPtr CreateNewThread(std::string name) { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); + auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware); auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*ios_surface_factory=*/surface_factory, /*task_runners=*/runners); - auto flutterPlatformViewsController = std::make_unique(); + auto flutterPlatformViewsController = + std::make_unique(surface_factory); + surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get()); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; @@ -373,12 +389,16 @@ fml::RefPtr CreateNewThread(std::string name) { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); + auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware); auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*ios_surface_factory=*/surface_factory, /*task_runners=*/runners); - auto flutterPlatformViewsController = std::make_unique(); + auto flutterPlatformViewsController = + std::make_unique(surface_factory); + surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get()); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; @@ -445,12 +465,16 @@ fml::RefPtr CreateNewThread(std::string name) { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); + auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware); auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*ios_surface_factory=*/surface_factory, /*task_runners=*/runners); - auto flutterPlatformViewsController = std::make_unique(); + auto flutterPlatformViewsController = + std::make_unique(surface_factory); + surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get()); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; @@ -518,12 +542,16 @@ fml::RefPtr CreateNewThread(std::string name) { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); + auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware); auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*ios_surface_factory=*/surface_factory, /*task_runners=*/runners); - auto flutterPlatformViewsController = std::make_unique(); + auto flutterPlatformViewsController = + std::make_unique(surface_factory); + surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get()); FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h index 4fcaaf387421222f62e54a6c501a1a0390498c19..d9638d75b6b15d10cdf9b637042d542f368b4448 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h @@ -61,6 +61,7 @@ void ResetAnchor(CALayer* layer); class IOSContextGL; class IOSSurface; +class IOSSurfaceFactory; struct FlutterPlatformViewLayer { FlutterPlatformViewLayer(fml::scoped_nsobject overlay_view, @@ -87,7 +88,9 @@ struct FlutterPlatformViewLayer { // This class isn't thread safe. class FlutterPlatformViewLayerPool { public: - FlutterPlatformViewLayerPool() = default; + FlutterPlatformViewLayerPool(std::shared_ptr ios_surface_factory) + : ios_surface_factory_(ios_surface_factory) {} + ~FlutterPlatformViewLayerPool() = default; // Gets a layer from the pool if available, or allocates a new one. @@ -118,12 +121,14 @@ class FlutterPlatformViewLayerPool { size_t available_layer_index_ = 0; std::vector> layers_; + const std::shared_ptr ios_surface_factory_; + FML_DISALLOW_COPY_AND_ASSIGN(FlutterPlatformViewLayerPool); }; class FlutterPlatformViewsController { public: - FlutterPlatformViewsController(); + FlutterPlatformViewsController(std::shared_ptr surface_factory); ~FlutterPlatformViewsController(); diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm index a6d3d03653b1786b0dcb1b2f8b61f6d696691abc..a46684ccb10645cd135d8fba444382d854a0515c 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm @@ -23,8 +23,9 @@ FlutterPlatformViewLayer::FlutterPlatformViewLayer( FlutterPlatformViewLayer::~FlutterPlatformViewLayer() = default; -FlutterPlatformViewsController::FlutterPlatformViewsController() - : layer_pool_(std::make_unique()), +FlutterPlatformViewsController::FlutterPlatformViewsController( + std::shared_ptr surface_factory) + : layer_pool_(std::make_unique(surface_factory)), weak_factory_(std::make_unique>(this)){}; FlutterPlatformViewsController::~FlutterPlatformViewsController() = default; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterView.h b/shell/platform/darwin/ios/framework/Source/FlutterView.h index 3a9c138de02aa08a4b46cd952f249b01fdf9c8ab..13d7b6ec27cee64b8f667bf53ded560717b04246 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterView.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterView.h @@ -32,7 +32,6 @@ - (instancetype)initWithDelegate:(id)delegate opaque:(BOOL)opaque NS_DESIGNATED_INITIALIZER; -- (std::unique_ptr)createSurface:(std::shared_ptr)context; // Set by FlutterEngine or FlutterViewController to override software rendering. @property(class, nonatomic) BOOL forceSoftwareRendering; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterView.mm b/shell/platform/darwin/ios/framework/Source/FlutterView.mm index 3f6b19decdac37ab89bc12e7deabe3ae85b30ec1..73a9b8b529088a5bd73b2beb7ccb7a6ba35226d5 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterView.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterView.mm @@ -83,15 +83,6 @@ static BOOL _forceSoftwareRendering; flutter::GetRenderingAPIForProcess(FlutterView.forceSoftwareRendering)); } -- (std::unique_ptr)createSurface: - (std::shared_ptr)ios_context { - return flutter::IOSSurface::Create( - std::move(ios_context), // context - fml::scoped_nsobject{[self.layer retain]}, // layer - [_delegate platformViewsController] // platform views controller - ); -} - - (void)drawLayer:(CALayer*)layer inContext:(CGContextRef)context { TRACE_EVENT0("flutter", "SnapshotFlutterView"); diff --git a/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm b/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm index 41970e67c8f7353a346fea6d1fc382a50edf6d87..754495cc527f4623d56b91b472ddad5b5866a702 100644 --- a/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm +++ b/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm @@ -137,6 +137,7 @@ fml::RefPtr CreateNewThread(std::string name) { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), /*task_runners=*/runners); auto bridge = std::make_unique(/*view=*/nil, @@ -156,6 +157,7 @@ fml::RefPtr CreateNewThread(std::string name) { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), /*task_runners=*/runners); id mockFlutterView = OCMClassMock([FlutterView class]); id mockFlutterViewController = OCMClassMock([FlutterViewController class]); @@ -182,6 +184,7 @@ fml::RefPtr CreateNewThread(std::string name) { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), /*task_runners=*/runners); id mockFlutterView = OCMClassMock([FlutterView class]); id mockFlutterViewController = OCMClassMock([FlutterViewController class]); @@ -224,9 +227,12 @@ fml::RefPtr CreateNewThread(std::string name) { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); + + auto surfaceFactory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware); auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + /*ios_surface_factory=*/surfaceFactory, /*task_runners=*/runners); id mockFlutterView = OCMClassMock([FlutterView class]); id mockFlutterViewController = OCMClassMock([FlutterViewController class]); @@ -234,8 +240,9 @@ fml::RefPtr CreateNewThread(std::string name) { std::string label = "some label"; auto flutterPlatformViewsController = - std::make_unique(); + std::make_unique(surfaceFactory); flutterPlatformViewsController->SetFlutterView(mockFlutterView); + surfaceFactory->SetPlatformViewsController(flutterPlatformViewsController.get()); MockFlutterPlatformFactory* factory = [[MockFlutterPlatformFactory new] autorelease]; flutterPlatformViewsController->RegisterViewFactory( @@ -279,6 +286,7 @@ fml::RefPtr CreateNewThread(std::string name) { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), /*task_runners=*/runners); id mockFlutterView = OCMClassMock([FlutterView class]); id mockFlutterViewController = OCMClassMock([FlutterViewController class]); @@ -344,6 +352,7 @@ fml::RefPtr CreateNewThread(std::string name) { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), /*task_runners=*/runners); id mockFlutterView = OCMClassMock([FlutterView class]); id mockFlutterViewController = OCMClassMock([FlutterViewController class]); @@ -411,6 +420,7 @@ fml::RefPtr CreateNewThread(std::string name) { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), /*task_runners=*/runners); id mockFlutterViewController = OCMClassMock([FlutterViewController class]); id mockFlutterView = OCMClassMock([FlutterView class]); @@ -477,6 +487,7 @@ fml::RefPtr CreateNewThread(std::string name) { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), /*task_runners=*/runners); id mockFlutterViewController = OCMClassMock([FlutterViewController class]); id mockFlutterView = OCMClassMock([FlutterView class]); @@ -549,6 +560,7 @@ fml::RefPtr CreateNewThread(std::string name) { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), /*task_runners=*/runners); id mockFlutterViewController = OCMClassMock([FlutterViewController class]); id mockFlutterView = OCMClassMock([FlutterView class]); @@ -623,6 +635,7 @@ fml::RefPtr CreateNewThread(std::string name) { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), /*task_runners=*/runners); id mockFlutterViewController = OCMClassMock([FlutterViewController class]); id mockFlutterView = OCMClassMock([FlutterView class]); @@ -693,6 +706,7 @@ fml::RefPtr CreateNewThread(std::string name) { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), /*task_runners=*/runners); id mockFlutterView = OCMClassMock([FlutterView class]); id mockFlutterViewController = OCMClassMock([FlutterViewController class]); @@ -760,6 +774,7 @@ fml::RefPtr CreateNewThread(std::string name) { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, + flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), /*task_runners=*/runners); fml::AutoResetWaitableEvent latch; thread_task_runner->PostTask([&] { diff --git a/shell/platform/darwin/ios/ios_surface_factory.h b/shell/platform/darwin/ios/ios_surface_factory.h new file mode 100644 index 0000000000000000000000000000000000000000..a692c56754887c43ac6305e0de41d00ab6bb906d --- /dev/null +++ b/shell/platform/darwin/ios/ios_surface_factory.h @@ -0,0 +1,39 @@ +// 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. + +#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS__SURFACE_FACTORY_H_ +#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS__SURFACE_FACTORY_H_ + +#include + +#import "flutter/shell/platform/darwin/ios/ios_surface.h" +#import "flutter/shell/platform/darwin/ios/rendering_api_selection.h" + +namespace flutter { + +class IOSSurfaceFactory { + public: + static std::shared_ptr Create( + IOSRenderingAPI rendering_api); + + explicit IOSSurfaceFactory(std::shared_ptr ios_context); + + ~IOSSurfaceFactory(); + + void SetPlatformViewsController( + FlutterPlatformViewsController* platform_views_controller); + + std::unique_ptr CreateSurface( + fml::scoped_nsobject ca_layer); + + private: + FlutterPlatformViewsController* platform_views_controller_; + std::shared_ptr ios_context_; + + FML_DISALLOW_COPY_AND_ASSIGN(IOSSurfaceFactory); +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS__SURFACE_FACTORY_H_ diff --git a/shell/platform/darwin/ios/ios_surface_factory.mm b/shell/platform/darwin/ios/ios_surface_factory.mm new file mode 100644 index 0000000000000000000000000000000000000000..4ed7d4c0b96a93c79bed6a59d41b9ef950cc2218 --- /dev/null +++ b/shell/platform/darwin/ios/ios_surface_factory.mm @@ -0,0 +1,30 @@ +// 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/ios/ios_surface_factory.h" +#import "flutter/shell/platform/darwin/ios/ios_context.h" + +namespace flutter { + +IOSSurfaceFactory::IOSSurfaceFactory(std::shared_ptr ios_context) + : ios_context_(ios_context) {} + +std::shared_ptr IOSSurfaceFactory::Create(IOSRenderingAPI rendering_api) { + std::shared_ptr ios_context = IOSContext::Create(rendering_api); + return std::make_shared(ios_context); +} + +IOSSurfaceFactory::~IOSSurfaceFactory() = default; + +void IOSSurfaceFactory::SetPlatformViewsController( + FlutterPlatformViewsController* platform_views_controller) { + platform_views_controller_ = platform_views_controller; +} + +std::unique_ptr IOSSurfaceFactory::CreateSurface( + fml::scoped_nsobject ca_layer) { + return flutter::IOSSurface::Create(ios_context_, ca_layer, platform_views_controller_); +} + +} // namespace flutter diff --git a/shell/platform/darwin/ios/platform_view_ios.h b/shell/platform/darwin/ios/platform_view_ios.h index 8e63bbda2f132de8db5fc0bef96159189da1ec01..661d5e57f5b854317d0c46bdbaacfd178bd8776d 100644 --- a/shell/platform/darwin/ios/platform_view_ios.h +++ b/shell/platform/darwin/ios/platform_view_ios.h @@ -19,6 +19,7 @@ #import "flutter/shell/platform/darwin/ios/framework/Source/platform_message_router.h" #import "flutter/shell/platform/darwin/ios/ios_context.h" #import "flutter/shell/platform/darwin/ios/ios_surface.h" +#import "flutter/shell/platform/darwin/ios/ios_surface_factory.h" #import "flutter/shell/platform/darwin/ios/rendering_api_selection.h" @class FlutterViewController; @@ -41,6 +42,7 @@ class PlatformViewIOS final : public PlatformView { public: explicit PlatformViewIOS(PlatformView::Delegate& delegate, IOSRenderingAPI rendering_api, + std::shared_ptr surface_factory, flutter::TaskRunners task_runners); ~PlatformViewIOS() override; @@ -124,6 +126,7 @@ class PlatformViewIOS final : public PlatformView { std::mutex ios_surface_mutex_; std::unique_ptr ios_surface_; std::shared_ptr ios_context_; + std::shared_ptr ios_surface_factory_; PlatformMessageRouter platform_message_router_; AccessibilityBridgePtr accessibility_bridge_; fml::scoped_nsprotocol text_input_plugin_; diff --git a/shell/platform/darwin/ios/platform_view_ios.mm b/shell/platform/darwin/ios/platform_view_ios.mm index faf764be7cb0cf2f7538c3484c3bd6fdb2e5069e..43543c1e2fcdeb37b47c3544d7f521c376aa3fd9 100644 --- a/shell/platform/darwin/ios/platform_view_ios.mm +++ b/shell/platform/darwin/ios/platform_view_ios.mm @@ -3,6 +3,7 @@ // found in the LICENSE file. #import "flutter/shell/platform/darwin/ios/platform_view_ios.h" +#include #include @@ -46,9 +47,11 @@ void PlatformViewIOS::AccessibilityBridgePtr::reset(AccessibilityBridge* bridge) PlatformViewIOS::PlatformViewIOS(PlatformView::Delegate& delegate, IOSRenderingAPI rendering_api, + std::shared_ptr surface_factory, flutter::TaskRunners task_runners) : PlatformView(delegate, std::move(task_runners)), ios_context_(IOSContext::Create(rendering_api)), + ios_surface_factory_(surface_factory), accessibility_bridge_([this](bool enabled) { PlatformView::SetSemanticsEnabled(enabled); }) {} PlatformViewIOS::~PlatformViewIOS() = default; @@ -102,8 +105,9 @@ void PlatformViewIOS::attachView() { FML_DCHECK(owner_controller_.get().isViewLoaded) << "FlutterViewController's view should be loaded " "before attaching to PlatformViewIOS."; - ios_surface_ = - [static_cast(owner_controller_.get().view) createSurface:ios_context_]; + auto flutter_view = static_cast(owner_controller_.get().view); + auto ca_layer = fml::scoped_nsobject{[[flutter_view layer] retain]}; + ios_surface_ = ios_surface_factory_->CreateSurface(ca_layer); FML_DCHECK(ios_surface_ != nullptr); if (accessibility_bridge_) {