mirror of
https://github.com/hyprwm/aquamarine.git
synced 2025-01-27 20:09:48 +01:00
move renderer to EGLRenderer
This commit is contained in:
parent
7fe006981f
commit
70c8bdf371
9 changed files with 88 additions and 76 deletions
|
@ -63,6 +63,6 @@ namespace Aquamarine {
|
|||
int drmfd = -1;
|
||||
|
||||
friend class CDRMDumbBuffer;
|
||||
friend class CDRMRenderer;
|
||||
friend class CEGLRenderer;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -66,6 +66,6 @@ namespace Aquamarine {
|
|||
std::string drmName = "";
|
||||
|
||||
friend class CGBMBuffer;
|
||||
friend class CDRMRenderer;
|
||||
friend class CEGLRenderer;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Aquamarine {
|
|||
class CDRMFB;
|
||||
class CDRMOutput;
|
||||
struct SDRMConnector;
|
||||
class CDRMRenderer;
|
||||
class CEGLRenderer;
|
||||
class CDRMDumbAllocator;
|
||||
|
||||
typedef std::function<void(void)> FIdleCallback;
|
||||
|
@ -411,7 +411,7 @@ namespace Aquamarine {
|
|||
|
||||
struct {
|
||||
Hyprutils::Memory::CSharedPointer<IAllocator> allocator;
|
||||
Hyprutils::Memory::CSharedPointer<CDRMRenderer> renderer; // may be null if creation fails
|
||||
Hyprutils::Memory::CSharedPointer<CEGLRenderer> renderer; // may be null if creation fails
|
||||
} rendererState;
|
||||
|
||||
Hyprutils::Memory::CWeakPointer<CBackend> backend;
|
||||
|
|
|
@ -73,5 +73,4 @@ namespace Aquamarine {
|
|||
private:
|
||||
int locks = 0;
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <aquamarine/backend/DRM.hpp>
|
||||
#include <aquamarine/buffer/Buffer.hpp>
|
||||
#include "FormatUtils.hpp"
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
|
@ -21,11 +22,11 @@ namespace Aquamarine {
|
|||
GLuint target = GL_TEXTURE_2D;
|
||||
};
|
||||
|
||||
class CDRMRendererBufferAttachment : public IAttachment {
|
||||
class CEGLRendererBufferAttachment : public IAttachment {
|
||||
public:
|
||||
CDRMRendererBufferAttachment(Hyprutils::Memory::CWeakPointer<CDRMRenderer> renderer_, Hyprutils::Memory::CSharedPointer<IBuffer> buffer, EGLImageKHR image, GLuint fbo_,
|
||||
CEGLRendererBufferAttachment(Hyprutils::Memory::CWeakPointer<CEGLRenderer> renderer_, Hyprutils::Memory::CSharedPointer<IBuffer> buffer, EGLImageKHR image, GLuint fbo_,
|
||||
GLuint rbo_, SGLTex tex);
|
||||
virtual ~CDRMRendererBufferAttachment() {
|
||||
virtual ~CEGLRendererBufferAttachment() {
|
||||
;
|
||||
}
|
||||
virtual eAttachmentType type() {
|
||||
|
@ -37,13 +38,13 @@ namespace Aquamarine {
|
|||
SGLTex tex;
|
||||
Hyprutils::Signal::CHyprSignalListener bufferDestroy;
|
||||
|
||||
Hyprutils::Memory::CWeakPointer<CDRMRenderer> renderer;
|
||||
Hyprutils::Memory::CWeakPointer<CEGLRenderer> renderer;
|
||||
};
|
||||
|
||||
class CDRMRenderer {
|
||||
class CEGLRenderer {
|
||||
public:
|
||||
~CDRMRenderer();
|
||||
static Hyprutils::Memory::CSharedPointer<CDRMRenderer> attempt(Hyprutils::Memory::CSharedPointer<CGBMAllocator> allocator_,
|
||||
~CEGLRenderer();
|
||||
static Hyprutils::Memory::CSharedPointer<CEGLRenderer> attempt(Hyprutils::Memory::CSharedPointer<CGBMAllocator> allocator_,
|
||||
Hyprutils::Memory::CSharedPointer<CBackend> backend_);
|
||||
|
||||
int drmFD = -1;
|
||||
|
@ -60,7 +61,7 @@ namespace Aquamarine {
|
|||
void setEGL();
|
||||
void restoreEGL();
|
||||
|
||||
void onBufferAttachmentDrop(CDRMRendererBufferAttachment* attachment);
|
||||
void onBufferAttachmentDrop(CEGLRendererBufferAttachment* attachment);
|
||||
|
||||
struct {
|
||||
struct SShader {
|
||||
|
@ -96,11 +97,11 @@ namespace Aquamarine {
|
|||
|
||||
SGLTex glTex(Hyprutils::Memory::CSharedPointer<IBuffer> buf);
|
||||
|
||||
Hyprutils::Memory::CWeakPointer<CDRMRenderer> self;
|
||||
Hyprutils::Memory::CWeakPointer<CEGLRenderer> self;
|
||||
std::vector<SGLFormat> formats;
|
||||
|
||||
private:
|
||||
CDRMRenderer() = default;
|
||||
CEGLRenderer() = default;
|
||||
|
||||
EGLImageKHR createEGLImage(const SDMABUFAttrs& attrs);
|
||||
std::optional<std::vector<std::pair<uint64_t, bool>>> getModsForFormat(EGLint format);
|
||||
|
@ -112,4 +113,4 @@ namespace Aquamarine {
|
|||
|
||||
Hyprutils::Memory::CWeakPointer<CBackend> backend;
|
||||
};
|
||||
};
|
||||
};
|
|
@ -2,6 +2,7 @@
|
|||
#include <aquamarine/backend/Backend.hpp>
|
||||
#include <aquamarine/backend/DRM.hpp>
|
||||
#include <aquamarine/allocator/Swapchain.hpp>
|
||||
#include <aquamarine/renderer/EGLRenderer.hpp>
|
||||
#include "FormatUtils.hpp"
|
||||
#include "Shared.hpp"
|
||||
#include <fcntl.h>
|
||||
|
@ -10,7 +11,6 @@
|
|||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
#include <sys/mman.h>
|
||||
#include "../backend/drm/Renderer.hpp"
|
||||
|
||||
using namespace Aquamarine;
|
||||
using namespace Hyprutils::Memory;
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
#include <aquamarine/backend/Backend.hpp>
|
||||
#include <aquamarine/backend/DRM.hpp>
|
||||
#include <aquamarine/allocator/Swapchain.hpp>
|
||||
#include <aquamarine/renderer/EGLRenderer.hpp>
|
||||
#include "FormatUtils.hpp"
|
||||
#include "Shared.hpp"
|
||||
#include <xf86drm.h>
|
||||
#include <gbm.h>
|
||||
#include <unistd.h>
|
||||
#include "../backend/drm/Renderer.hpp"
|
||||
|
||||
using namespace Aquamarine;
|
||||
using namespace Hyprutils::Memory;
|
||||
|
@ -24,8 +24,7 @@ static SDRMFormat guessFormatFrom(std::vector<SDRMFormat> formats, bool cursor,
|
|||
For cursors, don't, as these almost never support that.
|
||||
*/
|
||||
if (!scanout) {
|
||||
if (auto it =
|
||||
std::ranges::find_if(formats, [](const auto& f) { return f.drmFormat == DRM_FORMAT_ARGB2101010 || f.drmFormat == DRM_FORMAT_ABGR2101010; });
|
||||
if (auto it = std::ranges::find_if(formats, [](const auto& f) { return f.drmFormat == DRM_FORMAT_ARGB2101010 || f.drmFormat == DRM_FORMAT_ABGR2101010; });
|
||||
it != formats.end())
|
||||
return *it;
|
||||
}
|
||||
|
@ -36,13 +35,11 @@ static SDRMFormat guessFormatFrom(std::vector<SDRMFormat> formats, bool cursor,
|
|||
}
|
||||
|
||||
if (!scanout || cursor /* don't set opaque for cursor plane */) {
|
||||
if (auto it = std::ranges::find_if(formats, [](const auto& f) { return f.drmFormat == DRM_FORMAT_ARGB8888 || f.drmFormat == DRM_FORMAT_ABGR8888; });
|
||||
it != formats.end())
|
||||
if (auto it = std::ranges::find_if(formats, [](const auto& f) { return f.drmFormat == DRM_FORMAT_ARGB8888 || f.drmFormat == DRM_FORMAT_ABGR8888; }); it != formats.end())
|
||||
return *it;
|
||||
}
|
||||
|
||||
if (auto it = std::ranges::find_if(formats, [](const auto& f) { return f.drmFormat == DRM_FORMAT_XRGB8888 || f.drmFormat == DRM_FORMAT_XBGR8888; });
|
||||
it != formats.end())
|
||||
if (auto it = std::ranges::find_if(formats, [](const auto& f) { return f.drmFormat == DRM_FORMAT_XRGB8888 || f.drmFormat == DRM_FORMAT_XBGR8888; }); it != formats.end())
|
||||
return *it;
|
||||
|
||||
for (auto const& f : formats) {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <aquamarine/backend/drm/Atomic.hpp>
|
||||
#include <aquamarine/allocator/GBM.hpp>
|
||||
#include <aquamarine/allocator/DRMDumb.hpp>
|
||||
#include <aquamarine/renderer/EGLRenderer.hpp>
|
||||
#include <cstdint>
|
||||
#include <format>
|
||||
#include <hyprutils/string/VarList.hpp>
|
||||
|
@ -32,7 +33,6 @@ extern "C" {
|
|||
#include "FormatUtils.hpp"
|
||||
#include "Shared.hpp"
|
||||
#include "hwdata.hpp"
|
||||
#include "Renderer.hpp"
|
||||
|
||||
using namespace Aquamarine;
|
||||
using namespace Hyprutils::Memory;
|
||||
|
@ -562,7 +562,7 @@ bool Aquamarine::CDRMBackend::initMgpu() {
|
|||
return false;
|
||||
}
|
||||
|
||||
rendererState.renderer = CDRMRenderer::attempt(newAllocator, backend.lock());
|
||||
rendererState.renderer = CEGLRenderer::attempt(newAllocator, backend.lock());
|
||||
|
||||
if (!rendererState.renderer) {
|
||||
backend->log(AQ_LOG_ERROR, "drm: initMgpu: no renderer");
|
||||
|
@ -937,7 +937,7 @@ void Aquamarine::CDRMBackend::onReady() {
|
|||
if (!a)
|
||||
backend->log(AQ_LOG_ERROR, "drm: onReady: no renderer for gl formats");
|
||||
else {
|
||||
auto r = CDRMRenderer::attempt(a, backend.lock());
|
||||
auto r = CEGLRenderer::attempt(a, backend.lock());
|
||||
if (!r)
|
||||
backend->log(AQ_LOG_ERROR, "drm: onReady: no renderer for gl formats");
|
||||
else {
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
#include "Renderer.hpp"
|
||||
#include <xf86drm.h>
|
||||
#include <xf86drmMode.h>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include "Math.hpp"
|
||||
#include "../backend/drm/Math.hpp"
|
||||
#include "Shared.hpp"
|
||||
#include "FormatUtils.hpp"
|
||||
#include <aquamarine/allocator/GBM.hpp>
|
||||
#include <aquamarine/renderer/EGLRenderer.hpp>
|
||||
|
||||
using namespace Aquamarine;
|
||||
using namespace Hyprutils::Memory;
|
||||
|
@ -108,7 +108,7 @@ inline void loadGLProc(void* pProc, const char* name) {
|
|||
|
||||
// -------------------
|
||||
|
||||
std::optional<std::vector<std::pair<uint64_t, bool>>> CDRMRenderer::getModsForFormat(EGLint format) {
|
||||
std::optional<std::vector<std::pair<uint64_t, bool>>> CEGLRenderer::getModsForFormat(EGLint format) {
|
||||
// TODO: return std::expected when clang supports it
|
||||
|
||||
EGLint len = 0;
|
||||
|
@ -140,7 +140,7 @@ std::optional<std::vector<std::pair<uint64_t, bool>>> CDRMRenderer::getModsForFo
|
|||
return result;
|
||||
}
|
||||
|
||||
bool CDRMRenderer::initDRMFormats() {
|
||||
bool CEGLRenderer::initDRMFormats() {
|
||||
std::vector<EGLint> formats;
|
||||
|
||||
EGLint len = 0;
|
||||
|
@ -198,7 +198,7 @@ bool CDRMRenderer::initDRMFormats() {
|
|||
return true;
|
||||
}
|
||||
|
||||
Aquamarine::CDRMRenderer::~CDRMRenderer() {
|
||||
Aquamarine::CEGLRenderer::~CEGLRenderer() {
|
||||
eglMakeCurrent(egl.display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||
eglDestroyContext(egl.display, egl.context);
|
||||
|
||||
|
@ -207,8 +207,8 @@ Aquamarine::CDRMRenderer::~CDRMRenderer() {
|
|||
eglReleaseThread();
|
||||
}
|
||||
|
||||
SP<CDRMRenderer> CDRMRenderer::attempt(Hyprutils::Memory::CSharedPointer<CGBMAllocator> allocator_, SP<CBackend> backend_) {
|
||||
SP<CDRMRenderer> renderer = SP<CDRMRenderer>(new CDRMRenderer());
|
||||
SP<CEGLRenderer> CEGLRenderer::attempt(Hyprutils::Memory::CSharedPointer<CGBMAllocator> allocator_, SP<CBackend> backend_) {
|
||||
SP<CEGLRenderer> renderer = SP<CEGLRenderer>(new CEGLRenderer());
|
||||
renderer->drmFD = allocator_->drmFD();
|
||||
renderer->backend = backend_;
|
||||
gBackend = backend_;
|
||||
|
@ -216,14 +216,14 @@ SP<CDRMRenderer> CDRMRenderer::attempt(Hyprutils::Memory::CSharedPointer<CGBMAll
|
|||
const std::string EGLEXTENSIONS = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
|
||||
|
||||
if (!EGLEXTENSIONS.contains("KHR_platform_gbm")) {
|
||||
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, no gbm support");
|
||||
backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, no gbm support");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// init egl
|
||||
|
||||
if (eglBindAPI(EGL_OPENGL_ES_API) == EGL_FALSE) {
|
||||
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, eglBindAPI failed");
|
||||
backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, eglBindAPI failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -240,45 +240,45 @@ SP<CDRMRenderer> CDRMRenderer::attempt(Hyprutils::Memory::CSharedPointer<CGBMAll
|
|||
loadGLProc(&renderer->egl.eglDupNativeFenceFDANDROID, "eglDupNativeFenceFDANDROID");
|
||||
|
||||
if (!renderer->egl.eglCreateSyncKHR) {
|
||||
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, no eglCreateSyncKHR");
|
||||
backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, no eglCreateSyncKHR");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!renderer->egl.eglDupNativeFenceFDANDROID) {
|
||||
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, no eglDupNativeFenceFDANDROID");
|
||||
backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, no eglDupNativeFenceFDANDROID");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!renderer->egl.eglGetPlatformDisplayEXT) {
|
||||
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, no eglGetPlatformDisplayEXT");
|
||||
backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, no eglGetPlatformDisplayEXT");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!renderer->egl.eglCreateImageKHR) {
|
||||
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, no eglCreateImageKHR");
|
||||
backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, no eglCreateImageKHR");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!renderer->egl.eglQueryDmaBufFormatsEXT) {
|
||||
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, no eglQueryDmaBufFormatsEXT");
|
||||
backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, no eglQueryDmaBufFormatsEXT");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!renderer->egl.eglQueryDmaBufModifiersEXT) {
|
||||
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, no eglQueryDmaBufModifiersEXT");
|
||||
backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, no eglQueryDmaBufModifiersEXT");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<EGLint> attrs = {EGL_NONE};
|
||||
renderer->egl.display = renderer->egl.eglGetPlatformDisplayEXT(EGL_PLATFORM_GBM_KHR, allocator_->gbmDevice, attrs.data());
|
||||
if (renderer->egl.display == EGL_NO_DISPLAY) {
|
||||
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, eglGetPlatformDisplayEXT failed");
|
||||
backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, eglGetPlatformDisplayEXT failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
EGLint major, minor;
|
||||
if (eglInitialize(renderer->egl.display, &major, &minor) == EGL_FALSE) {
|
||||
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, eglInitialize failed");
|
||||
backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, eglInitialize failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -297,12 +297,12 @@ SP<CDRMRenderer> CDRMRenderer::attempt(Hyprutils::Memory::CSharedPointer<CGBMAll
|
|||
}
|
||||
|
||||
if (!EGLEXTENSIONS2.contains("EXT_image_dma_buf_import_modifiers")) {
|
||||
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, no EXT_image_dma_buf_import_modifiers ext");
|
||||
backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, no EXT_image_dma_buf_import_modifiers ext");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!EGLEXTENSIONS2.contains("EXT_image_dma_buf_import")) {
|
||||
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, no EXT_image_dma_buf_import ext");
|
||||
backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, no EXT_image_dma_buf_import ext");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -317,7 +317,7 @@ SP<CDRMRenderer> CDRMRenderer::attempt(Hyprutils::Memory::CSharedPointer<CGBMAll
|
|||
|
||||
renderer->egl.context = eglCreateContext(renderer->egl.display, EGL_NO_CONFIG_KHR, EGL_NO_CONTEXT, attrs.data());
|
||||
if (renderer->egl.context == EGL_NO_CONTEXT) {
|
||||
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, eglCreateContext failed");
|
||||
backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, eglCreateContext failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -325,9 +325,9 @@ SP<CDRMRenderer> CDRMRenderer::attempt(Hyprutils::Memory::CSharedPointer<CGBMAll
|
|||
EGLint priority = EGL_CONTEXT_PRIORITY_MEDIUM_IMG;
|
||||
eglQueryContext(renderer->egl.display, renderer->egl.context, EGL_CONTEXT_PRIORITY_LEVEL_IMG, &priority);
|
||||
if (priority != EGL_CONTEXT_PRIORITY_HIGH_IMG)
|
||||
backend_->log(AQ_LOG_DEBUG, "CDRMRenderer: didnt get a high priority context");
|
||||
backend_->log(AQ_LOG_DEBUG, "CEGLRenderer: didnt get a high priority context");
|
||||
else
|
||||
backend_->log(AQ_LOG_DEBUG, "CDRMRenderer: got a high priority context");
|
||||
backend_->log(AQ_LOG_DEBUG, "CEGLRenderer: got a high priority context");
|
||||
}
|
||||
|
||||
// init shaders
|
||||
|
@ -335,13 +335,13 @@ SP<CDRMRenderer> CDRMRenderer::attempt(Hyprutils::Memory::CSharedPointer<CGBMAll
|
|||
renderer->setEGL();
|
||||
|
||||
if (!renderer->initDRMFormats()) {
|
||||
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, initDRMFormats failed");
|
||||
backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, initDRMFormats failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
renderer->gl.shader.program = createProgram(VERT_SRC, FRAG_SRC);
|
||||
if (renderer->gl.shader.program == 0) {
|
||||
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, shader failed");
|
||||
backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, shader failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -352,7 +352,7 @@ SP<CDRMRenderer> CDRMRenderer::attempt(Hyprutils::Memory::CSharedPointer<CGBMAll
|
|||
|
||||
renderer->gl.shaderExt.program = createProgram(VERT_SRC, FRAG_SRC_EXT);
|
||||
if (renderer->gl.shaderExt.program == 0) {
|
||||
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, shaderExt failed");
|
||||
backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, shaderExt failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -363,22 +363,22 @@ SP<CDRMRenderer> CDRMRenderer::attempt(Hyprutils::Memory::CSharedPointer<CGBMAll
|
|||
|
||||
renderer->restoreEGL();
|
||||
|
||||
backend_->log(AQ_LOG_DEBUG, "CDRMRenderer: success");
|
||||
backend_->log(AQ_LOG_DEBUG, "CEGLRenderer: success");
|
||||
|
||||
return renderer;
|
||||
}
|
||||
|
||||
void CDRMRenderer::setEGL() {
|
||||
void CEGLRenderer::setEGL() {
|
||||
savedEGLState.display = eglGetCurrentDisplay();
|
||||
savedEGLState.context = eglGetCurrentContext();
|
||||
savedEGLState.draw = eglGetCurrentSurface(EGL_DRAW);
|
||||
savedEGLState.read = eglGetCurrentSurface(EGL_READ);
|
||||
|
||||
if (!eglMakeCurrent(egl.display, EGL_NO_SURFACE, EGL_NO_SURFACE, egl.context))
|
||||
backend->log(AQ_LOG_WARNING, "CDRMRenderer: setEGL eglMakeCurrent failed");
|
||||
backend->log(AQ_LOG_WARNING, "CEGLRenderer: setEGL eglMakeCurrent failed");
|
||||
}
|
||||
|
||||
void CDRMRenderer::restoreEGL() {
|
||||
void CEGLRenderer::restoreEGL() {
|
||||
EGLDisplay dpy = savedEGLState.display ? savedEGLState.display : egl.display;
|
||||
|
||||
// egl can't handle this
|
||||
|
@ -386,10 +386,10 @@ void CDRMRenderer::restoreEGL() {
|
|||
return;
|
||||
|
||||
if (!eglMakeCurrent(dpy, savedEGLState.draw, savedEGLState.read, savedEGLState.context))
|
||||
backend->log(AQ_LOG_WARNING, "CDRMRenderer: restoreEGL eglMakeCurrent failed");
|
||||
backend->log(AQ_LOG_WARNING, "CEGLRenderer: restoreEGL eglMakeCurrent failed");
|
||||
}
|
||||
|
||||
EGLImageKHR CDRMRenderer::createEGLImage(const SDMABUFAttrs& attrs) {
|
||||
EGLImageKHR CEGLRenderer::createEGLImage(const SDMABUFAttrs& attrs) {
|
||||
std::vector<uint32_t> attribs;
|
||||
|
||||
attribs.push_back(EGL_WIDTH);
|
||||
|
@ -407,11 +407,26 @@ EGLImageKHR CDRMRenderer::createEGLImage(const SDMABUFAttrs& attrs) {
|
|||
EGLint pitch;
|
||||
EGLint modlo;
|
||||
EGLint modhi;
|
||||
} attrNames[4] = {
|
||||
{.fd = EGL_DMA_BUF_PLANE0_FD_EXT, .offset = EGL_DMA_BUF_PLANE0_OFFSET_EXT, .pitch = EGL_DMA_BUF_PLANE0_PITCH_EXT, .modlo = EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT, .modhi = EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT},
|
||||
{.fd = EGL_DMA_BUF_PLANE1_FD_EXT, .offset = EGL_DMA_BUF_PLANE1_OFFSET_EXT, .pitch = EGL_DMA_BUF_PLANE1_PITCH_EXT, .modlo = EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT, .modhi = EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT},
|
||||
{.fd = EGL_DMA_BUF_PLANE2_FD_EXT, .offset = EGL_DMA_BUF_PLANE2_OFFSET_EXT, .pitch = EGL_DMA_BUF_PLANE2_PITCH_EXT, .modlo = EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT, .modhi = EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT},
|
||||
{.fd = EGL_DMA_BUF_PLANE3_FD_EXT, .offset = EGL_DMA_BUF_PLANE3_OFFSET_EXT, .pitch = EGL_DMA_BUF_PLANE3_PITCH_EXT, .modlo = EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT, .modhi = EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT}};
|
||||
} attrNames[4] = {{.fd = EGL_DMA_BUF_PLANE0_FD_EXT,
|
||||
.offset = EGL_DMA_BUF_PLANE0_OFFSET_EXT,
|
||||
.pitch = EGL_DMA_BUF_PLANE0_PITCH_EXT,
|
||||
.modlo = EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT,
|
||||
.modhi = EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT},
|
||||
{.fd = EGL_DMA_BUF_PLANE1_FD_EXT,
|
||||
.offset = EGL_DMA_BUF_PLANE1_OFFSET_EXT,
|
||||
.pitch = EGL_DMA_BUF_PLANE1_PITCH_EXT,
|
||||
.modlo = EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT,
|
||||
.modhi = EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT},
|
||||
{.fd = EGL_DMA_BUF_PLANE2_FD_EXT,
|
||||
.offset = EGL_DMA_BUF_PLANE2_OFFSET_EXT,
|
||||
.pitch = EGL_DMA_BUF_PLANE2_PITCH_EXT,
|
||||
.modlo = EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT,
|
||||
.modhi = EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT},
|
||||
{.fd = EGL_DMA_BUF_PLANE3_FD_EXT,
|
||||
.offset = EGL_DMA_BUF_PLANE3_OFFSET_EXT,
|
||||
.pitch = EGL_DMA_BUF_PLANE3_PITCH_EXT,
|
||||
.modlo = EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT,
|
||||
.modhi = EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT}};
|
||||
|
||||
for (int i = 0; i < attrs.planes; i++) {
|
||||
attribs.push_back(attrNames[i].fd);
|
||||
|
@ -453,7 +468,7 @@ EGLImageKHR CDRMRenderer::createEGLImage(const SDMABUFAttrs& attrs) {
|
|||
} \
|
||||
}
|
||||
|
||||
SGLTex CDRMRenderer::glTex(Hyprutils::Memory::CSharedPointer<IBuffer> buffa) {
|
||||
SGLTex CEGLRenderer::glTex(Hyprutils::Memory::CSharedPointer<IBuffer> buffa) {
|
||||
SGLTex tex;
|
||||
|
||||
const auto dma = buffa->dmabuf();
|
||||
|
@ -469,7 +484,7 @@ SGLTex CDRMRenderer::glTex(Hyprutils::Memory::CSharedPointer<IBuffer> buffa) {
|
|||
if (fmt.drmFormat != dma.format || fmt.modifier != dma.modifier)
|
||||
continue;
|
||||
|
||||
backend->log(AQ_LOG_DEBUG, std::format("CDRMRenderer::glTex: found format+mod, external = {}", fmt.external));
|
||||
backend->log(AQ_LOG_DEBUG, std::format("CEGLRenderer::glTex: found format+mod, external = {}", fmt.external));
|
||||
external = fmt.external;
|
||||
break;
|
||||
}
|
||||
|
@ -494,7 +509,7 @@ inline const float fullVerts[] = {
|
|||
0, 1, // bottom left
|
||||
};
|
||||
|
||||
void CDRMRenderer::waitOnSync(int fd) {
|
||||
void CEGLRenderer::waitOnSync(int fd) {
|
||||
TRACE(backend->log(AQ_LOG_TRACE, std::format("EGL (waitOnSync): attempting to wait on fd {}", fd)));
|
||||
|
||||
std::vector<EGLint> attribs;
|
||||
|
@ -529,7 +544,7 @@ void CDRMRenderer::waitOnSync(int fd) {
|
|||
TRACE(backend->log(AQ_LOG_TRACE, "EGL (waitOnSync): failed to destroy sync"));
|
||||
}
|
||||
|
||||
int CDRMRenderer::recreateBlitSync() {
|
||||
int CEGLRenderer::recreateBlitSync() {
|
||||
TRACE(backend->log(AQ_LOG_TRACE, "EGL (recreateBlitSync): recreating blit sync"));
|
||||
|
||||
if (egl.lastBlitSync) {
|
||||
|
@ -571,7 +586,7 @@ int CDRMRenderer::recreateBlitSync() {
|
|||
return fd;
|
||||
}
|
||||
|
||||
void CDRMRenderer::clearBuffer(IBuffer* buf) {
|
||||
void CEGLRenderer::clearBuffer(IBuffer* buf) {
|
||||
setEGL();
|
||||
|
||||
auto dmabuf = buf->dmabuf();
|
||||
|
@ -617,7 +632,7 @@ void CDRMRenderer::clearBuffer(IBuffer* buf) {
|
|||
restoreEGL();
|
||||
}
|
||||
|
||||
CDRMRenderer::SBlitResult CDRMRenderer::blit(SP<IBuffer> from, SP<IBuffer> to, int waitFD) {
|
||||
CEGLRenderer::SBlitResult CEGLRenderer::blit(SP<IBuffer> from, SP<IBuffer> to, int waitFD) {
|
||||
setEGL();
|
||||
|
||||
if (from->dmabuf().size != to->dmabuf().size) {
|
||||
|
@ -640,7 +655,7 @@ CDRMRenderer::SBlitResult CDRMRenderer::blit(SP<IBuffer> from, SP<IBuffer> to, i
|
|||
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();
|
||||
auto att = (CEGLRendererBufferAttachment*)attachment.get();
|
||||
fromTex = att->tex;
|
||||
}
|
||||
|
||||
|
@ -650,7 +665,7 @@ CDRMRenderer::SBlitResult CDRMRenderer::blit(SP<IBuffer> from, SP<IBuffer> to, i
|
|||
|
||||
// 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<CDRMRendererBufferAttachment>(self, from, nullptr, 0, 0, fromTex));
|
||||
from->attachments.add(makeShared<CEGLRendererBufferAttachment>(self, from, nullptr, 0, 0, fromTex));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -674,7 +689,7 @@ CDRMRenderer::SBlitResult CDRMRenderer::blit(SP<IBuffer> from, SP<IBuffer> to, i
|
|||
auto attachment = to->attachments.get(AQ_ATTACHMENT_DRM_RENDERER_DATA);
|
||||
if (attachment) {
|
||||
TRACE(backend->log(AQ_LOG_TRACE, "EGL (blit): To attachment found"));
|
||||
auto att = (CDRMRendererBufferAttachment*)attachment.get();
|
||||
auto att = (CEGLRendererBufferAttachment*)attachment.get();
|
||||
rboImage = att->eglImage;
|
||||
fboID = att->fbo;
|
||||
rboID = att->rbo;
|
||||
|
@ -705,7 +720,7 @@ CDRMRenderer::SBlitResult CDRMRenderer::blit(SP<IBuffer> from, SP<IBuffer> to, i
|
|||
|
||||
// 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<CDRMRendererBufferAttachment>(self, to, rboImage, fboID, rboID, SGLTex{}));
|
||||
to->attachments.add(makeShared<CEGLRendererBufferAttachment>(self, to, rboImage, fboID, rboID, SGLTex{}));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -791,7 +806,7 @@ CDRMRenderer::SBlitResult CDRMRenderer::blit(SP<IBuffer> from, SP<IBuffer> to, i
|
|||
return {.success = true, .syncFD = explicitFD == -1 ? std::nullopt : std::optional<int>{explicitFD}};
|
||||
}
|
||||
|
||||
void CDRMRenderer::onBufferAttachmentDrop(CDRMRendererBufferAttachment* attachment) {
|
||||
void CEGLRenderer::onBufferAttachmentDrop(CEGLRendererBufferAttachment* attachment) {
|
||||
setEGL();
|
||||
|
||||
TRACE(backend->log(AQ_LOG_TRACE,
|
||||
|
@ -811,7 +826,7 @@ void CDRMRenderer::onBufferAttachmentDrop(CDRMRendererBufferAttachment* attachme
|
|||
restoreEGL();
|
||||
}
|
||||
|
||||
bool CDRMRenderer::verifyDestinationDMABUF(const SDMABUFAttrs& attrs) {
|
||||
bool CEGLRenderer::verifyDestinationDMABUF(const SDMABUFAttrs& attrs) {
|
||||
for (auto const& fmt : formats) {
|
||||
if (fmt.drmFormat != attrs.format)
|
||||
continue;
|
||||
|
@ -826,7 +841,7 @@ bool CDRMRenderer::verifyDestinationDMABUF(const SDMABUFAttrs& attrs) {
|
|||
return false;
|
||||
}
|
||||
|
||||
CDRMRendererBufferAttachment::CDRMRendererBufferAttachment(Hyprutils::Memory::CWeakPointer<CDRMRenderer> renderer_, Hyprutils::Memory::CSharedPointer<IBuffer> buffer,
|
||||
CEGLRendererBufferAttachment::CEGLRendererBufferAttachment(Hyprutils::Memory::CWeakPointer<CEGLRenderer> renderer_, Hyprutils::Memory::CSharedPointer<IBuffer> buffer,
|
||||
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); });
|
Loading…
Reference in a new issue