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
15 files changed
tree: b0cc0dc0e8c27e95ffea0b288da2b9b82acb4dcf
  1. src/
  2. .cargo_vcs_info.json
  3. Android.bp
  4. Cargo.toml
  5. Cargo.toml.orig
  6. cargo_embargo.json
  7. CHANGELOG.md
  8. LICENSE
  9. METADATA
  10. MODULE_LICENSE_MIT
  11. OWNERS
  12. README.md
README.md

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.14.2"

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();