servo: Merge #13695 - avoid initializing image layers after repeat/origin values have already been written (from heycam:layer-init); r=Manishearth
authorCameron McCormack <cam@mcc.id.au>
Tue, 11 Oct 2016 18:37:39 -0500
changeset 339890 fb24eb654269199c1954f73d415ebc4420d4743b
parent 339889 a8a707b7b5641596e8bce76e41e39056eb0db86f
child 339891 d844fcce600ece7386e585fc002ee4ef524a8287
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersManishearth
servo: Merge #13695 - avoid initializing image layers after repeat/origin values have already been written (from heycam:layer-init); r=Manishearth <!-- Please describe your changes on the following line: --> @bors-servo r=manishearth given in https://bugzilla.mozilla.org/show_bug.cgi?id=1309081 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 4ca7ce6329421d031188dd071c4d75c475a0cc88
servo/components/style/gecko_bindings/bindings.rs
servo/components/style/properties/gecko.mako.rs
--- a/servo/components/style/gecko_bindings/bindings.rs
+++ b/servo/components/style/gecko_bindings/bindings.rs
@@ -489,22 +489,19 @@ extern "C" {
     pub fn Gecko_ClearStyleContents(content: *mut nsStyleContent);
 }
 extern "C" {
     pub fn Gecko_CopyStyleContentsFrom(content: *mut nsStyleContent,
                                        other: *const nsStyleContent);
 }
 extern "C" {
     pub fn Gecko_EnsureImageLayersLength(layers: *mut nsStyleImageLayers,
-                                         len: usize);
-}
-extern "C" {
-    pub fn Gecko_InitializeImageLayer(layer: *mut nsStyleImageLayers_Layer,
-                                      layer_type:
-                                          nsStyleImageLayers_LayerType);
+                                         len: usize,
+                                         layer_type:
+                                             nsStyleImageLayers_LayerType);
 }
 extern "C" {
     pub fn Gecko_ResetStyleCoord(unit: *mut nsStyleUnit,
                                  value: *mut nsStyleUnion);
 }
 extern "C" {
     pub fn Gecko_SetStyleCoordCalcValue(unit: *mut nsStyleUnit,
                                         value: *mut nsStyleUnion,
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -18,17 +18,17 @@ use gecko_bindings::bindings::Gecko_Copy
 use gecko_bindings::bindings::Gecko_Destroy_${style_struct.gecko_ffi_name};
 % endfor
 use gecko_bindings::bindings::{Gecko_CopyMozBindingFrom, Gecko_CopyListStyleTypeFrom};
 use gecko_bindings::bindings::{Gecko_SetMozBinding, Gecko_SetListStyleType};
 use gecko_bindings::bindings::{Gecko_SetNullImageValue, Gecko_SetGradientImageValue};
 use gecko_bindings::bindings::{Gecko_EnsureImageLayersLength, Gecko_CreateGradient};
 use gecko_bindings::bindings::{Gecko_CopyImageValueFrom, Gecko_CopyFontFamilyFrom};
 use gecko_bindings::bindings::{Gecko_FontFamilyList_AppendGeneric, Gecko_FontFamilyList_AppendNamed};
-use gecko_bindings::bindings::{Gecko_FontFamilyList_Clear, Gecko_InitializeImageLayer};
+use gecko_bindings::bindings::{Gecko_FontFamilyList_Clear};
 use gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull;
 use gecko_bindings::structs;
 use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordData, CoordDataMut};
 use gecko_bindings::sugar::ownership::HasArcFFI;
 use gecko::values::{StyleCoordHelpers, GeckoStyleCoordConvertible, convert_nscolor_to_rgba};
 use gecko::values::convert_rgba_to_nscolor;
 use gecko::values::round_border_to_device_pixels;
 use logical_geometry::WritingMode;
@@ -944,34 +944,40 @@ fn static_assert() {
 
 </%self:impl_trait>
 
 <%def name="simple_image_array_property(name, shorthand, field_name)">
     <%
         image_layers_field = "mImage" if shorthand == "background" else "mMask"
     %>
     pub fn copy_${shorthand}_${name}_from(&mut self, other: &Self) {
+        use gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType;
+
         unsafe {
             Gecko_EnsureImageLayersLength(&mut self.gecko.${image_layers_field},
-                                          other.gecko.${image_layers_field}.mLayers.len());
+                                          other.gecko.${image_layers_field}.mLayers.len(),
+                                          LayerType::${shorthand.title()});
         }
         for (layer, other) in self.gecko.${image_layers_field}.mLayers.iter_mut()
                                   .zip(other.gecko.${image_layers_field}.mLayers.iter())
                                   .take(other.gecko.${image_layers_field}
                                                    .${field_name}Count as usize) {
             layer.${field_name} = other.${field_name};
         }
         self.gecko.${image_layers_field}.${field_name}Count =
             other.gecko.${image_layers_field}.${field_name}Count;
     }
 
     pub fn set_${shorthand}_${name}(&mut self,
                                     v: longhands::${shorthand}_${name}::computed_value::T) {
+        use gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType;
+
         unsafe {
-          Gecko_EnsureImageLayersLength(&mut self.gecko.${image_layers_field}, v.0.len());
+          Gecko_EnsureImageLayersLength(&mut self.gecko.${image_layers_field}, v.0.len(),
+                                        LayerType::${shorthand.title()});
         }
 
         self.gecko.${image_layers_field}.${field_name}Count = v.0.len() as u32;
         for (servo, geckolayer) in v.0.into_iter()
                                     .zip(self.gecko.${image_layers_field}.mLayers.iter_mut()) {
             geckolayer.${field_name} = {
                 ${caller.body()}
             };
@@ -1027,25 +1033,28 @@ fn static_assert() {
         match servo {
             T::border_box => structs::NS_STYLE_IMAGELAYER_ORIGIN_BORDER as u8,
             T::padding_box => structs::NS_STYLE_IMAGELAYER_ORIGIN_PADDING as u8,
             T::content_box => structs::NS_STYLE_IMAGELAYER_ORIGIN_CONTENT as u8,
         }
     </%self:simple_image_array_property>
 
     pub fn copy_${shorthand}_position_from(&mut self, other: &Self) {
+        use gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType;
+
         self.gecko.${image_layers_field}.mPositionXCount
                 = cmp::min(1, other.gecko.${image_layers_field}.mPositionXCount);
         self.gecko.${image_layers_field}.mPositionYCount
                 = cmp::min(1, other.gecko.${image_layers_field}.mPositionYCount);
         self.gecko.${image_layers_field}.mLayers.mFirstElement.mPosition =
             other.gecko.${image_layers_field}.mLayers.mFirstElement.mPosition;
         unsafe {
             Gecko_EnsureImageLayersLength(&mut self.gecko.${image_layers_field},
-                                          other.gecko.${image_layers_field}.mLayers.len());
+                                          other.gecko.${image_layers_field}.mLayers.len(),
+                                          LayerType::${shorthand.title()});
         }
         for (layer, other) in self.gecko.${image_layers_field}.mLayers.iter_mut()
                                   .zip(other.gecko.${image_layers_field}.mLayers.iter())
                                   .take(other.gecko.${image_layers_field}.mPositionXCount as usize) {
             layer.mPosition.mXPosition
                 = other.mPosition.mXPosition;
         }
         for (layer, other) in self.gecko.${image_layers_field}.mLayers.iter_mut()
@@ -1072,18 +1081,21 @@ fn static_assert() {
                     vertical: position.mPosition.mYPosition.into(),
                 })
                 .collect()
         )
     }
 
     pub fn set_${shorthand}_position(&mut self,
                                      v: longhands::${shorthand}_position::computed_value::T) {
+        use gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType;
+
         unsafe {
-          Gecko_EnsureImageLayersLength(&mut self.gecko.${image_layers_field}, v.0.len());
+          Gecko_EnsureImageLayersLength(&mut self.gecko.${image_layers_field}, v.0.len(),
+                                        LayerType::${shorthand.title()});
         }
 
         self.gecko.${image_layers_field}.mPositionXCount = v.0.len() as u32;
         self.gecko.${image_layers_field}.mPositionYCount = v.0.len() as u32;
         for (servo, geckolayer) in v.0.into_iter().zip(self.gecko.${image_layers_field}
                                                            .mLayers.iter_mut()) {
             geckolayer.mPosition.mXPosition = servo.horizontal.into();
             geckolayer.mPosition.mYPosition = servo.vertical.into();
@@ -1339,20 +1351,18 @@ fn static_assert() {
         }
 
         unsafe {
             // Prevent leaking of the last elements we did set
             for image in &mut self.gecko.${image_layers_field}.mLayers {
                 Gecko_SetNullImageValue(&mut image.mImage)
             }
             // XXXManishearth clear mSourceURI for masks
-            Gecko_EnsureImageLayersLength(&mut self.gecko.${image_layers_field}, images.0.len());
-            for image in &mut self.gecko.${image_layers_field}.mLayers {
-                Gecko_InitializeImageLayer(image, LayerType::${shorthand.title()});
-            }
+            Gecko_EnsureImageLayersLength(&mut self.gecko.${image_layers_field}, images.0.len(),
+                                          LayerType::${shorthand.title()});
         }
 
         self.gecko.${image_layers_field}.mImageCount = images.0.len() as u32;
 
         for (image, geckoimage) in images.0.into_iter().zip(self.gecko.${image_layers_field}
                                                                 .mLayers.iter_mut()) {
             % if shorthand == "background":
                 if let Some(image) = image.0 {