Skip to content

Commit 724b447

Browse files
authored
Use new web_sys Uint8ClampedArray bindings (#4184)
1 parent bc85317 commit 724b447

File tree

1 file changed

+2
-11
lines changed
  • examples/raytrace-parallel/src

1 file changed

+2
-11
lines changed

examples/raytrace-parallel/src/lib.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use futures_channel::oneshot;
22
use js_sys::{Promise, Uint8ClampedArray, WebAssembly};
33
use rayon::prelude::*;
44
use wasm_bindgen::prelude::*;
5+
use web_sys::ImageData;
56

67
macro_rules! console_log {
78
($($t:tt)*) => (crate::log(&format_args!($($t)*).to_string()))
@@ -117,16 +118,6 @@ pub struct RenderingScene {
117118
height: u32,
118119
}
119120

120-
// Inline the definition of `ImageData` here because `web_sys` uses
121-
// `&Clamped<Vec<u8>>`, whereas we want to pass in a JS object here.
122-
#[wasm_bindgen]
123-
extern "C" {
124-
pub type ImageData;
125-
126-
#[wasm_bindgen(constructor, catch)]
127-
fn new(data: &Uint8ClampedArray, width: f64, height: f64) -> Result<ImageData, JsValue>;
128-
}
129-
130121
#[wasm_bindgen]
131122
impl RenderingScene {
132123
/// Returns the JS promise object which resolves when the render is complete
@@ -157,5 +148,5 @@ fn image_data(base: usize, len: usize, width: u32, height: u32) -> ImageData {
157148
// could ensure that even on the Rust side of things it's not UB.
158149
let mem = wasm_bindgen::memory().unchecked_into::<WebAssembly::Memory>();
159150
let mem = Uint8ClampedArray::new(&mem.buffer()).slice(base as u32, (base + len) as u32);
160-
ImageData::new(&mem, width as f64, height as f64).unwrap()
151+
ImageData::new_with_js_u8_clamped_array_and_sh(&mem, width, height).unwrap()
161152
}

0 commit comments

Comments
 (0)