From 489c83b1dd49f92af530e3c152ed6027548b89ca Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 11 Nov 2015 14:23:14 -0800 Subject: [PATCH] Bug 1223690 - Remove implicit Rect conversions. r=jrmuizel. gfxRect can be implicitly constructed from IntRect, which hides a number of implicit conversion points, makes Moz2Dification harder, and has some surprising effects. This patch removes the implicit constructor and replaces it with an explicit conversion function: gfxRect ThebesRect(const IntRect&) This is the obvious outcome of removing the constructor. But there is also a second, less obvious outcome: currently we do a number of IntRect-to-Rect conversions using ToRect(), which (surprisingly) works because it turns into an implicit IntRect-to-gfxRect conversion (via the implicit constructor) combined with an explicit gfxRect-to-Rect conversion (via ToRect()). I.e. we do two conversions, going from a Moz2D type to a Thebes type and back to a Moz2D type! So this patch also changes these conversion. It moves this existing function: Rect ToRect(const IntRect&) from gfx2DGlue.h -- where it doesn't really belong because it doesn't involve any Thebes types -- to gfx/2d/Rect.h, templatifying and renaming it as IntRectToRect() in the process. The rest of the patch deals with fall-out from these changes. The call sites change as follows: - IntRect-to-gfxRect conversions: - old: implicit - new: ThebesRect() - IntRect-to-Rect conversions: - old: ToRect() - new: IntRectToRect() --HG-- extra : rebase_source : e4e4c2ad10b36ecad4d57d1630158f3374e403be --- gfx/2d/Rect.h | 6 ++++++ gfx/layers/Compositor.cpp | 5 +++-- gfx/layers/LayerSorter.cpp | 4 ++-- gfx/layers/RotatedBuffer.cpp | 6 +++--- gfx/layers/basic/BasicCompositor.cpp | 2 +- gfx/layers/basic/BasicLayerManager.cpp | 2 +- gfx/layers/composite/ContainerLayerComposite.cpp | 6 ++++-- gfx/layers/composite/LayerManagerComposite.cpp | 2 +- gfx/thebes/gfx2DGlue.h | 10 +++++----- gfx/thebes/gfxBlur.cpp | 9 +++++---- gfx/thebes/gfxRect.h | 2 -- image/imgFrame.cpp | 2 +- layout/base/FrameLayerBuilder.cpp | 2 +- layout/svg/nsFilterInstance.cpp | 6 +++--- widget/gonk/HwcUtils.cpp | 15 ++++++++------- 15 files changed, 44 insertions(+), 35 deletions(-) diff --git a/gfx/2d/Rect.h b/gfx/2d/Rect.h index 2cce1655f994..c2e8d7a2bddd 100644 --- a/gfx/2d/Rect.h +++ b/gfx/2d/Rect.h @@ -229,6 +229,12 @@ IntRectTyped RoundedOut(const RectTyped& aRect) int32_t(copy.height)); } +template +RectTyped IntRectToRect(const IntRectTyped& aRect) +{ + return RectTyped(aRect.x, aRect.y, aRect.width, aRect.height); +} + } // namespace gfx } // namespace mozilla diff --git a/gfx/layers/Compositor.cpp b/gfx/layers/Compositor.cpp index 75d4c6acb058..a974b2c53128 100644 --- a/gfx/layers/Compositor.cpp +++ b/gfx/layers/Compositor.cpp @@ -66,11 +66,12 @@ Compositor::DrawDiagnostics(DiagnosticFlags aFlags, while (const gfx::IntRect* rect = screenIter.Next()) { DrawDiagnostics(aFlags | DiagnosticFlags::REGION_RECT, - ToRect(*rect), aClipRect, aTransform, aFlashCounter); + IntRectToRect(*rect), aClipRect, aTransform, + aFlashCounter); } } - DrawDiagnostics(aFlags, ToRect(aVisibleRegion.GetBounds()), + DrawDiagnostics(aFlags, IntRectToRect(aVisibleRegion.GetBounds()), aClipRect, aTransform, aFlashCounter); } diff --git a/gfx/layers/LayerSorter.cpp b/gfx/layers/LayerSorter.cpp index c1e2472a7e1a..f3149063f672 100644 --- a/gfx/layers/LayerSorter.cpp +++ b/gfx/layers/LayerSorter.cpp @@ -76,8 +76,8 @@ static gfxFloat RecoverZDepth(const Matrix4x4& aTransform, const gfxPoint& aPoin * unsolved without changing our rendering code. */ static LayerSortOrder CompareDepth(Layer* aOne, Layer* aTwo) { - gfxRect ourRect = aOne->GetEffectiveVisibleRegion().GetBounds(); - gfxRect otherRect = aTwo->GetEffectiveVisibleRegion().GetBounds(); + gfxRect ourRect = ThebesRect(aOne->GetEffectiveVisibleRegion().GetBounds()); + gfxRect otherRect = ThebesRect(aTwo->GetEffectiveVisibleRegion().GetBounds()); MOZ_ASSERT(aOne->GetParent() && aOne->GetParent()->Extend3DContext() && aTwo->GetParent() && aTwo->GetParent()->Extend3DContext()); diff --git a/gfx/layers/RotatedBuffer.cpp b/gfx/layers/RotatedBuffer.cpp index 96e2c0e003b2..e0a026799c56 100644 --- a/gfx/layers/RotatedBuffer.cpp +++ b/gfx/layers/RotatedBuffer.cpp @@ -109,7 +109,7 @@ RotatedBuffer::DrawBufferQuadrant(gfx::DrawTarget* aTarget, aOperator == CompositionOp::OP_SOURCE) { aOperator = CompositionOp::OP_OVER; if (snapshot->GetFormat() == SurfaceFormat::B8G8R8A8) { - aTarget->ClearRect(ToRect(fillRect)); + aTarget->ClearRect(IntRectToRect(fillRect)); } } @@ -119,7 +119,7 @@ RotatedBuffer::DrawBufferQuadrant(gfx::DrawTarget* aTarget, // We also need this clip in the case where we have a mask, since the mask surface // might cover more than fillRect, but we only want to touch the pixels inside // fillRect. - aTarget->PushClipRect(gfx::ToRect(fillRect)); + aTarget->PushClipRect(IntRectToRect(fillRect)); if (aMask) { Matrix oldTransform = aTarget->GetTransform(); @@ -149,7 +149,7 @@ RotatedBuffer::DrawBufferQuadrant(gfx::DrawTarget* aTarget, #else DrawSurfaceOptions options; #endif - aTarget->DrawSurface(snapshot, ToRect(fillRect), + aTarget->DrawSurface(snapshot, IntRectToRect(fillRect), GetSourceRectangle(aXSide, aYSide), options, DrawOptions(aOpacity, aOperator)); diff --git a/gfx/layers/basic/BasicCompositor.cpp b/gfx/layers/basic/BasicCompositor.cpp index fe602df1e3d1..a68fc580602a 100644 --- a/gfx/layers/basic/BasicCompositor.cpp +++ b/gfx/layers/basic/BasicCompositor.cpp @@ -587,7 +587,7 @@ BasicCompositor::EndFrame() float g = float(rand()) / RAND_MAX; float b = float(rand()) / RAND_MAX; // We're still clipped to mInvalidRegion, so just fill the bounds. - mRenderTarget->mDrawTarget->FillRect(ToRect(mInvalidRegion.GetBounds()), + mRenderTarget->mDrawTarget->FillRect(IntRectToRect(mInvalidRegion.GetBounds()), ColorPattern(Color(r, g, b, 0.2f))); } diff --git a/gfx/layers/basic/BasicLayerManager.cpp b/gfx/layers/basic/BasicLayerManager.cpp index e925f1697afc..6c0405e66d41 100644 --- a/gfx/layers/basic/BasicLayerManager.cpp +++ b/gfx/layers/basic/BasicLayerManager.cpp @@ -1094,7 +1094,7 @@ BasicLayerManager::PaintLayer(gfxContext* aTarget, #endif Matrix4x4 effectiveTransform = aLayer->GetEffectiveTransform(); RefPtr result = - Transform3D(untransformedDT->Snapshot(), aTarget, bounds, + Transform3D(untransformedDT->Snapshot(), aTarget, ThebesRect(bounds), effectiveTransform, destRect); if (result) { diff --git a/gfx/layers/composite/ContainerLayerComposite.cpp b/gfx/layers/composite/ContainerLayerComposite.cpp index a15ce760b832..eedffb9a19c8 100755 --- a/gfx/layers/composite/ContainerLayerComposite.cpp +++ b/gfx/layers/composite/ContainerLayerComposite.cpp @@ -226,9 +226,11 @@ ContainerRenderVR(ContainerT* aContainer, // proper bounds here (visible region bounds are 0,0,0,0) // and I'm not sure if this is the bounds we want anyway. if (layer->GetType() == Layer::TYPE_CANVAS) { - layerBounds = ToRect(static_cast(layer)->GetBounds()); + layerBounds = + IntRectToRect(static_cast(layer)->GetBounds()); } else { - layerBounds = ToRect(layer->GetEffectiveVisibleRegion().GetBounds()); + layerBounds = + IntRectToRect(layer->GetEffectiveVisibleRegion().GetBounds()); } const gfx::Matrix4x4 childTransform = layer->GetEffectiveTransform(); layerBounds = childTransform.TransformBounds(layerBounds); diff --git a/gfx/layers/composite/LayerManagerComposite.cpp b/gfx/layers/composite/LayerManagerComposite.cpp index 29e117ecebc5..a135a99f0fa4 100644 --- a/gfx/layers/composite/LayerManagerComposite.cpp +++ b/gfx/layers/composite/LayerManagerComposite.cpp @@ -1068,7 +1068,7 @@ SubtractTransformedRegion(nsIntRegion& aRegion, // subtract it from the screen region. nsIntRegionRectIterator it(aRegionToSubtract); while (const IntRect* rect = it.Next()) { - Rect incompleteRect = aTransform.TransformAndClipBounds(ToRect(*rect), + Rect incompleteRect = aTransform.TransformAndClipBounds(IntRectToRect(*rect), Rect::MaxIntRect()); aRegion.Sub(aRegion, IntRect(incompleteRect.x, incompleteRect.y, diff --git a/gfx/thebes/gfx2DGlue.h b/gfx/thebes/gfx2DGlue.h index 6b650b65d9f7..9bba6ef371ba 100644 --- a/gfx/thebes/gfx2DGlue.h +++ b/gfx/thebes/gfx2DGlue.h @@ -29,11 +29,6 @@ inline RectDouble ToRectDouble(const gfxRect &aRect) return RectDouble(aRect.x, aRect.y, aRect.width, aRect.height); } -inline Rect ToRect(const IntRect &aRect) -{ - return Rect(aRect.x, aRect.y, aRect.width, aRect.height); -} - inline Matrix ToMatrix(const gfxMatrix &aMatrix) { return Matrix(Float(aMatrix._11), Float(aMatrix._12), Float(aMatrix._21), @@ -71,6 +66,11 @@ inline gfxRect ThebesRect(const Rect &aRect) return gfxRect(aRect.x, aRect.y, aRect.width, aRect.height); } +inline gfxRect ThebesRect(const IntRect &aRect) +{ + return gfxRect(aRect.x, aRect.y, aRect.width, aRect.height); +} + inline gfxRect ThebesRect(const RectDouble &aRect) { return gfxRect(aRect.x, aRect.y, aRect.width, aRect.height); diff --git a/gfx/thebes/gfxBlur.cpp b/gfx/thebes/gfxBlur.cpp index a75a5ef4e7d0..97d90a67a60a 100644 --- a/gfx/thebes/gfxBlur.cpp +++ b/gfx/thebes/gfxBlur.cpp @@ -955,16 +955,17 @@ gfxAlphaBoxBlur::GetInsetBlur(IntMargin& aExtendDestBy, // When rendering inset box shadows, we respect the spread radius by changing // the shape of the unblurred shadow, and can pass a spread radius of zero here. IntSize zeroSpread(0, 0); - gfxContext* minGfxContext = Init(ThebesRect(ToRect(outerRect)), + gfxContext* minGfxContext = Init(ThebesRect(outerRect), zeroSpread, aBlurRadius, nullptr, nullptr); if (!minGfxContext) { return nullptr; } DrawTarget* minDrawTarget = minGfxContext->GetDrawTarget(); - RefPtr maskPath = GetBoxShadowInsetPath(minDrawTarget, ToRect(outerRect), - ToRect(innerRect), aHasBorderRadius, - aInnerClipRadii); + RefPtr maskPath = + GetBoxShadowInsetPath(minDrawTarget, IntRectToRect(outerRect), + IntRectToRect(innerRect), aHasBorderRadius, + aInnerClipRadii); Color black(0.f, 0.f, 0.f, 1.f); minGfxContext->SetColor(black); diff --git a/gfx/thebes/gfxRect.h b/gfx/thebes/gfxRect.h index d5045c51ec4c..9a83fbe8e7e5 100644 --- a/gfx/thebes/gfxRect.h +++ b/gfx/thebes/gfxRect.h @@ -71,8 +71,6 @@ struct gfxRect : Super(aPos, aSize) {} gfxRect(gfxFloat aX, gfxFloat aY, gfxFloat aWidth, gfxFloat aHeight) : Super(aX, aY, aWidth, aHeight) {} - MOZ_IMPLICIT gfxRect(const mozilla::gfx::IntRect& aRect) : - Super(aRect.x, aRect.y, aRect.width, aRect.height) {} /** * Return true if all components of this rect are within diff --git a/image/imgFrame.cpp b/image/imgFrame.cpp index c25acb822d7f..583c85313439 100644 --- a/image/imgFrame.cpp +++ b/image/imgFrame.cpp @@ -304,7 +304,7 @@ imgFrame::InitWithDrawable(gfxDrawable* aDrawable, nsIntRect imageRect(0, 0, mSize.width, mSize.height); RefPtr ctx = new gfxContext(target); gfxUtils::DrawPixelSnapped(ctx, aDrawable, mSize, - ImageRegion::Create(imageRect), + ImageRegion::Create(ThebesRect(imageRect)), mFormat, aFilter, aImageFlags); if (canUseDataSurface && !mImageSurface) { diff --git a/layout/base/FrameLayerBuilder.cpp b/layout/base/FrameLayerBuilder.cpp index 49b09e997254..5158b10392b5 100644 --- a/layout/base/FrameLayerBuilder.cpp +++ b/layout/base/FrameLayerBuilder.cpp @@ -5885,7 +5885,7 @@ FrameLayerBuilder::DrawPaintedLayer(PaintedLayer* aLayer, while (const nsIntRect* iterRect = it.Next()) { gfxContextAutoSaveRestore save(aContext); aContext->NewPath(); - aContext->Rectangle(*iterRect); + aContext->Rectangle(ThebesRect(*iterRect)); aContext->Clip(); DrawForcedBackgroundColor(aDrawTarget, aLayer, diff --git a/layout/svg/nsFilterInstance.cpp b/layout/svg/nsFilterInstance.cpp index bd1f2454ffea..b271a9a9cb32 100644 --- a/layout/svg/nsFilterInstance.cpp +++ b/layout/svg/nsFilterInstance.cpp @@ -376,7 +376,7 @@ nsFilterInstance::BuildSourcePaint(SourceInfo *aSource, nsSVGUtils::MakeStrokePatternFor(mTargetFrame, gfx, &pattern); } if (pattern.GetPattern()) { - offscreenDT->FillRect(ToRect(FilterSpaceToUserSpace(neededRect)), + offscreenDT->FillRect(ToRect(FilterSpaceToUserSpace(ThebesRect(neededRect))), pattern); } gfx->Restore(); @@ -422,7 +422,7 @@ nsFilterInstance::BuildSourceImage(DrawTarget* aTargetDT) return NS_ERROR_OUT_OF_MEMORY; } - gfxRect r = FilterSpaceToUserSpace(neededRect); + gfxRect r = FilterSpaceToUserSpace(ThebesRect(neededRect)); r.RoundOut(); nsIntRect dirty; if (!gfxUtils::GfxRectToIntRect(r, &dirty)) @@ -484,7 +484,7 @@ nsFilterInstance::Render(gfxContext* aContext) return rv; FilterSupport::RenderFilterDescription( - dt, mFilterDescription, ToRect(filterRect), + dt, mFilterDescription, IntRectToRect(filterRect), mSourceGraphic.mSourceSurface, mSourceGraphic.mSurfaceRect, mFillPaint.mSourceSurface, mFillPaint.mSurfaceRect, mStrokePaint.mSourceSurface, mStrokePaint.mSurfaceRect, diff --git a/widget/gonk/HwcUtils.cpp b/widget/gonk/HwcUtils.cpp index 67a7cfa565bd..16bec42af57e 100644 --- a/widget/gonk/HwcUtils.cpp +++ b/widget/gonk/HwcUtils.cpp @@ -45,8 +45,8 @@ HwcUtils::PrepareLayerRects(nsIntRect aVisible, hwc_rect_t* aSourceCrop, hwc_rect_t* aVisibleRegionScreen) { gfxMatrix aTransform = gfx::ThebesMatrix(aLayerTransform); - gfxRect visibleRect(aVisible); - gfxRect clip(aClip); + gfxRect visibleRect(ThebesRect(aVisible)); + gfxRect clip(ThebesRect(aClip)); gfxRect visibleRectScreen = aTransform.TransformBounds(visibleRect); // |clip| is guaranteed to be integer visibleRectScreen.IntersectRect(visibleRectScreen, clip); @@ -60,7 +60,7 @@ HwcUtils::PrepareLayerRects(nsIntRect aVisible, gfxRect crop = inverse.TransformBounds(visibleRectScreen); //clip to buffer size - crop.IntersectRect(crop, aBufferRect); + crop.IntersectRect(crop, ThebesRect(aBufferRect)); crop.Round(); if (crop.IsEmpty()) { @@ -103,7 +103,8 @@ HwcUtils::PrepareVisibleRegion(const nsIntRegion& aVisible, gfxMatrix layerTransform = gfx::ThebesMatrix(aLayerTransform); gfxMatrix layerBufferTransform = gfx::ThebesMatrix(aLayerBufferTransform); - gfxRect bufferRect = layerBufferTransform.TransformBounds(aBufferRect); + gfxRect bufferRect = + layerBufferTransform.TransformBounds(ThebesRect(aBufferRect)); gfxMatrix inverse = gfx::ThebesMatrix(aLayerBufferTransform); inverse.Invert(); nsIntRegionRectIterator rect(aVisible); @@ -112,9 +113,9 @@ HwcUtils::PrepareVisibleRegion(const nsIntRegion& aVisible, hwc_rect_t visibleRectScreen; gfxRect screenRect; - screenRect = layerTransform.TransformBounds(gfxRect(*visibleRect)); + screenRect = layerTransform.TransformBounds(ThebesRect(*visibleRect)); screenRect.IntersectRect(screenRect, bufferRect); - screenRect.IntersectRect(screenRect, aClip); + screenRect.IntersectRect(screenRect, ThebesRect(aClip)); screenRect.Round(); if (screenRect.IsEmpty()) { continue; @@ -156,7 +157,7 @@ HwcUtils::CalculateClipRect(const gfx::Matrix& transform, nsIntRect clip = *aLayerClip; - gfxRect r(clip); + gfxRect r = ThebesRect(clip); gfxRect trClip = aTransform.TransformBounds(r); trClip.Round(); gfxUtils::GfxRectToIntRect(trClip, &clip);