Format remaining files

This commit is contained in:
Pyfisch 2018-11-06 13:01:35 +01:00
parent bf47f90da6
commit cb07debcb6
252 changed files with 5944 additions and 3744 deletions

View file

@ -22,7 +22,12 @@ pub struct CanvasId(pub u64);
#[derive(Deserialize, Serialize)]
pub enum CanvasMsg {
Canvas2d(Canvas2dMsg, CanvasId),
Create(IpcSender<CanvasId>, Size2D<u32>, webrender_api::RenderApiSender, bool),
Create(
IpcSender<CanvasId>,
Size2D<u32>,
webrender_api::RenderApiSender,
bool,
),
FromLayout(FromLayoutMsg, CanvasId),
FromScript(FromScriptMsg, CanvasId),
Recreate(Size2D<u32>, CanvasId),
@ -40,8 +45,7 @@ pub enum Canvas2dMsg {
Arc(Point2D<f32>, f32, f32, f32, bool),
ArcTo(Point2D<f32>, Point2D<f32>, f32),
DrawImage(Option<ByteBuf>, Size2D<f64>, Rect<f64>, Rect<f64>, bool),
DrawImageInOther(
CanvasId, Size2D<f64>, Rect<f64>, Rect<f64>, bool),
DrawImageInOther(CanvasId, Size2D<f64>, Rect<f64>, Rect<f64>, bool),
BeginPath,
BezierCurveTo(Point2D<f32>, Point2D<f32>, Point2D<f32>),
ClearRect(Rect<f32>),
@ -99,12 +103,17 @@ pub struct LinearGradientStyle {
pub y0: f64,
pub x1: f64,
pub y1: f64,
pub stops: Vec<CanvasGradientStop>
pub stops: Vec<CanvasGradientStop>,
}
impl LinearGradientStyle {
pub fn new(x0: f64, y0: f64, x1: f64, y1: f64, stops: Vec<CanvasGradientStop>)
-> LinearGradientStyle {
pub fn new(
x0: f64,
y0: f64,
x1: f64,
y1: f64,
stops: Vec<CanvasGradientStop>,
) -> LinearGradientStyle {
LinearGradientStyle {
x0: x0,
y0: y0,
@ -123,12 +132,19 @@ pub struct RadialGradientStyle {
pub x1: f64,
pub y1: f64,
pub r1: f64,
pub stops: Vec<CanvasGradientStop>
pub stops: Vec<CanvasGradientStop>,
}
impl RadialGradientStyle {
pub fn new(x0: f64, y0: f64, r0: f64, x1: f64, y1: f64, r1: f64, stops: Vec<CanvasGradientStop>)
-> RadialGradientStyle {
pub fn new(
x0: f64,
y0: f64,
r0: f64,
x1: f64,
y1: f64,
r1: f64,
stops: Vec<CanvasGradientStop>,
) -> RadialGradientStyle {
RadialGradientStyle {
x0: x0,
y0: y0,
@ -165,7 +181,6 @@ impl SurfaceStyle {
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum FillOrStrokeStyle {
Color(RGBA),
@ -256,18 +271,18 @@ impl FromStr for CompositionStyle {
fn from_str(string: &str) -> Result<CompositionStyle, ()> {
match string {
"source-in" => Ok(CompositionStyle::SrcIn),
"source-out" => Ok(CompositionStyle::SrcOut),
"source-over" => Ok(CompositionStyle::SrcOver),
"source-atop" => Ok(CompositionStyle::SrcAtop),
"destination-in" => Ok(CompositionStyle::DestIn),
"destination-out" => Ok(CompositionStyle::DestOut),
"source-in" => Ok(CompositionStyle::SrcIn),
"source-out" => Ok(CompositionStyle::SrcOut),
"source-over" => Ok(CompositionStyle::SrcOver),
"source-atop" => Ok(CompositionStyle::SrcAtop),
"destination-in" => Ok(CompositionStyle::DestIn),
"destination-out" => Ok(CompositionStyle::DestOut),
"destination-over" => Ok(CompositionStyle::DestOver),
"destination-atop" => Ok(CompositionStyle::DestAtop),
"copy" => Ok(CompositionStyle::Copy),
"lighter" => Ok(CompositionStyle::Lighter),
"xor" => Ok(CompositionStyle::Xor),
_ => Err(())
"copy" => Ok(CompositionStyle::Copy),
"lighter" => Ok(CompositionStyle::Lighter),
"xor" => Ok(CompositionStyle::Xor),
_ => Err(()),
}
}
}
@ -275,17 +290,17 @@ impl FromStr for CompositionStyle {
impl CompositionStyle {
pub fn to_str(&self) -> &str {
match *self {
CompositionStyle::SrcIn => "source-in",
CompositionStyle::SrcOut => "source-out",
CompositionStyle::SrcOver => "source-over",
CompositionStyle::SrcAtop => "source-atop",
CompositionStyle::DestIn => "destination-in",
CompositionStyle::DestOut => "destination-out",
CompositionStyle::SrcIn => "source-in",
CompositionStyle::SrcOut => "source-out",
CompositionStyle::SrcOver => "source-over",
CompositionStyle::SrcAtop => "source-atop",
CompositionStyle::DestIn => "destination-in",
CompositionStyle::DestOut => "destination-out",
CompositionStyle::DestOver => "destination-over",
CompositionStyle::DestAtop => "destination-atop",
CompositionStyle::Copy => "copy",
CompositionStyle::Lighter => "lighter",
CompositionStyle::Xor => "xor",
CompositionStyle::Copy => "copy",
CompositionStyle::Lighter => "lighter",
CompositionStyle::Xor => "xor",
}
}
}
@ -314,22 +329,22 @@ impl FromStr for BlendingStyle {
fn from_str(string: &str) -> Result<BlendingStyle, ()> {
match string {
"multiply" => Ok(BlendingStyle::Multiply),
"screen" => Ok(BlendingStyle::Screen),
"overlay" => Ok(BlendingStyle::Overlay),
"darken" => Ok(BlendingStyle::Darken),
"lighten" => Ok(BlendingStyle::Lighten),
"multiply" => Ok(BlendingStyle::Multiply),
"screen" => Ok(BlendingStyle::Screen),
"overlay" => Ok(BlendingStyle::Overlay),
"darken" => Ok(BlendingStyle::Darken),
"lighten" => Ok(BlendingStyle::Lighten),
"color-dodge" => Ok(BlendingStyle::ColorDodge),
"color-burn" => Ok(BlendingStyle::ColorBurn),
"hard-light" => Ok(BlendingStyle::HardLight),
"soft-light" => Ok(BlendingStyle::SoftLight),
"difference" => Ok(BlendingStyle::Difference),
"exclusion" => Ok(BlendingStyle::Exclusion),
"hue" => Ok(BlendingStyle::Hue),
"saturation" => Ok(BlendingStyle::Saturation),
"color" => Ok(BlendingStyle::Color),
"luminosity" => Ok(BlendingStyle::Luminosity),
_ => Err(())
"color-burn" => Ok(BlendingStyle::ColorBurn),
"hard-light" => Ok(BlendingStyle::HardLight),
"soft-light" => Ok(BlendingStyle::SoftLight),
"difference" => Ok(BlendingStyle::Difference),
"exclusion" => Ok(BlendingStyle::Exclusion),
"hue" => Ok(BlendingStyle::Hue),
"saturation" => Ok(BlendingStyle::Saturation),
"color" => Ok(BlendingStyle::Color),
"luminosity" => Ok(BlendingStyle::Luminosity),
_ => Err(()),
}
}
}
@ -337,20 +352,20 @@ impl FromStr for BlendingStyle {
impl BlendingStyle {
pub fn to_str(&self) -> &str {
match *self {
BlendingStyle::Multiply => "multiply",
BlendingStyle::Screen => "screen",
BlendingStyle::Overlay => "overlay",
BlendingStyle::Darken => "darken",
BlendingStyle::Lighten => "lighten",
BlendingStyle::Multiply => "multiply",
BlendingStyle::Screen => "screen",
BlendingStyle::Overlay => "overlay",
BlendingStyle::Darken => "darken",
BlendingStyle::Lighten => "lighten",
BlendingStyle::ColorDodge => "color-dodge",
BlendingStyle::ColorBurn => "color-burn",
BlendingStyle::HardLight => "hard-light",
BlendingStyle::SoftLight => "soft-light",
BlendingStyle::ColorBurn => "color-burn",
BlendingStyle::HardLight => "hard-light",
BlendingStyle::SoftLight => "soft-light",
BlendingStyle::Difference => "difference",
BlendingStyle::Exclusion => "exclusion",
BlendingStyle::Hue => "hue",
BlendingStyle::Exclusion => "exclusion",
BlendingStyle::Hue => "hue",
BlendingStyle::Saturation => "saturation",
BlendingStyle::Color => "color",
BlendingStyle::Color => "color",
BlendingStyle::Luminosity => "luminosity",
}
}

View file

@ -4,18 +4,20 @@
#![crate_name = "canvas_traits"]
#![crate_type = "rlib"]
#![deny(unsafe_code)]
extern crate cssparser;
extern crate euclid;
extern crate gleam;
extern crate ipc_channel;
#[macro_use] extern crate lazy_static;
#[macro_use]
extern crate lazy_static;
extern crate malloc_size_of;
#[macro_use] extern crate malloc_size_of_derive;
#[macro_use]
extern crate malloc_size_of_derive;
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 webrender_api;

View file

@ -134,13 +134,15 @@ impl WebGLMsgSender {
/// Send a WebGLCommand message
#[inline]
pub fn send(&self, command: WebGLCommand, backtrace: WebGLCommandBacktrace) -> WebGLSendResult {
self.sender.send(WebGLMsg::WebGLCommand(self.ctx_id, command, backtrace))
self.sender
.send(WebGLMsg::WebGLCommand(self.ctx_id, command, backtrace))
}
/// Send a WebVRCommand message
#[inline]
pub fn send_vr(&self, command: WebVRCommand) -> WebGLSendResult {
self.sender.send(WebGLMsg::WebVRCommand(self.ctx_id, command))
self.sender
.send(WebGLMsg::WebVRCommand(self.ctx_id, command))
}
/// Send a resize message
@ -150,7 +152,8 @@ impl WebGLMsgSender {
size: Size2D<u32>,
sender: WebGLSender<Result<(), String>>,
) -> WebGLSendResult {
self.sender.send(WebGLMsg::ResizeContext(self.ctx_id, size, sender))
self.sender
.send(WebGLMsg::ResizeContext(self.ctx_id, size, sender))
}
#[inline]
@ -160,7 +163,8 @@ impl WebGLMsgSender {
#[inline]
pub fn send_update_wr_image(&self, sender: WebGLSender<ImageKey>) -> WebGLSendResult {
self.sender.send(WebGLMsg::UpdateWebRenderImage(self.ctx_id, sender))
self.sender
.send(WebGLMsg::UpdateWebRenderImage(self.ctx_id, sender))
}
pub fn send_dom_to_texture(&self, command: DOMToTextureCommand) -> WebGLSendResult {
@ -290,11 +294,34 @@ pub enum WebGLCommand {
GetTexParameterInt(u32, TexParameterInt, WebGLSender<i32>),
TexParameteri(u32, u32, i32),
TexParameterf(u32, u32, f32),
DrawArrays { mode: u32, first: i32, count: i32 },
DrawArraysInstanced { mode: u32, first: i32, count: i32, primcount: i32 },
DrawElements { mode: u32, count: i32, type_: u32, offset: u32 },
DrawElementsInstanced { mode: u32, count: i32, type_: u32, offset: u32, primcount: i32 },
VertexAttribDivisor { index: u32, divisor: u32 },
DrawArrays {
mode: u32,
first: i32,
count: i32,
},
DrawArraysInstanced {
mode: u32,
first: i32,
count: i32,
primcount: i32,
},
DrawElements {
mode: u32,
count: i32,
type_: u32,
offset: u32,
},
DrawElementsInstanced {
mode: u32,
count: i32,
type_: u32,
offset: u32,
primcount: i32,
},
VertexAttribDivisor {
index: u32,
divisor: u32,
},
GetUniformBool(WebGLProgramId, i32, WebGLSender<bool>),
GetUniformBool2(WebGLProgramId, i32, WebGLSender<[bool; 2]>),
GetUniformBool3(WebGLProgramId, i32, WebGLSender<[bool; 3]>),
@ -309,7 +336,11 @@ pub enum WebGLCommand {
GetUniformFloat4(WebGLProgramId, i32, WebGLSender<[f32; 4]>),
GetUniformFloat9(WebGLProgramId, i32, WebGLSender<[f32; 9]>),
GetUniformFloat16(WebGLProgramId, i32, WebGLSender<[f32; 16]>),
InitializeFramebuffer { color: bool, depth: bool, stencil: bool },
InitializeFramebuffer {
color: bool,
depth: bool,
stencil: bool,
},
}
macro_rules! define_resource_id_struct {
@ -329,7 +360,6 @@ macro_rules! define_resource_id_struct {
self.0.get()
}
}
};
}
@ -340,7 +370,8 @@ macro_rules! define_resource_id {
#[allow(unsafe_code)]
impl<'de> ::serde::Deserialize<'de> for $name {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: ::serde::Deserializer<'de>
where
D: ::serde::Deserializer<'de>,
{
let id = u32::deserialize(deserializer)?;
if id == 0 {
@ -353,32 +384,33 @@ macro_rules! define_resource_id {
impl ::serde::Serialize for $name {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: ::serde::Serializer
where
S: ::serde::Serializer,
{
self.get().serialize(serializer)
}
}
impl ::std::fmt::Debug for $name {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter)
-> Result<(), ::std::fmt::Error> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
fmt.debug_tuple(stringify!($name))
.field(&self.get())
.finish()
.field(&self.get())
.finish()
}
}
impl ::std::fmt::Display for $name {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter)
-> Result<(), ::std::fmt::Error> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
write!(fmt, "{}", self.get())
}
}
impl ::malloc_size_of::MallocSizeOf for $name {
fn size_of(&self, _ops: &mut ::malloc_size_of::MallocSizeOfOps) -> usize { 0 }
fn size_of(&self, _ops: &mut ::malloc_size_of::MallocSizeOfOps) -> usize {
0
}
}
}
};
}
define_resource_id!(WebGLBufferId);
@ -389,8 +421,9 @@ define_resource_id!(WebGLProgramId);
define_resource_id!(WebGLShaderId);
define_resource_id!(WebGLVertexArrayId);
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, Ord)]
#[derive(PartialEq, PartialOrd, Serialize)]
#[derive(
Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, Ord, PartialEq, PartialOrd, Serialize,
)]
pub struct WebGLContextId(pub usize);
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
@ -423,7 +456,7 @@ pub enum WebVRCommand {
/// Submit the frame to a VR device using the specified texture coordinates.
SubmitFrame(WebVRDeviceId, [f32; 4], [f32; 4]),
/// Stop presenting to a VR device
Release(WebVRDeviceId)
Release(WebVRDeviceId),
}
// Trait object that handles WebVR commands.
@ -436,7 +469,13 @@ pub trait WebVRRenderHandler: Send {
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum DOMToTextureCommand {
/// Attaches a HTMLIFrameElement to a WebGLTexture.
Attach(WebGLContextId, WebGLTextureId, DocumentId, PipelineId, Size2D<i32>),
Attach(
WebGLContextId,
WebGLTextureId,
DocumentId,
PipelineId,
Size2D<i32>,
),
/// Releases the HTMLIFrameElement to WebGLTexture attachment.
Detach(WebGLTextureId),
/// Lock message used for a correct synchronization with WebRender GL flow.