mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-26 11:25:59 +01:00
opengl: move to CFileDescriptor
use CFileDescriptor in m_iGBMFD and eglsync functions, convert related usage aswell.
This commit is contained in:
parent
ec58b255b3
commit
c058551ff1
3 changed files with 18 additions and 25 deletions
|
@ -296,11 +296,11 @@ CHyprOpenGLImpl::CHyprOpenGLImpl() {
|
||||||
Debug::log(WARN, "EGL: EXT_platform_device or EGL_EXT_device_query not supported, using gbm");
|
Debug::log(WARN, "EGL: EXT_platform_device or EGL_EXT_device_query not supported, using gbm");
|
||||||
if (EGLEXTENSIONS.contains("KHR_platform_gbm")) {
|
if (EGLEXTENSIONS.contains("KHR_platform_gbm")) {
|
||||||
success = true;
|
success = true;
|
||||||
m_iGBMFD = openRenderNode(m_iDRMFD);
|
m_iGBMFD = CFileDescriptor(openRenderNode(m_iDRMFD));
|
||||||
if (m_iGBMFD < 0)
|
if (!m_iGBMFD.isValid())
|
||||||
RASSERT(false, "Couldn't open a gbm fd");
|
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)
|
if (!m_pGbmDevice)
|
||||||
RASSERT(false, "Couldn't open a gbm device");
|
RASSERT(false, "Couldn't open a gbm device");
|
||||||
|
|
||||||
|
@ -366,9 +366,6 @@ CHyprOpenGLImpl::~CHyprOpenGLImpl() {
|
||||||
|
|
||||||
if (m_pGbmDevice)
|
if (m_pGbmDevice)
|
||||||
gbm_device_destroy(m_pGbmDevice);
|
gbm_device_destroy(m_pGbmDevice);
|
||||||
|
|
||||||
if (m_iGBMFD >= 0)
|
|
||||||
close(m_iGBMFD);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::vector<uint64_t>> CHyprOpenGLImpl::getModsForFormat(EGLint format) {
|
std::optional<std::vector<uint64_t>> CHyprOpenGLImpl::getModsForFormat(EGLint format) {
|
||||||
|
@ -3011,11 +3008,11 @@ std::vector<SDRMFormat> CHyprOpenGLImpl::getDRMFormats() {
|
||||||
return drmFormats;
|
return drmFormats;
|
||||||
}
|
}
|
||||||
|
|
||||||
SP<CEGLSync> CHyprOpenGLImpl::createEGLSync(int fenceFD) {
|
SP<CEGLSync> CHyprOpenGLImpl::createEGLSync(CFileDescriptor fenceFD) {
|
||||||
std::vector<EGLint> attribs;
|
std::vector<EGLint> attribs;
|
||||||
int dupFd = -1;
|
int dupFd = -1;
|
||||||
if (fenceFD > 0) {
|
if (fenceFD.isValid()) {
|
||||||
dupFd = fcntl(fenceFD, F_DUPFD_CLOEXEC, 0);
|
dupFd = fcntl(fenceFD.get(), F_DUPFD_CLOEXEC, 0);
|
||||||
if (dupFd < 0) {
|
if (dupFd < 0) {
|
||||||
Debug::log(ERR, "createEGLSync: dup failed");
|
Debug::log(ERR, "createEGLSync: dup failed");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -3037,27 +3034,26 @@ SP<CEGLSync> CHyprOpenGLImpl::createEGLSync(int fenceFD) {
|
||||||
// we need to flush otherwise we might not get a valid fd
|
// we need to flush otherwise we might not get a valid fd
|
||||||
glFlush();
|
glFlush();
|
||||||
|
|
||||||
int fd = g_pHyprOpenGL->m_sProc.eglDupNativeFenceFDANDROID(g_pHyprOpenGL->m_pEglDisplay, sync);
|
CFileDescriptor fd(g_pHyprOpenGL->m_sProc.eglDupNativeFenceFDANDROID(g_pHyprOpenGL->m_pEglDisplay, sync));
|
||||||
if (fd == EGL_NO_NATIVE_FENCE_FD_ANDROID) {
|
if (fd.get() == EGL_NO_NATIVE_FENCE_FD_ANDROID) {
|
||||||
Debug::log(ERR, "eglDupNativeFenceFDANDROID failed");
|
Debug::log(ERR, "eglDupNativeFenceFDANDROID failed");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto eglsync = SP<CEGLSync>(new CEGLSync);
|
auto eglsync = SP<CEGLSync>(new CEGLSync);
|
||||||
eglsync->sync = sync;
|
eglsync->sync = sync;
|
||||||
eglsync->m_iFd = fd;
|
eglsync->m_iFd = std::move(fd);
|
||||||
return eglsync;
|
return eglsync;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CHyprOpenGLImpl::waitForTimelinePoint(SP<CSyncTimeline> timeline, uint64_t point) {
|
bool CHyprOpenGLImpl::waitForTimelinePoint(SP<CSyncTimeline> timeline, uint64_t point) {
|
||||||
int fd = timeline->exportAsSyncFileFD(point);
|
CFileDescriptor fd(timeline->exportAsSyncFileFD(point));
|
||||||
if (fd < 0) {
|
if (!fd.isValid()) {
|
||||||
Debug::log(ERR, "waitForTimelinePoint: failed to get a fd from explicit timeline");
|
Debug::log(ERR, "waitForTimelinePoint: failed to get a fd from explicit timeline");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto sync = g_pHyprOpenGL->createEGLSync(fd);
|
auto sync = g_pHyprOpenGL->createEGLSync(std::move(fd));
|
||||||
close(fd);
|
|
||||||
if (!sync) {
|
if (!sync) {
|
||||||
Debug::log(ERR, "waitForTimelinePoint: failed to get an eglsync from explicit timeline");
|
Debug::log(ERR, "waitForTimelinePoint: failed to get an eglsync from explicit timeline");
|
||||||
return false;
|
return false;
|
||||||
|
@ -3138,13 +3134,10 @@ CEGLSync::~CEGLSync() {
|
||||||
|
|
||||||
if (g_pHyprOpenGL->m_sProc.eglDestroySyncKHR(g_pHyprOpenGL->m_pEglDisplay, sync) != EGL_TRUE)
|
if (g_pHyprOpenGL->m_sProc.eglDestroySyncKHR(g_pHyprOpenGL->m_pEglDisplay, sync) != EGL_TRUE)
|
||||||
Debug::log(ERR, "eglDestroySyncKHR failed");
|
Debug::log(ERR, "eglDestroySyncKHR failed");
|
||||||
|
|
||||||
if (m_iFd >= 0)
|
|
||||||
close(m_iFd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int CEGLSync::fd() {
|
int CEGLSync::fd() {
|
||||||
return m_iFd;
|
return m_iFd.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CEGLSync::wait() {
|
bool CEGLSync::wait() {
|
||||||
|
|
|
@ -137,7 +137,7 @@ class CEGLSync {
|
||||||
private:
|
private:
|
||||||
CEGLSync() = default;
|
CEGLSync() = default;
|
||||||
|
|
||||||
int m_iFd = -1;
|
CFileDescriptor m_iFd;
|
||||||
|
|
||||||
friend class CHyprOpenGLImpl;
|
friend class CHyprOpenGLImpl;
|
||||||
};
|
};
|
||||||
|
@ -208,14 +208,14 @@ class CHyprOpenGLImpl {
|
||||||
uint32_t getPreferredReadFormat(PHLMONITOR pMonitor);
|
uint32_t getPreferredReadFormat(PHLMONITOR pMonitor);
|
||||||
std::vector<SDRMFormat> getDRMFormats();
|
std::vector<SDRMFormat> getDRMFormats();
|
||||||
EGLImageKHR createEGLImage(const Aquamarine::SDMABUFAttrs& attrs);
|
EGLImageKHR createEGLImage(const Aquamarine::SDMABUFAttrs& attrs);
|
||||||
SP<CEGLSync> createEGLSync(int fenceFD);
|
SP<CEGLSync> createEGLSync(CFileDescriptor fenceFD = {});
|
||||||
bool waitForTimelinePoint(SP<CSyncTimeline> timeline, uint64_t point);
|
bool waitForTimelinePoint(SP<CSyncTimeline> timeline, uint64_t point);
|
||||||
|
|
||||||
SCurrentRenderData m_RenderData;
|
SCurrentRenderData m_RenderData;
|
||||||
|
|
||||||
GLint m_iCurrentOutputFb = 0;
|
GLint m_iCurrentOutputFb = 0;
|
||||||
|
|
||||||
int m_iGBMFD = -1;
|
CFileDescriptor m_iGBMFD;
|
||||||
gbm_device* m_pGbmDevice = nullptr;
|
gbm_device* m_pGbmDevice = nullptr;
|
||||||
EGLContext m_pEglContext = nullptr;
|
EGLContext m_pEglContext = nullptr;
|
||||||
EGLDisplay m_pEglDisplay = nullptr;
|
EGLDisplay m_pEglDisplay = nullptr;
|
||||||
|
|
|
@ -1553,7 +1553,7 @@ bool CHyprRenderer::commitPendingAndDoExplicitSync(PHLMONITOR pMonitor) {
|
||||||
Debug::log(TRACE, "Aquamarine did not return an explicit out fence");
|
Debug::log(TRACE, "Aquamarine did not return an explicit out fence");
|
||||||
|
|
||||||
Debug::log(TRACE, "Explicit: {} presented", explicitPresented.size());
|
Debug::log(TRACE, "Explicit: {} presented", explicitPresented.size());
|
||||||
auto sync = g_pHyprOpenGL->createEGLSync(-1);
|
auto sync = g_pHyprOpenGL->createEGLSync();
|
||||||
|
|
||||||
if (!sync)
|
if (!sync)
|
||||||
Debug::log(TRACE, "Explicit: can't add sync, EGLSync failed");
|
Debug::log(TRACE, "Explicit: can't add sync, EGLSync failed");
|
||||||
|
@ -2802,7 +2802,7 @@ void CHyprRenderer::endRender() {
|
||||||
auto explicitOptions = getExplicitSyncSettings();
|
auto explicitOptions = getExplicitSyncSettings();
|
||||||
|
|
||||||
if (PMONITOR->inTimeline && explicitOptions.explicitEnabled && explicitOptions.explicitKMSEnabled) {
|
if (PMONITOR->inTimeline && explicitOptions.explicitEnabled && explicitOptions.explicitKMSEnabled) {
|
||||||
auto sync = g_pHyprOpenGL->createEGLSync(-1);
|
auto sync = g_pHyprOpenGL->createEGLSync();
|
||||||
if (!sync) {
|
if (!sync) {
|
||||||
Debug::log(ERR, "renderer: couldn't create an EGLSync for out in endRender");
|
Debug::log(ERR, "renderer: couldn't create an EGLSync for out in endRender");
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue