Do a better job at finding a crtc in the example

This commit is contained in:
Drakulix 2017-09-17 22:37:54 +02:00
parent bdb91fc1f1
commit d3fca34475
2 changed files with 38 additions and 11 deletions

View File

@ -16,12 +16,10 @@ mod helpers;
use drm::control::{Device as ControlDevice, ResourceInfo}; use drm::control::{Device as ControlDevice, ResourceInfo};
use drm::control::connector::{Info as ConnectorInfo, State as ConnectorState}; use drm::control::connector::{Info as ConnectorInfo, State as ConnectorState};
use drm::control::encoder::Info as EncoderInfo;
use glium::Surface; use glium::Surface;
use helpers::GliumDrawer; use helpers::GliumDrawer;
use slog::*; use slog::*;
use smithay::backend::drm::{DrmBackend, DrmDevice, DrmHandler, Id}; use smithay::backend::drm::{DrmBackend, DrmDevice, DrmHandler, Id};
use smithay::backend::graphics::egl::EGLGraphicsBackend; use smithay::backend::graphics::egl::EGLGraphicsBackend;
use smithay::backend::graphics::glium::{GliumGraphicsBackend, IntoGlium}; use smithay::backend::graphics::glium::{GliumGraphicsBackend, IntoGlium};
@ -30,14 +28,11 @@ use smithay::compositor::roles::Role;
use smithay::shell::{self, PopupConfigure, PopupSurface, ShellClient, ShellHandler, ShellSurfaceRole, use smithay::shell::{self, PopupConfigure, PopupSurface, ShellClient, ShellHandler, ShellSurfaceRole,
ToplevelConfigure, ToplevelSurface}; ToplevelConfigure, ToplevelSurface};
use smithay::shm::{ShmGlobal, ShmToken}; use smithay::shm::{ShmGlobal, ShmToken};
use std::fs::OpenOptions; use std::fs::OpenOptions;
use std::io::Error as IoError; use std::io::Error as IoError;
use std::os::unix::io::AsRawFd; use std::os::unix::io::AsRawFd;
use std::time::Duration; use std::time::Duration;
use wayland_protocols::unstable::xdg_shell::server::{zxdg_shell_v6, zxdg_toplevel_v6}; use wayland_protocols::unstable::xdg_shell::server::{zxdg_shell_v6, zxdg_toplevel_v6};
use wayland_server::{Client, EventLoopHandle}; use wayland_server::{Client, EventLoopHandle};
use wayland_server::protocol::{wl_callback, wl_compositor, wl_output, wl_seat, wl_shell, wl_shm, use wayland_server::protocol::{wl_callback, wl_compositor, wl_output, wl_seat, wl_shell, wl_shm,
wl_subcompositor, wl_surface}; wl_subcompositor, wl_surface};
@ -204,8 +199,17 @@ fn main() {
.find(|conn| conn.connection_state() == ConnectorState::Connected) .find(|conn| conn.connection_state() == ConnectorState::Connected)
.unwrap(); .unwrap();
// Use the first crtc (should be successful in most cases) // Use the first encoder
let crtc = res_handles.crtcs()[0]; let encoder_info = EncoderInfo::load_from_device(&device, connector_info.encoders()[0]).unwrap();
// use the connected crtc if any
let crtc = encoder_info.current_crtc()
// or use the first one that is compatible with the encoder
.unwrap_or_else(||
*res_handles.crtcs()
.iter()
.find(|crtc| encoder_info.supports_crtc(**crtc))
.unwrap());
// Assuming we found a good connector and loaded the info into `connector_info` // Assuming we found a good connector and loaded the info into `connector_info`
let mode = connector_info.modes()[0]; // Use first mode (usually highest resoltion, but in reality you should filter and sort and check and match with other connectors, if you use more then one.) let mode = connector_info.modes()[0]; // Use first mode (usually highest resoltion, but in reality you should filter and sort and check and match with other connectors, if you use more then one.)

View File

@ -39,15 +39,20 @@
//! You will need to use the `drm` crate to provide the required types to create //! You will need to use the `drm` crate to provide the required types to create
//! a backend. //! a backend.
//! //!
//! ```rust,ignore //! ```rust,no_run
//! extern crate drm; //! extern crate drm;
//! extern crate smithay; //! extern crate smithay;
//! # extern crate wayland_server; //! # extern crate wayland_server;
//! //!
//! use drm::control::{Device as ControlDevice, ResourceInfo}; //! use drm::control::{Device as ControlDevice, ResourceInfo};
//! use drm::control::connector::{Info as ConnectorInfo, State as ConnectorState}; //! use drm::control::connector::{Info as ConnectorInfo, State as ConnectorState};
//! use drm::control::encoder::{Info as EncoderInfo};
//! # use std::io::Error as IoError;
//! use std::fs::OpenOptions; //! use std::fs::OpenOptions;
//! # use std::time::Duration;
//! use smithay::backend::drm::DrmDevice; //! use smithay::backend::drm::DrmDevice;
//! # use smithay::backend::drm::{DrmHandler, Id};
//! # use wayland_server::EventLoopHandle;
//! //!
//! # fn main() { //! # fn main() {
//! // Open the drm device //! // Open the drm device
@ -68,8 +73,17 @@
//! .find(|conn| conn.connection_state() == ConnectorState::Connected) //! .find(|conn| conn.connection_state() == ConnectorState::Connected)
//! .unwrap(); //! .unwrap();
//! //!
//! // Use first crtc (should be successful in most cases) //! // Use the first encoder
//! let crtc = res_handles.crtcs()[0]; //! let encoder_info = EncoderInfo::load_from_device(&device, connector_info.encoders()[0]).unwrap();
//!
//! // use the connected crtc if any
//! let crtc = encoder_info.current_crtc()
//! // or use the first one that is compatible with the encoder
//! .unwrap_or_else(||
//! *res_handles.crtcs()
//! .iter()
//! .find(|crtc| encoder_info.supports_crtc(**crtc))
//! .unwrap());
//! //!
//! // Use first mode (usually the highest resolution) //! // Use first mode (usually the highest resolution)
//! let mode = connector_info.modes()[0]; //! let mode = connector_info.modes()[0];
@ -80,6 +94,14 @@
//! mode, //! mode,
//! vec![connector_info.handle()] //! vec![connector_info.handle()]
//! ).unwrap(); //! ).unwrap();
//! # struct MyDrmHandler;
//! #
//! # impl DrmHandler for MyDrmHandler {
//! # fn ready(&mut self, _: &mut EventLoopHandle, id: Id, _frame: u32, _duration: Duration) {}
//! # fn error(&mut self, _: &mut EventLoopHandle, error: IoError) {}
//! # }
//! #
//! # device.set_handler(MyDrmHandler);
//! # } //! # }
//! ``` //! ```
//! //!
@ -123,6 +145,7 @@
//! # options.open("/dev/dri/card0").unwrap(), // try to detect it properly //! # options.open("/dev/dri/card0").unwrap(), // try to detect it properly
//! # None /*put a logger here*/ //! # None /*put a logger here*/
//! # ).unwrap(); //! # ).unwrap();
//! #
//! # let res_handles = device.resource_handles().unwrap(); //! # let res_handles = device.resource_handles().unwrap();
//! # let connector_info = res_handles.connectors().iter() //! # let connector_info = res_handles.connectors().iter()
//! # .map(|conn| ConnectorInfo::load_from_device(&device, *conn).unwrap()) //! # .map(|conn| ConnectorInfo::load_from_device(&device, *conn).unwrap())