Skip to content

trissylegs/rust-drm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust DRM

Rust DRM provides a Rust interface to the Direct Rendering Manager API in Linux. This uses ioctl's to talk to a DRM driver in order to get the current state of screens, perform mode setting, get vsync timing and allocate dumb buffers.

(Nothing to do with Digital Rights Management.)

Documentation

To use

Add to Cargo.toml:

drm = "0.1"

or

drm = { git = "https://github.com/trissylegs/rust-drm.git" }

Add to your crate:

extern crate drm;

Things to see and do:

  • Listing availble cards:
use drm::Device;
for path in Device::cards().unwrap() {
    println!("{}", path.display());
    let mut dev = Device::open(&path).unwrap();
}
  • Get the version information:
let version = dev.version();
println!("name: {}, description: {}", version.name().unwrap(), version.description().unwrap());
let (major, minor, patch) = version.number();
println!("version {}.{}.{}", major, minor, patch);
  • Get resource information:
use drm::mode::*;
let res = dev.get_resources().unwrap();
for conn in res.connectors() {
    println!("{:#?}", dev.get(conn));
}
  • Get vblank events:
use std::io::ErrorKind;
dev.request_vblank(12345, 0).unwrap();
loop {
    match dev.read_event() {
        // The actual message
        Ok(event) => { println!("{:?}", event); break }

        // Error handling
        Err(ref err) if err.kind() == ErrorKind::Interrupted { continue }
        Err(ref err) if err.kind() == ErrorKind::WouldBlock  { continue }
        Err(err) => panic!("Device::read_event: {}", err)
    }
}
  • Create a "Dumb buffer".
use drm::mode::{DumbBuf, DUNNO};
let buf = DumbBuf::create(&dev, 1920, 1080, 32, DUNNO).unwrap();
  • Put a frame buffer on a screen: Requires some setup. (See examples/magenta.rs)
let master = dev.set_master().unwrap();
master.set_crtc(crtc_id, Some(fb_id), 0, 0, &[conn_id], mode).unwrap();

TODO:

  • Better documentation.
  • Capability information.
  • Page flip.
  • Clean up DumbBuf.
  • Implement Cursors.

About

Direct Rendering Manager API for Rust.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published