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

iOS,macOS: Refactor TestMetalContext for ARC #56510

Merged
merged 1 commit into from
Nov 11, 2024

Conversation

cbracken
Copy link
Member

@cbracken cbracken commented Nov 11, 2024

TestMetalContext cannot include any Objective-C types in its header file since that header is included in pure C++ translation units. Previously, we declared these fields as void*, which then requires manual __bridge_retained and __bridge_transfer casts to perform the necessary retain/relase manipulation while opting the object in and out of ARC management.

Instead, we extract these to a struct in the implementation file and allow the fields to be managed by ARC. This is an interim measure consistent with the approach we've taken elsewhere until we implement the proper long-term solution.

The proper long-term solution is to refactor EmbedderTest (see: flutter/flutter#157942) and other related code to split out backends into separate translation units, with the Metal backend code in Objective-C++ implementation files, which would then mean the headers could include Objective-C ivars.

No changes to tests, since this change introduces no behaviour changes.

Issue: flutter/flutter#157942
Issue: flutter/flutter#158998

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.

`TestMetalContext` cannot include any Objective-C types in its header
file since that header is included in pure C++ translation units.
Previously, we declared these fields as `void*`, which then requires
manual `__bridge_retained` and `__bridge_transfer` casts to perform the
necessary retain/relase manipulation while opting the object in and out
of ARC management.

Instead, we extract these to a struct in the implementation file and
allow the fields to be managed by ARC. This is an interim measure
consistent with the approach we've taken [elsewhere][1] until we
implement the proper long-term solution.

The proper long-term solution is to refactor `EmbedderTest` and other
related code to split out backends into separate translation units, with
the Metal backend code in Objective-C++ implementation files, which
would then mean the headers could include Objective-C ivars.

No changes to tests, since this change introduces no behaviour changes.

[1]: https://github.com/flutter/engine/blob/950e240eb7a6bd52124d8efda6806a9eb3a18a83/shell/common/shell_test_platform_view_metal.mm#L21-L27

Issue: flutter/flutter#157942
@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.

@stuartmorgan-g
Copy link
Contributor

test-exempt: code refactor with no semantic change

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

@cbracken cbracken added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 11, 2024
@auto-submit auto-submit bot merged commit 73ccb5b into flutter:main Nov 11, 2024
30 checks passed
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 11, 2024
@cbracken cbracken deleted the arc-objc-struct branch November 11, 2024 22:02
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 11, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 12, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Nov 12, 2024
…158485)

flutter/engine@7b3eacd...35041f1

2024-11-11 skia-flutter-autoroll@skia.org Roll Dart SDK from a393f3ed040a to 69170fac244c (1 revision) (flutter/engine#56513)
2024-11-11 chris@bracken.jp iOS,macOS: Refactor TestMetalContext for ARC (flutter/engine#56510)
2024-11-11 jonahwilliams@google.com [Impeller] geometry changes to support line/point style. (flutter/engine#56340)
2024-11-11 skia-flutter-autoroll@skia.org Roll Skia from af6a4f9a85ee to 11046fd10394 (9 revisions) (flutter/engine#56508)
2024-11-11 jonahwilliams@google.com [Impeller] dont unnecessarily copy point data out of display list. (flutter/engine#56492)
2024-11-11 jonahwilliams@google.com [Impeller] fix line/polygon depth and GLES scissor state. (flutter/engine#56494)
2024-11-11 jason-simmons@users.noreply.github.com Do not stop flutter_tester if microtasks are still pending (flutter/engine#56432)
2024-11-11 skia-flutter-autoroll@skia.org Roll Skia from 261316c10484 to af6a4f9a85ee (5 revisions) (flutter/engine#56505)
2024-11-11 skia-flutter-autoroll@skia.org Roll Dart SDK from 4ea43aa234a4 to a393f3ed040a (1 revision) (flutter/engine#56506)

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,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
nick9822 pushed a commit to nick9822/flutter that referenced this pull request Dec 18, 2024
`TestMetalContext` cannot include any Objective-C types in its header file since that header is included in pure C++ translation units. Previously, we declared these fields as `void*`, which then requires manual `__bridge_retained` and `__bridge_transfer` casts to perform the necessary retain/relase manipulation while opting the object in and out of ARC management.

Instead, we extract these to a struct in the implementation file and allow the fields to be managed by ARC. This is an interim measure consistent with the approach we've taken [elsewhere][1] until we implement the proper long-term solution.

The proper long-term solution is to refactor `EmbedderTest` (see: flutter#157942) and other related code to split out backends into separate translation units, with the Metal backend code in Objective-C++ implementation files, which would then mean the headers could include Objective-C ivars.

No changes to tests, since this change introduces no behaviour changes.

Issue: flutter#157942

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

Successfully merging this pull request may close these issues.

2 participants