style: Remove refcount for StyleBasicShape draft
authorTing-Yu Lin <tlin@mozilla.com>
Tue, 26 Sep 2017 10:53:59 +0800
changeset 673012 d27ac22c6f74f65717e2c07294a49be77f4247dc
parent 673011 d1743e5c711e419f63c204ba4e507db842895942
child 673013 98419e7b43ac10129d08b8b9f1ebd88f2dfe962a
push id82436
push userbmo:tlin@mozilla.com
push dateSat, 30 Sep 2017 06:12:02 +0000
bugs1404243
milestone58.0a1
style: Remove refcount for StyleBasicShape This is due to Bug 1404243 Part 3. MozReview-Commit-ID: DKymebmAYLX
servo/components/style/gecko/conversions.rs
servo/components/style/properties/gecko.mako.rs
--- a/servo/components/style/gecko/conversions.rs
+++ b/servo/components/style/gecko/conversions.rs
@@ -618,17 +618,17 @@ pub mod basic_shape {
                 StyleShapeSourceType::URL => {
                     unsafe {
                         let other_url = &(**other.__bindgen_anon_1.mURL.as_ref());
                         let url = SpecifiedUrl::from_url_value_data(&other_url._base).unwrap();
                         ShapeSource::Url(url)
                     }
                 },
                 StyleShapeSourceType::Shape => {
-                    let other_shape = unsafe { &(**other.__bindgen_anon_1.mBasicShape.as_ref()) };
+                    let other_shape = unsafe { &*other.mBasicShape.mPtr };
                     let shape = other_shape.into();
                     let reference_box = if other.mReferenceBox == StyleGeometryBox::NoBox {
                         None
                     } else {
                         Some(other.mReferenceBox.into())
                     };
                     ShapeSource::Shape(shape, reference_box)
                 }
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -4941,27 +4941,23 @@ fn static_assert() {
                 }
             }
             ShapeSource::None => {} // don't change the type
             ShapeSource::Box(reference) => {
                 ${ident}.mReferenceBox = reference.into();
                 ${ident}.mType = StyleShapeSourceType::Box;
             }
             ShapeSource::Shape(servo_shape, maybe_box) => {
-                ${ident}.mReferenceBox = maybe_box.map(Into::into)
-                                                   .unwrap_or(StyleGeometryBox::NoBox);
-                ${ident}.mType = StyleShapeSourceType::Shape;
-
-                fn init_shape(${ident}: &mut StyleShapeSource, ty: StyleBasicShapeType) -> &mut StyleBasicShape {
+                fn init_shape(${ident}: &mut StyleShapeSource, basic_shape_type: StyleBasicShapeType)
+                              -> &mut StyleBasicShape {
                     unsafe {
-                        // We have to be very careful to avoid a copy here!
-                        let ref mut union = ${ident}.__bindgen_anon_1;
-                        let shape: &mut *mut StyleBasicShape = union.mBasicShape.as_mut();
-                        *shape = Gecko_NewBasicShape(ty);
-                        &mut **shape
+                        // Create StyleBasicShape in StyleShapeSource. mReferenceBox and mType
+                        // will be set manually later.
+                        Gecko_NewBasicShape(${ident}, basic_shape_type);
+                        &mut *${ident}.mBasicShape.mPtr
                     }
                 }
                 match servo_shape {
                     BasicShape::Inset(inset) => {
                         let shape = init_shape(${ident}, StyleBasicShapeType::Inset);
                         unsafe { shape.mCoordinates.set_len(4) };
 
                         // set_len() can't call constructors, so the coordinates
@@ -5013,16 +5009,20 @@ fn static_assert() {
                         }
                         shape.mFillRule = if poly.fill == FillRule::EvenOdd {
                             StyleFillRule::Evenodd
                         } else {
                             StyleFillRule::Nonzero
                         };
                     }
                 }
+
+                ${ident}.mReferenceBox = maybe_box.map(Into::into)
+                                                  .unwrap_or(StyleGeometryBox::NoBox);
+                ${ident}.mType = StyleShapeSourceType::Shape;
             }
         }
 
     }
 
     pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
         (&self.gecko.${gecko_ffi_name}).into()
     }