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.
This commit is contained in:
Tom Englund 2025-09-27 02:50:40 +02:00 committed by Vaxry
parent c30036bdac
commit b627885788
5 changed files with 20 additions and 15 deletions

View file

@ -147,7 +147,7 @@ SBoxExtents CWindow::getFullWindowExtents() {
SBoxExtents maxExtents = {.topLeft = {BORDERSIZE + 2, BORDERSIZE + 2}, .bottomRight = {BORDERSIZE + 2, BORDERSIZE + 2}}; 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); 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 CWindow::getWindowExtentsUnified(uint64_t properties) {
SBoxExtents extents = {.topLeft = {0, 0}, .bottomRight = {0, 0}}; SBoxExtents extents = {.topLeft = {0, 0}, .bottomRight = {0, 0}};
if (properties & RESERVED_EXTENTS) if (properties & RESERVED_EXTENTS)
extents.addExtents(g_pDecorationPositioner->getWindowDecorationReserved(m_self.lock())); extents.addExtents(g_pDecorationPositioner->getWindowDecorationReserved(m_self));
if (properties & INPUT_EXTENTS) 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) if (properties & FULL_EXTENTS)
extents.addExtents(g_pDecorationPositioner->getWindowDecorationExtents(m_self.lock(), false)); extents.addExtents(g_pDecorationPositioner->getWindowDecorationExtents(m_self, false));
return extents; return extents;
} }
@ -264,7 +264,7 @@ CBox CWindow::getWindowBoxUnified(uint64_t properties) {
} }
SBoxExtents CWindow::getFullWindowReservedArea() { SBoxExtents CWindow::getFullWindowReservedArea() {
return g_pDecorationPositioner->getWindowDecorationReserved(m_self.lock()); return g_pDecorationPositioner->getWindowDecorationReserved(m_self);
} }
void CWindow::updateWindowDecos() { void CWindow::updateWindowDecos() {

View file

@ -34,7 +34,7 @@ void CHyprBorderDecoration::onPositioningReply(const SDecorationPositioningReply
CBox CHyprBorderDecoration::assignedBoxGlobal() { CBox CHyprBorderDecoration::assignedBoxGlobal() {
CBox box = m_assignedGeometry; 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; const auto PWORKSPACE = m_window->m_workspace;

View file

@ -596,7 +596,7 @@ std::string CHyprGroupBarDecoration::getDisplayName() {
CBox CHyprGroupBarDecoration::assignedBoxGlobal() { CBox CHyprGroupBarDecoration::assignedBoxGlobal() {
CBox box = m_assignedBox; 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; const auto PWORKSPACE = m_window->m_workspace;

View file

@ -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 TOP = edges & DECORATION_EDGE_TOP;
const bool BOTTOM = edges & DECORATION_EDGE_BOTTOM; const bool BOTTOM = edges & DECORATION_EDGE_BOTTOM;
const bool LEFT = edges & DECORATION_EDGE_LEFT; const bool LEFT = edges & DECORATION_EDGE_LEFT;
@ -286,14 +291,14 @@ void CDecorationPositioner::onWindowMap(PHLWINDOW pWindow) {
m_windowDatas[pWindow] = {}; m_windowDatas[pWindow] = {};
} }
SBoxExtents CDecorationPositioner::getWindowDecorationReserved(PHLWINDOW pWindow) { SBoxExtents CDecorationPositioner::getWindowDecorationReserved(PHLWINDOWREF pWindow) {
try { try {
const auto E = m_windowDatas.at(pWindow); const auto E = m_windowDatas.at(pWindow);
return E.reserved; return E.reserved;
} catch (std::out_of_range& e) { return {}; } } 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 const mainSurfaceBox = pWindow->getWindowMainSurfaceBox();
CBox accum = mainSurfaceBox; CBox accum = mainSurfaceBox;
@ -301,7 +306,7 @@ SBoxExtents CDecorationPositioner::getWindowDecorationExtents(PHLWINDOW pWindow,
if (!data->pDecoration || (inputOnly && !(data->pDecoration->getDecorationFlags() & DECORATION_ALLOWS_MOUSE_INPUT))) if (!data->pDecoration || (inputOnly && !(data->pDecoration->getDecorationFlags() & DECORATION_ALLOWS_MOUSE_INPUT)))
continue; continue;
auto const window = data->pWindow.lock(); auto const window = data->pWindow;
if (!window || window != pWindow) if (!window || window != pWindow)
continue; continue;

View file

@ -59,13 +59,13 @@ class CDecorationPositioner {
public: public:
CDecorationPositioner(); 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 // called on resize, or insert/removal of a new deco
void onWindowUpdate(PHLWINDOW pWindow); void onWindowUpdate(PHLWINDOW pWindow);
void uncacheDecoration(IHyprWindowDecoration* deco); void uncacheDecoration(IHyprWindowDecoration* deco);
SBoxExtents getWindowDecorationReserved(PHLWINDOW pWindow); SBoxExtents getWindowDecorationReserved(PHLWINDOWREF pWindow);
SBoxExtents getWindowDecorationExtents(PHLWINDOW pWindow, bool inputOnly = false); SBoxExtents getWindowDecorationExtents(PHLWINDOWREF pWindow, bool inputOnly = false);
CBox getBoxWithIncludedDecos(PHLWINDOW pWindow); CBox getBoxWithIncludedDecos(PHLWINDOW pWindow);
void repositionDeco(IHyprWindowDecoration* deco); void repositionDeco(IHyprWindowDecoration* deco);
CBox getWindowDecorationBox(IHyprWindowDecoration* deco); CBox getWindowDecorationBox(IHyprWindowDecoration* deco);
@ -96,4 +96,4 @@ class CDecorationPositioner {
void sanitizeDatas(); void sanitizeDatas();
}; };
inline UP<CDecorationPositioner> g_pDecorationPositioner; inline UP<CDecorationPositioner> g_pDecorationPositioner;