Revert "[ios] Refactor IOSSurface factory and unify surface creation (#21877)" (flutter/engine#21970)

This commit is contained in:
Jenn Magder
2020-10-19 16:32:03 -07:00
committed by GitHub
parent 939c3de58a
commit ebc513283f
17 changed files with 46 additions and 167 deletions

View File

@@ -1010,8 +1010,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_render_target_gl.mm
FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface.h 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.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.h
FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_gl.mm FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_gl.mm
FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_metal.h 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_render_target_gl.mm",
"ios_surface.h", "ios_surface.h",
"ios_surface.mm", "ios_surface.mm",
"ios_surface_factory.h",
"ios_surface_factory.mm",
"ios_surface_gl.h", "ios_surface_gl.h",
"ios_surface_gl.mm", "ios_surface_gl.mm",
"ios_surface_software.h", "ios_surface_software.h",

View File

@@ -28,9 +28,7 @@
#import "flutter/shell/platform/darwin/ios/framework/Source/platform_message_response_darwin.h" #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/profiler_metrics_ios.h"
#import "flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_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.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/platform_view_ios.h"
#import "flutter/shell/platform/darwin/ios/rendering_api_selection.h" #import "flutter/shell/platform/darwin/ios/rendering_api_selection.h"
#include "flutter/shell/profiling/sampling_profiler.h" #include "flutter/shell/profiling/sampling_profiler.h"
@@ -65,7 +63,6 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
fml::WeakPtr<FlutterViewController> _viewController; fml::WeakPtr<FlutterViewController> _viewController;
fml::scoped_nsobject<FlutterObservatoryPublisher> _publisher; fml::scoped_nsobject<FlutterObservatoryPublisher> _publisher;
std::shared_ptr<flutter::IOSSurfaceFactory> _surfaceFactory;
std::unique_ptr<flutter::FlutterPlatformViewsController> _platformViewsController; std::unique_ptr<flutter::FlutterPlatformViewsController> _platformViewsController;
std::unique_ptr<flutter::ProfilerMetricsIOS> _profiler_metrics; std::unique_ptr<flutter::ProfilerMetricsIOS> _profiler_metrics;
std::unique_ptr<flutter::SamplingProfiler> _profiler; std::unique_ptr<flutter::SamplingProfiler> _profiler;
@@ -131,7 +128,7 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
_pluginPublications = [NSMutableDictionary new]; _pluginPublications = [NSMutableDictionary new];
_registrars = [[NSMutableDictionary alloc] init]; _registrars = [[NSMutableDictionary alloc] init];
[self ensurePlatformViewController]; _platformViewsController.reset(new flutter::FlutterPlatformViewsController());
_binaryMessenger = [[FlutterBinaryMessengerRelay alloc] initWithParent:self]; _binaryMessenger = [[FlutterBinaryMessengerRelay alloc] initWithParent:self];
_connections.reset(new flutter::ConnectionCollection()); _connections.reset(new flutter::ConnectionCollection());
@@ -165,16 +162,6 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
return self; 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 { - (void)dealloc {
/// Notify plugins of dealloc. This should happen first in dealloc since the /// Notify plugins of dealloc. This should happen first in dealloc since the
/// plugins may be talking to things like the binaryMessenger. /// plugins may be talking to things like the binaryMessenger.
@@ -533,13 +520,13 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
threadHostType}; threadHostType};
// Lambda captures by pointers to ObjC objects are fine here because the // Lambda captures by pointers to ObjC objects are fine here because the
// create call is synchronous. // create call is
// synchronous.
flutter::Shell::CreateCallback<flutter::PlatformView> on_create_platform_view = flutter::Shell::CreateCallback<flutter::PlatformView> on_create_platform_view =
[self](flutter::Shell& shell) { [](flutter::Shell& shell) {
[self ensurePlatformViewController];
return std::make_unique<flutter::PlatformViewIOS>( return std::make_unique<flutter::PlatformViewIOS>(
shell, flutter::GetRenderingAPIForProcess(FlutterView.forceSoftwareRendering), shell, flutter::GetRenderingAPIForProcess(FlutterView.forceSoftwareRendering),
self->_surfaceFactory, shell.GetTaskRunners()); shell.GetTaskRunners());
}; };
flutter::Shell::CreateCallback<flutter::Rasterizer> on_create_rasterizer = flutter::Shell::CreateCallback<flutter::Rasterizer> on_create_rasterizer =
@@ -567,6 +554,9 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
[self setupChannels]; [self setupChannels];
[self onLocaleUpdated:nil]; [self onLocaleUpdated:nil];
[self initializeDisplays]; [self initializeDisplays];
if (!_platformViewsController) {
_platformViewsController.reset(new flutter::FlutterPlatformViewsController());
}
_publisher.reset([[FlutterObservatoryPublisher alloc] _publisher.reset([[FlutterObservatoryPublisher alloc]
initWithEnableObservatoryPublication:settings.enable_observatory_publication]); initWithEnableObservatoryPublication:settings.enable_observatory_publication]);
[self maybeSetupPlatformViewChannels]; [self maybeSetupPlatformViewChannels];

View File

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

View File

@@ -35,6 +35,8 @@
- (instancetype)init NS_DESIGNATED_INITIALIZER; - (instancetype)init NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithContentsScale:(CGFloat)contentsScale; - (instancetype)initWithContentsScale:(CGFloat)contentsScale;
- (std::unique_ptr<flutter::IOSSurface>)createSurface:
(std::shared_ptr<flutter::IOSContext>)ios_context;
@end @end

View File

@@ -62,6 +62,14 @@
return [FlutterView layerClass]; return [FlutterView layerClass];
} }
- (std::unique_ptr<flutter::IOSSurface>)createSurface:
(std::shared_ptr<flutter::IOSContext>)ios_context {
return flutter::IOSSurface::Create(std::move(ios_context), // context
fml::scoped_nsobject<CALayer>{[self.layer retain]}, // layer
nullptr // platform views controller
);
}
// TODO(amirh): implement drawLayer to support snapshotting. // TODO(amirh): implement drawLayer to support snapshotting.
@end @end

View File

@@ -16,7 +16,6 @@
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h" #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/framework/Source/FlutterPlatformViews_Internal.h"
#import "flutter/shell/platform/darwin/ios/ios_surface.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" #import "flutter/shell/platform/darwin/ios/ios_surface_gl.h"
namespace flutter { namespace flutter {
@@ -33,8 +32,8 @@ std::shared_ptr<FlutterPlatformViewLayer> FlutterPlatformViewLayerPool::GetLayer
overlay_view.reset([[FlutterOverlayView alloc] init]); overlay_view.reset([[FlutterOverlayView alloc] init]);
overlay_view_wrapper.reset([[FlutterOverlayView alloc] init]); 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 =
std::unique_ptr<IOSSurface> ios_surface = ios_surface_factory_->CreateSurface(ca_layer); [overlay_view.get() createSurface:std::move(ios_context)];
std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface(); std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface();
layer = std::make_shared<FlutterPlatformViewLayer>( layer = std::make_shared<FlutterPlatformViewLayer>(
@@ -45,8 +44,8 @@ std::shared_ptr<FlutterPlatformViewLayer> FlutterPlatformViewLayerPool::GetLayer
overlay_view.reset([[FlutterOverlayView alloc] initWithContentsScale:screenScale]); overlay_view.reset([[FlutterOverlayView alloc] initWithContentsScale:screenScale]);
overlay_view_wrapper.reset([[FlutterOverlayView alloc] initWithContentsScale:screenScale]); 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 =
std::unique_ptr<IOSSurface> ios_surface = ios_surface_factory_->CreateSurface(ca_layer); [overlay_view.get() createSurface:std::move(ios_context)];
std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface(gr_context); std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface(gr_context);
layer = std::make_shared<FlutterPlatformViewLayer>( layer = std::make_shared<FlutterPlatformViewLayer>(

View File

@@ -121,16 +121,12 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*raster=*/thread_task_runner, /*raster=*/thread_task_runner,
/*ui=*/thread_task_runner, /*ui=*/thread_task_runner,
/*io=*/thread_task_runner); /*io=*/thread_task_runner);
auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware);
auto platform_view = std::make_unique<flutter::PlatformViewIOS>( auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate, /*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*ios_surface_factory=*/surface_factory,
/*task_runners=*/runners); /*task_runners=*/runners);
auto flutterPlatformViewsController = auto flutterPlatformViewsController = std::make_unique<flutter::FlutterPlatformViewsController>();
std::make_unique<flutter::FlutterPlatformViewsController>(surface_factory);
surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get());
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -179,16 +175,12 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*raster=*/thread_task_runner, /*raster=*/thread_task_runner,
/*ui=*/thread_task_runner, /*ui=*/thread_task_runner,
/*io=*/thread_task_runner); /*io=*/thread_task_runner);
auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware);
auto platform_view = std::make_unique<flutter::PlatformViewIOS>( auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate, /*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*ios_surface_factory=*/surface_factory,
/*task_runners=*/runners); /*task_runners=*/runners);
auto flutterPlatformViewsController = auto flutterPlatformViewsController = std::make_unique<flutter::FlutterPlatformViewsController>();
std::make_unique<flutter::FlutterPlatformViewsController>(surface_factory);
surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get());
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -238,16 +230,12 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*raster=*/thread_task_runner, /*raster=*/thread_task_runner,
/*ui=*/thread_task_runner, /*ui=*/thread_task_runner,
/*io=*/thread_task_runner); /*io=*/thread_task_runner);
auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware);
auto platform_view = std::make_unique<flutter::PlatformViewIOS>( auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate, /*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*ios_surface_factory=*/surface_factory,
/*task_runners=*/runners); /*task_runners=*/runners);
auto flutterPlatformViewsController = auto flutterPlatformViewsController = std::make_unique<flutter::FlutterPlatformViewsController>();
std::make_unique<flutter::FlutterPlatformViewsController>(surface_factory);
surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get());
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -313,16 +301,12 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*raster=*/thread_task_runner, /*raster=*/thread_task_runner,
/*ui=*/thread_task_runner, /*ui=*/thread_task_runner,
/*io=*/thread_task_runner); /*io=*/thread_task_runner);
auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware);
auto platform_view = std::make_unique<flutter::PlatformViewIOS>( auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate, /*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*ios_surface_factory=*/surface_factory,
/*task_runners=*/runners); /*task_runners=*/runners);
auto flutterPlatformViewsController = auto flutterPlatformViewsController = std::make_unique<flutter::FlutterPlatformViewsController>();
std::make_unique<flutter::FlutterPlatformViewsController>(surface_factory);
surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get());
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -389,16 +373,12 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*raster=*/thread_task_runner, /*raster=*/thread_task_runner,
/*ui=*/thread_task_runner, /*ui=*/thread_task_runner,
/*io=*/thread_task_runner); /*io=*/thread_task_runner);
auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware);
auto platform_view = std::make_unique<flutter::PlatformViewIOS>( auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate, /*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*ios_surface_factory=*/surface_factory,
/*task_runners=*/runners); /*task_runners=*/runners);
auto flutterPlatformViewsController = auto flutterPlatformViewsController = std::make_unique<flutter::FlutterPlatformViewsController>();
std::make_unique<flutter::FlutterPlatformViewsController>(surface_factory);
surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get());
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -465,16 +445,12 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*raster=*/thread_task_runner, /*raster=*/thread_task_runner,
/*ui=*/thread_task_runner, /*ui=*/thread_task_runner,
/*io=*/thread_task_runner); /*io=*/thread_task_runner);
auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware);
auto platform_view = std::make_unique<flutter::PlatformViewIOS>( auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate, /*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*ios_surface_factory=*/surface_factory,
/*task_runners=*/runners); /*task_runners=*/runners);
auto flutterPlatformViewsController = auto flutterPlatformViewsController = std::make_unique<flutter::FlutterPlatformViewsController>();
std::make_unique<flutter::FlutterPlatformViewsController>(surface_factory);
surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get());
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -542,16 +518,12 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*raster=*/thread_task_runner, /*raster=*/thread_task_runner,
/*ui=*/thread_task_runner, /*ui=*/thread_task_runner,
/*io=*/thread_task_runner); /*io=*/thread_task_runner);
auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware);
auto platform_view = std::make_unique<flutter::PlatformViewIOS>( auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate, /*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*ios_surface_factory=*/surface_factory,
/*task_runners=*/runners); /*task_runners=*/runners);
auto flutterPlatformViewsController = auto flutterPlatformViewsController = std::make_unique<flutter::FlutterPlatformViewsController>();
std::make_unique<flutter::FlutterPlatformViewsController>(surface_factory);
surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get());
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];

View File

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

View File

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

View File

@@ -32,6 +32,7 @@
- (instancetype)initWithDelegate:(id<FlutterViewEngineDelegate>)delegate - (instancetype)initWithDelegate:(id<FlutterViewEngineDelegate>)delegate
opaque:(BOOL)opaque NS_DESIGNATED_INITIALIZER; opaque:(BOOL)opaque NS_DESIGNATED_INITIALIZER;
- (std::unique_ptr<flutter::IOSSurface>)createSurface:(std::shared_ptr<flutter::IOSContext>)context;
// Set by FlutterEngine or FlutterViewController to override software rendering. // Set by FlutterEngine or FlutterViewController to override software rendering.
@property(class, nonatomic) BOOL forceSoftwareRendering; @property(class, nonatomic) BOOL forceSoftwareRendering;

View File

@@ -83,6 +83,15 @@ static BOOL _forceSoftwareRendering;
flutter::GetRenderingAPIForProcess(FlutterView.forceSoftwareRendering)); flutter::GetRenderingAPIForProcess(FlutterView.forceSoftwareRendering));
} }
- (std::unique_ptr<flutter::IOSSurface>)createSurface:
(std::shared_ptr<flutter::IOSContext>)ios_context {
return flutter::IOSSurface::Create(
std::move(ios_context), // context
fml::scoped_nsobject<CALayer>{[self.layer retain]}, // layer
[_delegate platformViewsController] // platform views controller
);
}
- (void)drawLayer:(CALayer*)layer inContext:(CGContextRef)context { - (void)drawLayer:(CALayer*)layer inContext:(CGContextRef)context {
TRACE_EVENT0("flutter", "SnapshotFlutterView"); TRACE_EVENT0("flutter", "SnapshotFlutterView");

View File

@@ -137,7 +137,6 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>( auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate, /*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*task_runners=*/runners); /*task_runners=*/runners);
auto bridge = auto bridge =
std::make_unique<flutter::AccessibilityBridge>(/*view=*/nil, std::make_unique<flutter::AccessibilityBridge>(/*view=*/nil,
@@ -157,7 +156,6 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>( auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate, /*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*task_runners=*/runners); /*task_runners=*/runners);
id mockFlutterView = OCMClassMock([FlutterView class]); id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]); id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
@@ -184,7 +182,6 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>( auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate, /*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*task_runners=*/runners); /*task_runners=*/runners);
id mockFlutterView = OCMClassMock([FlutterView class]); id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]); id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
@@ -227,12 +224,9 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
/*raster=*/thread_task_runner, /*raster=*/thread_task_runner,
/*ui=*/thread_task_runner, /*ui=*/thread_task_runner,
/*io=*/thread_task_runner); /*io=*/thread_task_runner);
auto surfaceFactory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware);
auto platform_view = std::make_unique<flutter::PlatformViewIOS>( auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate, /*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*ios_surface_factory=*/surfaceFactory,
/*task_runners=*/runners); /*task_runners=*/runners);
id mockFlutterView = OCMClassMock([FlutterView class]); id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]); id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
@@ -240,9 +234,8 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
std::string label = "some label"; std::string label = "some label";
auto flutterPlatformViewsController = auto flutterPlatformViewsController =
std::make_unique<flutter::FlutterPlatformViewsController>(surfaceFactory); std::make_unique<flutter::FlutterPlatformViewsController>();
flutterPlatformViewsController->SetFlutterView(mockFlutterView); flutterPlatformViewsController->SetFlutterView(mockFlutterView);
surfaceFactory->SetPlatformViewsController(flutterPlatformViewsController.get());
MockFlutterPlatformFactory* factory = [[MockFlutterPlatformFactory new] autorelease]; MockFlutterPlatformFactory* factory = [[MockFlutterPlatformFactory new] autorelease];
flutterPlatformViewsController->RegisterViewFactory( flutterPlatformViewsController->RegisterViewFactory(
@@ -286,7 +279,6 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>( auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate, /*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*task_runners=*/runners); /*task_runners=*/runners);
id mockFlutterView = OCMClassMock([FlutterView class]); id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]); id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
@@ -352,7 +344,6 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>( auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate, /*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*task_runners=*/runners); /*task_runners=*/runners);
id mockFlutterView = OCMClassMock([FlutterView class]); id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]); id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
@@ -420,7 +411,6 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>( auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate, /*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*task_runners=*/runners); /*task_runners=*/runners);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]); id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
id mockFlutterView = OCMClassMock([FlutterView class]); id mockFlutterView = OCMClassMock([FlutterView class]);
@@ -487,7 +477,6 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>( auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate, /*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*task_runners=*/runners); /*task_runners=*/runners);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]); id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
id mockFlutterView = OCMClassMock([FlutterView class]); id mockFlutterView = OCMClassMock([FlutterView class]);
@@ -560,7 +549,6 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>( auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate, /*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*task_runners=*/runners); /*task_runners=*/runners);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]); id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
id mockFlutterView = OCMClassMock([FlutterView class]); id mockFlutterView = OCMClassMock([FlutterView class]);
@@ -635,7 +623,6 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>( auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate, /*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*task_runners=*/runners); /*task_runners=*/runners);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]); id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
id mockFlutterView = OCMClassMock([FlutterView class]); id mockFlutterView = OCMClassMock([FlutterView class]);
@@ -706,7 +693,6 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>( auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate, /*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*task_runners=*/runners); /*task_runners=*/runners);
id mockFlutterView = OCMClassMock([FlutterView class]); id mockFlutterView = OCMClassMock([FlutterView class]);
id mockFlutterViewController = OCMClassMock([FlutterViewController class]); id mockFlutterViewController = OCMClassMock([FlutterViewController class]);
@@ -774,7 +760,6 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(std::string name) {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>( auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate, /*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*task_runners=*/runners); /*task_runners=*/runners);
fml::AutoResetWaitableEvent latch; fml::AutoResetWaitableEvent latch;
thread_task_runner->PostTask([&] { thread_task_runner->PostTask([&] {

View File

@@ -1,39 +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_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(
FlutterPlatformViewsController* platform_views_controller);
std::unique_ptr<IOSSurface> CreateSurface(
fml::scoped_nsobject<CALayer> ca_layer);
private:
FlutterPlatformViewsController* platform_views_controller_;
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,30 +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"
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(
FlutterPlatformViewsController* platform_views_controller) {
platform_views_controller_ = platform_views_controller;
}
std::unique_ptr<IOSSurface> IOSSurfaceFactory::CreateSurface(
fml::scoped_nsobject<CALayer> ca_layer) {
return flutter::IOSSurface::Create(ios_context_, ca_layer, platform_views_controller_);
}
} // namespace flutter

View File

@@ -19,7 +19,6 @@
#import "flutter/shell/platform/darwin/ios/framework/Source/platform_message_router.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_context.h"
#import "flutter/shell/platform/darwin/ios/ios_surface.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" #import "flutter/shell/platform/darwin/ios/rendering_api_selection.h"
@class FlutterViewController; @class FlutterViewController;
@@ -42,7 +41,6 @@ class PlatformViewIOS final : public PlatformView {
public: public:
explicit PlatformViewIOS(PlatformView::Delegate& delegate, explicit PlatformViewIOS(PlatformView::Delegate& delegate,
IOSRenderingAPI rendering_api, IOSRenderingAPI rendering_api,
std::shared_ptr<IOSSurfaceFactory> surface_factory,
flutter::TaskRunners task_runners); flutter::TaskRunners task_runners);
~PlatformViewIOS() override; ~PlatformViewIOS() override;
@@ -126,7 +124,6 @@ class PlatformViewIOS final : public PlatformView {
std::mutex ios_surface_mutex_; std::mutex ios_surface_mutex_;
std::unique_ptr<IOSSurface> ios_surface_; std::unique_ptr<IOSSurface> ios_surface_;
std::shared_ptr<IOSContext> ios_context_; std::shared_ptr<IOSContext> ios_context_;
std::shared_ptr<IOSSurfaceFactory> ios_surface_factory_;
PlatformMessageRouter platform_message_router_; PlatformMessageRouter platform_message_router_;
AccessibilityBridgePtr accessibility_bridge_; AccessibilityBridgePtr accessibility_bridge_;
fml::scoped_nsprotocol<FlutterTextInputPlugin*> text_input_plugin_; fml::scoped_nsprotocol<FlutterTextInputPlugin*> text_input_plugin_;

View File

@@ -3,7 +3,6 @@
// found in the LICENSE file. // found in the LICENSE file.
#import "flutter/shell/platform/darwin/ios/platform_view_ios.h" #import "flutter/shell/platform/darwin/ios/platform_view_ios.h"
#include <memory>
#include <utility> #include <utility>
@@ -47,11 +46,9 @@ void PlatformViewIOS::AccessibilityBridgePtr::reset(AccessibilityBridge* bridge)
PlatformViewIOS::PlatformViewIOS(PlatformView::Delegate& delegate, PlatformViewIOS::PlatformViewIOS(PlatformView::Delegate& delegate,
IOSRenderingAPI rendering_api, IOSRenderingAPI rendering_api,
std::shared_ptr<IOSSurfaceFactory> surface_factory,
flutter::TaskRunners task_runners) flutter::TaskRunners task_runners)
: PlatformView(delegate, std::move(task_runners)), : PlatformView(delegate, std::move(task_runners)),
ios_context_(IOSContext::Create(rendering_api)), ios_context_(IOSContext::Create(rendering_api)),
ios_surface_factory_(surface_factory),
accessibility_bridge_([this](bool enabled) { PlatformView::SetSemanticsEnabled(enabled); }) {} accessibility_bridge_([this](bool enabled) { PlatformView::SetSemanticsEnabled(enabled); }) {}
PlatformViewIOS::~PlatformViewIOS() = default; PlatformViewIOS::~PlatformViewIOS() = default;
@@ -105,9 +102,8 @@ void PlatformViewIOS::attachView() {
FML_DCHECK(owner_controller_.get().isViewLoaded) FML_DCHECK(owner_controller_.get().isViewLoaded)
<< "FlutterViewController's view should be loaded " << "FlutterViewController's view should be loaded "
"before attaching to PlatformViewIOS."; "before attaching to PlatformViewIOS.";
auto flutter_view = static_cast<FlutterView*>(owner_controller_.get().view); ios_surface_ =
auto ca_layer = fml::scoped_nsobject<CALayer>{[[flutter_view layer] retain]}; [static_cast<FlutterView*>(owner_controller_.get().view) createSurface:ios_context_];
ios_surface_ = ios_surface_factory_->CreateSurface(ca_layer);
FML_DCHECK(ios_surface_ != nullptr); FML_DCHECK(ios_surface_ != nullptr);
if (accessibility_bridge_) { if (accessibility_bridge_) {