From a4c0df1b591c5b28ef855b25006a3ff3e1bee4d9 Mon Sep 17 00:00:00 2001 From: Gert-dev Date: Wed, 2 Oct 2024 17:39:32 +0200 Subject: [PATCH] egl: Add helpers to manage and wait for EGLSync objects This adds meta_egl_create_sync and meta_egl_destroy_sync to be able to create and dispose EGLSync objects, respectively, as well as meta_egl_wait_sync to be able to wait for an EGLSync on the GPU. (cherry picked from commit d2e70c15ec1cf6b6f7cd8c8825a5d92a1f89b35b) Part-of: Signed-off-by: Mingi Sung --- src/backends/meta-egl.c | 71 +++++++++++++++++++++++++++++++++++++++++ src/backends/meta-egl.h | 18 +++++++++++ 2 files changed, 89 insertions(+) diff --git a/src/backends/meta-egl.c b/src/backends/meta-egl.c index cc023f705..50da9c464 100644 --- a/src/backends/meta-egl.c +++ b/src/backends/meta-egl.c @@ -44,6 +44,10 @@ struct _MetaEgl PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR; PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR; + PFNEGLCREATESYNCPROC eglCreateSync; + PFNEGLDESTROYSYNCPROC eglDestroySync; + PFNEGLWAITSYNCPROC eglWaitSync; + PFNEGLBINDWAYLANDDISPLAYWL eglBindWaylandDisplayWL; PFNEGLQUERYWAYLANDBUFFERWL eglQueryWaylandBufferWL; @@ -1162,6 +1166,69 @@ meta_egl_query_display_attrib (MetaEgl *egl, return TRUE; } +gboolean +meta_egl_create_sync (MetaEgl *egl, + EGLDisplay display, + EGLenum type, + const EGLAttrib *attrib_list, + EGLSync *egl_sync, + GError **error) +{ + EGLSync sync; + + if (!is_egl_proc_valid (egl->eglCreateSync, error)) + return FALSE; + + sync = egl->eglCreateSync (display, type, attrib_list); + + if (sync == EGL_NO_SYNC) + { + set_egl_error (error); + return FALSE; + } + + *egl_sync = sync; + + return TRUE; +} + +gboolean +meta_egl_destroy_sync (MetaEgl *egl, + EGLDisplay display, + EGLSync sync, + GError **error) +{ + if (!is_egl_proc_valid (egl->eglDestroySync, error)) + return FALSE; + + if (!egl->eglDestroySync (display, sync)) + { + set_egl_error (error); + return FALSE; + } + + return TRUE; +} + +gboolean +meta_egl_wait_sync (MetaEgl *egl, + EGLDisplay display, + EGLSync sync, + EGLint flags, + GError **error) +{ + if (!is_egl_proc_valid (egl->eglWaitSync, error)) + return FALSE; + + if (!egl->eglWaitSync (display, sync, flags)) + { + set_egl_error (error); + return FALSE; + } + + return TRUE; +} + #define GET_EGL_PROC_ADDR(proc) \ egl->proc = (void *) eglGetProcAddress (#proc); @@ -1175,6 +1242,10 @@ meta_egl_constructed (GObject *object) GET_EGL_PROC_ADDR (eglCreateImageKHR); GET_EGL_PROC_ADDR (eglDestroyImageKHR); + GET_EGL_PROC_ADDR (eglCreateSync); + GET_EGL_PROC_ADDR (eglDestroySync); + GET_EGL_PROC_ADDR (eglWaitSync); + GET_EGL_PROC_ADDR (eglBindWaylandDisplayWL); GET_EGL_PROC_ADDR (eglQueryWaylandBufferWL); diff --git a/src/backends/meta-egl.h b/src/backends/meta-egl.h index 8b955c90c..af3150c3c 100644 --- a/src/backends/meta-egl.h +++ b/src/backends/meta-egl.h @@ -276,3 +276,21 @@ gboolean meta_egl_query_display_attrib (MetaEgl *egl, EGLint attribute, EGLAttrib *value, GError **error); + +gboolean meta_egl_create_sync (MetaEgl *egl, + EGLDisplay display, + EGLenum type, + const EGLAttrib *attrib_list, + EGLSync *egl_sync, + GError **error); + +gboolean meta_egl_destroy_sync (MetaEgl *egl, + EGLDisplay display, + EGLSync sync, + GError **error); + +gboolean meta_egl_wait_sync (MetaEgl *egl, + EGLDisplay display, + EGLSync sync, + EGLint flags, + GError **error);