From 53296a5ddf109b33dafa7256bd896766c63fff5e Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Fri, 6 Feb 2026 07:31:25 +0100 Subject: [PATCH 1/2] Remove SurfaceExtWeb This was added before raw-window-handle got support for the canvas and offscreen canvas handles, so they should now be redundant. --- CHANGELOG.md | 1 + src/backends/web.rs | 41 +---------------------------------------- src/lib.rs | 37 ++++++++++--------------------------- 3 files changed, 12 insertions(+), 67 deletions(-) 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..3504f1a0 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 a 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", From a186ad803469c38e362df6602d2d9e5b0e591c1d Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sat, 7 Feb 2026 23:42:39 +0100 Subject: [PATCH 2/2] fix typo Co-authored-by: daxpedda --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 3504f1a0..83caa7f0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -85,7 +85,7 @@ impl Surface { /// /// # Platform Dependent Behavior /// - /// - Web: If the handle is a [`WebOffscreenCanvasWindowHandle`], this will error if a another + /// - 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`.