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
This commit is contained in:
Kartikaya Gupta 2017-05-03 08:48:08 -04:00
parent 667603672c
commit 989470c342
10 changed files with 87 additions and 62 deletions

View File

@ -6,6 +6,7 @@
#include "mozilla/layers/StackingContextHelper.h"
#include "mozilla/layers/WebRenderLayer.h"
#include "UnitTransforms.h"
namespace mozilla {
namespace layers {
@ -60,11 +61,23 @@ 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

View File

@ -52,9 +52,15 @@ public:
// 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;

View File

@ -8,6 +8,7 @@
#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"
@ -170,13 +171,13 @@ WebRenderDisplayItemLayer::PushItemAsImage(wr::DisplayListBuilder& aBuilder,
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);

View File

@ -372,14 +372,20 @@ static inline WrOpacityProperty ToWrOpacityProperty(uint64_t id, const float opa
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.

View File

@ -13,6 +13,7 @@
#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"
@ -465,12 +466,11 @@ BulletRenderer::CreateWebRenderCommandsForImage(nsDisplayItem* aItem,
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());

View File

@ -23,6 +23,7 @@
#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"
@ -316,9 +317,9 @@ nsDisplayCanvasBackgroundColor::CreateWebRenderCommands(mozilla::wr::DisplayList
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)));
}

View File

@ -28,6 +28,7 @@
#include "mozilla/gfx/2D.h"
#include "gfx2DGlue.h"
#include "gfxGradientCache.h"
#include "mozilla/layers/StackingContextHelper.h"
#include "mozilla/layers/WebRenderDisplayItemLayer.h"
#include <algorithm>
@ -3556,13 +3557,13 @@ nsCSSBorderRenderer::CreateWebRenderCommands(wr::DisplayListBuilder& aBuilder,
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));
}
@ -3570,7 +3571,7 @@ nsCSSBorderRenderer::CreateWebRenderCommands(wr::DisplayListBuilder& aBuilder,
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],

View File

@ -29,6 +29,7 @@
#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"
@ -1066,10 +1067,10 @@ nsCSSGradientRenderer::BuildWebRenderDisplayItems(wr::DisplayListBuilder& aBuild
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),
@ -1085,8 +1086,8 @@ nsCSSGradientRenderer::BuildWebRenderDisplayItems(wr::DisplayListBuilder& aBuild
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,
@ -1098,8 +1099,8 @@ nsCSSGradientRenderer::BuildWebRenderDisplayItems(wr::DisplayListBuilder& aBuild
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,

View File

@ -84,6 +84,7 @@
#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"
@ -4525,20 +4526,17 @@ nsDisplayCaret::CreateWebRenderCommands(wr::DisplayListBuilder& aBuilder,
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));
}
}
@ -4781,15 +4779,13 @@ nsDisplayBorder::CreateBorderImageWebRenderCommands(mozilla::wr::DisplayListBuil
LayoutDeviceRect destRect = LayoutDeviceRect::FromAppUnits(
mBorderImageRenderer->mArea, appUnitsPerDevPixel);
LayerRect destRectTransformed = aLayer->RelativeToParent(destRect);
LayerIntRect dest = RoundedToInt(destRectTransformed);
WrRect dest = aSc.ToRelativeWrRectRounded(destRect);
LayerIntRect clip = dest;
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()) {
@ -4811,8 +4807,8 @@ nsDisplayBorder::CreateBorderImageWebRenderCommands(mozilla::wr::DisplayListBuil
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(
@ -4839,13 +4835,13 @@ nsDisplayBorder::CreateBorderImageWebRenderCommands(mozilla::wr::DisplayListBuil
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),
@ -4853,8 +4849,8 @@ nsDisplayBorder::CreateBorderImageWebRenderCommands(mozilla::wr::DisplayListBuil
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),
@ -5188,9 +5184,8 @@ nsDisplayBoxShadowOuter::CreateWebRenderCommands(wr::DisplayListBuilder& aBuilde
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
@ -5209,19 +5204,19 @@ nsDisplayBoxShadowOuter::CreateWebRenderCommands(wr::DisplayListBuilder& aBuilde
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,
@ -5377,7 +5372,7 @@ nsDisplayBoxShadowInner::CreateInsetBoxShadowWebRenderCommands(mozilla::wr::Disp
// 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;
@ -5391,7 +5386,7 @@ nsDisplayBoxShadowInner::CreateInsetBoxShadowWebRenderCommands(mozilla::wr::Disp
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),

View File

@ -12,6 +12,7 @@
#include "gfxDrawable.h"
#include "ImageOps.h"
#include "mozilla/layers/StackingContextHelper.h"
#include "nsContentUtils.h"
#include "nsCSSRendering.h"
#include "nsCSSRenderingGradients.h"
@ -632,13 +633,13 @@ nsImageRenderer::BuildWebRenderDisplayItems(nsPresContext* aPresContext,
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;