diff --git a/src/backend/drm/Renderer.cpp b/src/backend/drm/Renderer.cpp index 1d20e16..7ce9e7a 100644 --- a/src/backend/drm/Renderer.cpp +++ b/src/backend/drm/Renderer.cpp @@ -474,8 +474,8 @@ EGLImageKHR CDRMRenderer::createEGLImage(const SDMABUFAttrs& attrs) { } \ } -CDRMRenderer::GLTex CDRMRenderer::glTex(Hyprutils::Memory::CSharedPointer buffa) { - GLTex tex; +SGLTex CDRMRenderer::glTex(Hyprutils::Memory::CSharedPointer buffa) { + SGLTex tex; const auto dma = buffa->dmabuf(); @@ -490,7 +490,7 @@ CDRMRenderer::GLTex CDRMRenderer::glTex(Hyprutils::Memory::CSharedPointerlog(AQ_LOG_DEBUG, std::format("CDRMRenderer::glTex: found format+mod, external = {}", external)); + backend->log(AQ_LOG_DEBUG, std::format("CDRMRenderer::glTex: found format+mod, external = {}", fmt.external)); external = fmt.external; break; } @@ -528,13 +528,13 @@ bool CDRMRenderer::blit(SP from, SP to) { // both from and to have the same AQ_ATTACHMENT_DRM_RENDERER_DATA. // Those buffers always come from different swapchains, so it's OK. - GLTex fromTex; + SGLTex fromTex; { auto attachment = from->attachments.get(AQ_ATTACHMENT_DRM_RENDERER_DATA); if (attachment) { TRACE(backend->log(AQ_LOG_TRACE, "EGL (blit): From attachment found")); auto att = (CDRMRendererBufferAttachment*)attachment.get(); - fromTex = {att->eglImage, att->texid}; + fromTex = att->tex; } if (!fromTex.image) { @@ -543,7 +543,7 @@ bool CDRMRenderer::blit(SP from, SP to) { // should never remove anything, but JIC. We'll leak an EGLImage if this removes anything. from->attachments.removeByType(AQ_ATTACHMENT_DRM_RENDERER_DATA); - from->attachments.add(makeShared(self, from, fromTex.image, 0, 0, fromTex.texid)); + from->attachments.add(makeShared(self, from, nullptr, 0, 0, fromTex)); } } @@ -598,7 +598,7 @@ bool CDRMRenderer::blit(SP from, SP to) { // should never remove anything, but JIC. We'll leak an RBO and FBO if this removes anything. to->attachments.removeByType(AQ_ATTACHMENT_DRM_RENDERER_DATA); - to->attachments.add(makeShared(self, to, rboImage, fboID, rboID, 0)); + to->attachments.add(makeShared(self, to, rboImage, fboID, rboID, SGLTex{})); } } @@ -686,14 +686,16 @@ void CDRMRenderer::onBufferAttachmentDrop(CDRMRendererBufferAttachment* attachme TRACE(backend->log(AQ_LOG_TRACE, std::format("EGL (onBufferAttachmentDrop): dropping fbo {} rbo {} image 0x{:x}", attachment->fbo, attachment->rbo, (uintptr_t)attachment->eglImage))); - if (attachment->texid) - GLCALL(glDeleteTextures(1, &attachment->texid)); + if (attachment->tex.texid) + GLCALL(glDeleteTextures(1, &attachment->tex.texid)); if (attachment->rbo) GLCALL(glDeleteRenderbuffers(1, &attachment->rbo)); if (attachment->fbo) GLCALL(glDeleteFramebuffers(1, &attachment->fbo)); if (attachment->eglImage) egl.eglDestroyImageKHR(egl.display, attachment->eglImage); + if (attachment->tex.image) + egl.eglDestroyImageKHR(egl.display, attachment->tex.image); restoreEGL(); } @@ -719,7 +721,7 @@ bool CDRMRenderer::verifyDestinationDMABUF(const SDMABUFAttrs& attrs) { } CDRMRendererBufferAttachment::CDRMRendererBufferAttachment(Hyprutils::Memory::CWeakPointer renderer_, Hyprutils::Memory::CSharedPointer buffer, - EGLImageKHR image, GLuint fbo_, GLuint rbo_, GLuint texid_) : - eglImage(image), fbo(fbo_), rbo(rbo_), renderer(renderer_), texid(texid_) { + EGLImageKHR image, GLuint fbo_, GLuint rbo_, SGLTex tex_) : + eglImage(image), fbo(fbo_), rbo(rbo_), renderer(renderer_), tex(tex_) { bufferDestroy = buffer->events.destroy.registerListener([this](std::any d) { renderer->onBufferAttachmentDrop(this); }); } diff --git a/src/backend/drm/Renderer.hpp b/src/backend/drm/Renderer.hpp index c3b6e40..55d1420 100644 --- a/src/backend/drm/Renderer.hpp +++ b/src/backend/drm/Renderer.hpp @@ -11,10 +11,16 @@ #include namespace Aquamarine { + + struct SGLTex { + EGLImage image = nullptr; + GLuint texid = 0; + GLuint target = GL_TEXTURE_2D; + }; class CDRMRendererBufferAttachment : public IAttachment { public: CDRMRendererBufferAttachment(Hyprutils::Memory::CWeakPointer renderer_, Hyprutils::Memory::CSharedPointer buffer, EGLImageKHR image, GLuint fbo_, - GLuint rbo_, GLuint texid_); + GLuint rbo_, SGLTex tex); virtual ~CDRMRendererBufferAttachment() { ; } @@ -23,7 +29,8 @@ namespace Aquamarine { } EGLImageKHR eglImage = nullptr; - GLuint fbo = 0, rbo = 0, texid = 0; + GLuint fbo = 0, rbo = 0; + SGLTex tex; Hyprutils::Signal::CHyprSignalListener bufferDestroy; Hyprutils::Memory::CWeakPointer renderer; @@ -73,19 +80,13 @@ namespace Aquamarine { EGLSurface draw = nullptr, read = nullptr; } savedEGLState; - struct GLTex { - EGLImage image = nullptr; - GLuint texid = 0; - GLuint target = GL_TEXTURE_2D; - }; - struct GLFormat { uint32_t drmFormat = 0; uint64_t modifier = 0; bool external = false; }; - GLTex glTex(Hyprutils::Memory::CSharedPointer buf); + SGLTex glTex(Hyprutils::Memory::CSharedPointer buf); Hyprutils::Memory::CWeakPointer self; std::vector formats;