Skip to content

Commit 2e5aa2c

Browse files
committed
drm: centralize syncobj timeline check in compositor
1 parent 09b0fbc commit 2e5aa2c

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

src/Compositor.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,16 @@ void CCompositor::initServer(std::string socketName, int socketFd) {
354354
m_drmFD = m_aqBackend->drmFD();
355355
Debug::log(LOG, "Running on DRMFD: {}", m_drmFD);
356356

357+
if (m_drmFD >= 0) {
358+
uint64_t cap = 0;
359+
int ret = drmGetCap(m_drmFD, DRM_CAP_SYNCOBJ_TIMELINE, &cap);
360+
m_bDrmSyncobjTimelineSupported = (ret == 0 && cap != 0);
361+
Debug::log(LOG, "DRM syncobj timeline support: {}", m_bDrmSyncobjTimelineSupported ? "yes" : "no");
362+
} else {
363+
m_bDrmSyncobjTimelineSupported = false;
364+
Debug::log(LOG, "DRM syncobj timeline support: no (no DRM FD)");
365+
}
366+
357367
if (!socketName.empty() && socketFd != -1) {
358368
fcntl(socketFd, F_SETFD, FD_CLOEXEC);
359369
const auto RETVAL = wl_display_add_socket_fd(m_wlDisplay, socketFd);

src/Compositor.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ class CCompositor {
152152
NColorManagement::SImageDescription getPreferredImageDescription();
153153
bool shouldChangePreferredImageDescription();
154154

155+
bool supportsDrmSyncobjTimeline() const { return m_bDrmSyncobjTimelineSupported; }
156+
155157
std::string m_explicitConfigPath;
156158

157159
private:
@@ -165,6 +167,8 @@ class CCompositor {
165167
void removeLockFile();
166168
void setMallocThreshold();
167169

170+
bool m_bDrmSyncobjTimelineSupported = false;
171+
168172
uint64_t m_hyprlandPID = 0;
169173
wl_event_source* m_critSigSource = nullptr;
170174
rlimit m_originalNofile = {};

src/helpers/sync/SyncTimeline.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
#include "SyncTimeline.hpp"
22
#include "../../defines.hpp"
33
#include "../../managers/eventLoop/EventLoopManager.hpp"
4+
#include "../../Compositor.hpp"
45

56
#include <xf86drm.h>
67
#include <sys/eventfd.h>
78
using namespace Hyprutils::OS;
89

9-
static bool checkDrmSyncobjTimelineSupport(int drmFD) {
10-
uint64_t cap = 0;
11-
int ret = drmGetCap(drmFD, DRM_CAP_SYNCOBJ_TIMELINE, &cap);
12-
return (ret == 0 && cap != 0);
13-
}
14-
1510
SP<CSyncTimeline> CSyncTimeline::create(int drmFD_) {
16-
if (!checkDrmSyncobjTimelineSupport(drmFD_))
11+
if (!g_pCompositor->supportsDrmSyncobjTimeline())
1712
return nullptr;
1813

1914
auto timeline = SP<CSyncTimeline>(new CSyncTimeline);
@@ -29,7 +24,7 @@ SP<CSyncTimeline> CSyncTimeline::create(int drmFD_) {
2924
}
3025

3126
SP<CSyncTimeline> CSyncTimeline::create(int drmFD_, CFileDescriptor&& drmSyncobjFD) {
32-
if (!checkDrmSyncobjTimelineSupport(drmFD_))
27+
if (!g_pCompositor->supportsDrmSyncobjTimeline())
3328
return nullptr;
3429

3530
auto timeline = SP<CSyncTimeline>(new CSyncTimeline);

src/managers/ProtocolManager.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,7 @@ CProtocolManager::CProtocolManager() {
212212
lease.reset();
213213

214214
if (g_pHyprOpenGL->m_exts.EGL_ANDROID_native_fence_sync_ext && !PROTO::sync) {
215-
// Check if DRM supports syncobj timelines before creating the protocol
216-
uint64_t cap = 0;
217-
int ret = drmGetCap(g_pCompositor->m_drmFD, DRM_CAP_SYNCOBJ_TIMELINE, &cap);
218-
if (ret == 0 && cap != 0) {
215+
if (g_pCompositor->supportsDrmSyncobjTimeline()) {
219216
PROTO::sync = makeUnique<CDRMSyncobjProtocol>(&wp_linux_drm_syncobj_manager_v1_interface, 1, "DRMSyncobj");
220217
Debug::log(LOG, "DRM Syncobj Timeline support detected, enabling explicit sync protocol");
221218
} else {

0 commit comments

Comments
 (0)