Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send an IpcSharedMemory in tex_image_2d and tex_sub_image_2d #22225

Merged
merged 9 commits into from Nov 21, 2018
Prev

Make HTMLCanvasElement::fetch_all_data return a shared memory blob

  • Loading branch information
nox committed Nov 21, 2018
commit 9a8d03a0f3047d8408b2368d46d144fea670f95d
@@ -13,9 +13,8 @@ use azure::azure_hl::{ExtendMode, GradientStop, LinearGradientPattern, RadialGra
use canvas_traits::canvas::*;
use cssparser::RGBA;
use euclid::{Point2D, Rect, Size2D, Transform2D, Vector2D};
use ipc_channel::ipc::IpcSender;
use ipc_channel::ipc::{IpcSender, IpcSharedMemory};
use num_traits::ToPrimitive;
use serde_bytes::ByteBuf;
use std::mem;
use std::sync::Arc;

@@ -451,15 +450,11 @@ impl<'a> CanvasData<'a> {
}

#[allow(unsafe_code)]
pub fn send_pixels(&mut self, chan: IpcSender<Option<ByteBuf>>) {
let data = unsafe {
self.drawtarget
.snapshot()
.get_data_surface()
.data()
.to_vec()
};
chan.send(Some(data.into())).unwrap();
pub fn send_pixels(&mut self, chan: IpcSender<IpcSharedMemory>) {
let data = IpcSharedMemory::from_bytes(unsafe {
self.drawtarget.snapshot().get_data_surface().data()
});
chan.send(data).unwrap();
}

#[allow(unsafe_code)]
@@ -4,7 +4,7 @@

use cssparser::RGBA;
use euclid::{Point2D, Rect, Size2D, Transform2D};
use ipc_channel::ipc::{IpcBytesReceiver, IpcBytesSender, IpcSender};
use ipc_channel::ipc::{IpcBytesReceiver, IpcBytesSender, IpcSender, IpcSharedMemory};
use serde_bytes::ByteBuf;
use std::default::Default;
use std::str::FromStr;
@@ -87,7 +87,7 @@ pub enum FromLayoutMsg {

#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum FromScriptMsg {
SendPixels(IpcSender<Option<ByteBuf>>),
SendPixels(IpcSender<IpcSharedMemory>),
}

#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
@@ -1296,7 +1296,11 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
.ok_or(Error::InvalidState)?
},
CanvasImageSource::HTMLCanvasElement(ref canvas) => {
canvas.fetch_all_data().ok_or(Error::InvalidState)?
let (data, size) = canvas.fetch_all_data().ok_or(Error::InvalidState)?;
let data = data
.map(|data| data.to_vec())
.unwrap_or_else(|| vec![0; size.area() as usize * 4]);
(data, size)
},
CanvasImageSource::CSSStyleValue(ref value) => value
.get_url(self.base_url.clone())
@@ -36,6 +36,7 @@ use euclid::{Rect, Size2D};
use html5ever::{LocalName, Prefix};
use image::png::PNGEncoder;
use image::ColorType;
use ipc_channel::ipc::IpcSharedMemory;
use js::error::throw_type_error;
use js::jsapi::JSContext;
use js::rust::HandleValue;
@@ -280,7 +281,7 @@ impl HTMLCanvasElement {
self.Height() != 0 && self.Width() != 0
}

pub fn fetch_all_data(&self) -> Option<(Vec<u8>, Size2D<u32>)> {
pub fn fetch_all_data(&self) -> Option<(Option<IpcSharedMemory>, Size2D<u32>)> {
let size = self.get_size();

if size.width == 0 || size.height == 0 {
@@ -297,7 +298,7 @@ impl HTMLCanvasElement {
);
context.get_ipc_renderer().send(msg).unwrap();

receiver.recv().unwrap()?.into()
Some(receiver.recv().unwrap())
},
Some(&CanvasContext::WebGL(_)) => {
// TODO: add a method in WebGLRenderingContext to get the pixels.
@@ -307,7 +308,7 @@ impl HTMLCanvasElement {
// TODO: add a method in WebGL2RenderingContext to get the pixels.
return None;
},
None => vec![0; size.height as usize * size.width as usize * 4],
None => None,
};

Some((data, size))
@@ -569,12 +569,10 @@ impl WebGLRenderingContext {
return Err(Error::Security);
}
if let Some((data, size)) = canvas.fetch_all_data() {
TexPixels::new(
IpcSharedMemory::from_bytes(&data),
size,
PixelFormat::BGRA8,
true,
)
let data = data.unwrap_or_else(|| {
IpcSharedMemory::from_bytes(&vec![0; size.area() as usize * 4])
});
TexPixels::new(data, size, PixelFormat::BGRA8, true)
} else {
return Ok(None);
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.