Bug 1326406 Part 2 - Extract the computation of ellipse radii as ComputeEllipseRadii(). r=dbaron
authorTing-Yu Lin <tlin@mozilla.com>
Mon, 23 Jan 2017 17:17:05 +0800
changeset 377685 166f7bf0f4074a7a76d493cf3feb946d6584f0ed
parent 377684 16c24b3a1e5cf4502f6f7520f9264665a8d27477
child 377686 1557fe7d766b7568e8cbdf57c6feb12c90625127
push id7198
push userjlorenzo@mozilla.com
push dateTue, 18 Apr 2017 12:07:49 +0000
treeherdermozilla-beta@d57aa49c3948 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs1326406
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1326406 Part 2 - Extract the computation of ellipse radii as ComputeEllipseRadii(). r=dbaron MozReview-Commit-ID: LPdvg66adHQ
layout/base/ShapeUtils.cpp
layout/base/ShapeUtils.h
layout/svg/nsCSSClipPathInstance.cpp
--- a/layout/base/ShapeUtils.cpp
+++ b/layout/base/ShapeUtils.cpp
@@ -72,9 +72,37 @@ ShapeUtils::ComputeCircleRadius(StyleBas
       SVGContentUtils::ComputeNormalizedHypotenuse(aRefBox.width,
                                                    aRefBox.height);
     r = nsRuleNode::ComputeCoordPercentCalc(coords[0],
                                             NSToCoordRound(referenceLength));
   }
   return r;
 }
 
+nsSize
+ShapeUtils::ComputeEllipseRadii(StyleBasicShape* const aBasicShape,
+                                const nsPoint& aCenter,
+                                const nsRect& aRefBox)
+{
+  const nsTArray<nsStyleCoord>& coords = aBasicShape->Coordinates();
+  MOZ_ASSERT(coords.Length() == 2, "wrong number of arguments");
+  nsSize radii;
+
+  if (coords[0].GetUnit() == eStyleUnit_Enumerated) {
+    const StyleShapeRadius radiusX = coords[0].GetEnumValue<StyleShapeRadius>();
+    radii.width = ComputeShapeRadius(radiusX, aCenter.x, aRefBox.x,
+                                     aRefBox.XMost());
+  } else {
+    radii.width = nsRuleNode::ComputeCoordPercentCalc(coords[0], aRefBox.width);
+  }
+
+  if (coords[1].GetUnit() == eStyleUnit_Enumerated) {
+    const StyleShapeRadius radiusY = coords[1].GetEnumValue<StyleShapeRadius>();
+    radii.height = ComputeShapeRadius(radiusY, aCenter.y, aRefBox.y,
+                                      aRefBox.YMost());
+  } else {
+    radii.height = nsRuleNode::ComputeCoordPercentCalc(coords[1], aRefBox.height);
+  }
+
+  return radii;
+}
+
 } // namespace mozilla
--- a/layout/base/ShapeUtils.h
+++ b/layout/base/ShapeUtils.h
@@ -43,13 +43,22 @@ struct ShapeUtils final
 
   // Compute the radius for a circle.
   // @param aCenter the center of the circle.
   // @param aRefBox the reference box of the circle.
   // @return The length of the radius in app units.
   static nscoord ComputeCircleRadius(
     mozilla::StyleBasicShape* const aBasicShape,
     const nsPoint& aCenter, const nsRect& aRefBox);
+
+  // Compute the radii for an ellipse.
+  // @param aCenter the center of the ellipse.
+  // @param aRefBox the reference box of the ellipse.
+  // @return The radii of the ellipse in app units. The width and height
+  // represent the x-axis and y-axis radii of the ellipse.
+  static nsSize ComputeEllipseRadii(
+    mozilla::StyleBasicShape* const aBasicShape,
+    const nsPoint& aCenter, const nsRect& aRefBox);
 };
 
 } // namespace mozilla
 
 #endif // mozilla_ShapeUtils_h
--- a/layout/svg/nsCSSClipPathInstance.cpp
+++ b/layout/svg/nsCSSClipPathInstance.cpp
@@ -130,42 +130,22 @@ nsCSSClipPathInstance::CreateClipPathEll
                                              const nsRect& aRefBox)
 {
   StyleBasicShape* basicShape = mClipPathStyle.GetBasicShape();
 
   RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder();
 
   nsPoint center =
     ShapeUtils::ComputeCircleOrEllipseCenter(basicShape, aRefBox);
-
-  const nsTArray<nsStyleCoord>& coords = basicShape->Coordinates();
-  MOZ_ASSERT(coords.Length() == 2, "wrong number of arguments");
-  nscoord rx = 0, ry = 0;
-  if (coords[0].GetUnit() == eStyleUnit_Enumerated) {
-    rx = ShapeUtils::ComputeShapeRadius(coords[0].GetEnumValue<StyleShapeRadius>(),
-                                        center.x,
-                                        aRefBox.x,
-                                        aRefBox.x + aRefBox.width);
-  } else {
-    rx = nsRuleNode::ComputeCoordPercentCalc(coords[0], aRefBox.width);
-  }
-  if (coords[1].GetUnit() == eStyleUnit_Enumerated) {
-    ry = ShapeUtils::ComputeShapeRadius(coords[1].GetEnumValue<StyleShapeRadius>(),
-                                        center.y,
-                                        aRefBox.y,
-                                        aRefBox.y + aRefBox.height);
-  } else {
-    ry = nsRuleNode::ComputeCoordPercentCalc(coords[1], aRefBox.height);
-  }
-
+  nsSize radii = ShapeUtils::ComputeEllipseRadii(basicShape, center, aRefBox);
   nscoord appUnitsPerDevPixel =
     mTargetFrame->PresContext()->AppUnitsPerDevPixel();
   EllipseToBezier(builder.get(),
                   Point(center.x, center.y) / appUnitsPerDevPixel,
-                  Size(rx, ry) / appUnitsPerDevPixel);
+                  Size(radii.width, radii.height) / appUnitsPerDevPixel);
   builder->Close();
   return builder->Finish();
 }
 
 already_AddRefed<Path>
 nsCSSClipPathInstance::CreateClipPathPolygon(DrawTarget* aDrawTarget,
                                              const nsRect& aRefBox)
 {