Skip to content

Commit eb603e4

Browse files
committed
use static constructor for CEGLSync
1 parent 999392b commit eb603e4

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

src/helpers/sync/SyncReleaser.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
*/
1313

1414
class CSyncTimeline;
15-
class CEGLSync;
1615

1716
class CSyncReleaser {
1817
public:
@@ -29,5 +28,4 @@ class CSyncReleaser {
2928
SP<CSyncTimeline> m_timeline;
3029
uint64_t m_point = 0;
3130
Hyprutils::OS::CFileDescriptor m_fd;
32-
SP<CEGLSync> m_sync;
3331
};

src/render/OpenGL.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3151,10 +3151,12 @@ float SRenderModifData::combinedScale() {
31513151
return scale;
31523152
}
31533153

3154-
CEGLSync::CEGLSync() : sync(g_pHyprOpenGL->m_sProc.eglCreateSyncKHR(g_pHyprOpenGL->m_pEglDisplay, EGL_SYNC_NATIVE_FENCE_ANDROID, nullptr)) {
3154+
UP<CEGLSync> CEGLSync::create() {
3155+
EGLSyncKHR sync = g_pHyprOpenGL->m_sProc.eglCreateSyncKHR(g_pHyprOpenGL->m_pEglDisplay, EGL_SYNC_NATIVE_FENCE_ANDROID, nullptr);
3156+
31553157
if (sync == EGL_NO_SYNC_KHR) {
31563158
Debug::log(ERR, "eglCreateSyncKHR failed");
3157-
return;
3159+
return nullptr;
31583160
}
31593161

31603162
// we need to flush otherwise we might not get a valid fd
@@ -3163,18 +3165,22 @@ CEGLSync::CEGLSync() : sync(g_pHyprOpenGL->m_sProc.eglCreateSyncKHR(g_pHyprOpenG
31633165
int fd = g_pHyprOpenGL->m_sProc.eglDupNativeFenceFDANDROID(g_pHyprOpenGL->m_pEglDisplay, sync);
31643166
if (fd == EGL_NO_NATIVE_FENCE_FD_ANDROID) {
31653167
Debug::log(ERR, "eglDupNativeFenceFDANDROID failed");
3166-
return;
3168+
return nullptr;
31673169
}
31683170

3169-
m_valid = true;
3170-
m_fd = CFileDescriptor(fd);
3171+
UP<CEGLSync> eglSync(new CEGLSync);
3172+
eglSync->m_fd = CFileDescriptor(fd);
3173+
eglSync->m_sync = sync;
3174+
eglSync->m_valid = true;
3175+
3176+
return eglSync;
31713177
}
31723178

31733179
CEGLSync::~CEGLSync() {
3174-
if (sync == EGL_NO_SYNC_KHR)
3180+
if (m_sync == EGL_NO_SYNC_KHR)
31753181
return;
31763182

3177-
if (g_pHyprOpenGL && g_pHyprOpenGL->m_sProc.eglDestroySyncKHR(g_pHyprOpenGL->m_pEglDisplay, sync) != EGL_TRUE)
3183+
if (g_pHyprOpenGL && g_pHyprOpenGL->m_sProc.eglDestroySyncKHR(g_pHyprOpenGL->m_pEglDisplay, m_sync) != EGL_TRUE)
31783184
Debug::log(ERR, "eglDestroySyncKHR failed");
31793185
}
31803186

@@ -3187,5 +3193,5 @@ CFileDescriptor&& CEGLSync::takeFd() {
31873193
}
31883194

31893195
bool CEGLSync::isValid() {
3190-
return m_valid && sync != EGL_NO_SYNC_KHR && m_fd.isValid();
3196+
return m_valid && m_sync != EGL_NO_SYNC_KHR && m_fd.isValid();
31913197
}

src/render/OpenGL.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,19 @@ struct SCurrentRenderData {
150150

151151
class CEGLSync {
152152
public:
153-
CEGLSync();
153+
static UP<CEGLSync> create();
154+
154155
~CEGLSync();
155156

156157
Hyprutils::OS::CFileDescriptor& fd();
157158
Hyprutils::OS::CFileDescriptor&& takeFd();
158159
bool isValid();
159160

160161
private:
162+
CEGLSync() = default;
163+
161164
Hyprutils::OS::CFileDescriptor m_fd;
162-
EGLSyncKHR sync = nullptr;
165+
EGLSyncKHR m_sync = EGL_NO_SYNC_KHR;
163166
bool m_valid = false;
164167

165168
friend class CHyprOpenGLImpl;

src/render/Renderer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,27 +2285,27 @@ void CHyprRenderer::endRender(const std::function<void()>& renderingDoneCallback
22852285
if (m_eRenderMode == RENDER_MODE_NORMAL)
22862286
PMONITOR->output->state->setBuffer(m_pCurrentBuffer);
22872287

2288-
CEGLSync eglSync = CEGLSync();
2289-
if (eglSync.isValid()) {
2288+
UP<CEGLSync> eglSync = CEGLSync::create();
2289+
if (eglSync && eglSync->isValid()) {
22902290
for (auto const& buf : usedAsyncBuffers) {
22912291
for (const auto& releaser : buf->syncReleasers) {
2292-
releaser->addSyncFileFd(eglSync.fd());
2292+
releaser->addSyncFileFd(eglSync->fd());
22932293
}
22942294
}
22952295

22962296
// release buffer refs with release points now, since syncReleaser handles actual buffer release based on EGLSync
22972297
std::erase_if(usedAsyncBuffers, [](const auto& buf) { return !buf->syncReleasers.empty(); });
22982298

22992299
// release buffer refs without release points when EGLSync sync_file/fence is signalled
2300-
g_pEventLoopManager->doOnReadable(eglSync.fd().duplicate(), [renderingDoneCallback, prevbfs = std::move(usedAsyncBuffers)]() mutable {
2300+
g_pEventLoopManager->doOnReadable(eglSync->fd().duplicate(), [renderingDoneCallback, prevbfs = std::move(usedAsyncBuffers)]() mutable {
23012301
prevbfs.clear();
23022302
if (renderingDoneCallback)
23032303
renderingDoneCallback();
23042304
});
23052305
usedAsyncBuffers.clear();
23062306

23072307
if (m_eRenderMode == RENDER_MODE_NORMAL) {
2308-
PMONITOR->inFence = eglSync.takeFd();
2308+
PMONITOR->inFence = eglSync->takeFd();
23092309
PMONITOR->output->state->setExplicitInFence(PMONITOR->inFence.get());
23102310
}
23112311
} else {

0 commit comments

Comments
 (0)