Bug 1485823 - Use cbindgen for basic_shape::FillRule. r=xidorn
authorBoris Chiou <boris.chiou@gmail.com>
Thu, 23 Aug 2018 23:00:16 +0000
changeset 481568 4a333f450838fbc7dd58146696e2ec9a11e84bdf
parent 481567 623fd496e6ea0c24428ba413e0f63ff3809121df
child 481569 073b8e49194afc45eca6efbc08f903128fe0d7bd
push id232
push userfmarier@mozilla.com
push dateWed, 05 Sep 2018 20:45:54 +0000
reviewersxidorn
bugs1485823
milestone63.0a1
Bug 1485823 - Use cbindgen for basic_shape::FillRule. r=xidorn Just a minor fix to use cbindgen to avoid the conversion between basic_shape::FillRule and mozilla::StyleFillRule. Differential Revision: https://phabricator.services.mozilla.com/D4171
layout/style/nsStyleConsts.h
servo/components/style/cbindgen.toml
servo/components/style/properties/gecko.mako.rs
servo/components/style/values/generics/basic_shape.rs
--- a/layout/style/nsStyleConsts.h
+++ b/layout/style/nsStyleConsts.h
@@ -140,22 +140,16 @@ enum class StyleGeometryBox : uint8_t {
                          // background-clip is 'padding' when we have a solid
                          // border" optimization.  This isn't actually equal
                          // to StyleGeometryBox::Padding because using that
                          // causes antialiasing seams between the background
                          // and border.
                          // background-clip only.
 };
 
-// fill-rule
-enum class StyleFillRule : uint8_t {
-  Nonzero,
-  Evenodd,
-};
-
 // float
 // https://developer.mozilla.org/en-US/docs/Web/CSS/float
 enum class StyleFloat : uint8_t {
   None,
   Left,
   Right,
 };
 
--- a/servo/components/style/cbindgen.toml
+++ b/servo/components/style/cbindgen.toml
@@ -18,10 +18,16 @@ namespaces = ["mozilla"]
 [struct]
 derive_eq = true
 
 [enum]
 derive_helper_methods = true
 
 [export]
 prefix = "Style"
-include = ["StyleDisplay", "StyleAppearance", "StyleDisplayMode", "StylePathCommand"]
+include = [
+  "StyleAppearance",
+  "StyleDisplay",
+  "StyleDisplayMode",
+  "StyleFillRule",
+  "StylePathCommand"
+]
 item_types = ["enums", "structs", "typedefs"]
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -4981,20 +4981,20 @@ fn static_assert() {
         (self.gecko.mTextDecorationLine & (structs::NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH as u8)) != 0
     }
 </%self:impl_trait>
 
 <%def name="impl_shape_source(ident, gecko_ffi_name)">
     pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
         use gecko_bindings::bindings::{Gecko_NewBasicShape, Gecko_DestroyShapeSource};
         use gecko_bindings::structs::{StyleBasicShape, StyleBasicShapeType, StyleShapeSourceType};
-        use gecko_bindings::structs::{StyleFillRule, StyleGeometryBox, StyleShapeSource};
+        use gecko_bindings::structs::{StyleGeometryBox, StyleShapeSource};
         use gecko::conversions::basic_shape::set_corners_from_radius;
         use gecko::values::GeckoStyleCoordConvertible;
-        use values::generics::basic_shape::{BasicShape, FillRule, ShapeSource};
+        use values::generics::basic_shape::{BasicShape, ShapeSource};
 
         let ref mut ${ident} = self.gecko.${gecko_ffi_name};
 
         // clean up existing struct
         unsafe { Gecko_DestroyShapeSource(${ident}) };
         ${ident}.mType = StyleShapeSourceType::None;
 
         match v {
@@ -5078,21 +5078,18 @@ fn static_assert() {
                             shape.mCoordinates.set_len(poly.coordinates.len() as u32 * 2);
                         }
                         for (i, coord) in poly.coordinates.iter().enumerate() {
                             shape.mCoordinates[2 * i].leaky_set_null();
                             shape.mCoordinates[2 * i + 1].leaky_set_null();
                             coord.0.to_gecko_style_coord(&mut shape.mCoordinates[2 * i]);
                             coord.1.to_gecko_style_coord(&mut shape.mCoordinates[2 * i + 1]);
                         }
-                        shape.mFillRule = if poly.fill == FillRule::Evenodd {
-                            StyleFillRule::Evenodd
-                        } else {
-                            StyleFillRule::Nonzero
-                        };
+                        // unsafe: cbindgen ensures the representation is the same.
+                        shape.mFillRule = unsafe { transmute(poly.fill) };
                     }
                 }
 
                 ${ident}.mReferenceBox = maybe_box.map(Into::into)
                                                   .unwrap_or(StyleGeometryBox::NoBox);
                 ${ident}.mType = StyleShapeSourceType::Shape;
             }
         }
--- a/servo/components/style/values/generics/basic_shape.rs
+++ b/servo/components/style/values/generics/basic_shape.rs
@@ -133,16 +133,17 @@ pub struct PolygonCoord<LengthOrPercenta
 // https://drafts.csswg.org/css-shapes/#typedef-fill-rule
 // NOTE: Basic shapes spec says that these are the only two values, however
 // https://www.w3.org/TR/SVG/painting.html#FillRuleProperty
 // says that it can also be `inherit`
 #[allow(missing_docs)]
 #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
 #[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq,
          SpecifiedValueInfo, ToComputedValue, ToCss)]
+#[repr(u8)]
 pub enum FillRule {
     Nonzero,
     Evenodd,
 }
 
 // FIXME(nox): Implement ComputeSquaredDistance for T types and stop
 // using PartialEq here, this will let us derive this impl.
 impl<B, T, U> ComputeSquaredDistance for ShapeSource<B, T, U>