From 9c9f56743eb450df4a67904a547ccf900fbe8fb0 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Tue, 11 Jul 2023 20:57:33 +0200 Subject: [PATCH] groupbar: fix vram leak --- .../decorations/CHyprGroupBarDecoration.cpp | 32 ++++--------------- .../decorations/CHyprGroupBarDecoration.hpp | 7 +++- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/src/render/decorations/CHyprGroupBarDecoration.cpp b/src/render/decorations/CHyprGroupBarDecoration.cpp index 9a544023c..43c944045 100644 --- a/src/render/decorations/CHyprGroupBarDecoration.cpp +++ b/src/render/decorations/CHyprGroupBarDecoration.cpp @@ -4,9 +4,8 @@ #include // shared things to conserve VRAM -static std::deque> m_dpTitleTextures; -static CTexture m_tGradientActive; -static CTexture m_tGradientInactive; +static CTexture m_tGradientActive; +static CTexture m_tGradientInactive; CHyprGroupBarDecoration::CHyprGroupBarDecoration(CWindow* pWindow) { m_pWindow = pWindow; @@ -135,7 +134,7 @@ void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a, const Vector2D& if (!pTitleTex) pTitleTex = - m_dpTitleTextures + m_sTitleTexs.titleTexs .emplace_back(std::make_unique(m_dwGroupMembers[i], Vector2D{BARW * pMonitor->scale, (*PTITLEFONTSIZE + 2 * BAR_TEXT_PAD) * pMonitor->scale})) .get(); @@ -159,7 +158,7 @@ void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a, const Vector2D& } if (*PRENDERTITLES) - clearUnusedTextures(); + invalidateTextures(); } SWindowDecorationExtents CHyprGroupBarDecoration::getWindowDecorationReservedArea() { @@ -169,7 +168,7 @@ SWindowDecorationExtents CHyprGroupBarDecoration::getWindowDecorationReservedAre } CTitleTex* CHyprGroupBarDecoration::textureFromTitle(const std::string& title) { - for (auto& tex : m_dpTitleTextures) { + for (auto& tex : m_sTitleTexs.titleTexs) { if (tex->szContent == title) return tex.get(); } @@ -177,27 +176,8 @@ CTitleTex* CHyprGroupBarDecoration::textureFromTitle(const std::string& title) { return nullptr; } -void CHyprGroupBarDecoration::clearUnusedTextures() { - for (auto& tex : m_dpTitleTextures | std::views::reverse) { - bool found = false; - - for (auto& w : g_pCompositor->m_vWindows) { - if (!w->m_sGroupData.pNextWindow) - continue; - - if (tex->szContent == w->m_szTitle && tex->pWindowOwner == w.get()) { - found = true; - break; - } - } - - if (!found) - std::erase(m_dpTitleTextures, tex); - } -} - void CHyprGroupBarDecoration::invalidateTextures() { - m_dpTitleTextures.clear(); + m_sTitleTexs.titleTexs.clear(); } CTitleTex::CTitleTex(CWindow* pWindow, const Vector2D& bufferSize) { diff --git a/src/render/decorations/CHyprGroupBarDecoration.hpp b/src/render/decorations/CHyprGroupBarDecoration.hpp index d8b0f46aa..ac6d103f4 100644 --- a/src/render/decorations/CHyprGroupBarDecoration.hpp +++ b/src/render/decorations/CHyprGroupBarDecoration.hpp @@ -4,6 +4,7 @@ #include #include "../Texture.hpp" #include +#include class CTitleTex { public: @@ -43,8 +44,12 @@ class CHyprGroupBarDecoration : public IHyprWindowDecoration { std::deque m_dwGroupMembers; CTitleTex* textureFromTitle(const std::string&); - void clearUnusedTextures(); void invalidateTextures(); void refreshGradients(); + + struct STitleTexs { + // STitleTexs* overriden = nullptr; // TODO: make shit shared in-group to decrease VRAM usage. + std::deque> titleTexs; + } m_sTitleTexs; }; \ No newline at end of file