web: Disable alpha on canvas

This commit is contained in:
Mike Welsh 2019-08-19 23:33:12 -07:00
parent dd3748a520
commit d021b02e90
1 changed files with 10 additions and 1 deletions

View File

@ -32,8 +32,17 @@ struct BitmapData {
impl WebCanvasRenderBackend {
pub fn new(canvas: &HtmlCanvasElement) -> Result<Self, Box<dyn std::error::Error>> {
// Request the CanvasRenderingContext2d.
// Disable alpha for possible speedup.
// TODO: Allow user to enable transparent background (transparent wmode in legacy Flash).
let context_options = js_sys::Object::new();
let _ = js_sys::Reflect::set(
&context_options,
&"alpha".into(),
&wasm_bindgen::JsValue::FALSE,
);
let context: CanvasRenderingContext2d = canvas
.get_context("2d")
.get_context_with_context_options("2d", &context_options)
.map_err(|_| "Could not create context")?
.ok_or("Could not create context")?
.dyn_into()