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/protocols/SinglePixel.cpp | 4 ++-- src/protocols/types/Buffer.hpp | 2 +- src/protocols/types/DMABuffer.cpp | 19 ++++++++----------- src/protocols/types/SurfaceState.cpp | 5 +++-- src/protocols/types/SurfaceState.hpp | 6 +++--- 5 files changed, 17 insertions(+), 19 deletions(-) (limited to 'src/protocols') diff --git a/src/protocols/SinglePixel.cpp b/src/protocols/SinglePixel.cpp index 51c3551c..c32379a3 100644 --- a/src/protocols/SinglePixel.cpp +++ b/src/protocols/SinglePixel.cpp @@ -12,11 +12,11 @@ CSinglePixelBuffer::CSinglePixelBuffer(uint32_t id, wl_client* client, CHyprColo m_opaque = col_.a >= 1.F; - m_texture = makeShared(DRM_FORMAT_ARGB8888, rc(&m_color), 4, Vector2D{1, 1}); + m_texture = g_pHyprRenderer->createTexture(DRM_FORMAT_ARGB8888, rc(&m_color), 4, Vector2D{1, 1}); m_resource = CWLBufferResource::create(makeShared(client, 1, id)); - m_success = m_texture->m_texID; + m_success = m_texture->ok(); size = {1, 1}; diff --git a/src/protocols/types/Buffer.hpp b/src/protocols/types/Buffer.hpp index bda44ebc..afff11a5 100644 --- a/src/protocols/types/Buffer.hpp +++ b/src/protocols/types/Buffer.hpp @@ -26,7 +26,7 @@ class IHLBuffer : public Aquamarine::IBuffer { void onBackendRelease(const std::function& fn); void addReleasePoint(CDRMSyncPointState& point); - SP m_texture; + SP m_texture; bool m_opaque = false; SP m_resource; std::vector> m_syncReleasers; diff --git a/src/protocols/types/DMABuffer.cpp b/src/protocols/types/DMABuffer.cpp index f3c3e067..86db8ca6 100644 --- a/src/protocols/types/DMABuffer.cpp +++ b/src/protocols/types/DMABuffer.cpp @@ -13,31 +13,28 @@ using namespace Hyprutils::OS; CDMABuffer::CDMABuffer(uint32_t id, wl_client* client, Aquamarine::SDMABUFAttrs const& attrs_) : m_attrs(attrs_) { - g_pHyprRenderer->makeEGLCurrent(); - m_listeners.resourceDestroy = events.destroy.listen([this] { closeFDs(); m_listeners.resourceDestroy.reset(); }); - size = m_attrs.size; - m_resource = CWLBufferResource::create(makeShared(client, 1, id)); - auto eglImage = g_pHyprOpenGL->createEGLImage(m_attrs); + size = m_attrs.size; + m_resource = CWLBufferResource::create(makeShared(client, 1, id)); + m_opaque = NFormatUtils::isFormatOpaque(m_attrs.format); + m_texture = g_pHyprRenderer->createTexture(m_attrs, m_opaque); // texture takes ownership of the eglImage - if UNLIKELY (!eglImage) { + if UNLIKELY (!m_texture) { Log::logger->log(Log::ERR, "CDMABuffer: failed to import EGLImage, retrying as implicit"); m_attrs.modifier = DRM_FORMAT_MOD_INVALID; - eglImage = g_pHyprOpenGL->createEGLImage(m_attrs); + m_texture = g_pHyprRenderer->createTexture(m_attrs, m_opaque); - if UNLIKELY (!eglImage) { + if UNLIKELY (!m_texture) { Log::logger->log(Log::ERR, "CDMABuffer: failed to import EGLImage"); return; } } - m_texture = makeShared(m_attrs, eglImage); // texture takes ownership of the eglImage - m_opaque = NFormatUtils::isFormatOpaque(m_attrs.format); - m_success = m_texture->m_texID; + m_success = m_texture->ok(); if UNLIKELY (!m_success) Log::logger->log(Log::ERR, "Failed to create a dmabuf: texture is null"); diff --git a/src/protocols/types/SurfaceState.cpp b/src/protocols/types/SurfaceState.cpp index 46f2a563..da98d3fb 100644 --- a/src/protocols/types/SurfaceState.cpp +++ b/src/protocols/types/SurfaceState.cpp @@ -1,6 +1,7 @@ #include "SurfaceState.hpp" #include "helpers/Format.hpp" #include "protocols/types/Buffer.hpp" +#include "render/Renderer.hpp" #include "render/Texture.hpp" Vector2D SSurfaceState::sourceSize() { @@ -34,7 +35,7 @@ CRegion SSurfaceState::accumulateBufferDamage() { return bufferDamage; } -void SSurfaceState::updateSynchronousTexture(SP lastTexture) { +void SSurfaceState::updateSynchronousTexture(SP lastTexture) { auto [dataPtr, fmt, size] = buffer->beginDataPtr(0); if (dataPtr) { auto drmFmt = NFormatUtils::shmToDRM(fmt); @@ -43,7 +44,7 @@ void SSurfaceState::updateSynchronousTexture(SP lastTexture) { texture = lastTexture; texture->update(drmFmt, dataPtr, stride, accumulateBufferDamage()); } else - texture = makeShared(drmFmt, dataPtr, stride, bufferSize); + texture = g_pHyprRenderer->createTexture(drmFmt, dataPtr, stride, bufferSize); } buffer->endDataPtr(); } diff --git a/src/protocols/types/SurfaceState.hpp b/src/protocols/types/SurfaceState.hpp index f6caa83c..d5b7e4b9 100644 --- a/src/protocols/types/SurfaceState.hpp +++ b/src/protocols/types/SurfaceState.hpp @@ -6,7 +6,7 @@ #include "../WaylandProtocol.hpp" #include "./Buffer.hpp" -class CTexture; +class ITexture; class CDRMSyncPointState; class CWLCallbackResource; @@ -88,8 +88,8 @@ struct SSurfaceState { eLockReason lockMask = LOCK_REASON_NONE; // texture of surface content, used for rendering - SP texture; - void updateSynchronousTexture(SP lastTexture); + SP texture; + void updateSynchronousTexture(SP lastTexture); // fifo bool barrierSet = false; -- cgit v1.2.3