-
Notifications
You must be signed in to change notification settings - Fork 6k
Windows: FlutterDesktopPixelBuffer: Add optional release callback #28298
Windows: FlutterDesktopPixelBuffer: Add optional release callback #28298
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. |
I think this is a fine addition. But can we a test for this? I don't see an existing test for this so I am unable to provide any guidance here. Perhaps @cbracken might know. |
Will take a quick look -- I'm pretty sure I added a test for something similar a couple months back. |
Chris may be busy with other things. To test this, I think we can just add a latch that is signalled in the unregistration callback and wait for it after calling |
074e2b2
to
61fb7ae
Compare
61fb7ae
to
4ada4b9
Compare
@chinmaygarde |
Thanks! |
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! Thanks!
// An optional callback that gets invoked when the |buffer| can be released. | ||
void (*release_callback)(void* release_context); | ||
// Opaque data passed to |release_callback|. | ||
void* release_context; |
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.
Adding these caused undefined behavior for existing code (unless the code was specifically written to defend against the possibility of new values by zero-initializing the entire memory block).
If we edit this again we should add a struct size to do safe reads, as we do with embedder.h.
I have set up the Following buffer update function: void Frame::Update(uint8_t *buffer, int32_t width, int32_t height)
{
const std::lock_guard<std::mutex> lock(mutex_);
flutter_pixel_buffer_.buffer = buffer;
flutter_pixel_buffer_.width = width;
flutter_pixel_buffer_.height = height;
flutter_pixel_buffer_.release_context = &buffer;
flutter_pixel_buffer_.release_callback = [](void *user_data)
{
uint8_t *old_buffer = reinterpret_cast<uint8_t *>(user_data);
if (old_buffer != nullptr)
free(old_buffer);
};
texture_registrar_->MarkTextureFrameAvailable(texture_id_);
} This gets invoked by dart throught the method channel However when I try to I get the following error:
The original buffer is a How and where am I supposed to free the buffer? |
This PR adds an optional callback to
FlutterDesktopPixelBuffer
that gets invoked when it's safe to release the backing buffer (or unlock a mutex protecting that buffer etc.).Pre-launch Checklist
writing and running engine tests.
///
).