commit | 367c0f6625381ba9b0ae299bb94d3e6b729e797f | [log] [tgz] |
---|---|---|
author | Marcin Radomski <dextero@google.com> | Wed Mar 13 17:11:51 2024 +0000 |
committer | Marcin Radomski <dextero@google.com> | Wed Mar 13 17:32:13 2024 +0000 |
tree | b0cc0dc0e8c27e95ffea0b288da2b9b82acb4dcf | |
parent | 3873302c6716e710b9ccae31d0de5d8af07b1554 [diff] |
Import 'gbm' crate Request Document: go/android-rust-importing-crates For CL Reviewers: go/android3p#cl-review For Build Team: go/ab-third-party-imports Bug: http://b/325953018 Test: m libgbm_rust (with aosp/2997556 + aosp/3000518 checked out) Change-Id: I64f7dc10caadfadd8e2bda0fb1c8e196de6c6f3f
libgbm
bindings for rustThe 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.
Add to your Cargo.toml
gbm = "0.14.2"
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();