Skip to content
Permalink
Browse files
added getter function for bitmap_data and origin_clean
  • Loading branch information
ramyananth committed Apr 24, 2020
1 parent ff05e82 commit 6696e08ce889c59ca5372494e40a48f5ef6612bb
Showing 2 changed files with 25 additions and 12 deletions.
@@ -42,6 +42,14 @@ impl ImageBitmap {

Ok(reflect_dom_object(imagebitmap, global))
}

pub fn set_bitmap_data(&self, data: DomRefCell<Vec<u8>>) {
self.bitmap_data = data;
}

pub fn set_origin_clean(&self, origin_is_clean: Cell<bool>) {
self.origin_clean = origin_is_clean;
}
}

impl ImageBitmapMethods for ImageBitmap {
@@ -140,9 +140,8 @@ use style_traits::{CSSPixel, DevicePixel, ParsingMode};
use url::Position;
use webrender_api::units::{DeviceIntPoint, DeviceIntSize, LayoutPixel};
use webrender_api::{DocumentId, ExternalScrollId};
// use crate::canvas_state::CanvasState;
use crate::dom::bindings::codegen::Bindings::ImageBitmapBinding::{ImageBitmapSource, ImageBitmapOptions};
// use crate::dom::element::cors_setting_for_element;
use crate::dom::bindings::reflector::Reflector;

/// Current state of the window object
#[derive(Clone, Copy, Debug, JSTraceable, MallocSizeOf, PartialEq)]
@@ -906,27 +905,33 @@ impl WindowMethods for Window {
p.reject_error(Error::InvalidState)
}

let mut imageBitmap = ImageBitmap::new(&global, 0, 0, Cell::new(true));
let mut imageBitmap = ImageBitmap {
reflector_: Reflector::new(),
width: 0,
height: 0,
bitmap_data: DomRefCell::new(vec![]),
origin_clean: Cell::new(true),
};

//let result = match image {
let promise = match image {
ImageBitmapSource::HTMLCanvasElement(ref canvas) => {
// https://html.spec.whatwg.org/multipage/#check-the-usability-of-the-image-argument
if !canvas.is_valid() {
p.reject_error(Error::InvalidState)
}
// let url = self.get_url().into_string();
// let url = canvas.get_url().ok_or(Error::InvalidState);
// let cors_setting = cors_setting_for_element(canvas.upcast());

let (data, size) = canvas.fetch_all_data();
imageBitmap.bitmap_data = data;
imageBitmap.origin_clean = canvas.origin_clean;
let Some((data, size)) = canvas.fetch_all_data();
let data = DomRefCell::new(data
.map(|data| data.to_vec())
.unwrap_or_else(|| vec![0; size.area() as usize * 4]));

let origin_is_clean = Cell::new(canvas.origin_is_clean());
imageBitmap.set_bitmap_data(data);
imageBitmap.set_origin_clean(origin_is_clean);
p.resolve_native(&(imageBitmap));
p
}
};
promise
p
}

// https://html.spec.whatwg.org/multipage/#dom-window

0 comments on commit 6696e08

Please sign in to comment.