twizzler_display/
lib.rs

1//! This crate provides basic interfaces for working with the compositor and display manager.
2//!
3//! Currently, you can create and manage windows, and fill their framebuffers, and flip that
4//! to the compositor. This interface is unstable, and will be changing.
5
6pub use display_core::*;
7use secgate::util::Handle;
8use twizzler::object::{MapFlags, Object};
9use twizzler_rt_abi::error::TwzError;
10
11#[repr(C)]
12/// A window handle for the compositor. Provides a compositing buffer.
13pub struct WindowHandle {
14    key: u32,
15    pub window_buffer: BufferObject,
16}
17
18impl WindowHandle {
19    /// Change window parameters, such as position, size, or z-sorting.
20    pub fn reconfigure(&self, wconfig: WindowConfig) -> Result<(), TwzError> {
21        display_srv::reconfigure_window(self.key, wconfig)
22    }
23
24    /// Get the current window configuration.
25    pub fn get_config(&self) -> Result<WindowConfig, TwzError> {
26        display_srv::get_window_config(self.key)
27    }
28}
29
30impl Drop for WindowHandle {
31    fn drop(&mut self) {
32        self.release();
33    }
34}
35
36impl Handle for WindowHandle {
37    type OpenError = TwzError;
38
39    type OpenInfo = WindowConfig;
40
41    fn open(info: Self::OpenInfo) -> Result<Self, Self::OpenError>
42    where
43        Self: Sized,
44    {
45        let (id, key) = display_srv::create_window(info)?;
46        Ok(WindowHandle {
47            key,
48            window_buffer: BufferObject::from(unsafe {
49                Object::map_unchecked(id, MapFlags::READ | MapFlags::WRITE)
50            }?),
51        })
52    }
53
54    fn release(&mut self) {
55        let _ = display_srv::drop_window(self.key);
56    }
57}
58
59/// Get the current display information. Current resolution is returned in
60/// the width and height fields.
61pub fn get_display_info() -> Result<WindowConfig, TwzError> {
62    display_srv::get_display_info()
63}