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 FlutterView, FlutterPlatformViews, FlutterOverlayView to ARC #52535

Merged
merged 3 commits into from
May 10, 2024

Conversation

jmagman
Copy link
Member

@jmagman jmagman commented May 2, 2024

Smart pointers support ARC as of #47612, and the unit tests were migrated in #48162.

Migrate FlutterView, FlutterPlatformViews, and FlutterOverlayView from MRC to ARC.

Part of flutter/flutter#137801.

@@ -87,6 +92,9 @@ source_set("flutter_framework_source_arc") {
"framework/Source/FlutterUndoManagerDelegate.h",
"framework/Source/FlutterUndoManagerPlugin.h",
"framework/Source/FlutterUndoManagerPlugin.mm",
"framework/Source/FlutterView.h",
"framework/Source/FlutterView.mm",
"framework/Source/FlutterViewResponder.h",
Copy link
Member Author

Choose a reason for hiding this comment

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

FlutterViewResponder.h wasn't included anywhere?

@@ -210,16 +210,19 @@ class FlutterPlatformViewsController {

fml::WeakPtr<flutter::FlutterPlatformViewsController> GetWeakPtr();

void SetFlutterView(UIView* flutter_view);
void SetFlutterView(UIView* flutter_view) __attribute__((cf_audited_transfer));
Copy link
Member Author

Choose a reason for hiding this comment

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

See cf_audited_transfer discussion #52226 (comment)

@@ -99,6 +100,7 @@
0AC232E924BA71D300A85907 /* Source */ = {
isa = PBXGroup;
children = (
F76A3A892BE48F2F00A654F1 /* FlutterPlatformViewsTest.mm */,
Copy link
Member Author

Choose a reason for hiding this comment

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

Just a convenience to add it here, the test dylib made from BUILD.gn already built it.

auto-submit bot pushed a commit that referenced this pull request May 8, 2024
I found this while migrating `FlutterPlatformViews_Internal.mm` to ARC #52535.  I'll land this first.

```objc
  if (_backdropFilterView != visualEffectView) {
    _backdropFilterView = [visualEffectView retain];
  }
```
should instead be something like:
```objc
  if (_backdropFilterView != visualEffectView) {
    id oldBackdropFilterView = _backdropFilterView;
    _backdropFilterView = [visualEffectView retain];
    [oldBackdropFilterView release];
  }
```
But that's already what the built-in MRC `nonatomic, retain` property setter does, so use that instead.

Added a test that passes on this PR and fails on main.
- (void)dealloc {
[_flutterAccessibilityContainer release];
[super dealloc];
return self.flutterAccessibilityContainer;
Copy link
Member Author

Choose a reason for hiding this comment

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

@tacck can you double-check me here re: #52484 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's LGTM!

UIView* _embeddedView;
}
@interface FlutterTouchInterceptingView ()
@property(nonatomic, weak, readonly) UIView* embeddedView;
Copy link
Member Author

Choose a reason for hiding this comment

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

Not retained:

@property(nonatomic) bool touchedEndedWithoutBlocking;
@property(nonatomic) BOOL touchedEndedWithoutBlocking;

@property(nonatomic, readonly) UIGestureRecognizer* forwardingRecognizer;
Copy link
Member Author

Choose a reason for hiding this comment

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

Swapping from scoped_nsobject to a property.

@implementation DelayingGestureRecognizer {
fml::scoped_nsobject<UIGestureRecognizer> _forwardingRecognizer;
}

}
@interface FlutterTouchInterceptingView ()
@property(nonatomic, weak, readonly) UIView* embeddedView;
@property(nonatomic, readonly) DelayingGestureRecognizer* delayingRecognizer;
Copy link
Member Author

Choose a reason for hiding this comment

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

Swapping from scoped_nsobject to a property.

fml::scoped_nsobject<DelayingGestureRecognizer> _delayingRecognizer;

@property(retain, nonatomic) NSArray<PlatformViewFilter*>* filters;
@property(retain, nonatomic) NSMutableArray<UIVisualEffectView*>* backdropFilterSubviews;
@property(nonatomic, copy) NSArray<PlatformViewFilter*>* filters;
@property(nonatomic) NSMutableArray<UIVisualEffectView*>* backdropFilterSubviews;
Copy link
Member Author

Choose a reason for hiding this comment

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

Mutable collection, strong


// The pool contains the views that are available to use.
// The number of items in the pool must not excceds `capacity`.
@property(retain, nonatomic) NSMutableSet<FlutterClippingMaskView*>* pool;
@property(nonatomic) NSMutableSet<FlutterClippingMaskView*>* pool;
Copy link
Member Author

Choose a reason for hiding this comment

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

Mutable collection, strong

FLUTTER_ASSERT_ARC

@interface FlutterView ()
@property(nonatomic, weak) id<FlutterViewEngineDelegate> delegate;
Copy link
Member Author

Choose a reason for hiding this comment

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

Not retained

@@ -417,7 +416,7 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,

long FlutterPlatformViewsController::FindFirstResponderPlatformViewId() {
for (auto const& [id, root_view] : root_views_) {
if ((UIView*)(root_view.get()).flt_hasFirstResponderInViewHierarchySubtree) {
if (((UIView*)root_view.get()).flt_hasFirstResponderInViewHierarchySubtree) {
Copy link
Member Author

@jmagman jmagman May 10, 2024

Choose a reason for hiding this comment

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

error: cast of 'BOOL' (aka 'bool') to 'UIView *' is disallowed with ARC

../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm:419:9: error: cast of 'BOOL' (aka 'bool') to 'UIView *' is disallowed with ARC
  419 |     if ((UIView*)(root_view.get()).flt_hasFirstResponderInViewHierarchySubtree) {
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

This was somehow working before?

XCTAssertTrue(textField.isFirstResponder);
XCTAssertTrue(textField.flt_hasFirstResponderInViewHierarchySubtree);
[textField resignFirstResponder];
XCTAssertFalse(textField.isFirstResponder);
XCTAssertFalse(textField.flt_hasFirstResponderInViewHierarchySubtree);

#33093

Copy link
Contributor

Choose a reason for hiding this comment

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

weird

@jmagman jmagman marked this pull request as ready for review May 10, 2024 17:00
@@ -417,7 +416,7 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,

long FlutterPlatformViewsController::FindFirstResponderPlatformViewId() {
for (auto const& [id, root_view] : root_views_) {
if ((UIView*)(root_view.get()).flt_hasFirstResponderInViewHierarchySubtree) {
if (((UIView*)root_view.get()).flt_hasFirstResponderInViewHierarchySubtree) {
Copy link
Contributor

Choose a reason for hiding this comment

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

weird

@jmagman jmagman merged commit f553caa into flutter:main May 10, 2024
26 checks passed
@jmagman jmagman deleted the flutter-view-arc branch May 10, 2024 19:07
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 10, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 10, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request May 10, 2024
…148147)

flutter/engine@d4f705c...ba8e0d3

2024-05-10 1961493+harryterkelsen@users.noreply.github.com [canvaskit] Clip before applying ColorFilter so it doesn't filter beyond child bounds (flutter/engine#52704)
2024-05-10 magder@google.com Migrate FlutterView, FlutterPlatformViews, FlutterOverlayView to ARC (flutter/engine#52535)
2024-05-10 matanlurey@users.noreply.github.com Infer `--rbe` based on the existence of `//flutter/build/rbe` (flutter/engine#52700)
2024-05-10 jonahwilliams@google.com [Impeller] Disable AHB swapchain. (flutter/engine#52713)
2024-05-10 skia-flutter-autoroll@skia.org Roll Skia from c7cd1e9690d1 to 11d892ce49b6 (25 revisions) (flutter/engine#52712)
2024-05-10 chinmaygarde@google.com [Impeller] Document how to do basic rendering in Impeller. (flutter/engine#52703)
2024-05-10 30870216+gaaclarke@users.noreply.github.com [impeller] adds experimental canvas docstring (flutter/engine#52710)
2024-05-10 daniel.l@hpcnt.com Roll third_party/freetype2 from 3bea27612 to af4c2d86d (2 revisions) (flutter/engine#52689)

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 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants