Bug 1239864 (part 2) - Use the new rect iterators in nsRegion.cpp. r=roc.

This commit is contained in:
Nicholas Nethercote 2016-01-14 21:47:16 -08:00
parent 9f7e90ef15
commit 930b809f01

View File

@ -12,9 +12,8 @@ bool nsRegion::Contains(const nsRegion& aRgn) const
{ {
// XXX this could be made faster by iterating over // XXX this could be made faster by iterating over
// both regions at the same time some how // both regions at the same time some how
nsRegionRectIterator iter(aRgn); for (auto iter = aRgn.RectIter(); !iter.Done(); iter.Next()) {
while (const nsRect* r = iter.Next()) { if (!Contains(iter.Get())) {
if (!Contains (*r)) {
return false; return false;
} }
} }
@ -24,9 +23,8 @@ bool nsRegion::Contains(const nsRegion& aRgn) const
bool nsRegion::Intersects(const nsRect& aRect) const bool nsRegion::Intersects(const nsRect& aRect) const
{ {
// XXX this could be made faster by using pixman_region32_contains_rect // XXX this could be made faster by using pixman_region32_contains_rect
nsRegionRectIterator iter(*this); for (auto iter = RectIter(); !iter.Done(); iter.Next()) {
while (const nsRect* r = iter.Next()) { if (iter.Get().Intersects(aRect)) {
if (r->Intersects(aRect)) {
return true; return true;
} }
} }
@ -555,10 +553,9 @@ void nsRegion::SimplifyInward (uint32_t aMaxRects)
uint64_t nsRegion::Area () const uint64_t nsRegion::Area () const
{ {
uint64_t area = 0; uint64_t area = 0;
nsRegionRectIterator iter(*this); for (auto iter = RectIter(); !iter.Done(); iter.Next()) {
const nsRect* r; const nsRect& rect = iter.Get();
while ((r = iter.Next()) != nullptr) { area += uint64_t(rect.width) * rect.height;
area += uint64_t(r->width)*r->height;
} }
return area; return area;
} }
@ -730,11 +727,9 @@ nsIntRegion nsRegion::ScaleToNearestPixels (float aScaleX, float aScaleY,
nscoord aAppUnitsPerPixel) const nscoord aAppUnitsPerPixel) const
{ {
nsIntRegion result; nsIntRegion result;
nsRegionRectIterator rgnIter(*this); for (auto iter = RectIter(); !iter.Done(); iter.Next()) {
const nsRect* currentRect;
while ((currentRect = rgnIter.Next())) {
mozilla::gfx::IntRect deviceRect = mozilla::gfx::IntRect deviceRect =
currentRect->ScaleToNearestPixels(aScaleX, aScaleY, aAppUnitsPerPixel); iter.Get().ScaleToNearestPixels(aScaleX, aScaleY, aAppUnitsPerPixel);
result.Or(result, deviceRect); result.Or(result, deviceRect);
} }
return result; return result;
@ -744,11 +739,9 @@ nsIntRegion nsRegion::ScaleToOutsidePixels (float aScaleX, float aScaleY,
nscoord aAppUnitsPerPixel) const nscoord aAppUnitsPerPixel) const
{ {
nsIntRegion result; nsIntRegion result;
nsRegionRectIterator rgnIter(*this); for (auto iter = RectIter(); !iter.Done(); iter.Next()) {
const nsRect* currentRect;
while ((currentRect = rgnIter.Next())) {
mozilla::gfx::IntRect deviceRect = mozilla::gfx::IntRect deviceRect =
currentRect->ScaleToOutsidePixels(aScaleX, aScaleY, aAppUnitsPerPixel); iter.Get().ScaleToOutsidePixels(aScaleX, aScaleY, aAppUnitsPerPixel);
result.Or(result, deviceRect); result.Or(result, deviceRect);
} }
return result; return result;
@ -1027,13 +1020,12 @@ nsRect nsRegion::GetLargestRectangle (const nsRect& aContainingRect) const {
AxisPartition xaxis, yaxis; AxisPartition xaxis, yaxis;
// Step 1: Calculate the grid lines // Step 1: Calculate the grid lines
nsRegionRectIterator iter(*this); for (auto iter = RectIter(); !iter.Done(); iter.Next()) {
const nsRect *currentRect; const nsRect& rect = iter.Get();
while ((currentRect = iter.Next())) { xaxis.InsertCoord(rect.x);
xaxis.InsertCoord(currentRect->x); xaxis.InsertCoord(rect.XMost());
xaxis.InsertCoord(currentRect->XMost()); yaxis.InsertCoord(rect.y);
yaxis.InsertCoord(currentRect->y); yaxis.InsertCoord(rect.YMost());
yaxis.InsertCoord(currentRect->YMost());
} }
if (!aContainingRect.IsEmpty()) { if (!aContainingRect.IsEmpty()) {
xaxis.InsertCoord(aContainingRect.x); xaxis.InsertCoord(aContainingRect.x);
@ -1051,19 +1043,19 @@ nsRect nsRegion::GetLargestRectangle (const nsRect& aContainingRect) const {
nsTArray<SizePair> areas(matrixSize); nsTArray<SizePair> areas(matrixSize);
areas.SetLength(matrixSize); areas.SetLength(matrixSize);
iter.Reset(); for (auto iter = RectIter(); !iter.Done(); iter.Next()) {
while ((currentRect = iter.Next())) { const nsRect& rect = iter.Get();
int32_t xstart = xaxis.IndexOf(currentRect->x); int32_t xstart = xaxis.IndexOf(rect.x);
int32_t xend = xaxis.IndexOf(currentRect->XMost()); int32_t xend = xaxis.IndexOf(rect.XMost());
int32_t y = yaxis.IndexOf(currentRect->y); int32_t y = yaxis.IndexOf(rect.y);
int32_t yend = yaxis.IndexOf(currentRect->YMost()); int32_t yend = yaxis.IndexOf(rect.YMost());
for (; y < yend; y++) { for (; y < yend; y++) {
nscoord height = yaxis.StopSize(y); nscoord height = yaxis.StopSize(y);
for (int32_t x = xstart; x < xend; x++) { for (int32_t x = xstart; x < xend; x++) {
nscoord width = xaxis.StopSize(x); nscoord width = xaxis.StopSize(x);
int64_t size = width*int64_t(height); int64_t size = width*int64_t(height);
if (currentRect->Intersects(aContainingRect)) { if (rect.Intersects(aContainingRect)) {
areas[y*matrixWidth+x].mSizeContainingRect = size; areas[y*matrixWidth+x].mSizeContainingRect = size;
} }
areas[y*matrixWidth+x].mSize = size; areas[y*matrixWidth+x].mSize = size;