surfman/platform/unix/x11/
device.rs

1// surfman/surfman/src/platform/unix/x11/device.rs
2//
3//! A wrapper around X11 `EGLDisplay`s.
4
5use super::connection::{Connection, NativeConnectionWrapper};
6use crate::{Error, GLApi};
7
8use std::sync::Arc;
9
10pub use crate::platform::unix::generic::device::Adapter;
11
12/// A thread-local handle to a device.
13///
14/// Devices contain most of the relevant surface management methods.
15pub struct Device {
16    pub(crate) native_connection: Arc<NativeConnectionWrapper>,
17    pub(crate) adapter: Adapter,
18}
19
20/// Wraps an adapter.
21///
22/// On X11, devices and adapters are essentially identical types.
23#[derive(Clone)]
24pub struct NativeDevice {
25    /// The hardware adapter corresponding to this device.
26    pub adapter: Adapter,
27}
28
29impl Device {
30    #[inline]
31    pub(crate) fn new(connection: &Connection, adapter: &Adapter) -> Result<Device, Error> {
32        Ok(Device {
33            native_connection: connection.native_connection.clone(),
34            adapter: (*adapter).clone(),
35        })
36    }
37
38    /// Returns the native device corresponding to this device.
39    ///
40    /// This method is essentially an alias for the `adapter()` method on Wayland, since there is
41    /// no explicit concept of a device on this backend.
42    #[inline]
43    pub fn native_device(&self) -> NativeDevice {
44        NativeDevice {
45            adapter: self.adapter(),
46        }
47    }
48
49    /// Returns the display server connection that this device was created with.
50    #[inline]
51    pub fn connection(&self) -> Connection {
52        Connection {
53            native_connection: self.native_connection.clone(),
54        }
55    }
56
57    /// Returns the adapter that this device was created with.
58    #[inline]
59    pub fn adapter(&self) -> Adapter {
60        self.adapter.clone()
61    }
62
63    /// Returns the OpenGL API flavor that this device supports (OpenGL or OpenGL ES).
64    #[inline]
65    pub fn gl_api(&self) -> GLApi {
66        GLApi::GL
67    }
68}