mirror of
https://github.com/hyprwm/aquamarine.git
synced 2024-12-22 11:39:49 +01:00
drm/renderer: use the duped fd for gl
This commit is contained in:
parent
5199868794
commit
8d73016db8
4 changed files with 12 additions and 58 deletions
|
@ -64,5 +64,6 @@ namespace Aquamarine {
|
|||
std::string drmName = "";
|
||||
|
||||
friend class CGBMBuffer;
|
||||
friend class CDRMRenderer;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -475,14 +475,15 @@ bool Aquamarine::CDRMBackend::initMgpu() {
|
|||
if (!primary)
|
||||
return true;
|
||||
|
||||
mgpu.allocator = CGBMAllocator::create(backend->reopenDRMNode(gpu->fd), backend);
|
||||
auto newAllocator = CGBMAllocator::create(backend->reopenDRMNode(gpu->fd), backend);
|
||||
mgpu.allocator = newAllocator;
|
||||
|
||||
if (!mgpu.allocator) {
|
||||
backend->log(AQ_LOG_ERROR, "drm: initMgpu: no allocator");
|
||||
return false;
|
||||
}
|
||||
|
||||
mgpu.renderer = CDRMRenderer::attempt(gpu->fd, backend.lock());
|
||||
mgpu.renderer = CDRMRenderer::attempt(newAllocator, backend.lock());
|
||||
|
||||
if (!mgpu.renderer) {
|
||||
backend->log(AQ_LOG_ERROR, "drm: initMgpu: no renderer");
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "Shared.hpp"
|
||||
#include "FormatUtils.hpp"
|
||||
#include <xf86drm.h>
|
||||
#include <aquamarine/allocator/GBM.hpp>
|
||||
|
||||
using namespace Aquamarine;
|
||||
using namespace Hyprutils::Memory;
|
||||
|
@ -93,39 +94,6 @@ void main() {
|
|||
gl_FragColor = texture2D(texture0, v_texcoord);
|
||||
})#";
|
||||
|
||||
// ------------------- gbm stuff
|
||||
|
||||
static int openRenderNode(int drmFd) {
|
||||
auto renderName = drmGetRenderDeviceNameFromFd(drmFd);
|
||||
if (!renderName) {
|
||||
// This can happen on split render/display platforms, fallback to
|
||||
// primary node
|
||||
renderName = drmGetPrimaryDeviceNameFromFd(drmFd);
|
||||
if (!renderName) {
|
||||
gBackend->log(AQ_LOG_ERROR, "drmRenderer: drmGetPrimaryDeviceNameFromFd failed");
|
||||
return -1;
|
||||
}
|
||||
gBackend->log(AQ_LOG_WARNING, std::format("DRM dev {} has no render node, falling back to primary", renderName));
|
||||
|
||||
drmVersion* render_version = drmGetVersion(drmFd);
|
||||
if (render_version && render_version->name) {
|
||||
if (strcmp(render_version->name, "evdi") == 0) {
|
||||
free(renderName);
|
||||
renderName = (char*)malloc(sizeof(char) * 15);
|
||||
strcpy(renderName, "/dev/dri/card0");
|
||||
}
|
||||
drmFreeVersion(render_version);
|
||||
}
|
||||
}
|
||||
|
||||
int renderFD = open(renderName, O_RDWR | O_CLOEXEC);
|
||||
if (renderFD < 0)
|
||||
gBackend->log(AQ_LOG_ERROR, std::format("openRenderNode failed to open drm device {}", renderName));
|
||||
|
||||
free(renderName);
|
||||
return renderFD;
|
||||
}
|
||||
|
||||
// ------------------- egl stuff
|
||||
|
||||
inline void loadGLProc(void* pProc, const char* name) {
|
||||
|
@ -228,9 +196,9 @@ bool CDRMRenderer::initDRMFormats() {
|
|||
return true;
|
||||
}
|
||||
|
||||
SP<CDRMRenderer> CDRMRenderer::attempt(int drmfd, SP<CBackend> backend_) {
|
||||
SP<CDRMRenderer> CDRMRenderer::attempt(Hyprutils::Memory::CSharedPointer<CGBMAllocator> allocator_, SP<CBackend> backend_) {
|
||||
SP<CDRMRenderer> renderer = SP<CDRMRenderer>(new CDRMRenderer());
|
||||
renderer->drmFD = drmfd;
|
||||
renderer->drmFD = allocator_->drmFD();
|
||||
renderer->backend = backend_;
|
||||
gBackend = backend_;
|
||||
|
||||
|
@ -241,20 +209,6 @@ SP<CDRMRenderer> CDRMRenderer::attempt(int drmfd, SP<CBackend> backend_) {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
// init gbm stuff
|
||||
|
||||
renderer->gbm.fd = openRenderNode(drmfd);
|
||||
if (!renderer->gbm.fd) {
|
||||
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, no gbm fd");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
renderer->gbm.device = gbm_create_device(renderer->gbm.fd);
|
||||
if (!renderer->gbm.device) {
|
||||
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, no gbm device");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// init egl
|
||||
|
||||
if (eglBindAPI(EGL_OPENGL_ES_API) == EGL_FALSE) {
|
||||
|
@ -291,7 +245,7 @@ SP<CDRMRenderer> CDRMRenderer::attempt(int drmfd, SP<CBackend> backend_) {
|
|||
}
|
||||
|
||||
std::vector<EGLint> attrs = {EGL_NONE};
|
||||
renderer->egl.display = renderer->egl.eglGetPlatformDisplayEXT(EGL_PLATFORM_GBM_KHR, renderer->gbm.device, attrs.data());
|
||||
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");
|
||||
return nullptr;
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
|
||||
namespace Aquamarine {
|
||||
|
||||
class CGBMAllocator;
|
||||
|
||||
struct SGLTex {
|
||||
EGLImage image = nullptr;
|
||||
GLuint texid = 0;
|
||||
|
@ -38,7 +40,8 @@ namespace Aquamarine {
|
|||
|
||||
class CDRMRenderer {
|
||||
public:
|
||||
static Hyprutils::Memory::CSharedPointer<CDRMRenderer> attempt(int drmfd, Hyprutils::Memory::CSharedPointer<CBackend> backend_);
|
||||
static Hyprutils::Memory::CSharedPointer<CDRMRenderer> attempt(Hyprutils::Memory::CSharedPointer<CGBMAllocator> allocator_,
|
||||
Hyprutils::Memory::CSharedPointer<CBackend> backend_);
|
||||
|
||||
int drmFD = -1;
|
||||
|
||||
|
@ -56,11 +59,6 @@ namespace Aquamarine {
|
|||
} shader, shaderExt;
|
||||
} gl;
|
||||
|
||||
struct {
|
||||
int fd = -1;
|
||||
gbm_device* device = nullptr;
|
||||
} gbm;
|
||||
|
||||
struct {
|
||||
EGLDisplay display = nullptr;
|
||||
EGLContext context = nullptr;
|
||||
|
|
Loading…
Reference in a new issue