Rename SwBufError back to SoftBufferError
This seems to be the last thing left over from the `swbuf` rename.
This commit is contained in:
parent
0109b1538a
commit
fc1bba64ab
8 changed files with 37 additions and 34 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use crate::SwBufError;
|
||||
use crate::SoftBufferError;
|
||||
use core_graphics::base::{
|
||||
kCGBitmapByteOrder32Little, kCGImageAlphaNoneSkipFirst, kCGRenderingIntentDefault,
|
||||
};
|
||||
|
|
@ -19,7 +19,7 @@ pub struct CGImpl {
|
|||
}
|
||||
|
||||
impl CGImpl {
|
||||
pub unsafe fn new(handle: AppKitWindowHandle) -> Result<Self, SwBufError> {
|
||||
pub unsafe fn new(handle: AppKitWindowHandle) -> Result<Self, SoftBufferError> {
|
||||
let window = handle.ns_window as id;
|
||||
let view = handle.ns_view as id;
|
||||
let layer = CALayer::new();
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use thiserror::Error;
|
|||
|
||||
#[derive(Error, Debug)]
|
||||
#[non_exhaustive]
|
||||
pub enum SwBufError {
|
||||
pub enum SoftBufferError {
|
||||
#[error(
|
||||
"The provided window returned an unsupported platform: {human_readable_window_platform_name}, {human_readable_display_platform_name}."
|
||||
)]
|
||||
|
|
@ -29,10 +29,10 @@ pub enum SwBufError {
|
|||
pub(crate) fn unwrap<T, E: std::error::Error + 'static>(
|
||||
res: Result<T, E>,
|
||||
str: &str,
|
||||
) -> Result<T, SwBufError> {
|
||||
) -> Result<T, SoftBufferError> {
|
||||
match res {
|
||||
Ok(t) => Ok(t),
|
||||
Err(e) => Err(SwBufError::PlatformError(
|
||||
Err(e) => Err(SoftBufferError::PlatformError(
|
||||
Some(str.into()),
|
||||
Some(Box::new(e)),
|
||||
)),
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ mod x11;
|
|||
|
||||
mod error;
|
||||
|
||||
pub use error::SwBufError;
|
||||
pub use error::SoftBufferError;
|
||||
|
||||
use raw_window_handle::{
|
||||
HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle,
|
||||
|
|
@ -90,7 +90,7 @@ impl GraphicsContext {
|
|||
pub unsafe fn new<W: HasRawWindowHandle, D: HasRawDisplayHandle>(
|
||||
window: &W,
|
||||
display: &D,
|
||||
) -> Result<Self, SwBufError> {
|
||||
) -> Result<Self, SoftBufferError> {
|
||||
unsafe { Self::from_raw(window.raw_window_handle(), display.raw_display_handle()) }
|
||||
}
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ impl GraphicsContext {
|
|||
pub unsafe fn from_raw(
|
||||
raw_window_handle: RawWindowHandle,
|
||||
raw_display_handle: RawDisplayHandle,
|
||||
) -> Result<Self, SwBufError> {
|
||||
) -> Result<Self, SoftBufferError> {
|
||||
let imple: Dispatch = match (raw_window_handle, raw_display_handle) {
|
||||
#[cfg(all(feature = "x11", any(target_os = "linux", target_os = "freebsd")))]
|
||||
(
|
||||
|
|
@ -141,7 +141,7 @@ impl GraphicsContext {
|
|||
Dispatch::Orbital(orbital::OrbitalImpl::new(orbital_handle)?)
|
||||
}
|
||||
(unimplemented_window_handle, unimplemented_display_handle) => {
|
||||
return Err(SwBufError::UnsupportedPlatform {
|
||||
return Err(SoftBufferError::UnsupportedPlatform {
|
||||
human_readable_window_platform_name: window_handle_type_name(
|
||||
&unimplemented_window_handle,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use raw_window_handle::OrbitalWindowHandle;
|
||||
use std::{cmp, slice, str};
|
||||
|
||||
use crate::SwBufError;
|
||||
use crate::SoftBufferError;
|
||||
|
||||
struct OrbitalMap {
|
||||
address: usize,
|
||||
|
|
@ -45,7 +45,7 @@ pub struct OrbitalImpl {
|
|||
}
|
||||
|
||||
impl OrbitalImpl {
|
||||
pub fn new(handle: OrbitalWindowHandle) -> Result<Self, SwBufError> {
|
||||
pub fn new(handle: OrbitalWindowHandle) -> Result<Self, SoftBufferError> {
|
||||
Ok(Self { handle })
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{error::unwrap, SwBufError};
|
||||
use crate::{error::unwrap, SoftBufferError};
|
||||
use raw_window_handle::{WaylandDisplayHandle, WaylandWindowHandle};
|
||||
use std::collections::VecDeque;
|
||||
use wayland_client::{
|
||||
|
|
@ -26,7 +26,7 @@ impl WaylandImpl {
|
|||
pub unsafe fn new(
|
||||
window_handle: WaylandWindowHandle,
|
||||
display_handle: WaylandDisplayHandle,
|
||||
) -> Result<Self, SwBufError> {
|
||||
) -> Result<Self, SoftBufferError> {
|
||||
// SAFETY: Ensured by user
|
||||
let backend = unsafe { Backend::from_foreign_display(display_handle.display as *mut _) };
|
||||
let conn = Connection::from_backend(backend);
|
||||
|
|
|
|||
17
src/web.rs
17
src/web.rs
|
|
@ -5,7 +5,7 @@ use web_sys::CanvasRenderingContext2d;
|
|||
use web_sys::HtmlCanvasElement;
|
||||
use web_sys::ImageData;
|
||||
|
||||
use crate::SwBufError;
|
||||
use crate::SoftBufferError;
|
||||
|
||||
pub struct WebImpl {
|
||||
canvas: HtmlCanvasElement,
|
||||
|
|
@ -13,17 +13,17 @@ pub struct WebImpl {
|
|||
}
|
||||
|
||||
impl WebImpl {
|
||||
pub fn new(handle: WebWindowHandle) -> Result<Self, SwBufError> {
|
||||
pub fn new(handle: WebWindowHandle) -> Result<Self, SoftBufferError> {
|
||||
let canvas: HtmlCanvasElement = web_sys::window()
|
||||
.ok_or_else(|| {
|
||||
SwBufError::PlatformError(
|
||||
SoftBufferError::PlatformError(
|
||||
Some("`window` is not present in this runtime".into()),
|
||||
None,
|
||||
)
|
||||
})?
|
||||
.document()
|
||||
.ok_or_else(|| {
|
||||
SwBufError::PlatformError(
|
||||
SoftBufferError::PlatformError(
|
||||
Some("`document` is not present in this runtime".into()),
|
||||
None,
|
||||
)
|
||||
|
|
@ -32,7 +32,10 @@ impl WebImpl {
|
|||
// `querySelector` only throws an error if the selector is invalid.
|
||||
.unwrap()
|
||||
.ok_or_else(|| {
|
||||
SwBufError::PlatformError(Some("No canvas found with the given id".into()), None)
|
||||
SoftBufferError::PlatformError(
|
||||
Some("No canvas found with the given id".into()),
|
||||
None,
|
||||
)
|
||||
})?
|
||||
// We already made sure this was a canvas in `querySelector`.
|
||||
.unchecked_into();
|
||||
|
|
@ -40,13 +43,13 @@ impl WebImpl {
|
|||
let ctx = canvas
|
||||
.get_context("2d")
|
||||
.map_err(|_| {
|
||||
SwBufError::PlatformError(
|
||||
SoftBufferError::PlatformError(
|
||||
Some("Canvas already controlled using `OffscreenCanvas`".into()),
|
||||
None,
|
||||
)
|
||||
})?
|
||||
.ok_or_else(|| {
|
||||
SwBufError::PlatformError(
|
||||
SoftBufferError::PlatformError(
|
||||
Some("A canvas context other than `CanvasRenderingContext2d` was already created".into()),
|
||||
None,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
//!
|
||||
//! This module converts the input buffer into a bitmap and then stretches it to the window.
|
||||
|
||||
use crate::SwBufError;
|
||||
use crate::SoftBufferError;
|
||||
use raw_window_handle::Win32WindowHandle;
|
||||
|
||||
use std::io;
|
||||
|
|
@ -37,10 +37,10 @@ impl Win32Impl {
|
|||
/// # Safety
|
||||
///
|
||||
/// The `Win32WindowHandle` must be a valid window handle.
|
||||
pub unsafe fn new(handle: &Win32WindowHandle) -> Result<Self, crate::SwBufError> {
|
||||
pub unsafe fn new(handle: &Win32WindowHandle) -> Result<Self, crate::SoftBufferError> {
|
||||
// It is valid for the window handle to be null here. Error out if it is.
|
||||
if handle.hwnd.is_null() {
|
||||
return Err(SwBufError::IncompleteWindowHandle);
|
||||
return Err(SoftBufferError::IncompleteWindowHandle);
|
||||
}
|
||||
|
||||
// Get the handle to the device context.
|
||||
|
|
@ -50,7 +50,7 @@ impl Win32Impl {
|
|||
|
||||
// GetDC returns null if there is a platform error.
|
||||
if dc == 0 {
|
||||
return Err(SwBufError::PlatformError(
|
||||
return Err(SoftBufferError::PlatformError(
|
||||
Some("Device Context is null".into()),
|
||||
Some(Box::new(io::Error::last_os_error())),
|
||||
));
|
||||
|
|
|
|||
20
src/x11.rs
20
src/x11.rs
|
|
@ -4,7 +4,7 @@
|
|||
//! drawn. A more effective implementation would use shared memory instead of the wire. In
|
||||
//! addition, we may also want to blit to a pixmap instead of a window.
|
||||
|
||||
use crate::SwBufError;
|
||||
use crate::SoftBufferError;
|
||||
use raw_window_handle::{XcbDisplayHandle, XcbWindowHandle, XlibDisplayHandle, XlibWindowHandle};
|
||||
use std::fmt;
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ impl X11Impl {
|
|||
pub unsafe fn from_xlib(
|
||||
window_handle: XlibWindowHandle,
|
||||
display_handle: XlibDisplayHandle,
|
||||
) -> Result<Self, SwBufError> {
|
||||
) -> Result<Self, SoftBufferError> {
|
||||
// TODO: We should cache the shared libraries.
|
||||
|
||||
// Try to open the XlibXCB shared library.
|
||||
|
|
@ -47,7 +47,7 @@ impl X11Impl {
|
|||
|
||||
// Validate the display handle to ensure we can use it.
|
||||
if display_handle.display.is_null() {
|
||||
return Err(SwBufError::IncompleteDisplayHandle);
|
||||
return Err(SoftBufferError::IncompleteDisplayHandle);
|
||||
}
|
||||
|
||||
// Get the underlying XCB connection.
|
||||
|
|
@ -76,14 +76,14 @@ impl X11Impl {
|
|||
pub(crate) unsafe fn from_xcb(
|
||||
window_handle: XcbWindowHandle,
|
||||
display_handle: XcbDisplayHandle,
|
||||
) -> Result<Self, SwBufError> {
|
||||
) -> Result<Self, SoftBufferError> {
|
||||
// Check that the handles are valid.
|
||||
if display_handle.connection.is_null() {
|
||||
return Err(SwBufError::IncompleteDisplayHandle);
|
||||
return Err(SoftBufferError::IncompleteDisplayHandle);
|
||||
}
|
||||
|
||||
if window_handle.window == 0 {
|
||||
return Err(SwBufError::IncompleteWindowHandle);
|
||||
return Err(SoftBufferError::IncompleteWindowHandle);
|
||||
}
|
||||
|
||||
// Wrap the display handle in an x11rb connection.
|
||||
|
|
@ -160,15 +160,15 @@ impl Drop for X11Impl {
|
|||
}
|
||||
}
|
||||
|
||||
/// Convenient wrapper to cast errors into SwBufError.
|
||||
/// Convenient wrapper to cast errors into SoftBufferError.
|
||||
trait ResultExt<T, E> {
|
||||
fn swbuf_err(self, msg: impl Into<String>) -> Result<T, SwBufError>;
|
||||
fn swbuf_err(self, msg: impl Into<String>) -> Result<T, SoftBufferError>;
|
||||
}
|
||||
|
||||
impl<T, E: fmt::Debug + fmt::Display + 'static> ResultExt<T, E> for Result<T, E> {
|
||||
fn swbuf_err(self, msg: impl Into<String>) -> Result<T, SwBufError> {
|
||||
fn swbuf_err(self, msg: impl Into<String>) -> Result<T, SoftBufferError> {
|
||||
self.map_err(|e| {
|
||||
SwBufError::PlatformError(Some(msg.into()), Some(Box::new(LibraryError(e))))
|
||||
SoftBufferError::PlatformError(Some(msg.into()), Some(Box::new(LibraryError(e))))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue