Open
Description
It looks like drawing with wasm is way slower than it needs to be. I'm using tiny-skia and it takes 14ms just to present a 1000x1000 picture:
doing this I could draw way faster:
#[cfg(target_arch = "wasm32")]
fn draw_buffer_web(win: &Window, pixmap: &Pixmap) {
use wasm_bindgen::prelude::*;
web_sys::console::log_1(&"draw_buffer_web".into());
let canvas = get_a_canvas(win);
let ctx: web_sys::CanvasRenderingContext2d = canvas
.get_context("2d")
.expect("Failed to get 2d context")
.expect("Failed to get 2d context")
.dyn_into()
.expect("Failed to convert to CanvasRenderingContext2d");
let width = pixmap.width();
let clamped = wasm_bindgen::Clamped(pixmap.data());
let image = web_sys::ImageData::new_with_u8_clamped_array(clamped, width)
.expect("Failed to create image data");
ctx.put_image_data(&image, 0.0, 0.0)
.expect("Failed to put image data");
fn get_a_canvas(win: &Window) -> web_sys::HtmlCanvasElement {
use winit::platform::web::WindowExtWebSys;
win.canvas().expect("Failed to get canvas")
}
}
It looks like the current present_with_damage
function iterates throught the whole buffer and makes a copy each time. Wouldn't it be possible to just take in some buffer and present it with no copies or individual byte manipulation?