From ecfae194cebf97ca23e450e4f4541d911fa132a0 Mon Sep 17 00:00:00 2001 From: jtnunley Date: Thu, 4 May 2023 20:40:47 -0700 Subject: [PATCH 1/4] Add @daxpedda as web maintainer --- .github/CODEOWNERS | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 6505862..d138a22 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -10,8 +10,8 @@ # Wayland /src/wayland @ids1024 -# Web (no maintainer) -/src/web.rs +# Web +/src/web.rs @daxpedda # Windows /src/win32.rs @notgull From fcda747ddfb7062606787a369540db5badf03503 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Mon, 8 May 2023 15:43:34 +0200 Subject: [PATCH 2/4] Add `from_canvas()` to `Surface` for Wasm (#76) Co-authored-by: Toniman575 --- .github/workflows/ci.yml | 11 +++++++++++ Cargo.toml | 11 +++++++++++ src/lib.rs | 4 ++++ src/web.rs | 22 ++++++++++++++++++++++ 4 files changed, 48 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 83568fc..d8fed1d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -118,3 +118,14 @@ jobs: !contains(matrix.platform.target, 'freebsd') && !contains(matrix.platform.target, 'netbsd') run: cargo clippy --all-targets --target ${{ matrix.platform.target }} $OPTIONS --features $FEATURES -- -Dwarnings + + - name: Lint with rustdoc + shell: bash + if: > + (matrix.rust_version == 'stable') && + !contains(matrix.platform.options, '--no-default-features') && + !((matrix.platform.os == 'ubuntu-latest') && contains(matrix.platform.target, 'i686')) && + !contains(matrix.platform.target, 'redox') && + !contains(matrix.platform.target, 'freebsd') && + !contains(matrix.platform.target, 'netbsd') + run: cargo doc --no-deps --target ${{ matrix.platform.target }} $OPTIONS --features $FEATURES --document-private-items diff --git a/Cargo.toml b/Cargo.toml index c6da900..7ad9739 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -85,3 +85,14 @@ rayon = "1.5.1" members = [ "run-wasm", ] + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] +default-target = "x86_64-unknown-linux-gnu" +targets = [ + "x86_64-pc-windows-msvc", + "x86_64-apple-darwin", + "x86_64-unknown-linux-gnu", + "wasm32-unknown-unknown", +] diff --git a/src/lib.rs b/src/lib.rs index f7dadf6..b7064d3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,7 @@ #![doc = include_str!("../README.md")] #![deny(unsafe_op_in_unsafe_fn)] #![warn(missing_docs)] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] #[cfg(target_os = "macos")] #[macro_use] @@ -35,6 +36,9 @@ use raw_window_handle::{ HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle, }; +#[cfg(target_arch = "wasm32")] +pub use self::web::SurfaceExtWeb; + /// An instance of this struct contains the platform-specific data that must be managed in order to /// write to a window on that platform. pub struct Context { diff --git a/src/web.rs b/src/web.rs index c8286d1..920b443 100644 --- a/src/web.rs +++ b/src/web.rs @@ -11,6 +11,7 @@ use web_sys::ImageData; use crate::error::SwResultExt; use crate::SoftBufferError; use std::convert::TryInto; +use std::marker::PhantomData; use std::num::NonZeroU32; /// Display implementation for the web platform. @@ -56,6 +57,10 @@ impl WebImpl { // We already made sure this was a canvas in `querySelector`. .unchecked_into(); + Self::from_canvas(canvas) + } + + fn from_canvas(canvas: HtmlCanvasElement) -> Result { let ctx = canvas .get_context("2d") .ok() @@ -96,6 +101,23 @@ impl 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`]. + fn from_canvas(canvas: HtmlCanvasElement) -> Result; +} + +impl SurfaceExtWeb for crate::Surface { + fn from_canvas(canvas: HtmlCanvasElement) -> Result { + let imple = crate::SurfaceDispatch::Web(WebImpl::from_canvas(canvas)?); + + Ok(Self { + surface_impl: Box::new(imple), + _marker: PhantomData, + }) + } +} + pub struct BufferImpl<'a> { imp: &'a mut WebImpl, } From 4268c732a6a70af57a76e585412ff7123a2f9c3d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 May 2023 06:48:56 -0700 Subject: [PATCH 3/4] Update memmap2 requirement from 0.5.8 to 0.6.1 (#108) --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7ad9739..fa82b5c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ thiserror = "1.0.30" [target.'cfg(all(unix, not(any(target_vendor = "apple", target_os = "android", target_os = "redox"))))'.dependencies] bytemuck = { version = "1.12.3", optional = true } -memmap2 = { version = "0.5.8", optional = true } +memmap2 = { version = "0.6.1", optional = true } nix = { version = "0.26.1", optional = true } wayland-backend = { version = "0.1.0", features = ["client_system"], optional = true } wayland-client = { version = "0.30.0", optional = true } From eb227f10f06f8e5cd4d34ab0c3694c4e60606ff7 Mon Sep 17 00:00:00 2001 From: dAxpeDDa Date: Sat, 27 May 2023 12:47:54 +0200 Subject: [PATCH 4/4] Bump `x11rb` to v0.12 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index fa82b5c..2965f15 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,7 @@ wayland-backend = { version = "0.1.0", features = ["client_system"], optional = wayland-client = { version = "0.30.0", optional = true } wayland-sys = "0.30.0" x11-dl = { version = "2.19.1", optional = true } -x11rb = { version = "0.11.0", features = ["allow-unsafe-code", "dl-libxcb", "shm"], optional = true } +x11rb = { version = "0.12.0", features = ["allow-unsafe-code", "dl-libxcb", "shm"], optional = true } [target.'cfg(all(unix, not(any(target_vendor = "apple", target_os = "android", target_os = "redox", target_os = "linux", target_os = "freebsd"))))'.dependencies] fastrand = { version = "1.8.0", optional = true }