Bug 1519499. Only use a nsRegion when needing during ComputeGeometryChange clippedBounds. r=mstange
authorJeff Muizelaar <jrmuizel@gmail.com>
Tue, 15 Jan 2019 21:15:32 +0000
changeset 511096 4ee8f7951ed5cb5fe9b4955dae15e1ca9d6be9c6
parent 511095 0aba112c5ad99d2f3b6045ebc85f5035e5d5be99
child 511097 d94c4b92b44b313a48c3581d6804950f1235b7cb
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1519499
milestone66.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 1519499. Only use a nsRegion when needing during ComputeGeometryChange clippedBounds. r=mstange Differential Revision: https://phabricator.services.mozilla.com/D16597
gfx/layers/wr/WebRenderCommandBuilder.cpp
--- a/gfx/layers/wr/WebRenderCommandBuilder.cpp
+++ b/gfx/layers/wr/WebRenderCommandBuilder.cpp
@@ -376,17 +376,16 @@ struct DIGroup {
 
   void ComputeGeometryChange(nsDisplayItem* aItem, BlobItemData* aData,
                              Matrix& aMatrix, nsDisplayListBuilder* aBuilder) {
     // If the frame is marked as invalidated, and didn't specify a rect to
     // invalidate then we want to invalidate both the old and new bounds,
     // otherwise we only want to invalidate the changed areas. If we do get an
     // invalid rect, then we want to add this on top of the change areas.
     nsRect invalid;
-    nsRegion combined;
     const DisplayItemClip& clip = aItem->GetClip();
 
     int32_t appUnitsPerDevPixel =
         aItem->Frame()->PresContext()->AppUnitsPerDevPixel();
     MOZ_RELEASE_ASSERT(mAppUnitsPerDevPixel == appUnitsPerDevPixel);
     LayoutDeviceRect bounds =
         LayoutDeviceRect::FromAppUnits(mGroupBounds, appUnitsPerDevPixel);
     LayoutDeviceIntPoint offset = RoundedToInt(bounds.TopLeft());
@@ -402,93 +401,82 @@ struct DIGroup {
     GP("pre mInvalidRect: %s %p-%d - inv: %d %d %d %d\n", aItem->Name(),
        aItem->Frame(), aItem->GetPerFrameKey(), mInvalidRect.x, mInvalidRect.y,
        mInvalidRect.width, mInvalidRect.height);
     if (!aData->mGeometry) {
       // This item is being added for the first time, invalidate its entire
       // area.
       UniquePtr<nsDisplayItemGeometry> geometry(
           aItem->AllocateGeometry(aBuilder));
-      combined = clip.ApplyNonRoundedIntersection(
+      nsRect clippedBounds = clip.ApplyNonRoundedIntersection(
           geometry->ComputeInvalidationRegion());
       aData->mGeometry = std::move(geometry);
-      nsRect bounds = combined.GetBounds();
 
       IntRect transformedRect =
-          ToDeviceSpace(combined.GetBounds(), aMatrix, appUnitsPerDevPixel,
+          ToDeviceSpace(clippedBounds, aMatrix, appUnitsPerDevPixel,
                         mLayerBounds.TopLeft());
       aData->mRect = transformedRect.Intersect(mImageBounds);
-      GP("CGC %s %d %d %d %d\n", aItem->Name(), bounds.x, bounds.y,
-         bounds.width, bounds.height);
+      GP("CGC %s %d %d %d %d\n", aItem->Name(), clippedBounds.x,
+         clippedBounds.y, clippedBounds.width, clippedBounds.height);
       GP("%d %d,  %f %f\n", mLayerBounds.TopLeft().x, mLayerBounds.TopLeft().y,
          aMatrix._11, aMatrix._22);
       GP("mRect %d %d %d %d\n", aData->mRect.x, aData->mRect.y,
          aData->mRect.width, aData->mRect.height);
       InvalidateRect(aData->mRect);
       aData->mInvalid = true;
     } else if (aData->mInvalid ||
                /* XXX: handle image load invalidation */ (
                    aItem->IsInvalid(invalid) && invalid.IsEmpty())) {
       MOZ_RELEASE_ASSERT(mLayerBounds.TopLeft() == aData->mGroupOffset);
       UniquePtr<nsDisplayItemGeometry> geometry(
           aItem->AllocateGeometry(aBuilder));
-      /* Instead of doing this dance, let's just invalidate the old rect and the
-       * new rect.
-      combined =
-        aData->mClip.ApplyNonRoundedIntersection(
-          aData->mGeometry->ComputeInvalidationRegion());
-      combined.MoveBy(shift);
-      combined.Or(combined,
-                  clip.ApplyNonRoundedIntersection(
-                    geometry->ComputeInvalidationRegion()));
-      aData->mGeometry = std::move(geometry);
-      */
-      combined = clip.ApplyNonRoundedIntersection(
+      nsRect clippedBounds = clip.ApplyNonRoundedIntersection(
           geometry->ComputeInvalidationRegion());
       aData->mGeometry = std::move(geometry);
 
       GP("matrix: %f %f\n", aMatrix._31, aMatrix._32);
       GP("frame invalid invalidate: %s\n", aItem->Name());
       GP("old rect: %d %d %d %d\n", aData->mRect.x, aData->mRect.y,
          aData->mRect.width, aData->mRect.height);
       InvalidateRect(aData->mRect.Intersect(mImageBounds));
       // We want to snap to outside pixels. When should we multiply by the
       // matrix?
       // XXX: TransformBounds is expensive. We should avoid doing it if we have
       // no transform
       IntRect transformedRect =
-          ToDeviceSpace(combined.GetBounds(), aMatrix, appUnitsPerDevPixel,
+          ToDeviceSpace(clippedBounds, aMatrix, appUnitsPerDevPixel,
                         mLayerBounds.TopLeft());
       aData->mRect = transformedRect.Intersect(mImageBounds);
       InvalidateRect(aData->mRect);
       GP("new rect: %d %d %d %d\n", aData->mRect.x, aData->mRect.y,
          aData->mRect.width, aData->mRect.height);
       aData->mInvalid = true;
     } else {
       MOZ_RELEASE_ASSERT(mLayerBounds.TopLeft() == aData->mGroupOffset);
       GP("else invalidate: %s\n", aItem->Name());
+      nsRegion combined;
       // this includes situations like reflow changing the position
       aItem->ComputeInvalidationRegion(aBuilder, aData->mGeometry.get(),
                                        &combined);
       if (!combined.IsEmpty()) {
         // There might be no point in doing this elaborate tracking here to get
         // smaller areas
         InvalidateRect(aData->mRect.Intersect(
             mImageBounds));  // invalidate the old area -- in theory combined
                              // should take care of this
         UniquePtr<nsDisplayItemGeometry> geometry(
             aItem->AllocateGeometry(aBuilder));
         // invalidate the invalidated area.
 
         aData->mGeometry = std::move(geometry);
 
-        combined = clip.ApplyNonRoundedIntersection(
+        nsRect clippedBounds = clip.ApplyNonRoundedIntersection(
             aData->mGeometry->ComputeInvalidationRegion());
         IntRect transformedRect =
-            ToDeviceSpace(combined.GetBounds(), aMatrix, appUnitsPerDevPixel,
+            ToDeviceSpace(clippedBounds, aMatrix, appUnitsPerDevPixel,
                           mLayerBounds.TopLeft());
         aData->mRect = transformedRect.Intersect(mImageBounds);
         InvalidateRect(aData->mRect);
 
         // CGC invariant broken
         if (!mInvalidRect.Contains(aData->mRect)) {
           gfxCriticalError()
               << "CGC-"
@@ -506,20 +494,20 @@ struct DIGroup {
             // the bounds of layer items can change on us without
             // ComputeInvalidationRegion returning any change. Other items
             // shouldn't have any hidden geometry change.
             MOZ_RELEASE_ASSERT(
                 geometry->mBounds.IsEqualEdges(aData->mGeometry->mBounds));
           } else {
             aData->mGeometry = std::move(geometry);
           }
-          combined = clip.ApplyNonRoundedIntersection(
+          nsRect clippedBounds = clip.ApplyNonRoundedIntersection(
               aData->mGeometry->ComputeInvalidationRegion());
           IntRect transformedRect =
-              ToDeviceSpace(combined.GetBounds(), aMatrix, appUnitsPerDevPixel,
+              ToDeviceSpace(clippedBounds, aMatrix, appUnitsPerDevPixel,
                             mLayerBounds.TopLeft());
           InvalidateRect(aData->mRect.Intersect(mImageBounds));
           aData->mRect = transformedRect.Intersect(mImageBounds);
           InvalidateRect(aData->mRect);
 
           GP("ClipChange: %s %d %d %d %d\n", aItem->Name(), aData->mRect.x,
              aData->mRect.y, aData->mRect.XMost(), aData->mRect.YMost());
 
@@ -536,93 +524,93 @@ struct DIGroup {
           if (!IsContainerLayerItem(aItem)) {
             // the bounds of layer items can change on us
             // other items shouldn't
             MOZ_RELEASE_ASSERT(
                 geometry->mBounds.IsEqualEdges(aData->mGeometry->mBounds));
           } else {
             aData->mGeometry = std::move(geometry);
           }
-          combined = clip.ApplyNonRoundedIntersection(
+          nsRect clippedBounds = clip.ApplyNonRoundedIntersection(
               aData->mGeometry->ComputeInvalidationRegion());
           IntRect transformedRect =
-              ToDeviceSpace(combined.GetBounds(), aMatrix, appUnitsPerDevPixel,
+              ToDeviceSpace(clippedBounds, aMatrix, appUnitsPerDevPixel,
                             mLayerBounds.TopLeft());
           InvalidateRect(aData->mRect.Intersect(mImageBounds));
           aData->mRect = transformedRect.Intersect(mImageBounds);
           InvalidateRect(aData->mRect);
 
           GP("TransformChange: %s %d %d %d %d\n", aItem->Name(), aData->mRect.x,
              aData->mRect.y, aData->mRect.XMost(), aData->mRect.YMost());
         } else if (IsContainerLayerItem(aItem)) {
           UniquePtr<nsDisplayItemGeometry> geometry(
               aItem->AllocateGeometry(aBuilder));
           // we need to catch bounds changes of containers so that we continue
           // to have the correct bounds rects in the recording
           if (UpdateContainerLayerPropertiesAndDetectChange(aItem, aData,
                                                             *geometry)) {
-            combined = clip.ApplyNonRoundedIntersection(
+            nsRect clippedBounds = clip.ApplyNonRoundedIntersection(
                 geometry->ComputeInvalidationRegion());
             aData->mGeometry = std::move(geometry);
             IntRect transformedRect =
-                ToDeviceSpace(combined.GetBounds(), aMatrix,
+                ToDeviceSpace(clippedBounds, aMatrix,
                               appUnitsPerDevPixel, mLayerBounds.TopLeft());
             InvalidateRect(aData->mRect.Intersect(mImageBounds));
             aData->mRect = transformedRect.Intersect(mImageBounds);
             InvalidateRect(aData->mRect);
             GP("UpdateContainerLayerPropertiesAndDetectChange change\n");
           } else if (!aData->mImageRect.IsEqualEdges(mImageBounds)) {
             // Make sure we update mRect for mImageBounds changes
-            combined = clip.ApplyNonRoundedIntersection(
+            nsRect clippedBounds = clip.ApplyNonRoundedIntersection(
                 geometry->ComputeInvalidationRegion());
             IntRect transformedRect =
-                ToDeviceSpace(combined.GetBounds(), aMatrix,
+                ToDeviceSpace(clippedBounds, aMatrix,
                               appUnitsPerDevPixel, mLayerBounds.TopLeft());
             // The invalid rect should contain the old rect and the new rect
             // but may not because the parent may have been removed.
             InvalidateRect(aData->mRect);
             aData->mRect = transformedRect.Intersect(mImageBounds);
             InvalidateRect(aData->mRect);
             GP("ContainerLayer image rect bounds change\n");
           } else {
             // XXX: this code can eventually be deleted/made debug only
-            combined = clip.ApplyNonRoundedIntersection(
+            nsRect clippedBounds = clip.ApplyNonRoundedIntersection(
                 geometry->ComputeInvalidationRegion());
             IntRect transformedRect =
-                ToDeviceSpace(combined.GetBounds(), aMatrix,
+                ToDeviceSpace(clippedBounds, aMatrix,
                               appUnitsPerDevPixel, mLayerBounds.TopLeft());
             auto rect = transformedRect.Intersect(mImageBounds);
             GP("Layer NoChange: %s %d %d %d %d\n", aItem->Name(),
                aData->mRect.x, aData->mRect.y, aData->mRect.XMost(),
                aData->mRect.YMost());
             MOZ_RELEASE_ASSERT(rect.IsEqualEdges(aData->mRect));
           }
         } else if (!aData->mImageRect.IsEqualEdges(mImageBounds)) {
           // Make sure we update mRect for mImageBounds changes
           UniquePtr<nsDisplayItemGeometry> geometry(
               aItem->AllocateGeometry(aBuilder));
-          combined = clip.ApplyNonRoundedIntersection(
+          nsRect clippedBounds = clip.ApplyNonRoundedIntersection(
               geometry->ComputeInvalidationRegion());
           IntRect transformedRect =
-              ToDeviceSpace(combined.GetBounds(), aMatrix, appUnitsPerDevPixel,
+              ToDeviceSpace(clippedBounds, aMatrix, appUnitsPerDevPixel,
                             mLayerBounds.TopLeft());
           // The invalid rect should contain the old rect and the new rect
           // but may not because the parent may have been removed.
           InvalidateRect(aData->mRect);
           aData->mRect = transformedRect.Intersect(mImageBounds);
           InvalidateRect(aData->mRect);
           GP("image rect bounds change\n");
         } else {
           // XXX: this code can eventually be deleted/made debug only
           UniquePtr<nsDisplayItemGeometry> geometry(
               aItem->AllocateGeometry(aBuilder));
-          combined = clip.ApplyNonRoundedIntersection(
+          nsRect clippedBounds = clip.ApplyNonRoundedIntersection(
               geometry->ComputeInvalidationRegion());
           IntRect transformedRect =
-              ToDeviceSpace(combined.GetBounds(), aMatrix, appUnitsPerDevPixel,
+              ToDeviceSpace(clippedBounds, aMatrix, appUnitsPerDevPixel,
                             mLayerBounds.TopLeft());
           auto rect = transformedRect.Intersect(mImageBounds);
           GP("NoChange: %s %d %d %d %d\n", aItem->Name(), aData->mRect.x,
              aData->mRect.y, aData->mRect.XMost(), aData->mRect.YMost());
           MOZ_RELEASE_ASSERT(rect.IsEqualEdges(aData->mRect));
         }
       }
     }