Skip to content

fix(skia): reset the GL state cache before composing a frame - #24796

Merged
MartinZikmund merged 1 commit into
unoplatform:masterfrom
ramezgerges:dev/rara/gl-reset-context
Sep 30, 2026
Merged

MartinZikmund merged 1 commit into
unoplatform:masterfrom
ramezgerges:dev/rara/gl-reset-context

Conversation

@ramezgerges

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #24795

PR Type:

🐞 Bugfix

What changed? 🚀

On Win32 + OpenGL the window rendered blank and, after a resize, froze on a single frame — while the app stayed completely healthy (pump responsive, CPU spent, SwapBuffers always succeeding).

The host retains the previous frame by composing into its own framebuffer and blitting it at present. That blit is raw GL, and it rebinds the framebuffer:

_bindFramebuffer(GL_READ_FRAMEBUFFER, _framebuffer);
_bindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
_blitFramebuffer(...);
_bindFramebuffer(GL_FRAMEBUFFER, 0);

Skia's GrDirectContext caches GL state and nothing invalidated that cache, so from the next frame Skia believed the host's framebuffer was still bound and drew into the default one instead — while the blit kept copying the retained framebuffer over the top. The window showed whatever that framebuffer last legitimately received: blank from startup, or frozen on the frame a resize happened to produce.

PresentForGL now calls GRContext.ResetContext() before handing out the session.

Vulkan and Metal never had this: they present their own image and issue no raw GL around Skia.

Measurement

glReadPixels on the default framebuffer immediately before SwapBuffers, sampling a full row across the middle of the frame (flat = max − min ≤ 2). An external capture is not usable here — PrintWindow returns stale frames for this window, so it reports a frozen window as live.

before after
windowed 577/577 frames flat (blank) 531 frames with content
after maximize 2 distinct rows across 93 frames (frozen) 96/96 with content, 11 distinct rows

I also tried adding the GRContext.Flush(submit: true) that Vulkan and Metal perform on present (GL is the only backend whose present session doesn't submit). That alone did not fix it, which is what ruled out command submission and pointed at the state cache. ResetContext() alone is sufficient, so this PR does not add a per-frame submit.

PR Checklist ✅

  • 🧪 Added Runtime tests, UI tests, or a manual test sample (for bug fixes / features, if applicable) — see note below
  • 📚 Docs have been added/updated following the documentation template (for bug fixes / features) — internal rendering path, no public API or documented behaviour changes
  • 🖼️ Validated PR Screenshots Compare Test Run results.
  • ❗ Contains NO breaking changes
  • 👀 Reviewed 2 other open pull requests (optional but appreciated!)

On tests: this is not observable from inside the process — the app renders, reports damage, and swaps successfully the entire time it is showing a blank window; only reading back the presented framebuffer distinguishes the two states. A runtime test would need a GL-backed host plus a framebuffer read-back after present, which no existing harness provides, and RenderTargetBitmap renders offscreen and so passes either way. I verified it with the glReadPixels probe above rather than claim coverage I don't have.

Validation

  • Runtime — Win32 + OpenGL on real hardware (Intel UHD 620), before/after table above.
  • Compile — SamplesApp desktop head (net11.0-desktop).
  • Not verified: the same PresentForGL path serves X11, Android GLES and WebAssembly/WebGL. Those hosts are equally exposed if they touch GL state around present, but I only tested Win32.

🤖 Generated with Claude Code

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 236072 found UI Test snapshots differences: skia-linux-screenshots: 57, skia-windows-screenshots: 2310, wasm: 11

Details
  • skia-linux-screenshots: 57 changed over 2348

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ClipboardTests.png-dark
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • ContextRequested.png-dark
    • ContextRequested.png
    • Focus_FocusVisual_Properties.png-dark
    • DisplayInformation.png-dark
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • Image_AnimatedWebP.png-dark
    • Image_AnimatedWebP.png
    • DropDownButtonPage.png-dark
    • DropDownButtonPage.png
    • Examples.png-dark
    • Examples.png
    • ExpanderColorValidationPage.png-dark
  • skia-windows-screenshots: 2310 changed over 2500

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedIconPage.png
    • AppBar_KeyBoard.png-dark
    • ApplicationViewSizing.png
    • AppWindowPositionAndSize.png
    • AppXamlDefinedResources.png-dark
    • Attributed_text_FontSize_Changing.png-dark
    • AutoBorderStretchwithbottommargin.png-dark
    • AutoBorderStretchwithtopmargin.png
    • AutoSizedPathCentered.png
    • AutoSizedTopLeft.png-dark
    • AutoSuggestBox_SoftKeboard.png-dark
    • AutoSuggestBox_SoftKeboard.png
    • Basics_Automated.png-dark
    • Basics_Automated.png
    • BezierSegment.png-dark
    • BezierSegment.png
    • BitmapIcon_Foreground.png-dark
    • BitmapIcon_Foreground.png
    • BorderTopwithmargins.png-dark
    • BorderTopwithmargins.png
  • wasm: 11 changed over 1076

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListViewSelectedItems
    • UITests.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_NavigationProperties
    • SamplesApp.Wasm.Windows_UI_Xaml_Controls.ListView.ListView_IsSelected
    • UITests.Shared.Microsoft_UI_Xaml_Controls.ExpanderTests.WinUIExpanderPage
    • SamplesApp.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_EnableDevTools
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Minimal
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Ogg_Extension
    • UITests.Uno_Web.Http.CookieManagerTests
    • UITests.Windows_UI_Xaml_Controls.CalendarView.CalendarView_Theming
    • Uno.UI.Samples.Content.UITests.WebView.WebView_AnchorNavigation
    • UITests.Windows_UI_Xaml_Media_Animation.ColorAnimation_Background

A host that retains through its own framebuffer (Win32 OpenGL) blits with raw
GL calls at present, rebinding GL_FRAMEBUFFER behind Skia's back. Skia caches
GL state, so from the next frame it believed the host's framebuffer was still
bound and drew into the default one instead, while the blit kept copying the
retained framebuffer. The window showed whatever that framebuffer last legitimately
received: blank from startup, or frozen on the frame a resize happened to produce.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@ramezgerges
ramezgerges force-pushed the dev/rara/gl-reset-context branch from e68d826 to c4d5d91 Compare September 29, 2026 22:00
@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 236418 found UI Test snapshots differences: skia-linux-screenshots: 57, skia-windows-screenshots: 2304, wasm: 11

Details
  • skia-linux-screenshots: 57 changed over 2348

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Buttons.png-dark
    • Buttons.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • ClipboardTests.png-dark
    • DisplayInformation.png-dark
    • ContextRequested.png-dark
    • ContextRequested.png
    • DropDownButtonPage.png-dark
    • DropDownButtonPage.png
    • Focus_FocusVisual_Properties.png-dark
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • Examples.png-dark
    • Examples.png
    • ExpanderColorValidationPage.png-dark
    • ExpanderColorValidationPage.png
    • Gamepad_CurrentReading.png-dark
  • skia-windows-screenshots: 2304 changed over 2502

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedIconPage.png
    • AppBar_KeyBoard.png-dark
    • ApplicationViewMode.png
    • AppWindowPositionAndSize.png
    • AppXamlDefinedResources.png-dark
    • Attributed_text_FontSize_Changing.png
    • AutoBorderStretchwithleftmargin.png-dark
    • AutomationPropertiesExtensions_Role.png
    • AutoSizedTopLeft.png-dark
    • AutoSizedTopLeft.png
    • AutoSuggestBox_Reason.png-dark
    • AutoSuggestBox_Reason.png
    • BasicEnability.png-dark
    • BasicEnability.png
    • BeginTime_MultipleAnimations.png-dark
    • BeginTime_MultipleAnimations.png
    • BitmapIcon_Monochromatic.png-dark
    • BitmapIcon_Monochromatic.png
    • BitmapImage_vs_SvgImageSource.png-dark
    • BitmapImage_vs_SvgImageSource.png
  • wasm: 11 changed over 1076

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • SamplesApp.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_EnableDevTools
    • SamplesApp.Windows_UI_Xaml_Controls.ListView.ListViewSelectedItems
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Minimal
    • UITests.Shared.Windows_UI_Xaml_Controls.MediaPlayerElement.MediaPlayerElement_Ogg_Extension
    • UITests.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_NavigationProperties
    • UITests.Shared.Microsoft_UI_Xaml_Controls.ExpanderTests.WinUIExpanderPage
    • SamplesApp.Wasm.Windows_UI_Xaml_Controls.ListView.ListView_IsSelected
    • UITests.Windows_UI_Xaml_Controls.CalendarView.CalendarView_Theming
    • UITests.Uno_Web.Http.CookieManagerTests
    • Uno.UI.Samples.Content.UITests.WebView.WebView_AnchorNavigation
    • UITests.Windows_UI_Xaml_Media_Animation.ColorAnimation_Background

@mergify

mergify Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@MartinZikmund
MartinZikmund merged commit eee4d60 into unoplatform:master Sep 30, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Skia][Win32] OpenGL backend renders a blank window that freezes after a resize (Skia GL state cache not reset around the host's blit)

5 participants