mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-07 18:45:59 +01:00
Fix VRAM memory leak when releasing snapshots
This commit is contained in:
parent
f9985a36b3
commit
bf762f566f
6 changed files with 29 additions and 17 deletions
|
@ -852,9 +852,12 @@ void CCompositor::moveWindowToTop(CWindow* pWindow) {
|
|||
}
|
||||
}
|
||||
|
||||
void CCompositor::cleanupFadingOut() {
|
||||
void CCompositor::cleanupFadingOut(const int& monid) {
|
||||
for (auto& w : m_vWindowsFadingOut) {
|
||||
|
||||
if (w->m_iMonitorID != (long unsigned int)monid)
|
||||
continue;
|
||||
|
||||
bool valid = windowExists(w);
|
||||
|
||||
if (!valid || !w->m_bFadingOut || w->m_fAlpha.fl() == 0.f) {
|
||||
|
@ -867,11 +870,16 @@ void CCompositor::cleanupFadingOut() {
|
|||
m_vWindowsFadingOut.erase(std::remove(m_vWindowsFadingOut.begin(), m_vWindowsFadingOut.end(), w));
|
||||
|
||||
Debug::log(LOG, "Cleanup: destroyed a window");
|
||||
|
||||
glFlush(); // to free mem NOW.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& ls : m_vSurfacesFadingOut) {
|
||||
if (ls->monitorID != monid)
|
||||
continue;
|
||||
|
||||
if (ls->fadingOut && ls->readyToDelete && !ls->alpha.isBeingAnimated()) {
|
||||
for (auto& m : m_vMonitors) {
|
||||
for (auto& lsl : m->m_aLayerSurfaceLists) {
|
||||
|
@ -887,6 +895,7 @@ void CCompositor::cleanupFadingOut() {
|
|||
|
||||
Debug::log(LOG, "Cleanup: destroyed a layersurface");
|
||||
|
||||
glFlush(); // to free mem NOW.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ public:
|
|||
bool doesSeatAcceptInput(wlr_surface*);
|
||||
bool isWindowActive(CWindow*);
|
||||
void moveWindowToTop(CWindow*);
|
||||
void cleanupFadingOut();
|
||||
void cleanupFadingOut(const int& monid);
|
||||
CWindow* getWindowInDirection(CWindow*, char);
|
||||
void deactivateAllWLRWorkspaces(wlr_ext_workspace_handle_v1* exclude = nullptr);
|
||||
CWindow* getNextWindowOnWorkspace(CWindow*);
|
||||
|
|
|
@ -186,7 +186,6 @@ void Events::listener_monitorFrame(void* owner, void* data) {
|
|||
if (PMONITOR->ID == pMostHzMonitor->ID || !*PNOVFR) { // unfortunately with VFR we don't have the guarantee mostHz is going to be updated all the time, so we have to ignore that
|
||||
g_pCompositor->sanityCheckWorkspaces();
|
||||
g_pAnimationManager->tick();
|
||||
g_pCompositor->cleanupFadingOut();
|
||||
|
||||
HyprCtl::tickHyprCtl(); // so that we dont get that race condition multithread bullshit
|
||||
|
||||
|
@ -229,6 +228,9 @@ void Events::listener_monitorFrame(void* owner, void* data) {
|
|||
return;
|
||||
}
|
||||
|
||||
// we need to cleanup fading out when rendering the appropriate context
|
||||
g_pCompositor->cleanupFadingOut(PMONITOR->ID);
|
||||
|
||||
if (!hasChanged && *PDAMAGETRACKINGMODE != DAMAGE_TRACKING_NONE && PMONITOR->forceFullFrames == 0 && damageBlinkCleanup == 0) {
|
||||
pixman_region32_fini(&damage);
|
||||
wlr_output_rollback(PMONITOR->output);
|
||||
|
|
|
@ -2,15 +2,14 @@
|
|||
#include "OpenGL.hpp"
|
||||
|
||||
bool CFramebuffer::alloc(int w, int h) {
|
||||
bool firstAlloc = false;
|
||||
if (m_iFb == (uint32_t)-1)
|
||||
{
|
||||
bool firstAlloc = false;
|
||||
|
||||
if (m_iFb == (uint32_t)-1) {
|
||||
firstAlloc = true;
|
||||
glGenFramebuffers(1, &m_iFb);
|
||||
}
|
||||
|
||||
if (m_cTex.m_iTexID == 0)
|
||||
{
|
||||
if (m_cTex.m_iTexID == 0) {
|
||||
firstAlloc = true;
|
||||
glGenTextures(1, &m_cTex.m_iTexID);
|
||||
glBindTexture(GL_TEXTURE_2D, m_cTex.m_iTexID);
|
||||
|
@ -20,13 +19,11 @@ bool CFramebuffer::alloc(int w, int h) {
|
|||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
}
|
||||
|
||||
if (firstAlloc || m_Size != Vector2D(w, h))
|
||||
{
|
||||
if (firstAlloc || m_Size != Vector2D(w, h)) {
|
||||
glBindTexture(GL_TEXTURE_2D, m_cTex.m_iTexID);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_iFb);
|
||||
glBindTexture(GL_TEXTURE_2D, m_cTex.m_iTexID);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_cTex.m_iTexID, 0);
|
||||
|
||||
|
||||
|
@ -37,7 +34,6 @@ bool CFramebuffer::alloc(int w, int h) {
|
|||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, w, h, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 0);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_iFb);
|
||||
glBindTexture(GL_TEXTURE_2D, m_pStencilTex->m_iTexID);
|
||||
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, m_pStencilTex->m_iTexID, 0);
|
||||
}
|
||||
|
@ -78,3 +74,7 @@ void CFramebuffer::release() {
|
|||
m_cTex.m_iTexID = 0;
|
||||
m_iFb = -1;
|
||||
}
|
||||
|
||||
CFramebuffer::~CFramebuffer() {
|
||||
release();
|
||||
}
|
|
@ -6,6 +6,8 @@
|
|||
class CFramebuffer {
|
||||
public:
|
||||
|
||||
~CFramebuffer();
|
||||
|
||||
bool alloc(int w, int h);
|
||||
void bind();
|
||||
void release();
|
||||
|
|
|
@ -702,8 +702,6 @@ void CHyprOpenGLImpl::makeWindowSnapshot(CWindow* pWindow) {
|
|||
|
||||
begin(PMONITOR, &fakeDamage, true);
|
||||
|
||||
pixman_region32_fini(&fakeDamage);
|
||||
|
||||
clear(CColor(0,0,0,0)); // JIC
|
||||
|
||||
timespec now;
|
||||
|
@ -742,9 +740,10 @@ void CHyprOpenGLImpl::makeWindowSnapshot(CWindow* pWindow) {
|
|||
#else
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_iCurrentOutputFb);
|
||||
#endif
|
||||
|
||||
end();
|
||||
|
||||
pixman_region32_fini(&fakeDamage);
|
||||
|
||||
wlr_output_rollback(PMONITOR->output);
|
||||
}
|
||||
|
||||
|
@ -762,8 +761,6 @@ void CHyprOpenGLImpl::makeLayerSnapshot(SLayerSurface* pLayer) {
|
|||
|
||||
begin(PMONITOR, &fakeDamage, true);
|
||||
|
||||
pixman_region32_fini(&fakeDamage);
|
||||
|
||||
const auto PFRAMEBUFFER = &m_mLayerFramebuffers[pLayer];
|
||||
|
||||
glViewport(0, 0, g_pHyprOpenGL->m_RenderData.pMonitor->vecPixelSize.x, g_pHyprOpenGL->m_RenderData.pMonitor->vecPixelSize.y);
|
||||
|
@ -792,6 +789,8 @@ void CHyprOpenGLImpl::makeLayerSnapshot(SLayerSurface* pLayer) {
|
|||
|
||||
end();
|
||||
|
||||
pixman_region32_fini(&fakeDamage);
|
||||
|
||||
wlr_output_rollback(PMONITOR->output);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue