From 60cd5b7a48af4a23717201d70395161a3bb4ab24 Mon Sep 17 00:00:00 2001 From: vaxerski Date: Fri, 9 May 2025 22:16:21 +0100 Subject: [PATCH] renderer: always render snapshots as 8bit fixes issues with transparent windows on 10b --- src/render/Framebuffer.cpp | 5 +++++ src/render/Framebuffer.hpp | 2 ++ src/render/OpenGL.cpp | 10 ++++++---- src/render/Renderer.cpp | 6 +++--- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/render/Framebuffer.cpp b/src/render/Framebuffer.cpp index ae2ce2a6..ab5a14a3 100644 --- a/src/render/Framebuffer.cpp +++ b/src/render/Framebuffer.cpp @@ -12,6 +12,11 @@ bool CFramebuffer::alloc(int w, int h, uint32_t drmFormat) { uint32_t glFormat = NFormatUtils::drmFormatToGL(drmFormat); uint32_t glType = NFormatUtils::glFormatToType(glFormat); + if (drmFormat != m_drmFormat || m_size != Vector2D{w, h}) + release(); + + m_drmFormat = drmFormat; + if (!m_tex) { m_tex = makeShared(); m_tex->allocate(); diff --git a/src/render/Framebuffer.hpp b/src/render/Framebuffer.hpp index 4e041573..0e18df5f 100644 --- a/src/render/Framebuffer.hpp +++ b/src/render/Framebuffer.hpp @@ -1,6 +1,7 @@ #pragma once #include "../defines.hpp" +#include "../helpers/Format.hpp" #include "Texture.hpp" class CFramebuffer { @@ -20,6 +21,7 @@ class CFramebuffer { GLuint getFBID(); Vector2D m_size; + DRMFormat m_drmFormat = 0 /* DRM_FORMAT_INVALID */; private: SP m_tex; diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index 4bd8eba3..9cbf091b 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -752,13 +752,15 @@ void CHyprOpenGLImpl::begin(PHLMONITOR pMonitor, const CRegion& damage_, CFrameb if (!m_shadersInitialized) initShaders(); + const auto DRM_FORMAT = fb ? fb->m_drmFormat : pMonitor->m_output->state->state().drmFormat; + // ensure a framebuffer for the monitor exists - if (m_renderData.pCurrentMonData->offloadFB.m_size != pMonitor->m_pixelSize) { + if (m_renderData.pCurrentMonData->offloadFB.m_size != pMonitor->m_pixelSize || DRM_FORMAT != m_renderData.pCurrentMonData->offloadFB.m_drmFormat) { m_renderData.pCurrentMonData->stencilTex->allocate(); - m_renderData.pCurrentMonData->offloadFB.alloc(pMonitor->m_pixelSize.x, pMonitor->m_pixelSize.y, pMonitor->m_output->state->state().drmFormat); - m_renderData.pCurrentMonData->mirrorFB.alloc(pMonitor->m_pixelSize.x, pMonitor->m_pixelSize.y, pMonitor->m_output->state->state().drmFormat); - m_renderData.pCurrentMonData->mirrorSwapFB.alloc(pMonitor->m_pixelSize.x, pMonitor->m_pixelSize.y, pMonitor->m_output->state->state().drmFormat); + m_renderData.pCurrentMonData->offloadFB.alloc(pMonitor->m_pixelSize.x, pMonitor->m_pixelSize.y, DRM_FORMAT); + m_renderData.pCurrentMonData->mirrorFB.alloc(pMonitor->m_pixelSize.x, pMonitor->m_pixelSize.y, DRM_FORMAT); + m_renderData.pCurrentMonData->mirrorSwapFB.alloc(pMonitor->m_pixelSize.x, pMonitor->m_pixelSize.y, DRM_FORMAT); m_renderData.pCurrentMonData->offloadFB.addStencil(m_renderData.pCurrentMonData->stencilTex); m_renderData.pCurrentMonData->mirrorFB.addStencil(m_renderData.pCurrentMonData->stencilTex); diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index dde53f5d..343276c9 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -2389,7 +2389,7 @@ void CHyprRenderer::makeRawWindowSnapshot(PHLWINDOW pWindow, CFramebuffer* pFram makeEGLCurrent(); - pFramebuffer->alloc(PMONITOR->m_pixelSize.x, PMONITOR->m_pixelSize.y, PMONITOR->m_output->state->state().drmFormat); + pFramebuffer->alloc(PMONITOR->m_pixelSize.x, PMONITOR->m_pixelSize.y, DRM_FORMAT_ABGR8888); pFramebuffer->addStencil(g_pHyprOpenGL->m_renderData.pCurrentMonData->stencilTex); beginRender(PMONITOR, fakeDamage, RENDER_MODE_FULL_FAKE, nullptr, pFramebuffer); @@ -2440,7 +2440,7 @@ void CHyprRenderer::makeWindowSnapshot(PHLWINDOW pWindow) { const auto PFRAMEBUFFER = &g_pHyprOpenGL->m_windowFramebuffers[ref]; - PFRAMEBUFFER->alloc(PMONITOR->m_pixelSize.x, PMONITOR->m_pixelSize.y, PMONITOR->m_output->state->state().drmFormat); + PFRAMEBUFFER->alloc(PMONITOR->m_pixelSize.x, PMONITOR->m_pixelSize.y, DRM_FORMAT_ABGR8888); beginRender(PMONITOR, fakeDamage, RENDER_MODE_FULL_FAKE, nullptr, PFRAMEBUFFER); @@ -2484,7 +2484,7 @@ void CHyprRenderer::makeLayerSnapshot(PHLLS pLayer) { const auto PFRAMEBUFFER = &g_pHyprOpenGL->m_layerFramebuffers[pLayer]; - PFRAMEBUFFER->alloc(PMONITOR->m_pixelSize.x, PMONITOR->m_pixelSize.y, PMONITOR->m_output->state->state().drmFormat); + PFRAMEBUFFER->alloc(PMONITOR->m_pixelSize.x, PMONITOR->m_pixelSize.y, DRM_FORMAT_ABGR8888); beginRender(PMONITOR, fakeDamage, RENDER_MODE_FULL_FAKE, nullptr, PFRAMEBUFFER);