Bug 1239864 (part 10) - Use the new rect iterators in view/ and widget/. r=roc.
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 18 Jan 2016 17:20:59 -0800
changeset 281960 3b02ba9cfc4f686b6d485c729c31c02e2477b611
parent 281959 ffd9ee1eb392f4ff24092186309adf1b22daf063
child 281961 e671b94aac73632dc50dcb12ef26fb1045d672dd
push id70991
push usernnethercote@mozilla.com
push dateWed, 27 Jan 2016 22:25:12 +0000
treeherdermozilla-inbound@e671b94aac73 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1239864
milestone47.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 1239864 (part 10) - Use the new rect iterators in view/ and widget/. r=roc.
view/nsViewManager.cpp
widget/PuppetWidget.cpp
widget/cocoa/VibrancyManager.mm
widget/cocoa/nsChildView.mm
widget/gonk/HwcUtils.cpp
widget/nsBaseWidget.cpp
widget/nsShmImage.cpp
widget/uikit/nsWindow.mm
--- a/view/nsViewManager.cpp
+++ b/view/nsViewManager.cpp
@@ -601,19 +601,18 @@ nsViewManager::InvalidateWidgetArea(nsVi
       }
     }
   }
 
   nsRegion leftOver;
   leftOver.Sub(aDamagedRegion, children);
 
   if (!leftOver.IsEmpty()) {
-    const nsRect* r;
-    for (nsRegionRectIterator iter(leftOver); (r = iter.Next());) {
-      LayoutDeviceIntRect bounds = ViewToWidget(aWidgetView, *r);
+    for (auto iter = leftOver.RectIter(); !iter.Done(); iter.Next()) {
+      LayoutDeviceIntRect bounds = ViewToWidget(aWidgetView, iter.Get());
       widget->Invalidate(bounds);
     }
   }
 }
 
 static bool
 ShouldIgnoreInvalidation(nsViewManager* aVM)
 {
--- a/widget/PuppetWidget.cpp
+++ b/widget/PuppetWidget.cpp
@@ -27,19 +27,18 @@ using namespace mozilla::dom;
 using namespace mozilla::hal;
 using namespace mozilla::gfx;
 using namespace mozilla::layers;
 using namespace mozilla::widget;
 
 static void
 InvalidateRegion(nsIWidget* aWidget, const LayoutDeviceIntRegion& aRegion)
 {
-  LayoutDeviceIntRegion::OldRectIterator it(aRegion);
-  while(const LayoutDeviceIntRect* r = it.Next()) {
-    aWidget->Invalidate(*r);
+  for (auto iter = aRegion.RectIter(); !iter.Done(); iter.Next()) {
+    aWidget->Invalidate(iter.Get());
   }
 }
 
 /*static*/ already_AddRefed<nsIWidget>
 nsIWidget::CreatePuppetWidget(TabChild* aTabChild)
 {
   MOZ_ASSERT(!aTabChild || nsIWidget::UsePuppetWidgets(),
              "PuppetWidgets not allowed in this configuration");
--- a/widget/cocoa/VibrancyManager.mm
+++ b/widget/cocoa/VibrancyManager.mm
@@ -23,35 +23,37 @@ VibrancyManager::UpdateVibrantRegion(Vib
   // as necessary. We try to update the geometry of existing views if
   // possible, or create new ones or remove old ones if the number of
   // rects in the region has changed.
 
   nsTArray<NSView*> viewsToRecycle;
   vr.effectViews.SwapElements(viewsToRecycle);
   // vr.effectViews is now empty.
 
-  LayoutDeviceIntRegion::OldRectIterator iter(aRegion);
-  const LayoutDeviceIntRect* iterRect = nullptr;
-  for (size_t i = 0; (iterRect = iter.Next()) || i < viewsToRecycle.Length(); ++i) {
-    if (iterRect) {
+  size_t i = 0;
+  for (auto iter = aRegion.RectIter();
+       !iter.Done() || i < viewsToRecycle.Length();
+       i++) {
+    if (!iter.Done()) {
       NSView* view = nil;
-      NSRect rect = mCoordinateConverter.DevPixelsToCocoaPoints(*iterRect);
+      NSRect rect = mCoordinateConverter.DevPixelsToCocoaPoints(iter.Get());
       if (i < viewsToRecycle.Length()) {
         view = viewsToRecycle[i];
         [view setFrame:rect];
         [view setNeedsDisplay:YES];
       } else {
         view = CreateEffectView(aType, rect);
         [mContainerView addSubview:view];
 
         // Now that the view is in the view hierarchy, it'll be kept alive by
         // its superview, so we can drop our reference.
         [view release];
       }
       vr.effectViews.AppendElement(view);
+      iter.Next();
     } else {
       // Our new region is made of less rects than the old region, so we can
       // remove this view. We only have a weak reference to it, so removing it
       // from the view hierarchy will release it.
       [viewsToRecycle[i] removeFromSuperview];
     }
   }
 
@@ -66,19 +68,18 @@ VibrancyManager::ClearVibrantAreas() con
   }
 }
 
 void
 VibrancyManager::ClearVibrantRegion(const VibrantRegion& aVibrantRegion) const
 {
   [[NSColor clearColor] set];
 
-  LayoutDeviceIntRegion::OldRectIterator iter(aVibrantRegion.region);
-  while (const LayoutDeviceIntRect* rect = iter.Next()) {
-    NSRectFill(mCoordinateConverter.DevPixelsToCocoaPoints(*rect));
+  for (auto iter = aVibrantRegion.region.RectIter(); !iter.Done(); iter.Next()) {
+    NSRectFill(mCoordinateConverter.DevPixelsToCocoaPoints(iter.Get()));
   }
 }
 
 @interface NSView(CurrentFillColor)
 - (NSColor*)_currentFillColor;
 @end
 
 static NSColor*
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -3748,23 +3748,20 @@ NSEvent* gLastDragMouseDownEvent = nil;
     gfx::Factory::CreateDrawTargetForCairoCGContext(aContext,
                                                     gfx::IntSize(backingSize.width,
                                                                  backingSize.height));
   MOZ_ASSERT(dt); // see implementation
   dt->AddUserData(&gfxContext::sDontUseAsSourceKey, dt, nullptr);
   RefPtr<gfxContext> targetContext = new gfxContext(dt);
 
   // Set up the clip region.
-  LayoutDeviceIntRegion::OldRectIterator iter(region);
   targetContext->NewPath();
-  for (;;) {
-    const LayoutDeviceIntRect* r = iter.Next();
-    if (!r)
-      break;
-    targetContext->Rectangle(gfxRect(r->x, r->y, r->width, r->height));
+  for (auto iter = region.RectIter(); !iter.Done(); iter.Next()) {
+    const LayoutDeviceIntRect& r = iter.Get();
+    targetContext->Rectangle(gfxRect(r.x, r.y, r.width, r.height));
   }
   targetContext->Clip();
 
   nsAutoRetainCocoaObject kungFuDeathGrip(self);
   bool painted = false;
   if (mGeckoChild->GetLayerManager()->GetBackendType() == LayersBackend::LAYERS_BASIC) {
     nsBaseWidget::AutoLayerManagerSetup
       setupLayerManager(mGeckoChild, targetContext, BufferMode::BUFFER_NONE);
@@ -4627,23 +4624,18 @@ NSEvent* gLastDragMouseDownEvent = nil;
   return NSRectToCGRect(inWindowCoords);
 }
 
 static CGSRegionObj
 NewCGSRegionFromRegion(const LayoutDeviceIntRegion& aRegion,
                        CGRect (^aRectConverter)(const LayoutDeviceIntRect&))
 {
   nsTArray<CGRect> rects;
-  LayoutDeviceIntRegion::OldRectIterator iter(aRegion);
-  for (;;) {
-    const LayoutDeviceIntRect* r = iter.Next();
-    if (!r) {
-      break;
-    }
-    rects.AppendElement(aRectConverter(*r));
+  for (auto iter = aRegion.RectIter(); !iter.Done(); iter.Next()) {
+    rects.AppendElement(aRectConverter(iter.Get()));
   }
 
   CGSRegionObj region;
   CGSNewRegionWithRectList(rects.Elements(), rects.Length(), &region);
   return region;
 }
 
 // This function is called with forMove:YES to calculate the draggable region
--- a/widget/gonk/HwcUtils.cpp
+++ b/widget/gonk/HwcUtils.cpp
@@ -102,29 +102,29 @@ HwcUtils::PrepareVisibleRegion(const nsI
     const float MIN_SRC_HEIGHT = 2.f;
 
     gfxMatrix layerTransform = gfx::ThebesMatrix(aLayerTransform);
     gfxMatrix layerBufferTransform = gfx::ThebesMatrix(aLayerBufferTransform);
     gfxRect bufferRect =
         layerBufferTransform.TransformBounds(ThebesRect(aBufferRect));
     gfxMatrix inverse = gfx::ThebesMatrix(aLayerBufferTransform);
     inverse.Invert();
-    nsIntRegionRectIterator rect(aVisible);
     aIsVisible = false;
-    while (const nsIntRect* visibleRect = rect.Next()) {
-        hwc_rect_t visibleRectScreen;
-        gfxRect screenRect;
 
-        screenRect = layerTransform.TransformBounds(ThebesRect(*visibleRect));
+    for (auto iter = aVisible.RectIter(); !iter.Done(); iter.Next()) {
+        gfxRect screenRect =
+          layerTransform.TransformBounds(ThebesRect(iter.Get()));
         screenRect.IntersectRect(screenRect, bufferRect);
         screenRect.IntersectRect(screenRect, ThebesRect(aClip));
         screenRect.Round();
         if (screenRect.IsEmpty()) {
             continue;
         }
+
+        hwc_rect_t visibleRectScreen;
         visibleRectScreen.left = screenRect.x;
         visibleRectScreen.top  = screenRect.y;
         visibleRectScreen.right  = screenRect.XMost();
         visibleRectScreen.bottom = screenRect.YMost();
 
         gfxRect srcCrop = inverse.TransformBounds(screenRect);
         // When src crop is very small, HWC could not render correctly in some cases.
         // See Bug 1169093
--- a/widget/nsBaseWidget.cpp
+++ b/widget/nsBaseWidget.cpp
@@ -752,19 +752,18 @@ nsBaseWidget::RegionFromArray(const nsTA
   }
   return region;
 }
 
 void
 nsBaseWidget::ArrayFromRegion(const LayoutDeviceIntRegion& aRegion,
                               nsTArray<LayoutDeviceIntRect>& aRects)
 {
-  const LayoutDeviceIntRect* r;
-  for (LayoutDeviceIntRegion::OldRectIterator iter(aRegion); (r = iter.Next()); ) {
-    aRects.AppendElement(*r);
+  for (auto iter = aRegion.RectIter(); !iter.Done(); iter.Next()) {
+    aRects.AppendElement(iter.Get());
   }
 }
 
 nsresult
 nsBaseWidget::SetWindowClipRegion(const nsTArray<LayoutDeviceIntRect>& aRects,
                                   bool aIntersectWithExisting)
 {
   if (!aIntersectWithExisting) {
--- a/widget/nsShmImage.cpp
+++ b/widget/nsShmImage.cpp
@@ -137,22 +137,22 @@ nsShmImage::CreateDrawTarget()
 void
 nsShmImage::Put(Display* aDisplay, Drawable aWindow,
                 const LayoutDeviceIntRegion& aRegion)
 {
     GC gc = XCreateGC(aDisplay, aWindow, 0, nullptr);
     LayoutDeviceIntRegion bounded;
     bounded.And(aRegion,
                 LayoutDeviceIntRect(0, 0, mImage->width, mImage->height));
-    LayoutDeviceIntRegion::OldRectIterator iter(bounded);
-    for (const LayoutDeviceIntRect *r = iter.Next(); r; r = iter.Next()) {
+    for (auto iter = bounded.RectIter(); !iter.Done(); iter.Next()) {
+        const LayoutDeviceIntRect& r = iter.Get();
         XShmPutImage(aDisplay, aWindow, gc, mImage,
-                     r->x, r->y,
-                     r->x, r->y,
-                     r->width, r->height,
+                     r.x, r.y,
+                     r.x, r.y,
+                     r.width, r.height,
                      False);
     }
 
     XFreeGC(aDisplay, gc);
 
     // FIXME/bug 597336: we need to ensure that the shm image isn't
     // scribbled over before all its pending XShmPutImage()s complete.
     // However, XSync() is an unnecessarily heavyweight
--- a/widget/uikit/nsWindow.mm
+++ b/widget/uikit/nsWindow.mm
@@ -372,23 +372,20 @@ private:
                                                                           backingSize.height));
     dt->AddUserData(&gfxContext::sDontUseAsSourceKey, dt, nullptr);
     targetContext = new gfxContext(dt);
   } else {
     MOZ_ASSERT_UNREACHABLE("COREGRAPHICS is the only supported backed");
   }
 
   // Set up the clip region.
-  LayoutDeviceIntRegion::OldRectIterator iter(region);
   targetContext->NewPath();
-  for (;;) {
-    const LayoutDeviceIntRect* r = iter.Next();
-    if (!r)
-      break;
-    targetContext->Rectangle(gfxRect(r->x, r->y, r->width, r->height));
+  for (auto iter = region.RectIter(); !iter.Done(); iter.Next()) {
+    const LayoutDeviceIntRect& r = iter.Get();
+    targetContext->Rectangle(gfxRect(r.x, r.y, r.width, r.height));
   }
   targetContext->Clip();
 
   //nsAutoRetainCocoaObject kungFuDeathGrip(self);
   bool painted = false;
   if (mGeckoChild->GetLayerManager()->GetBackendType() == LayersBackend::LAYERS_BASIC) {
     nsBaseWidget::AutoLayerManagerSetup
       setupLayerManager(mGeckoChild, targetContext, BufferMode::BUFFER_NONE);