-
Notifications
You must be signed in to change notification settings - Fork 6k
[metal] Darwin unified external metal textures #24157
[metal] Darwin unified external metal textures #24157
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat. 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. |
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.
I have a few doubts about the memory management of certain CF objects. Other than that, I only eyeballed the code that was moved which look fine to me.
@@ -7,19 +7,23 @@ assert(is_ios || is_mac) | |||
import("//flutter/common/config.gni") | |||
|
|||
source_set("graphics") { | |||
cflags_objc = flutter_cflags_objc | |||
cflags_objcc = flutter_cflags_objcc | |||
cflags_objcc = [ "-fobjc-arc" ] |
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.
Shouldn't this be in addition to the flutter_cflags_objc
? I am not sure what those flags currently are but we are no longer applying them to this target.
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.
I noticed that the other targets that enable arc, only had this will verify.
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.
I created a new high level param for arc targets and unified it.
@@ -33,32 +33,39 @@ - (instancetype)initWithMTLDevice:(id<MTLDevice>)device | |||
|
|||
if (!_device) { | |||
FML_DLOG(ERROR) << "Could not acquire Metal device."; | |||
[self release]; | |||
return 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.
Can we decorate translation units with FLUTTER_ASSERT_ARC
and FLUTTER_ASSERT_NON_ARC
now that we are mixing the two in 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.
Added it to the ARC targets that i've touched.
/** | ||
* Creates an external texture with the specified ID and contents. | ||
*/ | ||
- (FlutterDarwinExternalTextureMetal*)externalTextureWithID:(int64_t)textureID |
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.
IMO createExternalTexture:withIdentifier:
seems more idiomatic.
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!
nil, // cache attributes (nil default) | ||
_device, // metal device | ||
nil, // texture attributes (nil default) | ||
&_textureCache // [out] cache |
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.
CoreFoundation objects need to be explicitly released. IIRC, this would leak the texture cache in the dealloc unless __bridge_transfer
ed
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.
I was worried about the same. I will try to add a test to see that everything that was allocated gets collected.
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.
I wasn't able to come up with a way to test de-alloc in a nice way. I audited the code and made sure that are CoreFoundation objects are released and retained as necessary.
textureID:(int64_t)textureID | ||
texture:(NSObject<FlutterTexture>*)texture { | ||
if (self = [super init]) { | ||
_textureCache = textureCache; |
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.
Isn't this missing a CFRetain
and subsequent release in the dealloc? We might end up with a dangling reference otherwise.
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 (needsUpdatedTexture) { | ||
CVPixelBufferRef pixelBuffer = [_externalTexture copyPixelBuffer]; | ||
if (!pixelBuffer) { | ||
pixelBuffer = std::move(_lastPixelBuffer); |
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.
What does std::move
with ARC even do?
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.
Doesn't make sense :-) I've used CVPixelBufferRetain
and CVPixelBufferRelease
as needed.
…er#24157)" (flutter#24244)" This reverts commit 2e10a97.
…" (flutter#24223) This reverts commit 6a2df7f.
No description provided.