drm-rs
This library is a safe interface to the Direct Rendering Manager API found on various operating systems.
This library is currently a work in progress.
Usage
The user is expected to implement their own functionality for opening and
accessing the file descriptor of the device. Here we create a small wrapper
around File
and implement AsRawFd
, drm::Device
, and
drm::control::Device
:
extern crate drm;
use ;
use ;
use Device as BasicDevice;
use Device as ControlDevice;
// The drm crate does not provide a method of opening the device.
// It is expected to be implemented by the user.
;
// Required to implement drm::Device
// Required to implement drm::control::Device
// Allows modesetting functionality to be performed.
Assuming the program used the above wrapper, the user now opens the card:
// Open the device (usually located at /dev/dri/*) with rw access.
let mut options = new;
options.read;
options.write;
let file = options.open;
let card = Card;
Now we can check out what resources are available:
// Get a set of all modesetting resource handles (excluding planes):
let res_handles = card.resource_handles.unwrap;
// Print all connector information
for &con in res_handles.connectors
// Print all CRTC information
for &crtc in res_handles.crtcs
You'll also want to find a suitable mode:
// Assuming we found a good connector and loaded the info into `connector_info`
let &mode = connector_info.modes.iter; // Search until you find one you want.
Once you find a suitable connector and CRTC, it's time to create a framebuffer. Here we use a simple dumbbuffer as the backend:'
// Create a DB of size 1920x1080
let db = create_from_device
.expect;
// Map it and grey it out.
let mut map = db.map.expect;
for mut b in map.as_mut
let fb_info = create_from_buffer
let fb_handle = fb_info.handle;
Now we can apply the framebuffer onto the CRTC's internal plane, and connect it to a connector with the proper mode:
// Assuming `crtc` is a crtc handle and `con` is a connector handle
crtc.set_on_device
.expect;
The contents of the dumb buffer will now appear onto the screen.