diff options
| author | Vaxry <vaxry@vaxry.net> | 2024-04-30 02:41:27 +0100 |
|---|---|---|
| committer | Vaxry <vaxry@vaxry.net> | 2024-04-30 02:41:27 +0100 |
| commit | 5edc32930d85f5f481160b938965c8bc329487e7 (patch) | |
| tree | 3609cb2bebd1f72e17605022e2b9a2dd526377f6 /src/render | |
| parent | 5e6f7b1cdb72b394ad8556bb232ac8a406d851b4 (diff) | |
layerSurface: refactor/move to a memory-safe impl
Makes all the pointers smart to avoid memory issues
Refactors layerSurface code to live inside desktop/layersurface
Diffstat (limited to 'src/render')
| -rw-r--r-- | src/render/OpenGL.cpp | 32 | ||||
| -rw-r--r-- | src/render/OpenGL.hpp | 12 | ||||
| -rw-r--r-- | src/render/Renderer.cpp | 25 | ||||
| -rw-r--r-- | src/render/Renderer.hpp | 4 |
4 files changed, 36 insertions, 37 deletions
diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index 78698505..31625b3b 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -5,6 +5,7 @@ #include "Shaders.hpp" #include <random> #include "../config/ConfigValue.hpp" +#include "../desktop/LayerSurface.hpp" inline void loadGLProc(void* pProc, const char* name) { void* proc = (void*)eglGetProcAddress(name); @@ -1453,7 +1454,7 @@ bool CHyprOpenGLImpl::preBlurQueued() { return !(!m_RenderData.pCurrentMonData->blurFBDirty || !*PBLURNEWOPTIMIZE || !*PBLUR || !m_RenderData.pCurrentMonData->blurFBShouldRender); } -bool CHyprOpenGLImpl::shouldUseNewBlurOptimizations(SLayerSurface* pLayer, PHLWINDOW pWindow) { +bool CHyprOpenGLImpl::shouldUseNewBlurOptimizations(PHLLS pLayer, PHLWINDOW pWindow) { static auto PBLURNEWOPTIMIZE = CConfigValue<Hyprlang::INT>("decoration:blur:new_optimizations"); static auto PBLURXRAY = CConfigValue<Hyprlang::INT>("decoration:blur:xray"); @@ -1781,7 +1782,7 @@ void CHyprOpenGLImpl::makeWindowSnapshot(PHLWINDOW pWindow) { g_pHyprRenderer->m_bRenderingSnapshot = false; } -void CHyprOpenGLImpl::makeLayerSnapshot(SLayerSurface* pLayer) { +void CHyprOpenGLImpl::makeLayerSnapshot(PHLLS pLayer) { // we trust the window is valid. const auto PMONITOR = g_pCompositor->getMonitorFromID(pLayer->monitorID); @@ -1864,38 +1865,35 @@ void CHyprOpenGLImpl::renderSnapshot(PHLWINDOW pWindow) { m_bEndFrame = false; } -void CHyprOpenGLImpl::renderSnapshot(SLayerSurface** pLayer) { +void CHyprOpenGLImpl::renderSnapshot(PHLLS pLayer) { RASSERT(m_RenderData.pMonitor, "Tried to render snapshot rect without begin()!"); - const auto PLAYER = *pLayer; - auto it = m_mLayerFramebuffers.begin(); - for (; it != m_mLayerFramebuffers.end(); it++) { - if (it->first == PLAYER) { - break; - } - } + if (!m_mLayerFramebuffers.contains(pLayer)) + return; - if (it == m_mLayerFramebuffers.end() || !it->second.m_cTex.m_iTexID) + const auto FBDATA = &m_mLayerFramebuffers.at(pLayer); + + if (!FBDATA->m_cTex.m_iTexID) return; - const auto PMONITOR = g_pCompositor->getMonitorFromID(PLAYER->monitorID); + const auto PMONITOR = g_pCompositor->getMonitorFromID(pLayer->monitorID); CBox layerBox; // some mafs to figure out the correct box // the originalClosedPos is relative to the monitor's pos - Vector2D scaleXY = Vector2D((PMONITOR->scale * PLAYER->realSize.value().x / (PLAYER->geometry.w * PMONITOR->scale)), - (PMONITOR->scale * PLAYER->realSize.value().y / (PLAYER->geometry.h * PMONITOR->scale))); + Vector2D scaleXY = Vector2D((PMONITOR->scale * pLayer->realSize.value().x / (pLayer->geometry.w * PMONITOR->scale)), + (PMONITOR->scale * pLayer->realSize.value().y / (pLayer->geometry.h * PMONITOR->scale))); layerBox.width = PMONITOR->vecTransformedSize.x * scaleXY.x; layerBox.height = PMONITOR->vecTransformedSize.y * scaleXY.y; - layerBox.x = ((PLAYER->realPosition.value().x - PMONITOR->vecPosition.x) * PMONITOR->scale) - (((PLAYER->geometry.x - PMONITOR->vecPosition.x) * PMONITOR->scale) * scaleXY.x); - layerBox.y = ((PLAYER->realPosition.value().y - PMONITOR->vecPosition.y) * PMONITOR->scale) - (((PLAYER->geometry.y - PMONITOR->vecPosition.y) * PMONITOR->scale) * scaleXY.y); + layerBox.x = ((pLayer->realPosition.value().x - PMONITOR->vecPosition.x) * PMONITOR->scale) - (((pLayer->geometry.x - PMONITOR->vecPosition.x) * PMONITOR->scale) * scaleXY.x); + layerBox.y = ((pLayer->realPosition.value().y - PMONITOR->vecPosition.y) * PMONITOR->scale) - (((pLayer->geometry.y - PMONITOR->vecPosition.y) * PMONITOR->scale) * scaleXY.y); CRegion fakeDamage{0, 0, PMONITOR->vecTransformedSize.x, PMONITOR->vecTransformedSize.y}; m_bEndFrame = true; - renderTextureInternalWithDamage(it->second.m_cTex, &layerBox, PLAYER->alpha.value(), &fakeDamage, 0); + renderTextureInternalWithDamage(FBDATA->m_cTex, &layerBox, pLayer->alpha.value(), &fakeDamage, 0); m_bEndFrame = false; } diff --git a/src/render/OpenGL.hpp b/src/render/OpenGL.hpp index bbd022e7..f13d506b 100644 --- a/src/render/OpenGL.hpp +++ b/src/render/OpenGL.hpp @@ -154,10 +154,10 @@ class CHyprOpenGLImpl { void makeWindowSnapshot(PHLWINDOW); void makeRawWindowSnapshot(PHLWINDOW, CFramebuffer*); - void makeLayerSnapshot(SLayerSurface*); + void makeLayerSnapshot(PHLLS); void renderSnapshot(PHLWINDOW); - void renderSnapshot(SLayerSurface**); - bool shouldUseNewBlurOptimizations(SLayerSurface* pLayer, PHLWINDOW pWindow); + void renderSnapshot(PHLLS); + bool shouldUseNewBlurOptimizations(PHLLS pLayer, PHLWINDOW pWindow); void clear(const CColor&); void clearWithTex(); @@ -193,11 +193,11 @@ class CHyprOpenGLImpl { bool m_bReloadScreenShader = true; // at launch it can be set - PHLWINDOWREF m_pCurrentWindow; // hack to get the current rendered window - SLayerSurface* m_pCurrentLayer = nullptr; // hack to get the current rendered layer + PHLWINDOWREF m_pCurrentWindow; // hack to get the current rendered window + PHLLS m_pCurrentLayer; // hack to get the current rendered layer std::map<PHLWINDOWREF, CFramebuffer, std::owner_less<PHLWINDOWREF>> m_mWindowFramebuffers; - std::unordered_map<SLayerSurface*, CFramebuffer> m_mLayerFramebuffers; + std::map<PHLLSREF, CFramebuffer, std::owner_less<PHLLSREF>> m_mLayerFramebuffers; std::unordered_map<CMonitor*, SMonitorRenderData> m_mMonitorRenderResources; std::unordered_map<CMonitor*, CFramebuffer> m_mMonitorBGFBs; diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index e34e6a72..6b1545b1 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -6,6 +6,7 @@ #include "../config/ConfigValue.hpp" #include "../managers/CursorManager.hpp" #include "../desktop/Window.hpp" +#include "../desktop/LayerSurface.hpp" extern "C" { #include <xf86drm.h> @@ -662,7 +663,7 @@ void CHyprRenderer::renderWindow(PHLWINDOW pWindow, CMonitor* pMonitor, timespec g_pHyprOpenGL->m_RenderData.clipBox = CBox(); } -void CHyprRenderer::renderLayer(SLayerSurface* pLayer, CMonitor* pMonitor, timespec* time, bool popups) { +void CHyprRenderer::renderLayer(PHLLS pLayer, CMonitor* pMonitor, timespec* time, bool popups) { static auto PDIMAROUND = CConfigValue<Hyprlang::FLOAT>("decoration:dim_around"); if (*PDIMAROUND && pLayer->dimAround && !m_bRenderingSnapshot && !popups) { @@ -672,7 +673,7 @@ void CHyprRenderer::renderLayer(SLayerSurface* pLayer, CMonitor* pMonitor, times if (pLayer->fadingOut) { if (!popups) - g_pHyprOpenGL->renderSnapshot(&pLayer); + g_pHyprOpenGL->renderSnapshot(pLayer); return; } @@ -786,16 +787,16 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, PHLWORKSPAC g_pHyprOpenGL->blend(true); for (auto& ls : pMonitor->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND]) { - renderLayer(ls.get(), pMonitor, time); + renderLayer(ls, pMonitor, time); } for (auto& ls : pMonitor->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]) { - renderLayer(ls.get(), pMonitor, time); + renderLayer(ls, pMonitor, time); } for (auto& ls : pMonitor->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]) { - renderLayer(ls.get(), pMonitor, time); + renderLayer(ls, pMonitor, time); } for (auto& ls : pMonitor->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]) { - renderLayer(ls.get(), pMonitor, time); + renderLayer(ls, pMonitor, time); } g_pHyprOpenGL->m_RenderData.renderModif = {}; @@ -826,10 +827,10 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, PHLWORKSPAC g_pHyprOpenGL->blend(true); for (auto& ls : pMonitor->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND]) { - renderLayer(ls.get(), pMonitor, time); + renderLayer(ls, pMonitor, time); } for (auto& ls : pMonitor->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]) { - renderLayer(ls.get(), pMonitor, time); + renderLayer(ls, pMonitor, time); } g_pHyprOpenGL->m_RenderData.damage = preOccludedDamage; @@ -896,7 +897,7 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, PHLWORKSPAC // Render surfaces above windows for monitor for (auto& ls : pMonitor->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]) { - renderLayer(ls.get(), pMonitor, time); + renderLayer(ls, pMonitor, time); } // Render IME popups @@ -905,12 +906,12 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, PHLWORKSPAC } for (auto& ls : pMonitor->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]) { - renderLayer(ls.get(), pMonitor, time); + renderLayer(ls, pMonitor, time); } for (auto& lsl : pMonitor->m_aLayerSurfaceLayers) { for (auto& ls : lsl) { - renderLayer(ls.get(), pMonitor, time, true); + renderLayer(ls, pMonitor, time, true); } } @@ -1595,7 +1596,7 @@ static void applyExclusive(wlr_box& usableArea, uint32_t anchor, int32_t exclusi } } -void CHyprRenderer::arrangeLayerArray(CMonitor* pMonitor, const std::vector<std::unique_ptr<SLayerSurface>>& layerSurfaces, bool exclusiveZone, CBox* usableArea) { +void CHyprRenderer::arrangeLayerArray(CMonitor* pMonitor, const std::vector<PHLLS>& layerSurfaces, bool exclusiveZone, CBox* usableArea) { CBox full_area = {pMonitor->vecPosition.x, pMonitor->vecPosition.y, pMonitor->vecSize.x, pMonitor->vecSize.y}; for (auto& ls : layerSurfaces) { diff --git a/src/render/Renderer.hpp b/src/render/Renderer.hpp index 08b04dd2..fcf3f20b 100644 --- a/src/render/Renderer.hpp +++ b/src/render/Renderer.hpp @@ -108,11 +108,11 @@ class CHyprRenderer { } m_sLastCursorData; private: - void arrangeLayerArray(CMonitor*, const std::vector<std::unique_ptr<SLayerSurface>>&, bool, CBox*); + void arrangeLayerArray(CMonitor*, const std::vector<PHLLS>&, bool, CBox*); void renderWorkspaceWindowsFullscreen(CMonitor*, PHLWORKSPACE, timespec*); // renders workspace windows (fullscreen) (tiled, floating, pinned, but no special) void renderWorkspaceWindows(CMonitor*, PHLWORKSPACE, timespec*); // renders workspace windows (no fullscreen) (tiled, floating, pinned, but no special) void renderWindow(PHLWINDOW, CMonitor*, timespec*, bool, eRenderPassMode, bool ignorePosition = false, bool ignoreAllGeometry = false); - void renderLayer(SLayerSurface*, CMonitor*, timespec*, bool popups = false); + void renderLayer(PHLLS, CMonitor*, timespec*, bool popups = false); void renderSessionLockSurface(SSessionLockSurface*, CMonitor*, timespec*); void renderDragIcon(CMonitor*, timespec*); void renderIMEPopup(CInputPopup*, CMonitor*, timespec*); |
