summaryrefslogtreecommitdiff
path: root/src/render
diff options
context:
space:
mode:
authorTom Englund <tomenglund26@gmail.com>2025-01-30 12:30:12 +0100
committerGitHub <noreply@github.com>2025-01-30 11:30:12 +0000
commit32c0fa2f2fe02254d5887b38cf2cffa72ddfd769 (patch)
tree60a59e586526384f4bd8ac94dd083ca4fe0e4122 /src/render
parent7d1c78f4a3720b693fedeb5d4f2d3f4da37f7fd3 (diff)
core: begin using CFileDescriptor from hyprutils (#9122)
* config: make fd use CFileDescriptor make use of the new hyprutils CFileDescriptor instead of manual FD handling. * hyprctl: make fd use CFileDescriptor make use of the new hyprutils CFileDescriptor instead of manual FD handling. * ikeyboard: make fd use CFileDescriptor make use of the new CFileDescriptor instead of manual FD handling, also in sendKeymap remove dead code, it already early returns if keyboard isnt valid, and dont try to close the FD that ikeyboard owns. * core: make SHMFile functions use CFileDescriptor make SHMFile misc functions use CFileDescriptor and its associated usage in dmabuf and keyboard. * core: make explicit sync use CFileDescriptor begin using CFileDescriptor in explicit sync and its timelines and eglsync usage in opengl, there is still a bit left with manual handling that requires future aquamarine change aswell. * eventmgr: make fd and sockets use CFileDescriptor make use of the hyprutils CFileDescriptor instead of manual FD and socket handling and closing. * eventloopmgr: make timerfd use CFileDescriptor make the timerfd use CFileDescriptor instead of manual fd handling * opengl: make gbm fd use CFileDescriptor make the gbm rendernode fd use CFileDescriptor instead of manual fd handling * core: make selection source/offer use CFileDescriptor make data selection source and offers use CFileDescriptor and its associated use in xwm and protocols * protocols: convert protocols fd to CFileDescriptor make most fd handling use CFileDescriptor in protocols * shm: make SHMPool use CfileDescriptor make SHMPool use CFileDescriptor instead of manual fd handling. * opengl: duplicate fd with CFileDescriptor duplicate fenceFD with CFileDescriptor duplicate instead. * xwayland: make sockets and fds use CFileDescriptor instead of manual opening/closing make sockets and fds use CFileDescriptor * keybindmgr: make sockets and fds use CFileDescriptor make sockets and fds use CFileDescriptor instead of manual handling.
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();