Bug 960673 - Improve scrollgraph to track layer transform. r=benwa
authorMason Chang <mchang@mozilla.com>
Fri, 31 Jan 2014 21:50:06 -0500
changeset 182508 aff0cc866eb85c0c254dcb09ce7912414f253d6a
parent 182507 45840c6628d7bd1853ec535d1be010d99596e808
child 182509 dffbfd00ac4e67e06211b57d877d7d05466b4e9f
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbenwa
bugs960673
milestone29.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 960673 - Improve scrollgraph to track layer transform. r=benwa
gfx/layers/composite/ContainerLayerComposite.cpp
--- a/gfx/layers/composite/ContainerLayerComposite.cpp
+++ b/gfx/layers/composite/ContainerLayerComposite.cpp
@@ -95,52 +95,65 @@ public:
     {}
 
     TimeStamp mFrameTime;
     gfx::Point mPoint;
   };
   std::vector<VelocityData> mData;
 };
 
+static gfx::Point GetScrollData(Layer* aLayer) {
+  gfx::Matrix matrix;
+  if (aLayer->GetLocalTransform().Is2D(&matrix)) {
+    return matrix.GetTranslation();
+  }
+
+  gfx::Point origin;
+  return origin;
+}
+
+static LayerVelocityUserData* GetVelocityData(Layer* aLayer) {
+  static char sLayerVelocityUserDataKey;
+  void* key = reinterpret_cast<void*>(&sLayerVelocityUserDataKey);
+  if (!aLayer->HasUserData(key)) {
+    LayerVelocityUserData* newData = new LayerVelocityUserData();
+    aLayer->SetUserData(key, newData);
+  }
+
+  return static_cast<LayerVelocityUserData*>(aLayer->GetUserData(key));
+}
+
 static void DrawVelGraph(const nsIntRect& aClipRect,
                          LayerManagerComposite* aManager,
                          Layer* aLayer) {
-  static char sLayerVelocityUserDataKey;
   Compositor* compositor = aManager->GetCompositor();
   gfx::Rect clipRect(aClipRect.x, aClipRect.y,
                      aClipRect.width, aClipRect.height);
 
   TimeStamp now = TimeStamp::Now();
-
-  void* key = reinterpret_cast<void*>(&sLayerVelocityUserDataKey);
-  if (!aLayer->HasUserData(key)) {
-    aLayer->SetUserData(key, new LayerVelocityUserData());
-  }
-
-  LayerVelocityUserData* velocityData =
-    static_cast<LayerVelocityUserData*>(aLayer->GetUserData(key));
+  LayerVelocityUserData* velocityData = GetVelocityData(aLayer);
 
   if (velocityData->mData.size() >= 1 &&
     now > velocityData->mData[velocityData->mData.size() - 1].mFrameTime +
       TimeDuration::FromMilliseconds(200)) {
     // clear stale data
     velocityData->mData.clear();
   }
 
-  nsIntPoint scrollOffset =
-    aLayer->GetEffectiveVisibleRegion().GetBounds().TopLeft();
+  const gfx::Point layerTransform = GetScrollData(aLayer);
   velocityData->mData.push_back(
-    LayerVelocityUserData::VelocityData(now, scrollOffset.x, scrollOffset.y));
+    LayerVelocityUserData::VelocityData(now,
+      static_cast<int>(layerTransform.x), static_cast<int>(layerTransform.y)));
 
-
+  // TODO: dump to file
   // XXX: Uncomment these lines to enable ScrollGraph logging. This is
   //      useful for HVGA phones or to output the data to accurate
   //      graphing software.
-  //printf_stderr("ScrollGraph (%p): %i, %i\n",
-  //  aLayer, scrollOffset.x, scrollOffset.y);
+  // printf_stderr("ScrollGraph (%p): %f, %f\n",
+  // aLayer, layerTransform.x, layerTransform.y);
 
   // Keep a circular buffer of 100.
   size_t circularBufferSize = 100;
   if (velocityData->mData.size() > circularBufferSize) {
     velocityData->mData.erase(velocityData->mData.begin());
   }
 
   if (velocityData->mData.size() == 1) {
@@ -190,17 +203,16 @@ static void DrawVelGraph(const nsIntRect
                    (p1.y - p2.y) * (p1.y - p2.y));
     graph.push_back(
       gfx::Point(bounds.x + graphRect.width / circularBufferSize * i,
                  graphBounds.y + graphRect.height - vel/yScaleFactor));
   }
 
   compositor->DrawLines(graph, clipRect, gfx::Color(0,1,0,1),
                         opacity, transform);
-
 }
 
 template<class ContainerT> void
 ContainerRender(ContainerT* aContainer,
                 LayerManagerComposite* aManager,
                 const nsIntRect& aClipRect)
 {
   /**