mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
webgl: Honor ArrayBuffer or ArrayBufferView in bufferData and bufferSubData.
This commit is contained in:
parent
7a559ad442
commit
d7e2b40484
2 changed files with 40 additions and 5 deletions
|
@ -48,7 +48,7 @@ use js::glue::{RUST_JSID_IS_INT, RUST_JSID_TO_INT};
|
|||
use js::glue::{RUST_JSID_IS_STRING, RUST_JSID_TO_STRING, UnwrapObject};
|
||||
use js::jsapi::{HandleId, HandleObject, HandleValue, JSClass, JSContext};
|
||||
use js::jsapi::{JSObject, JSString, JS_GetArrayBufferViewType, JS_GetClass};
|
||||
use js::jsapi::{JS_GetLatin1StringCharsAndLength, JS_GetObjectAsArrayBufferView};
|
||||
use js::jsapi::{JS_GetLatin1StringCharsAndLength, JS_GetObjectAsArrayBuffer, JS_GetObjectAsArrayBufferView};
|
||||
use js::jsapi::{JS_GetReservedSlot, JS_GetTwoByteStringCharsAndLength, ToWindowProxyIfWindow};
|
||||
use js::jsapi::{JS_IsArrayObject, JS_NewStringCopyN, JS_StringHasLatin1Chars};
|
||||
use js::jsapi::{JS_WrapValue, MutableHandleValue, Type, IsObjectInContextCompartment};
|
||||
|
@ -580,6 +580,29 @@ pub unsafe fn array_buffer_view_to_vec_checked<T>(abv: *mut JSObject) -> Option<
|
|||
array_buffer_view_data_checked(abv).map(|data| data.to_vec())
|
||||
}
|
||||
|
||||
/// Similar API as the array_buffer_view_xxx functions, but for ArrayBuffer
|
||||
/// objects.
|
||||
pub unsafe fn array_buffer_data<'a, T>(ab: *mut JSObject) -> Option<&'a mut [T]>
|
||||
where T: ArrayBufferViewContents
|
||||
{
|
||||
assert!(!ab.is_null());
|
||||
|
||||
let mut byte_length = 0;
|
||||
let mut ptr = ptr::null_mut();
|
||||
let ret = JS_GetObjectAsArrayBuffer(ab, &mut byte_length, &mut ptr);
|
||||
if ret.is_null() {
|
||||
return None;
|
||||
}
|
||||
Some(slice::from_raw_parts_mut(ptr as *mut T, byte_length as usize / mem::size_of::<T>()))
|
||||
}
|
||||
|
||||
/// Similar API to array_buffer_view_to_vec, but for ArrayBuffer objects.
|
||||
pub unsafe fn array_buffer_to_vec<T>(ab: *mut JSObject) -> Option<Vec<T>>
|
||||
where T: ArrayBufferViewContents
|
||||
{
|
||||
array_buffer_data(ab).map(|data| data.to_vec())
|
||||
}
|
||||
|
||||
/// Returns whether `value` is an array-like object.
|
||||
/// Note: Currently only Arrays are supported.
|
||||
/// TODO: Expand this to support sequences and other array-like objects
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue