-
Notifications
You must be signed in to change notification settings - Fork 6k
iOS: only add explicit transactions when there are platform views (only on main threads) #21526
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. 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.
This is going to be somewhat costly. Couldn't we just do something like:
PlatformViews.mm
io_surface->AddCATransaction();
layer.transform = newTransform;
io_surface.mm:
void IOSurface::AddCATransaction() {
assert(IsRunningOnMainThread());
if (!has_ca_transaction_) {
[CATransaction begin];
has_ca_transaction_ = true;
}
}
void IOSSurface::SubmitFrame() {
if (has_ca_transaction) {
[CATransaction commit];
has_ca_transaction_ = false;
}
}
It is not true that the platform views code runs entirely on the main thread. The platform view's code will run on the raster thread until So even we move the transaction code into the I'm not sure how costly the code for checking main thread is (I thought it is just a bit check). If it is costly, we can just check once and set a flag like what you did, and only check our flag in the same frame. |
It's not a bit check because there are 2 different objc_msgsend's in order to even get to the implementation. It isn't just the cost, the proposal I'm making makes the logic more clear. We are adding a CATransaction only when one is needed. The addition of the transaction is close to the location that needs it, too, so it is easier to maintain and understand. The way the transaction is now, it isn't obvious why we even need it. |
580b39e
to
744e93f
Compare
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 a lot better from a code perspective. I would wrap up the begin
and the commit
into small helper methods. I do have concerns that we are changing the location of the [CATransaction commit]
. Did you test it out? I just want to make sure it doesn't cause synchronization problems. That's why I suggested keeping the commit in the same place.
@gaaclarke Yes, I have tested with local engine and it works. Also updated with your suggestions. |
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.
Code looks good, as long as manual testing checks out for synchronization in platformviews (which it has) LGTM.
I tested this on iPhone SE 2 with the image_picker example and the crash is gone on device.
tests: this PR can land without tests since our repro involves a specific plugin, on the condition that we prioritise the work to add an end-to-end test to the plugin itself that tests this ASAP. Thanks. |
…iews (only on main threads) (flutter/engine#21526)
…iews (only on main threads) (flutter/engine#21526)
…iews (only on main threads) (flutter/engine#21526)
…iews (only on main threads) (flutter/engine#21526)
…iews (only on main threads) (flutter/engine#21526)
…iews (only on main threads) (flutter/engine#21526)
…iews (only on main threads) (flutter/engine#21526)
…iews (only on main threads) (flutter/engine#21526)
…iews (only on main threads) (flutter/engine#21526)
* Update Dart to 2.10.1 * Extract the WindowInsetsAnimation.Callback subclass into a separate class that will be lazily loaded (#21548) WindowInsetsAnimation.Callback was introduced in API level 30. This PR moves the text input plugin's WindowInsetsAnimation.Callback subclass into a class that will only be loaded if the embedding has checked for a sufficient API level. See flutter/flutter#66908 * iOS: only add explicit transactions when there are platform views (only on main threads) (#21526) * update licenses golden * pin framework for build tests Co-authored-by: Jason Simmons <jason-simmons@users.noreply.github.com> Co-authored-by: Chris Yang <ychris@google.com>
…ly on main threads) (flutter#21526)
This pull request was opened against a branch other than main. Since Flutter pull requests should not normally be opened against branches other than main, I have changed the base to main. If this was intended, you may modify the base back to master. See the Release Process for information about how other branches get updated. Reviewers: Use caution before merging pull requests to branches other than main, unless this is an intentional hotfix/cherrypick. |
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 (don't just cc him here, he won't see it! He's on Discord!). 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. |
Description
We only need to add explicit CATransactions on the main thread since platform views are only going to be on the main thread.
Also, adding explicit transactions seem to crash in certain image picker scenarios on iOS 14, so remove these transactions on the background thread will fix those crashes (on metal only)
Related Issues
flutter/flutter#66647
Tests
Not sure what we can do to test the rendering synchronization. I added a bunch of FML_DCHECKs so at least, the scenario app tests in the engine should catch un-balanced CATransactions or CATransactions on the background thread.
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.Breaking Change
Did any tests fail when you ran them? Please read handling breaking changes.