1## Safe `libgbm` bindings for [rust](https://www.rust-lang.org) 2 3The Generic Buffer Manager 4 5This module provides an abstraction that the caller can use to request a 6buffer from the underlying memory management system for the platform. 7 8This allows the creation of portable code whilst still allowing access to 9the underlying memory manager. 10 11This library is best used in combination with [`drm-rs`](https://github.com/Smithay/drm-rs), 12provided through the `drm-support` feature. 13 14## Usage 15 16Add to your Cargo.toml 17 18```toml 19gbm = "0.15.0" 20``` 21 22## Example 23 24```rust 25extern crate drm; 26extern crate gbm; 27 28use drm::control::{self, crtc, framebuffer}; 29use gbm::{BufferObjectFlags, Device, Format}; 30 31// ... init your drm device ... 32let drm = init_drm_device(); 33 34// init a GBM device 35let gbm = Device::new(drm).unwrap(); 36 37// create a buffer 38let mut bo = gbm 39 .create_buffer_object::<()>( 40 1280, 41 720, 42 Format::Argb8888, 43 BufferObjectFlags::SCANOUT | BufferObjectFlags::WRITE, 44 ) 45 .unwrap(); 46 47// write something to it (usually use import or egl rendering instead) 48let buffer = { 49 let mut buffer = Vec::new(); 50 for i in 0..1280 { 51 for _ in 0..720 { 52 buffer.push(if i % 2 == 0 { 0 } else { 255 }); 53 } 54 } 55 buffer 56}; 57bo.write(&buffer).unwrap(); 58 59// create a framebuffer from our buffer 60let fb = gbm.add_framebuffer(&bo, 32, 32).unwrap(); 61 62// display it (and get a crtc, mode and connector before) 63gbm.set_crtc(crtc_handle, Some(fb), (0, 0), &[con], Some(mode)) 64 .unwrap(); 65``` 66