Bug 1091794 - Replace gfxCornerSizes with Moz2D's RectCornerRadii. r=mattwoodrow
authorJonathan Watt <jwatt@jwatt.org>
Sat, 01 Nov 2014 10:45:10 +0000
changeset 239908 b7805b80ca0d51c01fa11684c0503e655f59d08c
parent 239907 35011c4e3e29cb5b90a65a3275b785701c1bec43
child 239909 e89c06c004f828dfabff49f45725557f88e4db04
push id660
push userraliiev@mozilla.com
push dateWed, 18 Feb 2015 20:30:48 +0000
treeherdermozilla-release@49e493494178 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1091794
milestone36.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 1091794 - Replace gfxCornerSizes with Moz2D's RectCornerRadii. r=mattwoodrow
gfx/thebes/RoundedRect.h
gfx/thebes/gfxBlur.cpp
gfx/thebes/gfxBlur.h
gfx/thebes/gfxContext.cpp
gfx/thebes/gfxContext.h
gfx/thebes/gfxRect.h
layout/base/DisplayItemClip.cpp
layout/base/DisplayItemClip.h
layout/base/nsCSSRendering.cpp
layout/base/nsCSSRendering.h
layout/base/nsCSSRenderingBorders.cpp
layout/base/nsCSSRenderingBorders.h
layout/base/nsLayoutUtils.cpp
layout/base/nsLayoutUtils.h
--- a/gfx/thebes/RoundedRect.h
+++ b/gfx/thebes/RoundedRect.h
@@ -1,40 +1,43 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "gfxRect.h"
+#include "mozilla/gfx/PathHelpers.h"
 
 namespace mozilla {
 /* A rounded rectangle abstraction.
  *
  * This can represent a rectangle with a different pair of radii on each corner.
  *
  * Note: CoreGraphics and Direct2D only support rounded rectangle with the same
  * radii on all corners. However, supporting CSS's border-radius requires the extra flexibility. */
 struct RoundedRect {
-    RoundedRect(gfxRect &aRect, gfxCornerSizes &aCorners) : rect(aRect), corners(aCorners) { }
+    typedef mozilla::gfx::RectCornerRadii RectCornerRadii;
+
+    RoundedRect(gfxRect &aRect, RectCornerRadii &aCorners) : rect(aRect), corners(aCorners) { }
     void Deflate(gfxFloat aTopWidth, gfxFloat aBottomWidth, gfxFloat aLeftWidth, gfxFloat aRightWidth) {
         // deflate the internal rect
         rect.x += aLeftWidth;
         rect.y += aTopWidth;
         rect.width = std::max(0., rect.width - aLeftWidth - aRightWidth);
         rect.height = std::max(0., rect.height - aTopWidth - aBottomWidth);
 
-        corners.sizes[NS_CORNER_TOP_LEFT].width  = std::max(0., corners.sizes[NS_CORNER_TOP_LEFT].width - aLeftWidth);
-        corners.sizes[NS_CORNER_TOP_LEFT].height = std::max(0., corners.sizes[NS_CORNER_TOP_LEFT].height - aTopWidth);
+        corners.radii[NS_CORNER_TOP_LEFT].width  = std::max(0., corners.radii[NS_CORNER_TOP_LEFT].width - aLeftWidth);
+        corners.radii[NS_CORNER_TOP_LEFT].height = std::max(0., corners.radii[NS_CORNER_TOP_LEFT].height - aTopWidth);
 
-        corners.sizes[NS_CORNER_TOP_RIGHT].width  = std::max(0., corners.sizes[NS_CORNER_TOP_RIGHT].width - aRightWidth);
-        corners.sizes[NS_CORNER_TOP_RIGHT].height = std::max(0., corners.sizes[NS_CORNER_TOP_RIGHT].height - aTopWidth);
+        corners.radii[NS_CORNER_TOP_RIGHT].width  = std::max(0., corners.radii[NS_CORNER_TOP_RIGHT].width - aRightWidth);
+        corners.radii[NS_CORNER_TOP_RIGHT].height = std::max(0., corners.radii[NS_CORNER_TOP_RIGHT].height - aTopWidth);
 
-        corners.sizes[NS_CORNER_BOTTOM_LEFT].width  = std::max(0., corners.sizes[NS_CORNER_BOTTOM_LEFT].width - aLeftWidth);
-        corners.sizes[NS_CORNER_BOTTOM_LEFT].height = std::max(0., corners.sizes[NS_CORNER_BOTTOM_LEFT].height - aBottomWidth);
+        corners.radii[NS_CORNER_BOTTOM_LEFT].width  = std::max(0., corners.radii[NS_CORNER_BOTTOM_LEFT].width - aLeftWidth);
+        corners.radii[NS_CORNER_BOTTOM_LEFT].height = std::max(0., corners.radii[NS_CORNER_BOTTOM_LEFT].height - aBottomWidth);
 
-        corners.sizes[NS_CORNER_BOTTOM_RIGHT].width  = std::max(0., corners.sizes[NS_CORNER_BOTTOM_RIGHT].width - aRightWidth);
-        corners.sizes[NS_CORNER_BOTTOM_RIGHT].height = std::max(0., corners.sizes[NS_CORNER_BOTTOM_RIGHT].height - aBottomWidth);
+        corners.radii[NS_CORNER_BOTTOM_RIGHT].width  = std::max(0., corners.radii[NS_CORNER_BOTTOM_RIGHT].width - aRightWidth);
+        corners.radii[NS_CORNER_BOTTOM_RIGHT].height = std::max(0., corners.radii[NS_CORNER_BOTTOM_RIGHT].height - aBottomWidth);
     }
     gfxRect rect;
-    gfxCornerSizes corners;
+    RectCornerRadii corners;
 };
 
 } // namespace mozilla
--- a/gfx/thebes/gfxBlur.cpp
+++ b/gfx/thebes/gfxBlur.cpp
@@ -1,19 +1,21 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "gfxBlur.h"
+
+#include "gfx2DGlue.h"
 #include "gfxContext.h"
 #include "gfxPlatform.h"
-
+#include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/Blur.h"
-#include "mozilla/gfx/2D.h"
+#include "mozilla/gfx/PathHelpers.h"
 #include "mozilla/UniquePtr.h"
 #include "nsExpirationTracker.h"
 #include "nsClassHashtable.h"
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 
 gfxAlphaBoxBlur::gfxAlphaBoxBlur()
@@ -357,56 +359,54 @@ gfxAlphaBoxBlur::ShutdownBlurCache()
 {
   delete gBlurCache;
   gBlurCache = nullptr;
 }
 
 /* static */ void
 gfxAlphaBoxBlur::BlurRectangle(gfxContext *aDestinationCtx,
                                const gfxRect& aRect,
-                               gfxCornerSizes* aCornerRadii,
+                               RectCornerRadii* aCornerRadii,
                                const gfxPoint& aBlurStdDev,
                                const gfxRGBA& aShadowColor,
                                const gfxRect& aDirtyRect,
                                const gfxRect& aSkipRect)
 {
+  DrawTarget& aDrawTarget = *aDestinationCtx->GetDrawTarget();
+
   gfxIntSize blurRadius = CalculateBlurRadius(aBlurStdDev);
-    
-  DrawTarget *dt = aDestinationCtx->GetDrawTarget();
-  if (!dt) {
-    NS_WARNING("Blurring not supported for Thebes contexts!");
-    return;
-  }
 
   IntPoint topLeft;
-  RefPtr<SourceSurface> surface = GetCachedBlur(dt, aRect, blurRadius, aSkipRect, aDirtyRect, &topLeft);
+  RefPtr<SourceSurface> surface = GetCachedBlur(&aDrawTarget, aRect, blurRadius, aSkipRect, aDirtyRect, &topLeft);
   if (!surface) {
     // Create the temporary surface for blurring
     gfxAlphaBoxBlur blur;
-    gfxContext *dest = blur.Init(aRect, gfxIntSize(), blurRadius, &aDirtyRect, &aSkipRect);
-
-    if (!dest) {
+    gfxContext* blurCtx = blur.Init(aRect, gfxIntSize(), blurRadius, &aDirtyRect, &aSkipRect);
+    if (!blurCtx) {
       return;
     }
+    DrawTarget* blurDT = blurCtx->GetDrawTarget();
 
-    gfxRect shadowGfxRect = aRect;
+    Rect shadowGfxRect = ToRect(aRect);
     shadowGfxRect.Round();
 
-    dest->NewPath();
+    ColorPattern black(Color(0.f, 0.f, 0.f, 1.f)); // For masking, so no ToDeviceColor!
     if (aCornerRadii) {
-      dest->RoundedRectangle(shadowGfxRect, *aCornerRadii);
+      RefPtr<Path> roundedRect = MakePathForRoundedRect(*blurDT,
+                                                        shadowGfxRect,
+                                                        *aCornerRadii);
+      blurDT->Fill(roundedRect, black);
     } else {
-      dest->Rectangle(shadowGfxRect);
+      blurDT->FillRect(shadowGfxRect, black);
     }
-    dest->Fill();
 
-    surface = blur.DoBlur(dt, &topLeft);
+    surface = blur.DoBlur(&aDrawTarget, &topLeft);
     if (!surface) {
       return;
     }
-    CacheBlur(dt, aRect, blurRadius, aSkipRect, surface, topLeft, aDirtyRect);
+    CacheBlur(&aDrawTarget, aRect, blurRadius, aSkipRect, surface, topLeft, aDirtyRect);
   }
 
   aDestinationCtx->SetColor(aShadowColor);
   Rect dirtyRect(aDirtyRect.x, aDirtyRect.y, aDirtyRect.width, aDirtyRect.height);
   DrawBlur(aDestinationCtx, surface, topLeft, &dirtyRect);
 }
 
--- a/gfx/thebes/gfxBlur.h
+++ b/gfx/thebes/gfxBlur.h
@@ -11,22 +11,22 @@
 #include "nsAutoPtr.h"
 #include "gfxPoint.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/UniquePtr.h"
 
 class gfxContext;
 struct gfxRect;
 struct gfxRGBA;
-struct gfxCornerSizes;
 class gfxMatrix;
 
 namespace mozilla {
   namespace gfx {
     class AlphaBoxBlur;
+    struct RectCornerRadii;
     class SourceSurface;
     class DrawTarget;
   }
 }
 
 /**
  * Implementation of a triple box blur approximation of a Gaussian blur.
  *
@@ -43,16 +43,18 @@ namespace mozilla {
  * pixels within a square of side length 2N+1 centered on the output pixel.
  * 
  * A temporary surface is created in the Init function. The caller then draws
  * any desired content onto the context acquired through GetContext, and lastly
  * calls Paint to apply the blurred content as an alpha mask.
  */
 class gfxAlphaBoxBlur
 {
+    typedef mozilla::gfx::RectCornerRadii RectCornerRadii;
+
 public:
     gfxAlphaBoxBlur();
 
     ~gfxAlphaBoxBlur();
 
     /**
      * Constructs a box blur and initializes the temporary surface.
      * @param aRect The coordinates of the surface to create in device units.
@@ -121,17 +123,17 @@ public:
      * @param aShadowColor         The color to draw the blurred shadow.
      * @param aDirtyRect           An area in device pixels that is dirty and needs
      *                             to be redrawn.
      * @param aSkipRect            An area in device pixels to avoid blurring over,
      *                             to prevent unnecessary work.
      */
     static void BlurRectangle(gfxContext *aDestinationCtx,
                               const gfxRect& aRect,
-                              gfxCornerSizes* aCornerRadii,
+                              RectCornerRadii* aCornerRadii,
                               const gfxPoint& aBlurStdDev,
                               const gfxRGBA& aShadowColor,
                               const gfxRect& aDirtyRect,
                               const gfxRect& aSkipRect);
 
     static void ShutdownBlurCache();
 
 
--- a/gfx/thebes/gfxContext.cpp
+++ b/gfx/thebes/gfxContext.cpp
@@ -1075,17 +1075,17 @@ gfxContext::PopGroupToSource()
   mat.Invert();
   mat.PreTranslate(deviceOffset.x, deviceOffset.y); // device offset translation
 
   CurrentState().surfTransform = mat;
 }
 
 void
 gfxContext::RoundedRectangle(const gfxRect& rect,
-                             const gfxCornerSizes& corners,
+                             const RectCornerRadii& corners,
                              bool draw_clockwise)
 {
     //
     // For CW drawing, this looks like:
     //
     //  ...******0**      1    C
     //              ****
     //                  ***    2
@@ -1149,21 +1149,17 @@ gfxContext::RoundedRectangle(const gfxRe
     // 'alpha' gives much smaller radial error, even for very flat
     // ellipses, than Maisonobe's equivalent.
     //
     // For the various corners and for each axis, the sign of this
     // constant changes, or it might be 0 -- it's multiplied by the
     // appropriate multiplier from the list before using.
 
   EnsurePathBuilder();
-  RectCornerRadii radii(ToSize(corners[NS_CORNER_TOP_LEFT]),
-                        ToSize(corners[NS_CORNER_TOP_RIGHT]),
-                        ToSize(corners[NS_CORNER_BOTTOM_RIGHT]),
-                        ToSize(corners[NS_CORNER_BOTTOM_LEFT]));
-  AppendRoundedRectToPath(mPathBuilder, ToRect(rect), radii, draw_clockwise);
+  AppendRoundedRectToPath(mPathBuilder, ToRect(rect), corners, draw_clockwise);
 }
 
 #ifdef MOZ_DUMP_PAINTING
 void
 gfxContext::WriteAsPNG(const char* aFile)
 {
   gfxUtils::WriteAsPNG(mDT, aFile);
 }
--- a/gfx/thebes/gfxContext.h
+++ b/gfx/thebes/gfxContext.h
@@ -17,16 +17,22 @@
 #include "nsAutoPtr.h"
 
 #include "mozilla/gfx/2D.h"
 
 typedef struct _cairo cairo_t;
 class GlyphBufferAzure;
 template <typename T> class FallibleTArray;
 
+namespace mozilla {
+namespace gfx {
+struct RectCornerRadii;
+}
+}
+
 /**
  * This is the main class for doing actual drawing. It is initialized using
  * a surface and can be drawn on. It manages various state information like
  * a current transformation matrix (CTM), a current path, current color,
  * etc.
  *
  * All drawing happens by creating a path and then stroking or filling it.
  * The functions like Rectangle and Arc do not do any drawing themselves.
@@ -36,16 +42,17 @@ template <typename T> class FallibleTArr
  * Note that the gfxContext takes coordinates in device pixels,
  * as opposed to app units.
  */
 class gfxContext MOZ_FINAL {
     typedef mozilla::gfx::FillRule FillRule;
     typedef mozilla::gfx::Path Path;
     typedef mozilla::gfx::Pattern Pattern;
     typedef mozilla::gfx::Rect Rect;
+    typedef mozilla::gfx::RectCornerRadii RectCornerRadii;
 
     NS_INLINE_DECL_REFCOUNTING(gfxContext)
 
 public:
 
     /**
      * Initialize this context from a DrawTarget.
      * Strips any transform from aTarget.
@@ -188,17 +195,17 @@ public:
      * Draw a rounded rectangle, with the given outer rect and
      * corners.  The corners specify the radii of the two axes of an
      * ellipse (the horizontal and vertical directions given by the
      * width and height, respectively).  By default the ellipse is
      * drawn in a clockwise direction; if draw_clockwise is false,
      * then it's drawn counterclockwise.
      */
     void RoundedRectangle(const gfxRect& rect,
-                          const gfxCornerSizes& corners,
+                          const RectCornerRadii& corners,
                           bool draw_clockwise = true);
 
     /**
      ** Transformation Matrix manipulation
      **/
 
     /**
      * Post-multiplies 'other' onto the current CTM, i.e. this
--- a/gfx/thebes/gfxRect.h
+++ b/gfx/thebes/gfxRect.h
@@ -134,59 +134,9 @@ struct gfxRect :
         NS_ASSERTION(k > 0.0, "Invalid (negative) scale factor");
         x /= k;
         y /= k;
         width /= k;
         height /= k;
     }
 };
 
-struct gfxCornerSizes {
-    gfxSize sizes[NS_NUM_CORNERS];
-
-    gfxCornerSizes () { }
-
-    explicit gfxCornerSizes (gfxFloat v) {
-        for (int i = 0; i < NS_NUM_CORNERS; i++)
-            sizes[i].SizeTo(v, v);
-    }
-
-    gfxCornerSizes (gfxFloat tl, gfxFloat tr, gfxFloat br, gfxFloat bl) {
-        sizes[NS_CORNER_TOP_LEFT].SizeTo(tl, tl);
-        sizes[NS_CORNER_TOP_RIGHT].SizeTo(tr, tr);
-        sizes[NS_CORNER_BOTTOM_RIGHT].SizeTo(br, br);
-        sizes[NS_CORNER_BOTTOM_LEFT].SizeTo(bl, bl);
-    }
-
-    gfxCornerSizes (const gfxSize& tl, const gfxSize& tr, const gfxSize& br, const gfxSize& bl) {
-        sizes[NS_CORNER_TOP_LEFT] = tl;
-        sizes[NS_CORNER_TOP_RIGHT] = tr;
-        sizes[NS_CORNER_BOTTOM_RIGHT] = br;
-        sizes[NS_CORNER_BOTTOM_LEFT] = bl;
-    }
-
-    const gfxSize& operator[] (mozilla::css::Corner index) const {
-        return sizes[index];
-    }
-
-    gfxSize& operator[] (mozilla::css::Corner index) {
-        return sizes[index];
-    }
-
-    void Scale(gfxFloat aXScale, gfxFloat aYScale)
-    {
-        for (int i = 0; i < NS_NUM_CORNERS; i++)
-            sizes[i].Scale(aXScale, aYScale);
-    }
-
-    const gfxSize TopLeft() const { return sizes[NS_CORNER_TOP_LEFT]; }
-    gfxSize& TopLeft() { return sizes[NS_CORNER_TOP_LEFT]; }
-
-    const gfxSize TopRight() const { return sizes[NS_CORNER_TOP_RIGHT]; }
-    gfxSize& TopRight() { return sizes[NS_CORNER_TOP_RIGHT]; }
-
-    const gfxSize BottomLeft() const { return sizes[NS_CORNER_BOTTOM_LEFT]; }
-    gfxSize& BottomLeft() { return sizes[NS_CORNER_BOTTOM_LEFT]; }
-
-    const gfxSize BottomRight() const { return sizes[NS_CORNER_BOTTOM_RIGHT]; }
-    gfxSize& BottomRight() { return sizes[NS_CORNER_BOTTOM_RIGHT]; }
-};
 #endif /* GFX_RECT_H */
--- a/layout/base/DisplayItemClip.cpp
+++ b/layout/base/DisplayItemClip.cpp
@@ -1,21 +1,24 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "DisplayItemClip.h"
 
 #include "gfxContext.h"
+#include "mozilla/gfx/PathHelpers.h"
 #include "nsPresContext.h"
 #include "nsCSSRendering.h"
 #include "nsLayoutUtils.h"
 #include "nsRegion.h"
 
+using namespace mozilla::gfx;
+
 namespace mozilla {
 
 void
 DisplayItemClip::SetTo(const nsRect& aRect)
 {
   mHaveClipRect = true;
   mClipRect = aRect;
   mRoundedClipRects.Clear();
@@ -81,72 +84,76 @@ DisplayItemClip::IntersectWith(const Dis
 
 void
 DisplayItemClip::ApplyTo(gfxContext* aContext,
                          nsPresContext* aPresContext,
                          uint32_t aBegin, uint32_t aEnd)
 {
   int32_t A2D = aPresContext->AppUnitsPerDevPixel();
   ApplyRectTo(aContext, A2D);
-  ApplyRoundedRectsTo(aContext, A2D, aBegin, aEnd);
+  ApplyRoundedRectClipsTo(aContext, A2D, aBegin, aEnd);
 }
 
 void
 DisplayItemClip::ApplyRectTo(gfxContext* aContext, int32_t A2D) const
 {
   aContext->NewPath();
   gfxRect clip = nsLayoutUtils::RectToGfxRect(mClipRect, A2D);
   aContext->Rectangle(clip, true);
   aContext->Clip();
 }
 
 void
-DisplayItemClip::ApplyRoundedRectsTo(gfxContext* aContext,
-                                     int32_t A2D,
-                                     uint32_t aBegin, uint32_t aEnd) const
+DisplayItemClip::ApplyRoundedRectClipsTo(gfxContext* aContext,
+                                         int32_t A2D,
+                                         uint32_t aBegin, uint32_t aEnd) const
 {
+  DrawTarget& aDrawTarget = *aContext->GetDrawTarget();
+
   aEnd = std::min<uint32_t>(aEnd, mRoundedClipRects.Length());
 
   for (uint32_t i = aBegin; i < aEnd; ++i) {
-    AddRoundedRectPathTo(aContext, A2D, mRoundedClipRects[i]);
-    aContext->Clip();
+    RefPtr<Path> roundedRect =
+      MakeRoundedRectPath(aDrawTarget, A2D, mRoundedClipRects[i]);
+    aContext->Clip(roundedRect);
   }
 }
 
 void
 DisplayItemClip::DrawRoundedRectsTo(gfxContext* aContext,
                                     int32_t A2D,
                                     uint32_t aBegin, uint32_t aEnd) const
 {
+  DrawTarget& aDrawTarget = *aContext->GetDrawTarget();
+
   aEnd = std::min<uint32_t>(aEnd, mRoundedClipRects.Length());
 
   if (aEnd - aBegin == 0)
     return;
 
   // If there is just one rounded rect we can just fill it, if there are more then we
   // must clip the rest to get the intersection of clips
-  ApplyRoundedRectsTo(aContext, A2D, aBegin, aEnd - 1);
-  AddRoundedRectPathTo(aContext, A2D, mRoundedClipRects[aEnd - 1]);
+  ApplyRoundedRectClipsTo(aContext, A2D, aBegin, aEnd - 1);
+  RefPtr<Path> roundedRect =
+    MakeRoundedRectPath(aDrawTarget, A2D, mRoundedClipRects[aEnd - 1]);
+  aContext->SetPath(roundedRect);
   aContext->Fill();
 }
 
-void
-DisplayItemClip::AddRoundedRectPathTo(gfxContext* aContext,
-                                      int32_t A2D,
-                                      const RoundedRect &aRoundRect) const
+TemporaryRef<Path>
+DisplayItemClip::MakeRoundedRectPath(DrawTarget& aDrawTarget,
+                                     int32_t A2D,
+                                     const RoundedRect &aRoundRect) const
 {
-  gfxCornerSizes pixelRadii;
+  RectCornerRadii pixelRadii;
   nsCSSRendering::ComputePixelRadii(aRoundRect.mRadii, A2D, &pixelRadii);
 
-  gfxRect clip = nsLayoutUtils::RectToGfxRect(aRoundRect.mRect, A2D);
-  clip.Round();
-  clip.Condition();
+  Rect rect = NSRectToSnappedRect(aRoundRect.mRect, A2D, aDrawTarget);
 
-  aContext->NewPath();
-  aContext->RoundedRectangle(clip, pixelRadii);
+  return MakePathForRoundedRect(aDrawTarget, rect, pixelRadii);
 }
 
 nsRect
 DisplayItemClip::ApproximateIntersectInward(const nsRect& aRect) const
 {
   nsRect r = aRect;
   if (mHaveClipRect) {
     r.IntersectRect(r, mClipRect);
@@ -280,17 +287,17 @@ DisplayItemClip::IsRectAffectedByClip(co
   unscaled.Scale(1/aXScale, 1/aYScale);
 
   for (uint32_t i = 0, iEnd = mRoundedClipRects.Length();
        i < iEnd; ++i) {
     const RoundedRect &rr = mRoundedClipRects[i];
 
     nsIntRect pixelRect = rr.mRect.ToNearestPixels(A2D);
 
-    gfxCornerSizes pixelRadii;
+    RectCornerRadii pixelRadii;
     nsCSSRendering::ComputePixelRadii(rr.mRadii, A2D, &pixelRadii);
 
     nsIntRegion rgn = nsLayoutUtils::RoundedRectIntersectIntRect(pixelRect, pixelRadii, unscaled);
     if (!rgn.Contains(unscaled)) {
       return true;
     }
   }
   return false;
--- a/layout/base/DisplayItemClip.h
+++ b/layout/base/DisplayItemClip.h
@@ -1,34 +1,45 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef DISPLAYITEMCLIP_H_
 #define DISPLAYITEMCLIP_H_
 
+#include "mozilla/RefPtr.h"
 #include "nsRect.h"
 #include "nsTArray.h"
 #include "nsStyleConsts.h"
 
 class gfxContext;
 class nsDisplayItem;
 class nsPresContext;
 class nsRegion;
 
 namespace mozilla {
+namespace gfx {
+class DrawTarget;
+class Path;
+}
+}
+
+namespace mozilla {
 
 /**
  * An DisplayItemClip represents the intersection of an optional rectangle
  * with a list of rounded rectangles (which is often empty), all in appunits.
  * It can represent everything CSS clipping can do to an element (except for
  * SVG clip-path), including no clipping at all.
  */
 class DisplayItemClip {
+  typedef mozilla::gfx::DrawTarget DrawTarget;
+  typedef mozilla::gfx::Path Path;
+
 public:
   struct RoundedRect {
     nsRect mRect;
     // Indices into mRadii are the NS_CORNER_* constants in nsStyleConsts.h
     nscoord mRadii[8];
 
     RoundedRect operator+(const nsPoint& aOffset) const {
       RoundedRect r = *this;
@@ -65,25 +76,26 @@ public:
   // See aBegin/aEnd note on ApplyRoundedRectsTo.
   void ApplyTo(gfxContext* aContext, nsPresContext* aPresContext,
                uint32_t aBegin = 0, uint32_t aEnd = UINT32_MAX);
 
   void ApplyRectTo(gfxContext* aContext, int32_t A2D) const;
   // Applies the rounded rects in this Clip to aContext
   // Will only apply rounded rects from aBegin (inclusive) to aEnd
   // (exclusive) or the number of rounded rects, whichever is smaller.
-  void ApplyRoundedRectsTo(gfxContext* aContext, int32_t A2DPRInt32,
-                           uint32_t aBegin, uint32_t aEnd) const;
+  void ApplyRoundedRectClipsTo(gfxContext* aContext, int32_t A2DPRInt32,
+                               uint32_t aBegin, uint32_t aEnd) const;
 
   // Draw (fill) the rounded rects in this clip to aContext
   void DrawRoundedRectsTo(gfxContext* aContext, int32_t A2D,
                           uint32_t aBegin, uint32_t aEnd) const;
   // 'Draw' (create as a path, does not stroke or fill) aRoundRect to aContext
-  void AddRoundedRectPathTo(gfxContext* aContext, int32_t A2D,
-                            const RoundedRect &aRoundRect) const;
+  mozilla::TemporaryRef<Path> MakeRoundedRectPath(DrawTarget& aDrawTarget,
+                                                  int32_t A2D,
+                                                  const RoundedRect &aRoundRect) const;
 
   // Returns true if the intersection of aRect and this clip region is
   // non-empty. This is precise for DisplayItemClips with at most one
   // rounded rectangle. When multiple rounded rectangles are present, we just
   // check that the rectangle intersects all of them (but possibly in different
   // places). So it may return true when the correct answer is false.
   bool MayIntersect(const nsRect& aRect) const;
 
--- a/layout/base/nsCSSRendering.cpp
+++ b/layout/base/nsCSSRendering.cpp
@@ -452,17 +452,17 @@ GetRadii(nsIFrame* aForFrame, const nsSt
   }
 
   return haveRoundedCorners;
 }
 
 static bool
 GetRadii(nsIFrame* aForFrame, const nsStyleBorder& aBorder,
          const nsRect& aOrigBorderArea, const nsRect& aBorderArea,
-         gfxCornerSizes* aBgRadii)
+         RectCornerRadii* aBgRadii)
 {
   nscoord radii[8];
   bool haveRoundedCorners = GetRadii(aForFrame, aBorder, aOrigBorderArea, aBorderArea, radii);
 
   if (haveRoundedCorners) {
     auto d2a = aForFrame->PresContext()->AppUnitsPerDevPixel();
     nsCSSRendering::ComputePixelRadii(radii, d2a, aBgRadii);
   }
@@ -557,35 +557,16 @@ BoxDecorationRectForBackground(nsIFrame*
 
 /*
  * Compute the float-pixel radii that should be used for drawing
  * this border/outline, given the various input bits.
  */
 /* static */ void
 nsCSSRendering::ComputePixelRadii(const nscoord *aAppUnitsRadii,
                                   nscoord aAppUnitsPerPixel,
-                                  gfxCornerSizes *oBorderRadii)
-{
-  gfxFloat radii[8];
-  NS_FOR_CSS_HALF_CORNERS(corner)
-    radii[corner] = gfxFloat(aAppUnitsRadii[corner]) / aAppUnitsPerPixel;
-
-  (*oBorderRadii)[C_TL] = gfxSize(radii[NS_CORNER_TOP_LEFT_X],
-                                  radii[NS_CORNER_TOP_LEFT_Y]);
-  (*oBorderRadii)[C_TR] = gfxSize(radii[NS_CORNER_TOP_RIGHT_X],
-                                  radii[NS_CORNER_TOP_RIGHT_Y]);
-  (*oBorderRadii)[C_BR] = gfxSize(radii[NS_CORNER_BOTTOM_RIGHT_X],
-                                  radii[NS_CORNER_BOTTOM_RIGHT_Y]);
-  (*oBorderRadii)[C_BL] = gfxSize(radii[NS_CORNER_BOTTOM_LEFT_X],
-                                  radii[NS_CORNER_BOTTOM_LEFT_Y]);
-}
-
-/* static */ void
-nsCSSRendering::ComputePixelRadii(const nscoord *aAppUnitsRadii,
-                                  nscoord aAppUnitsPerPixel,
                                   RectCornerRadii *oBorderRadii)
 {
   Float radii[8];
   NS_FOR_CSS_HALF_CORNERS(corner)
     radii[corner] = Float(aAppUnitsRadii[corner]) / aAppUnitsPerPixel;
 
   (*oBorderRadii)[C_TL] = Size(radii[NS_CORNER_TOP_LEFT_X],
                                radii[NS_CORNER_TOP_LEFT_Y]);
@@ -686,17 +667,17 @@ nsCSSRendering::PaintBorderWithStyleBord
     // Empty border area
     return;
   }
 
   // Compute the outermost boundary of the area that might be painted.
   // Same coordinate space as aBorderArea & aBGClipRect.
   nsRect joinedBorderArea =
     ::BoxDecorationRectForBorder(aForFrame, aBorderArea, aSkipSides, &aStyleBorder);
-  gfxCornerSizes bgRadii;
+  RectCornerRadii bgRadii;
   ::GetRadii(aForFrame, aStyleBorder, aBorderArea, joinedBorderArea, &bgRadii);
 
   PrintAsFormatString(" joinedBorderArea: %d %d %d %d\n", joinedBorderArea.x, joinedBorderArea.y,
      joinedBorderArea.width, joinedBorderArea.height);
 
   // start drawing
   gfxContext* ctx = aRenderingContext.ThebesContext();
   ctx->Save();
@@ -847,17 +828,17 @@ nsCSSRendering::PaintOutline(nsPresConte
   // Get our conversion values
   nscoord twipsPerPixel = aPresContext->DevPixelsToAppUnits(1);
 
   // get the outer rectangles
   gfxRect oRect(nsLayoutUtils::RectToGfxRect(outerRect, twipsPerPixel));
 
   // convert the radii
   nsMargin outlineMargin(width, width, width, width);
-  gfxCornerSizes outlineRadii;
+  RectCornerRadii outlineRadii;
   ComputePixelRadii(twipsRadii, twipsPerPixel, &outlineRadii);
 
   if (nsLayoutUtils::IsOutlineStyleAutoEnabled()) {
     if (outlineStyle == NS_STYLE_BORDER_STYLE_AUTO) {
       nsITheme* theme = aPresContext->GetTheme();
       if (theme && theme->ThemeSupportsWidget(aPresContext, aForFrame,
                                               NS_THEME_FOCUS_OUTLINE)) {
         theme->DrawWidgetBackground(&aRenderingContext, aForFrame,
@@ -918,17 +899,17 @@ nsCSSRendering::PaintFocus(nsPresContext
                            const nsRect& aFocusRect,
                            nscolor aColor)
 {
   nscoord oneCSSPixel = nsPresContext::CSSPixelsToAppUnits(1);
   nscoord oneDevPixel = aPresContext->DevPixelsToAppUnits(1);
 
   gfxRect focusRect(nsLayoutUtils::RectToGfxRect(aFocusRect, oneDevPixel));
 
-  gfxCornerSizes focusRadii;
+  RectCornerRadii focusRadii;
   {
     nscoord twipsRadii[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
     ComputePixelRadii(twipsRadii, oneDevPixel, &focusRadii);
   }
   gfxFloat focusWidths[4] = { gfxFloat(oneCSSPixel / oneDevPixel),
                               gfxFloat(oneCSSPixel / oneDevPixel),
                               gfxFloat(oneCSSPixel / oneDevPixel),
                               gfxFloat(oneCSSPixel / oneDevPixel) };
@@ -1407,17 +1388,17 @@ nsCSSRendering::PaintBoxShadowOuter(nsPr
           }
         }
       }
       renderContext->
         Clip(NSRectToSnappedRect(fragmentClip,
                                  aForFrame->PresContext()->AppUnitsPerDevPixel(),
                                  aDrawTarget));
 
-      gfxCornerSizes clipRectRadii;
+      RectCornerRadii clipRectRadii;
       if (hasBorderRadius) {
         Float spreadDistance = shadowItem->mSpread / twipsPerPixel;
 
         Float borderSizes[4];
 
         borderSizes[NS_SIDE_LEFT] = spreadDistance;
         borderSizes[NS_SIDE_TOP] = spreadDistance;
         borderSizes[NS_SIDE_RIGHT] = spreadDistance;
@@ -1473,26 +1454,26 @@ nsCSSRendering::PaintBoxShadowInner(nsPr
 
   // Get any border radius, since box-shadow must also have rounded corners
   // if the frame does.
   nscoord twipsRadii[8];
   nsSize sz = frameRect.Size();
   bool hasBorderRadius = aForFrame->GetBorderRadii(sz, sz, Sides(), twipsRadii);
   const nscoord twipsPerPixel = aPresContext->DevPixelsToAppUnits(1);
 
-  gfxCornerSizes innerRadii;
+  RectCornerRadii innerRadii;
   if (hasBorderRadius) {
-    gfxCornerSizes borderRadii;
+    RectCornerRadii borderRadii;
 
     ComputePixelRadii(twipsRadii, twipsPerPixel, &borderRadii);
-    gfxFloat borderSizes[4] = {
-      gfxFloat(border.top / twipsPerPixel),
-      gfxFloat(border.right / twipsPerPixel),
-      gfxFloat(border.bottom / twipsPerPixel),
-      gfxFloat(border.left / twipsPerPixel)
+    Float borderSizes[4] = {
+      Float(border.top / twipsPerPixel),
+      Float(border.right / twipsPerPixel),
+      Float(border.bottom / twipsPerPixel),
+      Float(border.left / twipsPerPixel)
     };
     nsCSSBorderRenderer::ComputeInnerRadii(borderRadii, borderSizes,
                                            &innerRadii);
   }
 
   for (uint32_t i = shadows->Length(); i > 0; --i) {
     nsCSSShadowItem* shadowItem = shadows->ShadowAt(i - 1);
     if (!shadowItem->mInset)
@@ -1506,21 +1487,21 @@ nsCSSRendering::PaintBoxShadowInner(nsPr
       nsContextBoxBlur::GetBlurRadiusMargin(blurRadius, twipsPerPixel);
     nsRect shadowPaintRect = paddingRect;
     shadowPaintRect.Inflate(blurMargin);
 
     nsRect shadowClipRect = paddingRect;
     shadowClipRect.MoveBy(shadowItem->mXOffset, shadowItem->mYOffset);
     shadowClipRect.Deflate(shadowItem->mSpread, shadowItem->mSpread);
 
-    gfxCornerSizes clipRectRadii;
+    RectCornerRadii clipRectRadii;
     if (hasBorderRadius) {
       // Calculate the radii the inner clipping rect will have
-      gfxFloat spreadDistance = shadowItem->mSpread / twipsPerPixel;
-      gfxFloat borderSizes[4] = {0, 0, 0, 0};
+      Float spreadDistance = shadowItem->mSpread / twipsPerPixel;
+      Float borderSizes[4] = {0, 0, 0, 0};
 
       // See PaintBoxShadowOuter and bug 514670
       if (innerRadii[C_TL].width > 0 || innerRadii[C_BL].width > 0) {
         borderSizes[NS_SIDE_LEFT] = spreadDistance;
       }
 
       if (innerRadii[C_TL].height > 0 || innerRadii[C_TR].height > 0) {
         borderSizes[NS_SIDE_TOP] = spreadDistance;
@@ -5341,39 +5322,40 @@ nsContextBoxBlur::GetBlurRadiusMargin(ns
   result.left = result.right = blurRadius.width  * aAppUnitsPerDevPixel;
   return result;
 }
 
 /* static */ void
 nsContextBoxBlur::BlurRectangle(gfxContext* aDestinationCtx,
                                 const nsRect& aRect,
                                 int32_t aAppUnitsPerDevPixel,
-                                gfxCornerSizes* aCornerRadii,
+                                RectCornerRadii* aCornerRadii,
                                 nscoord aBlurRadius,
                                 const gfxRGBA& aShadowColor,
                                 const nsRect& aDirtyRect,
                                 const gfxRect& aSkipRect)
 {
+  DrawTarget& aDestDrawTarget = *aDestinationCtx->GetDrawTarget();
+
   if (aRect.IsEmpty()) {
     return;
   }
 
-  gfxRect shadowGfxRect =
-    nsLayoutUtils::RectToGfxRect(aRect, aAppUnitsPerDevPixel);
+  Rect shadowGfxRect = NSRectToRect(aRect, aAppUnitsPerDevPixel);
 
   if (aBlurRadius <= 0) {
-    aDestinationCtx->SetColor(aShadowColor);
-    aDestinationCtx->NewPath();
+    ColorPattern color(ToDeviceColor(aShadowColor));
     if (aCornerRadii) {
-      aDestinationCtx->RoundedRectangle(shadowGfxRect, *aCornerRadii);
+      RefPtr<Path> roundedRect = MakePathForRoundedRect(aDestDrawTarget,
+                                                        shadowGfxRect,
+                                                        *aCornerRadii);
+      aDestDrawTarget.Fill(roundedRect, color);
     } else {
-      aDestinationCtx->Rectangle(shadowGfxRect);
+      aDestDrawTarget.FillRect(shadowGfxRect, color);
     }
-
-    aDestinationCtx->Fill();
     return;
   }
 
   gfxFloat scaleX = 1;
   gfxFloat scaleY = 1;
 
   // Do blurs in device space when possible.
   // Chrome/Skia always does the blurs in device space
@@ -5389,24 +5371,24 @@ nsContextBoxBlur::BlurRectangle(gfxConte
   }
 
   gfxPoint blurStdDev = ComputeBlurStdDev(aBlurRadius, aAppUnitsPerDevPixel, scaleX, scaleY);
 
   gfxRect dirtyRect =
     nsLayoutUtils::RectToGfxRect(aDirtyRect, aAppUnitsPerDevPixel);
   dirtyRect.RoundOut();
 
-  shadowGfxRect = transform.TransformBounds(shadowGfxRect);
+  gfxRect shadowThebesRect = transform.TransformBounds(ThebesRect(shadowGfxRect));
   dirtyRect = transform.TransformBounds(dirtyRect);
   gfxRect skipRect = transform.TransformBounds(aSkipRect);
 
   if (aCornerRadii) {
     aCornerRadii->Scale(scaleX, scaleY);
   }
 
   gfxAlphaBoxBlur::BlurRectangle(aDestinationCtx,
-                                 shadowGfxRect,
+                                 shadowThebesRect,
                                  aCornerRadii,
                                  blurStdDev,
                                  aShadowColor,
                                  dirtyRect,
                                  skipRect);
 }
--- a/layout/base/nsCSSRendering.h
+++ b/layout/base/nsCSSRendering.h
@@ -5,31 +5,31 @@
 
 /* utility functions for drawing borders and backgrounds */
 
 #ifndef nsCSSRendering_h___
 #define nsCSSRendering_h___
 
 #include "gfxBlur.h"
 #include "gfxContext.h"
+#include "mozilla/gfx/PathHelpers.h"
 #include "mozilla/gfx/Rect.h"
 #include "nsLayoutUtils.h"
 #include "nsStyleStruct.h"
 #include "nsIFrame.h"
 
 class gfxDrawable;
 class nsStyleContext;
 class nsPresContext;
 class nsRenderingContext;
 
 namespace mozilla {
 
 namespace gfx {
 class DrawTarget;
-struct RectCornerRadii;
 }
 
 namespace layers {
 class ImageContainer;
 }
 
 // A CSSSizeOrRatio represents a (possibly partially specified) size for use
 // in computing image sizes. Either or both of the width and height might be
@@ -345,20 +345,16 @@ struct nsCSSRendering {
                                   const nsRect& aFrameArea,
                                   const nsRect& aDirtyRect,
                                   float aOpacity = 1.0);
 
   static void ComputePixelRadii(const nscoord *aAppUnitsRadii,
                                 nscoord aAppUnitsPerPixel,
                                 RectCornerRadii *oBorderRadii);
 
-  static void ComputePixelRadii(const nscoord *aAppUnitsRadii,
-                                nscoord aAppUnitsPerPixel,
-                                gfxCornerSizes *oBorderRadii);
-
   /**
    * Render the border for an element using css rendering rules
    * for borders. aSkipSides says which sides to skip
    * when rendering, the default is to skip none.
    */
   static void PaintBorder(nsPresContext* aPresContext,
                           nsRenderingContext& aRenderingContext,
                           nsIFrame* aForFrame,
@@ -517,17 +513,17 @@ struct nsCSSRendering {
 
   struct BackgroundClipState {
     nsRect mBGClipArea;  // Affected by mClippedRadii
     nsRect mAdditionalBGClipArea;  // Not affected by mClippedRadii
     nsRect mDirtyRect;
     gfxRect mDirtyRectGfx;
 
     nscoord mRadii[8];
-    gfxCornerSizes mClippedRadii;
+    RectCornerRadii mClippedRadii;
     bool mHasRoundedCorners;
     bool mHasAdditionalBGClipArea;
 
     // Whether we are being asked to draw with a caller provided background
     // clipping area. If this is true we also disable rounded corners.
     bool mCustomClip;
   };
 
@@ -830,16 +826,18 @@ protected:
  * You must call Init() first to create a suitable temporary surface to draw
  * on.  You must then draw any desired content onto the given context, then
  * call DoPaint() to apply the blurred content as a single-color mask. You
  * can only call Init() once, so objects cannot be reused.
  *
  * This is very useful for creating drop shadows or silhouettes.
  */
 class nsContextBoxBlur {
+  typedef mozilla::gfx::RectCornerRadii RectCornerRadii;
+
 public:
   enum {
     FORCE_MASK = 0x01
   };
   /**
    * Prepares a gfxContext to draw on. Do not call this twice; if you want
    * to get the gfxContext again use GetContext().
    *
@@ -935,17 +933,17 @@ public:
    * @param aDirtyRect           The absolute dirty rect in app units. Used to
    *                             optimize the temporary surface size and speed up blur.
    * @param aSkipRect            An area in device pixels (NOT app units!) to avoid
    *                             blurring over, to prevent unnecessary work.
    */
   static void BlurRectangle(gfxContext* aDestinationCtx,
                             const nsRect& aRect,
                             int32_t aAppUnitsPerDevPixel,
-                            gfxCornerSizes* aCornerRadii,
+                            RectCornerRadii* aCornerRadii,
                             nscoord aBlurRadius,
                             const gfxRGBA& aShadowColor,
                             const nsRect& aDirtyRect,
                             const gfxRect& aSkipRect);
 
 protected:
   gfxAlphaBoxBlur mAlphaBoxBlur;
   nsRefPtr<gfxContext> mContext;
--- a/layout/base/nsCSSRenderingBorders.cpp
+++ b/layout/base/nsCSSRenderingBorders.cpp
@@ -44,20 +44,20 @@ using namespace mozilla::gfx;
  *         |- for each side adjacent to corner
  *            |- clip to DoSideClipSubPath
  *            |- DrawBorderSides with one side
  *      |- for each side
  *         |- DoSideClipWithoutCornersSubPath
  *         |- DrawDashedSide || DrawBorderSides with one side
  */
 
-static void ComputeBorderCornerDimensions(const gfxRect& aOuterRect,
-                                          const gfxRect& aInnerRect,
-                                          const gfxCornerSizes& aRadii,
-                                          gfxCornerSizes *aDimsResult);
+static void ComputeBorderCornerDimensions(const Rect& aOuterRect,
+                                          const Rect& aInnerRect,
+                                          const RectCornerRadii& aRadii,
+                                          RectCornerRadii *aDimsResult);
 
 // given a side index, get the previous and next side index
 #define NEXT_SIDE(_s) mozilla::css::Side(((_s) + 1) & 3)
 #define PREV_SIDE(_s) mozilla::css::Side(((_s) + 3) & 3)
 
 // from the given base color and the background color, turn
 // color into a color for the given border pattern style
 static gfxRGBA MakeBorderColor(const gfxRGBA& aColor,
@@ -84,22 +84,31 @@ CheckFourFloatsEqual(const gfxFloat *val
 {
   return (vals[0] == k &&
           vals[1] == k &&
           vals[2] == k &&
           vals[3] == k);
 }
 
 static bool
-IsZeroSize(const gfxSize& sz) {
+CheckFourFloatsEqual(const Float *vals, Float k)
+{
+  return (vals[0] == k &&
+          vals[1] == k &&
+          vals[2] == k &&
+          vals[3] == k);
+}
+
+static bool
+IsZeroSize(const Size& sz) {
   return sz.width == 0.0 || sz.height == 0.0;
 }
 
 static bool
-AllCornersZeroSize(const gfxCornerSizes& corners) {
+AllCornersZeroSize(const RectCornerRadii& corners) {
   return IsZeroSize(corners[NS_CORNER_TOP_LEFT]) &&
     IsZeroSize(corners[NS_CORNER_TOP_RIGHT]) &&
     IsZeroSize(corners[NS_CORNER_BOTTOM_RIGHT]) &&
     IsZeroSize(corners[NS_CORNER_BOTTOM_LEFT]);
 }
 
 typedef enum {
   // Normal solid square corner.  Will be rectangular, the size of the
@@ -116,17 +125,17 @@ typedef enum {
   CORNER_DOT
 } CornerStyle;
 
 nsCSSBorderRenderer::nsCSSBorderRenderer(int32_t aAppUnitsPerPixel,
                                          gfxContext* aDestContext,
                                          gfxRect& aOuterRect,
                                          const uint8_t* aBorderStyles,
                                          const gfxFloat* aBorderWidths,
-                                         gfxCornerSizes& aBorderRadii,
+                                         RectCornerRadii& aBorderRadii,
                                          const nscolor* aBorderColors,
                                          nsBorderColors* const* aCompositeColors,
                                          nscolor aBackgroundColor)
   : mContext(aDestContext),
     mOuterRect(aOuterRect),
     mBorderStyles(aBorderStyles),
     mBorderWidths(aBorderWidths),
     mBorderRadii(aBorderRadii),
@@ -142,52 +151,53 @@ nsCSSBorderRenderer::nsCSSBorderRenderer
 
   mInnerRect = mOuterRect;
   mInnerRect.Deflate(
       gfxMargin(mBorderStyles[0] != NS_STYLE_BORDER_STYLE_NONE ? mBorderWidths[0] : 0,
                 mBorderStyles[1] != NS_STYLE_BORDER_STYLE_NONE ? mBorderWidths[1] : 0,
                 mBorderStyles[2] != NS_STYLE_BORDER_STYLE_NONE ? mBorderWidths[2] : 0,
                 mBorderStyles[3] != NS_STYLE_BORDER_STYLE_NONE ? mBorderWidths[3] : 0));
 
-  ComputeBorderCornerDimensions(mOuterRect, mInnerRect, mBorderRadii, &mBorderCornerDimensions);
+  ComputeBorderCornerDimensions(ToRect(mOuterRect), ToRect(mInnerRect),
+                                mBorderRadii, &mBorderCornerDimensions);
 
   mOneUnitBorder = CheckFourFloatsEqual(mBorderWidths, 1.0);
   mNoBorderRadius = AllCornersZeroSize(mBorderRadii);
   mAvoidStroke = false;
 }
 
 /* static */ void
-nsCSSBorderRenderer::ComputeInnerRadii(const gfxCornerSizes& aRadii,
-                                       const gfxFloat *aBorderSizes,
-                                       gfxCornerSizes *aInnerRadiiRet)
+nsCSSBorderRenderer::ComputeInnerRadii(const RectCornerRadii& aRadii,
+                                       const Float* aBorderSizes,
+                                       RectCornerRadii* aInnerRadiiRet)
 {
-  gfxCornerSizes& iRadii = *aInnerRadiiRet;
+  RectCornerRadii& iRadii = *aInnerRadiiRet;
 
-  iRadii[C_TL].width = std::max(0.0, aRadii[C_TL].width - aBorderSizes[NS_SIDE_LEFT]);
-  iRadii[C_TL].height = std::max(0.0, aRadii[C_TL].height - aBorderSizes[NS_SIDE_TOP]);
+  iRadii[C_TL].width = std::max(0.f, aRadii[C_TL].width - aBorderSizes[NS_SIDE_LEFT]);
+  iRadii[C_TL].height = std::max(0.f, aRadii[C_TL].height - aBorderSizes[NS_SIDE_TOP]);
 
-  iRadii[C_TR].width = std::max(0.0, aRadii[C_TR].width - aBorderSizes[NS_SIDE_RIGHT]);
-  iRadii[C_TR].height = std::max(0.0, aRadii[C_TR].height - aBorderSizes[NS_SIDE_TOP]);
+  iRadii[C_TR].width = std::max(0.f, aRadii[C_TR].width - aBorderSizes[NS_SIDE_RIGHT]);
+  iRadii[C_TR].height = std::max(0.f, aRadii[C_TR].height - aBorderSizes[NS_SIDE_TOP]);
 
-  iRadii[C_BR].width = std::max(0.0, aRadii[C_BR].width - aBorderSizes[NS_SIDE_RIGHT]);
-  iRadii[C_BR].height = std::max(0.0, aRadii[C_BR].height - aBorderSizes[NS_SIDE_BOTTOM]);
+  iRadii[C_BR].width = std::max(0.f, aRadii[C_BR].width - aBorderSizes[NS_SIDE_RIGHT]);
+  iRadii[C_BR].height = std::max(0.f, aRadii[C_BR].height - aBorderSizes[NS_SIDE_BOTTOM]);
 
-  iRadii[C_BL].width = std::max(0.0, aRadii[C_BL].width - aBorderSizes[NS_SIDE_LEFT]);
-  iRadii[C_BL].height = std::max(0.0, aRadii[C_BL].height - aBorderSizes[NS_SIDE_BOTTOM]);
+  iRadii[C_BL].width = std::max(0.f, aRadii[C_BL].width - aBorderSizes[NS_SIDE_LEFT]);
+  iRadii[C_BL].height = std::max(0.f, aRadii[C_BL].height - aBorderSizes[NS_SIDE_BOTTOM]);
 }
 
 /* static */ void
 nsCSSBorderRenderer::ComputeOuterRadii(const RectCornerRadii& aRadii,
-                                       const Float *aBorderSizes,
-                                       gfxCornerSizes *aOuterRadiiRet)
+                                       const Float* aBorderSizes,
+                                       RectCornerRadii* aOuterRadiiRet)
 {
-  gfxCornerSizes& oRadii = *aOuterRadiiRet;
+  RectCornerRadii& oRadii = *aOuterRadiiRet;
 
   // default all corners to sharp corners
-  oRadii = gfxCornerSizes(0.0);
+  oRadii = RectCornerRadii(0.f);
 
   // round the edges that have radii > 0.0 to start with
   if (aRadii[C_TL].width > 0.f && aRadii[C_TL].height > 0.f) {
     oRadii[C_TL].width = std::max(0.f, aRadii[C_TL].width + aBorderSizes[NS_SIDE_LEFT]);
     oRadii[C_TL].height = std::max(0.f, aRadii[C_TL].height + aBorderSizes[NS_SIDE_TOP]);
   }
 
   if (aRadii[C_TR].width > 0.f && aRadii[C_TR].height > 0.f) {
@@ -202,44 +212,44 @@ nsCSSBorderRenderer::ComputeOuterRadii(c
 
   if (aRadii[C_BL].width > 0.f && aRadii[C_BL].height > 0.f) {
     oRadii[C_BL].width = std::max(0.f, aRadii[C_BL].width + aBorderSizes[NS_SIDE_LEFT]);
     oRadii[C_BL].height = std::max(0.f, aRadii[C_BL].height + aBorderSizes[NS_SIDE_BOTTOM]);
   }
 }
 
 /*static*/ void
-ComputeBorderCornerDimensions(const gfxRect& aOuterRect,
-                              const gfxRect& aInnerRect,
-                              const gfxCornerSizes& aRadii,
-                              gfxCornerSizes *aDimsRet)
+ComputeBorderCornerDimensions(const Rect& aOuterRect,
+                              const Rect& aInnerRect,
+                              const RectCornerRadii& aRadii,
+                              RectCornerRadii* aDimsRet)
 {
-  gfxFloat leftWidth = aInnerRect.X() - aOuterRect.X();
-  gfxFloat topWidth = aInnerRect.Y() - aOuterRect.Y();
-  gfxFloat rightWidth = aOuterRect.Width() - aInnerRect.Width() - leftWidth;
-  gfxFloat bottomWidth = aOuterRect.Height() - aInnerRect.Height() - topWidth;
+  Float leftWidth = aInnerRect.X() - aOuterRect.X();
+  Float topWidth = aInnerRect.Y() - aOuterRect.Y();
+  Float rightWidth = aOuterRect.Width() - aInnerRect.Width() - leftWidth;
+  Float bottomWidth = aOuterRect.Height() - aInnerRect.Height() - topWidth;
 
   if (AllCornersZeroSize(aRadii)) {
     // These will always be in pixel units from CSS
-    (*aDimsRet)[C_TL] = gfxSize(leftWidth, topWidth);
-    (*aDimsRet)[C_TR] = gfxSize(rightWidth, topWidth);
-    (*aDimsRet)[C_BR] = gfxSize(rightWidth, bottomWidth);
-    (*aDimsRet)[C_BL] = gfxSize(leftWidth, bottomWidth);
+    (*aDimsRet)[C_TL] = Size(leftWidth, topWidth);
+    (*aDimsRet)[C_TR] = Size(rightWidth, topWidth);
+    (*aDimsRet)[C_BR] = Size(rightWidth, bottomWidth);
+    (*aDimsRet)[C_BL] = Size(leftWidth, bottomWidth);
   } else {
     // Always round up to whole pixels for the corners; it's safe to
     // make the corners bigger than necessary, and this way we ensure
     // that we avoid seams.
-    (*aDimsRet)[C_TL] = gfxSize(ceil(std::max(leftWidth, aRadii[C_TL].width)),
-                                ceil(std::max(topWidth, aRadii[C_TL].height)));
-    (*aDimsRet)[C_TR] = gfxSize(ceil(std::max(rightWidth, aRadii[C_TR].width)),
-                                ceil(std::max(topWidth, aRadii[C_TR].height)));
-    (*aDimsRet)[C_BR] = gfxSize(ceil(std::max(rightWidth, aRadii[C_BR].width)),
-                                ceil(std::max(bottomWidth, aRadii[C_BR].height)));
-    (*aDimsRet)[C_BL] = gfxSize(ceil(std::max(leftWidth, aRadii[C_BL].width)),
-                                ceil(std::max(bottomWidth, aRadii[C_BL].height)));
+    (*aDimsRet)[C_TL] = Size(ceil(std::max(leftWidth, aRadii[C_TL].width)),
+                             ceil(std::max(topWidth, aRadii[C_TL].height)));
+    (*aDimsRet)[C_TR] = Size(ceil(std::max(rightWidth, aRadii[C_TR].width)),
+                             ceil(std::max(topWidth, aRadii[C_TR].height)));
+    (*aDimsRet)[C_BR] = Size(ceil(std::max(rightWidth, aRadii[C_BR].width)),
+                             ceil(std::max(bottomWidth, aRadii[C_BR].height)));
+    (*aDimsRet)[C_BL] = Size(ceil(std::max(leftWidth, aRadii[C_BL].width)),
+                             ceil(std::max(bottomWidth, aRadii[C_BL].height)));
   }
 }
 
 bool
 nsCSSBorderRenderer::AreBorderSideFinalStylesSame(uint8_t aSides)
 {
   NS_ASSERTION(aSides != 0 && (aSides & ~SIDE_BITS_ALL) == 0,
                "AreBorderSidesSame: invalid whichSides!");
@@ -341,17 +351,17 @@ nsCSSBorderRenderer::DoCornerSubPath(moz
   gfxPoint offset(0.0, 0.0);
 
   if (aCorner == C_TR || aCorner == C_BR)
     offset.x = mOuterRect.Width() - mBorderCornerDimensions[aCorner].width;
   if (aCorner == C_BR || aCorner == C_BL)
     offset.y = mOuterRect.Height() - mBorderCornerDimensions[aCorner].height;
 
   mContext->Rectangle(gfxRect(mOuterRect.TopLeft() + offset,
-                              mBorderCornerDimensions[aCorner]));
+                              ThebesSize(mBorderCornerDimensions[aCorner])));
 }
 
 void
 nsCSSBorderRenderer::DoSideClipWithoutCornersSubPath(mozilla::css::Side aSide)
 {
   gfxPoint offset(0.0, 0.0);
 
   // The offset from the outside rect to the start of this side's
@@ -370,20 +380,20 @@ nsCSSBorderRenderer::DoSideClipWithoutCo
   } else if (aSide == NS_SIDE_LEFT) {
     offset.y = mBorderCornerDimensions[C_TL].height;
   }
 
   // The sum of the width & height of the corners adjacent to the
   // side.  This relies on the relationship between side indexing and
   // corner indexing; that is, 0 == SIDE_TOP and 0 == CORNER_TOP_LEFT,
   // with both proceeding clockwise.
-  gfxSize sideCornerSum = mBorderCornerDimensions[mozilla::css::Corner(aSide)]
-                        + mBorderCornerDimensions[mozilla::css::Corner(NEXT_SIDE(aSide))];
+  Size sideCornerSum = mBorderCornerDimensions[mozilla::css::Corner(aSide)]
+                     + mBorderCornerDimensions[mozilla::css::Corner(NEXT_SIDE(aSide))];
   gfxRect rect(mOuterRect.TopLeft() + offset,
-               mOuterRect.Size() - sideCornerSum);
+               mOuterRect.Size() - ThebesSize(sideCornerSum));
 
   if (aSide == NS_SIDE_TOP || aSide == NS_SIDE_BOTTOM)
     rect.height = mBorderWidths[aSide];
   else
     rect.width = mBorderWidths[aSide];
 
   mContext->Rectangle(rect);
 }
@@ -508,29 +518,29 @@ nsCSSBorderRenderer::DoSideClipSubPath(m
   mContext->LineTo(end[1]);
   mContext->LineTo(start[1]);
   mContext->ClosePath();
 }
 
 void
 nsCSSBorderRenderer::FillSolidBorder(const gfxRect& aOuterRect,
                                      const gfxRect& aInnerRect,
-                                     const gfxCornerSizes& aBorderRadii,
-                                     const gfxFloat *aBorderSizes,
+                                     const RectCornerRadii& aBorderRadii,
+                                     const Float* aBorderSizes,
                                      int aSides,
                                      const gfxRGBA& aColor)
 {
   mContext->SetColor(aColor);
   // Note that this function is allowed to draw more than just the
   // requested sides.
 
   // If we have a border radius, do full rounded rectangles
   // and fill, regardless of what sides we're asked to draw.
   if (!AllCornersZeroSize(aBorderRadii)) {
-    gfxCornerSizes innerRadii;
+    RectCornerRadii innerRadii;
     ComputeInnerRadii(aBorderRadii, aBorderSizes, &innerRadii);
 
     mContext->NewPath();
 
     // do the outer border
     mContext->RoundedRectangle(aOuterRect, aBorderRadii, true);
 
     // then do the inner border CCW
@@ -560,41 +570,41 @@ nsCSSBorderRenderer::FillSolidBorder(con
 
     return;
   }
 
   // Otherwise, we have unequal sized borders or we're only
   // drawing some sides; create rectangles for each side
   // and fill them.
 
-  gfxRect r[4];
+  Rect r[4];
 
   // compute base rects for each side
   if (aSides & SIDE_BIT_TOP) {
     r[NS_SIDE_TOP] =
-        gfxRect(aOuterRect.X(), aOuterRect.Y(),
-                aOuterRect.Width(), aBorderSizes[NS_SIDE_TOP]);
+        Rect(aOuterRect.X(), aOuterRect.Y(),
+             aOuterRect.Width(), aBorderSizes[NS_SIDE_TOP]);
   }
 
   if (aSides & SIDE_BIT_BOTTOM) {
     r[NS_SIDE_BOTTOM] =
-        gfxRect(aOuterRect.X(), aOuterRect.YMost() - aBorderSizes[NS_SIDE_BOTTOM],
-                aOuterRect.Width(), aBorderSizes[NS_SIDE_BOTTOM]);
+        Rect(aOuterRect.X(), aOuterRect.YMost() - aBorderSizes[NS_SIDE_BOTTOM],
+             aOuterRect.Width(), aBorderSizes[NS_SIDE_BOTTOM]);
   }
 
   if (aSides & SIDE_BIT_LEFT) {
     r[NS_SIDE_LEFT] =
-        gfxRect(aOuterRect.X(), aOuterRect.Y(),
-                aBorderSizes[NS_SIDE_LEFT], aOuterRect.Height());
+        Rect(aOuterRect.X(), aOuterRect.Y(),
+             aBorderSizes[NS_SIDE_LEFT], aOuterRect.Height());
   }
 
   if (aSides & SIDE_BIT_RIGHT) {
     r[NS_SIDE_RIGHT] =
-        gfxRect(aOuterRect.XMost() - aBorderSizes[NS_SIDE_RIGHT], aOuterRect.Y(),
-                aBorderSizes[NS_SIDE_RIGHT], aOuterRect.Height());
+        Rect(aOuterRect.XMost() - aBorderSizes[NS_SIDE_RIGHT], aOuterRect.Y(),
+             aBorderSizes[NS_SIDE_RIGHT], aOuterRect.Height());
   }
 
   // If two sides meet at a corner that we're rendering, then
   // make sure that we adjust one of the sides to avoid overlap.
   // This is especially important in the case of colors with
   // an alpha channel.
 
   if ((aSides & (SIDE_BIT_TOP | SIDE_BIT_LEFT)) == (SIDE_BIT_TOP | SIDE_BIT_LEFT)) {
@@ -618,17 +628,17 @@ nsCSSBorderRenderer::FillSolidBorder(con
     r[NS_SIDE_BOTTOM].x += aBorderSizes[NS_SIDE_LEFT];
     r[NS_SIDE_BOTTOM].width -= aBorderSizes[NS_SIDE_LEFT];
   }
 
   // Filling these one by one is faster than filling them all at once.
   for (uint32_t i = 0; i < 4; i++) {
     if (aSides & (1 << i)) {
       mContext->NewPath();
-      mContext->Rectangle(r[i], true);
+      mContext->Rectangle(ThebesRect(r[i]), true);
       mContext->Fill();
     }
   }
 }
 
 gfxRGBA
 MakeBorderColor(const gfxRGBA& aColor, const gfxRGBA& aBackgroundColor, BorderColorStyle aBorderColorStyle)
 {
@@ -672,54 +682,54 @@ ComputeCompositeColorForLine(uint32_t aL
     aBorderColors = aBorderColors->mNext;
 
   return gfxRGBA(aBorderColors->mColor);
 }
 
 void
 nsCSSBorderRenderer::DrawBorderSidesCompositeColors(int aSides, const nsBorderColors *aCompositeColors)
 {
-  gfxCornerSizes radii = mBorderRadii;
+  RectCornerRadii radii = mBorderRadii;
 
   // the generic composite colors path; each border is 1px in size
-  gfxRect soRect = mOuterRect;
-  gfxFloat maxBorderWidth = 0;
+  Rect soRect = ToRect(mOuterRect);
+  Float maxBorderWidth = 0;
   NS_FOR_CSS_SIDES (i) {
-    maxBorderWidth = std::max(maxBorderWidth, mBorderWidths[i]);
+    maxBorderWidth = std::max(maxBorderWidth, Float(mBorderWidths[i]));
   }
 
-  gfxFloat fakeBorderSizes[4];
+  Float fakeBorderSizes[4];
 
-  gfxPoint itl = mInnerRect.TopLeft();
-  gfxPoint ibr = mInnerRect.BottomRight();
+  Point itl = ToPoint(mInnerRect.TopLeft());
+  Point ibr = ToPoint(mInnerRect.BottomRight());
 
   for (uint32_t i = 0; i < uint32_t(maxBorderWidth); i++) {
     gfxRGBA lineColor = ComputeCompositeColorForLine(i, aCompositeColors);
 
-    gfxRect siRect = soRect;
+    Rect siRect = soRect;
     siRect.Deflate(1.0);
 
     // now cap the rects to the real mInnerRect
-    gfxPoint tl = siRect.TopLeft();
-    gfxPoint br = siRect.BottomRight();
+    Point tl = siRect.TopLeft();
+    Point br = siRect.BottomRight();
 
     tl.x = std::min(tl.x, itl.x);
     tl.y = std::min(tl.y, itl.y);
 
     br.x = std::max(br.x, ibr.x);
     br.y = std::max(br.y, ibr.y);
 
-    siRect = gfxRect(tl.x, tl.y, br.x - tl.x , br.y - tl.y);
+    siRect = Rect(tl.x, tl.y, br.x - tl.x , br.y - tl.y);
 
     fakeBorderSizes[NS_SIDE_TOP] = siRect.TopLeft().y - soRect.TopLeft().y;
     fakeBorderSizes[NS_SIDE_RIGHT] = soRect.TopRight().x - siRect.TopRight().x;
     fakeBorderSizes[NS_SIDE_BOTTOM] = soRect.BottomRight().y - siRect.BottomRight().y;
     fakeBorderSizes[NS_SIDE_LEFT] = siRect.BottomLeft().x - soRect.BottomLeft().x;
 
-    FillSolidBorder(soRect, siRect, radii, fakeBorderSizes, aSides, lineColor);
+    FillSolidBorder(ThebesRect(soRect), ThebesRect(siRect), radii, fakeBorderSizes, aSides, lineColor);
 
     soRect = siRect;
 
     ComputeInnerRadii(radii, fakeBorderSizes, &radii);
   }
 }
 
 void
@@ -845,67 +855,67 @@ nsCSSBorderRenderer::DrawBorderSides(int
   // of TL/BR if the border style would require a
   // TL/BR split.
   if (aSides & (SIDE_BIT_BOTTOM | SIDE_BIT_RIGHT))
     borderColorStyle = borderColorStyleBottomRight;
   else
     borderColorStyle = borderColorStyleTopLeft;
 
   // Distribute the border across the available space.
-  gfxFloat borderWidths[3][4];
+  Float borderWidths[3][4];
 
   if (borderColorStyleCount == 1) {
     NS_FOR_CSS_SIDES (i) {
       borderWidths[0][i] = mBorderWidths[i];
     }
   } else if (borderColorStyleCount == 2) {
     // with 2 color styles, any extra pixel goes to the outside
     NS_FOR_CSS_SIDES (i) {
       borderWidths[0][i] = int32_t(mBorderWidths[i]) / 2 + int32_t(mBorderWidths[i]) % 2;
       borderWidths[1][i] = int32_t(mBorderWidths[i]) / 2;
     }
   } else if (borderColorStyleCount == 3) {
     // with 3 color styles, any extra pixel (or lack of extra pixel)
     // goes to the middle
     NS_FOR_CSS_SIDES (i) {
       if (mBorderWidths[i] == 1.0) {
-        borderWidths[0][i] = 1.0;
-        borderWidths[1][i] = borderWidths[2][i] = 0.0;
+        borderWidths[0][i] = 1.f;
+        borderWidths[1][i] = borderWidths[2][i] = 0.f;
       } else {
         int32_t rest = int32_t(mBorderWidths[i]) % 3;
         borderWidths[0][i] = borderWidths[2][i] = borderWidths[1][i] = (int32_t(mBorderWidths[i]) - rest) / 3;
 
         if (rest == 1) {
-          borderWidths[1][i] += 1.0;
+          borderWidths[1][i] += 1.f;
         } else if (rest == 2) {
-          borderWidths[0][i] += 1.0;
-          borderWidths[2][i] += 1.0;
+          borderWidths[0][i] += 1.f;
+          borderWidths[2][i] += 1.f;
         }
       }
     }
   }
 
   // make a copy that we can modify
-  gfxCornerSizes radii = mBorderRadii;
+  RectCornerRadii radii = mBorderRadii;
 
-  gfxRect soRect(mOuterRect);
-  gfxRect siRect(mOuterRect);
+  Rect soRect(ToRect(mOuterRect));
+  Rect siRect(ToRect(mOuterRect));
 
   for (unsigned int i = 0; i < borderColorStyleCount; i++) {
     // walk siRect inwards at the start of the loop to get the
     // correct inner rect.
-    siRect.Deflate(gfxMargin(borderWidths[i][0], borderWidths[i][1],
-                             borderWidths[i][2], borderWidths[i][3]));
+    siRect.Deflate(Margin(borderWidths[i][0], borderWidths[i][1],
+                          borderWidths[i][2], borderWidths[i][3]));
 
     if (borderColorStyle[i] != BorderColorStyleNone) {
       gfxRGBA color = ComputeColorForLine(i,
                                           borderColorStyle, borderColorStyleCount,
                                           borderRenderColor, mBackgroundColor);
 
-      FillSolidBorder(soRect, siRect, radii, borderWidths[i], aSides, color);
+      FillSolidBorder(ThebesRect(soRect), ThebesRect(siRect), radii, borderWidths[i], aSides, color);
     }
 
     ComputeInnerRadii(radii, borderWidths[i], &radii);
 
     // And now soRect is the same as siRect, for the next line in.
     soRect = siRect;
   }
 }
@@ -1152,18 +1162,21 @@ nsCSSBorderRenderer::DrawNoCompositeColo
 
   const twoFloats centerAdjusts[4] = { { 0, +0.5 },
                                        { -0.5, 0 },
                                        { 0, -0.5 },
                                        { +0.5, 0 } };
 
   Point pc, pci, p0, p1, p2, p3, pd, p3i;
 
-  gfxCornerSizes innerRadii;
-  ComputeInnerRadii(mBorderRadii, mBorderWidths, &innerRadii);
+  Float borderWidths[4] = { Float(mBorderWidths[0]), Float(mBorderWidths[1]),
+                            Float(mBorderWidths[2]), Float(mBorderWidths[3]) };
+
+  RectCornerRadii innerRadii;
+  ComputeInnerRadii(mBorderRadii, borderWidths, &innerRadii);
 
   gfxRect strokeRect = mOuterRect;
   strokeRect.Deflate(gfxMargin(mBorderWidths[0] / 2.0, mBorderWidths[1] / 2.0,
                                mBorderWidths[2] / 2.0, mBorderWidths[3] / 2.0));
 
   ColorPattern colorPat(Color(0, 0, 0, 0));
   LinearGradientPattern gradPat(Point(), Point(), nullptr);
 
--- a/layout/base/nsCSSRenderingBorders.h
+++ b/layout/base/nsCSSRenderingBorders.h
@@ -4,29 +4,29 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef NS_CSS_RENDERING_BORDERS_H
 #define NS_CSS_RENDERING_BORDERS_H
 
 #include "gfxRect.h"
 #include "mozilla/gfx/2D.h"
+#include "mozilla/gfx/PathHelpers.h"
 #include "mozilla/RefPtr.h"
 #include "nsColor.h"
 #include "nsCOMPtr.h"
 #include "nsStyleConsts.h"
 
 class gfxContext;
 struct gfxRGBA;
 struct nsBorderColors;
 
 namespace mozilla {
 namespace gfx {
 class GradientStops;
-struct RectCornerRadii;
 }
 }
 
 // define this to enable a bunch of debug dump info
 #undef DEBUG_NEW_BORDERS
 
 //thickness of dashed line relative to dotted line
 #define DOT_LENGTH  1           //square
@@ -51,17 +51,17 @@ struct RectCornerRadii;
  * destContext -- the gfxContext to which the border should be rendered
  * outsideRect -- the rectangle on the outer edge of the border
  *
  * For any parameter where an array of side values is passed in,
  * they are in top, right, bottom, left order.
  *
  * borderStyles -- one border style enum per side
  * borderWidths -- one border width per side
- * borderRadii -- a gfxCornerSizes struct describing the w/h for each rounded corner.
+ * borderRadii -- a RectCornerRadii struct describing the w/h for each rounded corner.
  *    If the corner doesn't have a border radius, 0,0 should be given for it.
  * borderColors -- one nscolor per side
  * compositeColors -- a pointer to an array of composite color structs, or
  *    nullptr if none.
  *
  * skipSides -- a bit mask specifying which sides, if any, to skip
  * backgroundColor -- the background color of the element.
  *    Used in calculating colors for 2-tone borders, such as inset and outset
@@ -80,36 +80,36 @@ struct nsCSSBorderRenderer {
   typedef mozilla::gfx::Float Float;
   typedef mozilla::gfx::RectCornerRadii RectCornerRadii;
 
   nsCSSBorderRenderer(int32_t aAppUnitsPerPixel,
                       gfxContext* aDestContext,
                       gfxRect& aOuterRect,
                       const uint8_t* aBorderStyles,
                       const gfxFloat* aBorderWidths,
-                      gfxCornerSizes& aBorderRadii,
+                      RectCornerRadii& aBorderRadii,
                       const nscolor* aBorderColors,
                       nsBorderColors* const* aCompositeColors,
                       nscolor aBackgroundColor);
 
-  gfxCornerSizes mBorderCornerDimensions;
+  RectCornerRadii mBorderCornerDimensions;
 
   // destination context
   gfxContext* mContext;
 
   // the rectangle of the outside and the inside of the border
   gfxRect mOuterRect;
   gfxRect mInnerRect;
 
   // the style and size of the border
   const uint8_t* mBorderStyles;
   const gfxFloat* mBorderWidths;
   uint8_t* mSanitizedStyles;
   gfxFloat* mSanitizedWidths;
-  gfxCornerSizes mBorderRadii;
+  RectCornerRadii mBorderRadii;
 
   // colors
   const nscolor* mBorderColors;
   nsBorderColors* const* mCompositeColors;
 
   // core app units per pixel
   int32_t mAUPP;
 
@@ -159,18 +159,18 @@ struct nsCSSBorderRenderer {
   //
   // If we can't stroke, then if it's a TL/BR pair, we use the specific
   // TL/BR paths.  Otherwise, we do the full path and fill.
   //
   // Calling code is expected to only set up a clip as necessary; no
   // clip is needed if we can render the entire border in 1 or 2 passes.
   void FillSolidBorder(const gfxRect& aOuterRect,
                        const gfxRect& aInnerRect,
-                       const gfxCornerSizes& aBorderRadii,
-                       const gfxFloat *aBorderSizes,
+                       const RectCornerRadii& aBorderRadii,
+                       const Float *aBorderSizes,
                        int aSides,
                        const gfxRGBA& aColor);
 
   //
   // core rendering
   //
 
   // draw the border for the given sides, using the style of the first side
@@ -210,27 +210,27 @@ struct nsCSSBorderRenderer {
   // Draw a solid border that has no border radius (i.e. is rectangular) and
   // uses CompositeColors.
   void DrawRectangularCompositeColors();
 
   // draw the entire border
   void DrawBorders ();
 
   // utility function used for background painting as well as borders
-  static void ComputeInnerRadii(const gfxCornerSizes& aRadii,
-                                const gfxFloat *aBorderSizes,
-                                gfxCornerSizes *aInnerRadiiRet);
+  static void ComputeInnerRadii(const RectCornerRadii& aRadii,
+                                const Float* aBorderSizes,
+                                RectCornerRadii* aInnerRadiiRet);
 
   // Given aRadii as the border radii for a rectangle, compute the
   // appropriate radii for another rectangle *outside* that rectangle
   // by increasing the radii, except keeping sharp corners sharp.
   // Used for spread box-shadows
   static void ComputeOuterRadii(const RectCornerRadii& aRadii,
-                                const Float *aBorderSizes,
-                                gfxCornerSizes *aOuterRadiiRet);
+                                const Float* aBorderSizes,
+                                RectCornerRadii* aOuterRadiiRet);
 };
 
 namespace mozilla {
 #ifdef DEBUG_NEW_BORDERS
 #include <stdarg.h>
 
 static inline void PrintAsString(const gfxPoint& p) {
   fprintf (stderr, "[%f,%f]", p.x, p.y);
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -2159,34 +2159,36 @@ nsLayoutUtils::RoundedRectIntersectRect(
 
   nsRegion result;
   result.Or(r1, r2);
   return result;
 }
 
 nsIntRegion
 nsLayoutUtils::RoundedRectIntersectIntRect(const nsIntRect& aRoundedRect,
-                                           const gfxCornerSizes& aCorners,
+                                           const RectCornerRadii& aCornerRadii,
                                            const nsIntRect& aContainedRect)
 {
   // rectFullHeight and rectFullWidth together will approximately contain
   // the total area of the frame minus the rounded corners.
   nsIntRect rectFullHeight = aRoundedRect;
-  uint32_t xDiff = std::max(aCorners.TopLeft().width, aCorners.BottomLeft().width);
+  uint32_t xDiff = std::max(aCornerRadii.TopLeft().width,
+                            aCornerRadii.BottomLeft().width);
   rectFullHeight.x += xDiff;
-  rectFullHeight.width -= std::max(aCorners.TopRight().width,
-                                   aCorners.BottomRight().width) + xDiff;
+  rectFullHeight.width -= std::max(aCornerRadii.TopRight().width,
+                                   aCornerRadii.BottomRight().width) + xDiff;
   nsIntRect r1;
   r1.IntersectRect(rectFullHeight, aContainedRect);
 
   nsIntRect rectFullWidth = aRoundedRect;
-  uint32_t yDiff = std::max(aCorners.TopLeft().height, aCorners.TopRight().height);
+  uint32_t yDiff = std::max(aCornerRadii.TopLeft().height,
+                            aCornerRadii.TopRight().height);
   rectFullWidth.y += yDiff;
-  rectFullWidth.height -= std::max(aCorners.BottomLeft().height,
-                                   aCorners.BottomRight().height) + yDiff;
+  rectFullWidth.height -= std::max(aCornerRadii.BottomLeft().height,
+                                   aCornerRadii.BottomRight().height) + yDiff;
   nsIntRect r2;
   r2.IntersectRect(rectFullWidth, aContainedRect);
 
   nsIntRegion result;
   result.Or(r1, r2);
   return result;
 }
 
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -69,16 +69,19 @@ struct ContainerLayerParameters;
 class WritingMode;
 namespace dom {
 class DOMRectList;
 class Element;
 class HTMLImageElement;
 class HTMLCanvasElement;
 class HTMLVideoElement;
 } // namespace dom
+namespace gfx {
+struct RectCornerRadii;
+} // namespace gfx
 namespace layers {
 class Layer;
 class ClientLayerManager;
 }
 }
 
 namespace mozilla {
 
@@ -121,16 +124,17 @@ class nsLayoutUtils
   typedef mozilla::ContainerLayerParameters ContainerLayerParameters;
   typedef mozilla::gfx::SourceSurface SourceSurface;
   typedef mozilla::gfx::Color Color;
   typedef mozilla::gfx::DrawTarget DrawTarget;
   typedef mozilla::gfx::Float Float;
   typedef mozilla::gfx::Point Point;
   typedef mozilla::gfx::Rect Rect;
   typedef mozilla::gfx::Matrix4x4 Matrix4x4;
+  typedef mozilla::gfx::RectCornerRadii RectCornerRadii;
   typedef mozilla::gfx::StrokeOptions StrokeOptions;
 
 public:
   typedef mozilla::layers::FrameMetrics FrameMetrics;
   typedef FrameMetrics::ViewID ViewID;
   typedef mozilla::CSSPoint CSSPoint;
   typedef mozilla::CSSSize CSSSize;
   typedef mozilla::LayerMargin LayerMargin;
@@ -865,17 +869,17 @@ public:
    * Returns a subrectangle of aContainedRect that is entirely inside the rounded
    * rect. Complex cases are handled conservatively by returning a smaller
    * rect than necessary.
    */
   static nsRegion RoundedRectIntersectRect(const nsRect& aRoundedRect,
                                            const nscoord aRadii[8],
                                            const nsRect& aContainedRect);
   static nsIntRegion RoundedRectIntersectIntRect(const nsIntRect& aRoundedRect,
-                                                 const gfxCornerSizes& aCorners,
+                                                 const RectCornerRadii& aCornerRadii,
                                                  const nsIntRect& aContainedRect);
 
   /**
    * Return whether any part of aTestRect is inside of the rounded
    * rectangle formed by aBounds and aRadii (which are indexed by the
    * NS_CORNER_* constants in nsStyleConsts.h). This is precise.
    */
   static bool RoundedRectIntersectsRect(const nsRect& aRoundedRect,