From 55a9e504beef368bd97e51ffd5a7fa6c034eb8ad Mon Sep 17 00:00:00 2001 From: Zach Reizner Date: Wed, 3 Oct 2018 10:22:32 -0700 Subject: cargo fmt all source code Now that cargo fmt has landed, run it over everything at once to bring rust source to the standard formatting. TEST=cargo test BUG=None Change-Id: Ic95a48725e5a40dcbd33ba6d5aef2bd01e91865b Reviewed-on: https://chromium-review.googlesource.com/1259287 Commit-Ready: ChromeOS CL Exonerator Bot Tested-by: Zach Reizner Reviewed-by: Zach Reizner --- gpu_display/build.rs | 18 ++++--- gpu_display/src/dwl.rs | 46 +++++++++-------- gpu_display/src/lib.rs | 136 +++++++++++++++++++++++++------------------------ 3 files changed, 105 insertions(+), 95 deletions(-) (limited to 'gpu_display') diff --git a/gpu_display/build.rs b/gpu_display/build.rs index a1ce4f7..33a8653 100644 --- a/gpu_display/build.rs +++ b/gpu_display/build.rs @@ -45,9 +45,11 @@ fn find_protocol(name: &str) -> PathBuf { // Use bundled protocols as a fallback. let protocol_path = Path::new("protocol").join(protocol_file_name); - assert!(protocol_path.is_file(), - "unable to locate wayland protocol specification for `{}`", - name); + assert!( + protocol_path.is_file(), + "unable to locate wayland protocol specification for `{}`", + name + ); protocol_path } @@ -84,10 +86,12 @@ fn main() { build.file("src/display_wl.c"); println!("cargo:rerun-if-changed=src/display_wl.c"); - for protocol in &["aura-shell", - "linux-dmabuf-unstable-v1", - "xdg-shell-unstable-v6", - "viewporter"] { + for protocol in &[ + "aura-shell", + "linux-dmabuf-unstable-v1", + "xdg-shell-unstable-v6", + "viewporter", + ] { build.file(compile_protocol(protocol, &out_dir)); } build.compile("display_wl"); diff --git a/gpu_display/src/dwl.rs b/gpu_display/src/dwl.rs index cbe337d..41751a7 100644 --- a/gpu_display/src/dwl.rs +++ b/gpu_display/src/dwl.rs @@ -1,6 +1,5 @@ /* automatically generated by rust-bindgen */ - /// @page page_xdg_shell_unstable_v6 The xdg_shell_unstable_v6 protocol /// @section page_ifaces_xdg_shell_unstable_v6 Interfaces /// - @subpage page_iface_zxdg_shell_v6 - create desktop-style surfaces @@ -61,9 +60,10 @@ extern "C" { pub fn dwl_context_destroy(self_: *mut *mut dwl_context); } extern "C" { - pub fn dwl_context_setup(self_: *mut dwl_context, - socket_path: *const ::std::os::raw::c_char) - -> bool; + pub fn dwl_context_setup( + self_: *mut dwl_context, + socket_path: *const ::std::os::raw::c_char, + ) -> bool; } extern "C" { pub fn dwl_context_fd(self_: *mut dwl_context) -> ::std::os::raw::c_int; @@ -72,29 +72,31 @@ extern "C" { pub fn dwl_context_dispatch(self_: *mut dwl_context); } extern "C" { - pub fn dwl_context_dmabuf_new(self_: *mut dwl_context, - fd: ::std::os::raw::c_int, - offset: u32, - stride: u32, - modifiers: u64, - width: u32, - height: u32, - fourcc: u32) - -> *mut dwl_dmabuf; + pub fn dwl_context_dmabuf_new( + self_: *mut dwl_context, + fd: ::std::os::raw::c_int, + offset: u32, + stride: u32, + modifiers: u64, + width: u32, + height: u32, + fourcc: u32, + ) -> *mut dwl_dmabuf; } extern "C" { pub fn dwl_dmabuf_destroy(self_: *mut *mut dwl_dmabuf); } extern "C" { - pub fn dwl_context_surface_new(self_: *mut dwl_context, - parent: *mut dwl_surface, - shm_fd: ::std::os::raw::c_int, - shm_size: usize, - buffer_size: usize, - width: u32, - height: u32, - stride: u32) - -> *mut dwl_surface; + pub fn dwl_context_surface_new( + self_: *mut dwl_context, + parent: *mut dwl_surface, + shm_fd: ::std::os::raw::c_int, + shm_size: usize, + buffer_size: usize, + width: u32, + height: u32, + stride: u32, + ) -> *mut dwl_surface; } extern "C" { pub fn dwl_surface_destroy(self_: *mut *mut dwl_surface); diff --git a/gpu_display/src/lib.rs b/gpu_display/src/lib.rs index 7ff116a..da9d473 100644 --- a/gpu_display/src/lib.rs +++ b/gpu_display/src/lib.rs @@ -16,8 +16,8 @@ use std::os::unix::io::{AsRawFd, RawFd}; use std::path::Path; use std::ptr::null_mut; -use data_model::{VolatileSlice, VolatileMemory}; -use sys_util::{Error as SysError, SharedMemory, MemoryMapping, round_up_to_page_size}; +use data_model::{VolatileMemory, VolatileSlice}; +use sys_util::{round_up_to_page_size, Error as SysError, MemoryMapping, SharedMemory}; use dwl::*; @@ -127,18 +127,18 @@ impl GpuDisplay { }, None => return Err(GpuDisplayError::InvalidPath), }; - let setup_success = unsafe { dwl_context_setup(ctx.0, cstr_path.as_ptr() ) }; + let setup_success = unsafe { dwl_context_setup(ctx.0, cstr_path.as_ptr()) }; if !setup_success { return Err(GpuDisplayError::Connect); } Ok(GpuDisplay { - ctx, - dmabufs: Default::default(), - dmabuf_next_id: 0, - surfaces: Default::default(), - surface_next_id: 0, - }) + ctx, + dmabufs: Default::default(), + dmabuf_next_id: 0, + surfaces: Default::default(), + surface_next_id: 0, + }) } fn ctx(&self) -> *mut dwl_context { @@ -150,28 +150,31 @@ impl GpuDisplay { } /// Imports a dmabuf to the compositor for use as a surface buffer and returns a handle to it. - pub fn import_dmabuf(&mut self, - fd: RawFd, - offset: u32, - stride: u32, - modifiers: u64, - width: u32, - height: u32, - fourcc: u32) - -> Result { + pub fn import_dmabuf( + &mut self, + fd: RawFd, + offset: u32, + stride: u32, + modifiers: u64, + width: u32, + height: u32, + fourcc: u32, + ) -> Result { // Safe given that the context pointer is valid. Any other invalid parameters would be // rejected by dwl_context_dmabuf_new safely. We check that the resulting dmabuf is valid // before filing it away. let dmabuf = DwlDmabuf(unsafe { - dwl_context_dmabuf_new(self.ctx(), - fd, - offset, - stride, - modifiers, - width, - height, - fourcc) - }); + dwl_context_dmabuf_new( + self.ctx(), + fd, + offset, + stride, + modifiers, + width, + height, + fourcc, + ) + }); if dmabuf.0.is_null() { return Err(GpuDisplayError::FailedImport); } @@ -198,26 +201,25 @@ impl GpuDisplay { /// Creates a surface on the the compositor as either a top level window, or child of another /// surface, returning a handle to the new surface. - pub fn create_surface(&mut self, - parent_surface_id: Option, - width: u32, - height: u32) - -> Result { + pub fn create_surface( + &mut self, + parent_surface_id: Option, + width: u32, + height: u32, + ) -> Result { let parent_ptr = match parent_surface_id { - Some(id) => { - match self.get_surface(id).map(|p| p.surface()) { - Some(ptr) => ptr, - None => return Err(GpuDisplayError::InvalidSurfaceId), - } - } + Some(id) => match self.get_surface(id).map(|p| p.surface()) { + Some(ptr) => ptr, + None => return Err(GpuDisplayError::InvalidSurfaceId), + }, None => null_mut(), }; let row_size = width * BYTES_PER_PIXEL; let fb_size = row_size * height; let buffer_size = round_up_to_page_size(fb_size as usize * BUFFER_COUNT); - let mut buffer_shm = - SharedMemory::new(Some(CStr::from_bytes_with_nul(b"GpuDisplaySurface\0").unwrap())) - .map_err(GpuDisplayError::CreateShm)?; + let mut buffer_shm = SharedMemory::new(Some( + CStr::from_bytes_with_nul(b"GpuDisplaySurface\0").unwrap(), + )).map_err(GpuDisplayError::CreateShm)?; buffer_shm .set_size(buffer_size as u64) .map_err(GpuDisplayError::SetSize)?; @@ -226,29 +228,32 @@ impl GpuDisplay { // Safe because only a valid context, parent pointer (if not None), and buffer FD are used. // The returned surface is checked for validity before being filed away. let surface = DwlSurface(unsafe { - dwl_context_surface_new(self.ctx(), - parent_ptr, - buffer_shm.as_raw_fd(), - buffer_size, - fb_size as usize, - width, - height, - row_size) - }); + dwl_context_surface_new( + self.ctx(), + parent_ptr, + buffer_shm.as_raw_fd(), + buffer_size, + fb_size as usize, + width, + height, + row_size, + ) + }); if surface.0.is_null() { return Err(GpuDisplayError::CreateSurface); } let next_id = self.surface_next_id; - self.surfaces - .insert(next_id, - GpuDisplaySurface { - surface, - buffer_size: fb_size as usize, - buffer_index: Cell::new(0), - buffer_mem, - }); + self.surfaces.insert( + next_id, + GpuDisplaySurface { + surface, + buffer_size: fb_size as usize, + buffer_index: Cell::new(0), + buffer_mem, + }, + ); self.surface_next_id += 1; Ok(next_id) @@ -265,9 +270,10 @@ impl GpuDisplay { let buffer_index = (surface.buffer_index.get() + 1) % BUFFER_COUNT; surface .buffer_mem - .get_slice((buffer_index * surface.buffer_size) as u64, - surface.buffer_size as u64) - .ok() + .get_slice( + (buffer_index * surface.buffer_size) as u64, + surface.buffer_size as u64, + ).ok() } /// Commits any pending state for the identified surface. @@ -339,11 +345,9 @@ impl GpuDisplay { pub fn close_requested(&self, surface_id: u32) -> bool { match self.get_surface(surface_id) { Some(surface) => - // Safe because only a valid surface is used. - unsafe { - dwl_surface_close_requested(surface.surface()) - }, - None => false + // Safe because only a valid surface is used. + unsafe { dwl_surface_close_requested(surface.surface()) } + None => false, } } -- cgit 1.4.1