-
Notifications
You must be signed in to change notification settings - Fork 6k
iOS FlutterTextureRegistry should be a proxy, not the engine itself #37666
Conversation
There was a problem hiding this 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.
shell/platform/darwin/ios/framework/Source/FlutterTextureRegistryRelay.h
Outdated
Show resolved
Hide resolved
| self = [super init]; | ||
| if (self != nil) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optional nits:
| 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| if (self.parent) { | ||
| return [self.parent registerTexture:texture]; | ||
| } else { | ||
| FML_LOG(WARNING) << "Using on an empty registry."; | ||
| } | ||
| return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optional nits, escape early:
| 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]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
cyanglaz
left a comment
There was a problem hiding this 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.
|
@cyanglaz Can we land this now and file a followup perhaps? This looks good to go. |
|
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 :) |
|
@cyanglaz Updated. Anything else to do? |
|
re-ping @cyanglaz |
|
@cyanglaz says the PR description looks good, now waiting for a second review from @gaaclarke, @cbracken, or @stuartmorgan. |
shell/platform/darwin/ios/framework/Source/FlutterTextureRegistryRelayTest.mm
Show resolved
Hide resolved
shell/platform/darwin/ios/framework/Source/FlutterTextureRegistryRelay.mm
Show resolved
Hide resolved
| #if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG | ||
| FLUTTER_DARWIN_EXPORT | ||
| #endif | ||
| @interface FlutterTextureRegistryRelay : NSObject <FlutterTextureRegistry> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
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.
|
@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. |
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
///).