pub struct Monitor<T> { /* private fields */ }Expand description
Represents a connected display monitor with its own OpenGL ES rendering context.
Each monitor manages:
- DRM resources (connector, CRTC, planes)
- Display mode configuration with 3-state tracking
- Independent OpenGL ES context
- Render state tracking
§Display Modes (3-State System)
- default_mode: The optimal mode for this monitor (highest resolution + refresh rate)
- e.g., 4K@120Hz for a high-end monitor
- This is the fallback when no custom mode is requested
- requested_mode: The mode the user wants to use
Nonemeans use the optimal default modeSome(mode)means use a custom mode (e.g., 1080p@60Hz)
- current_mode: The mode currently set in hardware
Noneif no mode has been set yet (new monitor) or TTY lost focusSome(mode)is the last mode successfully committed to DRM- Compared against
requested_modeeach frame to trigger mode sets
§Rendering Flow
if monitor.can_render() {
monitor.make_current()?;
// OpenGL rendering calls here...
gl::Clear(gl::COLOR_BUFFER_BIT);
}
// EasyDRM::swap_buffers() will orchestrate the monitor swapsImplementations§
Source§impl<T> Monitor<T>
impl<T> Monitor<T>
Sourcepub fn context_mut(&mut self) -> &mut T
pub fn context_mut(&mut self) -> &mut T
Get a mutable reference to the user context
Sourcepub fn can_render(&self) -> bool
pub fn can_render(&self) -> bool
Returns whether this monitor is ready to be rendered to.
This is updated by poll_events() based on page flip completion and VBlank timing.
Only render to monitors where this returns true to avoid frame drops.
Sourcepub fn make_current(&mut self) -> Result<(), GlesContextError>
pub fn make_current(&mut self) -> Result<(), GlesContextError>
Makes this monitor’s OpenGL context current for rendering.
Call this before any OpenGL rendering operations. Automatically marks this monitor as having been drawn to for this frame.
§Errors
Returns an error if the EGL context cannot be made current.
§Example
if monitor.can_render() {
monitor.make_current()?;
gl::ClearColor(0.0, 0.0, 0.0, 1.0);
gl::Clear(gl::COLOR_BUFFER_BIT);
}Sourcepub fn gl(&self) -> &Gles2
pub fn gl(&self) -> &Gles2
Gets a reference to the OpenGL ES bindings.
This provides direct access to all OpenGL ES functions for this monitor. The GL context is automatically initialized when the monitor is created.
§Example
monitor.make_current()?;
let gl = monitor.gl();
unsafe {
gl.ClearColor(0.0, 0.0, 0.0, 1.0);
gl.Clear(gl::COLOR_BUFFER_BIT);
}Sourcepub fn get_proc_address(&self, symbol: &str) -> *const c_void
pub fn get_proc_address(&self, symbol: &str) -> *const c_void
Gets a function pointer for loading OpenGL functions.
This is provided for compatibility with external libraries that need
to load their own GL function pointers. Most users should use gl() instead.
§Example
// For use with external libraries
external_lib::load_with(|symbol| monitor.get_proc_address(symbol));Sourcepub fn connector_id(&self) -> Handle
pub fn connector_id(&self) -> Handle
Returns the DRM connector handle for this monitor.
Sourcepub fn default_mode(&self) -> &Mode
pub fn default_mode(&self) -> &Mode
Returns the optimal display mode for this monitor.
This is the preferred mode reported by the monitor (typically the highest resolution and refresh rate supported, e.g., 4K@120Hz).
Sourcepub fn current_mode(&self) -> Option<&Mode>
pub fn current_mode(&self) -> Option<&Mode>
Returns the mode currently set in hardware.
Returns None if no mode has been set yet (new monitor or after TTY focus loss).
Returns Some(&Mode) if a mode has been successfully committed to DRM.
This may differ from requested_mode() briefly during mode transitions.
Sourcepub fn requested_mode(&self) -> Option<&Mode>
pub fn requested_mode(&self) -> Option<&Mode>
Returns the mode that should be used for rendering.
Returns None if the optimal default mode should be used.
Returns Some(&Mode) if a custom mode has been requested
(e.g., downscaled to 1080p or lower refresh rate).
Sourcepub fn set_mode(&mut self, mode: Option<Mode>)
pub fn set_mode(&mut self, mode: Option<Mode>)
Sets the requested display mode for this monitor.
This allows using a different mode than the optimal default (e.g., lower resolution or refresh rate for compatibility).
The mode change will take effect on the next swap_buffers() call
if it differs from the current hardware state.
§Arguments
mode- The new display mode, orNoneto revert to the optimal default
§Example
// Use 1080p@60Hz instead of the default 4K@120Hz
let mode_1080p = find_mode_by_resolution(monitor, 1920, 1080);
monitor.set_mode(Some(mode_1080p));
// Revert to optimal default
monitor.set_mode(None);Sourcepub fn active_mode(&self) -> &Mode
pub fn active_mode(&self) -> &Mode
Returns the effective display mode for rendering.
This is a convenience method that returns the requested mode if set, otherwise returns the optimal default mode.
Use this to determine what resolution/refresh rate to render at.
§Example
let active = monitor.active_mode();
println!("Rendering at {}x{} @ {}Hz",
active.size().0, active.size().1, active.vrefresh());Sourcepub fn primary_plane(&self) -> Handle
pub fn primary_plane(&self) -> Handle
Returns the handle to the primary plane used for scanout.
Sourcepub fn cursor_plane(&self) -> Option<Handle>
pub fn cursor_plane(&self) -> Option<Handle>
Returns the handle to the cursor plane, if available.
Some GPUs (especially virtual ones like virtio-gpu) don’t expose a separate cursor plane.