Migrate PlatformViewIOS to ARC (flutter/engine#55672)
Migrates PlatformViewIOS from manual reference counting to ARC. Eliminates use of scoped_nsobject, scoped_nsprotocol, and WeakNSObject. Since this is the last non-ARC file in `flutter_framework_source`, this also eliminates the `flutter_framework_source` target, then also renames the `flutter_framework_source_arc` target to `flutter_framework_source` since... it's ALL ARC. No semantic changes, therefore no semantic changes to tests. Issue: https://github.com/flutter/flutter/issues/137801 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
parent
57167c8067
commit
dd8db914de
@ -39,7 +39,7 @@ _flutter_framework_headers = [
|
|||||||
|
|
||||||
_flutter_framework_headers_copy_dir = "$_flutter_framework_dir/Headers"
|
_flutter_framework_headers_copy_dir = "$_flutter_framework_dir/Headers"
|
||||||
|
|
||||||
source_set("flutter_framework_source_arc") {
|
source_set("flutter_framework_source") {
|
||||||
visibility = [ ":*" ]
|
visibility = [ ":*" ]
|
||||||
cflags_objc = flutter_cflags_objc_arc
|
cflags_objc = flutter_cflags_objc_arc
|
||||||
cflags_objcc = flutter_cflags_objcc_arc
|
cflags_objcc = flutter_cflags_objcc_arc
|
||||||
@ -48,15 +48,10 @@ source_set("flutter_framework_source_arc") {
|
|||||||
if (darwin_extension_safe) {
|
if (darwin_extension_safe) {
|
||||||
defines += [ "APPLICATION_EXTENSION_API_ONLY=1" ]
|
defines += [ "APPLICATION_EXTENSION_API_ONLY=1" ]
|
||||||
}
|
}
|
||||||
allow_circular_includes_from = [ ":flutter_framework_source" ]
|
public_configs = [
|
||||||
deps = [
|
":ios_gpu_configuration_config",
|
||||||
":flutter_framework_source",
|
"//flutter:config",
|
||||||
"//flutter/fml",
|
|
||||||
"//flutter/shell/platform/common:common_cpp_input",
|
|
||||||
"//flutter/shell/platform/darwin/common:framework_common",
|
|
||||||
"//flutter/third_party/icu",
|
|
||||||
]
|
]
|
||||||
public_configs = [ "//flutter:config" ]
|
|
||||||
|
|
||||||
sources = [
|
sources = [
|
||||||
"framework/Source/FlutterAppDelegate.mm",
|
"framework/Source/FlutterAppDelegate.mm",
|
||||||
@ -157,71 +152,18 @@ source_set("flutter_framework_source_arc") {
|
|||||||
"ios_surface_software.mm",
|
"ios_surface_software.mm",
|
||||||
"platform_message_handler_ios.h",
|
"platform_message_handler_ios.h",
|
||||||
"platform_message_handler_ios.mm",
|
"platform_message_handler_ios.mm",
|
||||||
|
"platform_view_ios.h",
|
||||||
|
"platform_view_ios.mm",
|
||||||
"rendering_api_selection.h",
|
"rendering_api_selection.h",
|
||||||
"rendering_api_selection.mm",
|
"rendering_api_selection.mm",
|
||||||
]
|
]
|
||||||
|
|
||||||
frameworks = [
|
|
||||||
"UIKit.framework",
|
|
||||||
"IOSurface.framework",
|
|
||||||
]
|
|
||||||
|
|
||||||
deps += [
|
|
||||||
":ios_gpu_configuration",
|
|
||||||
"//flutter/common:common",
|
|
||||||
"//flutter/common/graphics",
|
|
||||||
"//flutter/lib/ui",
|
|
||||||
"//flutter/runtime",
|
|
||||||
"//flutter/shell/common",
|
|
||||||
"//flutter/shell/platform/darwin/common",
|
|
||||||
"//flutter/shell/platform/darwin/graphics",
|
|
||||||
"//flutter/shell/platform/embedder:embedder_as_internal_library",
|
|
||||||
"//flutter/shell/profiling:profiling",
|
|
||||||
"//flutter/third_party/spring_animation",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
source_set("flutter_framework_source") {
|
|
||||||
visibility = [ ":*" ]
|
|
||||||
cflags_objc = flutter_cflags_objc
|
|
||||||
cflags_objcc = flutter_cflags_objcc
|
|
||||||
|
|
||||||
deps = []
|
|
||||||
|
|
||||||
sources = [
|
|
||||||
# iOS embedder is migrating to ARC.
|
|
||||||
# New files are highly encouraged to be in ARC.
|
|
||||||
# To add new files in ARC, add them to the `flutter_framework_source_arc` target.
|
|
||||||
"platform_view_ios.h",
|
|
||||||
"platform_view_ios.mm",
|
|
||||||
]
|
|
||||||
|
|
||||||
sources += _flutter_framework_headers
|
sources += _flutter_framework_headers
|
||||||
|
|
||||||
defines = [ "FLUTTER_FRAMEWORK=1" ]
|
|
||||||
if (darwin_extension_safe) {
|
|
||||||
defines += [ "APPLICATION_EXTENSION_API_ONLY=1" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
deps += [
|
|
||||||
"//flutter/fml",
|
|
||||||
"//flutter/runtime",
|
|
||||||
"//flutter/shell/common",
|
|
||||||
"//flutter/shell/platform/darwin/common",
|
|
||||||
"//flutter/shell/platform/darwin/common:framework_common",
|
|
||||||
"//flutter/shell/platform/embedder:embedder_as_internal_library",
|
|
||||||
"//flutter/shell/profiling:profiling",
|
|
||||||
]
|
|
||||||
|
|
||||||
public_configs = [
|
|
||||||
":ios_gpu_configuration_config",
|
|
||||||
"//flutter:config",
|
|
||||||
]
|
|
||||||
|
|
||||||
frameworks = [
|
frameworks = [
|
||||||
"AudioToolbox.framework",
|
"AudioToolbox.framework",
|
||||||
"CoreMedia.framework",
|
"CoreMedia.framework",
|
||||||
"CoreVideo.framework",
|
"CoreVideo.framework",
|
||||||
|
"IOSurface.framework",
|
||||||
"QuartzCore.framework",
|
"QuartzCore.framework",
|
||||||
"UIKit.framework",
|
"UIKit.framework",
|
||||||
]
|
]
|
||||||
@ -230,6 +172,24 @@ source_set("flutter_framework_source") {
|
|||||||
# Usage in release builds will cause rejection from the App Store.
|
# Usage in release builds will cause rejection from the App Store.
|
||||||
frameworks += [ "IOKit.framework" ]
|
frameworks += [ "IOKit.framework" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deps = [
|
||||||
|
":ios_gpu_configuration",
|
||||||
|
"//flutter/common:common",
|
||||||
|
"//flutter/common/graphics",
|
||||||
|
"//flutter/fml",
|
||||||
|
"//flutter/lib/ui",
|
||||||
|
"//flutter/runtime",
|
||||||
|
"//flutter/shell/common",
|
||||||
|
"//flutter/shell/platform/common:common_cpp_input",
|
||||||
|
"//flutter/shell/platform/darwin/common",
|
||||||
|
"//flutter/shell/platform/darwin/common:framework_common",
|
||||||
|
"//flutter/shell/platform/darwin/graphics",
|
||||||
|
"//flutter/shell/platform/embedder:embedder_as_internal_library",
|
||||||
|
"//flutter/shell/profiling:profiling",
|
||||||
|
"//flutter/third_party/icu",
|
||||||
|
"//flutter/third_party/spring_animation",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
platform_frameworks_path =
|
platform_frameworks_path =
|
||||||
@ -296,7 +256,6 @@ shared_library("ios_test_flutter") {
|
|||||||
deps = [
|
deps = [
|
||||||
":flutter_framework",
|
":flutter_framework",
|
||||||
":flutter_framework_source",
|
":flutter_framework_source",
|
||||||
":flutter_framework_source_arc",
|
|
||||||
":ios_gpu_configuration",
|
":ios_gpu_configuration",
|
||||||
"//flutter/common:common",
|
"//flutter/common:common",
|
||||||
"//flutter/lib/ui:ui",
|
"//flutter/lib/ui:ui",
|
||||||
@ -333,10 +292,7 @@ shared_library("create_flutter_framework_dylib") {
|
|||||||
|
|
||||||
public = _flutter_framework_headers
|
public = _flutter_framework_headers
|
||||||
|
|
||||||
deps = [
|
deps = [ ":flutter_framework_source" ]
|
||||||
":flutter_framework_source",
|
|
||||||
":flutter_framework_source_arc",
|
|
||||||
]
|
|
||||||
|
|
||||||
public_configs = [ "//flutter:config" ]
|
public_configs = [ "//flutter:config" ]
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
#include "flutter/common/constants.h"
|
#include "flutter/common/constants.h"
|
||||||
#include "flutter/fml/message_loop.h"
|
#include "flutter/fml/message_loop.h"
|
||||||
#include "flutter/fml/platform/darwin/platform_version.h"
|
#include "flutter/fml/platform/darwin/platform_version.h"
|
||||||
#include "flutter/fml/platform/darwin/weak_nsobject.h"
|
|
||||||
#include "flutter/fml/trace_event.h"
|
#include "flutter/fml/trace_event.h"
|
||||||
#include "flutter/runtime/ptrace_check.h"
|
#include "flutter/runtime/ptrace_check.h"
|
||||||
#include "flutter/shell/common/engine.h"
|
#include "flutter/shell/common/engine.h"
|
||||||
@ -152,10 +151,6 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
|
|||||||
std::shared_ptr<flutter::ThreadHost> _threadHost;
|
std::shared_ptr<flutter::ThreadHost> _threadHost;
|
||||||
std::unique_ptr<flutter::Shell> _shell;
|
std::unique_ptr<flutter::Shell> _shell;
|
||||||
|
|
||||||
// TODO(cbracken): https://github.com/flutter/flutter/issues/155943
|
|
||||||
// Migrate to @property(nonatomic, weak).
|
|
||||||
fml::WeakNSObject<FlutterViewController> _viewController;
|
|
||||||
|
|
||||||
std::shared_ptr<flutter::PlatformViewsController> _platformViewsController;
|
std::shared_ptr<flutter::PlatformViewsController> _platformViewsController;
|
||||||
flutter::IOSRenderingAPI _renderingApi;
|
flutter::IOSRenderingAPI _renderingApi;
|
||||||
std::shared_ptr<flutter::SamplingProfiler> _profiler;
|
std::shared_ptr<flutter::SamplingProfiler> _profiler;
|
||||||
@ -406,8 +401,7 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
|
|||||||
|
|
||||||
- (void)setViewController:(FlutterViewController*)viewController {
|
- (void)setViewController:(FlutterViewController*)viewController {
|
||||||
FML_DCHECK(self.iosPlatformView);
|
FML_DCHECK(self.iosPlatformView);
|
||||||
_viewController = viewController ? [viewController getWeakNSObject]
|
_viewController = viewController;
|
||||||
: fml::WeakNSObject<FlutterViewController>();
|
|
||||||
self.iosPlatformView->SetOwnerViewController(_viewController);
|
self.iosPlatformView->SetOwnerViewController(_viewController);
|
||||||
[self maybeSetupPlatformViewChannels];
|
[self maybeSetupPlatformViewChannels];
|
||||||
[self updateDisplays];
|
[self updateDisplays];
|
||||||
@ -454,7 +448,7 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
[self.textInputPlugin resetViewResponder];
|
[self.textInputPlugin resetViewResponder];
|
||||||
_viewController.reset();
|
_viewController = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)destroyContext {
|
- (void)destroyContext {
|
||||||
@ -466,13 +460,6 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
|
|||||||
_platformViewsController.reset();
|
_platformViewsController.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
- (FlutterViewController*)viewController {
|
|
||||||
if (!_viewController) {
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
return _viewController.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (std::shared_ptr<flutter::PlatformViewsController>&)platformViewsController {
|
- (std::shared_ptr<flutter::PlatformViewsController>&)platformViewsController {
|
||||||
return _platformViewsController;
|
return _platformViewsController;
|
||||||
}
|
}
|
||||||
|
@ -153,11 +153,7 @@ typedef struct MouseState {
|
|||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation FlutterViewController {
|
@implementation FlutterViewController {
|
||||||
// TODO(cbracken): https://github.com/flutter/flutter/issues/137801
|
|
||||||
// Eliminate once we can use weak pointers in platform_view_ios.h.
|
|
||||||
std::unique_ptr<fml::WeakNSObjectFactory<FlutterViewController>> _weakFactory;
|
|
||||||
FlutterEngine* _engine;
|
FlutterEngine* _engine;
|
||||||
|
|
||||||
flutter::ViewportMetrics _viewportMetrics;
|
flutter::ViewportMetrics _viewportMetrics;
|
||||||
MouseState _mouseState;
|
MouseState _mouseState;
|
||||||
}
|
}
|
||||||
@ -189,7 +185,6 @@ typedef struct MouseState {
|
|||||||
_flutterView = [[FlutterView alloc] initWithDelegate:_engine
|
_flutterView = [[FlutterView alloc] initWithDelegate:_engine
|
||||||
opaque:self.isViewOpaque
|
opaque:self.isViewOpaque
|
||||||
enableWideGamut:engine.project.isWideGamutEnabled];
|
enableWideGamut:engine.project.isWideGamutEnabled];
|
||||||
_weakFactory = std::make_unique<fml::WeakNSObjectFactory<FlutterViewController>>(self);
|
|
||||||
_ongoingTouches = [[NSMutableSet alloc] init];
|
_ongoingTouches = [[NSMutableSet alloc] init];
|
||||||
|
|
||||||
// TODO(cbracken): https://github.com/flutter/flutter/issues/157140
|
// TODO(cbracken): https://github.com/flutter/flutter/issues/157140
|
||||||
@ -256,7 +251,6 @@ typedef struct MouseState {
|
|||||||
project = [[FlutterDartProject alloc] init];
|
project = [[FlutterDartProject alloc] init];
|
||||||
}
|
}
|
||||||
FlutterView.forceSoftwareRendering = project.settings.enable_software_rendering;
|
FlutterView.forceSoftwareRendering = project.settings.enable_software_rendering;
|
||||||
_weakFactory = std::make_unique<fml::WeakNSObjectFactory<FlutterViewController>>(self);
|
|
||||||
FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"io.flutter"
|
FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"io.flutter"
|
||||||
project:project
|
project:project
|
||||||
allowHeadlessExecution:self.engineAllowHeadlessExecution
|
allowHeadlessExecution:self.engineAllowHeadlessExecution
|
||||||
@ -312,10 +306,6 @@ typedef struct MouseState {
|
|||||||
return _engine;
|
return _engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (fml::WeakNSObject<FlutterViewController>)getWeakNSObject {
|
|
||||||
return _weakFactory->GetWeakNSObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setUpNotificationCenterObservers {
|
- (void)setUpNotificationCenterObservers {
|
||||||
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
|
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
|
||||||
[center addObserver:self
|
[center addObserver:self
|
||||||
@ -980,10 +970,6 @@ static void SendFakeTouchEvent(UIScreen* screen,
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
// It will be destroyed and invalidate its weak pointers
|
|
||||||
// before any other members are destroyed.
|
|
||||||
_weakFactory.reset();
|
|
||||||
|
|
||||||
// TODO(cbracken): https://github.com/flutter/flutter/issues/157140
|
// TODO(cbracken): https://github.com/flutter/flutter/issues/157140
|
||||||
// Eliminate method calls in initializers and dealloc.
|
// Eliminate method calls in initializers and dealloc.
|
||||||
[self removeInternalPlugins];
|
[self removeInternalPlugins];
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERVIEWCONTROLLER_INTERNAL_H_
|
#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERVIEWCONTROLLER_INTERNAL_H_
|
||||||
#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERVIEWCONTROLLER_INTERNAL_H_
|
#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERVIEWCONTROLLER_INTERNAL_H_
|
||||||
|
|
||||||
#include "flutter/fml/platform/darwin/weak_nsobject.h"
|
|
||||||
#include "flutter/fml/time/time_point.h"
|
#include "flutter/fml/time/time_point.h"
|
||||||
|
|
||||||
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"
|
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"
|
||||||
@ -57,7 +56,6 @@ typedef void (^FlutterKeyboardAnimationCallback)(fml::TimePoint);
|
|||||||
*/
|
*/
|
||||||
@property(nonatomic, assign, readwrite) BOOL prefersStatusBarHidden;
|
@property(nonatomic, assign, readwrite) BOOL prefersStatusBarHidden;
|
||||||
|
|
||||||
- (fml::WeakNSObject<FlutterViewController>)getWeakNSObject;
|
|
||||||
- (std::shared_ptr<flutter::PlatformViewsController>&)platformViewsController;
|
- (std::shared_ptr<flutter::PlatformViewsController>&)platformViewsController;
|
||||||
- (FlutterRestorationPlugin*)restorationPlugin;
|
- (FlutterRestorationPlugin*)restorationPlugin;
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ AccessibilityBridge::AccessibilityBridge(
|
|||||||
weak_factory_(this) {
|
weak_factory_(this) {
|
||||||
accessibility_channel_.reset([[FlutterBasicMessageChannel alloc]
|
accessibility_channel_.reset([[FlutterBasicMessageChannel alloc]
|
||||||
initWithName:@"flutter/accessibility"
|
initWithName:@"flutter/accessibility"
|
||||||
binaryMessenger:platform_view->GetOwnerViewController().get().engine.binaryMessenger
|
binaryMessenger:platform_view->GetOwnerViewController().engine.binaryMessenger
|
||||||
codec:[FlutterStandardMessageCodec sharedInstance]]);
|
codec:[FlutterStandardMessageCodec sharedInstance]]);
|
||||||
[accessibility_channel_.get() setMessageHandler:^(id message, FlutterReply reply) {
|
[accessibility_channel_.get() setMessageHandler:^(id message, FlutterReply reply) {
|
||||||
HandleEvent((NSDictionary*)message);
|
HandleEvent((NSDictionary*)message);
|
||||||
@ -69,7 +69,7 @@ AccessibilityBridge::~AccessibilityBridge() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UIView<UITextInput>* AccessibilityBridge::textInputView() {
|
UIView<UITextInput>* AccessibilityBridge::textInputView() {
|
||||||
return [[platform_view_->GetOwnerViewController().get().engine textInputPlugin] textInputView];
|
return [[platform_view_->GetOwnerViewController().engine textInputPlugin] textInputView];
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccessibilityBridge::AccessibilityObjectDidBecomeFocused(int32_t id) {
|
void AccessibilityBridge::AccessibilityObjectDidBecomeFocused(int32_t id) {
|
||||||
|
@ -1402,9 +1402,7 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(const std::string& name) {
|
|||||||
/*is_gpu_disabled_sync_switch=*/std::make_shared<fml::SyncSwitch>());
|
/*is_gpu_disabled_sync_switch=*/std::make_shared<fml::SyncSwitch>());
|
||||||
fml::AutoResetWaitableEvent latch;
|
fml::AutoResetWaitableEvent latch;
|
||||||
thread_task_runner->PostTask([&] {
|
thread_task_runner->PostTask([&] {
|
||||||
auto weakFactory =
|
platform_view->SetOwnerViewController(flutterViewController);
|
||||||
std::make_unique<fml::WeakNSObjectFactory<FlutterViewController>>(flutterViewController);
|
|
||||||
platform_view->SetOwnerViewController(weakFactory->GetWeakNSObject());
|
|
||||||
auto bridge =
|
auto bridge =
|
||||||
std::make_unique<flutter::AccessibilityBridge>(/*view=*/nil,
|
std::make_unique<flutter::AccessibilityBridge>(/*view=*/nil,
|
||||||
/*platform_view=*/platform_view.get(),
|
/*platform_view=*/platform_view.get(),
|
||||||
@ -2091,9 +2089,7 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(const std::string& name) {
|
|||||||
/*is_gpu_disabled_sync_switch=*/std::make_shared<fml::SyncSwitch>());
|
/*is_gpu_disabled_sync_switch=*/std::make_shared<fml::SyncSwitch>());
|
||||||
fml::AutoResetWaitableEvent latch;
|
fml::AutoResetWaitableEvent latch;
|
||||||
thread_task_runner->PostTask([&] {
|
thread_task_runner->PostTask([&] {
|
||||||
auto weakFactory =
|
platform_view->SetOwnerViewController(flutterViewController);
|
||||||
std::make_unique<fml::WeakNSObjectFactory<FlutterViewController>>(flutterViewController);
|
|
||||||
platform_view->SetOwnerViewController(weakFactory->GetWeakNSObject());
|
|
||||||
auto bridge =
|
auto bridge =
|
||||||
std::make_unique<flutter::AccessibilityBridge>(/*view=*/nil,
|
std::make_unique<flutter::AccessibilityBridge>(/*view=*/nil,
|
||||||
/*platform_view=*/platform_view.get(),
|
/*platform_view=*/platform_view.get(),
|
||||||
@ -2184,9 +2180,7 @@ fml::RefPtr<fml::TaskRunner> CreateNewThread(const std::string& name) {
|
|||||||
|
|
||||||
OCMStub([mockFlutterViewController platformViewsController])
|
OCMStub([mockFlutterViewController platformViewsController])
|
||||||
.andReturn(flutterPlatformViewsController.get());
|
.andReturn(flutterPlatformViewsController.get());
|
||||||
auto weakFactory = std::make_unique<fml::WeakNSObjectFactory<FlutterViewController>>(
|
platform_view->SetOwnerViewController(mockFlutterViewController);
|
||||||
mockFlutterViewController);
|
|
||||||
platform_view->SetOwnerViewController(weakFactory->GetWeakNSObject());
|
|
||||||
|
|
||||||
platform_view->SetSemanticsEnabled(true);
|
platform_view->SetSemanticsEnabled(true);
|
||||||
XCTAssertNotEqual(test_delegate.set_semantics_enabled_calls, 0);
|
XCTAssertNotEqual(test_delegate.set_semantics_enabled_calls, 0);
|
||||||
|
@ -9,8 +9,6 @@
|
|||||||
|
|
||||||
#include "flutter/fml/closure.h"
|
#include "flutter/fml/closure.h"
|
||||||
#include "flutter/fml/macros.h"
|
#include "flutter/fml/macros.h"
|
||||||
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
|
|
||||||
#include "flutter/fml/platform/darwin/weak_nsobject.h"
|
|
||||||
#include "flutter/shell/common/platform_view.h"
|
#include "flutter/shell/common/platform_view.h"
|
||||||
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterTexture.h"
|
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterTexture.h"
|
||||||
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"
|
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"
|
||||||
@ -59,14 +57,14 @@ class PlatformViewIOS final : public PlatformView {
|
|||||||
* Returns the `FlutterViewController` currently attached to the `FlutterEngine` owning
|
* Returns the `FlutterViewController` currently attached to the `FlutterEngine` owning
|
||||||
* this PlatformViewIOS.
|
* this PlatformViewIOS.
|
||||||
*/
|
*/
|
||||||
fml::WeakNSObject<FlutterViewController> GetOwnerViewController() const;
|
FlutterViewController* GetOwnerViewController() const __attribute__((cf_audited_transfer));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the `FlutterViewController` currently attached to the `FlutterEngine` owning
|
* Updates the `FlutterViewController` currently attached to the `FlutterEngine` owning
|
||||||
* this PlatformViewIOS. This should be updated when the `FlutterEngine`
|
* this PlatformViewIOS. This should be updated when the `FlutterEngine`
|
||||||
* is given a new `FlutterViewController`.
|
* is given a new `FlutterViewController`.
|
||||||
*/
|
*/
|
||||||
void SetOwnerViewController(const fml::WeakNSObject<FlutterViewController>& owner_controller);
|
void SetOwnerViewController(__weak FlutterViewController* owner_controller);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called one time per `FlutterViewController` when the `FlutterViewController`'s
|
* Called one time per `FlutterViewController` when the `FlutterViewController`'s
|
||||||
@ -133,7 +131,7 @@ class PlatformViewIOS final : public PlatformView {
|
|||||||
std::function<void(bool)> set_semantics_enabled_;
|
std::function<void(bool)> set_semantics_enabled_;
|
||||||
};
|
};
|
||||||
|
|
||||||
fml::WeakNSObject<FlutterViewController> owner_controller_;
|
__weak FlutterViewController* owner_controller_;
|
||||||
// Since the `ios_surface_` is created on the platform thread but
|
// Since the `ios_surface_` is created on the platform thread but
|
||||||
// used on the raster thread we need to protect it with a mutex.
|
// used on the raster thread we need to protect it with a mutex.
|
||||||
std::mutex ios_surface_mutex_;
|
std::mutex ios_surface_mutex_;
|
||||||
@ -141,7 +139,6 @@ class PlatformViewIOS final : public PlatformView {
|
|||||||
std::shared_ptr<IOSContext> ios_context_;
|
std::shared_ptr<IOSContext> ios_context_;
|
||||||
const std::shared_ptr<PlatformViewsController>& platform_views_controller_;
|
const std::shared_ptr<PlatformViewsController>& platform_views_controller_;
|
||||||
AccessibilityBridgeManager accessibility_bridge_;
|
AccessibilityBridgeManager accessibility_bridge_;
|
||||||
fml::scoped_nsprotocol<FlutterTextInputPlugin*> text_input_plugin_;
|
|
||||||
ScopedObserver dealloc_view_controller_observer_;
|
ScopedObserver dealloc_view_controller_observer_;
|
||||||
std::vector<std::string> platform_resolved_locale_;
|
std::vector<std::string> platform_resolved_locale_;
|
||||||
std::shared_ptr<PlatformMessageHandlerIos> platform_message_handler_;
|
std::shared_ptr<PlatformMessageHandlerIos> platform_message_handler_;
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h"
|
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.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"
|
||||||
|
|
||||||
|
FLUTTER_ASSERT_ARC
|
||||||
|
|
||||||
namespace flutter {
|
namespace flutter {
|
||||||
|
|
||||||
PlatformViewIOS::AccessibilityBridgeManager::AccessibilityBridgeManager(
|
PlatformViewIOS::AccessibilityBridgeManager::AccessibilityBridgeManager(
|
||||||
@ -74,12 +76,11 @@ void PlatformViewIOS::HandlePlatformMessage(std::unique_ptr<flutter::PlatformMes
|
|||||||
platform_message_handler_->HandlePlatformMessage(std::move(message));
|
platform_message_handler_->HandlePlatformMessage(std::move(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
fml::WeakNSObject<FlutterViewController> PlatformViewIOS::GetOwnerViewController() const {
|
FlutterViewController* PlatformViewIOS::GetOwnerViewController() const {
|
||||||
return owner_controller_;
|
return owner_controller_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlatformViewIOS::SetOwnerViewController(
|
void PlatformViewIOS::SetOwnerViewController(__weak FlutterViewController* owner_controller) {
|
||||||
const fml::WeakNSObject<FlutterViewController>& owner_controller) {
|
|
||||||
FML_DCHECK(task_runners_.GetPlatformTaskRunner()->RunsTasksOnCurrentThread());
|
FML_DCHECK(task_runners_.GetPlatformTaskRunner()->RunsTasksOnCurrentThread());
|
||||||
std::lock_guard<std::mutex> guard(ios_surface_mutex_);
|
std::lock_guard<std::mutex> guard(ios_surface_mutex_);
|
||||||
if (ios_surface_ || !owner_controller) {
|
if (ios_surface_ || !owner_controller) {
|
||||||
@ -91,17 +92,17 @@ void PlatformViewIOS::SetOwnerViewController(
|
|||||||
|
|
||||||
// Add an observer that will clear out the owner_controller_ ivar and
|
// Add an observer that will clear out the owner_controller_ ivar and
|
||||||
// the accessibility_bridge_ in case the view controller is deleted.
|
// the accessibility_bridge_ in case the view controller is deleted.
|
||||||
dealloc_view_controller_observer_.reset(
|
dealloc_view_controller_observer_.reset([[NSNotificationCenter defaultCenter]
|
||||||
[[[NSNotificationCenter defaultCenter] addObserverForName:FlutterViewControllerWillDealloc
|
addObserverForName:FlutterViewControllerWillDealloc
|
||||||
object:owner_controller_.get()
|
object:owner_controller_
|
||||||
queue:[NSOperationQueue mainQueue]
|
queue:[NSOperationQueue mainQueue]
|
||||||
usingBlock:^(NSNotification* note) {
|
usingBlock:^(NSNotification* note) {
|
||||||
// Implicit copy of 'this' is fine.
|
// Implicit copy of 'this' is fine.
|
||||||
accessibility_bridge_.Clear();
|
accessibility_bridge_.Clear();
|
||||||
owner_controller_.reset();
|
owner_controller_ = nil;
|
||||||
}] retain]);
|
}]);
|
||||||
|
|
||||||
if (owner_controller_ && [owner_controller_.get() isViewLoaded]) {
|
if (owner_controller_ && owner_controller_.isViewLoaded) {
|
||||||
this->attachView();
|
this->attachView();
|
||||||
}
|
}
|
||||||
// Do not call `NotifyCreated()` here - let FlutterViewController take care
|
// Do not call `NotifyCreated()` here - let FlutterViewController take care
|
||||||
@ -112,17 +113,16 @@ void PlatformViewIOS::SetOwnerViewController(
|
|||||||
|
|
||||||
void PlatformViewIOS::attachView() {
|
void PlatformViewIOS::attachView() {
|
||||||
FML_DCHECK(owner_controller_);
|
FML_DCHECK(owner_controller_);
|
||||||
FML_DCHECK(owner_controller_.get().isViewLoaded)
|
FML_DCHECK(owner_controller_.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);
|
FlutterView* flutter_view = static_cast<FlutterView*>(owner_controller_.view);
|
||||||
auto ca_layer = fml::scoped_nsobject<CALayer>{[[flutter_view layer] retain]};
|
auto ca_layer = fml::scoped_nsobject<CALayer>{[flutter_view layer]};
|
||||||
ios_surface_ = IOSSurface::Create(ios_context_, ca_layer);
|
ios_surface_ = IOSSurface::Create(ios_context_, ca_layer);
|
||||||
FML_DCHECK(ios_surface_ != nullptr);
|
FML_DCHECK(ios_surface_ != nullptr);
|
||||||
|
|
||||||
if (accessibility_bridge_) {
|
if (accessibility_bridge_) {
|
||||||
accessibility_bridge_.Set(std::make_unique<AccessibilityBridge>(
|
accessibility_bridge_.Set(std::make_unique<AccessibilityBridge>(
|
||||||
owner_controller_.get(), this, [owner_controller_.get() platformViewsController]));
|
owner_controller_, this, owner_controller_.platformViewsController));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ PointerDataDispatcherMaker PlatformViewIOS::GetDispatcherMaker() {
|
|||||||
void PlatformViewIOS::RegisterExternalTexture(int64_t texture_id,
|
void PlatformViewIOS::RegisterExternalTexture(int64_t texture_id,
|
||||||
NSObject<FlutterTexture>* texture) {
|
NSObject<FlutterTexture>* texture) {
|
||||||
RegisterTexture(ios_context_->CreateExternalTexture(
|
RegisterTexture(ios_context_->CreateExternalTexture(
|
||||||
texture_id, fml::scoped_nsobject<NSObject<FlutterTexture>>{[texture retain]}));
|
texture_id, fml::scoped_nsobject<NSObject<FlutterTexture>>{texture}));
|
||||||
}
|
}
|
||||||
|
|
||||||
// |PlatformView|
|
// |PlatformView|
|
||||||
@ -174,7 +174,7 @@ void PlatformViewIOS::SetSemanticsEnabled(bool enabled) {
|
|||||||
}
|
}
|
||||||
if (enabled && !accessibility_bridge_) {
|
if (enabled && !accessibility_bridge_) {
|
||||||
accessibility_bridge_.Set(std::make_unique<AccessibilityBridge>(
|
accessibility_bridge_.Set(std::make_unique<AccessibilityBridge>(
|
||||||
owner_controller_.get(), this, [owner_controller_.get() platformViewsController]));
|
owner_controller_, this, owner_controller_.platformViewsController));
|
||||||
} else if (!enabled && accessibility_bridge_) {
|
} else if (!enabled && accessibility_bridge_) {
|
||||||
accessibility_bridge_.Clear();
|
accessibility_bridge_.Clear();
|
||||||
} else {
|
} else {
|
||||||
@ -194,7 +194,7 @@ void PlatformViewIOS::UpdateSemantics(flutter::SemanticsNodeUpdates update,
|
|||||||
if (accessibility_bridge_) {
|
if (accessibility_bridge_) {
|
||||||
accessibility_bridge_.get()->UpdateSemantics(std::move(update), actions);
|
accessibility_bridge_.get()->UpdateSemantics(std::move(update), actions);
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:FlutterSemanticsUpdateNotification
|
[[NSNotificationCenter defaultCenter] postNotificationName:FlutterSemanticsUpdateNotification
|
||||||
object:owner_controller_.get()];
|
object:owner_controller_];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,8 +210,8 @@ void PlatformViewIOS::OnPreEngineRestart() const {
|
|||||||
if (!owner_controller_) {
|
if (!owner_controller_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
[owner_controller_.get() platformViewsController]->Reset();
|
owner_controller_.platformViewsController->Reset();
|
||||||
[[owner_controller_.get() restorationPlugin] reset];
|
[owner_controller_.restorationPlugin reset];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<std::vector<std::string>> PlatformViewIOS::ComputePlatformResolvedLocales(
|
std::unique_ptr<std::vector<std::string>> PlatformViewIOS::ComputePlatformResolvedLocales(
|
||||||
@ -253,7 +253,6 @@ PlatformViewIOS::ScopedObserver::ScopedObserver() {}
|
|||||||
PlatformViewIOS::ScopedObserver::~ScopedObserver() {
|
PlatformViewIOS::ScopedObserver::~ScopedObserver() {
|
||||||
if (observer_) {
|
if (observer_) {
|
||||||
[[NSNotificationCenter defaultCenter] removeObserver:observer_];
|
[[NSNotificationCenter defaultCenter] removeObserver:observer_];
|
||||||
[observer_ release];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,7 +260,6 @@ void PlatformViewIOS::ScopedObserver::reset(id<NSObject> observer) {
|
|||||||
if (observer != observer_) {
|
if (observer != observer_) {
|
||||||
if (observer_) {
|
if (observer_) {
|
||||||
[[NSNotificationCenter defaultCenter] removeObserver:observer_];
|
[[NSNotificationCenter defaultCenter] removeObserver:observer_];
|
||||||
[observer_ release];
|
|
||||||
}
|
}
|
||||||
observer_ = observer;
|
observer_ = observer;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user