From b627885788acbab4c768632f800e010467ffbaf9 Mon Sep 17 00:00:00 2001 From: Tom Englund Date: Sat, 27 Sep 2025 02:50:40 +0200 Subject: [PATCH] decoration: reduce virtual calls this shows up as top contender in idle cpu usage, because decos in animations keeps locking weak pointers to shared pointers per window per frame when its not really needed, use weakpointers all the way and it drops to a bottom contender. marginal gains in the big picture. but gains is gains. --- src/desktop/Window.cpp | 10 +++++----- src/render/decorations/CHyprBorderDecoration.cpp | 2 +- src/render/decorations/CHyprGroupBarDecoration.cpp | 2 +- src/render/decorations/DecorationPositioner.cpp | 13 +++++++++---- src/render/decorations/DecorationPositioner.hpp | 8 ++++---- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp index ba0f09d5..49b1b698 100644 --- a/src/desktop/Window.cpp +++ b/src/desktop/Window.cpp @@ -147,7 +147,7 @@ SBoxExtents CWindow::getFullWindowExtents() { SBoxExtents maxExtents = {.topLeft = {BORDERSIZE + 2, BORDERSIZE + 2}, .bottomRight = {BORDERSIZE + 2, BORDERSIZE + 2}}; - const auto EXTENTS = g_pDecorationPositioner->getWindowDecorationExtents(m_self.lock()); + const auto EXTENTS = g_pDecorationPositioner->getWindowDecorationExtents(m_self); maxExtents.topLeft.x = std::max(EXTENTS.topLeft.x, maxExtents.topLeft.x); @@ -241,11 +241,11 @@ CBox CWindow::getWindowIdealBoundingBoxIgnoreReserved() { SBoxExtents CWindow::getWindowExtentsUnified(uint64_t properties) { SBoxExtents extents = {.topLeft = {0, 0}, .bottomRight = {0, 0}}; if (properties & RESERVED_EXTENTS) - extents.addExtents(g_pDecorationPositioner->getWindowDecorationReserved(m_self.lock())); + extents.addExtents(g_pDecorationPositioner->getWindowDecorationReserved(m_self)); if (properties & INPUT_EXTENTS) - extents.addExtents(g_pDecorationPositioner->getWindowDecorationExtents(m_self.lock(), true)); + extents.addExtents(g_pDecorationPositioner->getWindowDecorationExtents(m_self, true)); if (properties & FULL_EXTENTS) - extents.addExtents(g_pDecorationPositioner->getWindowDecorationExtents(m_self.lock(), false)); + extents.addExtents(g_pDecorationPositioner->getWindowDecorationExtents(m_self, false)); return extents; } @@ -264,7 +264,7 @@ CBox CWindow::getWindowBoxUnified(uint64_t properties) { } SBoxExtents CWindow::getFullWindowReservedArea() { - return g_pDecorationPositioner->getWindowDecorationReserved(m_self.lock()); + return g_pDecorationPositioner->getWindowDecorationReserved(m_self); } void CWindow::updateWindowDecos() { diff --git a/src/render/decorations/CHyprBorderDecoration.cpp b/src/render/decorations/CHyprBorderDecoration.cpp index 0bf1f16a..75298ff7 100644 --- a/src/render/decorations/CHyprBorderDecoration.cpp +++ b/src/render/decorations/CHyprBorderDecoration.cpp @@ -34,7 +34,7 @@ void CHyprBorderDecoration::onPositioningReply(const SDecorationPositioningReply CBox CHyprBorderDecoration::assignedBoxGlobal() { CBox box = m_assignedGeometry; - box.translate(g_pDecorationPositioner->getEdgeDefinedPoint(DECORATION_EDGE_BOTTOM | DECORATION_EDGE_LEFT | DECORATION_EDGE_RIGHT | DECORATION_EDGE_TOP, m_window.lock())); + box.translate(g_pDecorationPositioner->getEdgeDefinedPoint(DECORATION_EDGE_BOTTOM | DECORATION_EDGE_LEFT | DECORATION_EDGE_RIGHT | DECORATION_EDGE_TOP, m_window)); const auto PWORKSPACE = m_window->m_workspace; diff --git a/src/render/decorations/CHyprGroupBarDecoration.cpp b/src/render/decorations/CHyprGroupBarDecoration.cpp index 10f1503a..49fcd347 100644 --- a/src/render/decorations/CHyprGroupBarDecoration.cpp +++ b/src/render/decorations/CHyprGroupBarDecoration.cpp @@ -596,7 +596,7 @@ std::string CHyprGroupBarDecoration::getDisplayName() { CBox CHyprGroupBarDecoration::assignedBoxGlobal() { CBox box = m_assignedBox; - box.translate(g_pDecorationPositioner->getEdgeDefinedPoint(DECORATION_EDGE_TOP, m_window.lock())); + box.translate(g_pDecorationPositioner->getEdgeDefinedPoint(DECORATION_EDGE_TOP, m_window)); const auto PWORKSPACE = m_window->m_workspace; diff --git a/src/render/decorations/DecorationPositioner.cpp b/src/render/decorations/DecorationPositioner.cpp index 760a9a33..1082812f 100644 --- a/src/render/decorations/DecorationPositioner.cpp +++ b/src/render/decorations/DecorationPositioner.cpp @@ -15,7 +15,12 @@ CDecorationPositioner::CDecorationPositioner() { }); } -Vector2D CDecorationPositioner::getEdgeDefinedPoint(uint32_t edges, PHLWINDOW pWindow) { +Vector2D CDecorationPositioner::getEdgeDefinedPoint(uint32_t edges, PHLWINDOWREF pWindow) { + if (!pWindow) { + Debug::log(ERR, "getEdgeDefinedPoint: invalid pWindow"); + return {}; + } + const bool TOP = edges & DECORATION_EDGE_TOP; const bool BOTTOM = edges & DECORATION_EDGE_BOTTOM; const bool LEFT = edges & DECORATION_EDGE_LEFT; @@ -286,14 +291,14 @@ void CDecorationPositioner::onWindowMap(PHLWINDOW pWindow) { m_windowDatas[pWindow] = {}; } -SBoxExtents CDecorationPositioner::getWindowDecorationReserved(PHLWINDOW pWindow) { +SBoxExtents CDecorationPositioner::getWindowDecorationReserved(PHLWINDOWREF pWindow) { try { const auto E = m_windowDatas.at(pWindow); return E.reserved; } catch (std::out_of_range& e) { return {}; } } -SBoxExtents CDecorationPositioner::getWindowDecorationExtents(PHLWINDOW pWindow, bool inputOnly) { +SBoxExtents CDecorationPositioner::getWindowDecorationExtents(PHLWINDOWREF pWindow, bool inputOnly) { CBox const mainSurfaceBox = pWindow->getWindowMainSurfaceBox(); CBox accum = mainSurfaceBox; @@ -301,7 +306,7 @@ SBoxExtents CDecorationPositioner::getWindowDecorationExtents(PHLWINDOW pWindow, if (!data->pDecoration || (inputOnly && !(data->pDecoration->getDecorationFlags() & DECORATION_ALLOWS_MOUSE_INPUT))) continue; - auto const window = data->pWindow.lock(); + auto const window = data->pWindow; if (!window || window != pWindow) continue; diff --git a/src/render/decorations/DecorationPositioner.hpp b/src/render/decorations/DecorationPositioner.hpp index 7189db41..8048c7ad 100644 --- a/src/render/decorations/DecorationPositioner.hpp +++ b/src/render/decorations/DecorationPositioner.hpp @@ -59,13 +59,13 @@ class CDecorationPositioner { public: CDecorationPositioner(); - Vector2D getEdgeDefinedPoint(uint32_t edges, PHLWINDOW pWindow); + Vector2D getEdgeDefinedPoint(uint32_t edges, PHLWINDOWREF pWindow); // called on resize, or insert/removal of a new deco void onWindowUpdate(PHLWINDOW pWindow); void uncacheDecoration(IHyprWindowDecoration* deco); - SBoxExtents getWindowDecorationReserved(PHLWINDOW pWindow); - SBoxExtents getWindowDecorationExtents(PHLWINDOW pWindow, bool inputOnly = false); + SBoxExtents getWindowDecorationReserved(PHLWINDOWREF pWindow); + SBoxExtents getWindowDecorationExtents(PHLWINDOWREF pWindow, bool inputOnly = false); CBox getBoxWithIncludedDecos(PHLWINDOW pWindow); void repositionDeco(IHyprWindowDecoration* deco); CBox getWindowDecorationBox(IHyprWindowDecoration* deco); @@ -96,4 +96,4 @@ class CDecorationPositioner { void sanitizeDatas(); }; -inline UP g_pDecorationPositioner; \ No newline at end of file +inline UP g_pDecorationPositioner;