Skip to content

Commit

Permalink
egl Display::create_sync
Browse files Browse the repository at this point in the history
  • Loading branch information
i509VCB committed Nov 11, 2023
1 parent 6a57c12 commit 382a184
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions glutin/src/api/egl/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<super::sync::Sync> {
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
Expand Down

0 comments on commit 382a184

Please sign in to comment.