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

Conversation

@endless7
Copy link
Contributor

@endless7 endless7 commented Nov 16, 2022

Because the plugin retains the texture registrar there will be a cycle. We make the proxy object a weak reference back to the engine serve as the texture registry object that is returned instead.

Related issue: flutter/flutter#102990

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], including [Features we expect every widget to implement].
  • [✓] I signed the [CLA].
  • [✓] I listed at least one issue that this PR fixes in the description above.
  • [✓] I updated/added relevant documentation (doc comments with ///).
  • [✓] I added new tests to check the change I am making, or this PR is [test-exempt].
  • [✓] All existing and new tests are passing.

@flutter-dashboard flutter-dashboard bot added embedder Related to the embedder API platform-ios labels Nov 16, 2022
@endless7
Copy link
Contributor Author

cc @stuartmorgan

@ColdPaleLight ColdPaleLight requested review from cyanglaz and gaaclarke and removed request for cyanglaz November 16, 2022 10:47
Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

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

This is great! Thanks!
On macOS, both FlutterEngine and FlutterRenderer are "FlutterPluginRegistry".
https://github.com/flutter/engine/blob/main/shell/platform/darwin/macos/framework/Headers/FlutterEngine.h#L24
https://github.com/flutter/engine/blob/main/shell/platform/darwin/macos/framework/Source/FlutterRenderer.h#L15

Maybe while we are here it would be nice to migrate macOS to use FlutterTextureRegistryRelay? It doesn't have to be in the same PR but if we want to do this, it might make sense to put FlutterTextureRegistryRelay in a common code base. Maybe https://github.com/flutter/engine/tree/main/shell/platform/darwin/graphics?

cc @cbracken for thoughts on macOS.

Comment on lines 14 to 15
self = [super init];
if (self != nil) {
Copy link
Contributor

Choose a reason for hiding this comment

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

optional nits:

Suggested change
self = [super init];
if (self != nil) {
if (self = [super init]) {

this is following the pattern in the objc document: https://developer.apple.com/documentation/objectivec/nsobject/1418641-init?language=objc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 22 to 27
if (self.parent) {
return [self.parent registerTexture:texture];
} else {
FML_LOG(WARNING) << "Using on an empty registry.";
}
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

optional nits, escape early:

Suggested change
if (self.parent) {
return [self.parent registerTexture:texture];
} else {
FML_LOG(WARNING) << "Using on an empty registry.";
}
return 0;
if (!self.parent) {
FML_LOG(WARNING) << "Using on an empty registry.";
return 0;
}
return [self.parent registerTexture:texture];

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@cbracken cbracken self-requested a review November 17, 2022 00:26
Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

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

LGTM
talked offline with @cbracken. He has been doing related MacOS refactoring and would also like to take a look at this.

@chinmaygarde
Copy link
Member

@cyanglaz Can we land this now and file a followup perhaps? This looks good to go.

@cyanglaz
Copy link
Contributor

cyanglaz commented Dec 2, 2022

Yes, I'm ok to land it now. We will need a secondary review. @gaaclarke @cbracken @stuartmorgan

@endless7 Could you update your PR description to have more details, also please bring back the list and check the check marks accordingly :)

@endless7
Copy link
Contributor Author

endless7 commented Dec 5, 2022

@cyanglaz Updated. Anything else to do?

@jmagman
Copy link
Member

jmagman commented Dec 7, 2022

re-ping @cyanglaz

@jmagman
Copy link
Member

jmagman commented Dec 7, 2022

@cyanglaz says the PR description looks good, now waiting for a second review from @gaaclarke, @cbracken, or @stuartmorgan.

#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
FLUTTER_DARWIN_EXPORT
#endif
@interface FlutterTextureRegistryRelay : NSObject <FlutterTextureRegistry>
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a comment explaining that this relay is used to solve the issue with plugin retaining the engine?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

Copy link
Member

Choose a reason for hiding this comment

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

Use /** */
comments as in the other headers.

From this comment I don't really understand when this would be used. Returned from what?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jmagman, are these comments ok?

Copy link
Member

Choose a reason for hiding this comment

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

How about:

/**
 * Wrapper around a weakly held collection of registered textures.
 *
 * Avoids a retain cycle between plugins and the engine.
 */
@interface FlutterTextureRegistryRelay : NSObject <FlutterTextureRegistry>

/**
 * A weak reference to a FlutterEngine that will be passed texture registration.
 */
@property(nonatomic, assign) NSObject<FlutterTextureRegistry>* parent;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, this would be better.

@jmagman
Copy link
Member

jmagman commented Dec 21, 2022

@endless7 Once the test failures, merge conflicts are fixed, and @hellohuanlin's requested comment is added, this has been approved and will be ready to land.

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 embedder Related to the embedder API platform-ios

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants