mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Fix ArrayBuffer creation in buffer mapping
This commit is contained in:
parent
b484836dbc
commit
db2d313a1b
2 changed files with 10 additions and 10 deletions
|
@ -19,7 +19,6 @@ use dom_struct::dom_struct;
|
|||
use js::jsapi::{Heap, JSObject};
|
||||
use js::jsval::UndefinedValue;
|
||||
use js::rust::jsapi_wrapped::{DetachArrayBuffer, IsPromiseObject, RejectPromise};
|
||||
use js::rust::MutableHandle;
|
||||
use js::typedarray::{ArrayBuffer, CreateWith};
|
||||
use std::cell::Cell;
|
||||
use std::ops::Range;
|
||||
|
@ -277,12 +276,10 @@ impl AsyncWGPUListener for GPUBuffer {
|
|||
fn handle_response(&self, response: WebGPUResponse, promise: &Rc<Promise>) {
|
||||
match response {
|
||||
WebGPUResponse::BufferMapAsync(bytes) => {
|
||||
let cx = self.global().get_cx();
|
||||
rooted!(in(*cx) let mut array_buffer = ptr::null_mut::<JSObject>());
|
||||
match unsafe {
|
||||
ArrayBuffer::create(
|
||||
*self.global().get_cx(),
|
||||
CreateWith::Slice(&bytes),
|
||||
MutableHandle::from_raw(self.mapping.handle_mut()),
|
||||
)
|
||||
ArrayBuffer::create(*cx, CreateWith::Slice(&bytes), array_buffer.handle_mut())
|
||||
} {
|
||||
Ok(_) => promise.resolve_native(&()),
|
||||
Err(()) => {
|
||||
|
@ -293,6 +290,7 @@ impl AsyncWGPUListener for GPUBuffer {
|
|||
promise.reject_error(Error::Operation);
|
||||
},
|
||||
}
|
||||
self.mapping.set(array_buffer.get());
|
||||
self.state.set(GPUBufferState::Mapped);
|
||||
},
|
||||
_ => {
|
||||
|
|
|
@ -54,9 +54,8 @@ use crate::script_runtime::JSContext as SafeJSContext;
|
|||
use arrayvec::ArrayVec;
|
||||
use dom_struct::dom_struct;
|
||||
use js::jsapi::{Heap, JSObject};
|
||||
use js::rust::MutableHandle;
|
||||
use js::typedarray::{ArrayBuffer, CreateWith};
|
||||
use std::ptr::NonNull;
|
||||
use std::ptr::{self, NonNull};
|
||||
use webgpu::wgpu::binding_model::BufferBinding;
|
||||
use webgpu::{self, wgt, WebGPU, WebGPUBindings, WebGPURequest};
|
||||
|
||||
|
@ -182,14 +181,17 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
let state;
|
||||
let mapping_range;
|
||||
if descriptor.mappedAtCreation {
|
||||
let cx = self.global().get_cx();
|
||||
rooted!(in(*cx) let mut array_buffer = ptr::null_mut::<JSObject>());
|
||||
unsafe {
|
||||
assert!(ArrayBuffer::create(
|
||||
*self.global().get_cx(),
|
||||
*cx,
|
||||
CreateWith::Length(descriptor.size as u32),
|
||||
MutableHandle::from_raw(mapping.handle_mut()),
|
||||
array_buffer.handle_mut(),
|
||||
)
|
||||
.is_ok());
|
||||
}
|
||||
mapping.set(array_buffer.get());
|
||||
state = GPUBufferState::MappedAtCreation;
|
||||
mapping_range = 0..descriptor.size;
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue