diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e8b5fafd..f23489ed 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -70,10 +70,17 @@ jobs: cd surfman rustup component add rust-src --target=aarch64-uwp-windows-msvc cargo build -Z build-std --verbose --target=aarch64-uwp-windows-msvc + Format: + name: Run `rustfmt` + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: mkroening/rust-toolchain-toml@main + - run: cargo fmt --check build_result: name: Result runs-on: ubuntu-latest - needs: ["Build"] + needs: ["Build", "Format"] if: always() steps: - name: Mark the job as successful diff --git a/android-example/rust/src/lib.rs b/android-example/rust/src/lib.rs index e6ac95bc..c791a360 100644 --- a/android-example/rust/src/lib.rs +++ b/android-example/rust/src/lib.rs @@ -167,14 +167,12 @@ impl ResourceLoader for JavaResourceLoader { let loader = self.loader.as_obj(); let mut env = self.vm.get_env().unwrap(); - match env - .call_method( - loader, - "slurp", - "(Ljava/lang/String;)Ljava/nio/ByteBuffer;", - &[JValue::Object(&env.new_string(filename).unwrap())], - ) - { + match env.call_method( + loader, + "slurp", + "(Ljava/lang/String;)Ljava/nio/ByteBuffer;", + &[JValue::Object(&env.new_string(filename).unwrap())], + ) { Ok(JValueGen::Object(object)) => { let byte_buffer = JByteBuffer::from(object); unsafe { @@ -184,7 +182,7 @@ impl ResourceLoader for JavaResourceLoader { ); dest.extend_from_slice(slice); } - }, + } _ => panic!("Unexpected return value!"), } } diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 00000000..5c1dcc5e --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "1.76" +components = [ "rustfmt" ] +profile = "minimal" diff --git a/surfman/examples/chaos_game.rs b/surfman/examples/chaos_game.rs index 96788cce..cae27a57 100644 --- a/surfman/examples/chaos_game.rs +++ b/surfman/examples/chaos_game.rs @@ -6,7 +6,7 @@ use euclid::default::Point2D; use rand::{self, Rng}; use surfman::{SurfaceAccess, SurfaceType}; use winit::dpi::PhysicalSize; -use winit::event::{DeviceEvent, Event, WindowEvent, KeyboardInput, VirtualKeyCode}; +use winit::event::{DeviceEvent, Event, KeyboardInput, VirtualKeyCode, WindowEvent}; use winit::event_loop::{ControlFlow, EventLoop}; use winit::window::WindowBuilder; @@ -53,7 +53,7 @@ fn main() { let window_size = Size2D::new(window_size.width as i32, window_size.height as i32); let handle = window.window_handle().unwrap(); let native_widget = connection - .create_native_widget_from_raw_window_handle(handle.as_raw(), window_size); + .create_native_widget_from_raw_window_handle(handle.as_raw(), window_size) .unwrap(); let surface_type = SurfaceType::Widget { native_widget }; diff --git a/surfman/examples/threads.rs b/surfman/examples/threads.rs index e56816a8..d7f2a75e 100644 --- a/surfman/examples/threads.rs +++ b/surfman/examples/threads.rs @@ -21,7 +21,7 @@ use winit::{ dpi::PhysicalSize, event::{DeviceEvent, Event, WindowEvent}, event_loop::{ControlFlow, EventLoop}, - window::WindowBuilder + window::WindowBuilder, }; #[cfg(feature = "sm-raw-window-handle-05")] @@ -91,24 +91,27 @@ static BACKGROUND_COLOR: [f32; 4] = [ ]; #[cfg(feature = "sm-raw-window-handle-05")] -fn make_connection(window: &winit::window::Window) -> surfman::Connection -{ +fn make_connection(window: &winit::window::Window) -> surfman::Connection { let raw_display_handle = window.raw_display_handle(); let connection = Connection::from_raw_display_handle(raw_display_handle).unwrap(); connection } #[cfg(not(feature = "sm-raw-window-handle-05"))] -fn make_connection(window: &winit::window::Window) -> surfman::Connection -{ - let display_handle = window.display_handle().expect("failed to get display handle from window"); +fn make_connection(window: &winit::window::Window) -> surfman::Connection { + let display_handle = window + .display_handle() + .expect("failed to get display handle from window"); let connection = Connection::from_display_handle(display_handle).unwrap(); connection } #[cfg(feature = "sm-raw-window-handle-05")] -fn make_native_widget(window: &winit::window::Window, connection: &surfman::Connection, window_size: Size2D) -> surfman::NativeWidget -{ +fn make_native_widget( + window: &winit::window::Window, + connection: &surfman::Connection, + window_size: Size2D, +) -> surfman::NativeWidget { let raw_window_handle = window.raw_window_handle(); let native_widget = connection .create_native_widget_from_raw_window_handle(raw_window_handle, window_size) @@ -117,9 +120,14 @@ fn make_native_widget(window: &winit::window::Window, connection: &surfman::Conn } #[cfg(not(feature = "sm-raw-window-handle-05"))] -fn make_native_widget(window: &winit::window::Window, connection: &surfman::Connection, window_size: Size2D) -> surfman::NativeWidget -{ - let raw_window_handle = window.window_handle().expect("couldn't get window handle from window"); +fn make_native_widget( + window: &winit::window::Window, + connection: &surfman::Connection, + window_size: Size2D, +) -> surfman::NativeWidget { + let raw_window_handle = window + .window_handle() + .expect("couldn't get window handle from window"); let native_widget = connection .create_native_widget_from_window_handle(raw_window_handle, window_size) .unwrap(); @@ -128,7 +136,10 @@ fn make_native_widget(window: &winit::window::Window, connection: &surfman::Conn #[cfg(not(target_os = "android"))] fn main() { - use winit::{event::RawKeyEvent, keyboard::{KeyCode, PhysicalKey}}; + use winit::{ + event::RawKeyEvent, + keyboard::{KeyCode, PhysicalKey}, + }; let event_loop = EventLoop::new().expect("couldn't create eventloop"); let window_size = Size2D::new(WINDOW_WIDTH, WINDOW_HEIGHT); @@ -177,22 +188,26 @@ fn main() { window_size, ); - event_loop.run(move |event, target| match event { - Event::WindowEvent { - event: WindowEvent::CloseRequested, - .. - } - | Event::DeviceEvent { - event: - DeviceEvent::Key(RawKeyEvent { - physical_key: PhysicalKey::Code(KeyCode::Escape), - .. - }), - .. - } => target.exit(), - _ => { app.tick(true); target.set_control_flow(ControlFlow::Poll) } - }).expect("failed to run event loop"); - + event_loop + .run(move |event, target| match event { + Event::WindowEvent { + event: WindowEvent::CloseRequested, + .. + } + | Event::DeviceEvent { + event: + DeviceEvent::Key(RawKeyEvent { + physical_key: PhysicalKey::Code(KeyCode::Escape), + .. + }), + .. + } => target.exit(), + _ => { + app.tick(true); + target.set_control_flow(ControlFlow::Poll) + } + }) + .expect("failed to run event loop"); } pub struct App { main_from_worker_receiver: Receiver, @@ -213,7 +228,6 @@ impl Drop for App { } impl App { - pub fn new( connection: Connection, adapter: Adapter, diff --git a/surfman/src/chains.rs b/surfman/src/chains.rs index a2d683cb..d2366c5e 100644 --- a/surfman/src/chains.rs +++ b/surfman/src/chains.rs @@ -22,8 +22,8 @@ #![allow(missing_docs)] -use crate::{ContextID, Error, SurfaceAccess, SurfaceInfo, SurfaceType}; use crate::device::Device as DeviceAPI; +use crate::{ContextID, Error, SurfaceAccess, SurfaceInfo, SurfaceType}; use euclid::default::Size2D; use fnv::{FnvHashMap, FnvHashSet}; use log::debug; diff --git a/surfman/src/connection.rs b/surfman/src/connection.rs index b93e1968..b89216f6 100644 --- a/surfman/src/connection.rs +++ b/surfman/src/connection.rs @@ -56,15 +56,11 @@ pub trait Connection: Sized { /// Opens the display connection corresponding to the given `RawDisplayHandle`. #[cfg(feature = "sm-raw-window-handle-05")] - fn from_raw_display_handle( - raw_handle: rwh_05::RawDisplayHandle, - ) -> Result; + fn from_raw_display_handle(raw_handle: rwh_05::RawDisplayHandle) -> Result; /// Opens the display connection corresponding to the given `DisplayHandle`. #[cfg(feature = "sm-raw-window-handle-06")] - fn from_display_handle( - handle: rwh_06::DisplayHandle, - ) -> Result; + fn from_display_handle(handle: rwh_06::DisplayHandle) -> Result; /// Creates a native widget from a raw pointer unsafe fn create_native_widget_from_ptr( diff --git a/surfman/src/implementation/connection.rs b/surfman/src/implementation/connection.rs index e6d99851..7324dc7b 100644 --- a/surfman/src/implementation/connection.rs +++ b/surfman/src/implementation/connection.rs @@ -72,17 +72,13 @@ impl ConnectionInterface for Connection { #[inline] #[cfg(feature = "sm-raw-window-handle-05")] - fn from_raw_display_handle( - raw_handle: rwh_05::RawDisplayHandle, - ) -> Result { + fn from_raw_display_handle(raw_handle: rwh_05::RawDisplayHandle) -> Result { Connection::from_raw_display_handle(raw_handle) } #[inline] #[cfg(feature = "sm-raw-window-handle-06")] - fn from_display_handle( - handle: rwh_06::DisplayHandle, - ) -> Result { + fn from_display_handle(handle: rwh_06::DisplayHandle) -> Result { Connection::from_display_handle(handle) } diff --git a/surfman/src/platform/android/connection.rs b/surfman/src/platform/android/connection.rs index d574b1ef..1fa8ef41 100644 --- a/surfman/src/platform/android/connection.rs +++ b/surfman/src/platform/android/connection.rs @@ -99,17 +99,13 @@ impl Connection { /// Opens the display connection corresponding to the given raw display handle. #[cfg(feature = "sm-raw-window-handle-05")] - pub fn from_raw_display_handle( - _: rwh_05::RawDisplayHandle, - ) -> Result { + pub fn from_raw_display_handle(_: rwh_05::RawDisplayHandle) -> Result { Ok(Connection) } /// Opens the display connection corresponding to the given `DisplayHandle`. #[cfg(feature = "sm-raw-window-handle-06")] - pub fn from_display_handle( - _: rwh_06::DisplayHandle, - ) -> Result { + pub fn from_display_handle(_: rwh_06::DisplayHandle) -> Result { Ok(Connection) } diff --git a/surfman/src/platform/android/context.rs b/surfman/src/platform/android/context.rs index 57048b43..6ca26840 100644 --- a/surfman/src/platform/android/context.rs +++ b/surfman/src/platform/android/context.rs @@ -316,11 +316,17 @@ impl Device { context::get_proc_address(symbol_name) } - pub(crate) fn context_to_egl_config( - &self, - context: &Context, - ) -> EGLConfig { - unsafe { context::egl_config_from_id(self.egl_display, context::get_context_attr(self.egl_display, context.egl_context, egl::CONFIG_ID as EGLint)) } + pub(crate) fn context_to_egl_config(&self, context: &Context) -> EGLConfig { + unsafe { + context::egl_config_from_id( + self.egl_display, + context::get_context_attr( + self.egl_display, + context.egl_context, + egl::CONFIG_ID as EGLint, + ), + ) + } } pub(crate) fn temporarily_make_context_current( diff --git a/surfman/src/platform/generic/multi/connection.rs b/surfman/src/platform/generic/multi/connection.rs index d128dfaf..87b777bb 100644 --- a/surfman/src/platform/generic/multi/connection.rs +++ b/surfman/src/platform/generic/multi/connection.rs @@ -199,9 +199,7 @@ where ) -> Result, Error> { match ::from_display_handle(handle) { Ok(connection) => Ok(Connection::Default(connection)), - Err(_) => { - ::from_display_handle(handle).map(Connection::Alternate) - } + Err(_) => ::from_display_handle(handle).map(Connection::Alternate), } } @@ -325,9 +323,7 @@ where } #[cfg(feature = "sm-raw-window-handle-06")] - fn from_display_handle( - handle: rwh_06::DisplayHandle, - ) -> Result, Error> { + fn from_display_handle(handle: rwh_06::DisplayHandle) -> Result, Error> { Connection::from_display_handle(handle) } diff --git a/surfman/src/platform/macos/cgl/connection.rs b/surfman/src/platform/macos/cgl/connection.rs index 35b7f236..de364250 100644 --- a/surfman/src/platform/macos/cgl/connection.rs +++ b/surfman/src/platform/macos/cgl/connection.rs @@ -154,7 +154,7 @@ impl Connection { AppKit(handle) => { let ns_view = handle.ns_view.as_ptr() as id; // https://developer.apple.com/documentation/appkit/nsview/1483301-window - let ns_window: id = unsafe{ msg_send![ns_view, window] }; + let ns_window: id = unsafe { msg_send![ns_view, window] }; Ok(NativeWidget { // Increment the nsview's reference count with retain. See: // https://developer.apple.com/documentation/objectivec/1418956-nsobject/1571946-retain diff --git a/surfman/src/platform/macos/system/connection.rs b/surfman/src/platform/macos/system/connection.rs index 77ea6ded..22f3d16e 100644 --- a/surfman/src/platform/macos/system/connection.rs +++ b/surfman/src/platform/macos/system/connection.rs @@ -120,17 +120,13 @@ impl Connection { /// Opens the display connection corresponding to the given `RawDisplayHandle`. #[cfg(feature = "sm-raw-window-handle-05")] - pub fn from_raw_display_handle( - _: rwh_05::RawDisplayHandle, - ) -> Result { + pub fn from_raw_display_handle(_: rwh_05::RawDisplayHandle) -> Result { Connection::new() } /// Opens the display connection corresponding to the given `DisplayHandle`. #[cfg(feature = "sm-raw-window-handle-06")] - pub fn from_display_handle( - _: rwh_06::DisplayHandle, - ) -> Result { + pub fn from_display_handle(_: rwh_06::DisplayHandle) -> Result { Connection::new() } @@ -179,7 +175,7 @@ impl Connection { AppKit(handle) => { let ns_view = handle.ns_view.as_ptr() as id; // https://developer.apple.com/documentation/appkit/nsview/1483301-window - let ns_window: id = unsafe{ msg_send![ns_view, window] }; + let ns_window: id = unsafe { msg_send![ns_view, window] }; Ok(NativeWidget { // Increment the nsview's reference count with retain. See: // https://developer.apple.com/documentation/objectivec/1418956-nsobject/1571946-retain diff --git a/surfman/src/platform/unix/generic/connection.rs b/surfman/src/platform/unix/generic/connection.rs index d5b4521d..b4c050ab 100644 --- a/surfman/src/platform/unix/generic/connection.rs +++ b/surfman/src/platform/unix/generic/connection.rs @@ -136,17 +136,13 @@ impl Connection { /// Opens the display connection corresponding to the given `RawDisplayHandle`. #[cfg(feature = "sm-raw-window-handle-05")] - pub fn from_raw_display_handle( - _: rwh_05::RawDisplayHandle, - ) -> Result { + pub fn from_raw_display_handle(_: rwh_05::RawDisplayHandle) -> Result { Err(Error::IncompatibleNativeWidget) } /// Opens the display connection corresponding to the given `DisplayHandle`. #[cfg(feature = "sm-raw-window-handle-06")] - pub fn from_display_handle( - _: rwh_06::DisplayHandle, - ) -> Result { + pub fn from_display_handle(_: rwh_06::DisplayHandle) -> Result { Err(Error::IncompatibleNativeWidget) } diff --git a/surfman/src/platform/unix/wayland/connection.rs b/surfman/src/platform/unix/wayland/connection.rs index ca59dda9..fb13bc61 100644 --- a/surfman/src/platform/unix/wayland/connection.rs +++ b/surfman/src/platform/unix/wayland/connection.rs @@ -175,14 +175,14 @@ impl Connection { /// Opens the display connection corresponding to the given `DisplayHandle`. #[cfg(feature = "sm-raw-window-handle-06")] - pub fn from_display_handle( - handle: rwh_06::DisplayHandle, - ) -> Result { + pub fn from_display_handle(handle: rwh_06::DisplayHandle) -> Result { use rwh_06::RawDisplayHandle::Wayland; use rwh_06::WaylandDisplayHandle; unsafe { let wayland_display = match handle.as_raw() { - Wayland(WaylandDisplayHandle { display, .. }) => display.as_ptr() as *mut wl_display, + Wayland(WaylandDisplayHandle { display, .. }) => { + display.as_ptr() as *mut wl_display + } _ => return Err(Error::IncompatibleRawDisplayHandle), }; diff --git a/surfman/src/platform/unix/x11/connection.rs b/surfman/src/platform/unix/x11/connection.rs index 0b684c13..bebb434a 100644 --- a/surfman/src/platform/unix/x11/connection.rs +++ b/surfman/src/platform/unix/x11/connection.rs @@ -206,9 +206,7 @@ impl Connection { /// Opens the display connection corresponding to the given `DisplayHandle`. #[cfg(feature = "sm-raw-window-handle-06")] - pub fn from_display_handle( - handle: rwh_06::DisplayHandle, - ) -> Result { + pub fn from_display_handle(handle: rwh_06::DisplayHandle) -> Result { use rwh_06::RawDisplayHandle::Xcb; use rwh_06::RawDisplayHandle::Xlib; use rwh_06::XlibDisplayHandle; diff --git a/surfman/src/platform/windows/angle/connection.rs b/surfman/src/platform/windows/angle/connection.rs index be0fa18f..a4015825 100644 --- a/surfman/src/platform/windows/angle/connection.rs +++ b/surfman/src/platform/windows/angle/connection.rs @@ -130,17 +130,13 @@ impl Connection { /// Opens the display connection corresponding to the given `RawDisplayHandle`. #[cfg(feature = "sm-raw-window-handle-05")] - pub fn from_raw_display_handle( - _: rwh_05::RawDisplayHandle, - ) -> Result { + pub fn from_raw_display_handle(_: rwh_05::RawDisplayHandle) -> Result { Connection::new() } /// Opens the display connection corresponding to the given `DisplayHandle`. #[cfg(feature = "sm-raw-window-handle-06")] - pub fn from_display_handle( - _: rwh_06::DisplayHandle, - ) -> Result { + pub fn from_display_handle(_: rwh_06::DisplayHandle) -> Result { Connection::new() } diff --git a/surfman/src/platform/windows/angle/device.rs b/surfman/src/platform/windows/angle/device.rs index 29ebde4a..ea8e7c42 100644 --- a/surfman/src/platform/windows/angle/device.rs +++ b/surfman/src/platform/windows/angle/device.rs @@ -4,11 +4,11 @@ use super::connection::Connection; use crate::egl; -use crate::egl::types::{EGLAttrib, EGLDisplay, EGLint, EGLDeviceEXT}; +use crate::egl::types::{EGLAttrib, EGLDeviceEXT, EGLDisplay, EGLint}; use crate::platform::generic::egl::device::EGL_FUNCTIONS; +use crate::platform::generic::egl::ffi::EGL_DEVICE_EXT; use crate::platform::generic::egl::ffi::{EGL_D3D11_DEVICE_ANGLE, EGL_EXTENSION_FUNCTIONS}; use crate::platform::generic::egl::ffi::{EGL_NO_DEVICE_EXT, EGL_PLATFORM_DEVICE_EXT}; -use crate::platform::generic::egl::ffi::{EGL_DEVICE_EXT}; use crate::{Error, GLApi}; use std::cell::{RefCell, RefMut}; @@ -186,9 +186,9 @@ impl Device { debug_assert!(d3d11_feature_level >= D3D_FEATURE_LEVEL_9_3); let d3d11_device = ComPtr::from_raw(d3d11_device); - let eglCreateDeviceANGLE = EGL_EXTENSION_FUNCTIONS.CreateDeviceANGLE.expect( - "Where's the `EGL_ANGLE_device_creation` extension?", - ); + let eglCreateDeviceANGLE = EGL_EXTENSION_FUNCTIONS + .CreateDeviceANGLE + .expect("Where's the `EGL_ANGLE_device_creation` extension?"); let egl_device = eglCreateDeviceANGLE( EGL_D3D11_DEVICE_ANGLE as EGLint, d3d11_device.as_raw() as *mut c_void, @@ -234,27 +234,26 @@ impl Device { #[allow(non_snake_case)] pub(crate) fn from_egl_display(egl_display: EGLDisplay) -> Result { - - let eglQueryDisplayAttribEXT = EGL_EXTENSION_FUNCTIONS.QueryDisplayAttribEXT.expect( - "Where's the `EGL_EXT_device_query` extension?" - ); - let eglQueryDeviceAttribEXT = EGL_EXTENSION_FUNCTIONS.QueryDeviceAttribEXT.expect( - "Where's the `EGL_EXT_device_query` extension?" - ); - let mut angle_device : EGLAttrib = 0; + let eglQueryDisplayAttribEXT = EGL_EXTENSION_FUNCTIONS + .QueryDisplayAttribEXT + .expect("Where's the `EGL_EXT_device_query` extension?"); + let eglQueryDeviceAttribEXT = EGL_EXTENSION_FUNCTIONS + .QueryDeviceAttribEXT + .expect("Where's the `EGL_EXT_device_query` extension?"); + let mut angle_device: EGLAttrib = 0; let result = eglQueryDisplayAttribEXT( egl_display, EGL_DEVICE_EXT as EGLint, - &mut angle_device as *mut EGLAttrib + &mut angle_device as *mut EGLAttrib, ); if result == egl::FALSE { return Err(Error::DeviceOpenFailed); } - let mut device : EGLAttrib = 0; + let mut device: EGLAttrib = 0; let result = eglQueryDeviceAttribEXT( angle_device as EGLDeviceEXT, EGL_D3D11_DEVICE_ANGLE as EGLint, - &mut device as *mut EGLAttrib + &mut device as *mut EGLAttrib, ); if result == egl::FALSE { return Err(Error::DeviceOpenFailed); diff --git a/surfman/src/platform/windows/wgl/connection.rs b/surfman/src/platform/windows/wgl/connection.rs index eae675dc..17ccbe58 100644 --- a/surfman/src/platform/windows/wgl/connection.rs +++ b/surfman/src/platform/windows/wgl/connection.rs @@ -101,17 +101,13 @@ impl Connection { /// Opens the display connection corresponding to the given `RawDisplayHandle`. #[cfg(feature = "sm-raw-window-handle-05")] - pub fn from_raw_display_handle( - _: rwh_05::RawDisplayHandle, - ) -> Result { + pub fn from_raw_display_handle(_: rwh_05::RawDisplayHandle) -> Result { Connection::new() } /// Opens the display connection corresponding to the given `DisplayHandle`. #[cfg(feature = "sm-raw-window-handle-06")] - pub fn from_display_handle( - _: rwh_06::DisplayHandle, - ) -> Result { + pub fn from_display_handle(_: rwh_06::DisplayHandle) -> Result { Connection::new() }