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

Reformat code with cargo fmt #279

Merged
merged 4 commits into from
Mar 18, 2024
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
9 changes: 8 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 7 additions & 9 deletions android-example/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -184,7 +182,7 @@ impl ResourceLoader for JavaResourceLoader {
);
dest.extend_from_slice(slice);
}
},
}
_ => panic!("Unexpected return value!"),
}
}
Expand Down
4 changes: 4 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[toolchain]
channel = "1.76"
components = [ "rustfmt" ]
profile = "minimal"
4 changes: 2 additions & 2 deletions surfman/examples/chaos_game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 };
Expand Down
72 changes: 43 additions & 29 deletions surfman/examples/threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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<i32>) -> surfman::NativeWidget
{
fn make_native_widget(
window: &winit::window::Window,
connection: &surfman::Connection,
window_size: Size2D<i32>,
) -> 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)
Expand All @@ -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<i32>) -> 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<i32>,
) -> 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();
Expand All @@ -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);
Expand Down Expand Up @@ -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<Frame>,
Expand All @@ -213,7 +228,6 @@ impl Drop for App {
}

impl App {

pub fn new(
connection: Connection,
adapter: Adapter,
Expand Down
2 changes: 1 addition & 1 deletion surfman/src/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 2 additions & 6 deletions surfman/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self, Error>;
fn from_raw_display_handle(raw_handle: rwh_05::RawDisplayHandle) -> Result<Self, Error>;

/// 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<Self, Error>;
fn from_display_handle(handle: rwh_06::DisplayHandle) -> Result<Self, Error>;

/// Creates a native widget from a raw pointer
unsafe fn create_native_widget_from_ptr(
Expand Down
8 changes: 2 additions & 6 deletions surfman/src/implementation/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Connection, Error> {
fn from_raw_display_handle(raw_handle: rwh_05::RawDisplayHandle) -> Result<Connection, Error> {
Connection::from_raw_display_handle(raw_handle)
}

#[inline]
#[cfg(feature = "sm-raw-window-handle-06")]
fn from_display_handle(
handle: rwh_06::DisplayHandle,
) -> Result<Connection, Error> {
fn from_display_handle(handle: rwh_06::DisplayHandle) -> Result<Connection, Error> {
Connection::from_display_handle(handle)
}

Expand Down
8 changes: 2 additions & 6 deletions surfman/src/platform/android/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Connection, Error> {
pub fn from_raw_display_handle(_: rwh_05::RawDisplayHandle) -> Result<Connection, Error> {
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<Connection, Error> {
pub fn from_display_handle(_: rwh_06::DisplayHandle) -> Result<Connection, Error> {
Ok(Connection)
}

Expand Down
16 changes: 11 additions & 5 deletions surfman/src/platform/android/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 2 additions & 6 deletions surfman/src/platform/generic/multi/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,7 @@ where
) -> Result<Connection<Def, Alt>, Error> {
match <Def::Connection>::from_display_handle(handle) {
Ok(connection) => Ok(Connection::Default(connection)),
Err(_) => {
<Alt::Connection>::from_display_handle(handle).map(Connection::Alternate)
}
Err(_) => <Alt::Connection>::from_display_handle(handle).map(Connection::Alternate),
}
}

Expand Down Expand Up @@ -325,9 +323,7 @@ where
}

#[cfg(feature = "sm-raw-window-handle-06")]
fn from_display_handle(
handle: rwh_06::DisplayHandle,
) -> Result<Connection<Def, Alt>, Error> {
fn from_display_handle(handle: rwh_06::DisplayHandle) -> Result<Connection<Def, Alt>, Error> {
Connection::from_display_handle(handle)
}

Expand Down
2 changes: 1 addition & 1 deletion surfman/src/platform/macos/cgl/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions surfman/src/platform/macos/system/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Connection, Error> {
pub fn from_raw_display_handle(_: rwh_05::RawDisplayHandle) -> Result<Connection, Error> {
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<Connection, Error> {
pub fn from_display_handle(_: rwh_06::DisplayHandle) -> Result<Connection, Error> {
Connection::new()
}

Expand Down Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions surfman/src/platform/unix/generic/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Connection, Error> {
pub fn from_raw_display_handle(_: rwh_05::RawDisplayHandle) -> Result<Connection, Error> {
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<Connection, Error> {
pub fn from_display_handle(_: rwh_06::DisplayHandle) -> Result<Connection, Error> {
Err(Error::IncompatibleNativeWidget)
}

Expand Down
8 changes: 4 additions & 4 deletions surfman/src/platform/unix/wayland/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Connection, Error> {
pub fn from_display_handle(handle: rwh_06::DisplayHandle) -> Result<Connection, Error> {
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),
};

Expand Down
4 changes: 1 addition & 3 deletions surfman/src/platform/unix/x11/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Connection, Error> {
pub fn from_display_handle(handle: rwh_06::DisplayHandle) -> Result<Connection, Error> {
use rwh_06::RawDisplayHandle::Xcb;
use rwh_06::RawDisplayHandle::Xlib;
use rwh_06::XlibDisplayHandle;
Expand Down
Loading