mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Auto merge of #20423 - servo:bytes, r=emilio
Use ByteBuf for the canvas messages <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20423) <!-- Reviewable:end -->
This commit is contained in:
commit
9c5bdd932e
19 changed files with 170 additions and 62 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -274,6 +274,7 @@ dependencies = [
|
||||||
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
"num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"offscreen_gl_context 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"offscreen_gl_context 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"serde_bytes 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"servo_config 0.0.1",
|
"servo_config 0.0.1",
|
||||||
"webrender 0.57.0 (git+https://github.com/servo/webrender)",
|
"webrender 0.57.0 (git+https://github.com/servo/webrender)",
|
||||||
"webrender_api 0.57.0 (git+https://github.com/servo/webrender)",
|
"webrender_api 0.57.0 (git+https://github.com/servo/webrender)",
|
||||||
|
@ -292,6 +293,7 @@ dependencies = [
|
||||||
"nonzero 0.0.1",
|
"nonzero 0.0.1",
|
||||||
"offscreen_gl_context 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"offscreen_gl_context 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"serde_bytes 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"servo_config 0.0.1",
|
"servo_config 0.0.1",
|
||||||
"webrender_api 0.57.0 (git+https://github.com/servo/webrender)",
|
"webrender_api 0.57.0 (git+https://github.com/servo/webrender)",
|
||||||
]
|
]
|
||||||
|
@ -1628,6 +1630,7 @@ dependencies = [
|
||||||
"hashglobe 0.1.0",
|
"hashglobe 0.1.0",
|
||||||
"mozjs 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"mozjs 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"selectors 0.19.0",
|
"selectors 0.19.0",
|
||||||
|
"serde_bytes 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"servo_arc 0.1.1",
|
"servo_arc 0.1.1",
|
||||||
"smallbitvec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"smallbitvec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -2509,6 +2512,7 @@ dependencies = [
|
||||||
"script_traits 0.0.1",
|
"script_traits 0.0.1",
|
||||||
"selectors 0.19.0",
|
"selectors 0.19.0",
|
||||||
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"serde_bytes 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"servo_allocator 0.0.1",
|
"servo_allocator 0.0.1",
|
||||||
"servo_arc 0.1.1",
|
"servo_arc 0.1.1",
|
||||||
|
|
|
@ -21,6 +21,7 @@ ipc-channel = "0.10"
|
||||||
log = "0.3.5"
|
log = "0.3.5"
|
||||||
num-traits = "0.1.32"
|
num-traits = "0.1.32"
|
||||||
offscreen_gl_context = { version = "0.15", features = ["serde", "osmesa"] }
|
offscreen_gl_context = { version = "0.15", features = ["serde", "osmesa"] }
|
||||||
|
serde_bytes = "0.10"
|
||||||
servo_config = {path = "../config"}
|
servo_config = {path = "../config"}
|
||||||
webrender = {git = "https://github.com/servo/webrender"}
|
webrender = {git = "https://github.com/servo/webrender"}
|
||||||
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
|
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
|
||||||
|
|
|
@ -13,6 +13,7 @@ use cssparser::RGBA;
|
||||||
use euclid::{Transform2D, Point2D, Vector2D, Rect, Size2D};
|
use euclid::{Transform2D, Point2D, Vector2D, Rect, Size2D};
|
||||||
use ipc_channel::ipc::{self, IpcSender};
|
use ipc_channel::ipc::{self, IpcSender};
|
||||||
use num_traits::ToPrimitive;
|
use num_traits::ToPrimitive;
|
||||||
|
use serde_bytes::ByteBuf;
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -145,9 +146,20 @@ impl<'a> CanvasPaintThread<'a> {
|
||||||
Canvas2dMsg::IsPointInPath(x, y, fill_rule, chan) => {
|
Canvas2dMsg::IsPointInPath(x, y, fill_rule, chan) => {
|
||||||
painter.is_point_in_path(x, y, fill_rule, chan)
|
painter.is_point_in_path(x, y, fill_rule, chan)
|
||||||
},
|
},
|
||||||
Canvas2dMsg::DrawImage(imagedata, image_size, dest_rect, source_rect,
|
Canvas2dMsg::DrawImage(
|
||||||
smoothing_enabled) => {
|
imagedata,
|
||||||
painter.draw_image(imagedata, image_size, dest_rect, source_rect, smoothing_enabled)
|
image_size,
|
||||||
|
dest_rect,
|
||||||
|
source_rect,
|
||||||
|
smoothing_enabled,
|
||||||
|
) => {
|
||||||
|
painter.draw_image(
|
||||||
|
imagedata.into(),
|
||||||
|
image_size,
|
||||||
|
dest_rect,
|
||||||
|
source_rect,
|
||||||
|
smoothing_enabled,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
Canvas2dMsg::DrawImageSelf(image_size, dest_rect, source_rect, smoothing_enabled) => {
|
Canvas2dMsg::DrawImageSelf(image_size, dest_rect, source_rect, smoothing_enabled) => {
|
||||||
painter.draw_image_self(image_size, dest_rect, source_rect, smoothing_enabled)
|
painter.draw_image_self(image_size, dest_rect, source_rect, smoothing_enabled)
|
||||||
|
@ -189,8 +201,19 @@ impl<'a> CanvasPaintThread<'a> {
|
||||||
Canvas2dMsg::SetGlobalComposition(op) => painter.set_global_composition(op),
|
Canvas2dMsg::SetGlobalComposition(op) => painter.set_global_composition(op),
|
||||||
Canvas2dMsg::GetImageData(dest_rect, canvas_size, chan)
|
Canvas2dMsg::GetImageData(dest_rect, canvas_size, chan)
|
||||||
=> painter.image_data(dest_rect, canvas_size, chan),
|
=> painter.image_data(dest_rect, canvas_size, chan),
|
||||||
Canvas2dMsg::PutImageData(imagedata, offset, image_data_size, dirty_rect)
|
Canvas2dMsg::PutImageData(
|
||||||
=> painter.put_image_data(imagedata, offset, image_data_size, dirty_rect),
|
imagedata,
|
||||||
|
offset,
|
||||||
|
image_data_size,
|
||||||
|
dirty_rect,
|
||||||
|
) => {
|
||||||
|
painter.put_image_data(
|
||||||
|
imagedata.into(),
|
||||||
|
offset,
|
||||||
|
image_data_size,
|
||||||
|
dirty_rect,
|
||||||
|
)
|
||||||
|
}
|
||||||
Canvas2dMsg::SetShadowOffsetX(value) => painter.set_shadow_offset_x(value),
|
Canvas2dMsg::SetShadowOffsetX(value) => painter.set_shadow_offset_x(value),
|
||||||
Canvas2dMsg::SetShadowOffsetY(value) => painter.set_shadow_offset_y(value),
|
Canvas2dMsg::SetShadowOffsetY(value) => painter.set_shadow_offset_y(value),
|
||||||
Canvas2dMsg::SetShadowBlur(value) => painter.set_shadow_blur(value),
|
Canvas2dMsg::SetShadowBlur(value) => painter.set_shadow_blur(value),
|
||||||
|
@ -402,7 +425,12 @@ impl<'a> CanvasPaintThread<'a> {
|
||||||
byte_swap(&mut image_data);
|
byte_swap(&mut image_data);
|
||||||
|
|
||||||
let msg = CanvasMsg::Canvas2d(Canvas2dMsg::DrawImage(
|
let msg = CanvasMsg::Canvas2d(Canvas2dMsg::DrawImage(
|
||||||
image_data, source_rect.size, dest_rect, source_rect, smoothing_enabled));
|
image_data.into(),
|
||||||
|
source_rect.size,
|
||||||
|
dest_rect,
|
||||||
|
source_rect,
|
||||||
|
smoothing_enabled,
|
||||||
|
));
|
||||||
renderer.send(msg).unwrap();
|
renderer.send(msg).unwrap();
|
||||||
// We acknowledge to the caller here that the data was sent to the
|
// We acknowledge to the caller here that the data was sent to the
|
||||||
// other canvas so that if JS immediately afterwards try to get the
|
// other canvas so that if JS immediately afterwards try to get the
|
||||||
|
@ -578,9 +606,9 @@ impl<'a> CanvasPaintThread<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_pixels(&mut self, chan: IpcSender<Option<Vec<u8>>>) {
|
fn send_pixels(&mut self, chan: IpcSender<Option<ByteBuf>>) {
|
||||||
self.drawtarget.snapshot().get_data_surface().with_data(|element| {
|
self.drawtarget.snapshot().get_data_surface().with_data(|element| {
|
||||||
chan.send(Some(element.into())).unwrap();
|
chan.send(Some(Vec::from(element).into())).unwrap();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -632,12 +660,17 @@ impl<'a> CanvasPaintThread<'a> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn image_data(&self, dest_rect: Rect<i32>, canvas_size: Size2D<f64>, chan: IpcSender<Vec<u8>>) {
|
fn image_data(
|
||||||
|
&self,
|
||||||
|
dest_rect: Rect<i32>,
|
||||||
|
canvas_size: Size2D<f64>,
|
||||||
|
chan: IpcSender<ByteBuf>,
|
||||||
|
) {
|
||||||
let mut dest_data = self.read_pixels(dest_rect, canvas_size);
|
let mut dest_data = self.read_pixels(dest_rect, canvas_size);
|
||||||
|
|
||||||
// bgra -> rgba
|
// bgra -> rgba
|
||||||
byte_swap(&mut dest_data);
|
byte_swap(&mut dest_data);
|
||||||
chan.send(dest_data).unwrap();
|
chan.send(dest_data.into()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-putimagedata
|
// https://html.spec.whatwg.org/multipage/#dom-context-2d-putimagedata
|
||||||
|
|
|
@ -15,6 +15,7 @@ extern crate ipc_channel;
|
||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
extern crate num_traits;
|
extern crate num_traits;
|
||||||
extern crate offscreen_gl_context;
|
extern crate offscreen_gl_context;
|
||||||
|
extern crate serde_bytes;
|
||||||
extern crate servo_config;
|
extern crate servo_config;
|
||||||
extern crate webrender;
|
extern crate webrender;
|
||||||
extern crate webrender_api;
|
extern crate webrender_api;
|
||||||
|
|
|
@ -8,6 +8,7 @@ use euclid::Size2D;
|
||||||
use fnv::FnvHashMap;
|
use fnv::FnvHashMap;
|
||||||
use gleam::gl;
|
use gleam::gl;
|
||||||
use offscreen_gl_context::{GLContext, GLContextAttributes, GLLimits, NativeGLContextMethods};
|
use offscreen_gl_context::{GLContext, GLContextAttributes, GLLimits, NativeGLContextMethods};
|
||||||
|
use serde_bytes::ByteBuf;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use super::gl_context::{GLContextFactory, GLContextWrapper};
|
use super::gl_context::{GLContextFactory, GLContextWrapper};
|
||||||
use webrender;
|
use webrender;
|
||||||
|
@ -904,10 +905,18 @@ impl WebGLImpl {
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_pixels(gl: &gl::Gl, x: i32, y: i32, width: i32, height: i32, format: u32, pixel_type: u32,
|
fn read_pixels(
|
||||||
chan: WebGLSender<Vec<u8>>) {
|
gl: &gl::Gl,
|
||||||
|
x: i32,
|
||||||
|
y: i32,
|
||||||
|
width: i32,
|
||||||
|
height: i32,
|
||||||
|
format: u32,
|
||||||
|
pixel_type: u32,
|
||||||
|
chan: WebGLSender<ByteBuf>,
|
||||||
|
) {
|
||||||
let result = gl.read_pixels(x, y, width, height, format, pixel_type);
|
let result = gl.read_pixels(x, y, width, height, format, pixel_type);
|
||||||
chan.send(result).unwrap()
|
chan.send(result.into()).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn active_attrib(gl: &gl::Gl,
|
fn active_attrib(gl: &gl::Gl,
|
||||||
|
|
|
@ -19,5 +19,6 @@ malloc_size_of_derive = { path = "../malloc_size_of_derive" }
|
||||||
nonzero = {path = "../nonzero"}
|
nonzero = {path = "../nonzero"}
|
||||||
offscreen_gl_context = { version = "0.15", features = ["serde"] }
|
offscreen_gl_context = { version = "0.15", features = ["serde"] }
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
|
serde_bytes = "0.10"
|
||||||
servo_config = {path = "../config"}
|
servo_config = {path = "../config"}
|
||||||
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
|
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
use cssparser::RGBA;
|
use cssparser::RGBA;
|
||||||
use euclid::{Transform2D, Point2D, Vector2D, Rect, Size2D};
|
use euclid::{Transform2D, Point2D, Vector2D, Rect, Size2D};
|
||||||
use ipc_channel::ipc::IpcSender;
|
use ipc_channel::ipc::IpcSender;
|
||||||
|
use serde_bytes::ByteBuf;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use webrender_api;
|
use webrender_api;
|
||||||
|
@ -33,7 +34,7 @@ pub struct CanvasImageData {
|
||||||
pub enum Canvas2dMsg {
|
pub enum Canvas2dMsg {
|
||||||
Arc(Point2D<f32>, f32, f32, f32, bool),
|
Arc(Point2D<f32>, f32, f32, f32, bool),
|
||||||
ArcTo(Point2D<f32>, Point2D<f32>, f32),
|
ArcTo(Point2D<f32>, Point2D<f32>, f32),
|
||||||
DrawImage(Vec<u8>, Size2D<f64>, Rect<f64>, Rect<f64>, bool),
|
DrawImage(ByteBuf, Size2D<f64>, Rect<f64>, Rect<f64>, bool),
|
||||||
DrawImageSelf(Size2D<f64>, Rect<f64>, Rect<f64>, bool),
|
DrawImageSelf(Size2D<f64>, Rect<f64>, Rect<f64>, bool),
|
||||||
DrawImageInOther(
|
DrawImageInOther(
|
||||||
IpcSender<CanvasMsg>, Size2D<f64>, Rect<f64>, Rect<f64>, bool, IpcSender<()>),
|
IpcSender<CanvasMsg>, Size2D<f64>, Rect<f64>, Rect<f64>, bool, IpcSender<()>),
|
||||||
|
@ -46,11 +47,11 @@ pub enum Canvas2dMsg {
|
||||||
Fill,
|
Fill,
|
||||||
FillText(String, f64, f64, Option<f64>),
|
FillText(String, f64, f64, Option<f64>),
|
||||||
FillRect(Rect<f32>),
|
FillRect(Rect<f32>),
|
||||||
GetImageData(Rect<i32>, Size2D<f64>, IpcSender<Vec<u8>>),
|
GetImageData(Rect<i32>, Size2D<f64>, IpcSender<ByteBuf>),
|
||||||
IsPointInPath(f64, f64, FillRule, IpcSender<bool>),
|
IsPointInPath(f64, f64, FillRule, IpcSender<bool>),
|
||||||
LineTo(Point2D<f32>),
|
LineTo(Point2D<f32>),
|
||||||
MoveTo(Point2D<f32>),
|
MoveTo(Point2D<f32>),
|
||||||
PutImageData(Vec<u8>, Vector2D<f64>, Size2D<f64>, Rect<f64>),
|
PutImageData(ByteBuf, Vector2D<f64>, Size2D<f64>, Rect<f64>),
|
||||||
QuadraticCurveTo(Point2D<f32>, Point2D<f32>),
|
QuadraticCurveTo(Point2D<f32>, Point2D<f32>),
|
||||||
Rect(Rect<f32>),
|
Rect(Rect<f32>),
|
||||||
RestoreContext,
|
RestoreContext,
|
||||||
|
@ -79,7 +80,7 @@ pub enum FromLayoutMsg {
|
||||||
|
|
||||||
#[derive(Clone, Deserialize, Serialize)]
|
#[derive(Clone, Deserialize, Serialize)]
|
||||||
pub enum FromScriptMsg {
|
pub enum FromScriptMsg {
|
||||||
SendPixels(IpcSender<Option<Vec<u8>>>),
|
SendPixels(IpcSender<Option<ByteBuf>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Deserialize, MallocSizeOf, Serialize)]
|
#[derive(Clone, Deserialize, MallocSizeOf, Serialize)]
|
||||||
|
@ -138,20 +139,24 @@ impl RadialGradientStyle {
|
||||||
|
|
||||||
#[derive(Clone, Deserialize, Serialize)]
|
#[derive(Clone, Deserialize, Serialize)]
|
||||||
pub struct SurfaceStyle {
|
pub struct SurfaceStyle {
|
||||||
pub surface_data: Vec<u8>,
|
pub surface_data: ByteBuf,
|
||||||
pub surface_size: Size2D<i32>,
|
pub surface_size: Size2D<i32>,
|
||||||
pub repeat_x: bool,
|
pub repeat_x: bool,
|
||||||
pub repeat_y: bool,
|
pub repeat_y: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SurfaceStyle {
|
impl SurfaceStyle {
|
||||||
pub fn new(surface_data: Vec<u8>, surface_size: Size2D<i32>, repeat_x: bool, repeat_y: bool)
|
pub fn new(
|
||||||
-> SurfaceStyle {
|
surface_data: Vec<u8>,
|
||||||
SurfaceStyle {
|
surface_size: Size2D<i32>,
|
||||||
surface_data: surface_data,
|
repeat_x: bool,
|
||||||
surface_size: surface_size,
|
repeat_y: bool,
|
||||||
repeat_x: repeat_x,
|
) -> Self {
|
||||||
repeat_y: repeat_y,
|
Self {
|
||||||
|
surface_data: surface_data.into(),
|
||||||
|
surface_size,
|
||||||
|
repeat_x,
|
||||||
|
repeat_y,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ extern crate malloc_size_of;
|
||||||
extern crate nonzero;
|
extern crate nonzero;
|
||||||
extern crate offscreen_gl_context;
|
extern crate offscreen_gl_context;
|
||||||
#[macro_use] extern crate serde;
|
#[macro_use] extern crate serde;
|
||||||
|
extern crate serde_bytes;
|
||||||
extern crate servo_config;
|
extern crate servo_config;
|
||||||
extern crate webrender_api;
|
extern crate webrender_api;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
use euclid::Size2D;
|
use euclid::Size2D;
|
||||||
use nonzero::NonZero;
|
use nonzero::NonZero;
|
||||||
use offscreen_gl_context::{GLContextAttributes, GLLimits};
|
use offscreen_gl_context::{GLContextAttributes, GLLimits};
|
||||||
|
use serde_bytes::ByteBuf;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use webrender_api::{DocumentId, ImageKey, PipelineId};
|
use webrender_api::{DocumentId, ImageKey, PipelineId};
|
||||||
|
|
||||||
|
@ -165,8 +166,8 @@ pub enum WebGLCommand {
|
||||||
AttachShader(WebGLProgramId, WebGLShaderId),
|
AttachShader(WebGLProgramId, WebGLShaderId),
|
||||||
DetachShader(WebGLProgramId, WebGLShaderId),
|
DetachShader(WebGLProgramId, WebGLShaderId),
|
||||||
BindAttribLocation(WebGLProgramId, u32, String),
|
BindAttribLocation(WebGLProgramId, u32, String),
|
||||||
BufferData(u32, Vec<u8>, u32),
|
BufferData(u32, ByteBuf, u32),
|
||||||
BufferSubData(u32, isize, Vec<u8>),
|
BufferSubData(u32, isize, ByteBuf),
|
||||||
Clear(u32),
|
Clear(u32),
|
||||||
ClearColor(f32, f32, f32, f32),
|
ClearColor(f32, f32, f32, f32),
|
||||||
ClearDepth(f64),
|
ClearDepth(f64),
|
||||||
|
@ -222,7 +223,7 @@ pub enum WebGLCommand {
|
||||||
GetFramebufferAttachmentParameter(u32, u32, u32, WebGLSender<i32>),
|
GetFramebufferAttachmentParameter(u32, u32, u32, WebGLSender<i32>),
|
||||||
PolygonOffset(f32, f32),
|
PolygonOffset(f32, f32),
|
||||||
RenderbufferStorage(u32, u32, i32, i32),
|
RenderbufferStorage(u32, u32, i32, i32),
|
||||||
ReadPixels(i32, i32, i32, i32, u32, u32, WebGLSender<Vec<u8>>),
|
ReadPixels(i32, i32, i32, i32, u32, u32, WebGLSender<ByteBuf>),
|
||||||
SampleCoverage(f32, bool),
|
SampleCoverage(f32, bool),
|
||||||
Scissor(i32, i32, i32, i32),
|
Scissor(i32, i32, i32, i32),
|
||||||
StencilFunc(u32, i32, u32),
|
StencilFunc(u32, i32, u32),
|
||||||
|
@ -262,10 +263,10 @@ pub enum WebGLCommand {
|
||||||
VertexAttribPointer2f(u32, i32, bool, i32, u32),
|
VertexAttribPointer2f(u32, i32, bool, i32, u32),
|
||||||
GetViewport(WebGLSender<(i32, i32, i32, i32)>),
|
GetViewport(WebGLSender<(i32, i32, i32, i32)>),
|
||||||
SetViewport(i32, i32, i32, i32),
|
SetViewport(i32, i32, i32, i32),
|
||||||
TexImage2D(u32, i32, i32, i32, i32, u32, u32, Vec<u8>),
|
TexImage2D(u32, i32, i32, i32, i32, u32, u32, ByteBuf),
|
||||||
TexParameteri(u32, u32, i32),
|
TexParameteri(u32, u32, i32),
|
||||||
TexParameterf(u32, u32, f32),
|
TexParameterf(u32, u32, f32),
|
||||||
TexSubImage2D(u32, i32, i32, i32, i32, i32, u32, u32, Vec<u8>),
|
TexSubImage2D(u32, i32, i32, i32, i32, i32, u32, u32, ByteBuf),
|
||||||
DrawingBufferWidth(WebGLSender<i32>),
|
DrawingBufferWidth(WebGLSender<i32>),
|
||||||
DrawingBufferHeight(WebGLSender<i32>),
|
DrawingBufferHeight(WebGLSender<i32>),
|
||||||
Finish(WebGLSender<()>),
|
Finish(WebGLSender<()>),
|
||||||
|
@ -401,7 +402,7 @@ pub enum WebVRCommand {
|
||||||
/// Start presenting to a VR device.
|
/// Start presenting to a VR device.
|
||||||
Create(WebVRDeviceId),
|
Create(WebVRDeviceId),
|
||||||
/// Synchronize the pose information to be used in the frame.
|
/// Synchronize the pose information to be used in the frame.
|
||||||
SyncPoses(WebVRDeviceId, f64, f64, WebGLSender<Result<Vec<u8>, ()>>),
|
SyncPoses(WebVRDeviceId, f64, f64, WebGLSender<Result<ByteBuf, ()>>),
|
||||||
/// Submit the frame to a VR device using the specified texture coordinates.
|
/// Submit the frame to a VR device using the specified texture coordinates.
|
||||||
SubmitFrame(WebVRDeviceId, [f32; 4], [f32; 4]),
|
SubmitFrame(WebVRDeviceId, [f32; 4], [f32; 4]),
|
||||||
/// Stop presenting to a VR device
|
/// Stop presenting to a VR device
|
||||||
|
|
|
@ -9,7 +9,14 @@ publish = false
|
||||||
path = "lib.rs"
|
path = "lib.rs"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
servo = ["mozjs", "string_cache", "url", "webrender_api", "xml5ever"]
|
servo = [
|
||||||
|
"mozjs",
|
||||||
|
"serde_bytes",
|
||||||
|
"string_cache",
|
||||||
|
"url",
|
||||||
|
"webrender_api",
|
||||||
|
"xml5ever",
|
||||||
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
app_units = "0.6"
|
app_units = "0.6"
|
||||||
|
@ -18,6 +25,7 @@ euclid = "0.17"
|
||||||
hashglobe = { path = "../hashglobe" }
|
hashglobe = { path = "../hashglobe" }
|
||||||
mozjs = { version = "0.4", features = ["promises"], optional = true }
|
mozjs = { version = "0.4", features = ["promises"], optional = true }
|
||||||
selectors = { path = "../selectors" }
|
selectors = { path = "../selectors" }
|
||||||
|
serde_bytes = { version = "0.10", optional = true }
|
||||||
servo_arc = { path = "../servo_arc" }
|
servo_arc = { path = "../servo_arc" }
|
||||||
smallbitvec = "1.0.3"
|
smallbitvec = "1.0.3"
|
||||||
smallvec = "0.6"
|
smallvec = "0.6"
|
||||||
|
|
|
@ -50,6 +50,8 @@ extern crate hashglobe;
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
extern crate mozjs as js;
|
extern crate mozjs as js;
|
||||||
extern crate selectors;
|
extern crate selectors;
|
||||||
|
#[cfg(feature = "servo")]
|
||||||
|
extern crate serde_bytes;
|
||||||
extern crate servo_arc;
|
extern crate servo_arc;
|
||||||
extern crate smallbitvec;
|
extern crate smallbitvec;
|
||||||
extern crate smallvec;
|
extern crate smallvec;
|
||||||
|
@ -63,6 +65,8 @@ extern crate webrender_api;
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
extern crate xml5ever;
|
extern crate xml5ever;
|
||||||
|
|
||||||
|
#[cfg(feature = "servo")]
|
||||||
|
use serde_bytes::ByteBuf;
|
||||||
use std::hash::{BuildHasher, Hash};
|
use std::hash::{BuildHasher, Hash};
|
||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
|
@ -300,6 +304,24 @@ impl<T: MallocSizeOf> MallocSizeOf for [T] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "servo")]
|
||||||
|
impl MallocShallowSizeOf for ByteBuf {
|
||||||
|
fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
|
||||||
|
unsafe { ops.malloc_size_of(self.as_ptr()) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "servo")]
|
||||||
|
impl MallocSizeOf for ByteBuf {
|
||||||
|
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
|
||||||
|
let mut n = self.shallow_size_of(ops);
|
||||||
|
for elem in self.iter() {
|
||||||
|
n += elem.size_of(ops);
|
||||||
|
}
|
||||||
|
n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> MallocShallowSizeOf for Vec<T> {
|
impl<T> MallocShallowSizeOf for Vec<T> {
|
||||||
fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
|
fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
|
||||||
unsafe { ops.malloc_size_of(self.as_ptr()) }
|
unsafe { ops.malloc_size_of(self.as_ptr()) }
|
||||||
|
|
|
@ -78,6 +78,7 @@ script_plugins = {path = "../script_plugins"}
|
||||||
script_traits = {path = "../script_traits"}
|
script_traits = {path = "../script_traits"}
|
||||||
selectors = { path = "../selectors" }
|
selectors = { path = "../selectors" }
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
|
serde_bytes = "0.10"
|
||||||
servo_allocator = {path = "../allocator"}
|
servo_allocator = {path = "../allocator"}
|
||||||
servo_arc = {path = "../servo_arc"}
|
servo_arc = {path = "../servo_arc"}
|
||||||
servo_atoms = {path = "../atoms"}
|
servo_atoms = {path = "../atoms"}
|
||||||
|
|
|
@ -453,13 +453,13 @@ impl CanvasRenderingContext2D {
|
||||||
}
|
}
|
||||||
|
|
||||||
let smoothing_enabled = self.state.borrow().image_smoothing_enabled;
|
let smoothing_enabled = self.state.borrow().image_smoothing_enabled;
|
||||||
self.ipc_renderer
|
self.ipc_renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::DrawImage(
|
||||||
.send(CanvasMsg::Canvas2d(Canvas2dMsg::DrawImage(image_data,
|
image_data.into(),
|
||||||
image_size,
|
image_size,
|
||||||
dest_rect,
|
dest_rect,
|
||||||
source_rect,
|
source_rect,
|
||||||
smoothing_enabled)))
|
smoothing_enabled,
|
||||||
.unwrap();
|
))).unwrap();
|
||||||
self.mark_as_dirty();
|
self.mark_as_dirty();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1127,7 +1127,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
let sh = cmp::max(1, sh.to_u32().unwrap());
|
let sh = cmp::max(1, sh.to_u32().unwrap());
|
||||||
let sw = cmp::max(1, sw.to_u32().unwrap());
|
let sw = cmp::max(1, sw.to_u32().unwrap());
|
||||||
|
|
||||||
let (sender, receiver) = ipc::channel::<Vec<u8>>(self.global().time_profiler_chan().clone()).unwrap();
|
let (sender, receiver) = ipc::channel(self.global().time_profiler_chan().clone()).unwrap();
|
||||||
let dest_rect = Rect::new(Point2D::new(sx.to_i32().unwrap(), sy.to_i32().unwrap()),
|
let dest_rect = Rect::new(Point2D::new(sx.to_i32().unwrap(), sy.to_i32().unwrap()),
|
||||||
Size2D::new(sw as i32, sh as i32));
|
Size2D::new(sw as i32, sh as i32));
|
||||||
let canvas_size = self.canvas.as_ref().map(|c| c.get_size()).unwrap_or(Size2D::zero());
|
let canvas_size = self.canvas.as_ref().map(|c| c.get_size()).unwrap_or(Size2D::zero());
|
||||||
|
@ -1135,7 +1135,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
self.ipc_renderer
|
self.ipc_renderer
|
||||||
.send(CanvasMsg::Canvas2d(Canvas2dMsg::GetImageData(dest_rect, canvas_size, sender)))
|
.send(CanvasMsg::Canvas2d(Canvas2dMsg::GetImageData(dest_rect, canvas_size, sender)))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut data = receiver.recv().unwrap();
|
let mut data = Vec::from(receiver.recv().unwrap());
|
||||||
|
|
||||||
// Un-premultiply alpha
|
// Un-premultiply alpha
|
||||||
for chunk in data.chunks_mut(4) {
|
for chunk in data.chunks_mut(4) {
|
||||||
|
@ -1174,10 +1174,12 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
||||||
|
|
||||||
let dirty_rect = Rect::new(Point2D::new(*dirty_x, *dirty_y),
|
let dirty_rect = Rect::new(Point2D::new(*dirty_x, *dirty_y),
|
||||||
Size2D::new(*dirty_width, *dirty_height));
|
Size2D::new(*dirty_width, *dirty_height));
|
||||||
let msg = CanvasMsg::Canvas2d(Canvas2dMsg::PutImageData(data,
|
let msg = CanvasMsg::Canvas2d(Canvas2dMsg::PutImageData(
|
||||||
|
data.into(),
|
||||||
offset,
|
offset,
|
||||||
image_data_size,
|
image_data_size,
|
||||||
dirty_rect));
|
dirty_rect,
|
||||||
|
));
|
||||||
self.ipc_renderer.send(msg).unwrap();
|
self.ipc_renderer.send(msg).unwrap();
|
||||||
self.mark_as_dirty();
|
self.mark_as_dirty();
|
||||||
}
|
}
|
||||||
|
|
|
@ -263,7 +263,7 @@ impl HTMLCanvasElement {
|
||||||
let msg = CanvasMsg::FromScript(FromScriptMsg::SendPixels(sender));
|
let msg = CanvasMsg::FromScript(FromScriptMsg::SendPixels(sender));
|
||||||
context.get_ipc_renderer().send(msg).unwrap();
|
context.get_ipc_renderer().send(msg).unwrap();
|
||||||
|
|
||||||
receiver.recv().unwrap()?
|
receiver.recv().unwrap()?.into()
|
||||||
},
|
},
|
||||||
Some(&CanvasContext::WebGL(_)) => {
|
Some(&CanvasContext::WebGL(_)) => {
|
||||||
// TODO: add a method in WebGLRenderingContext to get the pixels.
|
// TODO: add a method in WebGLRenderingContext to get the pixels.
|
||||||
|
|
|
@ -35,6 +35,7 @@ use ipc_channel::ipc::IpcSender;
|
||||||
use profile_traits::ipc;
|
use profile_traits::ipc;
|
||||||
use script_runtime::CommonScriptMsg;
|
use script_runtime::CommonScriptMsg;
|
||||||
use script_runtime::ScriptThreadEventCategory::WebVREvent;
|
use script_runtime::ScriptThreadEventCategory::WebVREvent;
|
||||||
|
use serde_bytes::ByteBuf;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
@ -68,7 +69,7 @@ pub struct VRDisplay {
|
||||||
// Compositor VRFrameData synchonization
|
// Compositor VRFrameData synchonization
|
||||||
frame_data_status: Cell<VRFrameDataStatus>,
|
frame_data_status: Cell<VRFrameDataStatus>,
|
||||||
#[ignore_malloc_size_of = "closures are hard"]
|
#[ignore_malloc_size_of = "closures are hard"]
|
||||||
frame_data_receiver: DomRefCell<Option<WebGLReceiver<Result<Vec<u8>, ()>>>>,
|
frame_data_receiver: DomRefCell<Option<WebGLReceiver<Result<ByteBuf, ()>>>>,
|
||||||
running_display_raf: Cell<bool>,
|
running_display_raf: Cell<bool>,
|
||||||
paused: Cell<bool>,
|
paused: Cell<bool>,
|
||||||
stopped_on_pause: Cell<bool>,
|
stopped_on_pause: Cell<bool>,
|
||||||
|
|
|
@ -93,7 +93,11 @@ impl WebGLBuffer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.capacity.set(data.len());
|
self.capacity.set(data.len());
|
||||||
self.renderer.send(WebGLCommand::BufferData(target, data.to_vec(), usage)).unwrap();
|
self.renderer.send(WebGLCommand::BufferData(
|
||||||
|
target,
|
||||||
|
data.to_vec().into(),
|
||||||
|
usage,
|
||||||
|
)).unwrap();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1050,12 +1050,15 @@ impl WebGLRenderingContext {
|
||||||
let internal_format = self.extension_manager.get_effective_tex_internal_format(format, data_type);
|
let internal_format = self.extension_manager.get_effective_tex_internal_format(format, data_type);
|
||||||
|
|
||||||
// TODO(emilio): convert colorspace if requested
|
// TODO(emilio): convert colorspace if requested
|
||||||
let msg = WebGLCommand::TexImage2D(target.as_gl_constant(), level as i32,
|
let msg = WebGLCommand::TexImage2D(
|
||||||
|
target.as_gl_constant(),
|
||||||
|
level as i32,
|
||||||
internal_format as i32,
|
internal_format as i32,
|
||||||
width as i32, height as i32,
|
width as i32, height as i32,
|
||||||
format,
|
format,
|
||||||
data_type,
|
data_type,
|
||||||
pixels);
|
pixels.into(),
|
||||||
|
);
|
||||||
|
|
||||||
self.send_command(msg);
|
self.send_command(msg);
|
||||||
|
|
||||||
|
@ -1102,11 +1105,17 @@ impl WebGLRenderingContext {
|
||||||
self.send_command(WebGLCommand::PixelStorei(constants::UNPACK_ALIGNMENT, unpacking_alignment as i32));
|
self.send_command(WebGLCommand::PixelStorei(constants::UNPACK_ALIGNMENT, unpacking_alignment as i32));
|
||||||
|
|
||||||
// TODO(emilio): convert colorspace if requested
|
// TODO(emilio): convert colorspace if requested
|
||||||
let msg = WebGLCommand::TexSubImage2D(target.as_gl_constant(),
|
let msg = WebGLCommand::TexSubImage2D(
|
||||||
level as i32, xoffset, yoffset,
|
target.as_gl_constant(),
|
||||||
width as i32, height as i32,
|
level as i32,
|
||||||
|
xoffset,
|
||||||
|
yoffset,
|
||||||
|
width as i32,
|
||||||
|
height as i32,
|
||||||
format.as_gl_constant(),
|
format.as_gl_constant(),
|
||||||
data_type.as_gl_constant(), pixels);
|
data_type.as_gl_constant(),
|
||||||
|
pixels.into(),
|
||||||
|
);
|
||||||
|
|
||||||
self.send_command(msg);
|
self.send_command(msg);
|
||||||
}
|
}
|
||||||
|
@ -1182,7 +1191,7 @@ impl WebGLRenderingContext {
|
||||||
constants::UNSIGNED_BYTE,
|
constants::UNSIGNED_BYTE,
|
||||||
sender,
|
sender,
|
||||||
));
|
));
|
||||||
Some(receiver.recv().unwrap())
|
Some(receiver.recv().unwrap().into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1759,7 +1768,11 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
if (offset as usize) + data_vec.len() > bound_buffer.capacity() {
|
if (offset as usize) + data_vec.len() > bound_buffer.capacity() {
|
||||||
return self.webgl_error(InvalidValue);
|
return self.webgl_error(InvalidValue);
|
||||||
}
|
}
|
||||||
self.send_command(WebGLCommand::BufferSubData(target, offset as isize, data_vec));
|
self.send_command(WebGLCommand::BufferSubData(
|
||||||
|
target,
|
||||||
|
offset as isize,
|
||||||
|
data_vec.into(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
|
||||||
|
|
|
@ -81,6 +81,7 @@ extern crate script_layout_interface;
|
||||||
extern crate script_traits;
|
extern crate script_traits;
|
||||||
extern crate selectors;
|
extern crate selectors;
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
|
extern crate serde_bytes;
|
||||||
extern crate servo_allocator;
|
extern crate servo_allocator;
|
||||||
extern crate servo_arc;
|
extern crate servo_arc;
|
||||||
#[macro_use] extern crate servo_atoms;
|
#[macro_use] extern crate servo_atoms;
|
||||||
|
|
|
@ -344,7 +344,7 @@ impl webgl::WebVRRenderHandler for WebVRCompositorHandler {
|
||||||
(*compositor.0).sync_poses();
|
(*compositor.0).sync_poses();
|
||||||
(*compositor.0).synced_frame_data(near, far).to_bytes()
|
(*compositor.0).synced_frame_data(near, far).to_bytes()
|
||||||
};
|
};
|
||||||
let _ = sender.send(Ok(pose));
|
let _ = sender.send(Ok(pose.into()));
|
||||||
} else {
|
} else {
|
||||||
let _ = sender.send(Err(()));
|
let _ = sender.send(Err(()));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue