Code Monkey home page Code Monkey logo

drm-rs's Introduction

drm-rs

Crates.io docs.rs Build Status

A safe interface to the Direct Rendering Manager.

Direct Rendering Manager

The Direct Rendering Manager is a subsystem found on multiple Unix-based operating systems that provides a userspace API to graphics hardware. See the Wikipedia article for more details.

Usage

Basic

The DRM is accessed using ioctls on a file representing a graphics card. These can normally be found in /dev/dri, but can also be opened in other ways (ex. udev).

This crate does not provide a method of opening these files. Instead, the user program must provide a way to access the file descriptor representing the device through the AsRawFd trait. Here is a basic example using File as a backend:

/// A simple wrapper for a device node.
pub struct Card(std::fs::File);

/// Implementing `AsRawFd` is a prerequisite to implementing the traits found
/// in this crate. Here, we are just calling `as_raw_fd()` on the inner File.
impl std::os::unix::io::AsRawFd for Card {
    fn as_raw_fd(&self) -> std::os::unix::io::RawFd {
        self.0.as_raw_fd()
    }
}

/// Simple helper methods for opening a `Card`.
impl Card {
    pub fn open(path: &str) -> Self {
        let mut options = std::fs::OpenOptions::new();
        options.read(true);
        options.write(true);
        Card(options.open(path).unwrap())
    }
}

Finally, you can implement drm::Device to gain access to the basic DRM functionality:

impl drm::Device for Card {}

fn main() {
    let gpu = Card::open("/dev/dri/card0");
    println!("{:#?}", gpu.get_driver().unwrap());
}

Control (modesetting)

See drm::control::Device as well as our mode-setting examples: atomic_modeset and legacy_modeset

Rendering

Rendering is done by creating and attaching framebuffers to crtcs.

A framebuffer is created from anything implementing Buffer like the always available, but very limited, DumbBuffer.

For faster hardware-backed buffers, checkout gbm.rs.

drm-rs's People

Contributors

bjorn3 avatar c0rneille avatar ctsrc avatar drakulix avatar elinorbgr avatar i509vcb avatar katyo avatar linkmauve avatar marijns95 avatar pum-purum-pum-pum avatar scrblue avatar slabity avatar spencercw avatar theedward162 avatar tomstokes avatar valpackett avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.