mirror of
https://github.com/hyprwm/Hyprland.git
synced 2025-08-04 06:01:56 -07:00
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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user