From 74ec7c89f02cd3d5580da2b041e234035b9563b1 Mon Sep 17 00:00:00 2001 From: Erik Simon Date: Sun, 2 Aug 2026 14:16:26 +0200 Subject: [PATCH] Stop position-only animations from invalidating the texture caches ChromePassElement::draw() rounded its device-space box with CBox::round(), which derives the size from the two rounded corners - round(x + w) - round(x) - making the rounded width and height a function of the *position's* fractional part. A box merely sliding at a constant size therefore has its size flip by a pixel every few frames. Every one of those flips misses the cachedTexSize check in GetBorderTexture, GetShadowTexture and GetTitleTexture alike, and each miss is a full cairo re-render plus a fresh GPU texture allocation and upload for content that did not change appearance at all. That is exactly what a workspace switch, a window move, or any other position-only animation does - every frame, for every window on screen - and it is why those animations stutter. Measured against hyprutils, a sliding window resized nothing yet rebuilt its textures on 18-40% of frames at scale 1.0/1.25/1.5/1.6 (integer scales happened to be stable); rounding the size on its own takes all of those to zero. What round()'s coupling buys is a far edge landing on the same device pixel as an adjacent box's near edge. Nothing abuts this box - it is a free-floating decoration drawn over everything - so there is no seam here to keep closed. damageEntire() gains a one-pixel margin to match: with position and size now rounded separately, the drawn box's far edge can land up to a device pixel past where the logical damage box scales to. Co-Authored-By: Claude Opus 5 --- src/ChromeDecoration.cpp | 7 ++++++- src/ChromePassElement.cpp | 21 ++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/ChromeDecoration.cpp b/src/ChromeDecoration.cpp index 627f9b7..eb2a7cc 100644 --- a/src/ChromeDecoration.cpp +++ b/src/ChromeDecoration.cpp @@ -460,7 +460,12 @@ void ChromeDecoration::damageEntire() { // The shadow hangs outside the decoration's own box (it's drawn, not // reserved - see ShadowMarginLogical), so damaging just that box would // leave its outer reaches stale. - g_pHyprRenderer->damageBox(FullDecorationExtentGlobal().expand(ShadowMarginLogical())); + // + // The extra pixel covers the gap ChromePassElement::draw()'s rounding can + // open: it rounds the device-space position and size separately, so the + // box's far edge can land up to a device pixel past where this logical box + // scales to. One logical px is at least that much on any scale >= 1. + g_pHyprRenderer->damageBox(FullDecorationExtentGlobal().expand(ShadowMarginLogical() + 1.0)); } double ChromeDecoration::ShadowMarginLogical() { diff --git a/src/ChromePassElement.cpp b/src/ChromePassElement.cpp index df3e4a1..f757dca 100644 --- a/src/ChromePassElement.cpp +++ b/src/ChromePassElement.cpp @@ -21,7 +21,26 @@ std::vector> ChromePassElement::draw() { return {}; auto box = data.decoration->FullDecorationExtentGlobal(); - box.translate(-monitor->m_position).scale(monitor->m_scale).round(); + box.translate(-monitor->m_position).scale(monitor->m_scale); + + // Round the position and the size independently, rather than via + // CBox::round(). That derives the size from the two *rounded corners* + // (round(x + w) - round(x)), which makes it a function of the position's + // fractional part - so a box that is merely sliding, at a perfectly + // constant size, has its rounded w/h flip by a pixel every few frames. + // Every one of those flips misses the caches in GetBorderTexture / + // GetShadowTexture / GetTitleTexture, each miss being a full cairo + // re-render plus a GPU re-upload of a texture that didn't actually change + // appearance - which is precisely what a workspace switch, a window move, + // or any other position-only animation does, every frame, for every window + // on screen. Rounded on its own, the size stays a pure function of the + // window's own size and can't be perturbed by translation at all. + // + // What round()'s coupling buys is a far edge that lands on the same device + // pixel as an adjacent box's near edge. Nothing abuts this box - it's a + // free-floating decoration drawn over everything - so there is no seam here + // to keep closed. + box = CBox{box.pos().round(), box.size().round()}; if (box.w < 1 || box.h < 1) return {};