Keep floating window moves pixel-stable
Round fitted window frames to whole logical pixels and accumulate drag deltas from the gesture start. This prevents floating-point size noise from rebuilding window content while preserving fractional pointer movement and resizing behavior.
This commit is contained in:
@@ -100,3 +100,115 @@ this scenario, not content.
|
||||
(`drag=483,523>120,80`), and a page pushed inside a window (click `page`) then
|
||||
dragged: the content must follow the window, stay inside it, and show no stale
|
||||
or clipped frame.
|
||||
|
||||
## Whole-pixel frames
|
||||
|
||||
Follow-up: after the change above, a drag still built and laid out every
|
||||
window's content on every pointer event (14-17 ms of build per frame in the
|
||||
browser bench). A `Rect` stores left, top, right and bottom, so shifting a
|
||||
fractional frame changes its width in the last bits (`360.00000000000006`), and
|
||||
`WindowPageBox` puts that size in a `MediaQuery`: every `MediaQuery` dependent
|
||||
rebuilt and laid out again on every move. The layer also regenerated its page
|
||||
theme on every frame, because Material's animated theme hands over a new but
|
||||
equal `ThemeData` object and `_pageThemeFor` compared with `identical`, so every
|
||||
theme dependent rebuilt too.
|
||||
|
||||
### Change
|
||||
|
||||
`lib/shell/windows/`:
|
||||
|
||||
- `window_entry.dart`: `fitWindowFrame` rounds left, top, width and height to
|
||||
whole logical pixels after clamping, keeping the frame inside the bounds and
|
||||
at the minimum size. A fractional minimum rounds up, so a whole-pixel frame is
|
||||
never smaller than the minimum the kind asked for (the bounds still win when
|
||||
they cannot hold it). Whole numbers add and subtract exactly, so a moved
|
||||
window keeps exactly its size.
|
||||
- `window_layer.dart`: `_WindowLayerState` remembers the frame a move or resize
|
||||
started from and the pointer delta summed since, and sets the frame from
|
||||
`start + total` on every event, so rounding one fractional step after another
|
||||
cannot lose part of the pointer's movement or drift. The drag state is
|
||||
cleared in `_moveEnded`, in the corner's `onPanEnd` (`_resizeEnded`, which
|
||||
still calls `manager.commit`) and on pointer down.
|
||||
- `window_layer.dart`: `_pageThemeFor` reuses the cached page theme when the app
|
||||
theme is `==` to the last one, not only identical, so an equal theme from an
|
||||
animation does not notify every content widget.
|
||||
|
||||
Snapping, `manager.commit`, `windowSnapRect` (still fractional where the bounds
|
||||
are) and a maximised frame are unchanged.
|
||||
|
||||
### Tests
|
||||
|
||||
`test/shell/windows/window_rebuild_test.dart`:
|
||||
|
||||
- dragging a title by eight `Offset(10.3, 4.7)` moves with
|
||||
`debugOnRebuildDirtyWidget` (reset in a `finally`): no `TextButton`,
|
||||
`ListView` or `Scrollable` element inside either window's content rebuilds,
|
||||
the `WindowFrame` size stays exactly `360x420` after every move, and the
|
||||
window ends within 1 px of `start + 8 x (10.3, 4.7)` (`100,80` -> `182,118`);
|
||||
- resizing by five `Offset(-10.3, -6.7)` moves: every frame is a whole-pixel
|
||||
size, the other window does not rebuild, and the resized window's content
|
||||
rebuilds with the new `MediaQuery` size (within 1 px of
|
||||
`360x420 - 5 x (10.3, 6.7)`).
|
||||
|
||||
`test/shell/windows/window_store_test.dart` also pins the fit: a fractional
|
||||
minimum (`320.1x240.4`) yields a whole-pixel `321x241` frame, and bounds smaller
|
||||
than that minimum (`319.6x239.2`) yield `319x239` instead of exceeding the area.
|
||||
|
||||
Against the old lib (lib/shell/windows changes stashed, tests unchanged): 2
|
||||
failed - the drag rebuilt `ListView`, `Scrollable` and `TextButton` at move 1,
|
||||
and the first resize move gave a fractional `349.70000000000005` width. The new
|
||||
code passes all 5.
|
||||
|
||||
### Browser bench
|
||||
|
||||
Built after (`build/probe-app`) and before (`build/probe-before`, lib change
|
||||
stashed):
|
||||
|
||||
```
|
||||
/Users/alan/development/flutter/bin/flutter build web \
|
||||
--target tool/search_selection_probe_entry.dart --output build/probe-app
|
||||
/Users/alan/development/flutter/bin/flutter build web \
|
||||
--target tool/search_selection_probe_entry.dart --output build/probe-before
|
||||
```
|
||||
|
||||
Then, from `app/`:
|
||||
|
||||
```
|
||||
node tool/perf/interaction_bench.mjs --build build/probe-before --out /tmp/bench \
|
||||
--gpu --repeat 3 --only 'desktop: drag a probe window'
|
||||
node tool/perf/interaction_bench.mjs --build build/probe-app --out /tmp/bench \
|
||||
--gpu --repeat 3 --only 'desktop: drag a probe window'
|
||||
```
|
||||
|
||||
The machine was shared with other pipeline test runs (load average 11.8-75.7
|
||||
during the rounds; `ms/frame = buildSum / frames`):
|
||||
|
||||
| round | load | code | frames | buildSum | ms/frame | buildMax | longest | over16 |
|
||||
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
||||
| 1 | 22.1 | before | 54 | 995.1 | 18.4 | 77.8 | 80.4 | 29 |
|
||||
| 1 | 22.1 | after | 42 | 419.2 | 10.0 | 25.8 | 30.3 | 11 |
|
||||
| 2 | 11.8 | before | 51 | 489.8 | 9.6 | 20.2 | 22.4 | 3 |
|
||||
| 2 | 11.8 | after | 42 | 549.8 | 13.1 | 44.4 | 59.7 | 14 |
|
||||
| 3 | 75.7 | before | 48 | 4590.1 | 95.6 | 320.0 | 437.1 | 44 |
|
||||
| 3 | 75.7 | after | 42 | 1741.3 | 41.5 | 136.3 | 148.9 | 36 |
|
||||
|
||||
The browser numbers stay indicative on this loaded machine: round 2 has the
|
||||
before build ahead, while rounds 1 and 3 (including the heavily loaded one)
|
||||
show the after build at about half the build time per frame. The deterministic
|
||||
result is the widget test: a fractional drag no longer rebuilds any content,
|
||||
and the window size is bit-identical from frame to frame.
|
||||
|
||||
### Checks
|
||||
|
||||
- `tool/memwatch/full.sh 'test/shell/windows test/features/chat/chat_floating_pane_test.dart test/features/terminal'`:
|
||||
121 passed, 0 failed.
|
||||
- `tool/analyze.sh`: clean.
|
||||
|
||||
### Affected UI states (for ui-review)
|
||||
|
||||
`/runs?windows=2` at 1280x800 light: drag the top window by its title
|
||||
(`drag=250,132>301,153`), then resize it by its corner: the title bar, body and
|
||||
edges must stay aligned with no gap or overlap of a pixel, the content must not
|
||||
reflow during the drag, and the resize corner must stay on the window's lower
|
||||
right corner.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user