From 4152ac76d0813d9d0f67d2f04653a13fa6e17433 Mon Sep 17 00:00:00 2001 From: UjinT34 <41110182+UjinT34@users.noreply.github.com> Date: Sat, 7 Mar 2026 00:44:10 +0300 Subject: renderer: refactor Texture, Framebuffer and Renderbuffer (#13437) Part 1 of the renderer refactors --- src/managers/PointerManager.cpp | 9 ++++--- src/managers/PointerManager.hpp | 8 +++--- src/managers/screenshare/CursorshareSession.cpp | 12 ++++----- src/managers/screenshare/ScreenshareFrame.cpp | 36 ++++++++++++------------- src/managers/screenshare/ScreenshareManager.hpp | 2 +- 5 files changed, 34 insertions(+), 33 deletions(-) (limited to 'src/managers') diff --git a/src/managers/PointerManager.cpp b/src/managers/PointerManager.cpp index c802d3e1..7256e176 100644 --- a/src/managers/PointerManager.cpp +++ b/src/managers/PointerManager.cpp @@ -8,6 +8,7 @@ #include "../protocols/IdleNotify.hpp" #include "../protocols/core/Compositor.hpp" #include "../protocols/core/Seat.hpp" +#include "debug/log/Logger.hpp" #include "eventLoop/EventLoopManager.hpp" #include "../render/pass/TexPassElement.hpp" #include "../managers/input/InputManager.hpp" @@ -22,6 +23,8 @@ #include #include #include +#include +#include #include using namespace Hyprutils::Utils; @@ -407,7 +410,7 @@ bool CPointerManager::setHWCursorBuffer(SP state, SP CPointerManager::renderHWCursorBuffer(SP state, SP texture) { +SP CPointerManager::renderHWCursorBuffer(SP state, SP texture) { auto maxSize = state->monitor->m_output->cursorPlaneSize(); auto const& cursorSize = m_currentCursorImage.size; @@ -900,13 +903,13 @@ const CPointerManager::SCursorImage& CPointerManager::currentCursorImage() { return m_currentCursorImage; } -SP CPointerManager::getCurrentCursorTexture() { +SP CPointerManager::getCurrentCursorTexture() { if (!m_currentCursorImage.pBuffer && (!m_currentCursorImage.surface || !m_currentCursorImage.surface->resource()->m_current.texture)) return nullptr; if (m_currentCursorImage.pBuffer) { if (!m_currentCursorImage.bufferTex) - m_currentCursorImage.bufferTex = makeShared(m_currentCursorImage.pBuffer, true); + m_currentCursorImage.bufferTex = g_pHyprRenderer->createTexture(m_currentCursorImage.pBuffer, true); return m_currentCursorImage.bufferTex; } diff --git a/src/managers/PointerManager.hpp b/src/managers/PointerManager.hpp index 218541a4..a4fe1971 100644 --- a/src/managers/PointerManager.hpp +++ b/src/managers/PointerManager.hpp @@ -12,7 +12,7 @@ class CMonitor; class IHID; -class CTexture; +class ITexture; AQUAMARINE_FORWARD(IBuffer); @@ -71,7 +71,7 @@ class CPointerManager { struct SCursorImage { SP pBuffer; - SP bufferTex; + SP bufferTex; WP surface; Vector2D hotspot; @@ -83,7 +83,7 @@ class CPointerManager { }; const SCursorImage& currentCursorImage(); - SP getCurrentCursorTexture(); + SP getCurrentCursorTexture(); struct { CSignalT<> cursorChanged; @@ -181,7 +181,7 @@ class CPointerManager { std::vector> m_monitorStates; SP stateFor(PHLMONITOR mon); bool attemptHardwareCursor(SP state); - SP renderHWCursorBuffer(SP state, SP texture); + SP renderHWCursorBuffer(SP state, SP texture); bool setHWCursorBuffer(SP state, SP buf); struct { diff --git a/src/managers/screenshare/CursorshareSession.cpp b/src/managers/screenshare/CursorshareSession.cpp index 2322625f..703832ab 100644 --- a/src/managers/screenshare/CursorshareSession.cpp +++ b/src/managers/screenshare/CursorshareSession.cpp @@ -169,10 +169,10 @@ bool CCursorshareSession::copy() { return false; } - CFramebuffer outFB; - outFB.alloc(m_bufferSize.x, m_bufferSize.y, m_format); + auto outFB = g_pHyprRenderer->createFB(); + outFB->alloc(m_bufferSize.x, m_bufferSize.y, m_format); - if (!g_pHyprRenderer->beginRender(m_pendingFrame.monitor, fakeDamage, RENDER_MODE_FULL_FAKE, nullptr, &outFB, true)) { + if (!g_pHyprRenderer->beginRender(m_pendingFrame.monitor, fakeDamage, RENDER_MODE_FULL_FAKE, nullptr, outFB, true)) { LOGM(Log::ERR, "Can't copy: failed to begin rendering to shm"); return false; } @@ -182,8 +182,8 @@ bool CCursorshareSession::copy() { g_pHyprRenderer->endRender(); g_pHyprOpenGL->m_renderData.pMonitor = m_pendingFrame.monitor; - outFB.bind(); - glBindFramebuffer(GL_READ_FRAMEBUFFER, outFB.getFBID()); + outFB->bind(); + glBindFramebuffer(GL_READ_FRAMEBUFFER, GLFB(outFB)->getFBID()); glPixelStorei(GL_PACK_ALIGNMENT, 1); @@ -212,7 +212,7 @@ bool CCursorshareSession::copy() { g_pHyprOpenGL->m_renderData.pMonitor.reset(); m_pendingFrame.buffer->endDataPtr(); - outFB.unbind(); + GLFB(outFB)->unbind(); glPixelStorei(GL_PACK_ALIGNMENT, 4); glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); diff --git a/src/managers/screenshare/ScreenshareFrame.cpp b/src/managers/screenshare/ScreenshareFrame.cpp index 18d5aac9..d747ecee 100644 --- a/src/managers/screenshare/ScreenshareFrame.cpp +++ b/src/managers/screenshare/ScreenshareFrame.cpp @@ -10,6 +10,7 @@ #include "../../helpers/Monitor.hpp" #include "../../desktop/view/Window.hpp" #include "../../desktop/state/FocusState.hpp" +#include using namespace Screenshare; @@ -133,7 +134,7 @@ void CScreenshareFrame::copy() { // store a snapshot before the permission popup so we don't break screenshots const auto PERM = g_pDynamicPermissionManager->clientPermissionMode(m_session->m_client, PERMISSION_TYPE_SCREENCOPY); if (PERM == PERMISSION_RULE_ALLOW_MODE_PENDING) { - if (!m_session->m_tempFB.isAllocated()) + if (!m_session->m_tempFB || !m_session->m_tempFB->isAllocated()) storeTempFB(); // don't copy a frame while allow is pending because screenshot tools will only take the first frame we give, which is empty @@ -159,10 +160,7 @@ void CScreenshareFrame::renderMonitor() { const auto PMONITOR = m_session->monitor(); - if (!g_pHyprOpenGL->m_monitorRenderResources.contains(PMONITOR)) - return; // wtf? - - auto TEXTURE = g_pHyprOpenGL->m_monitorRenderResources[PMONITOR].monitorMirrorFB.getTexture(); + auto TEXTURE = g_pHyprRenderer->createTexture(PMONITOR->m_output->state->state().buffer); const bool IS_CM_AWARE = PROTO::colorManagement && PROTO::colorManagement->isClientCMAware(m_session->m_client); g_pHyprOpenGL->m_renderData.transformDamage = false; @@ -328,10 +326,10 @@ void CScreenshareFrame::render() { return; } - if (m_session->m_tempFB.isAllocated()) { + if (m_session->m_tempFB && m_session->m_tempFB->isAllocated()) { CBox texbox = {{}, m_bufferSize}; - g_pHyprOpenGL->renderTexture(m_session->m_tempFB.getTexture(), texbox, {}); - m_session->m_tempFB.release(); + g_pHyprOpenGL->renderTexture(m_session->m_tempFB->getTexture(), texbox, {}); + m_session->m_tempFB->release(); return; } @@ -384,12 +382,12 @@ bool CScreenshareFrame::copyShm() { return false; } - const auto PMONITOR = m_session->monitor(); + const auto PMONITOR = m_session->monitor(); - CFramebuffer outFB; - outFB.alloc(m_bufferSize.x, m_bufferSize.y, shm.format); + auto outFB = g_pHyprRenderer->createFB(); + outFB->alloc(m_bufferSize.x, m_bufferSize.y, shm.format); - if (!g_pHyprRenderer->beginRender(PMONITOR, m_damage, RENDER_MODE_FULL_FAKE, nullptr, &outFB, true)) { + if (!g_pHyprRenderer->beginRender(PMONITOR, m_damage, RENDER_MODE_FULL_FAKE, nullptr, outFB, true)) { LOGM(Log::ERR, "Can't copy: failed to begin rendering"); return false; } @@ -401,8 +399,8 @@ bool CScreenshareFrame::copyShm() { g_pHyprRenderer->endRender(); g_pHyprOpenGL->m_renderData.pMonitor = PMONITOR; - outFB.bind(); - glBindFramebuffer(GL_READ_FRAMEBUFFER, outFB.getFBID()); + outFB->bind(); + glBindFramebuffer(GL_READ_FRAMEBUFFER, GLFB(outFB)->getFBID()); glPixelStorei(GL_PACK_ALIGNMENT, 1); @@ -444,7 +442,7 @@ bool CScreenshareFrame::copyShm() { }); } - outFB.unbind(); + GLFB(outFB)->unbind(); glPixelStorei(GL_PACK_ALIGNMENT, 4); glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); @@ -459,13 +457,13 @@ bool CScreenshareFrame::copyShm() { } void CScreenshareFrame::storeTempFB() { - g_pHyprRenderer->makeEGLCurrent(); - - m_session->m_tempFB.alloc(m_bufferSize.x, m_bufferSize.y); + if (!m_session->m_tempFB) + m_session->m_tempFB = g_pHyprRenderer->createFB(); + m_session->m_tempFB->alloc(m_bufferSize.x, m_bufferSize.y); CRegion fakeDamage = {0, 0, INT16_MAX, INT16_MAX}; - if (!g_pHyprRenderer->beginRender(m_session->monitor(), fakeDamage, RENDER_MODE_FULL_FAKE, nullptr, &m_session->m_tempFB, true)) { + if (!g_pHyprRenderer->beginRender(m_session->monitor(), fakeDamage, RENDER_MODE_FULL_FAKE, nullptr, m_session->m_tempFB, true)) { LOGM(Log::ERR, "Can't copy: failed to begin rendering to temp fb"); return; } diff --git a/src/managers/screenshare/ScreenshareManager.hpp b/src/managers/screenshare/ScreenshareManager.hpp index d62585ae..5a4ada5e 100644 --- a/src/managers/screenshare/ScreenshareManager.hpp +++ b/src/managers/screenshare/ScreenshareManager.hpp @@ -75,7 +75,7 @@ namespace Screenshare { std::vector m_formats; Vector2D m_bufferSize = Vector2D(0, 0); - CFramebuffer m_tempFB; + SP m_tempFB; SP m_shareStopTimer; bool m_sharing = false; -- cgit v1.2.3