style: Use serde to serialize LengthPercentage and StyleRayFunction.

We need to pass these two types into the compositor, so we need a better
way to serialize these rust types. We use serde and bincode to
serialize/deserialize them, and use ByteBuf to pass the &[u8] data
through IPC. We define StyleVecU8 for FFI usage only.

Differential Revision: https://phabricator.services.mozilla.com/D50688
This commit is contained in:
Boris Chiou 2019-10-31 21:35:05 +00:00 committed by Emilio Cobos Álvarez
parent d99606a841
commit 40ede5bacb
8 changed files with 18 additions and 8 deletions

View file

@ -78,7 +78,6 @@ extern crate parking_lot;
extern crate precomputed_hash; extern crate precomputed_hash;
extern crate rayon; extern crate rayon;
extern crate selectors; extern crate selectors;
#[cfg(feature = "servo")]
#[macro_use] #[macro_use]
extern crate serde; extern crate serde;
pub extern crate servo_arc; pub extern crate servo_arc;

View file

@ -13,16 +13,17 @@ use std::{f32, f64};
use style_traits::{CssWriter, ToCss}; use style_traits::{CssWriter, ToCss};
/// A computed angle in degrees. /// A computed angle in degrees.
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[derive( #[derive(
Add, Add,
Animate, Animate,
Clone, Clone,
Copy, Copy,
Debug, Debug,
Deserialize,
MallocSizeOf, MallocSizeOf,
PartialEq, PartialEq,
PartialOrd, PartialOrd,
Serialize,
ToAnimatedZero, ToAnimatedZero,
ToResolvedValue, ToResolvedValue,
)] )]

View file

@ -75,7 +75,9 @@ impl ToComputedValue for specified::Length {
/// ///
/// https://drafts.csswg.org/css-values-4/#typedef-length-percentage /// https://drafts.csswg.org/css-values-4/#typedef-length-percentage
#[allow(missing_docs)] #[allow(missing_docs)]
#[derive(Clone, Copy, Debug, MallocSizeOf, ToAnimatedZero, ToResolvedValue)] #[derive(
Clone, Copy, Debug, Deserialize, MallocSizeOf, Serialize, ToAnimatedZero, ToResolvedValue,
)]
#[repr(C)] #[repr(C)]
pub struct LengthPercentage { pub struct LengthPercentage {
length: Length, length: Length,
@ -611,9 +613,11 @@ impl Size {
Clone, Clone,
ComputeSquaredDistance, ComputeSquaredDistance,
Copy, Copy,
Deserialize,
MallocSizeOf, MallocSizeOf,
PartialEq, PartialEq,
PartialOrd, PartialOrd,
Serialize,
ToAnimatedValue, ToAnimatedValue,
ToAnimatedZero, ToAnimatedZero,
ToResolvedValue, ToResolvedValue,

View file

@ -12,7 +12,6 @@ use std::fmt;
use style_traits::{CssWriter, ToCss}; use style_traits::{CssWriter, ToCss};
/// A computed percentage. /// A computed percentage.
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[derive( #[derive(
Animate, Animate,
Clone, Clone,
@ -20,9 +19,11 @@ use style_traits::{CssWriter, ToCss};
Copy, Copy,
Debug, Debug,
Default, Default,
Deserialize,
MallocSizeOf, MallocSizeOf,
PartialEq, PartialEq,
PartialOrd, PartialOrd,
Serialize,
SpecifiedValueInfo, SpecifiedValueInfo,
ToAnimatedValue, ToAnimatedValue,
ToAnimatedZero, ToAnimatedZero,

View file

@ -14,9 +14,11 @@ use crate::values::specified::SVGPathData;
Clone, Clone,
Copy, Copy,
Debug, Debug,
Deserialize,
MallocSizeOf, MallocSizeOf,
Parse, Parse,
PartialEq, PartialEq,
Serialize,
SpecifiedValueInfo, SpecifiedValueInfo,
ToAnimatedZero, ToAnimatedZero,
ToComputedValue, ToComputedValue,
@ -41,8 +43,10 @@ pub enum RaySize {
Clone, Clone,
ComputeSquaredDistance, ComputeSquaredDistance,
Debug, Debug,
Deserialize,
MallocSizeOf, MallocSizeOf,
PartialEq, PartialEq,
Serialize,
SpecifiedValueInfo, SpecifiedValueInfo,
ToAnimatedZero, ToAnimatedZero,
ToComputedValue, ToComputedValue,

View file

@ -10,7 +10,7 @@ name = "style_traits"
path = "lib.rs" path = "lib.rs"
[features] [features]
servo = ["serde", "servo_atoms", "cssparser/serde", "webrender_api", "servo_url", "euclid/serde"] servo = ["servo_atoms", "cssparser/serde", "webrender_api", "servo_url", "euclid/serde"]
gecko = [] gecko = []
[dependencies] [dependencies]
@ -22,7 +22,7 @@ lazy_static = "1"
malloc_size_of = { path = "../malloc_size_of" } malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = "0.1" malloc_size_of_derive = "0.1"
selectors = { path = "../selectors" } selectors = { path = "../selectors" }
serde = {version = "1.0", optional = true} serde = "1.0"
webrender_api = {git = "https://github.com/servo/webrender", optional = true} webrender_api = {git = "https://github.com/servo/webrender", optional = true}
servo_atoms = {path = "../atoms", optional = true} servo_atoms = {path = "../atoms", optional = true}
servo_arc = { path = "../servo_arc" } servo_arc = { path = "../servo_arc" }

View file

@ -22,7 +22,6 @@ extern crate malloc_size_of;
#[macro_use] #[macro_use]
extern crate malloc_size_of_derive; extern crate malloc_size_of_derive;
extern crate selectors; extern crate selectors;
#[cfg(feature = "servo")]
#[macro_use] #[macro_use]
extern crate serde; extern crate serde;
extern crate servo_arc; extern crate servo_arc;

View file

@ -507,7 +507,9 @@ pub mod specified {
/// Whether to allow negative lengths or not. /// Whether to allow negative lengths or not.
#[repr(u8)] #[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, PartialOrd, ToShmem)] #[derive(
Clone, Copy, Debug, Deserialize, Eq, MallocSizeOf, PartialEq, PartialOrd, Serialize, ToShmem,
)]
pub enum AllowedNumericType { pub enum AllowedNumericType {
/// Allow all kind of numeric values. /// Allow all kind of numeric values.
All, All,