aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTaym Haddadi <haddadi.taym@gmail.com>2024-01-17 09:14:35 +0100
committerGitHub <noreply@github.com>2024-01-17 08:14:35 +0000
commit6a7b450478f69d9d83b0936a0ab28ac2d94761d4 (patch)
tree82ae47a03ec8ccb43c2785be8bf9d25b24401775
parent55bf020d8989c732b095b9e330bc55369f11d432 (diff)
downloadservo-6a7b450478f69d9d83b0936a0ab28ac2d94761d4.tar.gz
servo-6a7b450478f69d9d83b0936a0ab28ac2d94761d4.zip
use FLoat32Array in XRRigidTransform (#31076)
Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com>
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py2
-rw-r--r--components/script/dom/xrrigidtransform.rs27
2 files changed, 14 insertions, 15 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 8f341e0d8bc..7a10abba220 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -1461,7 +1461,7 @@ def getConversionConfigForType(type, isEnforceRange, isClamp, treatNullAs):
def todo_switch_float_32(des):
- return des.interface.identifier.name in ['XRRigidTransform', 'XRRay', 'GamepadPose']
+ return des.interface.identifier.name in ['XRRay', 'GamepadPose']
def builtin_return_type(returnType):
diff --git a/components/script/dom/xrrigidtransform.rs b/components/script/dom/xrrigidtransform.rs
index 3fabb23a297..42ad6f9fd70 100644
--- a/components/script/dom/xrrigidtransform.rs
+++ b/components/script/dom/xrrigidtransform.rs
@@ -2,19 +2,17 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
-use std::ptr::NonNull;
-
use dom_struct::dom_struct;
use euclid::{RigidTransform3D, Rotation3D, Vector3D};
-use js::jsapi::{Heap, JSObject};
use js::rust::HandleObject;
+use js::typedarray::Float32Array;
use crate::dom::bindings::codegen::Bindings::DOMPointBinding::DOMPointInit;
use crate::dom::bindings::codegen::Bindings::XRRigidTransformBinding::XRRigidTransformMethods;
use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::reflector::{reflect_dom_object_with_proto, DomObject, Reflector};
use crate::dom::bindings::root::{DomRoot, MutNullableDom};
-use crate::dom::bindings::utils::create_typed_array;
+use crate::dom::bindings::typedarrays::HeapFloat32Array;
use crate::dom::dompointreadonly::DOMPointReadOnly;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
@@ -31,7 +29,7 @@ pub struct XRRigidTransform {
transform: ApiRigidTransform,
inverse: MutNullableDom<XRRigidTransform>,
#[ignore_malloc_size_of = "defined in mozjs"]
- matrix: Heap<*mut JSObject>,
+ matrix: HeapFloat32Array,
}
impl XRRigidTransform {
@@ -42,7 +40,7 @@ impl XRRigidTransform {
orientation: MutNullableDom::default(),
transform,
inverse: MutNullableDom::default(),
- matrix: Heap::default(),
+ matrix: HeapFloat32Array::default(),
}
}
@@ -134,15 +132,16 @@ impl XRRigidTransformMethods for XRRigidTransform {
})
}
// https://immersive-web.github.io/webxr/#dom-xrrigidtransform-matrix
- fn Matrix(&self, _cx: JSContext) -> NonNull<JSObject> {
- if self.matrix.get().is_null() {
- let cx = GlobalScope::get_cx();
- // According to the spec all matrices are column-major,
- // however euclid uses row vectors so we use .to_array()
- let arr = self.transform.to_transform().to_array();
- create_typed_array(cx, &arr, &self.matrix);
+ fn Matrix(&self, _cx: JSContext) -> Float32Array {
+ if !self.matrix.is_initialized() {
+ self.matrix
+ .set_data(_cx, &self.transform.to_transform().to_array())
+ .expect("Failed to set on data on transform's internal matrix.")
}
- NonNull::new(self.matrix.get()).unwrap()
+
+ self.matrix
+ .get_internal()
+ .expect("Failed to get transform's internal matrix.")
}
}