14 releases (breaking)

0.12.0 Mar 30, 2023
0.10.0 Jan 3, 2023
0.9.0 Aug 29, 2022
0.8.0 Jan 26, 2022
0.1.0 Aug 24, 2016

#44 in Memory management

Download history 348/week @ 2023-02-06 464/week @ 2023-02-13 382/week @ 2023-02-20 290/week @ 2023-02-27 559/week @ 2023-03-06 569/week @ 2023-03-13 598/week @ 2023-03-20 626/week @ 2023-03-27 644/week @ 2023-04-03 487/week @ 2023-04-10 437/week @ 2023-04-17 530/week @ 2023-04-24 562/week @ 2023-05-01 390/week @ 2023-05-08 496/week @ 2023-05-15 410/week @ 2023-05-22

1,907 downloads per month
Used in smithay

MIT license

50KB
1K 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.12.0"

Example

extern crate drm;
extern crate gbm;

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.2–1.1MB
~24K SLoC