Bug 837242. Part 2. Add a function to calculate the area of an nsRegion. r=roc

This commit is contained in:
Timothy Nikkel 2013-07-30 11:22:43 -05:00
parent 7d3be384bc
commit 680c0cb73c
3 changed files with 14 additions and 12 deletions

View File

@ -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)

View File

@ -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.

View File

@ -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;
}
}