1 | //! Bindings to the EGL library `libwayland-egl.so` |
2 | //! |
3 | //! This lib allows to create EGL surfaces out of wayland surfaces. |
4 | //! |
5 | //! The created handle is named `wayland_egl_handle()`. |
6 | |
7 | use crate::client::wl_proxy; |
8 | #[cfg (feature = "dlopen" )] |
9 | use once_cell::sync::Lazy; |
10 | use std::os::raw::c_int; |
11 | |
12 | pub enum wl_egl_window {} |
13 | |
14 | external_library!(WaylandEgl, "wayland-egl" , |
15 | functions: |
16 | fn wl_egl_window_create(*mut wl_proxy, c_int, c_int) -> *mut wl_egl_window, |
17 | fn wl_egl_window_destroy(*mut wl_egl_window) -> (), |
18 | fn wl_egl_window_resize(*mut wl_egl_window, c_int, c_int, c_int, c_int) -> (), |
19 | fn wl_egl_window_get_attached_size(*mut wl_egl_window, *mut c_int, *mut c_int) -> (), |
20 | ); |
21 | |
22 | #[cfg (feature = "dlopen" )] |
23 | pub fn wayland_egl_option() -> Option<&'static WaylandEgl> { |
24 | static WAYLAND_EGL_OPTION: Lazy<Option<WaylandEgl>> = Lazy::new(|| { |
25 | let versions: [&str; 2] = ["libwayland-egl.so.1" , "libwayland-egl.so" ]; |
26 | |
27 | for ver: &&str in &versions { |
28 | match unsafe { WaylandEgl::open(name:ver) } { |
29 | Ok(h: WaylandEgl) => return Some(h), |
30 | Err(::dlib::DlError::CantOpen(_)) => continue, |
31 | Err(::dlib::DlError::MissingSymbol(s: &str)) => { |
32 | log::error!("Found library {} cannot be used: symbol {} is missing." , ver, s); |
33 | return None; |
34 | } |
35 | } |
36 | } |
37 | None |
38 | }); |
39 | |
40 | WAYLAND_EGL_OPTION.as_ref() |
41 | } |
42 | |
43 | #[cfg (feature = "dlopen" )] |
44 | pub fn wayland_egl_handle() -> &'static WaylandEgl { |
45 | static WAYLAND_EGL_HANDLE: Lazy<&'static WaylandEgl> = |
46 | Lazy::new(|| wayland_egl_option().expect(msg:"Library libwayland-egl.so could not be loaded." )); |
47 | |
48 | &WAYLAND_EGL_HANDLE |
49 | } |
50 | |
51 | #[cfg (not(feature = "dlopen" ))] |
52 | pub fn is_lib_available() -> bool { |
53 | true |
54 | } |
55 | #[cfg (feature = "dlopen" )] |
56 | pub fn is_lib_available() -> bool { |
57 | wayland_egl_option().is_some() |
58 | } |
59 | |