From 382a184033a28d057d6f3021ed5217bf6f3bdf96 Mon Sep 17 00:00:00 2001 From: i509VCB Date: Sat, 11 Nov 2023 01:19:50 -0600 Subject: [PATCH] egl Display::create_sync --- glutin/src/api/egl/display.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/glutin/src/api/egl/display.rs b/glutin/src/api/egl/display.rs index 0cd5611a54..cf6a31c6fc 100644 --- a/glutin/src/api/egl/display.rs +++ b/glutin/src/api/egl/display.rs @@ -231,6 +231,36 @@ impl Display { } } + /// Create a sync. + /// + /// This function returns [`Err`] if the EGL version is not at least 1.5 + /// or `EGL_KHR_fence_sync` is not available. An error is also returned if + /// native fences are not supported. + pub fn create_sync(&self, native: bool) -> Result { + if self.inner.version < super::VERSION_1_5 + && !self.inner.display_extensions.contains("EGL_KHR_fence_sync") + { + return Err(ErrorKind::NotSupported("Sync objects are not supported").into()); + } + + if native && !self.inner.display_extensions.contains("EGL_ANDROID_native_fence_sync") { + return Err(ErrorKind::NotSupported("Native fences are not supported").into()); + } + + let ty = if native { egl::SYNC_NATIVE_FENCE_ANDROID } else { egl::SYNC_FENCE_KHR }; + + let sync = unsafe { self.inner.egl.CreateSyncKHR(*self.inner.raw, ty, ptr::null_mut()) }; + + if sync == egl::NO_SYNC { + return Err(super::check_error().err().unwrap()); + } + + Ok(super::sync::Sync(Arc::new(super::sync::Inner { + inner: sync, + display: self.inner.clone(), + }))) + } + /// Import a sync fd into EGL. /// /// Glutin will duplicate the sync fd being imported since EGL assumes