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
This commit is contained in:
Nicholas Nethercote 2015-11-11 14:23:14 -08:00
parent 6f30bac4d2
commit 489c83b1dd
15 changed files with 44 additions and 35 deletions

View File

@ -229,6 +229,12 @@ IntRectTyped<units> RoundedOut(const RectTyped<units>& aRect)
int32_t(copy.height));
}
template<class units>
RectTyped<units> IntRectToRect(const IntRectTyped<units>& aRect)
{
return RectTyped<units>(aRect.x, aRect.y, aRect.width, aRect.height);
}
} // namespace gfx
} // namespace mozilla

View File

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

View File

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

View File

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

View File

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

View File

@ -1094,7 +1094,7 @@ BasicLayerManager::PaintLayer(gfxContext* aTarget,
#endif
Matrix4x4 effectiveTransform = aLayer->GetEffectiveTransform();
RefPtr<gfxASurface> result =
Transform3D(untransformedDT->Snapshot(), aTarget, bounds,
Transform3D(untransformedDT->Snapshot(), aTarget, ThebesRect(bounds),
effectiveTransform, destRect);
if (result) {

View File

@ -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<CanvasLayer*>(layer)->GetBounds());
layerBounds =
IntRectToRect(static_cast<CanvasLayer*>(layer)->GetBounds());
} else {
layerBounds = ToRect(layer->GetEffectiveVisibleRegion().GetBounds());
layerBounds =
IntRectToRect(layer->GetEffectiveVisibleRegion().GetBounds());
}
const gfx::Matrix4x4 childTransform = layer->GetEffectiveTransform();
layerBounds = childTransform.TransformBounds(layerBounds);

View File

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

View File

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

View File

@ -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<Path> maskPath = GetBoxShadowInsetPath(minDrawTarget, ToRect(outerRect),
ToRect(innerRect), aHasBorderRadius,
aInnerClipRadii);
RefPtr<Path> maskPath =
GetBoxShadowInsetPath(minDrawTarget, IntRectToRect(outerRect),
IntRectToRect(innerRect), aHasBorderRadius,
aInnerClipRadii);
Color black(0.f, 0.f, 0.f, 1.f);
minGfxContext->SetColor(black);

View File

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

View File

@ -304,7 +304,7 @@ imgFrame::InitWithDrawable(gfxDrawable* aDrawable,
nsIntRect imageRect(0, 0, mSize.width, mSize.height);
RefPtr<gfxContext> ctx = new gfxContext(target);
gfxUtils::DrawPixelSnapped(ctx, aDrawable, mSize,
ImageRegion::Create(imageRect),
ImageRegion::Create(ThebesRect(imageRect)),
mFormat, aFilter, aImageFlags);
if (canUseDataSurface && !mImageSurface) {

View File

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

View File

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

View File

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