Skip to content

Commit

Permalink
Move backends into a backends module
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 committed Feb 13, 2024
1 parent 878d51c commit c0ff669
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 40 deletions.
16 changes: 8 additions & 8 deletions src/backend_dispatch.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -146,17 +146,17 @@ macro_rules! make_dispatch {
make_dispatch! {
<D, W> =>
#[cfg(x11_platform)]
X11(Rc<crate::x11::X11DisplayImpl<D>>, crate::x11::X11Impl<D, W>, crate::x11::BufferImpl<'a, D, W>),
X11(Rc<backends::x11::X11DisplayImpl<D>>, backends::x11::X11Impl<D, W>, backends::x11::BufferImpl<'a, D, W>),
#[cfg(wayland_platform)]
Wayland(Rc<crate::wayland::WaylandDisplayImpl<D>>, crate::wayland::WaylandImpl<D, W>, crate::wayland::BufferImpl<'a, D, W>),
Wayland(Rc<backends::wayland::WaylandDisplayImpl<D>>, backends::wayland::WaylandImpl<D, W>, backends::wayland::BufferImpl<'a, D, W>),
#[cfg(kms_platform)]
Kms(Rc<crate::kms::KmsDisplayImpl<D>>, crate::kms::KmsImpl<D, W>, crate::kms::BufferImpl<'a, D, W>),
Kms(Rc<backends::kms::KmsDisplayImpl<D>>, backends::kms::KmsImpl<D, W>, backends::kms::BufferImpl<'a, D, W>),
#[cfg(target_os = "windows")]
Win32(D, crate::win32::Win32Impl<D, W>, crate::win32::BufferImpl<'a, D, W>),
Win32(D, backends::win32::Win32Impl<D, W>, backends::win32::BufferImpl<'a, D, W>),
#[cfg(target_os = "macos")]
CG(D, crate::cg::CGImpl<D, W>, crate::cg::BufferImpl<'a, D, W>),
CG(D, backends::cg::CGImpl<D, W>, backends::cg::BufferImpl<'a, D, W>),
#[cfg(target_arch = "wasm32")]
Web(crate::web::WebDisplayImpl<D>, crate::web::WebImpl<D, W>, crate::web::BufferImpl<'a, D, W>),
Web(backends::web::WebDisplayImpl<D>, backends::web::WebImpl<D, W>, backends::web::BufferImpl<'a, D, W>),
#[cfg(target_os = "redox")]
Orbital(D, crate::orbital::OrbitalImpl<D, W>, crate::orbital::BufferImpl<'a, D, W>),
Orbital(D, backends::orbital::OrbitalImpl<D, W>, backends::orbital::BufferImpl<'a, D, W>),
}
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions src/backends/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/web.rs → src/backends/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct WebDisplayImpl<D> {
}

impl<D: HasDisplayHandle> WebDisplayImpl<D> {
pub(super) fn new(display: D) -> Result<Self, InitError<D>> {
pub(crate) fn new(display: D) -> Result<Self, InitError<D>> {
let raw = display.display_handle()?.as_raw();
match raw {
RawDisplayHandle::Web(..) => {}
Expand Down
File renamed without changes.
File renamed without changes.
48 changes: 17 additions & 31 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.
Expand Down Expand Up @@ -73,17 +59,17 @@ impl<D: HasDisplayHandle> Context<D> {
}

#[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));

Expand Down Expand Up @@ -139,30 +125,30 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> Surface<D, W> {

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)))
}
};

Expand Down

0 comments on commit c0ff669

Please sign in to comment.