Skip to content

fix(framebuffer): Draw DRM frames before flipping - #25060

Merged
MartinZikmund merged 1 commit into
unoplatform:masterfrom
ramezgerges:dev/rara/drm-draw-then-flip
Oct 8, 2026
Merged

MartinZikmund merged 1 commit into
unoplatform:masterfrom
ramezgerges:dev/rara/drm-draw-then-flip

Conversation

@ramezgerges

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #24505

PR Type:

🐞 Bugfix

What changed? 🚀

On the Linux framebuffer host with KMS/DRM, an update that isn't followed by another invalidation (e.g. a DispatcherTimer setting a TextBlock) was shown one update late. A focused TextBox's caret blink masked it by invalidating continuously.

Cause (DRMRenderer):

  • InvalidateRender did not draw; it swapped and flipped whatever the page-flip handler had pre-drawn after the previous flip. That buffer was drawn before the content it was answering existed.
  • A request arriving while a flip was in flight set a pending flag, but the flip handler cleared that flag before drawing, so the request was lost and the freshly drawn frame was never flipped.

Trace from the issue's sample, one 5 s tick:

47.253 Invalidate -> swap+flip      // RequestNewFrame: presents the stale pre-drawn buffer
47.256 Invalidate -> deferred       // new picture recorded during the flip
47.270 PageFlip done -> Render      // pending flag cleared, then the new picture is drawn...
47.273 Render done, pending=False   // ...and never flipped

Fix:

  • InvalidateRender draws, then flips (DrawAndFlip), the same order the fbdev SoftwareRenderer already uses.
  • The two flags become a single _flipState (idle / in flight / in flight with a pending request), changed only by compare-and-swap. A request made during a flip is always served when that flip lands. Previously it could slip between the handler's "nothing pending" check and its return to idle.
  • OnPageFlipCore no longer draws ahead; it serves a pending request or returns to idle.
  • Both paths return to idle on failure, so a failed draw or flip can no longer leave the flip gate shut.

Validation:

  • Runtime: the issue's sample (Uno.Sdk 6.6.42) in a QEMU VM on virtio-gpu, with DRM active, 16 screenshots per run. The same state machine was ported into a 6.6 build of the framebuffer runtime, because master's runtime can't load into a 6.6.42 app.
    • Before the fix, every screenshot showed the previous tick.
    • After the fix, every screenshot showed the current tick, with instant flips (QEMU's default) and with a 16 ms flip delay emulating a 60 Hz display.
  • Compile: Uno.UI.Runtime.Linux.FrameBuffer on master, analyzers on.
  • Not covered at runtime: the lost-request race is too narrow to reproduce on purpose. Its fix rests on review of the compare-and-swap transitions.

Note: a request that arrives with no flip in flight now draws on the calling thread, usually the UI thread. That thread already performed the swap and flip before this change.

PR Checklist ✅

No runtime test: CI doesn't exercise DRMRenderer. On the Linux Framebuffer lane, DRM init fails (drmModeAddFB2 failed -22) and the host falls back to the software renderer, so a test there would not cover this change.

🤖 Generated with Claude Code

Fixes unoplatform#24505.

The page-flip handler drew ahead of the next request, so each flip
presented a buffer drawn before the content it answered existed, and a
request arriving mid-flip was cleared before it was checked. Content
updates without follow-up invalidations stayed one frame behind.

Draw at the request, then flip, and track flip state in one word so a
request made during a flip is always served when it lands.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@github-actions github-actions Bot added the area/skia ✏️ Categorizes an issue or PR as relevant to Skia label Oct 6, 2026
@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 237768 found UI Test snapshots differences: skia-linux-screenshots: 130, skia-windows-screenshots: 253

Details
  • skia-linux-screenshots: 130 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AutomationProperties_AutomationId.png-dark
    • AutomationProperties_AutomationId.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • CalendarView_Theming.png-dark
    • ColorPickerSample.png-dark
    • ColorPickerSample.png
    • Buttons.png-dark
    • Buttons.png
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • ClipboardTests.png-dark
    • CompositionPath.png-dark
    • CompositionPath.png
    • DoubleImageBrushInList.png-dark
    • DoubleImageBrushInList.png
    • DisplayInformation.png-dark
    • DynamicFont.png-dark
  • skia-windows-screenshots: 253 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • DisplayInformation.png-dark
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • ElementLevelTheme.png-dark
    • ElementLevelTheme.png
    • Grid_DynamicRowColumn.png-dark
    • Grid_DynamicRowColumn.png
    • Grid_with_attributed_string.png-dark
    • Grid_with_attributed_string.png
    • Grid_with_Fixed_Size.png-dark
    • Grid_with_Fixed_Size.png
    • Grid_with_MinWidthColumns.png-dark

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 237768 has failed on Uno.UI - CI.

@mergify

mergify Bot commented Oct 7, 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 dd7e0a7 into unoplatform:master Oct 8, 2026
51 checks passed
@ramezgerges
ramezgerges deleted the dev/rara/drm-draw-then-flip branch October 8, 2026 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/skia ✏️ Categorizes an issue or PR as relevant to Skia

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Skia/Linux Framebuffer] Rendering is one frame behind

4 participants