Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate FlutterUIPressProxy, ios_context*, rendering_api_selection, and a few other files to ARC #51633

Merged
merged 5 commits into from
Apr 16, 2024

Conversation

jmagman
Copy link
Member

@jmagman jmagman commented Mar 22, 2024

Smart pointers support ARC as of #47612, and the unit tests were migrated in #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 flutter/flutter#137801.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@jmagman jmagman self-assigned this Mar 22, 2024
Comment on lines 27 to 24
if (@available(iOS METAL_IOS_VERSION_BASELINE, *)) {
auto device = MTLCreateSystemDefaultDevice();
ios_version_supports_metal = [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily1_v3];
[device release];
Copy link
Member Author

@jmagman jmagman Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kicked off a yak shave to remove this code by removing SHELL_ENABLE_METAL

https://github.com/flutter/engine/pull/51636/files#diff-1db60a8a74c1cfb40c970541dd1f7f0f6301853a2ba17451f5117f154036d732L27

I'll let that merge and then rebase this on top.

@jmagman jmagman marked this pull request as ready for review April 9, 2024 04:21
@@ -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 "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this order change? Does the engine not follow the suggested style guide header order where framework imports are before non-associated-header project imports?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seem to be many places in the engine that don't follow the guidelines. In this case I believe I should have made it:

#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterUIPressProxy.h"

#import <UIKit/UIKit.h>

#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"

#import <UIKit/UIKit.h>

#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterUIPressProxy.h"
FLUTTER_ASSERT_ARC

@interface FlutterUIPressProxy ()
@property(nonatomic, readonly) UIPress* press;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were these properties accidentally weak before and it just hadn't happened to break anything?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess? The usages look like this:

[self handlePressEvent:[[[FlutterUIPressProxy alloc] initWithPress:press
withEvent:event] autorelease]
nextAction:^() {
[super pressesBegan:[NSSet setWithObject:press] withEvent:event];
}];

so maybe press and event are being retained in the nextAction block? I don't see any obvious bugs about it...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting - yeah seems like this should previously have been explicitly strong, and maybe worked because (I assume) it's retained in that map we create to pointer events being sent to the framework until we get a response? (Didn't look but IIRC we hold onto them there)

fml::scoped_nsobject<FlutterDarwinExternalTextureMetal>{
[[darwin_context_metal_impeller_ createExternalTextureWithIdentifier:texture_id
texture:texture] retain]});
fml::scoped_nsobject<FlutterDarwinExternalTextureMetal>{[darwin_context_metal_impeller_
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need the scoped_nsobject here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally the answer should be no, but since scoped_nsobject is ARC-friendly, we should be safe to do those in a followup patch if preferred.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ios_context_->CreateExternalTexture is only called from mrc platform_view_ios:

RegisterTexture(ios_context_->CreateExternalTexture(
texture_id, fml::scoped_nsobject<NSObject<FlutterTexture>>{[texture retain]}));

I'm going to hold off on removing scoped_nsobject from this signature until I can remove it there as well. Do you foresee any issues with that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fine to keep scoped_nsobjects since we have the multi-mode compliant version.

@@ -52,8 +54,7 @@
fml::scoped_nsobject<NSObject<FlutterTexture>> texture) {
return std::make_unique<IOSExternalTextureMetal>(
fml::scoped_nsobject<FlutterDarwinExternalTextureMetal>{
[[darwin_context_metal_ createExternalTextureWithIdentifier:texture_id
texture:texture] retain]});
[darwin_context_metal_ createExternalTextureWithIdentifier:texture_id texture:texture]});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here.

@@ -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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we convert this scoped_nsobject to a simple Obj-C object property now?

@jmagman jmagman force-pushed the migrate-simple-arc branch 2 times, most recently from 59c56fd to 608bf8c Compare April 13, 2024 03:42
Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. Whether or not you prefer to deal with scoped_nsojbect in this patch or a followup, either way seems fine to me.

fml::scoped_nsobject<FlutterDarwinExternalTextureMetal>{
[[darwin_context_metal_impeller_ createExternalTextureWithIdentifier:texture_id
texture:texture] retain]});
fml::scoped_nsobject<FlutterDarwinExternalTextureMetal>{[darwin_context_metal_impeller_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally the answer should be no, but since scoped_nsobject is ARC-friendly, we should be safe to do those in a followup patch if preferred.

#import <UIKit/UIKit.h>

#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterUIPressProxy.h"
FLUTTER_ASSERT_ARC

@interface FlutterUIPressProxy ()
@property(nonatomic, readonly) UIPress* press;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting - yeah seems like this should previously have been explicitly strong, and maybe worked because (I assume) it's retained in that map we create to pointer events being sent to the framework until we get a response? (Didn't look but IIRC we hold onto them there)

@@ -25,8 +25,6 @@ class IOSContextMetalImpeller final : public IOSContext {

~IOSContextMetalImpeller();

fml::scoped_nsobject<FlutterDarwinContextMetalSkia> GetDarwinContext() const;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Hmm, why is IOSContextMetalImpeller returning FlutterDarwinContextMetalSkia?"
It's dead code.

@jmagman jmagman changed the title Migrate a few manually reference counted iOS files that do not import any other MRC files to ARC Migrate FlutterUIPressProxy, ios_context*, rendering_api_selection, and a few other files to ARC Apr 16, 2024
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

#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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional nit: I don't think this meets the style guide guidance on auto, since I couldn't tell what the type was; I would give this an explicit type instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@jmagman jmagman added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 16, 2024
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Apr 16, 2024
Copy link
Contributor

auto-submit bot commented Apr 16, 2024

auto label is removed for flutter/engine/51633, due to - The status or check suite Mac mac_unopt has failed. Please fix the issues identified (or deflake) before re-applying this label.

@jmagman jmagman added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 16, 2024
@auto-submit auto-submit bot merged commit 0e9ba75 into flutter:main Apr 16, 2024
32 checks passed
@jmagman jmagman deleted the migrate-simple-arc branch April 16, 2024 21:46
auto-submit bot pushed a commit that referenced this pull request Apr 16, 2024
…#52148)

Clean up headers in FlutterChannelKeyResponder and FlutterSpellCheckPlugin.  Migrate to ARC.

Move `FlutterSpellCheckResult` interface into the .mm since it's only used there.

Part of flutter/flutter#137801.
Blocked by #51633 `FlutterUIPressProxy`
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 16, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 17, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Apr 17, 2024
…146857)

flutter/engine@4d69c0c...e7d8c62

2024-04-16 magder@google.com Migrate FlutterChannelKeyResponder and FlutterSpellCheckPlugin to ARC (flutter/engine#52148)
2024-04-16 skia-flutter-autoroll@skia.org Roll Skia from b83b6bf7174f to e335a0a11aa0 (1 revision) (flutter/engine#52175)
2024-04-16 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[Impeller] remove most temporary allocation during polyline generation. (#52131)" (flutter/engine#52177)
2024-04-16 skia-flutter-autoroll@skia.org Roll Skia from d506a3d526f7 to b83b6bf7174f (2 revisions) (flutter/engine#52173)
2024-04-16 magder@google.com Migrate FlutterUIPressProxy, ios_context*, rendering_api_selection, and a few other files to ARC (flutter/engine#51633)
2024-04-16 skia-flutter-autoroll@skia.org Roll Skia from 98dbba281a84 to d506a3d526f7 (2 revisions) (flutter/engine#52170)
2024-04-16 skia-flutter-autoroll@skia.org Roll Dart SDK from f2464b2892a1 to 57d7cba5bc3d (1 revision) (flutter/engine#52168)
2024-04-16 skia-flutter-autoroll@skia.org Roll Skia from 300741074b41 to 98dbba281a84 (11 revisions) (flutter/engine#52167)
2024-04-16 30870216+gaaclarke@users.noreply.github.com [Impeller] removes advanced plus blending (flutter/engine#52163)
2024-04-16 jonahwilliams@google.com [Impeller] remove most temporary allocation during polyline generation. (flutter/engine#52131)
2024-04-16 jason-simmons@users.noreply.github.com Roll reclient, libpng, and zlib (flutter/engine#52072)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC jsimmons@google.com,rmistry@google.com,zra@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
gilnobrega pushed a commit to gilnobrega/flutter that referenced this pull request Apr 22, 2024
…lutter#146857)

flutter/engine@4d69c0c...e7d8c62

2024-04-16 magder@google.com Migrate FlutterChannelKeyResponder and FlutterSpellCheckPlugin to ARC (flutter/engine#52148)
2024-04-16 skia-flutter-autoroll@skia.org Roll Skia from b83b6bf7174f to e335a0a11aa0 (1 revision) (flutter/engine#52175)
2024-04-16 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[Impeller] remove most temporary allocation during polyline generation. (flutter#52131)" (flutter/engine#52177)
2024-04-16 skia-flutter-autoroll@skia.org Roll Skia from d506a3d526f7 to b83b6bf7174f (2 revisions) (flutter/engine#52173)
2024-04-16 magder@google.com Migrate FlutterUIPressProxy, ios_context*, rendering_api_selection, and a few other files to ARC (flutter/engine#51633)
2024-04-16 skia-flutter-autoroll@skia.org Roll Skia from 98dbba281a84 to d506a3d526f7 (2 revisions) (flutter/engine#52170)
2024-04-16 skia-flutter-autoroll@skia.org Roll Dart SDK from f2464b2892a1 to 57d7cba5bc3d (1 revision) (flutter/engine#52168)
2024-04-16 skia-flutter-autoroll@skia.org Roll Skia from 300741074b41 to 98dbba281a84 (11 revisions) (flutter/engine#52167)
2024-04-16 30870216+gaaclarke@users.noreply.github.com [Impeller] removes advanced plus blending (flutter/engine#52163)
2024-04-16 jonahwilliams@google.com [Impeller] remove most temporary allocation during polyline generation. (flutter/engine#52131)
2024-04-16 jason-simmons@users.noreply.github.com Roll reclient, libpng, and zlib (flutter/engine#52072)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC jsimmons@google.com,rmistry@google.com,zra@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App platform-ios
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants