Repository navigation
aosp: Defer Start until there's a surface - #13245
Conversation
|
🤖 Gemini Suggested Commit Message💡 Pro Tips for a Better Commit Message:
|
There was a problem hiding this comment.
Code Review
This pull request introduces a thread-safe mechanism to wait for an Android window surface when creating a window in the AOSP application implementation. Specifically, CreateWindow now loops and blocks using a new condition variable helper WaitForWindowSurface if the surface is not immediately available. Additionally, ReleaseWindowSurfaceAndWait is updated to clear the surface first under a new mutex (window_mutex_) to prevent race conditions during window creation. I have no further feedback to provide as the changes are well-structured and there are no review comments to address.
|
@ogarai LGTM, I couldn't reproduce the crash with this fix. |
|
Thanks for updating the PR — the Step 1 changes and the It looks like the branch just needs a quick rebase onto |
If the app went to the background before Cobalt created its window, SbWindowCreate() found no surface and Cobalt aborted on a CHECK. Wait for a new surface instead. Clear the surface under the same lock as window creation, so no window is created on a surface that is going away. Skip the 2 s release wait in surfaceDestroyed() when no window holds the surface. Test: Pressing HOME 0.8 s after launch crashed Cobalt in 1 of 10 runs. With this change 20 of 20 runs keep running. Without a window, surfaceDestroyed() returns immediately. Bug: 532158865
8245f05 to
5fbd6f6
Compare
Thanks @jellefoks ! Rebased. |
Refer to original PR: #13245 If the app goes to the background while Cobalt is still loading, there is no surface when Start runs. SbWindowCreate() then returns an invalid window and Cobalt aborts on a CHECK. Don't start Cobalt until Android provides a surface. If the app was backgrounded before Start, start it once the app comes back. A Stop before Start now ends the event loop, and other events before Start aren't passed to the app. Clear the surface under the same lock as window creation, so no window is created on a surface that is going away. Skip the 2 s release wait in surfaceDestroyed() when no window holds the surface. This is the first part of the fix. Backgrounding after Start has begun still makes SbWindowCreate() fail. A follow-up will handle that failure in Ozone and the lifecycle code, as proposed in the review. Bug: 532158865 (cherry picked from commit 42eb10d)
Refer to original PR: #13245 If the app goes to the background while Cobalt is still loading, there is no surface when Start runs. SbWindowCreate() then returns an invalid window and Cobalt aborts on a CHECK. Don't start Cobalt until Android provides a surface. If the app was backgrounded before Start, start it once the app comes back. A Stop before Start now ends the event loop, and other events before Start aren't passed to the app. Clear the surface under the same lock as window creation, so no window is created on a surface that is going away. Skip the 2 s release wait in surfaceDestroyed() when no window holds the surface. This is the first part of the fix. Backgrounding after Start has begun still makes SbWindowCreate() fail. A follow-up will handle that failure in Ozone and the lifecycle code, as proposed in the review. Bug: 532158865 (cherry picked from commit 42eb10d)
Since #13245, kSbEventTypeStart waits for a surface. The surface can still go away before Cobalt creates its first window, for example on HOME during startup. SbWindowCreate() then fails, and Cobalt crashes on a CHECK in PlatformWindowStarboard::Show(). Handle the missing window instead: - Log the failure in Show() and Restore() and leave the window unset. The Restore() on the next Reveal creates it. Until then there's no widget, so don't pass one to the compositor in the Views host. - Conceal after Start or Reveal without a window, so the next Focus reveals the app and creates the window. Because of this: - Wait for the conceal in HandleEvent(Start), just like a Conceal event. - Retry a failed Reveal once if a Focus arrives during it, so the Focus isn't lost. - Don't wait for a Reveal ACK without a window, and drop a pending one on Conceal. - ACK at once for a frame already in the target state. It has no state change to report, so its ACK would never come. - Ignore a Blur while concealed or concealing. The platform doesn't know Cobalt concealed itself, so it can still send a Blur. - Keep every WebContents on Conceal for the next Reveal. HOME during the splash screen used to come back black. Because the hidden main page now comes back, show the splash again on a Reveal during the splash, until the main page has loaded. This implements steps 2 and 3 of the design @jellefoks proposed in the Test: cobalt_unittests. On device, HOME during startup and back: no crash, and the app returns to the splash screen or the page. Android TV with and without the Starboard lifecycle: no new failures. Bug: 532158865
Refer to original PR: #13722 Since #13245, kSbEventTypeStart waits for a surface. The surface can still go away before Cobalt creates its first window, for example on HOME during startup. SbWindowCreate() then fails, and Cobalt crashes on a CHECK in PlatformWindowStarboard::Show(). Handle the missing window instead: - Log the failure in Show() and Restore() and leave the window unset. The Restore() on the next Reveal creates it. Until then there's no widget, so don't pass one to the compositor in the Views host. - Conceal after Start or Reveal without a window, so the next Focus reveals the app and creates the window. Because of this: - Wait for the conceal in HandleEvent(Start), just like a Conceal event. - Retry a failed Reveal once if a Focus arrives during it, so the Focus isn't lost. - Don't wait for a Reveal ACK without a window, and drop a pending one on Conceal. - ACK at once for a frame already in the target state. It has no state change to report, so its ACK would never come. - Ignore a Blur while concealed or concealing. The platform doesn't know Cobalt concealed itself, so it can still send a Blur. - Keep every WebContents on Conceal for the next Reveal. HOME during the splash screen used to come back black. Because the hidden main page now comes back, show the splash again on a Reveal during the splash, until the main page has loaded. This implements steps 2 and 3 of the design @jellefoks proposed in the Test: cobalt_unittests. On device, HOME during startup and back: no crash, and the app returns to the splash screen or the page. Android TV with and without the Starboard lifecycle: no new failures. Bug: 532158865 (cherry picked from commit 4f174e6)
Refer to original PR: #13722 Since #13245, kSbEventTypeStart waits for a surface. The surface can still go away before Cobalt creates its first window, for example on HOME during startup. SbWindowCreate() then fails, and Cobalt crashes on a CHECK in PlatformWindowStarboard::Show(). Handle the missing window instead: - Log the failure in Show() and Restore() and leave the window unset. The Restore() on the next Reveal creates it. Until then there's no widget, so don't pass one to the compositor in the Views host. - Conceal after Start or Reveal without a window, so the next Focus reveals the app and creates the window. Because of this: - Wait for the conceal in HandleEvent(Start), just like a Conceal event. - Retry a failed Reveal once if a Focus arrives during it, so the Focus isn't lost. - Don't wait for a Reveal ACK without a window, and drop a pending one on Conceal. - ACK at once for a frame already in the target state. It has no state change to report, so its ACK would never come. - Ignore a Blur while concealed or concealing. The platform doesn't know Cobalt concealed itself, so it can still send a Blur. - Keep every WebContents on Conceal for the next Reveal. HOME during the splash screen used to come back black. Because the hidden main page now comes back, show the splash again on a Reveal during the splash, until the main page has loaded. This implements steps 2 and 3 of the design @jellefoks proposed in the Test: cobalt_unittests. On device, HOME during startup and back: no crash, and the app returns to the splash screen or the page. Android TV with and without the Starboard lifecycle: no new failures. Bug: 532158865 (cherry picked from commit 4f174e6)
Refer to original PR: #13722 Since #13245, kSbEventTypeStart waits for a surface. The surface can still go away before Cobalt creates its first window, for example on HOME during startup. SbWindowCreate() then fails, and Cobalt crashes on a CHECK in PlatformWindowStarboard::Show(). Handle the missing window instead: - Log the failure in Show() and Restore() and leave the window unset. The Restore() on the next Reveal creates it. Until then there's no widget, so don't pass one to the compositor in the Views host. - Conceal after Start or Reveal without a window, so the next Focus reveals the app and creates the window. Because of this: - Wait for the conceal in HandleEvent(Start), just like a Conceal event. - Retry a failed Reveal once if a Focus arrives during it, so the Focus isn't lost. - Don't wait for a Reveal ACK without a window, and drop a pending one on Conceal. - ACK at once for a frame already in the target state. It has no state change to report, so its ACK would never come. - Ignore a Blur while concealed or concealing. The platform doesn't know Cobalt concealed itself, so it can still send a Blur. - Keep every WebContents on Conceal for the next Reveal. HOME during the splash screen used to come back black. Because the hidden main page now comes back, show the splash again on a Reveal during the splash, until the main page has loaded. This implements steps 2 and 3 of the design @jellefoks proposed in the Test: cobalt_unittests. On device, HOME during startup and back: no crash, and the app returns to the splash screen or the page. Android TV with and without the Starboard lifecycle: no new failures. Bug: 532158865 (cherry picked from commit 4f174e6)
Refer to original PR: #13722 Since #13245, kSbEventTypeStart waits for a surface. The surface can still go away before Cobalt creates its first window, for example on HOME during startup. SbWindowCreate() then fails, and Cobalt crashes on a CHECK in PlatformWindowStarboard::Show(). Handle the missing window instead: - Log the failure in Show() and Restore() and leave the window unset. The Restore() on the next Reveal creates it. Until then there's no widget, so don't pass one to the compositor in the Views host. - Conceal after Start or Reveal without a window, so the next Focus reveals the app and creates the window. Because of this: - Wait for the conceal in HandleEvent(Start), just like a Conceal event. - Retry a failed Reveal once if a Focus arrives during it, so the Focus isn't lost. - Don't wait for a Reveal ACK without a window, and drop a pending one on Conceal. - ACK at once for a frame already in the target state. It has no state change to report, so its ACK would never come. - Ignore a Blur while concealed or concealing. The platform doesn't know Cobalt concealed itself, so it can still send a Blur. - Keep every WebContents on Conceal for the next Reveal. HOME during the splash screen used to come back black. Because the hidden main page now comes back, show the splash again on a Reveal during the splash, until the main page has loaded. This implements steps 2 and 3 of the design @jellefoks proposed in the Test: cobalt_unittests. On device, HOME during startup and back: no crash, and the app returns to the splash screen or the page. Android TV with and without the Starboard lifecycle: no new failures. Bug: 532158865 (cherry picked from commit 4f174e6)
If the app goes to the background while Cobalt is still loading, there
is no surface when Start runs. SbWindowCreate() then returns an invalid
window and Cobalt aborts on a CHECK.
Don't start Cobalt until Android provides a surface. If the app was
backgrounded before Start, start it once the app comes back. A Stop
before Start now ends the event loop, and other events before Start
aren't passed to the app.
Clear the surface under the same lock as window creation, so no window
is created on a surface that is going away. Skip the 2 s release wait
in surfaceDestroyed() when no window holds the surface.
This is the first part of the fix. Backgrounding after Start has begun
still makes SbWindowCreate() fail. A follow-up will handle that failure
in Ozone and the lifecycle code, as proposed in the review.
Bug: 532158865