Bug 1236750 - Add typedef getters for layer transform matrices. r=kats draft
authorBotond Ballo <botond@mozilla.com>
Wed, 06 Jan 2016 18:56:58 -0500
changeset 319430 a8b991a115b6374c7df774ae4bcbeca2cd4a645a
parent 319429 3cfbdf6de595324bcbafa58dcbc35ea080b96f89
child 319431 a9d765830fb7196bdcdb6de4cdbbdafc02270755
push id9040
push userbballo@mozilla.com
push dateWed, 06 Jan 2016 23:57:33 +0000
reviewerskats
bugs1236750
milestone45.0a1
Bug 1236750 - Add typedef getters for layer transform matrices. r=kats
gfx/layers/LayerMetricsWrapper.h
gfx/layers/Layers.cpp
gfx/layers/Layers.h
--- a/gfx/layers/LayerMetricsWrapper.h
+++ b/gfx/layers/LayerMetricsWrapper.h
@@ -2,16 +2,17 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef GFX_LAYERMETRICSWRAPPER_H
 #define GFX_LAYERMETRICSWRAPPER_H
 
 #include "Layers.h"
+#include "UnitTransforms.h"
 
 namespace mozilla {
 namespace layers {
 
 /**
  * A wrapper class around a target Layer with that allows user code to
  * walk through the FrameMetrics objects on the layer the same way it
  * would walk through a ContainerLayer hierarchy. Consider the following
@@ -294,16 +295,21 @@ public:
     MOZ_ASSERT(IsValid());
 
     if (AtBottomLayer()) {
       return mLayer->GetTransform();
     }
     return gfx::Matrix4x4();
   }
 
+  CSSTransformMatrix GetTransformTyped() const
+  {
+    return ViewAs<CSSTransformMatrix>(GetTransform());
+  }
+
   bool TransformIsPerspective() const
   {
     MOZ_ASSERT(IsValid());
 
     // mLayer->GetTransformIsPerspective() tells us whether
     // mLayer->GetTransform() is a perspective transform. Since
     // mLayer->GetTransform() is only used at the bottom layer, we only
     // need to check GetTransformIsPerspective() at the bottom layer too.
--- a/gfx/layers/Layers.cpp
+++ b/gfx/layers/Layers.cpp
@@ -890,16 +890,22 @@ Layer::GetTransform() const
   Matrix4x4 transform = mTransform;
   transform.PostScale(GetPostXScale(), GetPostYScale(), 1.0f);
   if (const ContainerLayer* c = AsContainerLayer()) {
     transform.PreScale(c->GetPreXScale(), c->GetPreYScale(), 1.0f);
   }
   return transform;
 }
 
+const CSSTransformMatrix
+Layer::GetTransformTyped() const
+{
+  return ViewAs<CSSTransformMatrix>(GetTransform());
+}
+
 const Matrix4x4
 Layer::GetLocalTransform()
 {
   Matrix4x4 transform;
   if (LayerComposite* shadow = AsLayerComposite())
     transform = shadow->GetShadowTransform();
   else
     transform = mTransform;
@@ -907,16 +913,22 @@ Layer::GetLocalTransform()
   transform.PostScale(GetPostXScale(), GetPostYScale(), 1.0f);
   if (ContainerLayer* c = AsContainerLayer()) {
     transform.PreScale(c->GetPreXScale(), c->GetPreYScale(), 1.0f);
   }
 
   return transform;
 }
 
+const LayerToParentLayerMatrix4x4
+Layer::GetLocalTransformTyped()
+{
+  return ViewAs<LayerToParentLayerMatrix4x4>(GetLocalTransform());
+}
+
 bool
 Layer::HasTransformAnimation() const
 {
   for (uint32_t i = 0; i < mAnimations.Length(); i++) {
     if (mAnimations[i].property() == eCSSProperty_transform) {
       return true;
     }
   }
--- a/gfx/layers/Layers.h
+++ b/gfx/layers/Layers.h
@@ -1271,16 +1271,19 @@ public:
   ContainerLayer* GetParent() { return mParent; }
   Layer* GetNextSibling() { return mNextSibling; }
   const Layer* GetNextSibling() const { return mNextSibling; }
   Layer* GetPrevSibling() { return mPrevSibling; }
   const Layer* GetPrevSibling() const { return mPrevSibling; }
   virtual Layer* GetFirstChild() const { return nullptr; }
   virtual Layer* GetLastChild() const { return nullptr; }
   const gfx::Matrix4x4 GetTransform() const;
+  // Same as GetTransform(), but returns the transform as a strongly-typed
+  // matrix. Eventually this will replace GetTransform().
+  const CSSTransformMatrix GetTransformTyped() const;
   const gfx::Matrix4x4& GetBaseTransform() const { return mTransform; }
   // Note: these are virtual because ContainerLayerComposite overrides them.
   virtual float GetPostXScale() const { return mPostXScale; }
   virtual float GetPostYScale() const { return mPostYScale; }
   bool GetIsFixedPosition() { return mIsFixedPosition; }
   bool GetTransformIsPerspective() const { return mTransformIsPerspective; }
   bool GetIsStickyPosition() { return mStickyPositionData; }
   FrameMetrics::ViewID GetFixedPositionScrollContainerId() { return mFixedPositionData ? mFixedPositionData->mScrollId : FrameMetrics::NULL_SCROLL_ID; }
@@ -1341,21 +1344,28 @@ public:
 
   uint64_t GetAnimationGeneration() { return mAnimationGeneration; }
   void SetAnimationGeneration(uint64_t aCount) { mAnimationGeneration = aCount; }
 
   bool HasTransformAnimation() const;
 
   /**
    * Returns the local transform for this layer: either mTransform or,
-   * for shadow layers, GetShadowTransform()
+   * for shadow layers, GetShadowTransform(), in either case with the
+   * pre- and post-scales applied.
    */
   const gfx::Matrix4x4 GetLocalTransform();
 
   /**
+   * Same as GetLocalTransform(), but returns a strongly-typed matrix.
+   * Eventually, this will replace GetLocalTransform().
+   */
+  const LayerToParentLayerMatrix4x4 GetLocalTransformTyped();
+
+  /**
    * Returns the local opacity for this layer: either mOpacity or,
    * for shadow layers, GetShadowOpacity()
    */
   const float GetLocalOpacity();
 
   /**
    * DRAWING PHASE ONLY
    *