From f738fbd4f8754ae83c720a5b3cb81e8dc3315ee5 Mon Sep 17 00:00:00 2001 From: waffle Date: Tue, 24 Jun 2025 22:28:57 +0200 Subject: [PATCH] gpui: Disable rounding in the layout engine (#31836) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rounding broke (among other things, probably) pixel-perfect image rendering with non-power-of-two scaling factor. An example which reproduces the problem can be found [here](https://github.com/WaffleLapkin/gpui_taffy_rounding_whyyyyy). How it looks with `gpui` from `main`: ![2025-05-31 11:34:25+CEST](https://github.com/user-attachments/assets/2cb19312-6ba6-4e80-8072-f89ddedff77b) How it looks with this patch: ![2025-05-31 11:35:28+CEST](https://github.com/user-attachments/assets/114b52a9-58c0-4600-871c-a20eceb7179e) Both screenshots are made on kde+wayland with magnification using kde's built-in magnification (`Meta`+`+`, `Meta`+`-`). Note that screenshot apps have a high chance of lying 🙃 The image itself is 400 by 300 pixels of red/green checkerboard pattern made specifically to exaggerate scaling issues. Release Notes: - N/A --- crates/editor/src/editor_tests.rs | 2 +- crates/gpui/src/taffy.rs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs index a6460a5048..7f4e19e7d4 100644 --- a/crates/editor/src/editor_tests.rs +++ b/crates/editor/src/editor_tests.rs @@ -15440,7 +15440,7 @@ async fn test_completions_default_resolve_data_handling(cx: &mut TestAppContext) // Completions that have already been resolved are skipped. assert_eq!( *resolved_items.lock(), - items[items.len() - 16..items.len() - 4] + items[items.len() - 17..items.len() - 4] .iter() .cloned() .map(|mut item| { diff --git a/crates/gpui/src/taffy.rs b/crates/gpui/src/taffy.rs index 597bff13e2..f12c62d504 100644 --- a/crates/gpui/src/taffy.rs +++ b/crates/gpui/src/taffy.rs @@ -28,8 +28,10 @@ const EXPECT_MESSAGE: &str = "we should avoid taffy layout errors by constructio impl TaffyLayoutEngine { pub fn new() -> Self { + let mut taffy = TaffyTree::new(); + taffy.disable_rounding(); TaffyLayoutEngine { - taffy: TaffyTree::new(), + taffy, absolute_layout_bounds: FxHashMap::default(), computed_layouts: FxHashSet::default(), }