Bug 1077961, part 2 - Stop doing lots of unnecessary and expensive Matrix4x4 multiplication. r=Bas

This commit is contained in:
Jonathan Watt 2014-10-08 04:43:00 +01:00
Родитель 30c91163ad
Коммит c5ae349afc
12 изменённых файлов: 44 добавлений и 46 удалений

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

@ -715,10 +715,10 @@ const Matrix4x4
Layer::GetTransform() const
{
Matrix4x4 transform = mTransform;
transform.PostScale(mPostXScale, mPostYScale, 1.0f);
if (const ContainerLayer* c = AsContainerLayer()) {
transform.Scale(c->GetPreXScale(), c->GetPreYScale(), 1.0f);
}
transform = transform * Matrix4x4().Scale(mPostXScale, mPostYScale, 1.0f);
return transform;
}
@ -730,10 +730,11 @@ Layer::GetLocalTransform()
transform = shadow->GetShadowTransform();
else
transform = mTransform;
transform.PostScale(mPostXScale, mPostYScale, 1.0f);
if (ContainerLayer* c = AsContainerLayer()) {
transform.Scale(c->GetPreXScale(), c->GetPreYScale(), 1.0f);
}
transform = transform * Matrix4x4().Scale(mPostXScale, mPostYScale, 1.0f);
return transform;
}

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

@ -2498,7 +2498,7 @@ Matrix4x4 AsyncPanZoomController::GetOverscrollTransform() const {
}
// Combine the transformations into a matrix.
return Matrix4x4().Scale(scaleX, scaleY, 1)
return Matrix4x4::Scaling(scaleX, scaleY, 1)
.PostTranslate(translation.x, translation.y, 0);
}
@ -2623,7 +2623,7 @@ ViewTransform AsyncPanZoomController::GetCurrentAsyncTransform() const {
Matrix4x4 AsyncPanZoomController::GetNontransientAsyncTransform() const {
ReentrantMonitorAutoEnter lock(mMonitor);
return Matrix4x4().Scale(mLastContentPaintMetrics.mResolution.scale,
return Matrix4x4::Scaling(mLastContentPaintMetrics.mResolution.scale,
mLastContentPaintMetrics.mResolution.scale,
1.0f);
}
@ -2644,8 +2644,8 @@ Matrix4x4 AsyncPanZoomController::GetTransformToLastDispatchedPaint() const {
float zoomChange = mLastContentPaintMetrics.GetZoom().scale / mLastDispatchedPaintMetrics.GetZoom().scale;
return Matrix4x4().Translate(scrollChange.x, scrollChange.y, 0) *
Matrix4x4().Scale(zoomChange, zoomChange, 1);
return Matrix4x4::Translation(scrollChange.x, scrollChange.y, 0).
PostScale(zoomChange, zoomChange, 1);
}
bool AsyncPanZoomController::IsCurrentlyCheckerboarding() const {

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

@ -75,7 +75,7 @@ GetTransformToAncestorsParentLayer(Layer* aStart, const LayerMetricsWrapper& aAn
// If the layer has a non-transient async transform then we need to apply it here
// because it will get applied by the APZ in the compositor as well
const FrameMetrics& metrics = iter.Metrics();
transform = transform * gfx::Matrix4x4().Scale(metrics.mResolution.scale, metrics.mResolution.scale, 1.f);
transform.PostScale(metrics.mResolution.scale, metrics.mResolution.scale, 1.f);
}
return transform;
}

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

@ -1366,7 +1366,7 @@ GetCompositorSideCompositionBounds(const LayerMetricsWrapper& aScrollAncestor,
const Matrix4x4& aTransformToCompBounds,
const ViewTransform& aAPZTransform)
{
Matrix4x4 nonTransientAPZUntransform = Matrix4x4().Scale(
Matrix4x4 nonTransientAPZUntransform = Matrix4x4::Scaling(
aScrollAncestor.Metrics().mResolution.scale,
aScrollAncestor.Metrics().mResolution.scale,
1.f);

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

@ -178,8 +178,7 @@ TranslateShadowLayer2D(Layer* aLayer,
1.0f/c->GetPreYScale(),
1);
}
layerTransform3D = layerTransform3D *
Matrix4x4().Scale(1.0f/aLayer->GetPostXScale(),
layerTransform3D.PostScale(1.0f/aLayer->GetPostXScale(),
1.0f/aLayer->GetPostYScale(),
1);
@ -188,7 +187,7 @@ TranslateShadowLayer2D(Layer* aLayer,
layerComposite->SetShadowTransformSetByAnimation(false);
if (aAdjustClipRect) {
TransformClipRect(aLayer, Matrix4x4().Translate(aTranslation.x, aTranslation.y, 0));
TransformClipRect(aLayer, Matrix4x4::Translation(aTranslation.x, aTranslation.y, 0));
}
}
@ -500,9 +499,7 @@ SampleAnimations(Layer* aLayer, TimeStamp aPoint)
{
Matrix4x4 matrix = interpolatedValue.get_ArrayOfTransformFunction()[0].get_TransformMatrix().value();
if (ContainerLayer* c = aLayer->AsContainerLayer()) {
matrix = matrix * Matrix4x4().Scale(c->GetInheritedXScale(),
c->GetInheritedYScale(),
1);
matrix.PostScale(c->GetInheritedXScale(), c->GetInheritedYScale(), 1);
}
layerComposite->SetShadowTransform(matrix);
layerComposite->SetShadowTransformSetByAnimation(true);
@ -627,7 +624,7 @@ AsyncCompositionManager::ApplyAsyncContentTransformToTree(Layer *aLayer)
1.0f/container->GetPreYScale(),
1);
}
transform = transform * Matrix4x4().Scale(1.0f/aLayer->GetPostXScale(),
transform.PostScale(1.0f/aLayer->GetPostXScale(),
1.0f/aLayer->GetPostYScale(),
1);
layerComposite->SetShadowTransform(transform);
@ -715,13 +712,13 @@ ApplyAsyncTransformToScrollbarForContent(Layer* aScrollbar,
Matrix4x4 scrollbarTransform;
if (aScrollbar->GetScrollbarDirection() == Layer::VERTICAL) {
float scale = metrics.CalculateCompositedSizeInCssPixels().height / metrics.mScrollableRect.height;
scrollbarTransform = scrollbarTransform * Matrix4x4().Scale(1.f, 1.f / transientTransform._22, 1.f);
scrollbarTransform = scrollbarTransform * Matrix4x4().Translate(0, -transientTransform._42 * scale, 0);
scrollbarTransform.PostScale(1.f, 1.f / transientTransform._22, 1.f);
scrollbarTransform.PostTranslate(0, -transientTransform._42 * scale, 0);
}
if (aScrollbar->GetScrollbarDirection() == Layer::HORIZONTAL) {
float scale = metrics.CalculateCompositedSizeInCssPixels().width / metrics.mScrollableRect.width;
scrollbarTransform = scrollbarTransform * Matrix4x4().Scale(1.f / transientTransform._11, 1.f, 1.f);
scrollbarTransform = scrollbarTransform * Matrix4x4().Translate(-transientTransform._41 * scale, 0, 0);
scrollbarTransform.PostScale(1.f / transientTransform._11, 1.f, 1.f);
scrollbarTransform.PostTranslate(-transientTransform._41 * scale, 0, 0);
}
Matrix4x4 transform = scrollbarTransform * aScrollbar->GetTransform();
@ -760,7 +757,7 @@ ApplyAsyncTransformToScrollbarForContent(Layer* aScrollbar,
1.0f/container->GetPreYScale(),
1);
}
transform = transform * Matrix4x4().Scale(1.0f/aScrollbar->GetPostXScale(),
transform.PostScale(1.0f/aScrollbar->GetPostXScale(),
1.0f/aScrollbar->GetPostYScale(),
1);
aScrollbar->AsLayerComposite()->SetShadowTransform(transform);

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

@ -37,7 +37,7 @@ struct ViewTransform {
operator gfx::Matrix4x4() const
{
return
gfx::Matrix4x4().Scale(mScale.scale, mScale.scale, 1)
gfx::Matrix4x4::Scaling(mScale.scale, mScale.scale, 1)
.PostTranslate(mTranslation.x, mTranslation.y, 0);
}

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

@ -1701,7 +1701,7 @@ protected:
Matrix4x4 transforms[] = {
Matrix4x4(),
Matrix4x4(),
Matrix4x4().Scale(2, 1, 1),
Matrix4x4::Scaling(2, 1, 1),
Matrix4x4(),
};
root = CreateLayerTree(layerTreeSyntax, layerVisibleRegion, transforms, lm, layers);

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

@ -3735,7 +3735,7 @@ ChooseScaleAndSetTransform(FrameLayerBuilder* aLayerBuilder,
nsIntPoint offset;
Matrix4x4 transform =
Matrix4x4().Scale(aIncomingScale.mXScale, aIncomingScale.mYScale, 1.0);
Matrix4x4::Scaling(aIncomingScale.mXScale, aIncomingScale.mYScale, 1.0);
if (aTransform) {
// aTransform is applied first, then the scale is applied to the result
transform = (*aTransform)*transform;
@ -3764,7 +3764,9 @@ ChooseScaleAndSetTransform(FrameLayerBuilder* aLayerBuilder,
NS_lround(NSAppUnitsToDoublePixels(appUnitOffset.x, appUnitsPerDevPixel)*aIncomingScale.mXScale),
NS_lround(NSAppUnitsToDoublePixels(appUnitOffset.y, appUnitsPerDevPixel)*aIncomingScale.mYScale));
}
transform = transform * Matrix4x4().Translate(offset.x + aIncomingScale.mOffset.x, offset.y + aIncomingScale.mOffset.y, 0);
transform.PostTranslate(offset.x + aIncomingScale.mOffset.x,
offset.y + aIncomingScale.mOffset.y,
0);
if (transform.IsSingular()) {
return false;
@ -4137,7 +4139,7 @@ static gfxSize
PredictScaleForContent(nsIFrame* aFrame, nsIFrame* aAncestorWithScale,
const gfxSize& aScale)
{
Matrix4x4 transform = Matrix4x4().Scale(aScale.width, aScale.height, 1.0);
Matrix4x4 transform = Matrix4x4::Scaling(aScale.width, aScale.height, 1.0);
if (aFrame != aAncestorWithScale) {
// aTransform is applied first, then the scale is applied to the result
transform = nsLayoutUtils::GetTransformToAncestor(aFrame, aAncestorWithScale)*transform;

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

@ -4785,8 +4785,7 @@ nsIFrame::GetTransformMatrix(const nsIFrame* aStopAtAncestor,
// XXXjwatt: seems like this will double count offsets in the face of preserve-3d:
nsPoint delta = GetOffsetToCrossDoc(*aOutAncestor);
/* Combine the raw transform with a translation to our parent. */
result = result * Matrix4x4().Translate
(NSAppUnitsToFloatPixels(delta.x, scaleFactor),
result.PostTranslate(NSAppUnitsToFloatPixels(delta.x, scaleFactor),
NSAppUnitsToFloatPixels(delta.y, scaleFactor),
0.0f);
return result;
@ -4864,8 +4863,7 @@ nsIFrame::GetTransformMatrix(const nsIFrame* aStopAtAncestor,
*/
nsPoint delta = GetOffsetToCrossDoc(*aOutAncestor);
int32_t scaleFactor = PresContext()->AppUnitsPerDevPixel();
return Matrix4x4().Translate
(NSAppUnitsToFloatPixels(delta.x, scaleFactor),
return Matrix4x4::Translation(NSAppUnitsToFloatPixels(delta.x, scaleFactor),
NSAppUnitsToFloatPixels(delta.y, scaleFactor),
0.0f);
}

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

@ -463,7 +463,7 @@ static void PaintHeaderFooter(nsIFrame* aFrame, nsRenderingContext* aCtx,
static gfx::Matrix4x4 ComputePageTransform(nsIFrame* aFrame, float aAppUnitsPerPixel)
{
float scale = aFrame->PresContext()->GetPageScale();
return gfx::Matrix4x4().Scale(scale, scale, 1);
return gfx::Matrix4x4::Scaling(scale, scale, 1);
}
//------------------------------------------------------------------------------

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

@ -824,7 +824,7 @@ inline gfx::Matrix4x4
ComputePageSequenceTransform(nsIFrame* aFrame, float aAppUnitsPerPixel)
{
float scale = aFrame->PresContext()->GetPrintPreviewScale();
return gfx::Matrix4x4().Scale(scale, scale, 1);
return gfx::Matrix4x4::Scaling(scale, scale, 1);
}
void

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

@ -2515,8 +2515,8 @@ nsChildView::MaybeDrawRoundedCorners(GLManager* aManager, const nsIntRect& aRect
aManager->gl()->fBlendFuncSeparate(LOCAL_GL_ZERO, LOCAL_GL_SRC_ALPHA,
LOCAL_GL_ZERO, LOCAL_GL_SRC_ALPHA);
Matrix4x4 flipX = Matrix4x4().Scale(-1, 1, 1);
Matrix4x4 flipY = Matrix4x4().Scale(1, -1, 1);
Matrix4x4 flipX = Matrix4x4::Scaling(-1, 1, 1);
Matrix4x4 flipY = Matrix4x4::Scaling(1, -1, 1);
if (mIsCoveringTitlebar && !mIsFullscreen) {
// Mask the top corners.
@ -2928,7 +2928,7 @@ RectTextureImage::Draw(GLManager* aManager,
program->Activate();
program->SetProjectionMatrix(aManager->GetProjMatrix());
program->SetLayerTransform(aTransform * gfx::Matrix4x4().Translate(aLocation.x, aLocation.y, 0));
program->SetLayerTransform(Matrix4x4(aTransform).PostTranslate(aLocation.x, aLocation.y, 0));
program->SetTextureTransform(gfx::Matrix4x4());
program->SetRenderOffset(nsIntPoint(0, 0));
program->SetTexCoordMultiplier(mUsedSize.width, mUsedSize.height);