зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #15427 - Remove slice_to_array_buffer_view and update_array_buffer_view (from deror1869107:rewrite-webvr); r=jdm
<!-- Please describe your changes on the following line: --> Remove slice_to_array_buffer_view and update_array_buffer_view --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #15350 - [X] These changes do not require tests <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 1ab3c34dd937ab36ce6bf56e70f09f823c240fe0 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 65bf22e3a248dd52c491ffff7284f0f0922e8997
This commit is contained in:
Родитель
ac2e7f6e66
Коммит
8f852214e1
|
@ -580,23 +580,3 @@ pub unsafe fn is_array_like(cx: *mut JSContext, value: HandleValue) -> bool {
|
|||
assert!(JS_IsArrayObject(cx, value, &mut result));
|
||||
result
|
||||
}
|
||||
|
||||
/// Creates a typed JS array from a Rust slice
|
||||
pub unsafe fn slice_to_array_buffer_view<T>(cx: *mut JSContext, data: &[T]) -> *mut JSObject
|
||||
where T: ArrayBufferViewContents
|
||||
{
|
||||
let js_object = T::new(cx, data.len() as u32);
|
||||
assert!(!js_object.is_null());
|
||||
update_array_buffer_view(js_object, data);
|
||||
js_object
|
||||
}
|
||||
|
||||
/// Updates a typed JS array from a Rust slice
|
||||
pub unsafe fn update_array_buffer_view<T>(obj: *mut JSObject, data: &[T])
|
||||
where T: ArrayBufferViewContents
|
||||
{
|
||||
let mut buffer = array_buffer_view_data(obj);
|
||||
if let Some(ref mut buffer) = buffer {
|
||||
ptr::copy_nonoverlapping(&data[0], &mut buffer[0], data.len())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,12 +6,12 @@ use core::nonzero::NonZero;
|
|||
use dom::bindings::cell::DOMRefCell;
|
||||
use dom::bindings::codegen::Bindings::VREyeParametersBinding;
|
||||
use dom::bindings::codegen::Bindings::VREyeParametersBinding::VREyeParametersMethods;
|
||||
use dom::bindings::conversions::slice_to_array_buffer_view;
|
||||
use dom::bindings::js::{JS, Root};
|
||||
use dom::bindings::reflector::{Reflector, reflect_dom_object};
|
||||
use dom::globalscope::GlobalScope;
|
||||
use dom::vrfieldofview::VRFieldOfView;
|
||||
use js::jsapi::{Heap, JSContext, JSObject};
|
||||
use js::typedarray::Float32Array;
|
||||
use std::default::Default;
|
||||
use webvr_traits::WebVREyeParameters;
|
||||
|
||||
|
@ -39,7 +39,10 @@ impl VREyeParameters {
|
|||
};
|
||||
|
||||
unsafe {
|
||||
result.offset.set(slice_to_array_buffer_view(global.get_cx(), &result.parameters.borrow().offset));
|
||||
let _ = Float32Array::create(global.get_cx(),
|
||||
result.parameters.borrow().offset.len() as u32,
|
||||
Some(&result.parameters.borrow().offset),
|
||||
result.offset.handle_mut());
|
||||
}
|
||||
result
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
use core::nonzero::NonZero;
|
||||
use dom::bindings::codegen::Bindings::VRFrameDataBinding;
|
||||
use dom::bindings::codegen::Bindings::VRFrameDataBinding::VRFrameDataMethods;
|
||||
use dom::bindings::conversions::{slice_to_array_buffer_view, update_array_buffer_view};
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::js::{JS, Root};
|
||||
use dom::bindings::num::Finite;
|
||||
|
@ -14,6 +13,7 @@ use dom::globalscope::GlobalScope;
|
|||
use dom::vrpose::VRPose;
|
||||
use dom::window::Window;
|
||||
use js::jsapi::{Heap, JSContext, JSObject};
|
||||
use js::typedarray::Float32Array;
|
||||
use std::cell::Cell;
|
||||
use webvr_traits::WebVRFrameData;
|
||||
|
||||
|
@ -50,16 +50,23 @@ impl VRFrameData {
|
|||
first_timestamp: Cell::new(0.0)
|
||||
};
|
||||
|
||||
let root = reflect_dom_object(box framedata,
|
||||
global,
|
||||
VRFrameDataBinding::Wrap);
|
||||
|
||||
unsafe {
|
||||
framedata.left_proj.set(slice_to_array_buffer_view(global.get_cx(), &matrix));
|
||||
framedata.left_view.set(slice_to_array_buffer_view(global.get_cx(), &matrix));
|
||||
framedata.right_proj.set(slice_to_array_buffer_view(global.get_cx(), &matrix));
|
||||
framedata.right_view.set(slice_to_array_buffer_view(global.get_cx(), &matrix));
|
||||
let ref framedata = *root;
|
||||
let _ = Float32Array::create(global.get_cx(), matrix.len() as u32, Some(&matrix),
|
||||
framedata.left_proj.handle_mut());
|
||||
let _ = Float32Array::create(global.get_cx(), matrix.len() as u32, Some(&matrix),
|
||||
framedata.left_view.handle_mut());
|
||||
let _ = Float32Array::create(global.get_cx(), matrix.len() as u32, Some(&matrix),
|
||||
framedata.right_proj.handle_mut());
|
||||
let _ = Float32Array::create(global.get_cx(), matrix.len() as u32, Some(&matrix),
|
||||
framedata.right_view.handle_mut());
|
||||
}
|
||||
|
||||
reflect_dom_object(box framedata,
|
||||
global,
|
||||
VRFrameDataBinding::Wrap)
|
||||
root
|
||||
}
|
||||
|
||||
pub fn Constructor(window: &Window) -> Fallible<Root<VRFrameData>> {
|
||||
|
@ -72,10 +79,23 @@ impl VRFrameData {
|
|||
#[allow(unsafe_code)]
|
||||
pub fn update(&self, data: &WebVRFrameData) {
|
||||
unsafe {
|
||||
update_array_buffer_view(self.left_proj.get(), &data.left_projection_matrix);
|
||||
update_array_buffer_view(self.left_view.get(), &data.left_view_matrix);
|
||||
update_array_buffer_view(self.right_proj.get(), &data.right_projection_matrix);
|
||||
update_array_buffer_view(self.right_view.get(), &data.right_view_matrix);
|
||||
let cx = self.global().get_cx();
|
||||
typedarray!(in(cx) let left_proj_array: Float32Array = self.left_proj.get());
|
||||
if let Ok(mut array) = left_proj_array {
|
||||
array.update(&data.left_projection_matrix);
|
||||
}
|
||||
typedarray!(in(cx) let left_view_array: Float32Array = self.left_view.get());
|
||||
if let Ok(mut array) = left_view_array {
|
||||
array.update(&data.left_view_matrix);
|
||||
}
|
||||
typedarray!(in(cx) let right_proj_array: Float32Array = self.right_proj.get());
|
||||
if let Ok(mut array) = right_proj_array {
|
||||
array.update(&data.right_projection_matrix);
|
||||
}
|
||||
typedarray!(in(cx) let right_view_array: Float32Array = self.right_view.get());
|
||||
if let Ok(mut array) = right_view_array {
|
||||
array.update(&data.right_view_matrix);
|
||||
}
|
||||
}
|
||||
self.pose.update(&data.pose);
|
||||
self.timestamp.set(data.timestamp);
|
||||
|
|
|
@ -6,11 +6,11 @@ use core::nonzero::NonZero;
|
|||
use dom::bindings::cell::DOMRefCell;
|
||||
use dom::bindings::codegen::Bindings::VRPoseBinding;
|
||||
use dom::bindings::codegen::Bindings::VRPoseBinding::VRPoseMethods;
|
||||
use dom::bindings::conversions::{slice_to_array_buffer_view, update_array_buffer_view};
|
||||
use dom::bindings::js::Root;
|
||||
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
|
||||
use dom::globalscope::GlobalScope;
|
||||
use js::jsapi::{Heap, JSContext, JSObject};
|
||||
use js::typedarray::Float32Array;
|
||||
use std::ptr;
|
||||
use webvr_traits::webvr;
|
||||
|
||||
|
@ -33,9 +33,12 @@ unsafe fn update_or_create_typed_array(cx: *mut JSContext,
|
|||
match src {
|
||||
Some(ref data) => {
|
||||
if dst.get().is_null() {
|
||||
dst.set(slice_to_array_buffer_view(cx, &data));
|
||||
let _ = Float32Array::create(cx, data.len() as u32, src, dst.handle_mut());
|
||||
} else {
|
||||
update_array_buffer_view(dst.get(), &data);
|
||||
typedarray!(in(cx) let array: Float32Array = dst.get());
|
||||
if let Ok(mut array) = array {
|
||||
array.update(data);
|
||||
}
|
||||
}
|
||||
},
|
||||
None => {
|
||||
|
|
|
@ -6,12 +6,12 @@ use core::nonzero::NonZero;
|
|||
use dom::bindings::cell::DOMRefCell;
|
||||
use dom::bindings::codegen::Bindings::VRStageParametersBinding;
|
||||
use dom::bindings::codegen::Bindings::VRStageParametersBinding::VRStageParametersMethods;
|
||||
use dom::bindings::conversions::{slice_to_array_buffer_view, update_array_buffer_view};
|
||||
use dom::bindings::js::Root;
|
||||
use dom::bindings::num::Finite;
|
||||
use dom::bindings::reflector::{Reflector, reflect_dom_object};
|
||||
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
|
||||
use dom::globalscope::GlobalScope;
|
||||
use js::jsapi::{Heap, JSContext, JSObject};
|
||||
use js::typedarray::Float32Array;
|
||||
use webvr_traits::WebVRStageParameters;
|
||||
|
||||
#[dom_struct]
|
||||
|
@ -34,8 +34,10 @@ impl VRStageParameters {
|
|||
transform: Heap::default()
|
||||
};
|
||||
unsafe {
|
||||
stage.transform.set(slice_to_array_buffer_view(global.get_cx(),
|
||||
&stage.parameters.borrow().sitting_to_standing_transform));
|
||||
let _ = Float32Array::create(global.get_cx(),
|
||||
stage.parameters.borrow().sitting_to_standing_transform.len() as u32,
|
||||
Some(&stage.parameters.borrow().sitting_to_standing_transform),
|
||||
stage.transform.handle_mut());
|
||||
}
|
||||
|
||||
stage
|
||||
|
@ -50,7 +52,11 @@ impl VRStageParameters {
|
|||
#[allow(unsafe_code)]
|
||||
pub fn update(&self, parameters: &WebVRStageParameters) {
|
||||
unsafe {
|
||||
update_array_buffer_view(self.transform.get(), ¶meters.sitting_to_standing_transform);
|
||||
let cx = self.global().get_cx();
|
||||
typedarray!(in(cx) let array: Float32Array = self.transform.get());
|
||||
if let Ok(mut array) = array {
|
||||
array.update(¶meters.sitting_to_standing_transform);
|
||||
}
|
||||
}
|
||||
*self.parameters.borrow_mut() = parameters.clone();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче