From 0e9ba75853b2079630571d5b9f6517b9a7e7f179 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Tue, 16 Apr 2024 14:45:50 -0700 Subject: [PATCH] Migrate FlutterUIPressProxy, ios_context*, rendering_api_selection, and a few other files to ARC (#51633) Smart pointers support ARC as of https://github.com/flutter/engine/pull/47612, and the unit tests were migrated in https://github.com/flutter/engine/pull/48162. Migrate some files from MRC to ARC. These files do not themselves import any MRC files, only ARC-ified files like `FlutterMetalLayer.h`, making them leaf nodes in the dependency graph of MRC files. Just doing a few at a time to make the dependency graph manageable, and to easily revert if this causes retain cycles or other memory management issues. Part of https://github.com/flutter/flutter/issues/137801. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- shell/platform/darwin/ios/BUILD.gn | 48 ++++++++++--------- .../framework/Source/FlutterUIPressProxy.mm | 6 ++- .../framework/Source/connection_collection.mm | 4 ++ .../platform_message_response_darwin.mm | 4 ++ .../framework/Source/profiler_metrics_ios.mm | 3 ++ shell/platform/darwin/ios/ios_context.mm | 2 + .../darwin/ios/ios_context_metal_impeller.h | 2 - .../darwin/ios/ios_context_metal_impeller.mm | 13 ++--- .../darwin/ios/ios_context_metal_skia.mm | 5 +- .../darwin/ios/ios_context_software.mm | 2 + .../darwin/ios/ios_external_texture_metal.mm | 2 + .../darwin/ios/rendering_api_selection.mm | 6 ++- 12 files changed, 59 insertions(+), 38 deletions(-) diff --git a/shell/platform/darwin/ios/BUILD.gn b/shell/platform/darwin/ios/BUILD.gn index 5f97a319f1620..83e5ed10fedaa 100644 --- a/shell/platform/darwin/ios/BUILD.gn +++ b/shell/platform/darwin/ios/BUILD.gn @@ -78,12 +78,32 @@ source_set("flutter_framework_source_arc") { "framework/Source/FlutterTextInputPlugin.mm", "framework/Source/FlutterTextureRegistryRelay.h", "framework/Source/FlutterTextureRegistryRelay.mm", + "framework/Source/FlutterUIPressProxy.h", + "framework/Source/FlutterUIPressProxy.mm", "framework/Source/KeyCodeMap.g.mm", "framework/Source/KeyCodeMap_Internal.h", "framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.h", "framework/Source/UIViewController+FlutterScreenAndSceneIfLoaded.mm", + "framework/Source/connection_collection.h", + "framework/Source/connection_collection.mm", + "framework/Source/platform_message_response_darwin.h", + "framework/Source/platform_message_response_darwin.mm", + "framework/Source/profiler_metrics_ios.h", + "framework/Source/profiler_metrics_ios.mm", "framework/Source/vsync_waiter_ios.h", "framework/Source/vsync_waiter_ios.mm", + "ios_context.h", + "ios_context.mm", + "ios_context_metal_impeller.h", + "ios_context_metal_impeller.mm", + "ios_context_metal_skia.h", + "ios_context_metal_skia.mm", + "ios_context_software.h", + "ios_context_software.mm", + "ios_external_texture_metal.h", + "ios_external_texture_metal.mm", + "rendering_api_selection.h", + "rendering_api_selection.mm", ] frameworks = [ @@ -92,11 +112,16 @@ source_set("flutter_framework_source_arc") { ] 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", ] } @@ -132,8 +157,6 @@ source_set("flutter_framework_source") { "framework/Source/FlutterSemanticsScrollView.mm", "framework/Source/FlutterSpellCheckPlugin.h", "framework/Source/FlutterSpellCheckPlugin.mm", - "framework/Source/FlutterUIPressProxy.h", - "framework/Source/FlutterUIPressProxy.mm", "framework/Source/FlutterUndoManagerDelegate.h", "framework/Source/FlutterUndoManagerPlugin.h", "framework/Source/FlutterUndoManagerPlugin.mm", @@ -147,22 +170,6 @@ source_set("flutter_framework_source") { "framework/Source/accessibility_bridge.mm", "framework/Source/accessibility_text_entry.h", "framework/Source/accessibility_text_entry.mm", - "framework/Source/connection_collection.h", - "framework/Source/connection_collection.mm", - "framework/Source/platform_message_response_darwin.h", - "framework/Source/platform_message_response_darwin.mm", - "framework/Source/profiler_metrics_ios.h", - "framework/Source/profiler_metrics_ios.mm", - "ios_context.h", - "ios_context.mm", - "ios_context_metal_impeller.h", - "ios_context_metal_impeller.mm", - "ios_context_metal_skia.h", - "ios_context_metal_skia.mm", - "ios_context_software.h", - "ios_context_software.mm", - "ios_external_texture_metal.h", - "ios_external_texture_metal.mm", "ios_external_view_embedder.h", "ios_external_view_embedder.mm", "ios_surface.h", @@ -177,8 +184,6 @@ source_set("flutter_framework_source") { "platform_message_handler_ios.mm", "platform_view_ios.h", "platform_view_ios.mm", - "rendering_api_selection.h", - "rendering_api_selection.mm", ] sources += _flutter_framework_headers @@ -191,17 +196,14 @@ source_set("flutter_framework_source") { deps += [ ":ios_gpu_configuration", "//flutter/common", - "//flutter/common/graphics", "//flutter/flow", "//flutter/fml", - "//flutter/lib/ui", "//flutter/runtime", "//flutter/runtime:libdart", "//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/skia", diff --git a/shell/platform/darwin/ios/framework/Source/FlutterUIPressProxy.mm b/shell/platform/darwin/ios/framework/Source/FlutterUIPressProxy.mm index 8c2ad30a452bf..540b6ae0beb99 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterUIPressProxy.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterUIPressProxy.mm @@ -2,9 +2,13 @@ // 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/framework/Source/FlutterUIPressProxy.h" + #import -#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterUIPressProxy.h" +#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h" + +FLUTTER_ASSERT_ARC @interface FlutterUIPressProxy () @property(nonatomic, readonly) UIPress* press; diff --git a/shell/platform/darwin/ios/framework/Source/connection_collection.mm b/shell/platform/darwin/ios/framework/Source/connection_collection.mm index fc9e734109ea6..b52eb17f23dbb 100644 --- a/shell/platform/darwin/ios/framework/Source/connection_collection.mm +++ b/shell/platform/darwin/ios/framework/Source/connection_collection.mm @@ -4,6 +4,10 @@ #import "flutter/shell/platform/darwin/ios/framework/Source/connection_collection.h" +#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h" + +FLUTTER_ASSERT_ARC + namespace flutter { ConnectionCollection::Connection ConnectionCollection::AquireConnection(const std::string& name) { Connection nextConnection = ++counter_; diff --git a/shell/platform/darwin/ios/framework/Source/platform_message_response_darwin.mm b/shell/platform/darwin/ios/framework/Source/platform_message_response_darwin.mm index c823cf3f39bc2..00c155af049ca 100644 --- a/shell/platform/darwin/ios/framework/Source/platform_message_response_darwin.mm +++ b/shell/platform/darwin/ios/framework/Source/platform_message_response_darwin.mm @@ -4,6 +4,10 @@ #import "flutter/shell/platform/darwin/ios/framework/Source/platform_message_response_darwin.h" +#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h" + +FLUTTER_ASSERT_ARC + namespace flutter { PlatformMessageResponseDarwin::PlatformMessageResponseDarwin( diff --git a/shell/platform/darwin/ios/framework/Source/profiler_metrics_ios.mm b/shell/platform/darwin/ios/framework/Source/profiler_metrics_ios.mm index ac04c1183a804..01bb213d12275 100644 --- a/shell/platform/darwin/ios/framework/Source/profiler_metrics_ios.mm +++ b/shell/platform/darwin/ios/framework/Source/profiler_metrics_ios.mm @@ -6,8 +6,11 @@ #import +#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h" #import "flutter/shell/platform/darwin/ios/framework/Source/IOKit.h" +FLUTTER_ASSERT_ARC + namespace { // RAII holder for `thread_array_t` this is so any early returns in diff --git a/shell/platform/darwin/ios/ios_context.mm b/shell/platform/darwin/ios/ios_context.mm index 2a5fd7bc5de15..07d55a2cb9fc3 100644 --- a/shell/platform/darwin/ios/ios_context.mm +++ b/shell/platform/darwin/ios/ios_context.mm @@ -10,6 +10,8 @@ #include "flutter/shell/platform/darwin/ios/ios_context_metal_skia.h" #include "flutter/shell/platform/darwin/ios/ios_context_software.h" +FLUTTER_ASSERT_ARC + namespace flutter { IOSContext::IOSContext(MsaaSampleCount msaa_samples) : msaa_samples_(msaa_samples) {} diff --git a/shell/platform/darwin/ios/ios_context_metal_impeller.h b/shell/platform/darwin/ios/ios_context_metal_impeller.h index 10d9ca0c0ae28..5e2ed7a32dee9 100644 --- a/shell/platform/darwin/ios/ios_context_metal_impeller.h +++ b/shell/platform/darwin/ios/ios_context_metal_impeller.h @@ -25,8 +25,6 @@ class IOSContextMetalImpeller final : public IOSContext { ~IOSContextMetalImpeller(); - fml::scoped_nsobject GetDarwinContext() const; - IOSRenderingBackend GetBackend() const override; // |IOSContext| diff --git a/shell/platform/darwin/ios/ios_context_metal_impeller.mm b/shell/platform/darwin/ios/ios_context_metal_impeller.mm index 6d4cfdddb76e4..146980c341746 100644 --- a/shell/platform/darwin/ios/ios_context_metal_impeller.mm +++ b/shell/platform/darwin/ios/ios_context_metal_impeller.mm @@ -6,6 +6,8 @@ #include "flutter/impeller/entity/mtl/entity_shaders.h" #import "flutter/shell/platform/darwin/ios/ios_external_texture_metal.h" +FLUTTER_ASSERT_ARC + namespace flutter { IOSContextMetalImpeller::IOSContextMetalImpeller( @@ -16,11 +18,6 @@ IOSContextMetalImpeller::~IOSContextMetalImpeller() = default; -fml::scoped_nsobject IOSContextMetalImpeller::GetDarwinContext() - const { - return fml::scoped_nsobject{}; -} - IOSRenderingBackend IOSContextMetalImpeller::GetBackend() const { return IOSRenderingBackend::kImpeller; } @@ -54,9 +51,9 @@ int64_t texture_id, fml::scoped_nsobject> texture) { return std::make_unique( - fml::scoped_nsobject{ - [[darwin_context_metal_impeller_ createExternalTextureWithIdentifier:texture_id - texture:texture] retain]}); + fml::scoped_nsobject{[darwin_context_metal_impeller_ + createExternalTextureWithIdentifier:texture_id + texture:texture]}); } } // namespace flutter diff --git a/shell/platform/darwin/ios/ios_context_metal_skia.mm b/shell/platform/darwin/ios/ios_context_metal_skia.mm index 1a4d8c8ed358e..f58ea7c8db0d9 100644 --- a/shell/platform/darwin/ios/ios_context_metal_skia.mm +++ b/shell/platform/darwin/ios/ios_context_metal_skia.mm @@ -10,6 +10,8 @@ #import "flutter/shell/platform/darwin/ios/ios_external_texture_metal.h" #include "third_party/skia/include/gpu/GrContextOptions.h" +FLUTTER_ASSERT_ARC + namespace flutter { IOSContextMetalSkia::IOSContextMetalSkia(MsaaSampleCount msaa_samples) : IOSContext(msaa_samples) { @@ -52,8 +54,7 @@ fml::scoped_nsobject> texture) { return std::make_unique( fml::scoped_nsobject{ - [[darwin_context_metal_ createExternalTextureWithIdentifier:texture_id - texture:texture] retain]}); + [darwin_context_metal_ createExternalTextureWithIdentifier:texture_id texture:texture]}); } } // namespace flutter diff --git a/shell/platform/darwin/ios/ios_context_software.mm b/shell/platform/darwin/ios/ios_context_software.mm index c58ad6dc93ed8..2c24ce6e158fc 100644 --- a/shell/platform/darwin/ios/ios_context_software.mm +++ b/shell/platform/darwin/ios/ios_context_software.mm @@ -5,6 +5,8 @@ #import "flutter/shell/platform/darwin/ios/ios_context_software.h" #include "ios_context.h" +FLUTTER_ASSERT_ARC + namespace flutter { IOSContextSoftware::IOSContextSoftware() : IOSContext(MsaaSampleCount::kNone) {} diff --git a/shell/platform/darwin/ios/ios_external_texture_metal.mm b/shell/platform/darwin/ios/ios_external_texture_metal.mm index 65171b9186907..4e77bd35b2e66 100644 --- a/shell/platform/darwin/ios/ios_external_texture_metal.mm +++ b/shell/platform/darwin/ios/ios_external_texture_metal.mm @@ -5,6 +5,8 @@ #import "flutter/shell/platform/darwin/ios/ios_external_texture_metal.h" #include "flow/layers/layer.h" +FLUTTER_ASSERT_ARC + namespace flutter { IOSExternalTextureMetal::IOSExternalTextureMetal( diff --git a/shell/platform/darwin/ios/rendering_api_selection.mm b/shell/platform/darwin/ios/rendering_api_selection.mm index b9659796bb9b5..81099d7df1f3f 100644 --- a/shell/platform/darwin/ios/rendering_api_selection.mm +++ b/shell/platform/darwin/ios/rendering_api_selection.mm @@ -12,16 +12,18 @@ #include "flutter/fml/logging.h" +#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h" #include "flutter/shell/platform/darwin/ios/framework/Source/FlutterMetalLayer.h" +FLUTTER_ASSERT_ARC + namespace flutter { bool ShouldUseMetalRenderer() { bool ios_version_supports_metal = false; if (@available(iOS METAL_IOS_VERSION_BASELINE, *)) { - auto device = MTLCreateSystemDefaultDevice(); + id device = MTLCreateSystemDefaultDevice(); ios_version_supports_metal = [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily1_v3]; - [device release]; } return ios_version_supports_metal; }