mirror of
https://github.com/hyprwm/aquamarine.git
synced 2025-01-26 07:59:48 +01:00
move over eglSync
This commit is contained in:
parent
a300101d3f
commit
39d5694a66
2 changed files with 69 additions and 11 deletions
|
@ -41,6 +41,23 @@ namespace Aquamarine {
|
||||||
Hyprutils::Memory::CWeakPointer<CEGLRenderer> renderer;
|
Hyprutils::Memory::CWeakPointer<CEGLRenderer> renderer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CEGLSync {
|
||||||
|
public:
|
||||||
|
~CEGLSync();
|
||||||
|
|
||||||
|
EGLSyncKHR sync = nullptr;
|
||||||
|
|
||||||
|
int fd();
|
||||||
|
bool wait();
|
||||||
|
|
||||||
|
private:
|
||||||
|
CEGLSync() = default;
|
||||||
|
|
||||||
|
int m_iFd = -1;
|
||||||
|
|
||||||
|
friend class CEGLRenderer;
|
||||||
|
};
|
||||||
|
|
||||||
class CEGLRenderer {
|
class CEGLRenderer {
|
||||||
public:
|
public:
|
||||||
~CEGLRenderer();
|
~CEGLRenderer();
|
||||||
|
@ -123,6 +140,7 @@ namespace Aquamarine {
|
||||||
CEGLRenderer() = default;
|
CEGLRenderer() = default;
|
||||||
|
|
||||||
EGLImageKHR createEGLImage(const SDMABUFAttrs& attrs);
|
EGLImageKHR createEGLImage(const SDMABUFAttrs& attrs);
|
||||||
|
Hyprutils::Memory::CSharedPointer<CEGLSync> createEGLSync(int fenceFD);
|
||||||
bool verifyDestinationDMABUF(const SDMABUFAttrs& attrs);
|
bool verifyDestinationDMABUF(const SDMABUFAttrs& attrs);
|
||||||
void waitOnSync(int fd);
|
void waitOnSync(int fd);
|
||||||
int recreateBlitSync();
|
int recreateBlitSync();
|
||||||
|
|
|
@ -16,6 +16,18 @@ using namespace Hyprutils::Math;
|
||||||
#define SP CSharedPointer
|
#define SP CSharedPointer
|
||||||
#define WP CWeakPointer
|
#define WP CWeakPointer
|
||||||
|
|
||||||
|
// macros
|
||||||
|
#define GLCALL(__CALL__) \
|
||||||
|
{ \
|
||||||
|
__CALL__; \
|
||||||
|
auto err = glGetError(); \
|
||||||
|
if (err != GL_NO_ERROR) { \
|
||||||
|
backend->log(AQ_LOG_ERROR, \
|
||||||
|
std::format("[GLES] Error in call at {}@{}: 0x{:x}", __LINE__, \
|
||||||
|
([]() constexpr -> std::string { return std::string(__FILE__).substr(std::string(__FILE__).find_last_of('/') + 1); })(), err)); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
// static funcs
|
// static funcs
|
||||||
static WP<CBackend> gBackend;
|
static WP<CBackend> gBackend;
|
||||||
|
|
||||||
|
@ -584,6 +596,45 @@ void CEGLRenderer::restoreEGL() {
|
||||||
backend->log(AQ_LOG_WARNING, "CEGLRenderer: restoreEGL eglMakeCurrent failed");
|
backend->log(AQ_LOG_WARNING, "CEGLRenderer: restoreEGL eglMakeCurrent failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SP<CEGLSync> CEGLRenderer::createEGLSync(int fenceFD) {
|
||||||
|
std::vector<EGLint> attribs;
|
||||||
|
int dupFd = -1;
|
||||||
|
if (fenceFD > 0) {
|
||||||
|
dupFd = fcntl(fenceFD, F_DUPFD_CLOEXEC, 0);
|
||||||
|
if (dupFd < 0) {
|
||||||
|
backend->log(AQ_LOG_ERROR, "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(EGL_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
EGLSyncKHR sync = proc.eglCreateSyncKHR(egl.display, EGL_SYNC_NATIVE_FENCE_ANDROID, attribs.data());
|
||||||
|
if (sync == EGL_NO_SYNC_KHR) {
|
||||||
|
backend->log(AQ_LOG_ERROR, "eglCreateSyncKHR failed");
|
||||||
|
if (dupFd >= 0)
|
||||||
|
close(dupFd);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// we need to flush otherwise we might not get a valid fd
|
||||||
|
glFlush();
|
||||||
|
|
||||||
|
int fd = proc.eglDupNativeFenceFDANDROID(egl.display, sync);
|
||||||
|
if (fd == EGL_NO_NATIVE_FENCE_FD_ANDROID) {
|
||||||
|
backend->log(AQ_LOG_ERROR, "eglDupNativeFenceFDANDROID failed");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto eglsync = SP<CEGLSync>(new CEGLSync);
|
||||||
|
eglsync->sync = sync;
|
||||||
|
eglsync->m_iFd = fd;
|
||||||
|
return eglsync;
|
||||||
|
}
|
||||||
|
|
||||||
EGLImageKHR CEGLRenderer::createEGLImage(const SDMABUFAttrs& attrs) {
|
EGLImageKHR CEGLRenderer::createEGLImage(const SDMABUFAttrs& attrs) {
|
||||||
std::vector<uint32_t> attribs;
|
std::vector<uint32_t> attribs;
|
||||||
|
|
||||||
|
@ -652,17 +703,6 @@ EGLImageKHR CEGLRenderer::createEGLImage(const SDMABUFAttrs& attrs) {
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GLCALL(__CALL__) \
|
|
||||||
{ \
|
|
||||||
__CALL__; \
|
|
||||||
auto err = glGetError(); \
|
|
||||||
if (err != GL_NO_ERROR) { \
|
|
||||||
backend->log(AQ_LOG_ERROR, \
|
|
||||||
std::format("[GLES] Error in call at {}@{}: 0x{:x}", __LINE__, \
|
|
||||||
([]() constexpr -> std::string { return std::string(__FILE__).substr(std::string(__FILE__).find_last_of('/') + 1); })(), err)); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
SGLTex CEGLRenderer::glTex(Hyprutils::Memory::CSharedPointer<IBuffer> buffa) {
|
SGLTex CEGLRenderer::glTex(Hyprutils::Memory::CSharedPointer<IBuffer> buffa) {
|
||||||
SGLTex tex;
|
SGLTex tex;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue