From ea62e1e1124d93b647aa205411e59c54ccb192fc Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Sun, 11 Feb 2024 21:26:16 -0800 Subject: [PATCH] Move backends into a `backends` module --- src/backend_dispatch.rs | 16 +++++----- src/{ => backends}/cg.rs | 0 src/{ => backends}/kms.rs | 0 src/backends/mod.rs | 14 ++++++++ src/{ => backends}/orbital.rs | 0 src/{ => backends}/wayland/buffer.rs | 0 src/{ => backends}/wayland/mod.rs | 0 src/{ => backends}/web.rs | 2 +- src/{ => backends}/win32.rs | 0 src/{ => backends}/x11.rs | 0 src/lib.rs | 48 ++++++++++------------------ 11 files changed, 40 insertions(+), 40 deletions(-) rename src/{ => backends}/cg.rs (100%) rename src/{ => backends}/kms.rs (100%) create mode 100644 src/backends/mod.rs rename src/{ => backends}/orbital.rs (100%) rename src/{ => backends}/wayland/buffer.rs (100%) rename src/{ => backends}/wayland/mod.rs (100%) rename src/{ => backends}/web.rs (99%) rename src/{ => backends}/win32.rs (100%) rename src/{ => backends}/x11.rs (100%) diff --git a/src/backend_dispatch.rs b/src/backend_dispatch.rs index 825d08ef..01c25c1b 100644 --- a/src/backend_dispatch.rs +++ b/src/backend_dispatch.rs @@ -1,6 +1,6 @@ //! Implements `buffer_interface::*` traits for enums dispatching to backends -use crate::{backend_interface::*, Rect, SoftBufferError}; +use crate::{backend_interface::*, backends, Rect, SoftBufferError}; use raw_window_handle::{HasDisplayHandle, HasWindowHandle}; use std::num::NonZeroU32; @@ -146,17 +146,17 @@ macro_rules! make_dispatch { make_dispatch! { => #[cfg(x11_platform)] - X11(Rc>, crate::x11::X11Impl, crate::x11::BufferImpl<'a, D, W>), + X11(Rc>, backends::x11::X11Impl, backends::x11::BufferImpl<'a, D, W>), #[cfg(wayland_platform)] - Wayland(Rc>, crate::wayland::WaylandImpl, crate::wayland::BufferImpl<'a, D, W>), + Wayland(Rc>, backends::wayland::WaylandImpl, backends::wayland::BufferImpl<'a, D, W>), #[cfg(kms_platform)] - Kms(Rc>, crate::kms::KmsImpl, crate::kms::BufferImpl<'a, D, W>), + Kms(Rc>, backends::kms::KmsImpl, backends::kms::BufferImpl<'a, D, W>), #[cfg(target_os = "windows")] - Win32(D, crate::win32::Win32Impl, crate::win32::BufferImpl<'a, D, W>), + Win32(D, backends::win32::Win32Impl, backends::win32::BufferImpl<'a, D, W>), #[cfg(target_os = "macos")] - CG(D, crate::cg::CGImpl, crate::cg::BufferImpl<'a, D, W>), + CG(D, backends::cg::CGImpl, backends::cg::BufferImpl<'a, D, W>), #[cfg(target_arch = "wasm32")] - Web(crate::web::WebDisplayImpl, crate::web::WebImpl, crate::web::BufferImpl<'a, D, W>), + Web(backends::web::WebDisplayImpl, backends::web::WebImpl, backends::web::BufferImpl<'a, D, W>), #[cfg(target_os = "redox")] - Orbital(D, crate::orbital::OrbitalImpl, crate::orbital::BufferImpl<'a, D, W>), + Orbital(D, backends::orbital::OrbitalImpl, backends::orbital::BufferImpl<'a, D, W>), } diff --git a/src/cg.rs b/src/backends/cg.rs similarity index 100% rename from src/cg.rs rename to src/backends/cg.rs diff --git a/src/kms.rs b/src/backends/kms.rs similarity index 100% rename from src/kms.rs rename to src/backends/kms.rs diff --git a/src/backends/mod.rs b/src/backends/mod.rs new file mode 100644 index 00000000..35bc66ef --- /dev/null +++ b/src/backends/mod.rs @@ -0,0 +1,14 @@ +#[cfg(target_os = "macos")] +pub(crate) mod cg; +#[cfg(kms_platform)] +pub(crate) mod kms; +#[cfg(target_os = "redox")] +pub(crate) mod orbital; +#[cfg(wayland_platform)] +pub(crate) mod wayland; +#[cfg(target_arch = "wasm32")] +pub(crate) mod web; +#[cfg(target_os = "windows")] +pub(crate) mod win32; +#[cfg(x11_platform)] +pub(crate) mod x11; diff --git a/src/orbital.rs b/src/backends/orbital.rs similarity index 100% rename from src/orbital.rs rename to src/backends/orbital.rs diff --git a/src/wayland/buffer.rs b/src/backends/wayland/buffer.rs similarity index 100% rename from src/wayland/buffer.rs rename to src/backends/wayland/buffer.rs diff --git a/src/wayland/mod.rs b/src/backends/wayland/mod.rs similarity index 100% rename from src/wayland/mod.rs rename to src/backends/wayland/mod.rs diff --git a/src/web.rs b/src/backends/web.rs similarity index 99% rename from src/web.rs rename to src/backends/web.rs index 66fc18c0..5b631a80 100644 --- a/src/web.rs +++ b/src/backends/web.rs @@ -25,7 +25,7 @@ pub struct WebDisplayImpl { } impl WebDisplayImpl { - pub(super) fn new(display: D) -> Result> { + pub(crate) fn new(display: D) -> Result> { let raw = display.display_handle()?.as_raw(); match raw { RawDisplayHandle::Web(..) => {} diff --git a/src/win32.rs b/src/backends/win32.rs similarity index 100% rename from src/win32.rs rename to src/backends/win32.rs diff --git a/src/x11.rs b/src/backends/x11.rs similarity index 100% rename from src/x11.rs rename to src/backends/x11.rs diff --git a/src/lib.rs b/src/lib.rs index f23b5cec..ec298538 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,25 +8,11 @@ extern crate objc; extern crate core; -#[cfg(target_os = "macos")] -mod cg; -#[cfg(kms_platform)] -mod kms; -#[cfg(target_os = "redox")] -mod orbital; -#[cfg(wayland_platform)] -mod wayland; -#[cfg(target_arch = "wasm32")] -mod web; -#[cfg(target_os = "windows")] -mod win32; -#[cfg(x11_platform)] -mod x11; - mod backend_dispatch; use backend_dispatch::*; mod backend_interface; use backend_interface::*; +mod backends; mod error; mod util; @@ -42,7 +28,7 @@ pub use error::SoftBufferError; use raw_window_handle::{HasDisplayHandle, HasWindowHandle, RawDisplayHandle, RawWindowHandle}; #[cfg(target_arch = "wasm32")] -pub use self::web::SurfaceExtWeb; +pub use backends::web::SurfaceExtWeb; /// An instance of this struct contains the platform-specific data that must be managed in order to /// write to a window on that platform. @@ -73,17 +59,17 @@ impl Context { } #[cfg(x11_platform)] - try_init!(X11, display => x11::X11DisplayImpl::new(display).map(Rc::new)); + try_init!(X11, display => backends::x11::X11DisplayImpl::new(display).map(Rc::new)); #[cfg(wayland_platform)] - try_init!(Wayland, display => wayland::WaylandDisplayImpl::new(display).map(Rc::new)); + try_init!(Wayland, display => backends::wayland::WaylandDisplayImpl::new(display).map(Rc::new)); #[cfg(kms_platform)] - try_init!(Kms, display => kms::KmsDisplayImpl::new(display).map(Rc::new)); + try_init!(Kms, display => backends::kms::KmsDisplayImpl::new(display).map(Rc::new)); #[cfg(target_os = "windows")] try_init!(Win32, display => Ok(display)); #[cfg(target_os = "macos")] try_init!(CG, display => Ok(display)); #[cfg(target_arch = "wasm32")] - try_init!(Web, display => web::WebDisplayImpl::new(display)); + try_init!(Web, display => backends::web::WebDisplayImpl::new(display)); #[cfg(target_os = "redox")] try_init!(Orbital, display => Ok(display)); @@ -139,30 +125,30 @@ impl Surface { let imple = match &context.context_impl { #[cfg(x11_platform)] - ContextDispatch::X11(xcb_display_handle) => { - SurfaceDispatch::X11(leap!(x11::X11Impl::new(window, xcb_display_handle.clone()))) - } + ContextDispatch::X11(xcb_display_handle) => SurfaceDispatch::X11(leap!( + backends::x11::X11Impl::new(window, xcb_display_handle.clone()) + )), #[cfg(wayland_platform)] ContextDispatch::Wayland(wayland_display_impl) => SurfaceDispatch::Wayland(leap!( - wayland::WaylandImpl::new(window, wayland_display_impl.clone()) + backends::wayland::WaylandImpl::new(window, wayland_display_impl.clone()) )), #[cfg(kms_platform)] - ContextDispatch::Kms(kms_display_impl) => { - SurfaceDispatch::Kms(leap!(kms::KmsImpl::new(window, kms_display_impl.clone()))) - } + ContextDispatch::Kms(kms_display_impl) => SurfaceDispatch::Kms(leap!( + backends::kms::KmsImpl::new(window, kms_display_impl.clone()) + )), #[cfg(target_os = "windows")] ContextDispatch::Win32(_) => { - SurfaceDispatch::Win32(leap!(win32::Win32Impl::new(window))) + SurfaceDispatch::Win32(leap!(backends::win32::Win32Impl::new(window))) } #[cfg(target_os = "macos")] - ContextDispatch::CG(_) => SurfaceDispatch::CG(leap!(cg::CGImpl::new(window))), + ContextDispatch::CG(_) => SurfaceDispatch::CG(leap!(backends::cg::CGImpl::new(window))), #[cfg(target_arch = "wasm32")] ContextDispatch::Web(web_display_impl) => { - SurfaceDispatch::Web(leap!(web::WebImpl::new(web_display_impl, window))) + SurfaceDispatch::Web(leap!(backends::web::WebImpl::new(web_display_impl, window))) } #[cfg(target_os = "redox")] ContextDispatch::Orbital(_) => { - SurfaceDispatch::Orbital(leap!(orbital::OrbitalImpl::new(window))) + SurfaceDispatch::Orbital(leap!(backends::orbital::OrbitalImpl::new(window))) } };