From 40ede5bacb42ad0ebe10d6bec846606591b926d0 Mon Sep 17 00:00:00 2001 From: Boris Chiou Date: Thu, 31 Oct 2019 21:35:05 +0000 Subject: [PATCH] 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 --- components/style/lib.rs | 1 - components/style/values/computed/angle.rs | 3 ++- components/style/values/computed/length.rs | 6 +++++- components/style/values/computed/percentage.rs | 3 ++- components/style/values/generics/motion.rs | 4 ++++ components/style_traits/Cargo.toml | 4 ++-- components/style_traits/lib.rs | 1 - components/style_traits/values.rs | 4 +++- 8 files changed, 18 insertions(+), 8 deletions(-) diff --git a/components/style/lib.rs b/components/style/lib.rs index 35070b0f2546..354950f9c152 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -78,7 +78,6 @@ extern crate parking_lot; extern crate precomputed_hash; extern crate rayon; extern crate selectors; -#[cfg(feature = "servo")] #[macro_use] extern crate serde; pub extern crate servo_arc; diff --git a/components/style/values/computed/angle.rs b/components/style/values/computed/angle.rs index d8cdefb52630..ea321d22337a 100644 --- a/components/style/values/computed/angle.rs +++ b/components/style/values/computed/angle.rs @@ -13,16 +13,17 @@ use std::{f32, f64}; use style_traits::{CssWriter, ToCss}; /// A computed angle in degrees. -#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] #[derive( Add, Animate, Clone, Copy, Debug, + Deserialize, MallocSizeOf, PartialEq, PartialOrd, + Serialize, ToAnimatedZero, ToResolvedValue, )] diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index 6d61198d364a..5665c1e7373c 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -75,7 +75,9 @@ impl ToComputedValue for specified::Length { /// /// https://drafts.csswg.org/css-values-4/#typedef-length-percentage #[allow(missing_docs)] -#[derive(Clone, Copy, Debug, MallocSizeOf, ToAnimatedZero, ToResolvedValue)] +#[derive( + Clone, Copy, Debug, Deserialize, MallocSizeOf, Serialize, ToAnimatedZero, ToResolvedValue, +)] #[repr(C)] pub struct LengthPercentage { length: Length, @@ -611,9 +613,11 @@ impl Size { Clone, ComputeSquaredDistance, Copy, + Deserialize, MallocSizeOf, PartialEq, PartialOrd, + Serialize, ToAnimatedValue, ToAnimatedZero, ToResolvedValue, diff --git a/components/style/values/computed/percentage.rs b/components/style/values/computed/percentage.rs index c22f8ed5683c..b5a734367b21 100644 --- a/components/style/values/computed/percentage.rs +++ b/components/style/values/computed/percentage.rs @@ -12,7 +12,6 @@ use std::fmt; use style_traits::{CssWriter, ToCss}; /// A computed percentage. -#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] #[derive( Animate, Clone, @@ -20,9 +19,11 @@ use style_traits::{CssWriter, ToCss}; Copy, Debug, Default, + Deserialize, MallocSizeOf, PartialEq, PartialOrd, + Serialize, SpecifiedValueInfo, ToAnimatedValue, ToAnimatedZero, diff --git a/components/style/values/generics/motion.rs b/components/style/values/generics/motion.rs index e9ccc045186f..685eaad43e29 100644 --- a/components/style/values/generics/motion.rs +++ b/components/style/values/generics/motion.rs @@ -14,9 +14,11 @@ use crate::values::specified::SVGPathData; Clone, Copy, Debug, + Deserialize, MallocSizeOf, Parse, PartialEq, + Serialize, SpecifiedValueInfo, ToAnimatedZero, ToComputedValue, @@ -41,8 +43,10 @@ pub enum RaySize { Clone, ComputeSquaredDistance, Debug, + Deserialize, MallocSizeOf, PartialEq, + Serialize, SpecifiedValueInfo, ToAnimatedZero, ToComputedValue, diff --git a/components/style_traits/Cargo.toml b/components/style_traits/Cargo.toml index 213c09b08df7..f3dd0df744fa 100644 --- a/components/style_traits/Cargo.toml +++ b/components/style_traits/Cargo.toml @@ -10,7 +10,7 @@ name = "style_traits" path = "lib.rs" [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 = [] [dependencies] @@ -22,7 +22,7 @@ lazy_static = "1" malloc_size_of = { path = "../malloc_size_of" } malloc_size_of_derive = "0.1" selectors = { path = "../selectors" } -serde = {version = "1.0", optional = true} +serde = "1.0" webrender_api = {git = "https://github.com/servo/webrender", optional = true} servo_atoms = {path = "../atoms", optional = true} servo_arc = { path = "../servo_arc" } diff --git a/components/style_traits/lib.rs b/components/style_traits/lib.rs index b2dcc8431cbc..3fb17743c13b 100644 --- a/components/style_traits/lib.rs +++ b/components/style_traits/lib.rs @@ -22,7 +22,6 @@ extern crate malloc_size_of; #[macro_use] extern crate malloc_size_of_derive; extern crate selectors; -#[cfg(feature = "servo")] #[macro_use] extern crate serde; extern crate servo_arc; diff --git a/components/style_traits/values.rs b/components/style_traits/values.rs index 0c3166858a28..66c1d79cd075 100644 --- a/components/style_traits/values.rs +++ b/components/style_traits/values.rs @@ -507,7 +507,9 @@ pub mod specified { /// Whether to allow negative lengths or not. #[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 { /// Allow all kind of numeric values. All,