Send an IpcSharedMemory in tex_image_2d and tex_sub_image_2d

This avoids a copy in the case of textures coming from HTMLImageElement.
This commit is contained in:
Anthony Ramine 2018-11-19 12:36:45 +01:00
parent cfca906ee2
commit 804d964b7d
4 changed files with 56 additions and 38 deletions

View file

@ -10,6 +10,7 @@ use crate::dom::bindings::root::DomRoot;
use crate::dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
use euclid::{Rect, Size2D};
use ipc_channel::ipc::IpcSharedMemory;
use js::jsapi::{Heap, JSContext, JSObject};
use js::rust::Runtime;
use js::typedarray::{CreateWith, Uint8ClampedArray};
@ -156,8 +157,8 @@ impl ImageData {
}
#[allow(unsafe_code)]
pub fn to_vec(&self) -> Vec<u8> {
unsafe { self.as_slice().into() }
pub fn to_shared_memory(&self) -> IpcSharedMemory {
IpcSharedMemory::from_bytes(unsafe { self.as_slice() })
}
#[allow(unsafe_code)]