Skip to content

Commit 0c7c477

Browse files
authored
Revert "[ios] Refactor IOSSurface factory and unify surface creation (flutter#21877)" (flutter#21970)
1 parent 25d8fa5 commit 0c7c477

17 files changed

+46
-167
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,8 +1010,6 @@ FILE: ../../../flutter/shell/platform/darwin/ios/ios_render_target_gl.h
10101010
FILE: ../../../flutter/shell/platform/darwin/ios/ios_render_target_gl.mm
10111011
FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface.h
10121012
FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface.mm
1013-
FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_factory.h
1014-
FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_factory.mm
10151013
FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_gl.h
10161014
FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_gl.mm
10171015
FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_metal.h

shell/platform/darwin/ios/BUILD.gn

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ source_set("flutter_framework_source") {
9999
"ios_render_target_gl.mm",
100100
"ios_surface.h",
101101
"ios_surface.mm",
102-
"ios_surface_factory.h",
103-
"ios_surface_factory.mm",
104102
"ios_surface_gl.h",
105103
"ios_surface_gl.mm",
106104
"ios_surface_software.h",

shell/platform/darwin/ios/framework/Source/FlutterEngine.mm

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
#import "flutter/shell/platform/darwin/ios/framework/Source/platform_message_response_darwin.h"
2929
#import "flutter/shell/platform/darwin/ios/framework/Source/profiler_metrics_ios.h"
3030
#import "flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h"
31-
#import "flutter/shell/platform/darwin/ios/ios_context.h"
3231
#import "flutter/shell/platform/darwin/ios/ios_surface.h"
33-
#import "flutter/shell/platform/darwin/ios/ios_surface_factory.h"
3432
#import "flutter/shell/platform/darwin/ios/platform_view_ios.h"
3533
#import "flutter/shell/platform/darwin/ios/rendering_api_selection.h"
3634
#include "flutter/shell/profiling/sampling_profiler.h"
@@ -65,7 +63,6 @@ @implementation FlutterEngine {
6563
fml::WeakPtr<FlutterViewController> _viewController;
6664
fml::scoped_nsobject<FlutterObservatoryPublisher> _publisher;
6765

68-
std::shared_ptr<flutter::IOSSurfaceFactory> _surfaceFactory;
6966
std::unique_ptr<flutter::FlutterPlatformViewsController> _platformViewsController;
7067
std::unique_ptr<flutter::ProfilerMetricsIOS> _profiler_metrics;
7168
std::unique_ptr<flutter::SamplingProfiler> _profiler;
@@ -131,7 +128,7 @@ - (instancetype)initWithName:(NSString*)labelPrefix
131128

132129
_pluginPublications = [NSMutableDictionary new];
133130
_registrars = [[NSMutableDictionary alloc] init];
134-
[self ensurePlatformViewController];
131+
_platformViewsController.reset(new flutter::FlutterPlatformViewsController());
135132

136133
_binaryMessenger = [[FlutterBinaryMessengerRelay alloc] initWithParent:self];
137134
_connections.reset(new flutter::ConnectionCollection());
@@ -165,16 +162,6 @@ - (instancetype)initWithName:(NSString*)labelPrefix
165162
return self;
166163
}
167164

168-
- (void)ensurePlatformViewController {
169-
if (!_platformViewsController) {
170-
auto renderingApi = flutter::GetRenderingAPIForProcess(FlutterView.forceSoftwareRendering);
171-
_surfaceFactory = flutter::IOSSurfaceFactory::Create(renderingApi);
172-
auto pvc = new flutter::FlutterPlatformViewsController(_surfaceFactory);
173-
_surfaceFactory->SetPlatformViewsController(pvc);
174-
_platformViewsController.reset(pvc);
175-
}
176-
}
177-
178165
- (void)dealloc {
179166
/// Notify plugins of dealloc. This should happen first in dealloc since the
180167
/// plugins may be talking to things like the binaryMessenger.
@@ -533,13 +520,13 @@ - (BOOL)createShell:(NSString*)entrypoint
533520
threadHostType};
534521

535522
// Lambda captures by pointers to ObjC objects are fine here because the
536-
// create call is synchronous.
523+
// create call is
524+
// synchronous.
537525
flutter::Shell::CreateCallback<flutter::PlatformView> on_create_platform_view =
538-
[self](flutter::Shell& shell) {
539-
[self ensurePlatformViewController];
526+
[](flutter::Shell& shell) {
540527
return std::make_unique<flutter::PlatformViewIOS>(
541528
shell, flutter::GetRenderingAPIForProcess(FlutterView.forceSoftwareRendering),
542-
self->_surfaceFactory, shell.GetTaskRunners());
529+
shell.GetTaskRunners());
543530
};
544531

545532
flutter::Shell::CreateCallback<flutter::Rasterizer> on_create_rasterizer =
@@ -567,6 +554,9 @@ - (BOOL)createShell:(NSString*)entrypoint
567554
[self setupChannels];
568555
[self onLocaleUpdated:nil];
569556
[self initializeDisplays];
557+
if (!_platformViewsController) {
558+
_platformViewsController.reset(new flutter::FlutterPlatformViewsController());
559+
}
570560
_publisher.reset([[FlutterObservatoryPublisher alloc]
571561
initWithEnableObservatoryPublication:settings.enable_observatory_publication]);
572562
[self maybeSetupPlatformViewChannels];

shell/platform/darwin/ios/framework/Source/FlutterEnginePlatformViewTest.mm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ - (void)testCallsNotifyLowMemory {
6767
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
6868
/*delegate=*/mock_delegate,
6969
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
70-
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
7170
/*task_runners=*/runners);
7271

7372
id project = OCMClassMock([FlutterDartProject class]);

shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
- (instancetype)init NS_DESIGNATED_INITIALIZER;
3737
- (instancetype)initWithContentsScale:(CGFloat)contentsScale;
38+
- (std::unique_ptr<flutter::IOSSurface>)createSurface:
39+
(std::shared_ptr<flutter::IOSContext>)ios_context;
3840

3941
@end
4042

shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ + (Class)layerClass {
6262
return [FlutterView layerClass];
6363
}
6464

65+
- (std::unique_ptr<flutter::IOSSurface>)createSurface:
66+
(std::shared_ptr<flutter::IOSContext>)ios_context {
67+
return flutter::IOSSurface::Create(std::move(ios_context), // context
68+
fml::scoped_nsobject<CALayer>{[self.layer retain]}, // layer
69+
nullptr // platform views controller
70+
);
71+
}
72+
6573
// TODO(amirh): implement drawLayer to support snapshotting.
6674

6775
@end

shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h"
1717
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h"
1818
#import "flutter/shell/platform/darwin/ios/ios_surface.h"
19-
#import "flutter/shell/platform/darwin/ios/ios_surface_factory.h"
2019
#import "flutter/shell/platform/darwin/ios/ios_surface_gl.h"
2120

2221
namespace flutter {
@@ -33,8 +32,8 @@
3332
overlay_view.reset([[FlutterOverlayView alloc] init]);
3433
overlay_view_wrapper.reset([[FlutterOverlayView alloc] init]);
3534

36-
auto ca_layer = fml::scoped_nsobject<CALayer>{[[overlay_view.get() layer] retain]};
37-
std::unique_ptr<IOSSurface> ios_surface = ios_surface_factory_->CreateSurface(ca_layer);
35+
std::unique_ptr<IOSSurface> ios_surface =
36+
[overlay_view.get() createSurface:std::move(ios_context)];
3837
std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface();
3938

4039
layer = std::make_shared<FlutterPlatformViewLayer>(
@@ -45,8 +44,8 @@
4544
overlay_view.reset([[FlutterOverlayView alloc] initWithContentsScale:screenScale]);
4645
overlay_view_wrapper.reset([[FlutterOverlayView alloc] initWithContentsScale:screenScale]);
4746

48-
auto ca_layer = fml::scoped_nsobject<CALayer>{[[overlay_view.get() layer] retain]};
49-
std::unique_ptr<IOSSurface> ios_surface = ios_surface_factory_->CreateSurface(ca_layer);
47+
std::unique_ptr<IOSSurface> ios_surface =
48+
[overlay_view.get() createSurface:std::move(ios_context)];
5049
std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface(gr_context);
5150

5251
layer = std::make_shared<FlutterPlatformViewLayer>(

shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,12 @@ - (void)testCanCreatePlatformViewWithoutFlutterView {
121121
/*raster=*/thread_task_runner,
122122
/*ui=*/thread_task_runner,
123123
/*io=*/thread_task_runner);
124-
auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware);
125124
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
126125
/*delegate=*/mock_delegate,
127126
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
128-
/*ios_surface_factory=*/surface_factory,
129127
/*task_runners=*/runners);
130128

131-
auto flutterPlatformViewsController =
132-
std::make_unique<flutter::FlutterPlatformViewsController>(surface_factory);
133-
surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get());
129+
auto flutterPlatformViewsController = std::make_unique<flutter::FlutterPlatformViewsController>();
134130

135131
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
136132
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -179,16 +175,12 @@ - (void)testCompositePlatformView {
179175
/*raster=*/thread_task_runner,
180176
/*ui=*/thread_task_runner,
181177
/*io=*/thread_task_runner);
182-
auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware);
183178
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
184179
/*delegate=*/mock_delegate,
185180
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
186-
/*ios_surface_factory=*/surface_factory,
187181
/*task_runners=*/runners);
188182

189-
auto flutterPlatformViewsController =
190-
std::make_unique<flutter::FlutterPlatformViewsController>(surface_factory);
191-
surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get());
183+
auto flutterPlatformViewsController = std::make_unique<flutter::FlutterPlatformViewsController>();
192184

193185
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
194186
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -238,16 +230,12 @@ - (void)testChildClippingViewShouldBeTheBoundingRectOfPlatformView {
238230
/*raster=*/thread_task_runner,
239231
/*ui=*/thread_task_runner,
240232
/*io=*/thread_task_runner);
241-
auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware);
242233
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
243234
/*delegate=*/mock_delegate,
244235
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
245-
/*ios_surface_factory=*/surface_factory,
246236
/*task_runners=*/runners);
247237

248-
auto flutterPlatformViewsController =
249-
std::make_unique<flutter::FlutterPlatformViewsController>(surface_factory);
250-
surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get());
238+
auto flutterPlatformViewsController = std::make_unique<flutter::FlutterPlatformViewsController>();
251239

252240
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
253241
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -313,16 +301,12 @@ - (void)testClipRect {
313301
/*raster=*/thread_task_runner,
314302
/*ui=*/thread_task_runner,
315303
/*io=*/thread_task_runner);
316-
auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware);
317304
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
318305
/*delegate=*/mock_delegate,
319306
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
320-
/*ios_surface_factory=*/surface_factory,
321307
/*task_runners=*/runners);
322308

323-
auto flutterPlatformViewsController =
324-
std::make_unique<flutter::FlutterPlatformViewsController>(surface_factory);
325-
surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get());
309+
auto flutterPlatformViewsController = std::make_unique<flutter::FlutterPlatformViewsController>();
326310

327311
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
328312
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -389,16 +373,12 @@ - (void)testClipRRect {
389373
/*raster=*/thread_task_runner,
390374
/*ui=*/thread_task_runner,
391375
/*io=*/thread_task_runner);
392-
auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware);
393376
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
394377
/*delegate=*/mock_delegate,
395378
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
396-
/*ios_surface_factory=*/surface_factory,
397379
/*task_runners=*/runners);
398380

399-
auto flutterPlatformViewsController =
400-
std::make_unique<flutter::FlutterPlatformViewsController>(surface_factory);
401-
surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get());
381+
auto flutterPlatformViewsController = std::make_unique<flutter::FlutterPlatformViewsController>();
402382

403383
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
404384
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -465,16 +445,12 @@ - (void)testClipPath {
465445
/*raster=*/thread_task_runner,
466446
/*ui=*/thread_task_runner,
467447
/*io=*/thread_task_runner);
468-
auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware);
469448
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
470449
/*delegate=*/mock_delegate,
471450
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
472-
/*ios_surface_factory=*/surface_factory,
473451
/*task_runners=*/runners);
474452

475-
auto flutterPlatformViewsController =
476-
std::make_unique<flutter::FlutterPlatformViewsController>(surface_factory);
477-
surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get());
453+
auto flutterPlatformViewsController = std::make_unique<flutter::FlutterPlatformViewsController>();
478454

479455
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
480456
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
@@ -542,16 +518,12 @@ - (void)testSetFlutterViewControllerAfterCreateCanStillDispatchTouchEvents {
542518
/*raster=*/thread_task_runner,
543519
/*ui=*/thread_task_runner,
544520
/*io=*/thread_task_runner);
545-
auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware);
546521
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
547522
/*delegate=*/mock_delegate,
548523
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
549-
/*ios_surface_factory=*/surface_factory,
550524
/*task_runners=*/runners);
551525

552-
auto flutterPlatformViewsController =
553-
std::make_unique<flutter::FlutterPlatformViewsController>(surface_factory);
554-
surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get());
526+
auto flutterPlatformViewsController = std::make_unique<flutter::FlutterPlatformViewsController>();
555527

556528
FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
557529
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];

shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ void ResetAnchor(CALayer* layer);
6161

6262
class IOSContextGL;
6363
class IOSSurface;
64-
class IOSSurfaceFactory;
6564

6665
struct FlutterPlatformViewLayer {
6766
FlutterPlatformViewLayer(fml::scoped_nsobject<UIView> overlay_view,
@@ -88,9 +87,7 @@ struct FlutterPlatformViewLayer {
8887
// This class isn't thread safe.
8988
class FlutterPlatformViewLayerPool {
9089
public:
91-
FlutterPlatformViewLayerPool(std::shared_ptr<IOSSurfaceFactory> ios_surface_factory)
92-
: ios_surface_factory_(ios_surface_factory) {}
93-
90+
FlutterPlatformViewLayerPool() = default;
9491
~FlutterPlatformViewLayerPool() = default;
9592

9693
// Gets a layer from the pool if available, or allocates a new one.
@@ -121,14 +118,12 @@ class FlutterPlatformViewLayerPool {
121118
size_t available_layer_index_ = 0;
122119
std::vector<std::shared_ptr<FlutterPlatformViewLayer>> layers_;
123120

124-
const std::shared_ptr<IOSSurfaceFactory> ios_surface_factory_;
125-
126121
FML_DISALLOW_COPY_AND_ASSIGN(FlutterPlatformViewLayerPool);
127122
};
128123

129124
class FlutterPlatformViewsController {
130125
public:
131-
FlutterPlatformViewsController(std::shared_ptr<IOSSurfaceFactory> surface_factory);
126+
FlutterPlatformViewsController();
132127

133128
~FlutterPlatformViewsController();
134129

shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@
2323

2424
FlutterPlatformViewLayer::~FlutterPlatformViewLayer() = default;
2525

26-
FlutterPlatformViewsController::FlutterPlatformViewsController(
27-
std::shared_ptr<IOSSurfaceFactory> surface_factory)
28-
: layer_pool_(std::make_unique<FlutterPlatformViewLayerPool>(surface_factory)),
26+
FlutterPlatformViewsController::FlutterPlatformViewsController()
27+
: layer_pool_(std::make_unique<FlutterPlatformViewLayerPool>()),
2928
weak_factory_(std::make_unique<fml::WeakPtrFactory<FlutterPlatformViewsController>>(this)){};
3029

3130
FlutterPlatformViewsController::~FlutterPlatformViewsController() = default;

0 commit comments

Comments
 (0)