Bug 1471381 - Don't give up on rounded rects in DisplayItemClip r?mattwoodrow draft
 author Doug Thayer Fri, 13 Jul 2018 09:11:28 -0700 changeset 819021 e2ae9e28cbd7a1d878499b27be99ea57ff4b6859 parent 817669 e951f4ad123aa87d1d392c286db14cabb41a8560 push id 116414 push user bmo:dothayer@mozilla.com push date Mon, 16 Jul 2018 22:51:03 +0000 reviewers mattwoodrow bugs 1471381 milestone 63.0a1
Bug 1471381 - Don't give up on rounded rects in DisplayItemClip r?mattwoodrow Effectively we compute the diff by lopping off the rounded part of each rect where appropriate. This gets a bit weird to think about with very mismatched radii, but I think it works out(?) MozReview-Commit-ID: 472gx7Hw1Br
```--- a/layout/painting/DisplayItemClip.cpp
+++ b/layout/painting/DisplayItemClip.cpp
@@ -348,16 +348,110 @@ AccumulateRectDifference(const nsRect& a
if (aR1.IsEqualInterior(aR2))
return;
nsRegion r;
r.Xor(aR1, aR2);
r.And(r, aBounds);
aOut->Or(*aOut, r);
}

+static void
+AccumulateRoundedRectDifference(const DisplayItemClip::RoundedRect& aR1,
+                                const DisplayItemClip::RoundedRect& aR2,
+                                const nsRect& aBounds,
+                                const nsRect& aOtherBounds,
+                                nsRegion* aOut)
+{
+  const nsRect& rect1 = aR1.mRect;
+  const nsRect& rect2 = aR2.mRect;
+
+  // If the two rectangles are totally disjoint, just add them both - otherwise we'd
+  // end up adding one big enclosing rect
+    aOut->Or(*aOut, rect1.Intersect(aBounds));
+    aOut->Or(*aOut, rect2.Intersect(aOtherBounds));
+    return;
+  }
+
+  nscoord lowestBottom = std::max(rect1.YMost(), rect2.YMost());
+  nscoord highestTop = std::min(rect1.Y(), rect2.Y());
+  nscoord maxRight = std::max(rect1.XMost(), rect2.XMost());
+  nscoord minLeft = std::min(rect1.X(), rect2.X());
+
+  // At this point, we know that the radii haven't changed, and that the bounds
+  // are different in some way. To explain how this works, consider the case
+  // where the rounded rect has just been translated along the X direction.
+  // |          ______________________ _ _ _ _ _ _            |
+  // |        /           /            \           \          |
+  // |       |                          |                     |
+  // |       |     aR1   |              |     aR2   |         |
+  // |       |                          |                     |
+  // |        \ __________\___________ / _ _ _ _ _ /          |
+  // |                                                        |
+  // The invalidation region will be as if we lopped off the left rounded part
+  // of aR2, and the right rounded part of aR1, and XOR'd them:
+  // |          ______________________ _ _ _ _ _ _            |
+  // |       -/-----------/-          -\-----------\-         |
+  // |       |--------------          --|------------         |
+  // |       |-----aR1---|--          --|-----aR2---|         |
+  // |       |--------------          --|------------         |
+  // |       -\ __________\-__________-/ _ _ _ _ _ /-          |
+  // |                                                        |
+  // The logic below just implements this idea, but generalized to both the
+  // X and Y dimensions. The "(...)Adjusted(...)" values represent the lopped
+  // off sides.
+
+
+  // We only want to add an invalidation rect if the bounds have changed. If we always
+  // added all of the 4 rects below, we would always be invalidating a border around the
+  // rects, even in cases where we just translated along the X or Y axis.
+  nsRegion r;
+  // First, or with the Y delta rects, wide along the X axis
+  if (rect1.Y() != rect2.Y()) {
+    r.Or(r, nsRect(minLeft, highestTop,
+                   maxRight - minLeft, lowestAdjustedTop - highestTop));
+  }
+  if (rect1.YMost() != rect2.YMost()) {
+                   maxRight - minLeft, lowestBottom - highestAdjustedBottom));
+  }
+  // Then, or with the X delta rects, narrow along the Y axis
+  if (rect1.X() != rect2.X()) {
+  }
+  if (rect1.XMost() != rect2.XMost()) {
+  }
+
+  r.And(r, aBounds.Union(aOtherBounds));
+  aOut->Or(*aOut, r);
+}
+
void
const nsRect& aBounds,
const DisplayItemClip& aOther,
const nsRect& aOtherBounds,
{
if (mHaveClipRect != aOther.mHaveClipRect ||
}
if (mHaveClipRect) {
AccumulateRectDifference(mClipRect + aOffset, aOther.mClipRect,
aBounds.Union(aOtherBounds),
}
for (uint32_t i = 0; i < mRoundedClipRects.Length(); ++i) {
if (mRoundedClipRects[i] + aOffset != aOther.mRoundedClipRects[i]) {
-      // The corners make it tricky so we'll just add both rects here.