From 680c0cb73c341c8e3c1db839293cdc787afd0f7d Mon Sep 17 00:00:00 2001 From: Timothy Nikkel Date: Tue, 30 Jul 2013 11:22:43 -0500 Subject: [PATCH] Bug 837242. Part 2. Add a function to calculate the area of an nsRegion. r=roc --- gfx/src/nsRegion.cpp | 12 ++++++++++++ gfx/src/nsRegion.h | 1 + layout/base/nsDisplayList.cpp | 13 +------------ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/gfx/src/nsRegion.cpp b/gfx/src/nsRegion.cpp index 4015c587f75d..5e8e3ec2b2a2 100644 --- a/gfx/src/nsRegion.cpp +++ b/gfx/src/nsRegion.cpp @@ -1275,6 +1275,18 @@ bool nsRegion::IsEqual (const nsRegion& aRegion) const } +uint64_t nsRegion::Area () const +{ + uint64_t area = 0; + nsRegionRectIterator iter(*this); + const nsRect* r; + while ((r = iter.Next()) != nullptr) { + area += uint64_t(r->width)*r->height; + } + return area; +} + + void nsRegion::MoveBy (nsPoint aPt) { if (aPt.x || aPt.y) diff --git a/gfx/src/nsRegion.h b/gfx/src/nsRegion.h index 2830cbe2290d..bd4de4139d97 100644 --- a/gfx/src/nsRegion.h +++ b/gfx/src/nsRegion.h @@ -147,6 +147,7 @@ public: bool IsEqual (const nsRegion& aRegion) const; uint32_t GetNumRects () const { return mRectCount; } const nsRect& GetBounds () const { return mBoundRect; } + uint64_t Area () const; // Converts this region from aFromAPP, an appunits per pixel ratio, to // aToAPP. This applies nsRect::ConvertAppUnitsRoundOut/In to each rect of // the region. diff --git a/layout/base/nsDisplayList.cpp b/layout/base/nsDisplayList.cpp index a778a0c07965..5464e1b675c5 100644 --- a/layout/base/nsDisplayList.cpp +++ b/layout/base/nsDisplayList.cpp @@ -718,17 +718,6 @@ nsDisplayListBuilder::GetBackgroundPaintFlags() { return flags; } -static uint64_t RegionArea(const nsRegion& aRegion) -{ - uint64_t area = 0; - nsRegionRectIterator iter(aRegion); - const nsRect* r; - while ((r = iter.Next()) != nullptr) { - area += uint64_t(r->width)*r->height; - } - return area; -} - void nsDisplayListBuilder::SubtractFromVisibleRegion(nsRegion* aVisibleRegion, const nsRegion& aRegion) @@ -743,7 +732,7 @@ nsDisplayListBuilder::SubtractFromVisibleRegion(nsRegion* aVisibleRegion, // Do let aVisibleRegion get more complex if by doing so we reduce its // area by at least half. if (GetAccurateVisibleRegions() || tmp.GetNumRects() <= 15 || - RegionArea(tmp) <= RegionArea(*aVisibleRegion)/2) { + tmp.Area() <= aVisibleRegion->Area()/2) { *aVisibleRegion = tmp; } }