mirror of
https://github.com/servo/servo.git
synced 2025-08-08 15:05:35 +01:00
Use ByteBuf for the canvas messages
The type Vec<u8> is super unefficient to work with in Serde if all you want to represent is a simple blob.
This commit is contained in:
parent
3ce3f39383
commit
ce81420bef
19 changed files with 170 additions and 62 deletions
|
@ -19,5 +19,6 @@ malloc_size_of_derive = { path = "../malloc_size_of_derive" }
|
|||
nonzero = {path = "../nonzero"}
|
||||
offscreen_gl_context = { version = "0.15", features = ["serde"] }
|
||||
serde = "1.0"
|
||||
serde_bytes = "0.10"
|
||||
servo_config = {path = "../config"}
|
||||
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
use cssparser::RGBA;
|
||||
use euclid::{Transform2D, Point2D, Vector2D, Rect, Size2D};
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use serde_bytes::ByteBuf;
|
||||
use std::default::Default;
|
||||
use std::str::FromStr;
|
||||
use webrender_api;
|
||||
|
@ -33,7 +34,7 @@ pub struct CanvasImageData {
|
|||
pub enum Canvas2dMsg {
|
||||
Arc(Point2D<f32>, f32, f32, f32, bool),
|
||||
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),
|
||||
DrawImageInOther(
|
||||
IpcSender<CanvasMsg>, Size2D<f64>, Rect<f64>, Rect<f64>, bool, IpcSender<()>),
|
||||
|
@ -46,11 +47,11 @@ pub enum Canvas2dMsg {
|
|||
Fill,
|
||||
FillText(String, f64, f64, Option<f64>),
|
||||
FillRect(Rect<f32>),
|
||||
GetImageData(Rect<i32>, Size2D<f64>, IpcSender<Vec<u8>>),
|
||||
GetImageData(Rect<i32>, Size2D<f64>, IpcSender<ByteBuf>),
|
||||
IsPointInPath(f64, f64, FillRule, IpcSender<bool>),
|
||||
LineTo(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>),
|
||||
Rect(Rect<f32>),
|
||||
RestoreContext,
|
||||
|
@ -79,7 +80,7 @@ pub enum FromLayoutMsg {
|
|||
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
pub enum FromScriptMsg {
|
||||
SendPixels(IpcSender<Option<Vec<u8>>>),
|
||||
SendPixels(IpcSender<Option<ByteBuf>>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, MallocSizeOf, Serialize)]
|
||||
|
@ -138,20 +139,24 @@ impl RadialGradientStyle {
|
|||
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
pub struct SurfaceStyle {
|
||||
pub surface_data: Vec<u8>,
|
||||
pub surface_data: ByteBuf,
|
||||
pub surface_size: Size2D<i32>,
|
||||
pub repeat_x: bool,
|
||||
pub repeat_y: bool,
|
||||
}
|
||||
|
||||
impl SurfaceStyle {
|
||||
pub fn new(surface_data: Vec<u8>, surface_size: Size2D<i32>, repeat_x: bool, repeat_y: bool)
|
||||
-> SurfaceStyle {
|
||||
SurfaceStyle {
|
||||
surface_data: surface_data,
|
||||
surface_size: surface_size,
|
||||
repeat_x: repeat_x,
|
||||
repeat_y: repeat_y,
|
||||
pub fn new(
|
||||
surface_data: Vec<u8>,
|
||||
surface_size: Size2D<i32>,
|
||||
repeat_x: bool,
|
||||
repeat_y: bool,
|
||||
) -> Self {
|
||||
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 offscreen_gl_context;
|
||||
#[macro_use] extern crate serde;
|
||||
extern crate serde_bytes;
|
||||
extern crate servo_config;
|
||||
extern crate webrender_api;
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
use euclid::Size2D;
|
||||
use nonzero::NonZero;
|
||||
use offscreen_gl_context::{GLContextAttributes, GLLimits};
|
||||
use serde_bytes::ByteBuf;
|
||||
use std::fmt;
|
||||
use webrender_api::{DocumentId, ImageKey, PipelineId};
|
||||
|
||||
|
@ -165,8 +166,8 @@ pub enum WebGLCommand {
|
|||
AttachShader(WebGLProgramId, WebGLShaderId),
|
||||
DetachShader(WebGLProgramId, WebGLShaderId),
|
||||
BindAttribLocation(WebGLProgramId, u32, String),
|
||||
BufferData(u32, Vec<u8>, u32),
|
||||
BufferSubData(u32, isize, Vec<u8>),
|
||||
BufferData(u32, ByteBuf, u32),
|
||||
BufferSubData(u32, isize, ByteBuf),
|
||||
Clear(u32),
|
||||
ClearColor(f32, f32, f32, f32),
|
||||
ClearDepth(f64),
|
||||
|
@ -222,7 +223,7 @@ pub enum WebGLCommand {
|
|||
GetFramebufferAttachmentParameter(u32, u32, u32, WebGLSender<i32>),
|
||||
PolygonOffset(f32, f32),
|
||||
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),
|
||||
Scissor(i32, i32, i32, i32),
|
||||
StencilFunc(u32, i32, u32),
|
||||
|
@ -262,10 +263,10 @@ pub enum WebGLCommand {
|
|||
VertexAttribPointer2f(u32, i32, bool, i32, u32),
|
||||
GetViewport(WebGLSender<(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),
|
||||
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>),
|
||||
DrawingBufferHeight(WebGLSender<i32>),
|
||||
Finish(WebGLSender<()>),
|
||||
|
@ -401,7 +402,7 @@ pub enum WebVRCommand {
|
|||
/// Start presenting to a VR device.
|
||||
Create(WebVRDeviceId),
|
||||
/// 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.
|
||||
SubmitFrame(WebVRDeviceId, [f32; 4], [f32; 4]),
|
||||
/// Stop presenting to a VR device
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue