Bug 1262807 - Change the heuristic at which the TiledRegion collapses down to a single rect. r?mstange
MozReview-Commit-ID: JYeOC8J8tSB
--- a/gfx/src/TiledRegion.cpp
+++ b/gfx/src/TiledRegion.cpp
@@ -9,16 +9,17 @@
#include <algorithm>
#include "mozilla/fallible.h"
namespace mozilla {
namespace gfx {
static const int32_t kTileSize = 256;
+static const size_t kMaxTiles = 100;
/**
* TiledRegionImpl stores an array of non-empty rectangles (pixman_box32_ts) to
* represent the region. Each rectangle is contained in a single tile;
* rectangles never cross tile boundaries. The rectangles are sorted by their
* tile's origin in top-to-bottom, left-to-right order.
* (Note that this can mean that a rectangle r1 can come before another
* rectangle r2 even if r2.y1 < r1.y1, as long as the two rects are in the same
@@ -277,17 +278,17 @@ TiledRegionImpl::AddRect(const pixman_bo
{
// We are adding a rectangle that can span multiple tiles.
// For each empty tile that aRect intersects, we need to add the intersection
// of aRect with that tile to mRects, respecting the order of mRects.
// For each tile that already has a rectangle, we need to enlarge that
// existing rectangle to include the intersection of aRect with the tile.
return ProcessIntersectedTiles(aRect, mRects,
[&aRect](nsTArray<pixman_box32_t>& rects, size_t& rectIndex, TileRange emptyTiles) {
- if (!rects.InsertElementsAt(rectIndex, emptyTiles.Length(), fallible)) {
+ if (rects.Length() >= kMaxTiles || !rects.InsertElementsAt(rectIndex, emptyTiles.Length(), fallible)) {
return IterationAction::STOP;
}
for (TileIterator tileIt = emptyTiles.Begin();
tileIt != emptyTiles.End();
++tileIt, ++rectIndex) {
rects[rectIndex] = tileIt.IntersectionWith(aRect);
}
return IterationAction::CONTINUE;
--- a/gfx/src/TiledRegion.h
+++ b/gfx/src/TiledRegion.h
@@ -89,37 +89,29 @@ public:
return;
}
mBounds = mBounds.Union(aRect);
if (mCoversBounds) {
return;
}
- if (ExceedsMaximumSize()) {
- FallBackToBounds();
- return;
- }
if (!mImpl.AddRect(RectToBox(aRect))) {
FallBackToBounds();
}
}
void Add(const RegionT& aRegion)
{
mBounds = mBounds.Union(aRegion.GetBounds());
if (mCoversBounds) {
return;
}
- if (ExceedsMaximumSize()) {
- FallBackToBounds();
- return;
- }
for (auto iter = aRegion.RectIter(); !iter.Done(); iter.Next()) {
RectT r = iter.Get();
MOZ_ASSERT(!r.IsEmpty());
if (!mImpl.AddRect(RectToBox(r))) {
FallBackToBounds();
return;
}
@@ -158,22 +150,16 @@ public:
if (mCoversBounds) {
return true;
}
return mImpl.Contains(RectToBox(aRect));
}
private:
- bool ExceedsMaximumSize() const
- {
- // This stops us from allocating insane numbers of tiles.
- return mBounds.width >= 50 * 256 || mBounds.height >= 50 * 256;
- }
-
void FallBackToBounds()
{
mCoversBounds = true;
mImpl.Clear();
}
static pixman_box32_t RectToBox(const RectT& aRect)
{