mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Add constructors for typed arrays in DOMMatrix and DOMMatrixReadOnly
This commit is contained in:
parent
18ef5874dd
commit
6d08027890
7 changed files with 328 additions and 431 deletions
|
@ -15,8 +15,14 @@ use dom::dompoint::DOMPoint;
|
|||
use dom::globalscope::GlobalScope;
|
||||
use dom_struct::dom_struct;
|
||||
use euclid::{Transform3D, Angle};
|
||||
use js::jsapi::{JSObject, JSContext};
|
||||
use js::rust::CustomAutoRooterGuard;
|
||||
use js::typedarray::{Float32Array, Float64Array};
|
||||
use js::typedarray::CreateWith;
|
||||
use std::cell::{Cell, Ref};
|
||||
use std::f64;
|
||||
use std::ptr;
|
||||
use std::ptr::NonNull;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct DOMMatrixReadOnly {
|
||||
|
@ -334,6 +340,27 @@ impl DOMMatrixReadOnly {
|
|||
})
|
||||
// Step 3 in DOMMatrix.InvertSelf
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-fromfloat32array
|
||||
#[allow(unsafe_code)]
|
||||
pub fn FromFloat32Array(
|
||||
global: &GlobalScope,
|
||||
mut array: CustomAutoRooterGuard<Float32Array>)
|
||||
-> Fallible<DomRoot<DOMMatrixReadOnly>> {
|
||||
let vec: Vec<f64> = array.to_vec().iter().map(|&x| x as f64).collect();
|
||||
DOMMatrixReadOnly::Constructor_(global, vec)
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-fromfloat64array
|
||||
#[allow(unsafe_code)]
|
||||
pub fn FromFloat64Array(
|
||||
global: &GlobalScope,
|
||||
mut array: CustomAutoRooterGuard<Float64Array>)
|
||||
-> Fallible<DomRoot<DOMMatrixReadOnly>> {
|
||||
let vec: Vec<f64> = array.to_vec();
|
||||
DOMMatrixReadOnly::Constructor_(global, vec)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -553,6 +580,27 @@ impl DOMMatrixReadOnlyMethods for DOMMatrixReadOnly {
|
|||
|
||||
DOMPoint::new(&self.global(), x, y, z, w)
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-tofloat32array
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn ToFloat32Array(&self, cx: *mut JSContext) -> NonNull<JSObject> {
|
||||
let vec: Vec<f32> = self.matrix
|
||||
.borrow().to_row_major_array().iter().map(|&x| x as f32).collect();
|
||||
rooted!(in (cx) let mut array = ptr::null_mut::<JSObject>());
|
||||
let _ = Float32Array::create(cx, CreateWith::Slice(&vec), array.handle_mut())
|
||||
.unwrap();
|
||||
NonNull::new_unchecked(array.get())
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-tofloat64array
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn ToFloat64Array(&self, cx: *mut JSContext) -> NonNull<JSObject> {
|
||||
let arr = self.matrix.borrow().to_row_major_array();
|
||||
rooted!(in (cx) let mut array = ptr::null_mut::<JSObject>());
|
||||
let _ = Float64Array::create(cx, CreateWith::Slice(&arr), array.handle_mut())
|
||||
.unwrap();
|
||||
NonNull::new_unchecked(array.get())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue