Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 1 addition & 40 deletions src/backends/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -216,45 +216,6 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> SurfaceInterface<D, W> 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<Self, SoftBufferError>;

/// 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<Self, SoftBufferError>;
}

impl SurfaceExtWeb for crate::Surface<NoDisplayHandle, NoWindowHandle> {
fn from_canvas(canvas: HtmlCanvasElement) -> Result<Self, SoftBufferError> {
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<Self, SoftBufferError> {
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 {
Expand Down
37 changes: 10 additions & 27 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -84,6 +82,16 @@ pub struct Surface<D, W> {

impl<D: HasDisplayHandle, W: HasWindowHandle> Surface<D, W> {
/// 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<D>, window: W) -> Result<Self, SoftBufferError> {
match SurfaceDispatch::new(window, &context.context_impl) {
Ok(surface_dispatch) => Ok(Self {
Expand Down Expand Up @@ -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::DisplayHandle<'_>, 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::WindowHandle<'_>, raw_window_handle::HandleError> {
Err(raw_window_handle::HandleError::NotSupported)
}
}

fn window_handle_type_name(handle: &RawWindowHandle) -> &'static str {
match handle {
RawWindowHandle::Xlib(_) => "Xlib",
Expand Down