Bug 952977: Convert ComputeEffectiveTransforms to gfx::Matrix4x4 r=nical

This commit is contained in:
David Zbarsky 2014-01-27 10:28:04 -05:00
parent cbdd71e0f8
commit 4e68a5f47e
21 changed files with 60 additions and 66 deletions

View File

@ -27,7 +27,7 @@ void ImageLayer::SetContainer(ImageContainer* aContainer)
mContainer = aContainer;
}
void ImageLayer::ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface)
void ImageLayer::ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface)
{
gfx::Matrix4x4 local;
gfx::ToMatrix4x4(GetLocalTransform(), local);
@ -48,11 +48,9 @@ void ImageLayer::ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurfa
// This makes our snapping equivalent to what would happen if our content
// was drawn into a ThebesLayer (gfxContext would snap using the local
// transform, then we'd snap again when compositing the ThebesLayer).
gfx::Matrix4x4 transformToSurface;
gfx::ToMatrix4x4(aTransformToSurface, transformToSurface);
mEffectiveTransform =
SnapTransform(local, sourceRect, nullptr) *
SnapTransformTranslation(transformToSurface, nullptr);
SnapTransformTranslation(aTransformToSurface, nullptr);
ComputeEffectiveTransformForMaskLayer(aTransformToSurface);
}

View File

@ -14,8 +14,6 @@
#include "nsAutoPtr.h" // for nsRefPtr
#include "nscore.h" // for nsACString
class gfx3DMatrix;
namespace mozilla {
namespace layers {
@ -67,7 +65,7 @@ public:
MOZ_LAYER_DECL_NAME("ImageLayer", TYPE_IMAGE)
virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface);
virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface);
/**
* if true, the image will only be backed by a single tile texture

View File

@ -688,10 +688,10 @@ Layer::GetEffectiveMixBlendMode()
}
void
Layer::ComputeEffectiveTransformForMaskLayer(const gfx3DMatrix& aTransformToSurface)
Layer::ComputeEffectiveTransformForMaskLayer(const Matrix4x4& aTransformToSurface)
{
if (mMaskLayer) {
ToMatrix4x4(aTransformToSurface, mMaskLayer->mEffectiveTransform);
mMaskLayer->mEffectiveTransform = aTransformToSurface;
#ifdef DEBUG
gfxMatrix maskTranslation;
@ -885,10 +885,12 @@ ContainerLayer::SortChildrenBy3DZOrder(nsTArray<Layer*>& aArray)
}
void
ContainerLayer::DefaultComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface)
ContainerLayer::DefaultComputeEffectiveTransforms(const Matrix4x4& aTransformToSurface)
{
Matrix residual;
gfx3DMatrix idealTransform = GetLocalTransform()*aTransformToSurface;
gfx3DMatrix idealTransform;
To3DMatrix(aTransformToSurface, idealTransform);
idealTransform = GetLocalTransform() * idealTransform;
idealTransform.ProjectTo2D();
Matrix4x4 ideal;
ToMatrix4x4(idealTransform, ideal);
@ -935,20 +937,20 @@ ContainerLayer::DefaultComputeEffectiveTransforms(const gfx3DMatrix& aTransformT
mUseIntermediateSurface = useIntermediateSurface;
if (useIntermediateSurface) {
ComputeEffectiveTransformsForChildren(gfx3DMatrix::From2D(ThebesMatrix(residual)));
ComputeEffectiveTransformsForChildren(Matrix4x4::From2D(residual));
} else {
ComputeEffectiveTransformsForChildren(idealTransform);
ComputeEffectiveTransformsForChildren(ideal);
}
if (idealTransform.CanDraw2D()) {
ComputeEffectiveTransformForMaskLayer(aTransformToSurface);
} else {
ComputeEffectiveTransformForMaskLayer(gfx3DMatrix());
ComputeEffectiveTransformForMaskLayer(Matrix4x4());
}
}
void
ContainerLayer::ComputeEffectiveTransformsForChildren(const gfx3DMatrix& aTransformToSurface)
ContainerLayer::ComputeEffectiveTransformsForChildren(const Matrix4x4& aTransformToSurface)
{
for (Layer* l = mFirstChild; l; l = l->GetNextSibling()) {
l->ComputeEffectiveTransforms(aTransformToSurface);

View File

@ -1232,12 +1232,12 @@ public:
* We promise that when this is called on a layer, all ancestor layers
* have already had ComputeEffectiveTransforms called.
*/
virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface) = 0;
virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface) = 0;
/**
* computes the effective transform for a mask layer, if this layer has one
*/
void ComputeEffectiveTransformForMaskLayer(const gfx3DMatrix& aTransformToSurface);
void ComputeEffectiveTransformForMaskLayer(const gfx::Matrix4x4& aTransformToSurface);
/**
* Calculate the scissor rect required when rendering this layer.
@ -1478,10 +1478,11 @@ public:
MOZ_LAYER_DECL_NAME("ThebesLayer", TYPE_THEBES)
virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface)
virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface)
{
gfx::Matrix4x4 idealTransform;
gfx::ToMatrix4x4(GetLocalTransform() * aTransformToSurface, idealTransform);
gfx::ToMatrix4x4(GetLocalTransform(), idealTransform);
idealTransform = idealTransform * aTransformToSurface;
gfx::Matrix residual;
mEffectiveTransform = SnapTransformTranslation(idealTransform,
mAllowResidualTranslation ? &residual : nullptr);
@ -1642,7 +1643,7 @@ public:
* container is backend-specific. ComputeEffectiveTransforms must also set
* mUseIntermediateSurface.
*/
virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface) = 0;
virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface) = 0;
/**
* Call this only after ComputeEffectiveTransforms has been invoked
@ -1687,12 +1688,12 @@ protected:
* A default implementation of ComputeEffectiveTransforms for use by OpenGL
* and D3D.
*/
void DefaultComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface);
void DefaultComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface);
/**
* Loops over the children calling ComputeEffectiveTransforms on them.
*/
void ComputeEffectiveTransformsForChildren(const gfx3DMatrix& aTransformToSurface);
void ComputeEffectiveTransformsForChildren(const gfx::Matrix4x4& aTransformToSurface);
virtual nsACString& PrintInfo(nsACString& aTo, const char* aPrefix);
@ -1751,10 +1752,11 @@ public:
MOZ_LAYER_DECL_NAME("ColorLayer", TYPE_COLOR)
virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface)
virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface)
{
gfx::Matrix4x4 idealTransform;
gfx::ToMatrix4x4(GetLocalTransform() * aTransformToSurface, idealTransform);
gfx::ToMatrix4x4(GetLocalTransform(), idealTransform);
idealTransform = idealTransform * aTransformToSurface;
mEffectiveTransform = SnapTransformTranslation(idealTransform, nullptr);
ComputeEffectiveTransformForMaskLayer(aTransformToSurface);
}
@ -1892,20 +1894,18 @@ public:
MOZ_LAYER_DECL_NAME("CanvasLayer", TYPE_CANVAS)
virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface)
virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface)
{
// Snap our local transform first, and snap the inherited transform as well.
// This makes our snapping equivalent to what would happen if our content
// was drawn into a ThebesLayer (gfxContext would snap using the local
// transform, then we'd snap again when compositing the ThebesLayer).
gfx::Matrix4x4 localTransform;
gfx::Matrix4x4 transformToSurface;
gfx::ToMatrix4x4(GetLocalTransform(), localTransform);
gfx::ToMatrix4x4(aTransformToSurface, transformToSurface);
mEffectiveTransform =
SnapTransform(localTransform, gfxRect(0, 0, mBounds.width, mBounds.height),
nullptr)*
SnapTransformTranslation(transformToSurface, nullptr);
SnapTransformTranslation(aTransformToSurface, nullptr);
ComputeEffectiveTransformForMaskLayer(aTransformToSurface);
}

View File

@ -8,7 +8,6 @@
#include <stdint.h> // for uint64_t
#include "Layers.h" // for Layer, etc
#include "gfx3DMatrix.h" // for gfx3DMatrix
#include "gfxColor.h" // for gfxRGBA
#include "gfxRect.h" // for gfxRect
#include "mozilla/mozalloc.h" // for operator delete
@ -84,19 +83,18 @@ class ReadbackLayer : public Layer {
public:
MOZ_LAYER_DECL_NAME("ReadbackLayer", TYPE_READBACK)
virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface)
virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface)
{
// Snap our local transform first, and snap the inherited transform as well.
// This makes our snapping equivalent to what would happen if our content
// was drawn into a ThebesLayer (gfxContext would snap using the local
// transform, then we'd snap again when compositing the ThebesLayer).
gfx::Matrix4x4 localTransform, transformToSurface;
gfx::ToMatrix4x4(aTransformToSurface, transformToSurface);
gfx::Matrix4x4 localTransform;
gfx::ToMatrix4x4(GetLocalTransform(), localTransform);
mEffectiveTransform =
SnapTransform(localTransform, gfxRect(0, 0, mSize.width, mSize.height),
nullptr)*
SnapTransformTranslation(transformToSurface, nullptr);
SnapTransformTranslation(aTransformToSurface, nullptr);
}
/**

View File

@ -34,19 +34,21 @@ BasicContainerLayer::~BasicContainerLayer()
}
void
BasicContainerLayer::ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface)
BasicContainerLayer::ComputeEffectiveTransforms(const Matrix4x4& aTransformToSurface)
{
// We push groups for container layers if we need to, which always
// are aligned in device space, so it doesn't really matter how we snap
// containers.
Matrix residual;
gfx3DMatrix idealTransform = GetLocalTransform()*aTransformToSurface;
gfx3DMatrix idealTransform;
To3DMatrix(aTransformToSurface, idealTransform);
idealTransform = GetLocalTransform() * idealTransform;
idealTransform.ProjectTo2D();
if (!idealTransform.CanDraw2D()) {
ToMatrix4x4(idealTransform, mEffectiveTransform);
ComputeEffectiveTransformsForChildren(gfx3DMatrix());
ComputeEffectiveTransformForMaskLayer(gfx3DMatrix());
ComputeEffectiveTransformsForChildren(Matrix4x4());
ComputeEffectiveTransformForMaskLayer(Matrix4x4());
mUseIntermediateSurface = true;
return;
}
@ -56,7 +58,7 @@ BasicContainerLayer::ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToS
mEffectiveTransform = SnapTransformTranslation(ideal, &residual);
// We always pass the ideal matrix down to our children, so there is no
// need to apply any compensation using the residual from SnapTransformTranslation.
ComputeEffectiveTransformsForChildren(idealTransform);
ComputeEffectiveTransformsForChildren(ideal);
ComputeEffectiveTransformForMaskLayer(aTransformToSurface);

View File

@ -55,7 +55,7 @@ public:
ContainerLayer::RepositionChild(aChild, aAfter);
}
virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface);
virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface);
/**
* Returns true when:

View File

@ -599,7 +599,7 @@ BasicLayerManager::EndTransactionInternal(DrawThebesLayerCallback aCallback,
// which depends on correct effective transforms
mSnapEffectiveTransforms =
mTarget ? !(mTarget->GetFlags() & gfxContext::FLAG_DISABLE_SNAPPING) : true;
mRoot->ComputeEffectiveTransforms(mTarget ? gfx3DMatrix::From2D(mTarget->CurrentMatrix()) : gfx3DMatrix());
mRoot->ComputeEffectiveTransforms(mTarget ? Matrix4x4::From2D(ToMatrix(mTarget->CurrentMatrix())) : Matrix4x4());
ToData(mRoot)->Validate(aCallback, aCallbackData);
if (mRoot->GetMaskLayer()) {

View File

@ -75,12 +75,13 @@ public:
mValidRegion.SetEmpty();
}
virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface)
virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface)
{
if (!BasicManager()->IsRetained()) {
// Don't do any snapping of our transform, since we're just going to
// draw straight through without intermediate buffers.
gfx::ToMatrix4x4(GetLocalTransform() * aTransformToSurface, mEffectiveTransform);
gfx::ToMatrix4x4(GetLocalTransform(), mEffectiveTransform);
mEffectiveTransform = mEffectiveTransform * aTransformToSurface;
if (gfxPoint(0,0) != mResidualTranslation) {
mResidualTranslation = gfxPoint(0,0);
mValidRegion.SetEmpty();

View File

@ -121,7 +121,7 @@ public:
virtual Layer* AsLayer() { return this; }
virtual ShadowableLayer* AsShadowableLayer() { return this; }
virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface)
virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface)
{
DefaultComputeEffectiveTransforms(aTransformToSurface);
}
@ -161,7 +161,7 @@ public:
virtual void RenderLayer() { }
virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface)
virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface)
{
DefaultComputeEffectiveTransforms(aTransformToSurface);
}

View File

@ -6,7 +6,6 @@
#include "ClientLayerManager.h"
#include "CompositorChild.h" // for CompositorChild
#include "GeckoProfiler.h" // for PROFILER_LABEL
#include "gfx3DMatrix.h" // for gfx3DMatrix
#include "gfxASurface.h" // for gfxASurface, etc
#include "ipc/AutoOpenSurface.h" // for AutoOpenSurface
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
@ -183,7 +182,7 @@ ClientLayerManager::EndTransactionInternal(DrawThebesLayerCallback aCallback,
mThebesLayerCallback = aCallback;
mThebesLayerCallbackData = aCallbackData;
GetRoot()->ComputeEffectiveTransforms(gfx3DMatrix());
GetRoot()->ComputeEffectiveTransforms(Matrix4x4());
root->RenderLayer();

View File

@ -10,7 +10,6 @@
#include "mozilla/Attributes.h" // for MOZ_OVERRIDE
#include "mozilla/layers/LayerManagerComposite.h"
class gfx3DMatrix;
struct nsIntPoint;
struct nsIntRect;
@ -40,7 +39,7 @@ public:
virtual void RenderLayer(const nsIntRect& aClipRect) MOZ_OVERRIDE;
virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface) MOZ_OVERRIDE
virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface) MOZ_OVERRIDE
{
DefaultComputeEffectiveTransforms(aTransformToSurface);
}
@ -75,7 +74,7 @@ public:
virtual void RenderLayer(const nsIntRect& aClipRect) MOZ_OVERRIDE;
virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface) MOZ_OVERRIDE
virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface) MOZ_OVERRIDE
{
DefaultComputeEffectiveTransforms(aTransformToSurface);
}

View File

@ -7,7 +7,6 @@
#include "CompositableHost.h" // for CompositableHost
#include "Layers.h" // for WriteSnapshotToDumpFile, etc
#include "gfx2DGlue.h" // for ToFilter, ToMatrix4x4
#include "gfx3DMatrix.h" // for gfx3DMatrix
#include "gfxRect.h" // for gfxRect
#include "gfxUtils.h" // for gfxUtils, etc
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
@ -103,11 +102,11 @@ ImageLayerComposite::RenderLayer(const nsIntRect& aClipRect)
clipRect);
}
void
ImageLayerComposite::ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface)
void
ImageLayerComposite::ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface)
{
gfx::Matrix4x4 local;
gfx::ToMatrix4x4(GetLocalTransform(), local);
ToMatrix4x4(GetLocalTransform(), local);
// Snap image edges to pixel boundaries
gfxRect sourceRect(0, 0, 0, 0);
@ -130,11 +129,9 @@ ImageLayerComposite::ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToS
// This makes our snapping equivalent to what would happen if our content
// was drawn into a ThebesLayer (gfxContext would snap using the local
// transform, then we'd snap again when compositing the ThebesLayer).
gfx::Matrix4x4 transformToSurface;
gfx::ToMatrix4x4(aTransformToSurface, transformToSurface);
mEffectiveTransform =
SnapTransform(local, sourceRect, nullptr) *
SnapTransformTranslation(transformToSurface, nullptr);
SnapTransformTranslation(aTransformToSurface, nullptr);
ComputeEffectiveTransformForMaskLayer(aTransformToSurface);
}

View File

@ -15,7 +15,6 @@
#include "nsISupportsImpl.h" // for TextureImage::AddRef, etc
#include "nscore.h" // for nsACString
class gfx3DMatrix;
struct nsIntPoint;
struct nsIntRect;
@ -46,7 +45,7 @@ public:
virtual void RenderLayer(const nsIntRect& aClipRect);
virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface) MOZ_OVERRIDE;
virtual void ComputeEffectiveTransforms(const mozilla::gfx::Matrix4x4& aTransformToSurface) MOZ_OVERRIDE;
virtual void CleanupResources() MOZ_OVERRIDE;

View File

@ -236,7 +236,7 @@ LayerManagerComposite::EndTransaction(DrawThebesLayerCallback aCallback,
// The results of our drawing always go directly into a pixel buffer,
// so we don't need to pass any global transform here.
mRoot->ComputeEffectiveTransforms(gfx3DMatrix());
mRoot->ComputeEffectiveTransforms(gfx::Matrix4x4());
Render();
}

View File

@ -30,7 +30,7 @@ public:
virtual void LayerManagerDestroyed();
virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface)
virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface)
{
DefaultComputeEffectiveTransforms(aTransformToSurface);
}

View File

@ -383,7 +383,7 @@ LayerManagerD3D10::EndTransaction(DrawThebesLayerCallback aCallback,
// The results of our drawing always go directly into a pixel buffer,
// so we don't need to pass any global transform here.
mRoot->ComputeEffectiveTransforms(gfx3DMatrix());
mRoot->ComputeEffectiveTransforms(Matrix4x4());
#ifdef MOZ_LAYERS_HAVE_LOG
MOZ_LAYERS_LOG((" ----- (beginning paint)"));

View File

@ -32,7 +32,7 @@ public:
virtual void LayerManagerDestroyed();
virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface)
virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface)
{
DefaultComputeEffectiveTransforms(aTransformToSurface);
}

View File

@ -148,7 +148,7 @@ LayerManagerD3D9::EndTransaction(DrawThebesLayerCallback aCallback,
// The results of our drawing always go directly into a pixel buffer,
// so we don't need to pass any global transform here.
mRoot->ComputeEffectiveTransforms(gfx3DMatrix());
mRoot->ComputeEffectiveTransforms(gfx::Matrix4x4());
SetCompositingDisabled(aFlags & END_NO_COMPOSITE);
Render();

View File

@ -61,7 +61,7 @@ class TestAPZCContainerLayer : public ContainerLayer {
{}
void RemoveChild(Layer* aChild) {}
void InsertAfter(Layer* aChild, Layer* aAfter) {}
void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface) {}
void ComputeEffectiveTransforms(const Matrix4x4& aTransformToSurface) {}
void RepositionChild(Layer* aChild, Layer* aAfter) {}
};

View File

@ -8,6 +8,7 @@
#include "gmock/gmock.h"
using namespace mozilla;
using namespace mozilla::gfx;
using namespace mozilla::layers;
class TestLayerManager: public LayerManager {
@ -47,7 +48,7 @@ public:
return TYPE_CONTAINER;
}
virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface) {
virtual void ComputeEffectiveTransforms(const Matrix4x4& aTransformToSurface) {
DefaultComputeEffectiveTransforms(aTransformToSurface);
}
@ -234,7 +235,7 @@ already_AddRefed<Layer> CreateLayerTree(
}
}
if (rootLayer) {
rootLayer->ComputeEffectiveTransforms(gfx3DMatrix());
rootLayer->ComputeEffectiveTransforms(Matrix4x4());
}
return rootLayer.forget();
}