Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -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_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
Expand Down
2 changes: 0 additions & 2 deletions shell/platform/darwin/ios/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 8 additions & 18 deletions shell/platform/darwin/ios/framework/Source/FlutterEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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/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"
Expand Down Expand Up @@ -65,7 +63,6 @@ @implementation FlutterEngine {
fml::WeakPtr<FlutterViewController> _viewController;
fml::scoped_nsobject<FlutterObservatoryPublisher> _publisher;

std::shared_ptr<flutter::IOSSurfaceFactory> _surfaceFactory;
std::unique_ptr<flutter::FlutterPlatformViewsController> _platformViewsController;
std::unique_ptr<flutter::ProfilerMetricsIOS> _profiler_metrics;
std::unique_ptr<flutter::SamplingProfiler> _profiler;
Expand Down Expand Up @@ -130,7 +127,7 @@ - (instancetype)initWithName:(NSString*)labelPrefix

_pluginPublications = [NSMutableDictionary new];
_registrars = [[NSMutableDictionary alloc] init];
[self ensurePlatformViewController];
_platformViewsController.reset(new flutter::FlutterPlatformViewsController());

_binaryMessenger = [[FlutterBinaryMessengerRelay alloc] initWithParent:self];
_connections.reset(new flutter::ConnectionCollection());
Expand Down Expand Up @@ -164,16 +161,6 @@ - (instancetype)initWithName:(NSString*)labelPrefix
return self;
}

- (void)ensurePlatformViewController {
if (!_platformViewsController) {
auto renderingApi = flutter::GetRenderingAPIForProcess(FlutterView.forceSoftwareRendering);
_surfaceFactory = flutter::IOSSurfaceFactory::Create(renderingApi);
auto pvc = new flutter::FlutterPlatformViewsController(_surfaceFactory);
_surfaceFactory->SetPlatformViewsController(pvc);
_platformViewsController.reset(pvc);
}
}

- (void)dealloc {
/// Notify plugins of dealloc. This should happen first in dealloc since the
/// plugins may be talking to things like the binaryMessenger.
Expand Down Expand Up @@ -523,13 +510,13 @@ - (BOOL)createShell:(NSString*)entrypoint
threadHostType};

// 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 =
[self](flutter::Shell& shell) {
[self ensurePlatformViewController];
[](flutter::Shell& shell) {
return std::make_unique<flutter::PlatformViewIOS>(
shell, flutter::GetRenderingAPIForProcess(FlutterView.forceSoftwareRendering),
self->_surfaceFactory, shell.GetTaskRunners());
shell.GetTaskRunners());
};

flutter::Shell::CreateCallback<flutter::Rasterizer> on_create_rasterizer =
Expand Down Expand Up @@ -557,6 +544,9 @@ - (BOOL)createShell:(NSString*)entrypoint
[self setupChannels];
[self onLocaleUpdated:nil];
[self initializeDisplays];
if (!_platformViewsController) {
_platformViewsController.reset(new flutter::FlutterPlatformViewsController());
}
_publisher.reset([[FlutterObservatoryPublisher alloc]
initWithEnableObservatoryPublication:settings.enable_observatory_publication]);
[self maybeSetupPlatformViewChannels];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ - (void)testCallsNotifyLowMemory {
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
/*task_runners=*/runners);

id project = OCMClassMock([FlutterDartProject class]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

- (instancetype)init NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithContentsScale:(CGFloat)contentsScale;
- (std::unique_ptr<flutter::IOSSurface>)createSurface:
(std::shared_ptr<flutter::IOSContext>)ios_context;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ + (Class)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.

@end
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -33,8 +32,8 @@
overlay_view.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 = ios_surface_factory_->CreateSurface(ca_layer);
std::unique_ptr<IOSSurface> ios_surface =
[overlay_view.get() createSurface:std::move(ios_context)];
std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface();

layer = std::make_shared<FlutterPlatformViewLayer>(
Expand All @@ -45,8 +44,8 @@
overlay_view.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 = ios_surface_factory_->CreateSurface(ca_layer);
std::unique_ptr<IOSSurface> ios_surface =
[overlay_view.get() createSurface:std::move(ios_context)];
std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface(gr_context);

layer = std::make_shared<FlutterPlatformViewLayer>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,12 @@ - (void)testCanCreatePlatformViewWithoutFlutterView {
/*raster=*/thread_task_runner,
/*ui=*/thread_task_runner,
/*io=*/thread_task_runner);
auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware);
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*ios_surface_factory=*/surface_factory,
/*task_runners=*/runners);

auto flutterPlatformViewsController =
std::make_unique<flutter::FlutterPlatformViewsController>(surface_factory);
surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get());
auto flutterPlatformViewsController = std::make_unique<flutter::FlutterPlatformViewsController>();

FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
Expand Down Expand Up @@ -179,16 +175,12 @@ - (void)testCompositePlatformView {
/*raster=*/thread_task_runner,
/*ui=*/thread_task_runner,
/*io=*/thread_task_runner);
auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware);
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*ios_surface_factory=*/surface_factory,
/*task_runners=*/runners);

auto flutterPlatformViewsController =
std::make_unique<flutter::FlutterPlatformViewsController>(surface_factory);
surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get());
auto flutterPlatformViewsController = std::make_unique<flutter::FlutterPlatformViewsController>();

FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
Expand Down Expand Up @@ -238,16 +230,12 @@ - (void)testChildClippingViewShouldBeTheBoundingRectOfPlatformView {
/*raster=*/thread_task_runner,
/*ui=*/thread_task_runner,
/*io=*/thread_task_runner);
auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware);
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*ios_surface_factory=*/surface_factory,
/*task_runners=*/runners);

auto flutterPlatformViewsController =
std::make_unique<flutter::FlutterPlatformViewsController>(surface_factory);
surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get());
auto flutterPlatformViewsController = std::make_unique<flutter::FlutterPlatformViewsController>();

FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
Expand Down Expand Up @@ -313,16 +301,12 @@ - (void)testClipRect {
/*raster=*/thread_task_runner,
/*ui=*/thread_task_runner,
/*io=*/thread_task_runner);
auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware);
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*ios_surface_factory=*/surface_factory,
/*task_runners=*/runners);

auto flutterPlatformViewsController =
std::make_unique<flutter::FlutterPlatformViewsController>(surface_factory);
surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get());
auto flutterPlatformViewsController = std::make_unique<flutter::FlutterPlatformViewsController>();

FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
Expand Down Expand Up @@ -389,16 +373,12 @@ - (void)testClipRRect {
/*raster=*/thread_task_runner,
/*ui=*/thread_task_runner,
/*io=*/thread_task_runner);
auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware);
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*ios_surface_factory=*/surface_factory,
/*task_runners=*/runners);

auto flutterPlatformViewsController =
std::make_unique<flutter::FlutterPlatformViewsController>(surface_factory);
surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get());
auto flutterPlatformViewsController = std::make_unique<flutter::FlutterPlatformViewsController>();

FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
Expand Down Expand Up @@ -465,16 +445,12 @@ - (void)testClipPath {
/*raster=*/thread_task_runner,
/*ui=*/thread_task_runner,
/*io=*/thread_task_runner);
auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware);
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*ios_surface_factory=*/surface_factory,
/*task_runners=*/runners);

auto flutterPlatformViewsController =
std::make_unique<flutter::FlutterPlatformViewsController>(surface_factory);
surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get());
auto flutterPlatformViewsController = std::make_unique<flutter::FlutterPlatformViewsController>();

FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
Expand Down Expand Up @@ -542,16 +518,12 @@ - (void)testSetFlutterViewControllerAfterCreateCanStillDispatchTouchEvents {
/*raster=*/thread_task_runner,
/*ui=*/thread_task_runner,
/*io=*/thread_task_runner);
auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware);
auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
/*delegate=*/mock_delegate,
/*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
/*ios_surface_factory=*/surface_factory,
/*task_runners=*/runners);

auto flutterPlatformViewsController =
std::make_unique<flutter::FlutterPlatformViewsController>(surface_factory);
surface_factory->SetPlatformViewsController(flutterPlatformViewsController.get());
auto flutterPlatformViewsController = std::make_unique<flutter::FlutterPlatformViewsController>();

FlutterPlatformViewsTestMockFlutterPlatformFactory* factory =
[[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ void ResetAnchor(CALayer* layer);

class IOSContextGL;
class IOSSurface;
class IOSSurfaceFactory;

struct FlutterPlatformViewLayer {
FlutterPlatformViewLayer(fml::scoped_nsobject<UIView> overlay_view,
Expand All @@ -88,9 +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;

// Gets a layer from the pool if available, or allocates a new one.
Expand Down Expand Up @@ -121,14 +118,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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@

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;
Expand Down
1 change: 1 addition & 0 deletions shell/platform/darwin/ios/framework/Source/FlutterView.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

- (instancetype)initWithDelegate:(id<FlutterViewEngineDelegate>)delegate
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.
@property(class, nonatomic) BOOL forceSoftwareRendering;
Expand Down
9 changes: 9 additions & 0 deletions shell/platform/darwin/ios/framework/Source/FlutterView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ + (Class)layerClass {
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 {
TRACE_EVENT0("flutter", "SnapshotFlutterView");

Expand Down
Loading