Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoformat documentation examples and update README #9

Merged
merged 1 commit into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ provided through the `drm-support` feature.

Add to your Cargo.toml

`gbm = "0.2.2"`
```toml
gbm = "0.2.2"
```

## Example

```rust
extern crate drm;
extern crate gbm;

use drm::control::{crtc, framebuffer};
use gbm::{Device, Format, BufferObjectFlags};
use drm::control::{self, crtc, framebuffer};
use gbm::{BufferObjectFlags, Device, Format};

// ... init your drm device ...
let drm = init_drm_device();
Expand All @@ -33,13 +35,14 @@ let drm = init_drm_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();
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 = {
Expand All @@ -54,8 +57,9 @@ let buffer = {
bo.write(&buffer).unwrap();

// create a framebuffer from our buffer
let fb_info = framebuffer::create(&gbm, &bo).unwrap();
let fb = gbm.add_framebuffer(&bo, 32, 32).unwrap();

// display it (and get a crtc, mode and connector before)
crtc::set(&gbm, crtc_handle, fb_info.handle(), &[con], (0, 0), Some(mode)).unwrap();
gbm.set_crtc(crtc_handle, Some(fb), (0, 0), &[con], Some(mode))
.unwrap();
```
40 changes: 22 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,28 @@
//! ## Example
//!
//! ```rust,no_run
//! extern crate drm;
//! extern crate gbm;
//!
//! use drm::control::{self, crtc, framebuffer};
//! # use drm::control::Mode;
//! # extern crate drm;
//! # extern crate gbm;
//! # use drm::control::connector::Info as ConnectorInfo;
//! use gbm::{Device, Format, BufferObjectFlags};
//! # use drm::control::Mode;
//! use drm::control::{self, crtc, framebuffer};
//! use gbm::{BufferObjectFlags, Device, Format};
//!
//! # use std::fs::{OpenOptions, File};
//! # use std::fs::{File, OpenOptions};
//! # use std::os::unix::io::{AsRawFd, RawFd};
//! #
//! # use drm::Device as BasicDevice;
//! # use drm::control::Device as ControlDevice;
//! # use drm::Device as BasicDevice;
//! # struct Card(File);
//! #
//! # impl AsRawFd for Card {
//! # fn as_raw_fd(&self) -> RawFd { self.0.as_raw_fd() }
//! # fn as_raw_fd(&self) -> RawFd {
//! # self.0.as_raw_fd()
//! # }
//! # }
//! #
//! # impl BasicDevice for Card { }
//! # impl ControlDevice for Card { }
//! # impl BasicDevice for Card {}
//! # impl ControlDevice for Card {}
//! #
//! # fn init_drm_device() -> Card {
//! # let mut options = OpenOptions::new();
Expand All @@ -51,12 +52,14 @@
//! let gbm = Device::new(drm).unwrap();
//!
//! // create a 4x4 buffer
//! let mut bo = gbm.create_buffer_object::<()>(
//! 1280, 720,
//! Format::Argb8888,
//! BufferObjectFlags::SCANOUT | BufferObjectFlags::WRITE,
//! ).unwrap();
//!
//! 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();
Expand All @@ -79,7 +82,8 @@
//! # let mode: Mode = connector_info.modes()[0];
//! #
//! // display it (and get a crtc, mode and connector before)
//! gbm.set_crtc(crtc_handle, Some(fb), (0, 0), &[con], Some(mode)).unwrap();
//! gbm.set_crtc(crtc_handle, Some(fb), (0, 0), &[con], Some(mode))
//! .unwrap();
//! # }
//! ```

Expand Down