21 releases (breaking)

new 0.16.1 Nov 21, 2024
0.15.0 Apr 19, 2024
0.14.2 Feb 15, 2024
0.14.0 Nov 14, 2023
0.1.0 Aug 24, 2016

#22 in Memory management

Download history 13996/week @ 2024-08-04 14466/week @ 2024-08-11 15285/week @ 2024-08-18 15229/week @ 2024-08-25 16807/week @ 2024-09-01 14878/week @ 2024-09-08 15421/week @ 2024-09-15 17396/week @ 2024-09-22 20640/week @ 2024-09-29 20241/week @ 2024-10-06 19655/week @ 2024-10-13 18876/week @ 2024-10-20 17688/week @ 2024-10-27 19593/week @ 2024-11-03 7697/week @ 2024-11-10 7147/week @ 2024-11-17

53,106 downloads per month
Used in 12 crates (3 directly)

MIT license

67KB
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.16.1"

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.1–8.5MB
~93K SLoC