Clean up the compositor's transformation calculations.
authorAli Juma <ajuma@mozilla.com>
Fri, 17 Feb 2012 17:58:03 -0500
changeset 89162 ed42513a664612def0c97d64084b50680eaa4dd2
parent 89161 24039604393a8bc73c8fce82d6e5930280767776
child 89163 b2dc4db842b941f7dbf8eb57ea8d5ce97d29b56c
push id22242
push userkgupta@mozilla.com
push dateWed, 14 Mar 2012 15:19:09 +0000
treeherdermozilla-central@936ef50fa498 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone13.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
Clean up the compositor's transformation calculations.
gfx/layers/ipc/CompositorParent.cpp
gfx/layers/ipc/CompositorParent.h
--- a/gfx/layers/ipc/CompositorParent.cpp
+++ b/gfx/layers/ipc/CompositorParent.cpp
@@ -179,20 +179,18 @@ CompositorParent::Composite()
 
 #ifdef MOZ_RENDERTRACE
   Layer* aLayer = mLayerManager->GetRoot();
   mozilla::layers::RenderTraceLayers(aLayer, "0000");
 #endif
 
 #ifdef MOZ_WIDGET_ANDROID
   RequestViewTransform();
-  Layer* layer = GetPrimaryScrollableLayer();
   printf_stderr("Correcting for position fixed %i, %i\n", -mScrollOffset.x, -mScrollOffset.y);
-  ViewTransform v(mScrollOffset, mXScale, mYScale);
-  TransformShadowTree(layer, v);
+  TransformShadowTree();
 #endif
 
   mLayerManager->EndEmptyTransaction();
 
 #ifdef COMPOSITOR_PERFORMANCE_WARNING
   if (mExpectedComposeTime + TimeDuration::FromMilliseconds(15) < mozilla::TimeStamp::Now()) {
     printf_stderr("Compositor: Compose frame took %i time then expected.\n",
                   (int)(mozilla::TimeStamp::Now() - mExpectedComposeTime).ToMilliseconds());
@@ -254,77 +252,42 @@ static double GetXScale(const gfx3DMatri
   return aTransform._11;
 }
 
 static double GetYScale(const gfx3DMatrix& aTransform)
 {
   return aTransform._22;
 }
 
-static void ReverseTranslate(gfx3DMatrix& aTransform, ViewTransform& aViewTransform)
+void
+CompositorParent::TransformShadowTree()
 {
-  aTransform._41 -= aViewTransform.mTranslation.x / aViewTransform.mXScale;
-  aTransform._42 -= aViewTransform.mTranslation.y / aViewTransform.mYScale;
-}
-
-void
-CompositorParent::TransformShadowTree(Layer* aLayer, const ViewTransform& aTransform,
-                    float aTempScaleDiffX, float aTempScaleDiffY)
-{
-  ShadowLayer* shadow = aLayer->AsShadowLayer();
+  Layer* layer = GetPrimaryScrollableLayer();
+  ShadowLayer* shadow = layer->AsShadowLayer();
 
-  gfx3DMatrix shadowTransform = aLayer->GetTransform();
-  ViewTransform layerTransform = aTransform;
-
-  ContainerLayer* container = aLayer->AsContainerLayer();
+  gfx3DMatrix shadowTransform = layer->GetTransform();
 
-  if (container && container->GetFrameMetrics().IsScrollable()) {
-    const FrameMetrics* metrics = &container->GetFrameMetrics();
-    const gfx3DMatrix& currentTransform = aLayer->GetTransform();
-
-    aTempScaleDiffX *= GetXScale(mLayerManager->GetRoot()->GetTransform()) * mXScale;
-    aTempScaleDiffY *= GetYScale(mLayerManager->GetRoot()->GetTransform()) * mYScale;
+  ContainerLayer* container = layer->AsContainerLayer();
 
-    nsIntPoint metricsScrollOffset = metrics->mViewportScrollOffset;
+  const FrameMetrics* metrics = &container->GetFrameMetrics();
+  const gfx3DMatrix& currentTransform = layer->GetTransform();
 
-    nsIntPoint scrollCompensation(
-        (mScrollOffset.x / aTempScaleDiffX - metricsScrollOffset.x) * mXScale,
-        (mScrollOffset.y / aTempScaleDiffY - metricsScrollOffset.y) * mYScale);
-    ViewTransform treeTransform(-scrollCompensation, mXScale,
-                                mYScale);
-    shadowTransform = gfx3DMatrix(treeTransform) * currentTransform;
-    layerTransform = treeTransform;
-  }
+  float tempScaleDiffX = GetXScale(mLayerManager->GetRoot()->GetTransform()) * mXScale;
+  float tempScaleDiffY = GetYScale(mLayerManager->GetRoot()->GetTransform()) * mYScale;
 
-  // Uncomment to deal with position:fixed.
-  /*
-  if (aLayer->GetIsFixedPosition() &&
-      !aLayer->GetParent()->GetIsFixedPosition()) {
-    printf_stderr("Correcting for position fixed\n");
-    ReverseTranslate(shadowTransform, layerTransform);
-    const nsIntRect* clipRect = shadow->GetShadowClipRect();
-    if (clipRect) {
-      nsIntRect transformedClipRect(*clipRect);
-      transformedClipRect.MoveBy(shadowTransform._41, shadowTransform._42);
-      shadow->SetShadowClipRect(&transformedClipRect);
-    }
-  }*/
+  nsIntPoint metricsScrollOffset = metrics->mViewportScrollOffset;
+
+  nsIntPoint scrollCompensation(
+    (mScrollOffset.x / tempScaleDiffX - metricsScrollOffset.x) * mXScale,
+    (mScrollOffset.y / tempScaleDiffY - metricsScrollOffset.y) * mYScale);
+  ViewTransform treeTransform(-scrollCompensation, mXScale,
+                              mYScale);
+  shadowTransform = gfx3DMatrix(treeTransform) * currentTransform;
 
   shadow->SetShadowTransform(shadowTransform);
-
-  // Uncomment the following when we want to deal with position:fixed.
-  // Note that we need to modify other code to ensure that position:fixed
-  // things get their own layer. See Bug 607417.
-  /*
-  for (Layer* child = aLayer->GetFirstChild(); child;
-       child = child->GetNextSibling()) {
-    TransformShadowTree(child, layerTransform, aTempScaleDiffX,
-                       aTempScaleDiffY);
-  }*/
-
 }
 
 void
 CompositorParent::AsyncRender()
 {
   if (mPaused || !mLayerManager) {
     return;
   }
--- a/gfx/layers/ipc/CompositorParent.h
+++ b/gfx/layers/ipc/CompositorParent.h
@@ -109,19 +109,17 @@ protected:
   virtual bool DeallocPLayers(PLayersParent* aLayers);
 
 private:
   void PauseComposition();
   void ResumeComposition();
 
   void Composite();
   void ScheduleComposition();
-  void TransformShadowTree(Layer* aLayer, const ViewTransform& aTransform,
-                           float aTempScaleDiffX = 1.0,
-                           float aTempScaleDiffY = 1.0);
+  void TransformShadowTree();
 
   // Platform specific functions
 #ifdef MOZ_WIDGET_ANDROID
   /**
    * Asks Java for the viewport position and updates the world transform
    * accordingly.
    */
   void RequestViewTransform();