use super::connection::Connection;
use crate::egl;
use crate::egl::types::EGLDisplay;
use crate::platform::generic::egl::device::EGL_FUNCTIONS;
use crate::{Error, GLApi};
#[derive(Clone, Debug)]
pub struct Adapter;
pub struct Device {
pub(crate) egl_display: EGLDisplay,
pub(crate) display_is_owned: bool,
}
#[derive(Clone, Copy)]
pub struct NativeDevice(pub EGLDisplay);
impl Drop for Device {
fn drop(&mut self) {
EGL_FUNCTIONS.with(|egl| unsafe {
if !self.display_is_owned {
return;
}
let result = egl.Terminate(self.egl_display);
assert_ne!(result, egl::FALSE);
self.egl_display = egl::NO_DISPLAY;
})
}
}
impl NativeDevice {
pub fn current() -> NativeDevice {
EGL_FUNCTIONS.with(|egl| unsafe { NativeDevice(egl.GetCurrentDisplay()) })
}
}
impl Device {
#[inline]
pub(crate) fn new() -> Result<Device, Error> {
EGL_FUNCTIONS.with(|egl| {
unsafe {
let egl_display = egl.GetDisplay(egl::DEFAULT_DISPLAY);
assert_ne!(egl_display, egl::NO_DISPLAY);
let (mut major_version, mut minor_version) = (0, 0);
let result = egl.Initialize(egl_display, &mut major_version, &mut minor_version);
assert_ne!(result, egl::FALSE);
Ok(Device {
egl_display,
display_is_owned: true,
})
}
})
}
#[inline]
pub fn native_device(&self) -> NativeDevice {
NativeDevice(self.egl_display)
}
#[inline]
pub fn connection(&self) -> Connection {
Connection
}
#[inline]
pub fn adapter(&self) -> Adapter {
Adapter
}
#[inline]
pub fn gl_api(&self) -> GLApi {
GLApi::GLES
}
}