Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Option<T> to return from getters #13100

Merged
merged 6 commits into from Aug 31, 2016

Don't bother with the global in ImageData::get_image_data

  • Loading branch information
nox committed Aug 30, 2016
commit 2400b91d05fe314879718b6183a5e40c37dbbdd5
@@ -1100,7 +1100,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
dirtyY: Finite<f64>,
dirtyWidth: Finite<f64>,
dirtyHeight: Finite<f64>) {
let data = imagedata.get_data_array(&self.global().r());
let data = imagedata.get_data_array();
let offset = Point2D::new(*dx, *dy);
let image_data_size = Size2D::new(imagedata.Width() as f64, imagedata.Height() as f64);

@@ -273,11 +273,10 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
// Step 3.
let raw_data = match *self.context.borrow() {
Some(CanvasContext::Context2d(ref context)) => {
let window = window_from_node(self);
let image_data = try!(context.GetImageData(Finite::wrap(0f64), Finite::wrap(0f64),
Finite::wrap(self.Width() as f64),
Finite::wrap(self.Height() as f64)));
image_data.get_data_array(&GlobalRef::Window(window.r()))
image_data.get_data_array()
}
None => {
// Each pixel is fully-transparent black.
@@ -53,12 +53,12 @@ impl ImageData {
}

#[allow(unsafe_code)]
pub fn get_data_array(&self, global: &GlobalRef) -> Vec<u8> {
pub fn get_data_array(&self) -> Vec<u8> {
unsafe {
let cx = global.get_cx();
let mut is_shared = false;
assert!(!self.data.get().is_null());
let data: *const uint8_t =
JS_GetUint8ClampedArrayData(self.Data(cx), &mut is_shared, ptr::null()) as *const uint8_t;
JS_GetUint8ClampedArrayData(self.data.get(), &mut is_shared, ptr::null()) as *const uint8_t;
assert!(!data.is_null());
assert!(!is_shared);
let len = self.Width() * self.Height() * 4;
@@ -305,8 +305,7 @@ impl WebGLRenderingContext {
// complexity is worth it.
let (pixels, size) = match source {
ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement::ImageData(image_data) => {
let global = self.global();
(image_data.get_data_array(&global.r()), image_data.get_size())
(image_data.get_data_array(), image_data.get_size())
},
ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement::HTMLImageElement(image) => {
let img_url = match image.get_url() {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.