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 7, 2024

Document where CFRef takes over or hands back ownership of the underlying CoreFoundation object memory.

Migrates manual CoreFoundation object management to CFRef in:

  • impeller/golden_tests/metal_screenshot.mm
  • shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.mm
  • shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.mm
  • shell/platform/darwin/ios/framework/Source/FlutterView.mm
  • shell/platform/darwin/macos/framework/Source/FlutterSurface.mm

Adds a Retain() method to take shared ownership of the underlying object, as opposed to Reset, where ownership is transferred to the CFRef wrapper.

Adds a Get() method to make dealing with bridged Objective-C casts more convenient:

  fml::CFRef<CFStringRef> cfString(...);
  NSString* aString = (__bridge NSString*)cfString.Get();

as opposed to:

  fml::CFRef<CFStringRef> cfString(...);
  NSString* aString = (__bridge NSString*)static_cast<CFStringRef>(cfString);

I considered making use of fml::scoped_policy::OwnershipPolicy to add a second parameter to the ctor and Reset but, but I think documentation and addition of a Retain() method makes things a little clearer at the call site. It's also more consistent with sk_cfp, which we use in some Skia bits of the codebase.

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

This comment was marked as resolved.

@cbracken
Copy link
Member Author

cbracken commented Nov 7, 2024

Will add tests. Added.

@cbracken cbracken changed the title fml: Add docs to CFRef fml: Use CFRef where possible, add docs Nov 7, 2024
@cbracken cbracken changed the title fml: Use CFRef where possible, add docs fml: Use CFRef where possible and add docs Nov 7, 2024
@cbracken cbracken requested a review from jmagman November 7, 2024 21:24
Document where CFRef takes over or hands back ownership of the
underlying CoreFoundation object memory.

Migrates manual CoreFoundation object management to CFRef in:
* impeller/golden_tests/metal_screenshot.mm
* shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.mm
* shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.mm
* shell/platform/darwin/ios/framework/Source/FlutterView.mm
* shell/platform/darwin/macos/framework/Source/FlutterSurface.mm

Adds a Retain() method to take shared ownership of the underlying
object, as opposed to Reset, where ownership is transferred to the CFRef
wrapper.

Adds a Get() method to make dealing with bridged Objective-C casts more
convenient:
```objc
  fml::CFRef<CFStringRef> cfString(...);
  NSString* aString = (__bridge NSString*)cfString.Get();
```
as opposed to:
```objc
  fml::CFRef<CFStringRef> cfString(...);
  NSString* aString = (__bridge NSString*)static_cast<CFStringRef>(cfString);
```
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 8, 2024
@auto-submit auto-submit bot merged commit b7134d3 into flutter:main Nov 8, 2024
30 checks passed
@cbracken cbracken deleted the cfref-docs-usage branch November 8, 2024 20:55
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 8, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Nov 8, 2024
nick9822 pushed a commit to nick9822/flutter that referenced this pull request Dec 18, 2024
Document where CFRef takes over or hands back ownership of the underlying CoreFoundation object memory.

Migrates manual CoreFoundation object management to CFRef in:
* impeller/golden_tests/metal_screenshot.mm
* shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.mm
* shell/platform/darwin/graphics/FlutterDarwinExternalTextureMetal.mm
* shell/platform/darwin/ios/framework/Source/FlutterView.mm
* shell/platform/darwin/macos/framework/Source/FlutterSurface.mm

Adds a `Retain()` method to take shared ownership of the underlying object, as opposed to Reset, where ownership is transferred to the CFRef wrapper.

Adds a `Get()` method to make dealing with bridged Objective-C casts more convenient:
```objc
  fml::CFRef<CFStringRef> cfString(...);
  NSString* aString = (__bridge NSString*)cfString.Get();
```
as opposed to:
```objc
  fml::CFRef<CFStringRef> cfString(...);
  NSString* aString = (__bridge NSString*)static_cast<CFStringRef>(cfString);
```

I considered making use of `fml::scoped_policy::OwnershipPolicy` to add a second parameter to the ctor and `Reset` but, but I think documentation and addition of a `Retain()` method makes things a little clearer at the call site. It's also more consistent with `sk_cfp`, which we use in some Skia bits of the codebase.

[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

affects: desktop autosubmit Merge PR when tree becomes green via auto submit App e: impeller platform-ios platform-macos

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants