Rename SoftBufferError to SwBufError

This commit is contained in:
Jeremy Soller 2022-12-20 07:10:11 -07:00
parent 33fe3ae3c7
commit 95e8d05902
No known key found for this signature in database
GPG key ID: 87F211AF2BE4C2FE
8 changed files with 25 additions and 25 deletions

View file

@ -1,4 +1,4 @@
use crate::{GraphicsContextImpl, SoftBufferError}; use crate::{GraphicsContextImpl, SwBufError};
use raw_window_handle::{HasRawWindowHandle, AppKitWindowHandle}; use raw_window_handle::{HasRawWindowHandle, AppKitWindowHandle};
use core_graphics::base::{kCGBitmapByteOrder32Little, kCGImageAlphaNoneSkipFirst, kCGRenderingIntentDefault}; use core_graphics::base::{kCGBitmapByteOrder32Little, kCGImageAlphaNoneSkipFirst, kCGRenderingIntentDefault};
use core_graphics::color_space::CGColorSpace; use core_graphics::color_space::CGColorSpace;
@ -17,7 +17,7 @@ pub struct CGImpl {
} }
impl CGImpl { impl CGImpl {
pub unsafe fn new<W: HasRawWindowHandle>(handle: AppKitWindowHandle) -> Result<Self, SoftBufferError<W>> { pub unsafe fn new<W: HasRawWindowHandle>(handle: AppKitWindowHandle) -> Result<Self, SwBufError<W>> {
let view = handle.ns_view as id; let view = handle.ns_view as id;
let layer = CALayer::new(); let layer = CALayer::new();
let subview: id = NSView::alloc(nil).initWithFrame_(view.frame()); let subview: id = NSView::alloc(nil).initWithFrame_(view.frame());

View file

@ -3,7 +3,7 @@ use raw_window_handle::{HasRawWindowHandle, RawDisplayHandle, RawWindowHandle};
use thiserror::Error; use thiserror::Error;
#[derive(Error, Debug)] #[derive(Error, Debug)]
pub enum SoftBufferError<W: HasRawWindowHandle> { pub enum SwBufError<W: HasRawWindowHandle> {
#[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}."
)] )]
@ -19,9 +19,9 @@ pub enum SoftBufferError<W: HasRawWindowHandle> {
} }
#[allow(unused)] // This isn't used on all platforms #[allow(unused)] // This isn't used on all platforms
pub(crate) fn unwrap<T, E: std::error::Error + 'static, W: HasRawWindowHandle>(res: Result<T, E>, str: &str) -> Result<T, SoftBufferError<W>>{ pub(crate) fn unwrap<T, E: std::error::Error + 'static, W: HasRawWindowHandle>(res: Result<T, E>, str: &str) -> Result<T, SwBufError<W>>{
match res{ match res{
Ok(t) => Ok(t), Ok(t) => Ok(t),
Err(e) => Err(SoftBufferError::PlatformError(Some(str.into()), Some(Box::new(e)))) Err(e) => Err(SwBufError::PlatformError(Some(str.into()), Some(Box::new(e))))
} }
} }

View file

@ -20,7 +20,7 @@ mod orbital;
mod error; mod error;
pub use error::SoftBufferError; pub use error::SwBufError;
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle}; use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle};
@ -39,7 +39,7 @@ impl<W: HasRawWindowHandle + HasRawDisplayHandle> GraphicsContext<W> {
/// # Safety /// # Safety
/// ///
/// - Ensure that the passed object is valid to draw a 2D buffer to /// - Ensure that the passed object is valid to draw a 2D buffer to
pub unsafe fn new(window: W) -> Result<Self, SoftBufferError<W>> { pub unsafe fn new(window: W) -> Result<Self, SwBufError<W>> {
let raw_window_handle = window.raw_window_handle(); let raw_window_handle = window.raw_window_handle();
let raw_display_handle = window.raw_display_handle(); let raw_display_handle = window.raw_display_handle();
@ -56,7 +56,7 @@ impl<W: HasRawWindowHandle + HasRawDisplayHandle> GraphicsContext<W> {
(RawWindowHandle::Web(web_handle), _) => Box::new(web::WebImpl::new(web_handle)?), (RawWindowHandle::Web(web_handle), _) => Box::new(web::WebImpl::new(web_handle)?),
#[cfg(target_os = "redox")] #[cfg(target_os = "redox")]
(RawWindowHandle::Orbital(orbital_handle), _) => Box::new(orbital::OrbitalImpl::new(orbital_handle)?), (RawWindowHandle::Orbital(orbital_handle), _) => Box::new(orbital::OrbitalImpl::new(orbital_handle)?),
(unimplemented_window_handle, unimplemented_display_handle) => return Err(SoftBufferError::UnsupportedPlatform { (unimplemented_window_handle, unimplemented_display_handle) => return Err(SwBufError::UnsupportedPlatform {
window, window,
human_readable_window_platform_name: window_handle_type_name(&unimplemented_window_handle), human_readable_window_platform_name: window_handle_type_name(&unimplemented_window_handle),
human_readable_display_platform_name: display_handle_type_name(&unimplemented_display_handle), human_readable_display_platform_name: display_handle_type_name(&unimplemented_display_handle),

View file

@ -7,7 +7,7 @@ use std::{
}; };
use crate::GraphicsContextImpl; use crate::GraphicsContextImpl;
use crate::SoftBufferError; use crate::SwBufError;
struct OrbitalMap { struct OrbitalMap {
address: usize, address: usize,
@ -47,7 +47,7 @@ pub struct OrbitalImpl {
} }
impl OrbitalImpl { impl OrbitalImpl {
pub fn new<W: HasRawWindowHandle>(handle: OrbitalWindowHandle) -> Result<Self, SoftBufferError<W>> { pub fn new<W: HasRawWindowHandle>(handle: OrbitalWindowHandle) -> Result<Self, SwBufError<W>> {
Ok(Self { handle }) Ok(Self { handle })
} }
} }

View file

@ -1,4 +1,4 @@
use crate::{error::unwrap, GraphicsContextImpl, SoftBufferError}; use crate::{error::unwrap, GraphicsContextImpl, SwBufError};
use nix::sys::memfd::{memfd_create, MemFdCreateFlag}; use nix::sys::memfd::{memfd_create, MemFdCreateFlag};
use raw_window_handle::{HasRawWindowHandle, WaylandDisplayHandle, WaylandWindowHandle}; use raw_window_handle::{HasRawWindowHandle, WaylandDisplayHandle, WaylandWindowHandle};
use std::{ use std::{
@ -43,7 +43,7 @@ impl WaylandImpl {
pub unsafe fn new<W: HasRawWindowHandle>( pub unsafe fn new<W: HasRawWindowHandle>(
window_handle: WaylandWindowHandle, window_handle: WaylandWindowHandle,
display_handle: WaylandDisplayHandle, display_handle: WaylandDisplayHandle,
) -> Result<Self, SoftBufferError<W>> { ) -> Result<Self, SwBufError<W>> {
let conn = Connection::from_backend(Backend::from_foreign_display( let conn = Connection::from_backend(Backend::from_foreign_display(
display_handle.display as *mut _, display_handle.display as *mut _,
)); ));

View file

@ -7,7 +7,7 @@ use web_sys::HtmlCanvasElement;
use web_sys::ImageData; use web_sys::ImageData;
use crate::GraphicsContextImpl; use crate::GraphicsContextImpl;
use crate::SoftBufferError; use crate::SwBufError;
pub struct WebImpl { pub struct WebImpl {
canvas: HtmlCanvasElement, canvas: HtmlCanvasElement,
@ -15,17 +15,17 @@ pub struct WebImpl {
} }
impl WebImpl { impl WebImpl {
pub fn new<W: HasRawWindowHandle>(handle: WebWindowHandle) -> Result<Self, SoftBufferError<W>> { pub fn new<W: HasRawWindowHandle>(handle: WebWindowHandle) -> Result<Self, SwBufError<W>> {
let canvas: HtmlCanvasElement = web_sys::window() let canvas: HtmlCanvasElement = web_sys::window()
.ok_or_else(|| { .ok_or_else(|| {
SoftBufferError::PlatformError( SwBufError::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(|| {
SoftBufferError::PlatformError( SwBufError::PlatformError(
Some("`document` is not present in this runtime".into()), Some("`document` is not present in this runtime".into()),
None, None,
) )
@ -34,7 +34,7 @@ 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(|| {
SoftBufferError::PlatformError( SwBufError::PlatformError(
Some("No canvas found with the given id".into()), Some("No canvas found with the given id".into()),
None, None,
) )
@ -45,13 +45,13 @@ impl WebImpl {
let ctx = canvas let ctx = canvas
.get_context("2d") .get_context("2d")
.map_err(|_| { .map_err(|_| {
SoftBufferError::PlatformError( SwBufError::PlatformError(
Some("Canvas already controlled using `OffscreenCanvas`".into()), Some("Canvas already controlled using `OffscreenCanvas`".into()),
None, None,
) )
})? })?
.ok_or_else(|| { .ok_or_else(|| {
SoftBufferError::PlatformError( SwBufError::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,
) )

View file

@ -1,4 +1,4 @@
use crate::{GraphicsContextImpl, SoftBufferError}; use crate::{GraphicsContextImpl, SwBufError};
use raw_window_handle::{HasRawWindowHandle, Win32WindowHandle}; use raw_window_handle::{HasRawWindowHandle, Win32WindowHandle};
use std::os::raw::c_int; use std::os::raw::c_int;
use winapi::shared::windef::{HDC, HWND}; use winapi::shared::windef::{HDC, HWND};
@ -19,11 +19,11 @@ struct BitmapInfo {
} }
impl Win32Impl { impl Win32Impl {
pub unsafe fn new<W: HasRawWindowHandle>(handle: &Win32WindowHandle) -> Result<Self, crate::SoftBufferError<W>> { pub unsafe fn new<W: HasRawWindowHandle>(handle: &Win32WindowHandle) -> Result<Self, crate::SwBufError<W>> {
let dc = GetDC(handle.hwnd as HWND); let dc = GetDC(handle.hwnd as HWND);
if dc.is_null(){ if dc.is_null(){
return Err(SoftBufferError::PlatformError(Some("Device Context is null".into()), None)); return Err(SwBufError::PlatformError(Some("Device Context is null".into()), None));
} }
Ok( Ok(

View file

@ -1,4 +1,4 @@
use crate::{GraphicsContextImpl, SoftBufferError}; use crate::{GraphicsContextImpl, SwBufError};
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle, XlibDisplayHandle, XlibWindowHandle}; use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle, XlibDisplayHandle, XlibWindowHandle};
use std::os::raw::{c_char, c_uint}; use std::os::raw::{c_char, c_uint};
use x11_dl::xlib::{Display, Visual, Xlib, ZPixmap, GC}; use x11_dl::xlib::{Display, Visual, Xlib, ZPixmap, GC};
@ -13,10 +13,10 @@ pub struct X11Impl {
} }
impl X11Impl { impl X11Impl {
pub unsafe fn new<W: HasRawWindowHandle + HasRawDisplayHandle>(window_handle: XlibWindowHandle, display_handle: XlibDisplayHandle) -> Result<Self, SoftBufferError<W>> { pub unsafe fn new<W: HasRawWindowHandle + HasRawDisplayHandle>(window_handle: XlibWindowHandle, display_handle: XlibDisplayHandle) -> Result<Self, SwBufError<W>> {
let lib = match Xlib::open() { let lib = match Xlib::open() {
Ok(lib) => lib, Ok(lib) => lib,
Err(e) => return Err(SoftBufferError::PlatformError(Some("Failed to open Xlib".into()), Some(Box::new(e)))) Err(e) => return Err(SwBufError::PlatformError(Some("Failed to open Xlib".into()), Some(Box::new(e))))
}; };
let screen = (lib.XDefaultScreen)(display_handle.display as *mut Display); let screen = (lib.XDefaultScreen)(display_handle.display as *mut Display);
let gc = (lib.XDefaultGC)(display_handle.display as *mut Display, screen); let gc = (lib.XDefaultGC)(display_handle.display as *mut Display, screen);