PlatformViewIOS CreateExternalViewEmbedder refactor (flutter/engine#22353)

This commit is contained in:
Kaushik Iska
2020-11-13 06:58:44 -06:00
committed by GitHub
parent 52a64d03ec
commit 2665245a45
21 changed files with 81 additions and 241 deletions

View File

@@ -1023,8 +1023,6 @@ 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

View File

@@ -99,8 +99,6 @@ 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",

View File

@@ -28,9 +28,6 @@
#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"
@@ -67,7 +64,6 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
std::shared_ptr<flutter::FlutterPlatformViewsController> _platformViewsController;
flutter::IOSRenderingAPI _renderingApi;
std::shared_ptr<flutter::IOSSurfaceFactory> _surfaceFactory;
std::unique_ptr<flutter::ProfilerMetricsIOS> _profiler_metrics;
std::unique_ptr<flutter::SamplingProfiler> _profiler;
@@ -168,9 +164,7 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
- (void)recreatePlatformViewController {
_renderingApi = flutter::GetRenderingAPIForProcess(FlutterView.forceSoftwareRendering);
_surfaceFactory = flutter::IOSSurfaceFactory::Create(_renderingApi);
_platformViewsController.reset(new flutter::FlutterPlatformViewsController(_surfaceFactory));
_surfaceFactory->SetPlatformViewsController(_platformViewsController);
_platformViewsController.reset(new flutter::FlutterPlatformViewsController());
}
- (flutter::IOSRenderingAPI)platformViewsRenderingAPI {
@@ -564,7 +558,7 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
[self](flutter::Shell& shell) {
[self recreatePlatformViewController];
return std::make_unique<flutter::PlatformViewIOS>(
shell, self->_renderingApi, self->_surfaceFactory, shell.GetTaskRunners());
shell, self->_renderingApi, self->_platformViewsController, shell.GetTaskRunners());
};
flutter::Shell::CreateCallback<flutter::Rasterizer> on_create_rasterizer =

View File

@@ -61,7 +61,7 @@ class MockDelegate : public PlatformView::Delegate {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
id project = OCMClassMock([FlutterDartProject class]);

View File

@@ -16,7 +16,6 @@
#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 {
@@ -34,7 +33,7 @@ std::shared_ptr<FlutterPlatformViewLayer> FlutterPlatformViewLayerPool::GetLayer
overlay_view_wrapper.reset([[FlutterOverlayView alloc] init]);
auto ca_layer = fml::scoped_nsobject<CALayer>{[[overlay_view.get() layer] retain]};
std::unique_ptr<IOSSurface> ios_surface = ios_surface_factory_->CreateSurface(ca_layer);
std::unique_ptr<IOSSurface> ios_surface = IOSSurface::Create(ios_context, ca_layer);
std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface();
layer = std::make_shared<FlutterPlatformViewLayer>(
@@ -46,7 +45,7 @@ std::shared_ptr<FlutterPlatformViewLayer> FlutterPlatformViewLayerPool::GetLayer
overlay_view_wrapper.reset([[FlutterOverlayView alloc] initWithContentsScale:screenScale]);
auto ca_layer = fml::scoped_nsobject<CALayer>{[[overlay_view.get() layer] retain]};
std::unique_ptr<IOSSurface> ios_surface = ios_surface_factory_->CreateSurface(ca_layer);
std::unique_ptr<IOSSurface> ios_surface = IOSSurface::Create(ios_context, ca_layer);
std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface(gr_context);
layer = std::make_shared<FlutterPlatformViewLayer>(

View File

@@ -115,17 +115,13 @@ fml::RefPtr<fml::TaskRunner> 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 flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*ios_surface_factory=*/surface_factory,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
auto flutterPlatformViewsController =
std::make_shared<flutter::FlutterPlatformViewsController>(surface_factory);
surface_factory->SetPlatformViewsController(flutterPlatformViewsController);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
flutterPlatformViewsController->RegisterViewFactory(
@@ -173,17 +169,13 @@ fml::RefPtr<fml::TaskRunner> 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 flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*ios_surface_factory=*/surface_factory,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
auto flutterPlatformViewsController =
std::make_shared<flutter::FlutterPlatformViewsController>(surface_factory);
surface_factory->SetPlatformViewsController(flutterPlatformViewsController);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
flutterPlatformViewsController->RegisterViewFactory(
@@ -232,17 +224,13 @@ fml::RefPtr<fml::TaskRunner> 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 flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*ios_surface_factory=*/surface_factory,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
auto flutterPlatformViewsController =
std::make_shared<flutter::FlutterPlatformViewsController>(surface_factory);
surface_factory->SetPlatformViewsController(flutterPlatformViewsController);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
flutterPlatformViewsController->RegisterViewFactory(
@@ -307,17 +295,13 @@ fml::RefPtr<fml::TaskRunner> 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 flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*ios_surface_factory=*/surface_factory,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
auto flutterPlatformViewsController =
std::make_shared<flutter::FlutterPlatformViewsController>(surface_factory);
surface_factory->SetPlatformViewsController(flutterPlatformViewsController);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
flutterPlatformViewsController->RegisterViewFactory(
@@ -383,17 +367,13 @@ fml::RefPtr<fml::TaskRunner> 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 flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*ios_surface_factory=*/surface_factory,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
auto flutterPlatformViewsController =
std::make_shared<flutter::FlutterPlatformViewsController>(surface_factory);
surface_factory->SetPlatformViewsController(flutterPlatformViewsController);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
flutterPlatformViewsController->RegisterViewFactory(
@@ -459,17 +439,13 @@ fml::RefPtr<fml::TaskRunner> 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 flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*ios_surface_factory=*/surface_factory,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
auto flutterPlatformViewsController =
std::make_shared<flutter::FlutterPlatformViewsController>(surface_factory);
surface_factory->SetPlatformViewsController(flutterPlatformViewsController);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
flutterPlatformViewsController->RegisterViewFactory(
@@ -536,17 +512,13 @@ fml::RefPtr<fml::TaskRunner> 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 flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*ios_surface_factory=*/surface_factory,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
auto flutterPlatformViewsController =
std::make_shared<flutter::FlutterPlatformViewsController>(surface_factory);
surface_factory->SetPlatformViewsController(flutterPlatformViewsController);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
flutterPlatformViewsController->RegisterViewFactory(
@@ -604,17 +576,13 @@ fml::RefPtr<fml::TaskRunner> 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 flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*ios_surface_factory=*/surface_factory,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
auto flutterPlatformViewsController =
std::make_shared<flutter::FlutterPlatformViewsController>(surface_factory);
surface_factory->SetPlatformViewsController(flutterPlatformViewsController);
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
flutterPlatformViewsController->RegisterViewFactory(
@@ -667,16 +635,13 @@ fml::RefPtr<fml::TaskRunner> 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 flutterPlatformViewsController = std::make_shared<flutter::FlutterPlatformViewsController>();
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*ios_surface_factory=*/surface_factory,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
auto flutterPlatformViewsController =
std::make_shared<flutter::FlutterPlatformViewsController>(surface_factory);
surface_factory->SetPlatformViewsController(flutterPlatformViewsController);
UIView* mockFlutterView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)] autorelease];
flutterPlatformViewsController->SetFlutterView(mockFlutterView);

View File

@@ -61,7 +61,6 @@ void ResetAnchor(CALayer* layer);
class IOSContextGL;
class IOSSurface;
class IOSSurfaceFactory;
struct FlutterPlatformViewLayer {
FlutterPlatformViewLayer(fml::scoped_nsobject<UIView> overlay_view,
@@ -88,8 +87,7 @@ struct FlutterPlatformViewLayer {
// This class isn't thread safe.
class FlutterPlatformViewLayerPool {
public:
FlutterPlatformViewLayerPool(std::shared_ptr<IOSSurfaceFactory> ios_surface_factory)
: ios_surface_factory_(ios_surface_factory) {}
FlutterPlatformViewLayerPool() = default;
~FlutterPlatformViewLayerPool() = default;
@@ -121,14 +119,12 @@ class FlutterPlatformViewLayerPool {
size_t available_layer_index_ = 0;
std::vector<std::shared_ptr<FlutterPlatformViewLayer>> layers_;
const std::shared_ptr<IOSSurfaceFactory> ios_surface_factory_;
FML_DISALLOW_COPY_AND_ASSIGN(FlutterPlatformViewLayerPool);
};
class FlutterPlatformViewsController {
public:
FlutterPlatformViewsController(std::shared_ptr<IOSSurfaceFactory> surface_factory);
FlutterPlatformViewsController();
~FlutterPlatformViewsController();

View File

@@ -23,9 +23,8 @@ FlutterPlatformViewLayer::FlutterPlatformViewLayer(
FlutterPlatformViewLayer::~FlutterPlatformViewLayer() = default;
FlutterPlatformViewsController::FlutterPlatformViewsController(
std::shared_ptr<IOSSurfaceFactory> surface_factory)
: layer_pool_(std::make_unique<FlutterPlatformViewLayerPool>(surface_factory)),
FlutterPlatformViewsController::FlutterPlatformViewsController()
: layer_pool_(std::make_unique<FlutterPlatformViewLayerPool>()),
weak_factory_(std::make_unique<fml::WeakPtrFactory<FlutterPlatformViewsController>>(this)){};
FlutterPlatformViewsController::~FlutterPlatformViewsController() = default;

View File

@@ -131,7 +131,7 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
auto bridge =
std::make_unique<flutter::AccessibilityBridge>(/*view=*/nil,
@@ -151,7 +151,7 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
@@ -178,7 +178,7 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
@@ -222,21 +222,18 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*ui=*/thread_task_runner,
/*io=*/thread_task_runner);
auto surfaceFactory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware);
auto flutterPlatformViewsController =
std::make_shared<flutter::FlutterPlatformViewsController>();
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*ios_surface_factory=*/surfaceFactory,
/*platform_views_controller=*/flutterPlatformViewsController,
/*task_runners=*/runners);
id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
OCMStub([mockFlutterViewController view]).andReturn(mockFlutterView);
std::string label = "some label";
auto flutterPlatformViewsController =
std::make_shared<flutter::FlutterPlatformViewsController>(surfaceFactory);
flutterPlatformViewsController->SetFlutterView(mockFlutterView);
surfaceFactory->SetPlatformViewsController(flutterPlatformViewsController);
MockFlutterPlatformFactory* factory = [[MockFlutterPlatformFactory new] autorelease];
flutterPlatformViewsController->RegisterViewFactory(
@@ -280,7 +277,7 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
@@ -346,7 +343,7 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
@@ -430,7 +427,7 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
@@ -520,7 +517,7 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
@@ -588,7 +585,7 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
id mockFlutterView = OCMClassMock([FlutterView class]);
@@ -655,7 +652,7 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
id mockFlutterView = OCMClassMock([FlutterView class]);
@@ -728,7 +725,7 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
id mockFlutterView = OCMClassMock([FlutterView class]);
@@ -803,7 +800,7 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
id mockFlutterView = OCMClassMock([FlutterView class]);
@@ -874,7 +871,7 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
@@ -942,7 +939,7 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*platform_views_controller=*/nil,
/*task_runners=*/runners);
fml::AutoResetWaitableEvent latch;
thread_task_runner->PostTask([&] {

View File

@@ -6,7 +6,6 @@
#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_SURFACE_H_
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h"
#import "flutter/shell/platform/darwin/ios/ios_external_view_embedder.h"
#include <memory>
@@ -25,15 +24,11 @@ bool IsIosEmbeddedViewsPreviewEnabled();
class IOSSurface {
public:
static std::unique_ptr<IOSSurface> Create(
std::shared_ptr<IOSContext> context,
fml::scoped_nsobject<CALayer> layer,
const std::shared_ptr<IOSExternalViewEmbedder>& external_view_embedder);
static std::unique_ptr<IOSSurface> Create(std::shared_ptr<IOSContext> context,
fml::scoped_nsobject<CALayer> layer);
std::shared_ptr<IOSContext> GetContext() const;
std::shared_ptr<IOSExternalViewEmbedder> GetSurfaceExternalViewEmbedder() const;
virtual ~IOSSurface();
virtual bool IsValid() const = 0;
@@ -48,12 +43,10 @@ class IOSSurface {
virtual std::unique_ptr<Surface> CreateGPUSurface(GrDirectContext* gr_context = nullptr) = 0;
protected:
IOSSurface(std::shared_ptr<IOSContext> ios_context,
const std::shared_ptr<IOSExternalViewEmbedder>& external_view_embedder);
explicit IOSSurface(std::shared_ptr<IOSContext> ios_context);
private:
std::shared_ptr<IOSContext> ios_context_;
std::shared_ptr<IOSExternalViewEmbedder> external_view_embedder_;
FML_DISALLOW_COPY_AND_ASSIGN(IOSSurface);
};

View File

@@ -15,10 +15,8 @@
namespace flutter {
std::unique_ptr<IOSSurface> IOSSurface::Create(
std::shared_ptr<IOSContext> context,
fml::scoped_nsobject<CALayer> layer,
const std::shared_ptr<IOSExternalViewEmbedder>& external_view_embedder) {
std::unique_ptr<IOSSurface> IOSSurface::Create(std::shared_ptr<IOSContext> context,
fml::scoped_nsobject<CALayer> layer) {
FML_DCHECK(layer);
FML_DCHECK(context);
@@ -26,8 +24,7 @@ std::unique_ptr<IOSSurface> IOSSurface::Create(
return std::make_unique<IOSSurfaceGL>(
fml::scoped_nsobject<CAEAGLLayer>(
reinterpret_cast<CAEAGLLayer*>([layer.get() retain])), // EAGL layer
std::move(context), // context
external_view_embedder // external view embedder
std::move(context) // context
);
}
@@ -37,22 +34,19 @@ std::unique_ptr<IOSSurface> IOSSurface::Create(
return std::make_unique<IOSSurfaceMetal>(
fml::scoped_nsobject<CAMetalLayer>(
reinterpret_cast<CAMetalLayer*>([layer.get() retain])), // Metal layer
std::move(context), // context
external_view_embedder // external view embedder
std::move(context) // context
);
}
}
#endif // FLUTTER_SHELL_ENABLE_METAL
return std::make_unique<IOSSurfaceSoftware>(std::move(layer), // layer
std::move(context), // context
external_view_embedder // external view embedder
return std::make_unique<IOSSurfaceSoftware>(std::move(layer), // layer
std::move(context) // context
);
}
IOSSurface::IOSSurface(std::shared_ptr<IOSContext> ios_context,
const std::shared_ptr<IOSExternalViewEmbedder>& external_view_embedder)
: ios_context_(std::move(ios_context)), external_view_embedder_(external_view_embedder) {
IOSSurface::IOSSurface(std::shared_ptr<IOSContext> ios_context)
: ios_context_(std::move(ios_context)) {
FML_DCHECK(ios_context_);
}
@@ -62,8 +56,4 @@ std::shared_ptr<IOSContext> IOSSurface::GetContext() const {
return ios_context_;
}
std::shared_ptr<IOSExternalViewEmbedder> IOSSurface::GetSurfaceExternalViewEmbedder() const {
return external_view_embedder_;
}
} // namespace flutter

View File

@@ -1,43 +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.
#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS__SURFACE_FACTORY_H_
#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS__SURFACE_FACTORY_H_
#include <memory>
#import "flutter/shell/platform/darwin/ios/ios_external_view_embedder.h"
#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<IOSSurfaceFactory> Create(
IOSRenderingAPI rendering_api);
explicit IOSSurfaceFactory(std::shared_ptr<IOSContext> ios_context);
~IOSSurfaceFactory();
void SetPlatformViewsController(
const std::shared_ptr<FlutterPlatformViewsController>&
platform_views_controller);
std::unique_ptr<IOSSurface> CreateSurface(
fml::scoped_nsobject<CALayer> ca_layer);
std::shared_ptr<IOSExternalViewEmbedder> GetExternalViewEmbedder();
private:
std::shared_ptr<IOSExternalViewEmbedder> external_view_embedder_;
std::shared_ptr<IOSContext> ios_context_;
FML_DISALLOW_COPY_AND_ASSIGN(IOSSurfaceFactory);
};
} // namespace flutter
#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS__SURFACE_FACTORY_H_

View File

@@ -1,37 +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 "flutter/shell/platform/darwin/ios/ios_surface_factory.h"
#import "flutter/shell/platform/darwin/ios/ios_context.h"
#import "flutter/shell/platform/darwin/ios/ios_external_view_embedder.h"
namespace flutter {
IOSSurfaceFactory::IOSSurfaceFactory(std::shared_ptr<IOSContext> ios_context)
: ios_context_(ios_context) {}
std::shared_ptr<IOSSurfaceFactory> IOSSurfaceFactory::Create(IOSRenderingAPI rendering_api) {
std::shared_ptr<IOSContext> ios_context = IOSContext::Create(rendering_api);
return std::make_shared<IOSSurfaceFactory>(ios_context);
}
IOSSurfaceFactory::~IOSSurfaceFactory() = default;
void IOSSurfaceFactory::SetPlatformViewsController(
const std::shared_ptr<FlutterPlatformViewsController>& platform_views_controller) {
external_view_embedder_.reset(
new IOSExternalViewEmbedder(platform_views_controller, ios_context_));
}
std::shared_ptr<IOSExternalViewEmbedder> IOSSurfaceFactory::GetExternalViewEmbedder() {
return external_view_embedder_;
}
std::unique_ptr<IOSSurface> IOSSurfaceFactory::CreateSurface(
fml::scoped_nsobject<CALayer> ca_layer) {
return flutter::IOSSurface::Create(ios_context_, ca_layer, external_view_embedder_);
}
} // namespace flutter

View File

@@ -18,9 +18,7 @@ namespace flutter {
class IOSSurfaceGL final : public IOSSurface, public GPUSurfaceGLDelegate {
public:
IOSSurfaceGL(fml::scoped_nsobject<CAEAGLLayer> layer,
std::shared_ptr<IOSContext> context,
const std::shared_ptr<IOSExternalViewEmbedder>& external_view_embedder = nullptr);
IOSSurfaceGL(fml::scoped_nsobject<CAEAGLLayer> layer, std::shared_ptr<IOSContext> context);
~IOSSurfaceGL() override;

View File

@@ -15,9 +15,8 @@ static IOSContextGL* CastToGLContext(const std::shared_ptr<IOSContext>& context)
}
IOSSurfaceGL::IOSSurfaceGL(fml::scoped_nsobject<CAEAGLLayer> layer,
std::shared_ptr<IOSContext> context,
const std::shared_ptr<IOSExternalViewEmbedder>& external_view_embedder)
: IOSSurface(context, external_view_embedder) {
std::shared_ptr<IOSContext> context)
: IOSSurface(context) {
render_target_ = CastToGLContext(context)->CreateRenderTarget(std::move(layer));
}

View File

@@ -15,9 +15,7 @@ namespace flutter {
class SK_API_AVAILABLE_CA_METAL_LAYER IOSSurfaceMetal final : public IOSSurface {
public:
IOSSurfaceMetal(fml::scoped_nsobject<CAMetalLayer> layer,
std::shared_ptr<IOSContext> context,
const std::shared_ptr<IOSExternalViewEmbedder>& external_view_embedder);
IOSSurfaceMetal(fml::scoped_nsobject<CAMetalLayer> layer, std::shared_ptr<IOSContext> context);
// |IOSSurface|
~IOSSurfaceMetal();

View File

@@ -13,11 +13,9 @@ static IOSContextMetal* CastToMetalContext(const std::shared_ptr<IOSContext>& co
return reinterpret_cast<IOSContextMetal*>(context.get());
}
IOSSurfaceMetal::IOSSurfaceMetal(
fml::scoped_nsobject<CAMetalLayer> layer,
std::shared_ptr<IOSContext> context,
const std::shared_ptr<IOSExternalViewEmbedder>& external_view_embedder)
: IOSSurface(std::move(context), external_view_embedder), layer_(std::move(layer)) {
IOSSurfaceMetal::IOSSurfaceMetal(fml::scoped_nsobject<CAMetalLayer> layer,
std::shared_ptr<IOSContext> context)
: IOSSurface(std::move(context)), layer_(std::move(layer)) {
if (!layer_) {
return;
}

View File

@@ -18,9 +18,7 @@ namespace flutter {
class IOSSurfaceSoftware final : public IOSSurface, public GPUSurfaceSoftwareDelegate {
public:
IOSSurfaceSoftware(fml::scoped_nsobject<CALayer> layer,
std::shared_ptr<IOSContext> context,
const std::shared_ptr<IOSExternalViewEmbedder>& external_view_embedder);
IOSSurfaceSoftware(fml::scoped_nsobject<CALayer> layer, std::shared_ptr<IOSContext> context);
~IOSSurfaceSoftware() override;

View File

@@ -15,11 +15,9 @@
namespace flutter {
IOSSurfaceSoftware::IOSSurfaceSoftware(
fml::scoped_nsobject<CALayer> layer,
std::shared_ptr<IOSContext> context,
const std::shared_ptr<IOSExternalViewEmbedder>& external_view_embedder)
: IOSSurface(std::move(context), external_view_embedder), layer_(std::move(layer)) {}
IOSSurfaceSoftware::IOSSurfaceSoftware(fml::scoped_nsobject<CALayer> layer,
std::shared_ptr<IOSContext> context)
: IOSSurface(std::move(context)), layer_(std::move(layer)) {}
IOSSurfaceSoftware::~IOSSurfaceSoftware() = default;

View File

@@ -18,8 +18,8 @@
#import "flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h"
#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_external_view_embedder.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;
@@ -40,10 +40,11 @@ namespace flutter {
*/
class PlatformViewIOS final : public PlatformView {
public:
explicit PlatformViewIOS(PlatformView::Delegate& delegate,
IOSRenderingAPI rendering_api,
std::shared_ptr<IOSSurfaceFactory> surface_factory,
flutter::TaskRunners task_runners);
explicit PlatformViewIOS(
PlatformView::Delegate& delegate,
IOSRenderingAPI rendering_api,
const std::shared_ptr<FlutterPlatformViewsController>& platform_views_controller,
flutter::TaskRunners task_runners);
~PlatformViewIOS() override;
@@ -106,7 +107,7 @@ class PlatformViewIOS final : public PlatformView {
/// information to Dart.
class AccessibilityBridgePtr {
public:
AccessibilityBridgePtr(const std::function<void(bool)>& set_semantics_enabled);
explicit AccessibilityBridgePtr(const std::function<void(bool)>& set_semantics_enabled);
AccessibilityBridgePtr(const std::function<void(bool)>& set_semantics_enabled,
AccessibilityBridge* bridge);
~AccessibilityBridgePtr();
@@ -126,7 +127,7 @@ class PlatformViewIOS final : public PlatformView {
std::mutex ios_surface_mutex_;
std::unique_ptr<IOSSurface> ios_surface_;
std::shared_ptr<IOSContext> ios_context_;
std::shared_ptr<IOSSurfaceFactory> ios_surface_factory_;
const std::shared_ptr<FlutterPlatformViewsController>& platform_views_controller_;
PlatformMessageRouter platform_message_router_;
AccessibilityBridgePtr accessibility_bridge_;
fml::scoped_nsprotocol<FlutterTextInputPlugin*> text_input_plugin_;

View File

@@ -45,13 +45,14 @@ void PlatformViewIOS::AccessibilityBridgePtr::reset(AccessibilityBridge* bridge)
}
}
PlatformViewIOS::PlatformViewIOS(PlatformView::Delegate& delegate,
IOSRenderingAPI rendering_api,
std::shared_ptr<IOSSurfaceFactory> surface_factory,
flutter::TaskRunners task_runners)
PlatformViewIOS::PlatformViewIOS(
PlatformView::Delegate& delegate,
IOSRenderingAPI rendering_api,
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_surface_factory_(surface_factory),
platform_views_controller_(platform_views_controller),
accessibility_bridge_([this](bool enabled) { PlatformView::SetSemanticsEnabled(enabled); }) {}
PlatformViewIOS::~PlatformViewIOS() = default;
@@ -107,7 +108,7 @@ void PlatformViewIOS::attachView() {
"before attaching to PlatformViewIOS.";
auto flutter_view = static_cast<FlutterView*>(owner_controller_.get().view);
auto ca_layer = fml::scoped_nsobject<CALayer>{[[flutter_view layer] retain]};
ios_surface_ = ios_surface_factory_->CreateSurface(ca_layer);
ios_surface_ = IOSSurface::Create(ios_context_, ca_layer);
FML_DCHECK(ios_surface_ != nullptr);
if (accessibility_bridge_) {
@@ -142,7 +143,7 @@ std::unique_ptr<Surface> PlatformViewIOS::CreateRenderingSurface() {
// |PlatformView|
std::shared_ptr<ExternalViewEmbedder> PlatformViewIOS::CreateExternalViewEmbedder() {
return ios_surface_factory_->GetExternalViewEmbedder();
return std::make_shared<IOSExternalViewEmbedder>(platform_views_controller_, ios_context_);
}
// |PlatformView|