diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e605c92..0000bd9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - **Breaking:** Removed unintentional Cargo features for Softbuffer's optional dependencies. - **Breaking:** Disable the DRM/KMS backend by default. - **Breaking:** Removed `DamageOutOfRange` error case. If the damage value is greater than the backend supports, it is instead clamped to an appropriate value. +- **Breaking:** Removed `SurfaceExtWeb` and the associated `NoDisplayHandle` and `NoWindowHandle` helpers. Use `RawWindowHandle::WebCanvas` or `RawWindowHandle::WebOffscreenCanvas` instead. - Fixed `present_with_damage` with bounds out of range on Windows, Web and X11. # 0.4.7 diff --git a/src/backends/web.rs b/src/backends/web.rs index 1fa43071..3733fdd3 100644 --- a/src/backends/web.rs +++ b/src/backends/web.rs @@ -11,7 +11,7 @@ use web_sys::{OffscreenCanvas, OffscreenCanvasRenderingContext2d}; use crate::backend_interface::*; use crate::error::{InitError, SwResultExt}; -use crate::{util, NoDisplayHandle, NoWindowHandle, Pixel, Rect, SoftBufferError}; +use crate::{util, Pixel, Rect, SoftBufferError}; use std::marker::PhantomData; use std::num::NonZeroU32; @@ -216,45 +216,6 @@ impl SurfaceInterface for WebImpl } } -/// Extension methods for the Wasm target on [`Surface`](crate::Surface). -pub trait SurfaceExtWeb: Sized { - /// Creates a new instance of this struct, using the provided [`HtmlCanvasElement`]. - /// - /// # Errors - /// - If the canvas was already controlled by an `OffscreenCanvas`. - /// - If a another context then "2d" was already created for this canvas. - fn from_canvas(canvas: HtmlCanvasElement) -> Result; - - /// Creates a new instance of this struct, using the provided [`OffscreenCanvas`]. - /// - /// # Errors - /// If a another context then "2d" was already created for this canvas. - fn from_offscreen_canvas(offscreen_canvas: OffscreenCanvas) -> Result; -} - -impl SurfaceExtWeb for crate::Surface { - fn from_canvas(canvas: HtmlCanvasElement) -> Result { - let imple = crate::SurfaceDispatch::Web(WebImpl::from_canvas(canvas, NoWindowHandle(()))?); - - Ok(Self { - surface_impl: Box::new(imple), - _marker: PhantomData, - }) - } - - fn from_offscreen_canvas(offscreen_canvas: OffscreenCanvas) -> Result { - let imple = crate::SurfaceDispatch::Web(WebImpl::from_offscreen_canvas( - offscreen_canvas, - NoWindowHandle(()), - )?); - - Ok(Self { - surface_impl: Box::new(imple), - _marker: PhantomData, - }) - } -} - impl Canvas { fn set_width(&self, width: u32) { match self { diff --git a/src/lib.rs b/src/lib.rs index f410b803..83caa7f0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,8 +23,6 @@ use raw_window_handle::{HasDisplayHandle, HasWindowHandle, RawDisplayHandle, Raw use self::backend_dispatch::*; use self::backend_interface::*; -#[cfg(target_family = "wasm")] -pub use self::backends::web::SurfaceExtWeb; use self::error::InitError; pub use self::error::SoftBufferError; pub use self::format::PixelFormat; @@ -84,6 +82,16 @@ pub struct Surface { impl Surface { /// Creates a new surface for the context for the provided window. + /// + /// # Platform Dependent Behavior + /// + /// - Web: If the handle is a [`WebOffscreenCanvasWindowHandle`], this will error if another + /// context than "2d" was already created for the canvas. If the handle is a + /// [`WebCanvasWindowHandle`], this will additionally error if the canvas was already + /// controlled by an `OffscreenCanvas`. + /// + /// [`WebCanvasWindowHandle`]: raw_window_handle::WebCanvasWindowHandle + /// [`WebOffscreenCanvasWindowHandle`]: raw_window_handle::WebCanvasWindowHandle pub fn new(context: &Context, window: W) -> Result { match SurfaceDispatch::new(window, &context.context_impl) { Ok(surface_dispatch) => Ok(Self { @@ -505,31 +513,6 @@ impl Buffer<'_> { } } -/// There is no display handle. -#[derive(Debug)] -#[allow(dead_code)] -pub struct NoDisplayHandle(core::convert::Infallible); - -impl HasDisplayHandle for NoDisplayHandle { - fn display_handle( - &self, - ) -> Result, raw_window_handle::HandleError> { - match self.0 {} - } -} - -/// There is no window handle. -#[derive(Debug)] -pub struct NoWindowHandle(()); - -impl HasWindowHandle for NoWindowHandle { - fn window_handle( - &self, - ) -> Result, raw_window_handle::HandleError> { - Err(raw_window_handle::HandleError::NotSupported) - } -} - fn window_handle_type_name(handle: &RawWindowHandle) -> &'static str { match handle { RawWindowHandle::Xlib(_) => "Xlib",