Bug 979658 part 3 - Make LayerTransactionParent::RecvGetTransform convert to CSS pixels; r=dzbarsky
authorBrian Birtles <birtles@gmail.com>
Mon, 10 Mar 2014 13:47:12 +0900
changeset 189892 d6f58fa82ea761194e62f39161f9337086b53da2
parent 189891 a2395a98788163dc6c428c9e5b0d753459f8a1d9
child 189893 ef2e0154fc2e978899018b0f86ad373a600b430b
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdzbarsky
bugs979658
milestone30.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 979658 part 3 - Make LayerTransactionParent::RecvGetTransform convert to CSS pixels; r=dzbarsky LayerTransactionParent::RecvGetTransform takes care to reverse all the transformations applied by AsyncCompositionManager::SampleValue to the CSS values calculated so that it can return CSS values for testing. However, it fails to revert the conversion from CSS pixels to device pixels applied to the translation components of the transform by nsStyleTransformMatrix::ProcessTranslatePart as called by nsDisplayTransform::GetResultingTransformMatrix. This patch converts the resulting transform's translation components from device pixels back to CSS pixels. It also adds documentation for the other operations in LayerTransactionParent::RecvGetTransform.
gfx/layers/ipc/LayerTransactionParent.cpp
--- a/gfx/layers/ipc/LayerTransactionParent.cpp
+++ b/gfx/layers/ipc/LayerTransactionParent.cpp
@@ -27,16 +27,17 @@
 #include "mozilla/layers/LayersSurfaces.h"  // for PGrallocBufferParent
 #include "mozilla/layers/LayersTypes.h"  // for MOZ_LAYERS_LOG
 #include "mozilla/layers/PCompositableParent.h"
 #include "mozilla/layers/PLayerParent.h"  // for PLayerParent
 #include "mozilla/layers/ThebesLayerComposite.h"
 #include "mozilla/mozalloc.h"           // for operator delete, etc
 #include "nsCoord.h"                    // for NSAppUnitsToFloatPixels
 #include "nsDebug.h"                    // for NS_RUNTIMEABORT
+#include "nsDeviceContext.h"            // for AppUnitsPerCSSPixel
 #include "nsISupportsImpl.h"            // for Layer::Release, etc
 #include "nsLayoutUtils.h"              // for nsLayoutUtils
 #include "nsMathUtils.h"                // for NS_round
 #include "nsPoint.h"                    // for nsPoint
 #include "nsTArray.h"                   // for nsTArray, nsTArray_Impl, etc
 #include "GeckoProfiler.h"
 #include "mozilla/layers/TextureHost.h"
 #include "mozilla/layers/AsyncCompositionManager.h"
@@ -573,44 +574,65 @@ LayerTransactionParent::RecvGetTransform
 {
   if (mDestroyed || !layer_manager() || layer_manager()->IsDestroyed()) {
     return false;
   }
 
   // The following code recovers the untranslated transform
   // from the shadow transform by undoing the translations in
   // AsyncCompositionManager::SampleValue.
+
   Layer* layer = cast(aParent)->AsLayer();
   if (!layer) {
     return false;
   }
   gfx::To3DMatrix(layer->AsLayerComposite()->GetShadowTransform(), *aTransform);
   if (ContainerLayer* c = layer->AsContainerLayer()) {
+    // Undo the scale transform applied by AsyncCompositionManager::SampleValue
     aTransform->ScalePost(1.0f/c->GetInheritedXScale(),
                           1.0f/c->GetInheritedYScale(),
                           1.0f);
   }
   float scale = 1;
   gfxPoint3D scaledOrigin;
   gfxPoint3D transformOrigin;
   for (uint32_t i=0; i < layer->GetAnimations().Length(); i++) {
     if (layer->GetAnimations()[i].data().type() == AnimationData::TTransformData) {
       const TransformData& data = layer->GetAnimations()[i].data().get_TransformData();
       scale = data.appUnitsPerDevPixel();
       scaledOrigin =
         gfxPoint3D(NS_round(NSAppUnitsToFloatPixels(data.origin().x, scale)),
                    NS_round(NSAppUnitsToFloatPixels(data.origin().y, scale)),
                    0.0f);
-      transformOrigin = data.transformOrigin();
+      double cssPerDev =
+        double(nsDeviceContext::AppUnitsPerCSSPixel()) / double(scale);
+      transformOrigin = data.transformOrigin() * cssPerDev;
       break;
     }
   }
 
+  // Undo the translation to the origin of the reference frame applied by
+  // AsyncCompositionManager::SampleValue
   aTransform->Translate(-scaledOrigin);
-  *aTransform = nsLayoutUtils::ChangeMatrixBasis(-scaledOrigin - transformOrigin, *aTransform);
+
+  // Undo the rebasing applied by
+  // nsDisplayTransform::GetResultingTransformMatrixInternal
+  *aTransform =
+    nsLayoutUtils::ChangeMatrixBasis(-scaledOrigin - transformOrigin,
+                                     *aTransform);
+
+  // Convert to CSS pixels (this undoes the operations performed by
+  // nsStyleTransformMatrix::ProcessTranslatePart which is called from
+  // nsDisplayTransform::GetResultingTransformMatrix)
+  double devPerCss =
+    double(scale) / double(nsDeviceContext::AppUnitsPerCSSPixel());
+  aTransform->_41 *= devPerCss;
+  aTransform->_42 *= devPerCss;
+  aTransform->_43 *= devPerCss;
+
   return true;
 }
 
 bool
 LayerTransactionParent::Attach(ShadowLayerParent* aLayerParent,
                                CompositableParent* aCompositable,
                                bool aIsAsyncVideo)
 {