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

Implement glutin_interface on this crate. #2

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 10 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@ exclude = [".travis.yml", ".rustfmt.toml"]

[dependencies]
gbm-sys = { version = "0.1", path = "./gbm-sys" }
libc = "0.2"
bitflags = "1.0.0"
wayland-server = { version = "0.12", optional = true }
drm = { version = "0.3", optional = true }
libc = "0.2.66"
bitflags = "1.2.1"
wayland-client = { version = "0.23", optional = true }
drm = { version = "0.3.4", optional = true }
glutin_interface = { version = "0.1.0", path = "../glutin_interface", optional = true }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Drakulix These two lines will be fixed when the crates are published.

winit_types = { version = "0.1.0", path = "../winit_types", optional = true }

[dev-dependencies]
drm = "0.3.0"
drm = "0.3.4"

[features]
default = ["import-wayland", "import-egl", "drm-support"]
import-wayland = ["wayland-server"]
default = ["import-wayland", "import-egl", "drm-support", "glutin-support"]
glutin-support = ["glutin_interface", "winit_types"]
import-wayland = ["wayland-client"]
import-egl = []
drm-support = ["drm"]
gen = ["gbm-sys/gen"]
3 changes: 1 addition & 2 deletions gbm-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use std::path::Path;
fn main() {}

#[cfg(feature = "gen")]
fn main()
{
fn main() {
// Setup bindings builder
let generated = bindgen::builder()
.header("include/gbm.h")
Expand Down
120 changes: 59 additions & 61 deletions gbm-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,95 +3,93 @@
extern crate libc;

macro_rules! __gbm_fourcc_code {
($a:expr, $b:expr, $c:expr, $d:expr) => (
($a:expr, $b:expr, $c:expr, $d:expr) => {
($a as u32) | (($b as u32) << 8) | (($c as u32) << 16) | (($d as u32) << 24)
)
};
}

/* color index */
pub const GBM_FORMAT_C8 :u32 = __gbm_fourcc_code!('C', '8', ' ', ' '); /* [7:0] C */
// color index
pub const GBM_FORMAT_C8: u32 = __gbm_fourcc_code!('C', '8', ' ', ' '); // [7:0] C

/* 8 bpp Red */
pub const GBM_FORMAT_R8 :u32 = __gbm_fourcc_code!('R', '8', ' ', ' '); /* [7:0] R */
// 8 bpp Red
pub const GBM_FORMAT_R8: u32 = __gbm_fourcc_code!('R', '8', ' ', ' '); // [7:0] R

/* 16 bpp RG */
pub const GBM_FORMAT_GR88 :u32 = __gbm_fourcc_code!('G', 'R', '8', '8'); /* [15:0] G:R 8:8 little endian */
// 16 bpp RG
pub const GBM_FORMAT_GR88: u32 = __gbm_fourcc_code!('G', 'R', '8', '8'); // [15:0] G:R 8:8 little endian

/* 8 bpp RGB */
pub const GBM_FORMAT_RGB332 :u32 = __gbm_fourcc_code!('R', 'G', 'B', '8'); /* [7:0] R:G:B 3:3:2 */
pub const GBM_FORMAT_BGR233 :u32 = __gbm_fourcc_code!('B', 'G', 'R', '8'); /* [7:0] B:G:R 2:3:3 */
// 8 bpp RGB
pub const GBM_FORMAT_RGB332: u32 = __gbm_fourcc_code!('R', 'G', 'B', '8'); // [7:0] R:G:B 3:3:2
pub const GBM_FORMAT_BGR233: u32 = __gbm_fourcc_code!('B', 'G', 'R', '8'); // [7:0] B:G:R 2:3:3

/* 16 bpp RGB */
pub const GBM_FORMAT_XRGB4444 :u32 = __gbm_fourcc_code!('X', 'R', '1', '2'); /* [15:0] x:R:G:B 4:4:4:4 little endian */
pub const GBM_FORMAT_XBGR4444 :u32 = __gbm_fourcc_code!('X', 'B', '1', '2'); /* [15:0] x:B:G:R 4:4:4:4 little endian */
pub const GBM_FORMAT_RGBX4444 :u32 = __gbm_fourcc_code!('R', 'X', '1', '2'); /* [15:0] R:G:B:x 4:4:4:4 little endian */
pub const GBM_FORMAT_BGRX4444 :u32 = __gbm_fourcc_code!('B', 'X', '1', '2'); /* [15:0] B:G:R:x 4:4:4:4 little endian */
// 16 bpp RGB
pub const GBM_FORMAT_XRGB4444: u32 = __gbm_fourcc_code!('X', 'R', '1', '2'); // [15:0] x:R:G:B 4:4:4:4 little endian
pub const GBM_FORMAT_XBGR4444: u32 = __gbm_fourcc_code!('X', 'B', '1', '2'); // [15:0] x:B:G:R 4:4:4:4 little endian
pub const GBM_FORMAT_RGBX4444: u32 = __gbm_fourcc_code!('R', 'X', '1', '2'); // [15:0] R:G:B:x 4:4:4:4 little endian
pub const GBM_FORMAT_BGRX4444: u32 = __gbm_fourcc_code!('B', 'X', '1', '2'); // [15:0] B:G:R:x 4:4:4:4 little endian

pub const GBM_FORMAT_ARGB4444 :u32 = __gbm_fourcc_code!('A', 'R', '1', '2'); /* [15:0] A:R:G:B 4:4:4:4 little endian */
pub const GBM_FORMAT_ABGR4444 :u32 = __gbm_fourcc_code!('A', 'B', '1', '2'); /* [15:0] A:B:G:R 4:4:4:4 little endian */
pub const GBM_FORMAT_RGBA4444 :u32 = __gbm_fourcc_code!('R', 'A', '1', '2'); /* [15:0] R:G:B:A 4:4:4:4 little endian */
pub const GBM_FORMAT_BGRA4444 :u32 = __gbm_fourcc_code!('B', 'A', '1', '2'); /* [15:0] B:G:R:A 4:4:4:4 little endian */
pub const GBM_FORMAT_ARGB4444: u32 = __gbm_fourcc_code!('A', 'R', '1', '2'); // [15:0] A:R:G:B 4:4:4:4 little endian
pub const GBM_FORMAT_ABGR4444: u32 = __gbm_fourcc_code!('A', 'B', '1', '2'); // [15:0] A:B:G:R 4:4:4:4 little endian
pub const GBM_FORMAT_RGBA4444: u32 = __gbm_fourcc_code!('R', 'A', '1', '2'); // [15:0] R:G:B:A 4:4:4:4 little endian
pub const GBM_FORMAT_BGRA4444: u32 = __gbm_fourcc_code!('B', 'A', '1', '2'); // [15:0] B:G:R:A 4:4:4:4 little endian

pub const GBM_FORMAT_XRGB1555 :u32 = __gbm_fourcc_code!('X', 'R', '1', '5'); /* [15:0] x:R:G:B 1:5:5:5 little endian */
pub const GBM_FORMAT_XBGR1555 :u32 = __gbm_fourcc_code!('X', 'B', '1', '5'); /* [15:0] x:B:G:R 1:5:5:5 little endian */
pub const GBM_FORMAT_RGBX5551 :u32 = __gbm_fourcc_code!('R', 'X', '1', '5'); /* [15:0] R:G:B:x 5:5:5:1 little endian */
pub const GBM_FORMAT_BGRX5551 :u32 = __gbm_fourcc_code!('B', 'X', '1', '5'); /* [15:0] B:G:R:x 5:5:5:1 little endian */
pub const GBM_FORMAT_XRGB1555: u32 = __gbm_fourcc_code!('X', 'R', '1', '5'); // [15:0] x:R:G:B 1:5:5:5 little endian
pub const GBM_FORMAT_XBGR1555: u32 = __gbm_fourcc_code!('X', 'B', '1', '5'); // [15:0] x:B:G:R 1:5:5:5 little endian
pub const GBM_FORMAT_RGBX5551: u32 = __gbm_fourcc_code!('R', 'X', '1', '5'); // [15:0] R:G:B:x 5:5:5:1 little endian
pub const GBM_FORMAT_BGRX5551: u32 = __gbm_fourcc_code!('B', 'X', '1', '5'); // [15:0] B:G:R:x 5:5:5:1 little endian

pub const GBM_FORMAT_ARGB1555 :u32 = __gbm_fourcc_code!('A', 'R', '1', '5'); /* [15:0] A:R:G:B 1:5:5:5 little endian */
pub const GBM_FORMAT_ABGR1555 :u32 = __gbm_fourcc_code!('A', 'B', '1', '5'); /* [15:0] A:B:G:R 1:5:5:5 little endian */
pub const GBM_FORMAT_RGBA5551 :u32 = __gbm_fourcc_code!('R', 'A', '1', '5'); /* [15:0] R:G:B:A 5:5:5:1 little endian */
pub const GBM_FORMAT_BGRA5551 :u32 = __gbm_fourcc_code!('B', 'A', '1', '5'); /* [15:0] B:G:R:A 5:5:5:1 little endian */
pub const GBM_FORMAT_ARGB1555: u32 = __gbm_fourcc_code!('A', 'R', '1', '5'); // [15:0] A:R:G:B 1:5:5:5 little endian
pub const GBM_FORMAT_ABGR1555: u32 = __gbm_fourcc_code!('A', 'B', '1', '5'); // [15:0] A:B:G:R 1:5:5:5 little endian
pub const GBM_FORMAT_RGBA5551: u32 = __gbm_fourcc_code!('R', 'A', '1', '5'); // [15:0] R:G:B:A 5:5:5:1 little endian
pub const GBM_FORMAT_BGRA5551: u32 = __gbm_fourcc_code!('B', 'A', '1', '5'); // [15:0] B:G:R:A 5:5:5:1 little endian

pub const GBM_FORMAT_RGB565 :u32 = __gbm_fourcc_code!('R', 'G', '1', '6'); /* [15:0] R:G:B 5:6:5 little endian */
pub const GBM_FORMAT_BGR565 :u32 = __gbm_fourcc_code!('B', 'G', '1', '6'); /* [15:0] B:G:R 5:6:5 little endian */
pub const GBM_FORMAT_RGB565: u32 = __gbm_fourcc_code!('R', 'G', '1', '6'); // [15:0] R:G:B 5:6:5 little endian
pub const GBM_FORMAT_BGR565: u32 = __gbm_fourcc_code!('B', 'G', '1', '6'); // [15:0] B:G:R 5:6:5 little endian

/* 24 bpp RGB */
pub const GBM_FORMAT_RGB888 :u32 = __gbm_fourcc_code!('R', 'G', '2', '4'); /* [23:0] R:G:B little endian */
pub const GBM_FORMAT_BGR888 :u32 = __gbm_fourcc_code!('B', 'G', '2', '4'); /* [23:0] B:G:R little endian */
// 24 bpp RGB
pub const GBM_FORMAT_RGB888: u32 = __gbm_fourcc_code!('R', 'G', '2', '4'); // [23:0] R:G:B little endian
pub const GBM_FORMAT_BGR888: u32 = __gbm_fourcc_code!('B', 'G', '2', '4'); // [23:0] B:G:R little endian

/* 32 bpp RGB */
pub const GBM_FORMAT_XRGB8888 :u32 = __gbm_fourcc_code!('X', 'R', '2', '4'); /* [31:0] x:R:G:B 8:8:8:8 little endian */
pub const GBM_FORMAT_XBGR8888 :u32 = __gbm_fourcc_code!('X', 'B', '2', '4'); /* [31:0] x:B:G:R 8:8:8:8 little endian */
pub const GBM_FORMAT_RGBX8888 :u32 = __gbm_fourcc_code!('R', 'X', '2', '4'); /* [31:0] R:G:B:x 8:8:8:8 little endian */
pub const GBM_FORMAT_BGRX8888 :u32 = __gbm_fourcc_code!('B', 'X', '2', '4'); /* [31:0] B:G:R:x 8:8:8:8 little endian */
// 32 bpp RGB
pub const GBM_FORMAT_XRGB8888: u32 = __gbm_fourcc_code!('X', 'R', '2', '4'); // [31:0] x:R:G:B 8:8:8:8 little endian
pub const GBM_FORMAT_XBGR8888: u32 = __gbm_fourcc_code!('X', 'B', '2', '4'); // [31:0] x:B:G:R 8:8:8:8 little endian
pub const GBM_FORMAT_RGBX8888: u32 = __gbm_fourcc_code!('R', 'X', '2', '4'); // [31:0] R:G:B:x 8:8:8:8 little endian
pub const GBM_FORMAT_BGRX8888: u32 = __gbm_fourcc_code!('B', 'X', '2', '4'); // [31:0] B:G:R:x 8:8:8:8 little endian

pub const GBM_FORMAT_ARGB8888 :u32 = __gbm_fourcc_code!('A', 'R', '2', '4'); /* [31:0] A:R:G:B 8:8:8:8 little endian */
pub const GBM_FORMAT_ABGR8888 :u32 = __gbm_fourcc_code!('A', 'B', '2', '4'); /* [31:0] A:B:G:R 8:8:8:8 little endian */
pub const GBM_FORMAT_RGBA8888 :u32 = __gbm_fourcc_code!('R', 'A', '2', '4'); /* [31:0] R:G:B:A 8:8:8:8 little endian */
pub const GBM_FORMAT_BGRA8888 :u32 = __gbm_fourcc_code!('B', 'A', '2', '4'); /* [31:0] B:G:R:A 8:8:8:8 little endian */
pub const GBM_FORMAT_ARGB8888: u32 = __gbm_fourcc_code!('A', 'R', '2', '4'); // [31:0] A:R:G:B 8:8:8:8 little endian
pub const GBM_FORMAT_ABGR8888: u32 = __gbm_fourcc_code!('A', 'B', '2', '4'); // [31:0] A:B:G:R 8:8:8:8 little endian
pub const GBM_FORMAT_RGBA8888: u32 = __gbm_fourcc_code!('R', 'A', '2', '4'); // [31:0] R:G:B:A 8:8:8:8 little endian
pub const GBM_FORMAT_BGRA8888: u32 = __gbm_fourcc_code!('B', 'A', '2', '4'); // [31:0] B:G:R:A 8:8:8:8 little endian

pub const GBM_FORMAT_XRGB2101010 :u32 = __gbm_fourcc_code!('X', 'R', '3', '0'); /* [31:0] x:R:G:B 2:10:10:10 little endian */
pub const GBM_FORMAT_XBGR2101010 :u32 = __gbm_fourcc_code!('X', 'B', '3', '0'); /* [31:0] x:B:G:R 2:10:10:10 little endian */
pub const GBM_FORMAT_RGBX1010102 :u32 = __gbm_fourcc_code!('R', 'X', '3', '0'); /* [31:0] R:G:B:x 10:10:10:2 little endian */
pub const GBM_FORMAT_BGRX1010102 :u32 = __gbm_fourcc_code!('B', 'X', '3', '0'); /* [31:0] B:G:R:x 10:10:10:2 little endian */
pub const GBM_FORMAT_XRGB2101010: u32 = __gbm_fourcc_code!('X', 'R', '3', '0'); // [31:0] x:R:G:B 2:10:10:10 little endian
pub const GBM_FORMAT_XBGR2101010: u32 = __gbm_fourcc_code!('X', 'B', '3', '0'); // [31:0] x:B:G:R 2:10:10:10 little endian
pub const GBM_FORMAT_RGBX1010102: u32 = __gbm_fourcc_code!('R', 'X', '3', '0'); // [31:0] R:G:B:x 10:10:10:2 little endian
pub const GBM_FORMAT_BGRX1010102: u32 = __gbm_fourcc_code!('B', 'X', '3', '0'); // [31:0] B:G:R:x 10:10:10:2 little endian

pub const GBM_FORMAT_ARGB2101010 :u32 = __gbm_fourcc_code!('A', 'R', '3', '0'); /* [31:0] A:R:G:B 2:10:10:10 little endian */
pub const GBM_FORMAT_ABGR2101010 :u32 = __gbm_fourcc_code!('A', 'B', '3', '0'); /* [31:0] A:B:G:R 2:10:10:10 little endian */
pub const GBM_FORMAT_RGBA1010102 :u32 = __gbm_fourcc_code!('R', 'A', '3', '0'); /* [31:0] R:G:B:A 10:10:10:2 little endian */
pub const GBM_FORMAT_BGRA1010102 :u32 = __gbm_fourcc_code!('B', 'A', '3', '0'); /* [31:0] B:G:R:A 10:10:10:2 little endian */
pub const GBM_FORMAT_ARGB2101010: u32 = __gbm_fourcc_code!('A', 'R', '3', '0'); // [31:0] A:R:G:B 2:10:10:10 little endian
pub const GBM_FORMAT_ABGR2101010: u32 = __gbm_fourcc_code!('A', 'B', '3', '0'); // [31:0] A:B:G:R 2:10:10:10 little endian
pub const GBM_FORMAT_RGBA1010102: u32 = __gbm_fourcc_code!('R', 'A', '3', '0'); // [31:0] R:G:B:A 10:10:10:2 little endian
pub const GBM_FORMAT_BGRA1010102: u32 = __gbm_fourcc_code!('B', 'A', '3', '0'); // [31:0] B:G:R:A 10:10:10:2 little endian

/* packed YCbCr */
pub const GBM_FORMAT_YUYV :u32 = __gbm_fourcc_code!('Y', 'U', 'Y', 'V'); /* [31:0] Cr0:Y1:Cb0:Y0 8:8:8:8 little endian */
pub const GBM_FORMAT_YVYU :u32 = __gbm_fourcc_code!('Y', 'V', 'Y', 'U'); /* [31:0] Cb0:Y1:Cr0:Y0 8:8:8:8 little endian */
pub const GBM_FORMAT_UYVY :u32 = __gbm_fourcc_code!('U', 'Y', 'V', 'Y'); /* [31:0] Y1:Cr0:Y0:Cb0 8:8:8:8 little endian */
pub const GBM_FORMAT_VYUY :u32 = __gbm_fourcc_code!('V', 'Y', 'U', 'Y'); /* [31:0] Y1:Cb0:Y0:Cr0 8:8:8:8 little endian */
// packed YCbCr
pub const GBM_FORMAT_YUYV: u32 = __gbm_fourcc_code!('Y', 'U', 'Y', 'V'); // [31:0] Cr0:Y1:Cb0:Y0 8:8:8:8 little endian
pub const GBM_FORMAT_YVYU: u32 = __gbm_fourcc_code!('Y', 'V', 'Y', 'U'); // [31:0] Cb0:Y1:Cr0:Y0 8:8:8:8 little endian
pub const GBM_FORMAT_UYVY: u32 = __gbm_fourcc_code!('U', 'Y', 'V', 'Y'); // [31:0] Y1:Cr0:Y0:Cb0 8:8:8:8 little endian
pub const GBM_FORMAT_VYUY: u32 = __gbm_fourcc_code!('V', 'Y', 'U', 'Y'); // [31:0] Y1:Cb0:Y0:Cr0 8:8:8:8 little endian

pub const GBM_FORMAT_AYUV :u32 = __gbm_fourcc_code!('A', 'Y', 'U', 'V'); /* [31:0] A:Y:Cb:Cr 8:8:8:8 little endian */
pub const GBM_FORMAT_AYUV: u32 = __gbm_fourcc_code!('A', 'Y', 'U', 'V'); // [31:0] A:Y:Cb:Cr 8:8:8:8 little endian

#[repr(C)]
pub enum GBM_BO_IMPORT {
WL_BUFFER = 0x5501,
EGL_IMAGE = 0x5502,
FD = 0x5503,
FD = 0x5503,
}

#[cfg(feature = "gen")]
include!(concat!(env!("OUT_DIR"), "/gen.rs"));

#[cfg(all(not(feature = "gen"),
target_os="linux",
target_arch="x86_64"))]
#[cfg(all(not(feature = "gen"), target_os = "linux", target_arch = "x86_64"))]
include!(concat!("platforms/linux/x86_64/gen.rs"));

#[link(name = "gbm")]
extern {}
extern "C" {}
90 changes: 56 additions & 34 deletions src/buffer_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use std::io::{Error as IoError, Result as IoResult};
use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};
use std::os::unix::io::{AsRawFd, RawFd};
use std::rc::Weak;
use std::ptr;
use std::rc::Weak;
use std::slice;

/// A gbm buffer object
Expand Down Expand Up @@ -104,27 +104,27 @@ impl<'a, T: 'static> MappedBufferObject<'a, T> {
impl<'a, T: 'static> Deref for MappedBufferObject<'a, T> {
type Target = BufferObject<T>;
fn deref(&self) -> &BufferObject<T> {
match &self.bo {
&BORef::Ref(bo) => bo,
&BORef::Mut(ref bo) => bo,
match self.bo {
BORef::Ref(bo) => bo,
BORef::Mut(ref bo) => bo,
}
}
}

impl<'a, T: 'static> DerefMut for MappedBufferObject<'a, T> {
fn deref_mut(&mut self) -> &mut BufferObject<T> {
match &mut self.bo {
&mut BORef::Ref(_) => unreachable!(),
&mut BORef::Mut(ref mut bo) => bo,
match self.bo {
BORef::Ref(_) => unreachable!(),
BORef::Mut(ref mut bo) => bo,
}
}
}

impl<'a, T: 'static> Drop for MappedBufferObject<'a, T> {
fn drop(&mut self) {
let ffi = match &self.bo {
&BORef::Ref(bo) => bo.ffi,
&BORef::Mut(ref bo) => bo.ffi,
let ffi = match self.bo {
BORef::Ref(bo) => bo.ffi,
BORef::Mut(ref bo) => bo.ffi,
};
unsafe { ::ffi::gbm_bo_unmap(ffi, self.addr) }
}
Expand Down Expand Up @@ -169,7 +169,7 @@ impl<T: 'static> BufferObject<T> {
pub fn format(&self) -> Result<Format, DeviceDestroyedError> {
if self._device.upgrade().is_some() {
Ok(Format::from_ffi(unsafe { ::ffi::gbm_bo_get_format(self.ffi) })
.expect("libgbm returned invalid buffer format"))
.expect("libgbm returned invalid buffer format"))
} else {
Err(DeviceDestroyedError)
}
Expand All @@ -190,16 +190,26 @@ impl<T: 'static> BufferObject<T> {
/// Map a region of a gbm buffer object for cpu access
///
/// This function maps a region of a gbm bo for cpu read access.
pub fn map<'a, D, F, S>(&'a self, device: &Device<D>, x: u32, y: u32, width: u32, height: u32, f: F) -> Result<IoResult<S>, WrongDeviceError>
where
D: AsRawFd + 'static,
F: FnOnce(&MappedBufferObject<'a, T>) -> S,
pub fn map<'a, D, F, S>(
&'a self,
device: &Device<D>,
x: u32,
y: u32,
width: u32,
height: u32,
f: F,
) -> Result<IoResult<S>, WrongDeviceError>
where
D: AsRawFd + 'static,
F: FnOnce(&MappedBufferObject<'a, T>) -> S,
{
if let Some(_device) = self._device.upgrade() {
if *_device != device.as_raw_mut() { // not matching
if *_device != device.as_raw_mut() {
// not matching
return Err(WrongDeviceError);
}
} else { // not matching
} else {
// not matching
return Err(WrongDeviceError);
}

Expand Down Expand Up @@ -249,15 +259,17 @@ impl<T: 'static> BufferObject<T> {
height: u32,
f: F,
) -> Result<IoResult<S>, WrongDeviceError>
where
D: AsRawFd + 'static,
F: FnOnce(&mut MappedBufferObject<'a, T>) -> S,
where
D: AsRawFd + 'static,
F: FnOnce(&mut MappedBufferObject<'a, T>) -> S,
{
if let Some(_device) = self._device.upgrade() {
if *_device != device.as_raw_mut() { // not matching
if *_device != device.as_raw_mut() {
// not matching
return Err(WrongDeviceError);
}
} else { // not matching
} else {
// not matching
return Err(WrongDeviceError);
}

Expand Down Expand Up @@ -394,7 +406,10 @@ impl<T: 'static> BufferObject<T> {
}
}

pub(crate) unsafe fn new(ffi: *mut ::ffi::gbm_bo, device: Weak<*mut ::ffi::gbm_device>) -> BufferObject<T> {
pub(crate) unsafe fn new(
ffi: *mut ::ffi::gbm_bo,
device: Weak<*mut ::ffi::gbm_device>,
) -> BufferObject<T> {
BufferObject {
ffi,
_device: device,
Expand Down Expand Up @@ -426,7 +441,10 @@ impl<T: 'static> Drop for BufferObject<T> {
#[cfg(feature = "drm-support")]
impl<T: 'static> DrmBuffer for BufferObject<T> {
fn size(&self) -> (u32, u32) {
(self.width().expect("GbmDevice does not exist anymore"), self.height().expect("GbmDevice does not exist anymore"))
(
self.width().expect("GbmDevice does not exist anymore"),
self.height().expect("GbmDevice does not exist anymore"),
)
}

fn format(&self) -> DrmPixelFormat {
Expand All @@ -438,7 +456,15 @@ impl<T: 'static> DrmBuffer for BufferObject<T> {
}

fn handle(&self) -> DrmId {
unsafe { DrmId::from_raw(*self.handle().expect("GbmDevice does not exist anymore").u32.as_ref()) }
unsafe {
DrmId::from_raw(
*self
.handle()
.expect("GbmDevice does not exist anymore")
.u32
.as_ref(),
)
}
}
}

Expand All @@ -448,15 +474,11 @@ pub struct WrongDeviceError;

impl fmt::Display for WrongDeviceError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use std::error::Error;
write!(f, "{}", self.description())
write!(
f,
"The gbm specified is not the one this buffer object belongs to"
)
}
}

impl error::Error for WrongDeviceError {
fn description(&self) -> &str {
"The gbm specified is not the one this buffer object belongs to"
}

fn cause(&self) -> Option<&error::Error> { None }
}
impl error::Error for WrongDeviceError {}
Loading