Bug 1065127 - Avoid Matrix().Translate()/Scale()/Rotate() multiplication in lots of places. r=Bas

--HG--
extra : rebase_source : ef075258c31973c4943b9b3a9229685a9bb83917
This commit is contained in:
Jonathan Watt 2014-09-10 11:45:42 +01:00
Родитель 4d1ad7ca3b
Коммит ee916d4351
26 изменённых файлов: 56 добавлений и 66 удалений

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

@ -425,7 +425,7 @@ GetCTMInternal(nsSVGElement *aElement, bool aScreenCTM, bool aHaveRecursed)
}
}
}
return gfx::ToMatrix(matrix) * gfx::Matrix().Translate(x, y);
return ToMatrix(matrix).PostTranslate(x, y);
}
gfx::Matrix

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

@ -231,8 +231,8 @@ SVGFEImageElement::GetPrimitiveDescription(nsSVGFilterInstance* aInstance,
SVGContentUtils::GetViewBoxTransform(aFilterSubregion.width, aFilterSubregion.height,
0, 0, nativeSize.width, nativeSize.height,
mPreserveAspectRatio);
Matrix xyTM = Matrix().Translate(aFilterSubregion.x, aFilterSubregion.y);
Matrix TM = viewBoxTM * xyTM;
Matrix TM = viewBoxTM;
TM.PostTranslate(aFilterSubregion.x, aFilterSubregion.y);
Filter filter = ToFilter(nsLayoutUtils::GetGraphicsFilterForFrame(frame));

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

@ -85,7 +85,7 @@ SVGForeignObjectElement::PrependLocalTransformsTo(const gfxMatrix &aMatrix,
float x, y;
const_cast<SVGForeignObjectElement*>(this)->
GetAnimatedLengthValues(&x, &y, nullptr);
gfxMatrix toUserSpace = gfxMatrix().Translate(gfxPoint(x, y));
gfxMatrix toUserSpace = gfxMatrix::Translation(x, y);
if (aWhich == eChildToUserSpace) {
return toUserSpace * aMatrix;
}

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

@ -74,7 +74,7 @@ SVGIFrameElement::PrependLocalTransformsTo(const gfxMatrix &aMatrix,
float x, y;
const_cast<SVGIFrameElement*>(this)->
GetAnimatedLengthValues(&x, &y, nullptr);
gfxMatrix toUserSpace = gfxMatrix().Translate(gfxPoint(x, y));
gfxMatrix toUserSpace = gfxMatrix::Translation(x, y);
if (aWhich == eChildToUserSpace) {
return toUserSpace;
}

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

@ -16,6 +16,8 @@
#include "mozilla/gfx/Matrix.h"
#include "SVGContentUtils.h"
using namespace mozilla::gfx;
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(Marker)
namespace mozilla {
@ -359,7 +361,8 @@ SVGMarkerElement::GetViewBoxTransform()
gfx::Point ref = viewBoxTM * gfx::Point(refX, refY);
gfx::Matrix TM = viewBoxTM * gfx::Matrix().Translate(-ref.x, -ref.y);
Matrix TM = viewBoxTM;
TM.PostTranslate(-ref.x, -ref.y);
mViewBoxToViewportTransform = new gfx::Matrix(TM);
}

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

@ -968,10 +968,10 @@ SVGSVGElement::PrependLocalTransformsTo(const gfxMatrix &aMatrix,
const_cast<SVGSVGElement*>(this)->GetAnimatedLengthValues(&x, &y, nullptr);
if (aWhich == eAllTransforms) {
// the common case
return ThebesMatrix(GetViewBoxTransform()) * gfxMatrix().Translate(gfxPoint(x, y)) * fromUserSpace;
return ThebesMatrix(GetViewBoxTransform()) * gfxMatrix::Translation(x, y) * fromUserSpace;
}
NS_ABORT_IF_FALSE(aWhich == eChildToUserSpace, "Unknown TransformTypes");
return ThebesMatrix(GetViewBoxTransform()) * gfxMatrix().Translate(gfxPoint(x, y)) * aMatrix;
return ThebesMatrix(GetViewBoxTransform()) * gfxMatrix::Translation(x, y) * aMatrix;
}
if (IsRoot()) {

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

@ -434,7 +434,7 @@ SVGUseElement::PrependLocalTransformsTo(const gfxMatrix &aMatrix,
// our 'x' and 'y' attributes:
float x, y;
const_cast<SVGUseElement*>(this)->GetAnimatedLengthValues(&x, &y, nullptr);
gfxMatrix toUserSpace = gfxMatrix().Translate(gfxPoint(x, y));
gfxMatrix toUserSpace = gfxMatrix::Translation(x, y);
if (aWhich == eChildToUserSpace) {
return toUserSpace * aMatrix;
}

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

@ -95,8 +95,8 @@ DrawTargetD2D1::DrawSurface(SourceSurface *aSurface,
// Here we scale the source pattern up to the size and position where we want
// it to be.
Matrix transform;
transform.Translate(aDest.x, aDest.y);
transform.Scale(xScale, yScale);
transform.PreTranslate(aDest.x, aDest.y);
transform.PreScale(xScale, yScale);
mDC->CreateImageBrush(image, D2D1::ImageBrushProperties(samplingBounds),
D2D1::BrushProperties(aOptions.mAlpha, D2DMatrix(transform)),

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

@ -122,8 +122,8 @@ RotatedBuffer::DrawBufferQuadrant(gfx::DrawTarget* aTarget,
Matrix oldTransform = aTarget->GetTransform();
// Transform from user -> buffer space.
Matrix transform;
transform.Translate(quadrantTranslation.x, quadrantTranslation.y);
Matrix transform =
Matrix::Translation(quadrantTranslation.x, quadrantTranslation.y);
Matrix inverseMask = *aMaskTransform;
inverseMask.Invert();
@ -661,8 +661,7 @@ RotatedContentBuffer::BeginPaint(ThebesLayer* aLayer,
if (!isClear && (mode != SurfaceMode::SURFACE_COMPONENT_ALPHA || HaveBufferOnWhite())) {
// Copy the bits
nsIntPoint offset = -destBufferRect.TopLeft();
Matrix mat;
mat.Translate(offset.x, offset.y);
Matrix mat = Matrix::Translation(offset.x, offset.y);
destDTBuffer->SetTransform(mat);
if (!EnsureBuffer()) {
return result;

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

@ -261,9 +261,7 @@ BasicCompositor::DrawQuad(const gfx::Rect& aRect,
return;
}
Matrix destTransform;
destTransform.Translate(-aRect.x, -aRect.y);
dest->SetTransform(destTransform);
dest->SetTransform(Matrix::Translation(-aRect.x, -aRect.y));
// Get the bounds post-transform.
new3DTransform = To3DMatrix(aTransform);
@ -274,7 +272,7 @@ BasicCompositor::DrawQuad(const gfx::Rect& aRect,
transformBounds.RoundOut();
// Propagate the coordinate offset to our 2D draw target.
newTransform.Translate(transformBounds.x, transformBounds.y);
newTransform = Matrix::Translation(transformBounds.x, transformBounds.y);
// When we apply the 3D transformation, we do it against a temporary
// surface, so undo the coordinate offset.
@ -441,9 +439,8 @@ BasicCompositor::BeginFrame(const nsIntRegion& aInvalidRegion,
// We only allocate a surface sized to the invalidated region, so we need to
// translate future coordinates.
Matrix transform;
transform.Translate(-invalidRect.x, -invalidRect.y);
mRenderTarget->mDrawTarget->SetTransform(transform);
mRenderTarget->mDrawTarget->SetTransform(Matrix::Translation(-invalidRect.x,
-invalidRect.y));
gfxUtils::ClipToRegion(mRenderTarget->mDrawTarget, invalidRegionSafe);

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

@ -829,8 +829,7 @@ CompositorD3D11::PrepareViewport(const gfx::IntSize& aSize,
mContext->RSSetViewports(1, &viewport);
Matrix viewMatrix;
viewMatrix.Translate(-1.0, 1.0);
Matrix viewMatrix = Matrix::Translation(-1.0, 1.0);
viewMatrix.Scale(2.0f / float(aSize.width), 2.0f / float(aSize.height));
viewMatrix.Scale(1.0f, -1.0f);

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

@ -1055,9 +1055,8 @@ gfxContext::Paint(gfxFloat alpha)
IntSize surfSize = state.sourceSurface->GetSize();
Matrix mat;
mat.Translate(-state.deviceOffset.x, -state.deviceOffset.y);
mDT->SetTransform(mat);
mDT->SetTransform(Matrix::Translation(-state.deviceOffset.x,
-state.deviceOffset.y));
mDT->DrawSurface(state.sourceSurface,
Rect(state.sourceSurfaceDeviceOffset, Size(surfSize.width, surfSize.height)),
@ -1619,9 +1618,8 @@ gfxContext::GetDeviceOffset() const
Matrix
gfxContext::GetDeviceTransform() const
{
Matrix mat;
mat.Translate(-CurrentState().deviceOffset.x, -CurrentState().deviceOffset.y);
return mat;
return Matrix::Translation(-CurrentState().deviceOffset.x,
-CurrentState().deviceOffset.y);
}
Matrix

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

@ -407,10 +407,10 @@ CreateSamplingRestrictedDrawable(gfxDrawable* aDrawable,
nsRefPtr<gfxContext> tmpCtx = new gfxContext(target);
tmpCtx->SetOperator(OptimalFillOperator());
aDrawable->Draw(tmpCtx, needed - needed.TopLeft(), true,
GraphicsFilter::FILTER_FAST, 1.0, gfxMatrix().Translate(needed.TopLeft()));
GraphicsFilter::FILTER_FAST, 1.0, gfxMatrix::Translation(needed.TopLeft()));
RefPtr<SourceSurface> surface = target->Snapshot();
nsRefPtr<gfxDrawable> drawable = new gfxSurfaceDrawable(surface, size, gfxMatrix().Translate(-needed.TopLeft()));
nsRefPtr<gfxDrawable> drawable = new gfxSurfaceDrawable(surface, size, gfxMatrix::Translation(-needed.TopLeft()));
return drawable.forget();
}
#endif // !MOZ_GFX_OPTIMIZE_MOBILE

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

@ -1725,8 +1725,7 @@ ContainerState::CreateOrRecycleThebesLayer(const nsIFrame* aAnimatedGeometryRoot
RoundToMatchResidual(scaledOffset.y, data->mAnimatedGeometryRootPosition.y));
data->mTranslation = pixOffset;
pixOffset += mParameters.mOffset;
Matrix matrix;
matrix.Translate(pixOffset.x, pixOffset.y);
Matrix matrix = Matrix::Translation(pixOffset.x, pixOffset.y);
layer->SetBaseTransform(Matrix4x4::From2D(matrix));
// FIXME: Temporary workaround for bug 681192 and bug 724786.
@ -2567,8 +2566,8 @@ PaintInactiveLayer(nsDisplayListBuilder* aBuilder,
itemVisibleRect.Size().ToIntSize(),
SurfaceFormat::B8G8R8A8);
context = new gfxContext(tempDT);
context->SetMatrix(gfxMatrix().Translate(-gfxPoint(itemVisibleRect.x,
itemVisibleRect.y)));
context->SetMatrix(gfxMatrix::Translation(-itemVisibleRect.x,
-itemVisibleRect.y));
}
#endif
basic->BeginTransaction();
@ -4184,7 +4183,7 @@ static void DebugPaintItem(nsRenderingContext* aDest,
IntSize(bounds.width, bounds.height),
SurfaceFormat::B8G8R8A8);
nsRefPtr<gfxContext> context = new gfxContext(tempDT);
context->SetMatrix(gfxMatrix().Translate(-gfxPoint(bounds.x, bounds.y)));
context->SetMatrix(gfxMatrix::Translation(-gfxPoint(bounds.x, bounds.y)));
nsRefPtr<nsRenderingContext> ctx = new nsRenderingContext();
ctx->Init(aDest->DeviceContext(), context);
@ -4617,9 +4616,9 @@ ContainerState::SetupMaskLayer(Layer *aLayer,
// component of imageTransform), and its inverse used when the mask is used for
// masking.
// It is the transform from the masked layer's space to mask space
gfx::Matrix maskTransform;
maskTransform.Scale(surfaceSize.width/boundingRect.Width(),
surfaceSize.height/boundingRect.Height());
gfx::Matrix maskTransform =
Matrix::Scaling(surfaceSize.width / boundingRect.Width(),
surfaceSize.height / boundingRect.Height());
gfx::Point p = boundingRect.TopLeft();
maskTransform.Translate(-p.x, -p.y);
// imageTransform is only used when the clip is painted to the mask

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

@ -2179,8 +2179,7 @@ nsDisplayBackgroundImage::ConfigureLayer(ImageLayer* aLayer, const nsIntPoint& a
NS_ASSERTION(imageSize.width != 0 && imageSize.height != 0, "Invalid image size!");
gfxPoint p = mDestRect.TopLeft() + aOffset;
gfx::Matrix transform;
transform.Translate(p.x, p.y);
Matrix transform = Matrix::Translation(p.x, p.y);
transform.Scale(mDestRect.width/imageSize.width,
mDestRect.height/imageSize.height);
aLayer->SetBaseTransform(gfx::Matrix4x4::From2D(transform));

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

@ -19,6 +19,7 @@
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::layers;
using namespace mozilla::gfx;
class nsDisplayCanvas : public nsDisplayItem {
public:
@ -280,9 +281,8 @@ nsHTMLCanvasFrame::BuildLayer(nsDisplayListBuilder* aBuilder,
presContext->AppUnitsToGfxUnits(area.height));
// Transform the canvas into the right place
gfx::Matrix transform;
gfxPoint p = r.TopLeft() + aContainerParameters.mOffset;
transform.Translate(p.x, p.y);
Matrix transform = Matrix::Translation(p.x, p.y);
transform.Scale(r.Width()/canvasSize.width, r.Height()/canvasSize.height);
layer->SetBaseTransform(gfx::Matrix4x4::From2D(transform));
layer->SetFilter(nsLayoutUtils::GetGraphicsFilterForFrame(this));

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

@ -85,6 +85,7 @@ using namespace mozilla;
using namespace mozilla::layers;
using namespace mozilla::dom;
using namespace mozilla::gfx;
// static icon information
nsImageFrame::IconLoad* nsImageFrame::gIconLoad = nullptr;
@ -1442,9 +1443,8 @@ nsDisplayImage::ConfigureLayer(ImageLayer *aLayer, const nsIntPoint& aOffset)
const gfxRect destRect = GetDestRect();
gfx::Matrix transform;
gfxPoint p = destRect.TopLeft() + aOffset;
transform.Translate(p.x, p.y);
Matrix transform = Matrix::Translation(p.x, p.y);
transform.Scale(destRect.Width()/imageWidth,
destRect.Height()/imageHeight);
aLayer->SetBaseTransform(gfx::Matrix4x4::From2D(transform));

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

@ -1576,9 +1576,8 @@ nsObjectFrame::BuildLayer(nsDisplayListBuilder* aBuilder,
}
// Set a transform on the layer to draw the plugin in the right place
Matrix transform;
gfxPoint p = r.TopLeft() + aContainerParameters.mOffset;
transform.Translate(p.x, p.y);
Matrix transform = Matrix::Translation(p.x, p.y);
layer->SetBaseTransform(Matrix4x4::From2D(transform));
return layer.forget();

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

@ -222,9 +222,8 @@ nsVideoFrame::BuildLayer(nsDisplayListBuilder* aBuilder,
layer->SetFilter(nsLayoutUtils::GetGraphicsFilterForFrame(this));
layer->SetContentFlags(Layer::CONTENT_OPAQUE);
// Set a transform on the layer to draw the video in the right place
gfx::Matrix transform;
gfxPoint p = r.TopLeft() + aContainerParameters.mOffset;
transform.Translate(p.x, p.y);
Matrix transform = Matrix::Translation(p.x, p.y);
transform.Scale(r.Width()/frameSize.width, r.Height()/frameSize.height);
layer->SetBaseTransform(gfx::Matrix4x4::From2D(transform));
nsRefPtr<Layer> result = layer.forget();

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

@ -548,5 +548,5 @@ nsFilterInstance::FilterSpaceToFrameSpace(const nsIntRegion& aRegion) const
gfxMatrix
nsFilterInstance::GetUserSpaceToFrameSpaceInCSSPxTransform() const
{
return gfxMatrix().Translate(-nsSVGUtils::FrameSpaceInCSSPxToUserSpaceOffset(mTargetFrame));
return gfxMatrix::Translation(-nsSVGUtils::FrameSpaceInCSSPxToUserSpaceOffset(mTargetFrame));
}

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

@ -643,7 +643,7 @@ PaintFrameCallback::operator()(gfxContext* aContext,
int32_t appUnitsPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel();
nsPoint offset = GetOffsetToBoundingBox(mFrame);
gfxPoint devPxOffset = gfxPoint(offset.x, offset.y) / appUnitsPerDevPixel;
aContext->Multiply(gfxMatrix().Translate(devPxOffset));
aContext->Multiply(gfxMatrix::Translation(devPxOffset));
gfxSize paintServerSize =
gfxSize(mPaintServerSize.width, mPaintServerSize.height) /
@ -653,8 +653,7 @@ PaintFrameCallback::operator()(gfxContext* aContext,
// want it to render with mRenderSize, so we need to set up a scale transform.
gfxFloat scaleX = mRenderSize.width / paintServerSize.width;
gfxFloat scaleY = mRenderSize.height / paintServerSize.height;
gfxMatrix scaleMatrix = gfxMatrix().Scale(scaleX, scaleY);
aContext->Multiply(scaleMatrix);
aContext->Multiply(gfxMatrix::Scaling(scaleX, scaleY));
// Draw.
nsRect dirty(-offset.x, -offset.y,

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

@ -223,7 +223,7 @@ nsSVGMaskFrame::GetMaskForMaskedFrame(gfxContext* aContext,
}
gfxMatrix maskSurfaceMatrix =
aContext->CurrentMatrix() * gfxMatrix().Translate(-maskSurfaceRect.TopLeft());
aContext->CurrentMatrix() * gfxMatrix::Translation(-maskSurfaceRect.TopLeft());
nsRefPtr<nsRenderingContext> tmpCtx = new nsRenderingContext();
tmpCtx->Init(this->PresContext()->DeviceContext(), maskDT);

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

@ -864,7 +864,7 @@ nsSVGOuterSVGFrame::GetCanvasTM()
PresContext()->AppUnitsPerDevPixel());
gfxMatrix tm = content->PrependLocalTransformsTo(
gfxMatrix().Scale(devPxPerCSSPx, devPxPerCSSPx));
gfxMatrix::Scaling(devPxPerCSSPx, devPxPerCSSPx));
mCanvasTM = new gfxMatrix(tm);
}
return *mCanvasTM;

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

@ -958,9 +958,8 @@ nsSVGUtils::GetBBox(nsIFrame *aFrame, uint32_t aFlags)
static_cast<SVGClipPathElement*>(clipPathFrame->GetContent());
nsRefPtr<SVGAnimatedEnumeration> units = clipContent->ClipPathUnits();
if (units->AnimVal() == SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
matrix = gfxMatrix().Scale(width, height) *
gfxMatrix().Translate(gfxPoint(x, y)) *
matrix;
matrix.Translate(gfxPoint(x, y));
matrix.Scale(width, height);
} else if (aFrame->GetType() == nsGkAtoms::svgForeignObjectFrame) {
matrix.Reset();
}
@ -1072,9 +1071,10 @@ nsSVGUtils::AdjustMatrixForUnits(const gfxMatrix &aMatrix,
if (aFrame &&
aUnits->GetAnimValue() == SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
gfxRect bbox = GetBBox(aFrame);
return gfxMatrix().Scale(bbox.Width(), bbox.Height()) *
gfxMatrix().Translate(gfxPoint(bbox.X(), bbox.Y())) *
aMatrix;
gfxMatrix tm = aMatrix;
tm.Translate(gfxPoint(bbox.X(), bbox.Y()));
tm.Scale(bbox.Width(), bbox.Height());
return tm;
}
return aMatrix;
}

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

@ -54,6 +54,7 @@
#define ONLOAD_CALLED_TOO_EARLY 1
using namespace mozilla;
using namespace mozilla::gfx;
using namespace mozilla::layers;
class nsImageBoxFrameEvent : public nsRunnable
@ -402,8 +403,7 @@ nsDisplayXULImage::ConfigureLayer(ImageLayer* aLayer, const nsIntPoint& aOffset)
NS_ASSERTION(imageWidth != 0 && imageHeight != 0, "Invalid image size!");
gfxPoint p = destRect.TopLeft() + aOffset;
gfx::Matrix transform;
transform.Translate(p.x, p.y);
Matrix transform = Matrix::Translation(p.x, p.y);
transform.Scale(destRect.Width()/imageWidth,
destRect.Height()/imageHeight);
aLayer->SetBaseTransform(gfx::Matrix4x4::From2D(transform));

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

@ -3013,8 +3013,7 @@ GLPresenter::BeginFrame(nsIntSize aRenderSize)
// Matrix to transform (0, 0, width, height) to viewport space (-1.0, 1.0,
// 2, 2) and flip the contents.
gfx::Matrix viewMatrix;
viewMatrix.Translate(-1.0, 1.0);
gfx::Matrix viewMatrix = gfx::Matrix::Translation(-1.0, 1.0);
viewMatrix.Scale(2.0f / float(aRenderSize.width), 2.0f / float(aRenderSize.height));
viewMatrix.Scale(1.0f, -1.0f);