Bug 1370682 - Send DisplayItemClip's RoundedRect clips to WR. r=mstange

This was spot-tested by taking the
layout/reftests/border-radius-clipping-1.html testcase, removing the
border, and fiddling with the border-radius values. Without this patch,
the div always appears with rectangular corners but with this patch the
border-radius value is respected correctly.

MozReview-Commit-ID: 1wBFnJnYCwC

--HG--
extra : rebase_source : 542f814af9369fe712af76fc2a8c78de26c6227f
This commit is contained in:
Kartikaya Gupta 2017-08-10 14:00:08 -04:00
parent 96b110eb9e
commit b239f49bcb
3 changed files with 34 additions and 3 deletions

View File

@ -152,8 +152,9 @@ ScrollingLayersHelper::DefineAndPushChain(const DisplayItemClipChain* aChain,
// and save the id
LayoutDeviceRect clip = LayoutDeviceRect::FromAppUnits(
aChain->mClip.GetClipRect(), aAppUnitsPerDevPixel);
// TODO: deal with rounded corners here
clipId = Some(aBuilder.DefineClip(aStackingContext.ToRelativeLayoutRect(clip)));
nsTArray<wr::WrComplexClipRegion> wrRoundedRects;
aChain->mClip.ToWrComplexClipRegions(aAppUnitsPerDevPixel, aStackingContext, wrRoundedRects);
clipId = Some(aBuilder.DefineClip(aStackingContext.ToRelativeLayoutRect(clip), &wrRoundedRects));
aCache[aChain] = clipId.value();
}
// Finally, push the clip onto the WR stack

View File

@ -9,6 +9,8 @@
#include "gfxUtils.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/PathHelpers.h"
#include "mozilla/layers/StackingContextHelper.h"
#include "mozilla/webrender/WebRenderTypes.h"
#include "nsPresContext.h"
#include "nsCSSRendering.h"
#include "nsLayoutUtils.h"
@ -473,4 +475,22 @@ DisplayItemClip::ToString() const
return str;
}
void
DisplayItemClip::ToWrComplexClipRegions(int32_t aAppUnitsPerDevPixel,
const layers::StackingContextHelper& aSc,
nsTArray<wr::WrComplexClipRegion>& aOutArray) const
{
for (uint32_t i = 0; i < mRoundedClipRects.Length(); i++) {
wr::WrComplexClipRegion* region = aOutArray.AppendElement();
region->rect = aSc.ToRelativeLayoutRect(LayoutDeviceRect::FromAppUnits(
mRoundedClipRects[i].mRect, aAppUnitsPerDevPixel));
const nscoord* radii = mRoundedClipRects[i].mRadii;
region->radii = wr::ToBorderRadius(
LayoutDeviceSize::FromAppUnits(nsSize(radii[eCornerTopLeftX], radii[eCornerTopLeftY]), aAppUnitsPerDevPixel),
LayoutDeviceSize::FromAppUnits(nsSize(radii[eCornerTopRightX], radii[eCornerTopRightY]), aAppUnitsPerDevPixel),
LayoutDeviceSize::FromAppUnits(nsSize(radii[eCornerBottomLeftX], radii[eCornerBottomLeftY]), aAppUnitsPerDevPixel),
LayoutDeviceSize::FromAppUnits(nsSize(radii[eCornerBottomRightX], radii[eCornerBottomRightY]), aAppUnitsPerDevPixel));
}
}
} // namespace mozilla

View File

@ -20,6 +20,12 @@ namespace gfx {
class DrawTarget;
class Path;
} // namespace gfx
namespace layers {
class StackingContextHelper;
} // namespace layers
namespace wr {
struct WrComplexClipRegion;
} // namepsace wr
} // namespace mozilla
namespace mozilla {
@ -38,7 +44,7 @@ class DisplayItemClip {
public:
struct RoundedRect {
nsRect mRect;
// Indices into mRadii are the NS_CORNER_* constants in nsStyleConsts.h
// Indices into mRadii are the HalfCorner values in gfx/2d/Types.h
nscoord mRadii[8];
RoundedRect operator+(const nsPoint& aOffset) const {
@ -174,6 +180,10 @@ public:
uint32_t GetRoundedRectCount() const { return mRoundedClipRects.Length(); }
void AppendRoundedRects(nsTArray<RoundedRect>* aArray, uint32_t aCount) const;
void ToWrComplexClipRegions(int32_t aAppUnitsPerDevPixel,
const layers::StackingContextHelper& aSc,
nsTArray<wr::WrComplexClipRegion>& aOutArray) const;
static const DisplayItemClip& NoClip();
static void Shutdown();