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

Conversation

@cbracken
Copy link
Member

@cbracken cbracken commented Nov 5, 2024

Migrates DarwinContextMetal to a plain C struct, eliminating the need for constructor, getters, etc. since it's only used in this translation unit. The fields themselves cannot be inlined as fields on ShellTestPlatformViewMetal because the header in which that class is defined is included in plain C++ (non-Obj-C++) translation units and therefore cannot contain Obj-C types.

This simplifies the code and simultaneously fixes complicated ARC behaviour in which the const "DarwinContextMetal::context()" getter caused retainCount to be incremented on the underlying context_ pointer, but not decremented even if never unassigned. In particular the line

FML_CHECK([metal_context->context() mainContext]));

appeared to cause refcount to be incremented but never decremented.

Regardless of the ARC issue, this significantly simplifies the code.

This also eliminates the last remaining use of fml::scoped_nsobject in Flutter's codebase. That class will be removed in a followup PR.

No test changes since there is no change to semantics.

Issue: 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.

@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, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!).

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. The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

Migrates DarwinContextMetal to a plain C struct, eliminating the need
for constructor, getters, etc. since it's only used in this translation
unit. The fields themselves cannot be inlined as fields on
ShellTestPlatformViewMetal because the header in which that class is
defined is included in plain C++ (non-Obj-C++) translation units and
therefore cannot contain Obj-C types.

This simplifies the code and simultaneously fixes complicated ARC
behaviour in which the const "DarwinContextMetal::context()" getter
caused refcount to be incremented on the underlying context_ pointer,
but not decremented even if never unassigned. In particular the line
```objc
FML_CHECK([metal_context->context() mainContext]));
```
appeared to cause refcount to be incremented but never decremented.

Regardless of the ARC issue, this significantly simplifies the code.

This also eliminates the last remaining use of fml::scoped_nsobject in
Flutter's codebase. That class will be removed in a followup PR.

Issue: flutter/flutter#137801
@cbracken cbracken requested a review from hellohuanlin November 5, 2024 04:52
vsync_clock_(std::move(vsync_clock)),
shell_test_external_view_embedder_(std::move(shell_test_external_view_embedder)) {
if (GetSettings().enable_impeller) {
FML_CHECK([metal_context_->impeller_context() context] != nil);
Copy link
Member Author

@cbracken cbracken Nov 5, 2024

Choose a reason for hiding this comment

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

[impeller_context context] and [skia_context context] here and below was an sk_sp, not a plain Obj-C pointer. I don't see any implicit type conversion operators defined in there but that type does implement operator bool() so using that instead for the sanity of readers.

impeller ? [[FlutterDarwinContextMetalImpeller alloc] init:is_gpu_disabled_sync_switch]
: nil),
offscreen_texture_(CreateOffscreenTexture(
impeller ? [impeller_context_ context]->GetMTLDevice() : [context_ device])) {}
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 is now done in the static CreateDarwinContext func above, which inlines CreateOffscreenTexture since it was only used here.

None of the rest of the getter boilerplate is necessary.

// non-Objective-C TUs.
struct DarwinContextMetal {
FlutterDarwinContextMetalSkia* skia_context;
FlutterDarwinContextMetalImpeller* impeller_context;
Copy link
Member Author

Choose a reason for hiding this comment

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

Could this have been a union or std::variant? Yes. But we're going to delete the skia backend eventually anyway, so may as well avoid the extra complexity and make life easy on the person who deletes it.

Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

RSLGTM

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

I agree this should be a std::variant instead, but also that adding the complexity at this point isn't warranted.

@cbracken cbracken added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 5, 2024
@stuartmorgan-g
Copy link
Contributor

test-exempt: code refactor with no semantic change

@auto-submit auto-submit bot merged commit 0342d1d into flutter:main Nov 5, 2024
30 checks passed
@cbracken cbracken deleted the arc-shell-test-platform-view-metal branch November 5, 2024 18:32
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 5, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 5, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 5, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 5, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Nov 6, 2024
…158218)

flutter/engine@e5e06c9...a3741d6

2024-11-05 [email protected] Increase timeouts for Linux Fuchsia and Linux Web Framework Tests builders (flutter/engine#56387)
2024-11-05 [email protected] iOS: Use standard Obj-C cflags for ios_test_flutter (flutter/engine#56384)
2024-11-05 [email protected] Remove unnecessary method for getting engine switches (command line). (flutter/engine#56265)
2024-11-05 [email protected] Remove FlScrollingViewDelegate (flutter/engine#56270)
2024-11-05 [email protected] fml: delete scoped_nsobject.h,mm (flutter/engine#56382)
2024-11-05 [email protected] Roll Skia from b3be9cb59fe8 to 82175b411c80 (2 revisions) (flutter/engine#56383)
2024-11-05 [email protected] [Impeller] Delete any remaining GL objects during destruction of the ReactorGLES (flutter/engine#56361)
2024-11-05 [email protected] [web] Switch all fonts to WOFF2 (non-split) (flutter/engine#56035)
2024-11-05 [email protected] [Impeller] exploit content context options' perfect hash function. (flutter/engine#56360)
2024-11-05 [email protected] Roll Skia from 7989f782dbf4 to b3be9cb59fe8 (6 revisions) (flutter/engine#56380)
2024-11-05 [email protected] Roll Dart SDK from b39c729740eb to 3e840340c412 (1 revision) (flutter/engine#56377)
2024-11-05 [email protected] [Impeller] match Skia's old VMA default block size. (flutter/engine#56368)
2024-11-05 [email protected] iOS: Refactor ShellTestPlatformViewMetal (flutter/engine#56370)
2024-11-05 [email protected] Roll Fuchsia Linux SDK from amgHXcqtplha8LuI_... to z1otZzn3yKuGnu1st... (flutter/engine#56374)

Also rolling transitive DEPS:
  fuchsia/sdk/core/linux-amd64 from amgHXcqtplha to z1otZzn3yKuG

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] 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
nick9822 pushed a commit to nick9822/flutter that referenced this pull request Dec 18, 2024
Migrates DarwinContextMetal to a plain C struct, eliminating the need for constructor, getters, etc. since it's only used in this translation unit. The fields themselves cannot be inlined as fields on ShellTestPlatformViewMetal because the header in which that class is defined is included in plain C++ (non-Obj-C++) translation units and therefore cannot contain Obj-C types.

This simplifies the code and simultaneously fixes complicated ARC behaviour in which the const "DarwinContextMetal::context()" getter caused retainCount to be incremented on the underlying context_ pointer, but not decremented even if never unassigned. In particular the line
```objc
FML_CHECK([metal_context->context() mainContext]));
```
appeared to cause refcount to be incremented but never decremented.

Regardless of the ARC issue, this significantly simplifies the code.

This also eliminates the last remaining use of fml::scoped_nsobject in Flutter's codebase. That class will be removed in a followup PR.

No test changes since there is no change to semantics.

Issue: flutter#137801

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants