[fuchsia] Allow multiple vsync requests before the first Present#31316
[fuchsia] Allow multiple vsync requests before the first Present#31316fluttergithubbot merged 2 commits intoflutter:mainfrom
Conversation
c450820 to
6827c1e
Compare
arbreng
left a comment
There was a problem hiding this comment.
Looks great! All the stuff we talked about
2769021 to
8d44dab
Compare
akbiggs
left a comment
There was a problem hiding this comment.
Just wondering, were you able to test this change and confirm that it fixed the problem?
|
|
||
| // This method is called from the raster thread. | ||
| void FlatlandConnection::Present() { | ||
| if (!threadsafe_state_.first_present_called_) { |
There was a problem hiding this comment.
I'm wondering what first_present_called_ represents since it doesn't seem to care about whether DoPresent() actually did the presentation.
Will OnGetLayout() return the correct value if DoPresent wasn't called yet (either because this thread didn't reach DoPresent() or because present_credits_ == 0 on this call)?
There was a problem hiding this comment.
Flutter animator waits for a Vsync signal from Flatland before starting to render a frame, see Animator::RequestFrame(). Flatland returns Vsync signal to the client through OnNextFrameBegin(), but only after they send their first Present(). |first_present_called_| was used to fake the first vsync signal in AwaitVsync(). We then follow Present()-OnNextFrame() sequence for the render loop.
Flatland's OnGetLayout() returns values to Flutter on a separate protocol and platform thread. Ideally, the clients should wait for it before their first Present() so they know how big their content should be. Flutter does that and even skips render if size isn't there yet in Engine::Render(). However, it can take a couple AwaitVsync calls to have the size, so we fake vsync signals until the first Present().
All Flatland clients start with 1 present credit, so we know the first Present goes through.
|
Yes, I tested that this works 1) with the injected sleep() that makes it a consistent repro 2) 40 runs on OOBE app. |
8d44dab to
8657794
Compare
akbiggs
left a comment
There was a problem hiding this comment.
Thanks for the explanation, looks good.
| // Immediately fire callbacks until the first Present. We might receive | ||
| // multiple requests for AwaitVsync() until the first Present, which relies on | ||
| // receiving size on FlatlandPlatformView::OnGetLayout() at an uncertain time. | ||
| bool first_present_called; |
There was a problem hiding this comment.
Is acquiring and releasing this lock a second time on every frame expensive? It seems like we're adding additional work to every frame to handle a case that's only true for the first couple of vsyncs and never afterwards.
If this is cheap ignore this comment.
There was a problem hiding this comment.
Good call! I am changing so that we keep the lock. I was trying to handle the case that FlatlandConnectionTest.PresentCreditExhaustion exercises where FireCallbackCallback runs Present(). But it is not applicable in production code as we have a thread jump. AwaitVsync is always on UI thread and Present() is on raster thread. I am modifying the test.
akbiggs
left a comment
There was a problem hiding this comment.
New changes LGTM. Added label to submit when presubmits are green again.
|
This pull request is not suitable for automatic merging in its current state.
|
9d91847 to
bd34283
Compare
bd34283 to
44de155
Compare
This CL changes the flatland render loop so that we fire vsync callbacks immediately before the first present.
Bug: https://bugs.fuchsia.dev/p/fuchsia/issues/detail?id=93179