Bug 802321 - Use FuzzyEquals to compare matrices in LayerTreeInvalidation. r=roc
authorMatt Woodrow <mwoodrow@mozilla.com>
Wed, 17 Oct 2012 21:00:00 +1300
changeset 110649 4a69dfa3ed05bd73d7a9c261eec2b981a92b210e
parent 110648 6e111238c65eff495e008096c77c295641662eb7
child 110650 48aff95d2d299395ad2bb439075b234efa97e14f
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersroc
bugs802321
milestone19.0a1
Bug 802321 - Use FuzzyEquals to compare matrices in LayerTreeInvalidation. r=roc
gfx/layers/LayerTreeInvalidation.cpp
gfx/thebes/gfx3DMatrix.cpp
gfx/thebes/gfx3DMatrix.h
--- a/gfx/layers/LayerTreeInvalidation.cpp
+++ b/gfx/layers/LayerTreeInvalidation.cpp
@@ -90,17 +90,17 @@ struct LayerPropertiesBase : public Laye
   
   virtual nsIntRect ComputeDifferences(Layer* aRoot, 
                                        NotifySubDocInvalidationFunc aCallback);
 
   virtual void MoveBy(const nsIntPoint& aOffset);
 
   nsIntRect ComputeChange(NotifySubDocInvalidationFunc aCallback)
   {
-    bool transformChanged = mTransform != mLayer->GetTransform();
+    bool transformChanged = !mTransform.FuzzyEqual(mLayer->GetTransform());
     Layer* otherMask = mLayer->GetMaskLayer();
     const nsIntRect* otherClip = mLayer->GetClipRect();
     nsIntRect result;
     if ((mMaskLayer ? mMaskLayer->mLayer : nullptr) != otherMask ||
         (mUseClipRect != !!otherClip) ||
         mLayer->GetOpacity() != mOpacity ||
         transformChanged) 
     {
--- a/gfx/thebes/gfx3DMatrix.cpp
+++ b/gfx/thebes/gfx3DMatrix.cpp
@@ -5,16 +5,17 @@
 
 #include "gfxMatrix.h"
 #include "gfx3DMatrix.h"
 #include "mozilla/gfx/Tools.h"
 #include <math.h>
 #include <algorithm>
 
 using namespace std;
+using namespace mozilla;
 using namespace mozilla::gfx;
 
 /* Force small values to zero.  We do this to avoid having sin(360deg)
  * evaluate to a tiny but nonzero value.
  */
 static double FlushToZero(double aVal)
 {
   if (-FLT_EPSILON < aVal && aVal < FLT_EPSILON)
@@ -116,16 +117,29 @@ gfx3DMatrix::operator==(const gfx3DMatri
 }
 
 bool
 gfx3DMatrix::operator!=(const gfx3DMatrix& o) const
 {
   return !((*this) == o);
 }
 
+bool
+gfx3DMatrix::FuzzyEqual(const gfx3DMatrix& o) const
+{
+  static const float error = 1e-4;
+  return gfx::FuzzyEqual(_11, o._11, error) && gfx::FuzzyEqual(_12, o._12, error) && 
+         gfx::FuzzyEqual(_13, o._13, error) && gfx::FuzzyEqual(_14, o._14, error) &&
+         gfx::FuzzyEqual(_21, o._21, error) && gfx::FuzzyEqual(_22, o._22, error) && 
+         gfx::FuzzyEqual(_23, o._23, error) && gfx::FuzzyEqual(_24, o._24, error) &&
+         gfx::FuzzyEqual(_31, o._31, error) && gfx::FuzzyEqual(_32, o._32, error) && 
+         gfx::FuzzyEqual(_33, o._33, error) && gfx::FuzzyEqual(_34, o._34, error) &&
+         gfx::FuzzyEqual(_41, o._41, error) && gfx::FuzzyEqual(_42, o._42, error) && 
+         gfx::FuzzyEqual(_43, o._43, error) && gfx::FuzzyEqual(_44, o._44, error);
+}
 
 gfx3DMatrix&
 gfx3DMatrix::operator/=(const gfxFloat scalar)
 {
   _11 /= scalar;
   _12 /= scalar;
   _13 /= scalar;
   _14 /= scalar;
--- a/gfx/thebes/gfx3DMatrix.h
+++ b/gfx/thebes/gfx3DMatrix.h
@@ -52,16 +52,18 @@ public:
       return *reinterpret_cast<const gfxPointH3D*>((&_11)+4*aIndex);
   }
 
   /**
    * Return true if this matrix and |aMatrix| are the same matrix.
    */
   bool operator==(const gfx3DMatrix& aMatrix) const;
   bool operator!=(const gfx3DMatrix& aMatrix) const;
+
+  bool FuzzyEqual(const gfx3DMatrix& aMatrix) const;
   
   /**
    * Divide all values in the matrix by a scalar value
    */
   gfx3DMatrix& operator/=(gfxFloat scalar);
 
   /**
    * Create a 3D matrix from a gfxMatrix 2D affine transformation.