diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d04c3c1e4..4625d97f7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -90,6 +90,7 @@ By @teoxoy [#6134](https://github.com/gfx-rs/wgpu/pull/6134). - Deduplicate bind group layouts that are created from pipelines with "auto" layouts. By @teoxoy [#6049](https://github.com/gfx-rs/wgpu/pull/6049) - Fix crash when dropping the surface after the device. By @wumpf in [#6052](https://github.com/gfx-rs/wgpu/pull/6052) - Fix error message that is thrown in create_render_pass to no longer say `compute_pass`. By @matthew-wong1 [#6041](https://github.com/gfx-rs/wgpu/pull/6041) +- Add `VideoFrame` to `ExternalImageSource` enum. By @jprochazk in [#6170](https://github.com/gfx-rs/wgpu/pull/6170) #### GLES / OpenGL diff --git a/wgpu-hal/src/gles/queue.rs b/wgpu-hal/src/gles/queue.rs index e1c08d6bd6..39315f72b7 100644 --- a/wgpu-hal/src/gles/queue.rs +++ b/wgpu-hal/src/gles/queue.rs @@ -502,6 +502,22 @@ impl super::Queue { v, ); }, + #[cfg(web_sys_unstable_apis)] + wgt::ExternalImageSource::VideoFrame(ref v) => unsafe { + gl.tex_sub_image_3d_with_video_frame( + dst_target, + copy.dst_base.mip_level as i32, + copy.dst_base.origin.x as i32, + copy.dst_base.origin.y as i32, + z_offset as i32, + copy.size.width as i32, + copy.size.height as i32, + copy.size.depth as i32, + format_desc.external, + format_desc.data_type, + v, + ) + }, wgt::ExternalImageSource::ImageData(ref i) => unsafe { gl.tex_sub_image_3d_with_image_data( dst_target, @@ -577,6 +593,20 @@ impl super::Queue { v, ) }, + #[cfg(web_sys_unstable_apis)] + wgt::ExternalImageSource::VideoFrame(ref v) => unsafe { + gl.tex_sub_image_2d_with_video_frame_and_width_and_height( + dst_target, + copy.dst_base.mip_level as i32, + copy.dst_base.origin.x as i32, + copy.dst_base.origin.y as i32, + copy.size.width as i32, + copy.size.height as i32, + format_desc.external, + format_desc.data_type, + v, + ) + }, wgt::ExternalImageSource::ImageData(ref i) => unsafe { gl.tex_sub_image_2d_with_image_data_and_width_and_height( dst_target, diff --git a/wgpu-types/Cargo.toml b/wgpu-types/Cargo.toml index e79b301342..38bda98bc2 100644 --- a/wgpu-types/Cargo.toml +++ b/wgpu-types/Cargo.toml @@ -43,9 +43,11 @@ js-sys.workspace = true web-sys = { workspace = true, features = [ "ImageBitmap", "ImageData", + "HtmlImageElement", "HtmlVideoElement", "HtmlCanvasElement", "OffscreenCanvas", + "VideoFrame", ] } [dev-dependencies] diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 4162b3bd6a..cd2f5dcd0a 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -6871,6 +6871,9 @@ pub enum ExternalImageSource { /// /// Requires [`DownlevelFlags::UNRESTRICTED_EXTERNAL_TEXTURE_COPIES`] OffscreenCanvas(web_sys::OffscreenCanvas), + /// Copy from a video frame. + #[cfg(web_sys_unstable_apis)] + VideoFrame(web_sys::VideoFrame), } #[cfg(target_arch = "wasm32")] @@ -6884,6 +6887,8 @@ impl ExternalImageSource { ExternalImageSource::ImageData(i) => i.width(), ExternalImageSource::HTMLCanvasElement(c) => c.width(), ExternalImageSource::OffscreenCanvas(c) => c.width(), + #[cfg(web_sys_unstable_apis)] + ExternalImageSource::VideoFrame(v) => v.display_width(), } } @@ -6896,6 +6901,8 @@ impl ExternalImageSource { ExternalImageSource::ImageData(i) => i.height(), ExternalImageSource::HTMLCanvasElement(c) => c.height(), ExternalImageSource::OffscreenCanvas(c) => c.height(), + #[cfg(web_sys_unstable_apis)] + ExternalImageSource::VideoFrame(v) => v.display_height(), } } } @@ -6912,6 +6919,8 @@ impl std::ops::Deref for ExternalImageSource { Self::ImageData(i) => i, Self::HTMLCanvasElement(c) => c, Self::OffscreenCanvas(c) => c, + #[cfg(web_sys_unstable_apis)] + Self::VideoFrame(v) => v, } } }