Skip to content

Commit

Permalink
Add VideoFrame to ExternalImageSource enum (gfx-rs#6170)
Browse files Browse the repository at this point in the history
  • Loading branch information
jprochazk authored Aug 27, 2024
1 parent 690a3fb commit 5deaef3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 30 additions & 0 deletions wgpu-hal/src/gles/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions wgpu-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ js-sys.workspace = true
web-sys = { workspace = true, features = [
"ImageBitmap",
"ImageData",
"HtmlImageElement",
"HtmlVideoElement",
"HtmlCanvasElement",
"OffscreenCanvas",
"VideoFrame",
] }

[dev-dependencies]
Expand Down
9 changes: 9 additions & 0 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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(),
}
}

Expand All @@ -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(),
}
}
}
Expand All @@ -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,
}
}
}
Expand Down

0 comments on commit 5deaef3

Please sign in to comment.