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::{
|
use core_graphics::base::{
|
||||||
kCGBitmapByteOrder32Little, kCGImageAlphaNoneSkipFirst, kCGRenderingIntentDefault,
|
kCGBitmapByteOrder32Little, kCGImageAlphaNoneSkipFirst, kCGRenderingIntentDefault,
|
||||||
};
|
};
|
||||||
|
|
@ -19,7 +19,7 @@ pub struct CGImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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 window = handle.ns_window as id;
|
||||||
let view = handle.ns_view as id;
|
let view = handle.ns_view as id;
|
||||||
let layer = CALayer::new();
|
let layer = CALayer::new();
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use thiserror::Error;
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum SwBufError {
|
pub enum SoftBufferError {
|
||||||
#[error(
|
#[error(
|
||||||
"The provided window returned an unsupported platform: {human_readable_window_platform_name}, {human_readable_display_platform_name}."
|
"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>(
|
pub(crate) fn unwrap<T, E: std::error::Error + 'static>(
|
||||||
res: Result<T, E>,
|
res: Result<T, E>,
|
||||||
str: &str,
|
str: &str,
|
||||||
) -> Result<T, SwBufError> {
|
) -> Result<T, SoftBufferError> {
|
||||||
match res {
|
match res {
|
||||||
Ok(t) => Ok(t),
|
Ok(t) => Ok(t),
|
||||||
Err(e) => Err(SwBufError::PlatformError(
|
Err(e) => Err(SoftBufferError::PlatformError(
|
||||||
Some(str.into()),
|
Some(str.into()),
|
||||||
Some(Box::new(e)),
|
Some(Box::new(e)),
|
||||||
)),
|
)),
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ mod x11;
|
||||||
|
|
||||||
mod error;
|
mod error;
|
||||||
|
|
||||||
pub use error::SwBufError;
|
pub use error::SoftBufferError;
|
||||||
|
|
||||||
use raw_window_handle::{
|
use raw_window_handle::{
|
||||||
HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle,
|
HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle,
|
||||||
|
|
@ -90,7 +90,7 @@ impl GraphicsContext {
|
||||||
pub unsafe fn new<W: HasRawWindowHandle, D: HasRawDisplayHandle>(
|
pub unsafe fn new<W: HasRawWindowHandle, D: HasRawDisplayHandle>(
|
||||||
window: &W,
|
window: &W,
|
||||||
display: &D,
|
display: &D,
|
||||||
) -> Result<Self, SwBufError> {
|
) -> Result<Self, SoftBufferError> {
|
||||||
unsafe { Self::from_raw(window.raw_window_handle(), display.raw_display_handle()) }
|
unsafe { Self::from_raw(window.raw_window_handle(), display.raw_display_handle()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -103,7 +103,7 @@ impl GraphicsContext {
|
||||||
pub unsafe fn from_raw(
|
pub unsafe fn from_raw(
|
||||||
raw_window_handle: RawWindowHandle,
|
raw_window_handle: RawWindowHandle,
|
||||||
raw_display_handle: RawDisplayHandle,
|
raw_display_handle: RawDisplayHandle,
|
||||||
) -> Result<Self, SwBufError> {
|
) -> Result<Self, SoftBufferError> {
|
||||||
let imple: Dispatch = match (raw_window_handle, raw_display_handle) {
|
let imple: Dispatch = match (raw_window_handle, raw_display_handle) {
|
||||||
#[cfg(all(feature = "x11", any(target_os = "linux", target_os = "freebsd")))]
|
#[cfg(all(feature = "x11", any(target_os = "linux", target_os = "freebsd")))]
|
||||||
(
|
(
|
||||||
|
|
@ -141,7 +141,7 @@ impl GraphicsContext {
|
||||||
Dispatch::Orbital(orbital::OrbitalImpl::new(orbital_handle)?)
|
Dispatch::Orbital(orbital::OrbitalImpl::new(orbital_handle)?)
|
||||||
}
|
}
|
||||||
(unimplemented_window_handle, unimplemented_display_handle) => {
|
(unimplemented_window_handle, unimplemented_display_handle) => {
|
||||||
return Err(SwBufError::UnsupportedPlatform {
|
return Err(SoftBufferError::UnsupportedPlatform {
|
||||||
human_readable_window_platform_name: window_handle_type_name(
|
human_readable_window_platform_name: window_handle_type_name(
|
||||||
&unimplemented_window_handle,
|
&unimplemented_window_handle,
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use raw_window_handle::OrbitalWindowHandle;
|
use raw_window_handle::OrbitalWindowHandle;
|
||||||
use std::{cmp, slice, str};
|
use std::{cmp, slice, str};
|
||||||
|
|
||||||
use crate::SwBufError;
|
use crate::SoftBufferError;
|
||||||
|
|
||||||
struct OrbitalMap {
|
struct OrbitalMap {
|
||||||
address: usize,
|
address: usize,
|
||||||
|
|
@ -45,7 +45,7 @@ pub struct OrbitalImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OrbitalImpl {
|
impl OrbitalImpl {
|
||||||
pub fn new(handle: OrbitalWindowHandle) -> Result<Self, SwBufError> {
|
pub fn new(handle: OrbitalWindowHandle) -> Result<Self, SoftBufferError> {
|
||||||
Ok(Self { handle })
|
Ok(Self { handle })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{error::unwrap, SwBufError};
|
use crate::{error::unwrap, SoftBufferError};
|
||||||
use raw_window_handle::{WaylandDisplayHandle, WaylandWindowHandle};
|
use raw_window_handle::{WaylandDisplayHandle, WaylandWindowHandle};
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use wayland_client::{
|
use wayland_client::{
|
||||||
|
|
@ -26,7 +26,7 @@ impl WaylandImpl {
|
||||||
pub unsafe fn new(
|
pub unsafe fn new(
|
||||||
window_handle: WaylandWindowHandle,
|
window_handle: WaylandWindowHandle,
|
||||||
display_handle: WaylandDisplayHandle,
|
display_handle: WaylandDisplayHandle,
|
||||||
) -> Result<Self, SwBufError> {
|
) -> Result<Self, SoftBufferError> {
|
||||||
// SAFETY: Ensured by user
|
// SAFETY: Ensured by user
|
||||||
let backend = unsafe { Backend::from_foreign_display(display_handle.display as *mut _) };
|
let backend = unsafe { Backend::from_foreign_display(display_handle.display as *mut _) };
|
||||||
let conn = Connection::from_backend(backend);
|
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::HtmlCanvasElement;
|
||||||
use web_sys::ImageData;
|
use web_sys::ImageData;
|
||||||
|
|
||||||
use crate::SwBufError;
|
use crate::SoftBufferError;
|
||||||
|
|
||||||
pub struct WebImpl {
|
pub struct WebImpl {
|
||||||
canvas: HtmlCanvasElement,
|
canvas: HtmlCanvasElement,
|
||||||
|
|
@ -13,17 +13,17 @@ pub struct WebImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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()
|
let canvas: HtmlCanvasElement = web_sys::window()
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
SwBufError::PlatformError(
|
SoftBufferError::PlatformError(
|
||||||
Some("`window` is not present in this runtime".into()),
|
Some("`window` is not present in this runtime".into()),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
})?
|
})?
|
||||||
.document()
|
.document()
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
SwBufError::PlatformError(
|
SoftBufferError::PlatformError(
|
||||||
Some("`document` is not present in this runtime".into()),
|
Some("`document` is not present in this runtime".into()),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
|
@ -32,7 +32,10 @@ impl WebImpl {
|
||||||
// `querySelector` only throws an error if the selector is invalid.
|
// `querySelector` only throws an error if the selector is invalid.
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.ok_or_else(|| {
|
.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`.
|
// We already made sure this was a canvas in `querySelector`.
|
||||||
.unchecked_into();
|
.unchecked_into();
|
||||||
|
|
@ -40,13 +43,13 @@ impl WebImpl {
|
||||||
let ctx = canvas
|
let ctx = canvas
|
||||||
.get_context("2d")
|
.get_context("2d")
|
||||||
.map_err(|_| {
|
.map_err(|_| {
|
||||||
SwBufError::PlatformError(
|
SoftBufferError::PlatformError(
|
||||||
Some("Canvas already controlled using `OffscreenCanvas`".into()),
|
Some("Canvas already controlled using `OffscreenCanvas`".into()),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
})?
|
})?
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
SwBufError::PlatformError(
|
SoftBufferError::PlatformError(
|
||||||
Some("A canvas context other than `CanvasRenderingContext2d` was already created".into()),
|
Some("A canvas context other than `CanvasRenderingContext2d` was already created".into()),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
//!
|
//!
|
||||||
//! This module converts the input buffer into a bitmap and then stretches it to the window.
|
//! 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 raw_window_handle::Win32WindowHandle;
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
@ -37,10 +37,10 @@ impl Win32Impl {
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// The `Win32WindowHandle` must be a valid window handle.
|
/// 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.
|
// It is valid for the window handle to be null here. Error out if it is.
|
||||||
if handle.hwnd.is_null() {
|
if handle.hwnd.is_null() {
|
||||||
return Err(SwBufError::IncompleteWindowHandle);
|
return Err(SoftBufferError::IncompleteWindowHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the handle to the device context.
|
// Get the handle to the device context.
|
||||||
|
|
@ -50,7 +50,7 @@ impl Win32Impl {
|
||||||
|
|
||||||
// GetDC returns null if there is a platform error.
|
// GetDC returns null if there is a platform error.
|
||||||
if dc == 0 {
|
if dc == 0 {
|
||||||
return Err(SwBufError::PlatformError(
|
return Err(SoftBufferError::PlatformError(
|
||||||
Some("Device Context is null".into()),
|
Some("Device Context is null".into()),
|
||||||
Some(Box::new(io::Error::last_os_error())),
|
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
|
//! 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.
|
//! 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 raw_window_handle::{XcbDisplayHandle, XcbWindowHandle, XlibDisplayHandle, XlibWindowHandle};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
|
@ -39,7 +39,7 @@ impl X11Impl {
|
||||||
pub unsafe fn from_xlib(
|
pub unsafe fn from_xlib(
|
||||||
window_handle: XlibWindowHandle,
|
window_handle: XlibWindowHandle,
|
||||||
display_handle: XlibDisplayHandle,
|
display_handle: XlibDisplayHandle,
|
||||||
) -> Result<Self, SwBufError> {
|
) -> Result<Self, SoftBufferError> {
|
||||||
// TODO: We should cache the shared libraries.
|
// TODO: We should cache the shared libraries.
|
||||||
|
|
||||||
// Try to open the XlibXCB shared library.
|
// Try to open the XlibXCB shared library.
|
||||||
|
|
@ -47,7 +47,7 @@ impl X11Impl {
|
||||||
|
|
||||||
// Validate the display handle to ensure we can use it.
|
// Validate the display handle to ensure we can use it.
|
||||||
if display_handle.display.is_null() {
|
if display_handle.display.is_null() {
|
||||||
return Err(SwBufError::IncompleteDisplayHandle);
|
return Err(SoftBufferError::IncompleteDisplayHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the underlying XCB connection.
|
// Get the underlying XCB connection.
|
||||||
|
|
@ -76,14 +76,14 @@ impl X11Impl {
|
||||||
pub(crate) unsafe fn from_xcb(
|
pub(crate) unsafe fn from_xcb(
|
||||||
window_handle: XcbWindowHandle,
|
window_handle: XcbWindowHandle,
|
||||||
display_handle: XcbDisplayHandle,
|
display_handle: XcbDisplayHandle,
|
||||||
) -> Result<Self, SwBufError> {
|
) -> Result<Self, SoftBufferError> {
|
||||||
// Check that the handles are valid.
|
// Check that the handles are valid.
|
||||||
if display_handle.connection.is_null() {
|
if display_handle.connection.is_null() {
|
||||||
return Err(SwBufError::IncompleteDisplayHandle);
|
return Err(SoftBufferError::IncompleteDisplayHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
if window_handle.window == 0 {
|
if window_handle.window == 0 {
|
||||||
return Err(SwBufError::IncompleteWindowHandle);
|
return Err(SoftBufferError::IncompleteWindowHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrap the display handle in an x11rb connection.
|
// 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> {
|
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> {
|
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| {
|
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