Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Migrate vsync_waiter_ios to ARC #52104

Merged
merged 2 commits into from
Apr 16, 2024
Merged

Conversation

jmagman
Copy link
Member

@jmagman jmagman commented Apr 13, 2024

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

Migrate vsync_waiter_ios from MRC to ARC.

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 Apr 13, 2024
Comment on lines +142 to +143
// VSyncClient has released the CADisplayLink.
XCTAssertNil(weakLink);
Copy link
Member Author

Choose a reason for hiding this comment

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

This doesn't currently pass on main with the current code.

}
callback_(std::move(recorder));
}

- (void)invalidate {
[display_link_.get() invalidate];
[_displayLink invalidate];
_displayLink = nil; // Break retain cycle.
Copy link
Member Author

Choose a reason for hiding this comment

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

The test I wrote to validate the display link is released when VSyncClient invalidates and deallocs doesn't pass without this line (and also doesn't pass on main with the current code).

@@ -130,40 +123,37 @@ - (void)onDisplayLink:(CADisplayLink*)link {

recorder->RecordVsync(frame_start_time, frame_target_time);
if (_allowPauseAfterVsync) {
display_link_.get().paused = YES;
link.paused = YES;
Copy link
Member Author

Choose a reason for hiding this comment

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

Use link passed into onDisplayLink: instead of grabbing it again.

@jmagman jmagman marked this pull request as ready for review April 13, 2024 22:48
}

} // namespace flutter

@implementation VSyncClient {
flutter::VsyncWaiter::Callback callback_;
fml::scoped_nsobject<CADisplayLink> display_link_;
CADisplayLink* _displayLink;
double current_refresh_rate_;
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional, but maybe fix the other two names while you are here so they aren't inconsistent?

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.

// Strongly retain the the captured link until it is added to the runloop.
CADisplayLink* localDisplayLink = _displayLink;
task_runner->PostTask([localDisplayLink]() {
[localDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional modernization nit: NSRunLoop.currentRunLoop since it's a property.

Copy link
Member Author

Choose a reason for hiding this comment

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

Did a sweep of this file for dot notation and other property cleanup. Moved refreshRate off the header since it's only used in the implementation file and made it a readonly property, and made displayRefreshRate a class property.

}
callback_(std::move(recorder));
}

- (void)invalidate {
[display_link_.get() invalidate];
[_displayLink invalidate];
_displayLink = nil; // Break retain cycle.
}

- (void)dealloc {
Copy link
Contributor

@stuartmorgan-g stuartmorgan-g Apr 13, 2024

Choose a reason for hiding this comment

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

I would remove this method; it's basically a lie (and was before as well). The display link has a strong reference to this object, so it's impossible† for dealloc to be called unless the display link has already been invalidated.

† Unless there's an overrelease, of course, but then we have other problems.

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 removed it and added a comment to -invalidate in the header.

@jmagman jmagman force-pushed the vsync_waiter_ios-arc branch from 083937b to 08f4b22 Compare April 15, 2024 19:28
Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

LGTM

@jmagman jmagman force-pushed the vsync_waiter_ios-arc branch from 08f4b22 to 7fcab77 Compare April 16, 2024 04:04
@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 ae00c28 into flutter:main Apr 16, 2024
@jmagman jmagman deleted the vsync_waiter_ios-arc branch April 16, 2024 06:55
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 16, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 16, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Apr 16, 2024
…146811)

flutter/engine@66ad802...cba7678

2024-04-16 [email protected] Roll Dart SDK from 7d02f18b8a84 to cb0c34389d90 (1 revision) (flutter/engine#52151)
2024-04-16 [email protected] Roll Skia from 50ac1117f159 to 8013b7f1dcd3 (5 revisions) (flutter/engine#52149)
2024-04-16 49699333+dependabot[bot]@users.noreply.github.com Bump google/osv-scanner-action from 1.6.2.pre.beta1 to 1.7.1 (flutter/engine#52147)
2024-04-16 [email protected] Migrate vsync_waiter_ios to ARC (flutter/engine#52104)
2024-04-16 [email protected] Roll Skia from b159229f2174 to 50ac1117f159 (1 revision) (flutter/engine#52146)
2024-04-16 [email protected] Roll Dart SDK from 5f03197b9992 to 7d02f18b8a84 (2 revisions) (flutter/engine#52145)

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 [email protected],[email protected],[email protected] 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#146811)

flutter/engine@66ad802...cba7678

2024-04-16 [email protected] Roll Dart SDK from 7d02f18b8a84 to cb0c34389d90 (1 revision) (flutter/engine#52151)
2024-04-16 [email protected] Roll Skia from 50ac1117f159 to 8013b7f1dcd3 (5 revisions) (flutter/engine#52149)
2024-04-16 49699333+dependabot[bot]@users.noreply.github.com Bump google/osv-scanner-action from 1.6.2.pre.beta1 to 1.7.1 (flutter/engine#52147)
2024-04-16 [email protected] Migrate vsync_waiter_ios to ARC (flutter/engine#52104)
2024-04-16 [email protected] Roll Skia from b159229f2174 to 50ac1117f159 (1 revision) (flutter/engine#52146)
2024-04-16 [email protected] Roll Dart SDK from 5f03197b9992 to 7d02f18b8a84 (2 revisions) (flutter/engine#52145)

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 [email protected],[email protected],[email protected] 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 subscribe to this conversation on GitHub. Already have an account? Sign in.
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