Skip to content

fix(win32): gate resize-sync DComp detach on two DWM compositions and tick modal drag animations - #2753

Merged
Hona merged 1 commit into
devfrom
fix/win32-resize-sync-dwm-detach
Nov 28, 2026
Merged

Hona merged 1 commit into
devfrom
fix/win32-resize-sync-dwm-detach

Conversation

@Hona

@Hona Hona commented Nov 28, 2026

Copy link
Copy Markdown
Member

Addresses #2113

Root cause

  1. First-drag stale redirection surface flash: Between drags, Windows keeps the previous drag's last copy-model frame in the HWND's redirection surface underneath the re-attached DirectComposition tree. On a subsequent drag's first frame, a DXGI_SWAP_EFFECT_DISCARD Present(0, 0) submits its redirection-surface update to DWM asynchronously outside the D3D11 queue, so waiting on a post-present D3D11 fence does not guarantee DWM has ingested and composed the new bitmap before IDCompositionTarget::SetRoot(None) commits. For one refresh, DWM exposes the previous drag's stale redirection surface.
  2. Animations freezing while holding a drag edge: Inside Windows' modal size-move loop, about_to_wait never runs, so Redraw::Wants stays parked after the first paint and animations pause until the next WM_SIZE.

Changes

  • Explicit priming phase gated on DWM's composition count (machine.rs, frame.rs, resize_sync.rs, present.rs, platform/win32.rs):
    • Added DcompPhase::{Priming { presented_at }, Detached}, DETACH_DWM_FRAMES = 2, Event::DragFramePresented, and Effect::DetachDcomp.
    • BeginDrag renders and presents the first drag frame (waiting on the D3D11 post-present fence with WM_ERASEBKGND suppression active), samples DWM_TIMING_INFO::cFrame via DwmGetCompositionTimingInfo(NULL, ...), and keeps DirectComposition attached.
    • Subsequent drag frames stay in Priming until cFrame advances by at least 2 compositions (re-baselining on a counter reset, and falling back cleanly to normal DirectComposition resize if DWM timing is unavailable so the window never freezes attached). Once detached, steady-state frames skip DWM timing queries.
  • Demand-only modal drag tick timer (platform/win32/dpi_drag.rs, resize_sync.rs):
    • Arms an 8 ms WM_TIMER only on state edges while inside WM_ENTERSIZEMOVE..WM_EXITSIZEMOVE and either is_priming() or outcome.animating is true.
    • Invalidates with bErase = 0 so a paused first-step drag finishes detaching after 2 DWM compositions and live animations keep running while holding a border still, then kills the timer immediately once detached and idle (or on WM_EXITSIZEMOVE / cleanup / WM_NCDESTROY).
  • Tests (entry_tests.rs, tests.rs):
    • Added pure state-machine tests for 0/1/2 DWM frame gating, counter reset re-baselining, unavailable DWM count fallback, and quick exit while priming.
    • Added a multi-drag off-screen GPU/seam regression test verifying a second drag never detaches DirectComposition while the redirection surface still holds the first drag's stale frame.

Verification

@Hona
Hona merged commit b1878e6 into dev Nov 28, 2026
5 checks passed
@Hona
Hona deleted the fix/win32-resize-sync-dwm-detach branch November 28, 2026 12:23
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.

1 participant