Bug 1239864 (part 1) - Add new, nicer rect-iterators for nsRegion and nsIntRegion. r=roc.

This requires renaming the existing nsIntRegion::RectIterator as
nsIntRegion::OldRectIterator to make way for the new nsIntRegion::RectIterator.
This doesn't require many knock-on changes because most existing uses of
that type use the nsIntRegionRectIterator typedef.

--HG--
extra : rebase_source : 16c79610ae20820ead6aa63cbe214e4e4b3a9fab
This commit is contained in:
Nicholas Nethercote 2016-01-14 18:36:11 -08:00
Родитель 2548ea3c35
Коммит 6a194c8cf8
11 изменённых файлов: 79 добавлений и 16 удалений

Просмотреть файл

@ -393,7 +393,7 @@ template<class Units>
struct ParamTraits<mozilla::gfx::IntRegionTyped<Units>>
: RegionParamTraits<mozilla::gfx::IntRegionTyped<Units>,
mozilla::gfx::IntRectTyped<Units>,
typename mozilla::gfx::IntRegionTyped<Units>::RectIterator>
typename mozilla::gfx::IntRegionTyped<Units>::OldRectIterator>
{};
template<>

Просмотреть файл

@ -102,7 +102,7 @@ AppendToString(std::stringstream& aStream, const mozilla::gfx::IntRegionTyped<un
aStream << pfx;
typename RegionType::RectIterator it(r);
typename RegionType::OldRectIterator it(r);
aStream << "< ";
while (const typename RegionType::RectType* sr = it.Next()) {
AppendToString(aStream, *sr);

Просмотреть файл

@ -626,7 +626,7 @@ BasicCompositor::EndFrame()
// The source DrawTarget is clipped to the invalidation region, so we have
// to copy the individual rectangles in the region or else we'll draw blank
// pixels.
LayoutDeviceIntRegion::RectIterator iter(mInvalidRegion);
LayoutDeviceIntRegion::OldRectIterator iter(mInvalidRegion);
for (const LayoutDeviceIntRect *r = iter.Next(); r; r = iter.Next()) {
dest->CopySurface(source,
IntRect(r->x - mInvalidRect.x, r->y - mInvalidRect.y, r->width, r->height),

Просмотреть файл

@ -234,7 +234,7 @@ static void CalculatePluginClip(const LayoutDeviceIntRect& aBounds,
}
// shift to plugin widget origin
contentVisibleRegion.MoveBy(-aBounds.x, -aBounds.y);
LayoutDeviceIntRegion::RectIterator iter(contentVisibleRegion);
LayoutDeviceIntRegion::OldRectIterator iter(contentVisibleRegion);
for (const LayoutDeviceIntRect* rgnRect = iter.Next(); rgnRect; rgnRect = iter.Next()) {
aResult.AppendElement(*rgnRect);
aVisibleBounds.UnionRect(aVisibleBounds, *rgnRect);

Просмотреть файл

@ -351,6 +351,45 @@ public:
void VisitEdges(visitFn, void *closure);
nsCString ToString() const;
class RectIterator
{
int mCurrent; // Index of the current entry
int mLimit; // Index one past the final entry.
mutable nsRect mTmp; // The most recently gotten rectangle.
pixman_box32_t *mBoxes;
public:
explicit RectIterator(const nsRegion& aRegion)
{
mCurrent = 0;
mBoxes = pixman_region32_rectangles(aRegion.Impl(), &mLimit);
// Work around pixman bug. Sometimes pixman creates regions with 1 rect
// that's empty.
if (mLimit == 1 && nsRegion::BoxToRect(mBoxes[0]).IsEmpty()) {
mLimit = 0;
}
}
bool Done() const { return mCurrent == mLimit; }
const nsRect& Get() const
{
MOZ_ASSERT(!Done());
mTmp = nsRegion::BoxToRect(mBoxes[mCurrent]);
NS_ASSERTION(!mTmp.IsEmpty(), "Shouldn't return empty rect");
return mTmp;
}
void Next()
{
MOZ_ASSERT(!Done());
mCurrent++;
}
};
RectIterator RectIter() const { return RectIterator(*this); }
private:
pixman_region32_t mImpl;
@ -701,7 +740,7 @@ public:
nsRegion ToAppUnits (nscoord aAppUnitsPerPixel) const
{
nsRegion result;
RectIterator rgnIter(*this);
OldRectIterator rgnIter(*this);
const Rect* currentRect;
while ((currentRect = rgnIter.Next())) {
nsRect appRect = ::ToAppUnits(*currentRect, aAppUnitsPerPixel);
@ -768,13 +807,14 @@ public:
nsCString ToString() const { return mImpl.ToString(); }
class RectIterator
// XXX: this is going away soon in favour of RectIterator
class OldRectIterator
{
nsRegionRectIterator mImpl;
Rect mTmp;
public:
explicit RectIterator (const BaseIntRegion& aRegion) : mImpl (aRegion.mImpl) {}
explicit OldRectIterator (const BaseIntRegion& aRegion) : mImpl (aRegion.mImpl) {}
const Rect* Next ()
{
@ -800,6 +840,29 @@ public:
}
};
class RectIterator
{
nsRegion::RectIterator mImpl; // The underlying iterator.
mutable Rect mTmp; // The most recently gotten rectangle.
public:
explicit RectIterator(const BaseIntRegion& aRegion)
: mImpl(aRegion.mImpl)
{}
bool Done() const { return mImpl.Done(); }
const Rect& Get() const
{
mTmp = FromRect(mImpl.Get());
return mTmp;
}
void Next() { mImpl.Next(); }
};
RectIterator RectIter() const { return RectIterator(*this); }
protected:
// Expose enough to derived classes from them to define conversions
// between different types of BaseIntRegions.
@ -875,6 +938,6 @@ private:
} // namespace mozilla
typedef mozilla::gfx::IntRegion nsIntRegion;
typedef nsIntRegion::RectIterator nsIntRegionRectIterator;
typedef nsIntRegion::OldRectIterator nsIntRegionRectIterator;
#endif

Просмотреть файл

@ -32,7 +32,7 @@ using namespace mozilla::widget;
static void
InvalidateRegion(nsIWidget* aWidget, const LayoutDeviceIntRegion& aRegion)
{
LayoutDeviceIntRegion::RectIterator it(aRegion);
LayoutDeviceIntRegion::OldRectIterator it(aRegion);
while(const LayoutDeviceIntRect* r = it.Next()) {
aWidget->Invalidate(*r);
}

Просмотреть файл

@ -28,7 +28,7 @@ VibrancyManager::UpdateVibrantRegion(VibrancyType aType,
vr.effectViews.SwapElements(viewsToRecycle);
// vr.effectViews is now empty.
LayoutDeviceIntRegion::RectIterator iter(aRegion);
LayoutDeviceIntRegion::OldRectIterator iter(aRegion);
const LayoutDeviceIntRect* iterRect = nullptr;
for (size_t i = 0; (iterRect = iter.Next()) || i < viewsToRecycle.Length(); ++i) {
if (iterRect) {
@ -71,7 +71,7 @@ VibrancyManager::ClearVibrantRegion(const VibrantRegion& aVibrantRegion) const
{
[[NSColor clearColor] set];
LayoutDeviceIntRegion::RectIterator iter(aVibrantRegion.region);
LayoutDeviceIntRegion::OldRectIterator iter(aVibrantRegion.region);
while (const LayoutDeviceIntRect* rect = iter.Next()) {
NSRectFill(mCoordinateConverter.DevPixelsToCocoaPoints(*rect));
}

Просмотреть файл

@ -3753,7 +3753,7 @@ NSEvent* gLastDragMouseDownEvent = nil;
RefPtr<gfxContext> targetContext = new gfxContext(dt);
// Set up the clip region.
LayoutDeviceIntRegion::RectIterator iter(region);
LayoutDeviceIntRegion::OldRectIterator iter(region);
targetContext->NewPath();
for (;;) {
const LayoutDeviceIntRect* r = iter.Next();
@ -4632,7 +4632,7 @@ NewCGSRegionFromRegion(const LayoutDeviceIntRegion& aRegion,
CGRect (^aRectConverter)(const LayoutDeviceIntRect&))
{
nsTArray<CGRect> rects;
LayoutDeviceIntRegion::RectIterator iter(aRegion);
LayoutDeviceIntRegion::OldRectIterator iter(aRegion);
for (;;) {
const LayoutDeviceIntRect* r = iter.Next();
if (!r) {

Просмотреть файл

@ -758,7 +758,7 @@ nsBaseWidget::ArrayFromRegion(const LayoutDeviceIntRegion& aRegion,
nsTArray<LayoutDeviceIntRect>& aRects)
{
const LayoutDeviceIntRect* r;
for (LayoutDeviceIntRegion::RectIterator iter(aRegion); (r = iter.Next()); ) {
for (LayoutDeviceIntRegion::OldRectIterator iter(aRegion); (r = iter.Next()); ) {
aRects.AppendElement(*r);
}
}

Просмотреть файл

@ -142,7 +142,7 @@ nsShmImage::Put(Display* aDisplay, Drawable aWindow,
LayoutDeviceIntRegion bounded;
bounded.And(aRegion,
LayoutDeviceIntRect(0, 0, mImage->width, mImage->height));
LayoutDeviceIntRegion::RectIterator iter(bounded);
LayoutDeviceIntRegion::OldRectIterator iter(bounded);
for (const LayoutDeviceIntRect *r = iter.Next(); r; r = iter.Next()) {
XShmPutImage(aDisplay, aWindow, gc, mImage,
r->x, r->y,

Просмотреть файл

@ -377,7 +377,7 @@ private:
}
// Set up the clip region.
LayoutDeviceIntRegion::RectIterator iter(region);
LayoutDeviceIntRegion::OldRectIterator iter(region);
targetContext->NewPath();
for (;;) {
const LayoutDeviceIntRect* r = iter.Next();