Bug 1360246 - Update code to use StackingContextHelper::ToRelativeWr* instead of RelativeToParent. r=nical draft
authorKartikaya Gupta <kgupta@mozilla.com>
Tue, 02 May 2017 09:19:21 -0400
changeset 571372 2f24a876b6d10cb672cba7b62347878a6fec650f
parent 571371 113e2056b5db4fdca977f00100c0fe671eec3aa2
child 571373 781f2b38fd8623bd82eb3874c344e941bf23ac5f
push id56763
push userkgupta@mozilla.com
push dateTue, 02 May 2017 13:20:18 +0000
reviewersnical
bugs1360246
milestone55.0a1
Bug 1360246 - Update code to use StackingContextHelper::ToRelativeWr* instead of RelativeToParent. r=nical This updates more code that was using RelativeToParent() to use the stacking context helper's ToRelativeWr* functions instead. This get us closer to breaking the assumption that the WR stacking context order maps 1:1 to the layer tree structure. MozReview-Commit-ID: HQrbvCgPOW4
gfx/layers/wr/StackingContextHelper.cpp
gfx/layers/wr/StackingContextHelper.h
gfx/layers/wr/WebRenderDisplayItemLayer.cpp
gfx/webrender_bindings/WebRenderTypes.h
layout/generic/nsBulletFrame.cpp
layout/generic/nsCanvasFrame.cpp
layout/painting/nsCSSRenderingBorders.cpp
layout/painting/nsCSSRenderingGradients.cpp
layout/painting/nsDisplayList.cpp
layout/painting/nsImageRenderer.cpp
--- a/gfx/layers/wr/StackingContextHelper.cpp
+++ b/gfx/layers/wr/StackingContextHelper.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; 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 "mozilla/layers/StackingContextHelper.h"
 
 #include "mozilla/layers/WebRenderLayer.h"
+#include "UnitTransforms.h"
 
 namespace mozilla {
 namespace layers {
 
 StackingContextHelper::StackingContextHelper()
   : mBuilder(nullptr)
 {
   // mOrigin remains at 0,0
@@ -55,16 +56,28 @@ StackingContextHelper::~StackingContextH
 }
 
 WrRect
 StackingContextHelper::ToRelativeWrRect(const LayerRect& aRect) const
 {
   return wr::ToWrRect(aRect - mOrigin);
 }
 
+WrRect
+StackingContextHelper::ToRelativeWrRect(const LayoutDeviceRect& aRect) const
+{
+  return wr::ToWrRect(ViewAs<LayerPixel>(aRect, PixelCastJustification::WebRenderHasUnitResolution) - mOrigin);
+}
+
 WrPoint
 StackingContextHelper::ToRelativeWrPoint(const LayerPoint& aPoint) const
 {
   return wr::ToWrPoint(aPoint - mOrigin);
 }
 
+WrRect
+StackingContextHelper::ToRelativeWrRectRounded(const LayoutDeviceRect& aRect) const
+{
+  return wr::ToWrRect(RoundedToInt(ViewAs<LayerPixel>(aRect, PixelCastJustification::WebRenderHasUnitResolution) - mOrigin));
+}
+
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/wr/StackingContextHelper.h
+++ b/gfx/layers/wr/StackingContextHelper.h
@@ -47,19 +47,25 @@ public:
   // Pops the stacking context, if one was pushed during the constructor.
   ~StackingContextHelper();
 
   // When this StackingContextHelper is in scope, this function can be used
   // to convert a rect from the layer system's coordinate space to a WrRect
   // that is relative to the stacking context. This is useful because most
   // things that are pushed inside the stacking context need to be relative
   // to the stacking context.
+  // We allow passing in a LayoutDeviceRect for convenience because in a lot of
+  // cases with WebRender display item generate the layout device space is the
+  // same as the layer space. (TODO: try to make this more explicit somehow).
   WrRect ToRelativeWrRect(const LayerRect& aRect) const;
+  WrRect ToRelativeWrRect(const LayoutDeviceRect& aRect) const;
   // Same but for points
   WrPoint ToRelativeWrPoint(const LayerPoint& aPoint) const;
+  // Same but rounds the rectangle to ints after transforming.
+  WrRect ToRelativeWrRectRounded(const LayoutDeviceRect& aRect) const;
 
 private:
   wr::DisplayListBuilder* mBuilder;
   LayerPoint mOrigin;
 };
 
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/wr/WebRenderDisplayItemLayer.cpp
+++ b/gfx/layers/wr/WebRenderDisplayItemLayer.cpp
@@ -3,16 +3,17 @@
  * 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 "WebRenderDisplayItemLayer.h"
 
 #include "LayersLogging.h"
 #include "mozilla/webrender/webrender_ffi.h"
 #include "mozilla/webrender/WebRenderTypes.h"
+#include "mozilla/layers/StackingContextHelper.h"
 #include "mozilla/layers/WebRenderBridgeChild.h"
 #include "nsDisplayList.h"
 #include "mozilla/gfx/Matrix.h"
 #include "mozilla/layers/UpdateImageHelper.h"
 #include "UnitTransforms.h"
 
 namespace mozilla {
 namespace layers {
@@ -165,23 +166,23 @@ WebRenderDisplayItemLayer::PushItemAsIma
     nsRenderingContext ctx(context);
     mItem->Paint(mBuilder, &ctx);
   }
 
   if (!helper.UpdateImage()) {
     return false;
   }
 
-  LayerRect dest = RelativeToParent(imageRect) + offset;
-  WrClipRegion clipRegion = aBuilder.BuildClipRegion(wr::ToWrRect(dest));
+  WrRect dest = aSc.ToRelativeWrRect(imageRect + offset);
+  WrClipRegion clipRegion = aBuilder.BuildClipRegion(dest);
   WrImageKey key = GetImageKey();
   aParentCommands.AppendElement(layers::OpAddExternalImage(
                                 mExternalImageId.value(),
                                 key));
-  aBuilder.PushImage(wr::ToWrRect(dest),
+  aBuilder.PushImage(dest,
                      clipRegion,
                      WrImageRendering::Auto,
                      key);
 
   return true;
 }
 
 } // namespace layers
--- a/gfx/webrender_bindings/WebRenderTypes.h
+++ b/gfx/webrender_bindings/WebRenderTypes.h
@@ -367,24 +367,30 @@ static inline WrTransformProperty ToWrTr
 static inline WrOpacityProperty ToWrOpacityProperty(uint64_t id, const float opacity)
 {
   WrOpacityProperty prop;
   prop.id = id;
   prop.opacity = opacity;
   return prop;
 }
 
+static inline WrComplexClipRegion ToWrComplexClipRegion(const WrRect& rect,
+                                                        const LayerSize& size)
+{
+  WrComplexClipRegion complex_clip;
+  complex_clip.rect = rect;
+  complex_clip.radii = wr::ToWrUniformBorderRadius(size);
+  return complex_clip;
+}
+
 template<class T>
 static inline WrComplexClipRegion ToWrComplexClipRegion(const gfx::RectTyped<T>& rect,
                                                         const LayerSize& size)
 {
-  WrComplexClipRegion complex_clip;
-  complex_clip.rect = wr::ToWrRect(rect);
-  complex_clip.radii = wr::ToWrUniformBorderRadius(size);
-  return complex_clip;
+  return ToWrComplexClipRegion(wr::ToWrRect(rect), size);
 }
 
 // Whenever possible, use wr::ExternalImageId instead of manipulating uint64_t.
 inline uint64_t AsUint64(const ExternalImageId& aId) {
   return static_cast<uint64_t>(aId.mHandle);
 }
 
 static inline ExternalImageId ToExternalImageId(uint64_t aID)
--- a/layout/generic/nsBulletFrame.cpp
+++ b/layout/generic/nsBulletFrame.cpp
@@ -8,16 +8,17 @@
 #include "nsBulletFrame.h"
 
 #include "gfx2DGlue.h"
 #include "gfxPrefs.h"
 #include "gfxUtils.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/PathHelpers.h"
 #include "mozilla/layers/LayersMessages.h"
+#include "mozilla/layers/StackingContextHelper.h"
 #include "mozilla/layers/WebRenderDisplayItemLayer.h"
 #include "mozilla/layers/WebRenderMessages.h"
 #include "mozilla/MathAlgorithms.h"
 #include "mozilla/Move.h"
 #include "nsCOMPtr.h"
 #include "nsFontMetrics.h"
 #include "nsGkAtoms.h"
 #include "nsGenericHTMLElement.h"
@@ -466,22 +467,21 @@ BulletRenderer::CreateWebRenderCommandsF
 
   Maybe<wr::ImageKey> key = layer->SendImageContainer(container, aParentCommands);
   if (key.isNothing()) {
     return;
   }
 
   const int32_t appUnitsPerDevPixel = aItem->Frame()->PresContext()->AppUnitsPerDevPixel();
   LayoutDeviceRect destRect = LayoutDeviceRect::FromAppUnits(mDest, appUnitsPerDevPixel);
-  LayerRect destRectTransformed = aLayer->RelativeToParent(destRect);
-  LayerIntRect dest = RoundedToInt(destRectTransformed);
+  WrRect dest = aSc.ToRelativeWrRectRounded(destRect);
 
-  WrClipRegion clipRegion = aBuilder.BuildClipRegion(wr::ToWrRect(dest));
+  WrClipRegion clipRegion = aBuilder.BuildClipRegion(dest);
 
-  aBuilder.PushImage(wr::ToWrRect(dest),
+  aBuilder.PushImage(dest,
                      clipRegion,
                      WrImageRendering::Auto,
                      key.value());
 }
 
 void
 BulletRenderer::CreateWebRenderCommandsForPath(nsDisplayItem* aItem,
                                                wr::DisplayListBuilder& aBuilder,
--- a/layout/generic/nsCanvasFrame.cpp
+++ b/layout/generic/nsCanvasFrame.cpp
@@ -18,16 +18,17 @@
 #include "nsIFrameInlines.h"
 #include "nsIPresShell.h"
 #include "nsDisplayList.h"
 #include "nsCSSFrameConstructor.h"
 #include "nsFrameManager.h"
 #include "gfxPlatform.h"
 #include "nsPrintfCString.h"
 #include "mozilla/dom/AnonymousContent.h"
+#include "mozilla/layers/StackingContextHelper.h"
 #include "mozilla/PresShell.h"
 // for focus
 #include "nsIScrollableFrame.h"
 #ifdef DEBUG_CANVAS_FOCUS
 #include "nsIDocShell.h"
 #endif
 
 //#define DEBUG_CANVAS_FOCUS
@@ -311,19 +312,19 @@ nsDisplayCanvasBackgroundColor::CreateWe
   nsCanvasFrame* frame = static_cast<nsCanvasFrame*>(mFrame);
   nsPoint offset = ToReferenceFrame();
   nsRect bgClipRect = frame->CanvasArea() + offset;
   int32_t appUnitsPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel();
 
   LayoutDeviceRect rect = LayoutDeviceRect::FromAppUnits(
           bgClipRect, appUnitsPerDevPixel);
 
-  LayerRect transformedRect = aLayer->RelativeToParent(rect);
-  aBuilder.PushRect(wr::ToWrRect(transformedRect),
-                    aBuilder.BuildClipRegion(wr::ToWrRect(transformedRect)),
+  WrRect transformedRect = aSc.ToRelativeWrRect(rect);
+  aBuilder.PushRect(transformedRect,
+                    aBuilder.BuildClipRegion(transformedRect),
                     wr::ToWrColor(ToDeviceColor(mColor)));
 }
 
 #ifdef MOZ_DUMP_PAINTING
 void
 nsDisplayCanvasBackgroundColor::WriteDebugInfo(std::stringstream& aStream)
 {
   aStream << " (rgba "
--- a/layout/painting/nsCSSRenderingBorders.cpp
+++ b/layout/painting/nsCSSRenderingBorders.cpp
@@ -23,16 +23,17 @@
 #include "RoundedRect.h"
 #include "nsIScriptError.h"
 #include "nsClassHashtable.h"
 #include "nsPresContext.h"
 #include "nsStyleStruct.h"
 #include "mozilla/gfx/2D.h"
 #include "gfx2DGlue.h"
 #include "gfxGradientCache.h"
+#include "mozilla/layers/StackingContextHelper.h"
 #include "mozilla/layers/WebRenderDisplayItemLayer.h"
 #include <algorithm>
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 
 #define MAX_COMPOSITE_BORDER_WIDTH LayoutDeviceIntCoord(10000)
 
@@ -3551,31 +3552,31 @@ nsCSSBorderRenderer::CanCreateWebRenderC
 
 void
 nsCSSBorderRenderer::CreateWebRenderCommands(wr::DisplayListBuilder& aBuilder,
                                              const layers::StackingContextHelper& aSc,
                                              layers::WebRenderDisplayItemLayer* aLayer,
                                              gfx::Rect aClipRect)
 {
   LayoutDeviceRect outerRect = LayoutDeviceRect::FromUnknownRect(mOuterRect);
-  LayerRect transformedRect = aLayer->RelativeToParent(outerRect);
+  WrRect transformedRect = aSc.ToRelativeWrRect(outerRect);
   WrBorderSide side[4];
   NS_FOR_CSS_SIDES(i) {
     side[i] = wr::ToWrBorderSide(ToDeviceColor(mBorderColors[i]), mBorderStyles[i]);
   }
 
-  WrClipRegion clipRegion = aBuilder.BuildClipRegion(wr::ToWrRect(transformedRect));
+  WrClipRegion clipRegion = aBuilder.BuildClipRegion(transformedRect);
   if (!aClipRect.IsEmpty()) {
     clipRegion = aBuilder.BuildClipRegion(wr::ToWrRect(aClipRect));
   }
   WrBorderRadius borderRadius = wr::ToWrBorderRadius(LayerSize(mBorderRadii[0].width, mBorderRadii[0].height),
                                                      LayerSize(mBorderRadii[1].width, mBorderRadii[1].height),
                                                      LayerSize(mBorderRadii[3].width, mBorderRadii[3].height),
                                                      LayerSize(mBorderRadii[2].width, mBorderRadii[2].height));
-  aBuilder.PushBorder(wr::ToWrRect(transformedRect),
+  aBuilder.PushBorder(transformedRect,
                       clipRegion,
                       wr::ToWrBorderWidths(mBorderWidths[0], mBorderWidths[1], mBorderWidths[2], mBorderWidths[3]),
                       side[0], side[1], side[2], side[3],
                       borderRadius);
 }
 
 /* static */Maybe<nsCSSBorderImageRenderer>
 nsCSSBorderImageRenderer::CreateBorderImageRenderer(nsPresContext* aPresContext,
--- a/layout/painting/nsCSSRenderingGradients.cpp
+++ b/layout/painting/nsCSSRenderingGradients.cpp
@@ -24,16 +24,17 @@
 #include "gfxContext.h"
 #include "nsRenderingContext.h"
 #include "nsStyleStructInlines.h"
 #include "nsCSSProps.h"
 #include "mozilla/Telemetry.h"
 #include "gfxUtils.h"
 #include "gfxGradientCache.h"
 
+#include "mozilla/layers/StackingContextHelper.h"
 #include "mozilla/layers/WebRenderLayerManager.h"
 #include "mozilla/webrender/WebRenderTypes.h"
 #include "mozilla/webrender/WebRenderAPI.h"
 #include "Units.h"
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 
@@ -1061,50 +1062,50 @@ nsCSSGradientRenderer::BuildWebRenderDis
   LayoutDevicePoint tileToClip = clipBounds.BottomRight() - firstTileBounds.TopLeft();
   LayoutDeviceRect gradientBounds = LayoutDeviceRect(firstTileBounds.TopLeft(),
                                                      LayoutDeviceSize(tileToClip.x, tileToClip.y));
 
   // Calculate the tile spacing, which is the repeat size minus the tile size
   LayoutDeviceSize tileSpacing = tileRepeat - firstTileBounds.Size();
 
   // Make the rects relative to the parent stacking context
-  LayerRect layerClipBounds = aLayer->RelativeToParent(clipBounds);
+  WrRect wrClipBounds = aSc.ToRelativeWrRect(clipBounds);
   LayerSize layerFirstTileSize = ViewAs<LayerPixel>(firstTileBounds.Size(),
       PixelCastJustification::WebRenderHasUnitResolution);
-  LayerRect layerGradientBounds = aLayer->RelativeToParent(gradientBounds);
+  WrRect wrGradientBounds = aSc.ToRelativeWrRect(gradientBounds);
 
   // srcTransform is used for scaling the gradient to match aSrc
   LayoutDeviceRect srcTransform = LayoutDeviceRect(mPresContext->CSSPixelsToAppUnits(aSrc.x),
                                                    mPresContext->CSSPixelsToAppUnits(aSrc.y),
                                                    aDest.width / ((float)mPresContext->CSSPixelsToAppUnits(aSrc.width)),
                                                    aDest.height / ((float)mPresContext->CSSPixelsToAppUnits(aSrc.height)));
 
   lineStart.x = (lineStart.x - srcTransform.x) * srcTransform.width;
   lineStart.y = (lineStart.y - srcTransform.y) * srcTransform.height;
 
   if (mGradient->mShape == NS_STYLE_GRADIENT_SHAPE_LINEAR) {
     lineEnd.x = (lineEnd.x - srcTransform.x) * srcTransform.width;
     lineEnd.y = (lineEnd.y - srcTransform.y) * srcTransform.height;
 
     aBuilder.PushLinearGradient(
-      mozilla::wr::ToWrRect(layerGradientBounds),
-      aBuilder.BuildClipRegion(mozilla::wr::ToWrRect(layerClipBounds)),
+      wrGradientBounds,
+      aBuilder.BuildClipRegion(wrClipBounds),
       mozilla::wr::ToWrPoint(lineStart),
       mozilla::wr::ToWrPoint(lineEnd),
       stops,
       extendMode,
       mozilla::wr::ToWrSize(layerFirstTileSize),
       mozilla::wr::ToWrSize(tileSpacing));
   } else {
     gradientRadius.width *= srcTransform.width;
     gradientRadius.height *= srcTransform.height;
 
     aBuilder.PushRadialGradient(
-      mozilla::wr::ToWrRect(layerGradientBounds),
-      aBuilder.BuildClipRegion(mozilla::wr::ToWrRect(layerClipBounds)),
+      wrGradientBounds,
+      aBuilder.BuildClipRegion(wrClipBounds),
       mozilla::wr::ToWrPoint(lineStart),
       mozilla::wr::ToWrSize(gradientRadius),
       stops,
       extendMode,
       mozilla::wr::ToWrSize(layerFirstTileSize),
       mozilla::wr::ToWrSize(tileSpacing));
   }
 }
--- a/layout/painting/nsDisplayList.cpp
+++ b/layout/painting/nsDisplayList.cpp
@@ -79,16 +79,17 @@
 #include "nsCaret.h"
 #include "nsISelection.h"
 #include "nsDOMTokenList.h"
 #include "mozilla/RuleNodeCacheConditions.h"
 #include "nsCSSProps.h"
 #include "nsPluginFrame.h"
 #include "nsSVGMaskFrame.h"
 #include "ClientLayerManager.h"
+#include "mozilla/layers/StackingContextHelper.h"
 #include "mozilla/layers/WebRenderBridgeChild.h"
 #include "mozilla/layers/WebRenderLayerManager.h"
 #include "mozilla/layers/WebRenderDisplayItemLayer.h"
 #include "mozilla/layers/WebRenderMessages.h"
 #include "mozilla/layers/WebRenderDisplayItemLayer.h"
 
 // GetCurrentTime is defined in winbase.h as zero argument macro forwarding to
 // GetTickCount().
@@ -4518,30 +4519,27 @@ nsDisplayCaret::CreateWebRenderCommands(
   mCaret->ComputeCaretRects(frame, contentOffset, &caretRect, &hookRect);
 
   gfx::Color color = ToDeviceColor(frame->GetCaretColorAt(contentOffset));
   LayoutDeviceRect devCaretRect = LayoutDeviceRect::FromAppUnits(
     caretRect + ToReferenceFrame(), appUnitsPerDevPixel);
   LayoutDeviceRect devHookRect = LayoutDeviceRect::FromAppUnits(
     hookRect + ToReferenceFrame(), appUnitsPerDevPixel);
 
-  LayerRect caretTransformedRect = aLayer->RelativeToParent(devCaretRect);
-  LayerRect hookTransformedRect = aLayer->RelativeToParent(devHookRect);
-
-  LayerIntRect caret = RoundedToInt(caretTransformedRect);
-  LayerIntRect hook = RoundedToInt(hookTransformedRect);
+  WrRect caret = aSc.ToRelativeWrRectRounded(devCaretRect);
+  WrRect hook = aSc.ToRelativeWrRectRounded(devHookRect);
 
   // Note, WR will pixel snap anything that is layout aligned.
-  aBuilder.PushRect(wr::ToWrRect(caret),
-                    aBuilder.BuildClipRegion(wr::ToWrRect(caret)),
+  aBuilder.PushRect(caret,
+                    aBuilder.BuildClipRegion(caret),
                     wr::ToWrColor(color));
 
   if (!devHookRect.IsEmpty()) {
-    aBuilder.PushRect(wr::ToWrRect(hook),
-                      aBuilder.BuildClipRegion(wr::ToWrRect(hook)),
+    aBuilder.PushRect(hook,
+                      aBuilder.BuildClipRegion(hook),
                       wr::ToWrColor(color));
   }
 }
 
 LayerState
 nsDisplayCaret::GetLayerState(nsDisplayListBuilder* aBuilder,
                               LayerManager* aManager,
                               const ContainerLayerParameters& aParameters)
@@ -4774,25 +4772,23 @@ nsDisplayBorder::CreateBorderImageWebRen
   NS_FOR_CSS_SIDES(i) {
     slice[i] = (float)(mBorderImageRenderer->mSlice.Side(i)) / appUnitsPerDevPixel;
     widths[i] = (float)(mBorderImageRenderer->mWidths.Side(i)) / appUnitsPerDevPixel;
     outset[i] = (float)(mBorderImageRenderer->mImageOutset.Side(i)) / appUnitsPerDevPixel;
   }
 
   LayoutDeviceRect destRect = LayoutDeviceRect::FromAppUnits(
     mBorderImageRenderer->mArea, appUnitsPerDevPixel);
-  LayerRect destRectTransformed = aLayer->RelativeToParent(destRect);
-  LayerIntRect dest = RoundedToInt(destRectTransformed);
-
-  LayerIntRect clip = dest;
+  WrRect dest = aSc.ToRelativeWrRectRounded(destRect);
+
+  WrRect clip = dest;
   if (!mBorderImageRenderer->mClip.IsEmpty()) {
     LayoutDeviceRect clipRect = LayoutDeviceRect::FromAppUnits(
       mBorderImageRenderer->mClip, appUnitsPerDevPixel);
-    LayerRect clipRectTransformed = aLayer->RelativeToParent(clipRect);
-    clip = RoundedToInt(clipRectTransformed);
+    clip = aSc.ToRelativeWrRectRounded(clipRect);
   }
 
   switch (mBorderImageRenderer->mImageRenderer.GetType()) {
     case eStyleImageType_Image:
     {
       nsDisplayListBuilder* builder = aLayer->GetDisplayListBuilder();
       uint32_t flags = builder->ShouldSyncDecodeImages() ?
                        imgIContainer::FLAG_SYNC_DECODE :
@@ -4804,18 +4800,18 @@ nsDisplayBorder::CreateBorderImageWebRen
         return;
       }
 
       Maybe<wr::ImageKey> key = aLayer->SendImageContainer(container, aParentCommands);
       if (key.isNothing()) {
         return;
       }
 
-      aBuilder.PushBorderImage(wr::ToWrRect(dest),
-                               aBuilder.BuildClipRegion(wr::ToWrRect(clip)),
+      aBuilder.PushBorderImage(dest,
+                               aBuilder.BuildClipRegion(clip),
                                wr::ToWrBorderWidths(widths[0], widths[1], widths[2], widths[3]),
                                key.value(),
                                wr::ToWrNinePatchDescriptor(
                                  (float)(mBorderImageRenderer->mImageSize.width) / appUnitsPerDevPixel,
                                  (float)(mBorderImageRenderer->mImageSize.height) / appUnitsPerDevPixel,
                                  wr::ToWrSideOffsets2Du32(slice[0], slice[1], slice[2], slice[3])),
                                wr::ToWrSideOffsets2Df32(outset[0], outset[1], outset[2], outset[3]),
                                wr::ToWrRepeatMode(mBorderImageRenderer->mRepeatModeHorizontal),
@@ -4832,32 +4828,32 @@ nsDisplayBorder::CreateBorderImageWebRen
       WrGradientExtendMode extendMode;
       nsTArray<WrGradientStop> stops;
       LayoutDevicePoint lineStart;
       LayoutDevicePoint lineEnd;
       LayoutDeviceSize gradientRadius;
       renderer.BuildWebRenderParameters(1.0, extendMode, stops, lineStart, lineEnd, gradientRadius);
 
       if (gradientData->mShape == NS_STYLE_GRADIENT_SHAPE_LINEAR) {
-        LayerPoint startPoint = dest.TopLeft();
+        LayerPoint startPoint = LayerPoint(dest.x, dest.y);
         startPoint = startPoint + ViewAs<LayerPixel>(lineStart, PixelCastJustification::WebRenderHasUnitResolution);
-        LayerPoint endPoint = dest.TopLeft();
+        LayerPoint endPoint = LayerPoint(dest.x, dest.y);
         endPoint = endPoint + ViewAs<LayerPixel>(lineEnd, PixelCastJustification::WebRenderHasUnitResolution);
 
-        aBuilder.PushBorderGradient(wr::ToWrRect(dest),
-                                    aBuilder.BuildClipRegion(wr::ToWrRect(clip)),
+        aBuilder.PushBorderGradient(dest,
+                                    aBuilder.BuildClipRegion(clip),
                                     wr::ToWrBorderWidths(widths[0], widths[1], widths[2], widths[3]),
                                     wr::ToWrPoint(startPoint),
                                     wr::ToWrPoint(endPoint),
                                     stops,
                                     extendMode,
                                     wr::ToWrSideOffsets2Df32(outset[0], outset[1], outset[2], outset[3]));
       } else {
-        aBuilder.PushBorderRadialGradient(wr::ToWrRect(dest),
-                                          aBuilder.BuildClipRegion(wr::ToWrRect(clip)),
+        aBuilder.PushBorderRadialGradient(dest,
+                                          aBuilder.BuildClipRegion(clip),
                                           wr::ToWrBorderWidths(widths[0], widths[1], widths[2], widths[3]),
                                           wr::ToWrPoint(lineStart),
                                           wr::ToWrSize(gradientRadius),
                                           stops,
                                           extendMode,
                                           wr::ToWrSideOffsets2Df32(outset[0], outset[1], outset[2], outset[3]));
       }
       break;
@@ -5181,19 +5177,18 @@ nsDisplayBoxShadowOuter::CreateWebRender
       // Now translate everything to device pixels.
       nsRect shadowRect = frameRect;
       Point shadowOffset;
       shadowOffset.x = (shadow->mXOffset / appUnitsPerDevPixel);
       shadowOffset.y = (shadow->mYOffset / appUnitsPerDevPixel);
 
       LayoutDeviceRect deviceBox = LayoutDeviceRect::FromAppUnits(
           shadowRect, appUnitsPerDevPixel);
-      LayerRect deviceBoxRect = aLayer->RelativeToParent(deviceBox);
-      deviceBoxRect.Round();
-      LayerRect deviceClipRect = aLayer->RelativeToParent(clipRect);
+      WrRect deviceBoxRect = aSc.ToRelativeWrRectRounded(deviceBox);
+      WrRect deviceClipRect = aSc.ToRelativeWrRect(clipRect);
 
       // TODO: support non-uniform border radius.
       float borderRadius = hasBorderRadius ? borderRadii.TopLeft().width
                                            : 0.0;
       float spreadRadius = float(shadow->mSpread) / float(appUnitsPerDevPixel);
 
       if (blurRadius <= 0) {
         MOZ_ASSERT(false, "WR needs clip out first");
@@ -5202,29 +5197,29 @@ nsDisplayBoxShadowOuter::CreateWebRender
         // clip out yet
         if (hasBorderRadius) {
           LayerSize borderRadiusSize(borderRadius, borderRadius);
           WrComplexClipRegion roundedRect =
                                   wr::ToWrComplexClipRegion(deviceBoxRect,
                                                             borderRadiusSize);
           nsTArray<WrComplexClipRegion> clips;
           clips.AppendElement(roundedRect);
-          aBuilder.PushRect(wr::ToWrRect(deviceBoxRect),
-                            aBuilder.BuildClipRegion(wr::ToWrRect(deviceClipRect),
-                                                    clips),
+          aBuilder.PushRect(deviceBoxRect,
+                            aBuilder.BuildClipRegion(deviceClipRect,
+                                                     clips),
                             wr::ToWrColor(shadowColor));
         } else {
-          aBuilder.PushRect(wr::ToWrRect(deviceBoxRect),
-                            aBuilder.BuildClipRegion(wr::ToWrRect(deviceClipRect)),
+          aBuilder.PushRect(deviceBoxRect,
+                            aBuilder.BuildClipRegion(deviceClipRect),
                             wr::ToWrColor(shadowColor));
         }
       } else {
-        aBuilder.PushBoxShadow(wr::ToWrRect(deviceBoxRect),
-                              aBuilder.BuildClipRegion(wr::ToWrRect(deviceClipRect)),
-                              wr::ToWrRect(deviceBoxRect),
+        aBuilder.PushBoxShadow(deviceBoxRect,
+                              aBuilder.BuildClipRegion(deviceClipRect),
+                              deviceBoxRect,
                               wr::ToWrPoint(shadowOffset),
                               wr::ToWrColor(shadowColor),
                               blurRadius,
                               spreadRadius,
                               borderRadius,
                               WrBoxShadowClipMode::Outset);
       }
     }
@@ -5370,31 +5365,31 @@ nsDisplayBoxShadowInner::CreateInsetBoxS
       nsRect shadowRect =
         nsCSSRendering::GetBoxShadowInnerPaddingRect(aFrame, aBorderRect);
       RectCornerRadii innerRadii;
       nsCSSRendering::GetShadowInnerRadii(aFrame, aBorderRect, innerRadii);
 
       // Now translate everything to device pixels.
       Rect deviceBoxRect = LayoutDeviceRect::FromAppUnits(
           shadowRect, appUnitsPerDevPixel).ToUnknownRect();
-      LayerRect deviceClipRect = aLayer->RelativeToParent(clipRect);
+      WrRect deviceClipRect = aSc.ToRelativeWrRect(clipRect);
       Color shadowColor = nsCSSRendering::GetShadowColor(shadowItem, aFrame, 1.0);
 
       Point shadowOffset;
       shadowOffset.x = (shadowItem->mXOffset / appUnitsPerDevPixel);
       shadowOffset.y = (shadowItem->mYOffset / appUnitsPerDevPixel);
 
       float blurRadius = float(shadowItem->mRadius) / float(appUnitsPerDevPixel);
       // TODO: WR doesn't support non-uniform border radii
       float borderRadius = innerRadii.TopLeft().width;
       // NOTE: Any spread radius > 0 will render nothing. WR Bug.
       float spreadRadius = float(shadowItem->mSpread) / float(appUnitsPerDevPixel);
 
       aBuilder.PushBoxShadow(wr::ToWrRect(deviceBoxRect),
-                             aBuilder.BuildClipRegion(wr::ToWrRect(deviceClipRect)),
+                             aBuilder.BuildClipRegion(deviceClipRect),
                              wr::ToWrRect(deviceBoxRect),
                              wr::ToWrPoint(shadowOffset),
                              wr::ToWrColor(shadowColor),
                              blurRadius,
                              spreadRadius,
                              borderRadius,
                              WrBoxShadowClipMode::Inset
                              );
--- a/layout/painting/nsImageRenderer.cpp
+++ b/layout/painting/nsImageRenderer.cpp
@@ -7,16 +7,17 @@
 /* utility functions for drawing borders and backgrounds */
 
 #include "nsImageRenderer.h"
 
 #include "mozilla/webrender/WebRenderAPI.h"
 
 #include "gfxDrawable.h"
 #include "ImageOps.h"
+#include "mozilla/layers/StackingContextHelper.h"
 #include "nsContentUtils.h"
 #include "nsCSSRendering.h"
 #include "nsCSSRenderingGradients.h"
 #include "nsIFrame.h"
 #include "nsRenderingContext.h"
 #include "nsStyleStructInlines.h"
 #include "nsSVGEffects.h"
 #include "nsSVGIntegrationUtils.h"
@@ -627,23 +628,23 @@ nsImageRenderer::BuildWebRenderDisplayIt
 
       nsPoint firstTilePos = nsLayoutUtils::GetBackgroundFirstTilePos(aDest.TopLeft(),
                                                                       aFill.TopLeft(),
                                                                       aRepeatSize);
       LayoutDeviceRect fillRect = LayoutDeviceRect::FromAppUnits(
           nsRect(firstTilePos.x, firstTilePos.y,
                  aFill.XMost() - firstTilePos.x, aFill.YMost() - firstTilePos.y),
           appUnitsPerDevPixel);
-      LayerRect fill = aLayer->RelativeToParent(fillRect);
-      LayerRect clip = aLayer->RelativeToParent(
-                                 LayoutDeviceRect::FromAppUnits(aFill,appUnitsPerDevPixel));
+      WrRect fill = aSc.ToRelativeWrRect(fillRect);
+      WrRect clip = aSc.ToRelativeWrRect(
+          LayoutDeviceRect::FromAppUnits(aFill, appUnitsPerDevPixel));
 
       LayoutDeviceSize gapSize = LayoutDeviceSize::FromAppUnits(
           aRepeatSize - aDest.Size(), appUnitsPerDevPixel);
-      aBuilder.PushImage(wr::ToWrRect(fill), aBuilder.BuildClipRegion(wr::ToWrRect(clip)),
+      aBuilder.PushImage(fill, aBuilder.BuildClipRegion(clip),
                          wr::ToWrSize(destRect.Size()), wr::ToWrSize(gapSize),
                          wr::ImageRendering::Auto, key.value());
       break;
     }
     default:
       break;
   }