7 unstable releases

0.4.0 Dec 3, 2024
0.3.1 Sep 28, 2024
0.3.0 Nov 14, 2023
0.2.2 Jan 3, 2023
0.1.0 Sep 11, 2017

#213 in Graphics APIs

Download history 15250/week @ 2024-08-25 16820/week @ 2024-09-01 14900/week @ 2024-09-08 15447/week @ 2024-09-15 17368/week @ 2024-09-22 21193/week @ 2024-09-29 20607/week @ 2024-10-06 19927/week @ 2024-10-13 18946/week @ 2024-10-20 17755/week @ 2024-10-27 19600/week @ 2024-11-03 7716/week @ 2024-11-10 7120/week @ 2024-11-17 7683/week @ 2024-11-24 8977/week @ 2024-12-01 7146/week @ 2024-12-08

31,826 downloads per month
Used in 14 crates (2 directly)

MIT license

15KB
365 lines

Safe libgbm bindings for rust

The Generic Buffer Manager

This module provides an abstraction that the caller can use to request a buffer from the underlying memory management system for the platform.

This allows the creation of portable code whilst still allowing access to the underlying memory manager.

This library is best used in combination with drm-rs, provided through the drm-support feature.

Usage

Add to your Cargo.toml

gbm = "0.18.0"

Example

use drm::control::{self, crtc, framebuffer};
use gbm::{BufferObjectFlags, Device, Format};

// ... init your drm device ...
let drm = init_drm_device();

// init a GBM device
let gbm = Device::new(drm).unwrap();

// create a buffer
let mut bo = gbm
    .create_buffer_object::<()>(
        1280,
        720,
        Format::Argb8888,
        BufferObjectFlags::SCANOUT | BufferObjectFlags::WRITE,
    )
    .unwrap();

// write something to it (usually use import or egl rendering instead)
let buffer = {
    let mut buffer = Vec::new();
    for i in 0..1280 {
        for _ in 0..720 {
            buffer.push(if i % 2 == 0 { 0 } else { 255 });
        }
    }
    buffer
};
bo.write(&buffer).unwrap();

// create a framebuffer from our buffer
let fb = gbm.add_framebuffer(&bo, 32, 32).unwrap();

// display it (and get a crtc, mode and connector before)
gbm.set_crtc(crtc_handle, Some(fb), (0, 0), &[con], Some(mode))
    .unwrap();

Dependencies

~175KB