Skip to content

fix(android): Hand the window back from a stacked activity (backport #25901) - #26659

Open
mergify[bot] wants to merge 5 commits into
release/stable/7.0from
mergify/bp/release/stable/7.0/pr-25901
Open

mergify[bot] wants to merge 5 commits into
release/stable/7.0from
mergify/bp/release/stable/7.0/pr-25901

Conversation

@mergify

@mergify mergify Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #24862

PR Type:

🐞 Bugfix

What changed? 🚀

On Skia Android, an intent delivered to a running app whose activity uses the default standard launch mode (for example a protocol activation) stacks a second instance of the activity. That copy takes the window over. Since #24042 it renders, but finishing it (Back) closed the window with it and left the original activity frozen on a stale frame. The protocol activation docs ask for SingleTask, which avoids the stacking, but an app that doesn't set it should still work.

This fixes the hand-back and the rendering problems that the stacked case exposed:

  1. Window hand-back (ApplicationActivity): when the activity coming back to the foreground (OnStart, or OnResume when the copy finished before it was even stopped) finds that the activity driving its window is finishing, it takes the window back (accessibility helper, native elements, a fresh frame) instead of letting the window close with the copy.
  2. Only the driving activity presents the window (UnoVulkanView, UnoCanvasView, UnoWebGpuView): every activity that has held the window renders the same CompositionTarget, so a frame from a covered activity's view replayed the driving view's recordings into its own device and consumed the target's frame state.
  3. No lost render requests across a hand-over (CompositionTarget, render views): a record attempted while the new activity's view had no renderer yet was dropped with nothing asking again, and after a renderer swap the RequestNewFrame was absorbed by a request still latched for the previous view. A view now asks for a fresh record once it has negotiated a renderer (the contract the WASM host already follows), and a renderer swap also asks the host for a native frame.
  4. Software renderer: GL objects deleted in the wrong context (AndroidSoftwareGraphicsContext): disposed programs and textures went through a process-wide queue that any GL thread drained. GL names are per EGL context, so when one activity's context was torn down, the other activity deleted its own objects that shared those numbers, and every later blit was black. The queue is gone, since each activity owns its own view, GL thread and context: a context deletes its objects only while its own EGL context is current, and otherwise leaves them to that context's destruction; the CPU buffer is always freed. A teardown that the GL thread never ran now runs once the view detaches, after GLSurfaceView has joined that thread.
  5. GL: the retained frame was blitted through Skia's scissor (GLRetainedFramebuffer, shared by the Android, Win32 and X11 GL hosts): glBlitFramebuffer is clipped by the scissor test, which Skia leaves enabled around the damage it last painted. After a partial repaint only that strip reached the default framebuffer, so a new surface (the stacked activity, or the original after the hand-back) showed black apart from the damaged strip. The blit now disables the scissor test first.
  6. GL: stack overflow on activity re-creation (UnoCanvasView): the renderer teardown disposed the renderer's Java peer, but GLSurfaceView can still call OnDrawFrame until its thread exits; the call was bound to a fresh invoker that called back into Java and recursed until the stack overflowed. This reproduces on master with any activity re-creation on the GL renderer (e.g. Given_ApplicationActivity.When_Recreated_*). The peer is now left alive so the existing torn-down guard handles late frames.

Validation

  • Runtime test Given_ApplicationActivity.When_Stacked_Activity_Finishes_Then_Window_Returns_To_Original: stacks a test-only StackedWindowActivity (added to the SamplesApp Android head, default launch mode) over the running activity, finishes it, and checks the window is handed back without closing and still presents frames. Before the OnResume hand-back the window closed and the app exited.
  • Given_ApplicationActivity on the API 34 emulator: Vulkan 6/6 passed; GL and software 5 passed + the Vulkan-only test inconclusive (on master, GL crashes the app in When_Recreated_Dispatcher_Stays_Responsive).
  • Skia desktop (Windows): Given_CompositionTarget + Given_Visual_Damage 29 passed, 1 inconclusive (WebGPU-only), 1 skipped.
  • Manual, API 34 emulator, SamplesApp with SingleTask removed: cold launch → uno-samples-test:// deep link → Back → open a page → second deep link → Back → exit, on the Vulkan, GL (adb shell setprop debug.uno.samples.renderer gl) and software renderers. Every step renders and responds on all three. Before: frozen stale frame after Back (all renderers), black stacked activity on GL, black page after navigation on software.

Known limitation

Each activity's Vulkan view creates its own VkInstance/VkDevice. On the emulator (SwiftShader through gfxstream), repeated stack/finish cycles sometimes freeze or crash the emulator host process, after Skia allocation failures (BindBufferMemory -1). Rendering is correct up to that point; this looks like an emulator limitation and was not reproducible on other renderers. Sharing one device across activities would avoid it and is left for a follow-up.

PR Checklist ✅

🤖 Generated with Claude Code


This is an automatic backport of pull request #25901 done by [Mergify](https://mergify.com).

ramezgerges and others added 5 commits November 23, 2026 16:09
glBlitFramebuffer is clipped by the scissor test, which Skia leaves enabled
around the damage it last painted. After a partial repaint only that strip
reached the default framebuffer, so a new surface showed black elsewhere.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit 241ccaa)
Disposed programs and textures went through a process-wide queue drained by
any GL thread. GL names are per EGL context, so another activity's context
deleted its own objects that shared the numbers, and its blits went black.

Each activity owns its render view, GL thread and context, so the queue is
gone: a context deletes its objects only when its own EGL context is current,
and otherwise leaves them to that context's destruction. The CPU buffer is
always freed. A teardown that the GL thread never ran now runs once the view
detaches, after GLSurfaceView has joined that thread.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit 4eb2bb9)
GLSurfaceView can still call OnDrawFrame after the renderer is torn down.
Disposing the peer bound that call to a fresh invoker calling back into Java,
which recursed until the stack overflowed (any activity re-creation on GL).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit 59b0bcc)
An intent delivered in the standard launch mode stacks a second instance of
the activity, which takes the window over. When it finished, the window
closed with it and left the original frozen. The original now takes the
window back, only the driving activity presents it, and a render request
lost across the hand-over is asked for again.

Fixes #24862

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit 88602a0)
A finishing activity that still owns the window now hands it to the most
recently active copy still alive, instead of closing it, when that copy
did not reclaim it first (one left stopped in another task). A copy that
resumes also takes the window from one that is not resumed, as when the
user switches back through Recents.

Also sets IsSoftwareRenderer before posting the re-record, reuses the
resolved host on a renderer swap, and waits for the stacked activity's
destruction before asserting the window stayed open.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
(cherry picked from commit ff26512)
@github-actions github-actions Bot added platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform area/skia ✏️ Categorizes an issue or PR as relevant to Skia area/automation Categorizes an issue or PR as relevant to project automation labels Nov 23, 2026
@mergify

mergify Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 248442 found UI Test snapshots differences: skia-linux-screenshots: 235, skia-windows-screenshots: 265

Details
  • skia-linux-screenshots: 235 changed over 2496

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AppWindowTitleBar Properties.png
    • BreadcrumbBarPage.png-dark
    • BreadcrumbBarPage.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • AppWindowTitleBar Properties.png-dark
    • AutomationProperties_AutomationId.png-dark
    • BasicAcrylicBrushTest2.png-dark
    • BasicAcrylicBrushTest2.png
    • ComboBox_MaxDropdownHeight.png-dark
    • ComboBox_MaxDropdownHeight.png
    • AnimatedBackVisualSourceSamplePage.png
    • BasicAcrylicBrushTest.png-dark
    • BasicAcrylicBrushTest.png
    • Border_CornerRadius_Binding.png-dark
    • Border_CornerRadius_Binding.png
    • Border_CornerRadius_BorderThickness.png-dark
    • Border_CornerRadius_BorderThickness.png
    • AnimatedBackVisualSourceSamplePage.png-dark
    • AnimatedVisualsTestbedPage.png
  • skia-windows-screenshots: 265 changed over 2496

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedBackVisualSourceSamplePage.png
    • AnimatedVisualsTestbedPage.png
    • AutomationProperties_StructureAndProps.png
    • BreadcrumbBarPage.png-dark
    • BreadcrumbBarPage.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • AnimatedVisualsTestbedPage.png-dark
    • AutomationProperties_AutomationId.png
    • Basics.png-dark
    • Basics.png
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • Accessibility_Showcase.png-dark
    • BasicAcrylicBrushTest2.png-dark
    • BasicAcrylicBrushTest2.png
    • ComboBox_MaxDropdownHeight.png-dark

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation area/skia ✏️ Categorizes an issue or PR as relevant to Skia platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants