summaryrefslogtreecommitdiff
path: root/src/render
diff options
context:
space:
mode:
Diffstat (limited to 'src/render')
-rw-r--r--src/render/OpenGL.cpp41
-rw-r--r--src/render/OpenGL.hpp13
-rw-r--r--src/render/Renderer.cpp20
3 files changed, 33 insertions, 41 deletions
diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp
index 78b53c9b..e4aadd63 100644
--- a/src/render/OpenGL.cpp
+++ b/src/render/OpenGL.cpp
@@ -19,6 +19,7 @@
#include <fcntl.h>
#include <gbm.h>
#include <filesystem>
+using namespace Hyprutils::OS;
const std::vector<const char*> ASSET_PATHS = {
#ifdef DATAROOTDIR
@@ -301,11 +302,11 @@ CHyprOpenGLImpl::CHyprOpenGLImpl() : m_iDRMFD(g_pCompositor->m_iDRMFD) {
Debug::log(WARN, "EGL: EXT_platform_device or EGL_EXT_device_query not supported, using gbm");
if (EGLEXTENSIONS.contains("KHR_platform_gbm")) {
success = true;
- m_iGBMFD = openRenderNode(m_iDRMFD);
- if (m_iGBMFD < 0)
+ m_iGBMFD = CFileDescriptor{openRenderNode(m_iDRMFD)};
+ if (!m_iGBMFD.isValid())
RASSERT(false, "Couldn't open a gbm fd");
- m_pGbmDevice = gbm_create_device(m_iGBMFD);
+ m_pGbmDevice = gbm_create_device(m_iGBMFD.get());
if (!m_pGbmDevice)
RASSERT(false, "Couldn't open a gbm device");
@@ -371,9 +372,6 @@ CHyprOpenGLImpl::~CHyprOpenGLImpl() {
if (m_pGbmDevice)
gbm_device_destroy(m_pGbmDevice);
-
- if (m_iGBMFD >= 0)
- close(m_iGBMFD);
}
std::optional<std::vector<uint64_t>> CHyprOpenGLImpl::getModsForFormat(EGLint format) {
@@ -2954,29 +2952,28 @@ std::vector<SDRMFormat> CHyprOpenGLImpl::getDRMFormats() {
return drmFormats;
}
-SP<CEGLSync> CHyprOpenGLImpl::createEGLSync(int fenceFD) {
+SP<CEGLSync> CHyprOpenGLImpl::createEGLSync(CFileDescriptor fenceFD) {
std::vector<EGLint> attribs;
- int dupFd = -1;
- if (fenceFD > 0) {
- dupFd = fcntl(fenceFD, F_DUPFD_CLOEXEC, 0);
- if (dupFd < 0) {
+ CFileDescriptor dupFd;
+ if (fenceFD.isValid()) {
+ dupFd = fenceFD.duplicate();
+ if (!dupFd.isValid()) {
Debug::log(ERR, "createEGLSync: dup failed");
return nullptr;
}
// reserve number of elements to avoid reallocations
attribs.reserve(3);
attribs.push_back(EGL_SYNC_NATIVE_FENCE_FD_ANDROID);
- attribs.push_back(dupFd);
+ attribs.push_back(dupFd.get());
attribs.push_back(EGL_NONE);
}
EGLSyncKHR sync = m_sProc.eglCreateSyncKHR(m_pEglDisplay, EGL_SYNC_NATIVE_FENCE_ANDROID, attribs.data());
if (sync == EGL_NO_SYNC_KHR) {
Debug::log(ERR, "eglCreateSyncKHR failed");
- if (dupFd >= 0)
- close(dupFd);
return nullptr;
- }
+ } else
+ dupFd.take(); // eglCreateSyncKHR only takes ownership on success
// we need to flush otherwise we might not get a valid fd
glFlush();
@@ -2989,19 +2986,18 @@ SP<CEGLSync> CHyprOpenGLImpl::createEGLSync(int fenceFD) {
auto eglsync = SP<CEGLSync>(new CEGLSync);
eglsync->sync = sync;
- eglsync->m_iFd = fd;
+ eglsync->m_iFd = CFileDescriptor{fd};
return eglsync;
}
bool CHyprOpenGLImpl::waitForTimelinePoint(SP<CSyncTimeline> timeline, uint64_t point) {
- int fd = timeline->exportAsSyncFileFD(point);
- if (fd < 0) {
+ auto fd = timeline->exportAsSyncFileFD(point);
+ if (!fd.isValid()) {
Debug::log(ERR, "waitForTimelinePoint: failed to get a fd from explicit timeline");
return false;
}
- auto sync = g_pHyprOpenGL->createEGLSync(fd);
- close(fd);
+ auto sync = g_pHyprOpenGL->createEGLSync(std::move(fd));
if (!sync) {
Debug::log(ERR, "waitForTimelinePoint: failed to get an eglsync from explicit timeline");
return false;
@@ -3082,12 +3078,9 @@ CEGLSync::~CEGLSync() {
if (g_pHyprOpenGL->m_sProc.eglDestroySyncKHR(g_pHyprOpenGL->m_pEglDisplay, sync) != EGL_TRUE)
Debug::log(ERR, "eglDestroySyncKHR failed");
-
- if (m_iFd >= 0)
- close(m_iFd);
}
-int CEGLSync::fd() {
+CFileDescriptor& CEGLSync::fd() {
return m_iFd;
}
diff --git a/src/render/OpenGL.hpp b/src/render/OpenGL.hpp
index 1ebb0162..d7abdf63 100644
--- a/src/render/OpenGL.hpp
+++ b/src/render/OpenGL.hpp
@@ -24,6 +24,7 @@
#include <EGL/eglext.h>
#include <GLES2/gl2ext.h>
#include <aquamarine/buffer/Buffer.hpp>
+#include <hyprutils/os/FileDescriptor.hpp>
#include "../debug/TracyDefines.hpp"
@@ -146,15 +147,15 @@ class CEGLSync {
public:
~CEGLSync();
- EGLSyncKHR sync = nullptr;
+ EGLSyncKHR sync = nullptr;
- int fd();
- bool wait();
+ Hyprutils::OS::CFileDescriptor& fd();
+ bool wait();
private:
CEGLSync() = default;
- int m_iFd = -1;
+ Hyprutils::OS::CFileDescriptor m_iFd;
friend class CHyprOpenGLImpl;
};
@@ -228,14 +229,14 @@ class CHyprOpenGLImpl {
uint32_t getPreferredReadFormat(PHLMONITOR pMonitor);
std::vector<SDRMFormat> getDRMFormats();
EGLImageKHR createEGLImage(const Aquamarine::SDMABUFAttrs& attrs);
- SP<CEGLSync> createEGLSync(int fenceFD);
+ SP<CEGLSync> createEGLSync(Hyprutils::OS::CFileDescriptor fenceFD);
bool waitForTimelinePoint(SP<CSyncTimeline> timeline, uint64_t point);
SCurrentRenderData m_RenderData;
GLint m_iCurrentOutputFb = 0;
- int m_iGBMFD = -1;
+ Hyprutils::OS::CFileDescriptor m_iGBMFD;
gbm_device* m_pGbmDevice = nullptr;
EGLContext m_pEglContext = nullptr;
EGLDisplay m_pEglDisplay = nullptr;
diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp
index 67d8b58b..42445728 100644
--- a/src/render/Renderer.cpp
+++ b/src/render/Renderer.cpp
@@ -36,6 +36,7 @@
#include <hyprutils/utils/ScopeGuard.hpp>
using namespace Hyprutils::Utils;
+using namespace Hyprutils::OS;
extern "C" {
#include <xf86drm.h>
@@ -1462,10 +1463,10 @@ static hdr_output_metadata createHDRMetadata(SImageDescription settings, Aquamar
bool CHyprRenderer::commitPendingAndDoExplicitSync(PHLMONITOR pMonitor) {
// apply timelines for explicit sync
// save inFD otherwise reset will reset it
- auto inFD = pMonitor->output->state->state().explicitInFence;
+ CFileDescriptor inFD{pMonitor->output->state->state().explicitInFence};
pMonitor->output->state->resetExplicitFences();
- if (inFD >= 0)
- pMonitor->output->state->setExplicitInFence(inFD);
+ if (inFD.isValid())
+ pMonitor->output->state->setExplicitInFence(inFD.get());
static auto PHDR = CConfigValue<Hyprlang::INT>("experimental:hdr");
@@ -1515,7 +1516,7 @@ bool CHyprRenderer::commitPendingAndDoExplicitSync(PHLMONITOR pMonitor) {
bool ok = pMonitor->state.commit();
if (!ok) {
- if (inFD >= 0) {
+ if (inFD.isValid()) {
Debug::log(TRACE, "Monitor state commit failed, retrying without a fence");
pMonitor->output->state->resetExplicitFences();
ok = pMonitor->state.commit();
@@ -1534,11 +1535,8 @@ bool CHyprRenderer::commitPendingAndDoExplicitSync(PHLMONITOR pMonitor) {
if (!explicitOptions.explicitEnabled)
return ok;
- if (inFD >= 0)
- close(inFD);
-
Debug::log(TRACE, "Explicit: {} presented", explicitPresented.size());
- auto sync = g_pHyprOpenGL->createEGLSync(-1);
+ auto sync = g_pHyprOpenGL->createEGLSync({});
if (!sync)
Debug::log(TRACE, "Explicit: can't add sync, EGLSync failed");
@@ -2272,7 +2270,7 @@ void CHyprRenderer::endRender() {
auto explicitOptions = getExplicitSyncSettings();
if (PMONITOR->inTimeline && explicitOptions.explicitEnabled && explicitOptions.explicitKMSEnabled) {
- auto sync = g_pHyprOpenGL->createEGLSync(-1);
+ auto sync = g_pHyprOpenGL->createEGLSync({});
if (!sync) {
Debug::log(ERR, "renderer: couldn't create an EGLSync for out in endRender");
return;
@@ -2285,12 +2283,12 @@ void CHyprRenderer::endRender() {
}
auto fd = PMONITOR->inTimeline->exportAsSyncFileFD(PMONITOR->commitSeq);
- if (fd <= 0) {
+ if (!fd.isValid()) {
Debug::log(ERR, "renderer: couldn't export from sync timeline in endRender");
return;
}
- PMONITOR->output->state->setExplicitInFence(fd);
+ PMONITOR->output->state->setExplicitInFence(fd.take());
} else {
if (isNvidia() && *PNVIDIAANTIFLICKER)
glFinish();