23 releases (breaking)

0.18.0 Dec 3, 2024
0.16.1 Nov 21, 2024
0.15.0 Apr 19, 2024
0.14.2 Feb 15, 2024
0.1.0 Aug 24, 2016

#24 in Memory management

Download history 15707/week @ 2024-08-22 15500/week @ 2024-08-29 16389/week @ 2024-09-05 15098/week @ 2024-09-12 15830/week @ 2024-09-19 20008/week @ 2024-09-26 21212/week @ 2024-10-03 19572/week @ 2024-10-10 19218/week @ 2024-10-17 17539/week @ 2024-10-24 18809/week @ 2024-10-31 12850/week @ 2024-11-07 7227/week @ 2024-11-14 8541/week @ 2024-11-21 8215/week @ 2024-11-28 7940/week @ 2024-12-05

33,241 downloads per month
Used in 12 crates (3 directly)

MIT license

60KB
1.5K SLoC

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

~0.1–8.5MB
~93K SLoC