Bug 1503046 - Part 1: Add simple hit test info diagnostics r=mattwoodrow
authorMiko Mynttinen <mikokm@gmail.com>
Fri, 02 Nov 2018 02:18:35 +0000
changeset 500461 7afff3818ad7a259f88a0ec3965c46a73b42faef
parent 500460 806c9d31d1c6e94ca3e23a24e51753145e1079c5
child 500462 b4c35701070b26d9e370c2494cbac56a05e5884a
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1503046
milestone65.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 1503046 - Part 1: Add simple hit test info diagnostics r=mattwoodrow Differential Revision: https://phabricator.services.mozilla.com/D10130
layout/base/nsLayoutUtils.cpp
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -3504,16 +3504,72 @@ GetOrCreateRetainedDisplayListBuilder(ns
       new RetainedDisplayListBuilder(aFrame, nsDisplayListBuilderMode::PAINTING,
                                      aBuildCaret);
     aFrame->SetProperty(RetainedDisplayListBuilder::Cached(), retainedBuilder);
   }
 
   return retainedBuilder;
 }
 
+// #define PRINT_HITTESTINFO_STATS
+#ifdef PRINT_HITTESTINFO_STATS
+void
+PrintHitTestInfoStatsInternal(nsDisplayList& aList,
+                              int& aTotal,
+                              int& aHitTest,
+                              int& aVisible,
+                              int& aSpecial)
+{
+  for (nsDisplayItem* i = aList.GetBottom(); i; i = i->GetAbove()) {
+    aTotal++;
+
+    if (i->GetChildren()) {
+      PrintHitTestInfoStatsInternal(
+        *i->GetChildren(), aTotal, aHitTest, aVisible, aSpecial);
+    }
+
+    if (i->GetType() == DisplayItemType::TYPE_COMPOSITOR_HITTEST_INFO) {
+      aHitTest++;
+
+      const auto& hitTestInfo =
+        static_cast<nsDisplayHitTestInfoItem*>(i)->HitTestFlags();
+
+      if (hitTestInfo.size() > 1) {
+        aSpecial++;
+        continue;
+      }
+
+      if (hitTestInfo == CompositorHitTestVisibleToHit) {
+        aVisible++;
+        continue;
+      }
+
+      aSpecial++;
+    }
+  }
+}
+
+void
+PrintHitTestInfoStats(nsDisplayList& aList)
+{
+  int total = 0;
+  int hitTest = 0;
+  int visible = 0;
+  int special = 0;
+
+  PrintHitTestInfoStatsInternal(
+    aList, total, hitTest, visible, special);
+
+  double ratio = (double)hitTest / (double)total;
+
+  printf("List %p: total items: %d, hit test items: %d, ratio: %f, visible: %d, special: %d\n",
+    &aList, total, hitTest, ratio, visible, special);
+}
+#endif
+
 nsresult
 nsLayoutUtils::PaintFrame(gfxContext* aRenderingContext, nsIFrame* aFrame,
                           const nsRegion& aDirtyRegion, nscolor aBackstop,
                           nsDisplayListBuilderMode aBuilderMode,
                           PaintFrameFlags aFlags)
 {
   AUTO_PROFILER_LABEL("nsLayoutUtils::PaintFrame", GRAPHICS);
   typedef RetainedDisplayListBuilder::PartialUpdateResult PartialUpdateResult;
@@ -3902,16 +3958,22 @@ nsLayoutUtils::PaintFrame(gfxContext* aR
   if (aFlags & PaintFrameFlags::PAINT_COMPRESSED) {
     flags |= nsDisplayList::PAINT_COMPRESSED;
   }
   if (updateState == PartialUpdateResult::NoChange &&
       !aRenderingContext) {
     flags |= nsDisplayList::PAINT_IDENTICAL_DISPLAY_LIST;
   }
 
+#ifdef PRINT_HITTESTINFO_STATS
+  if (XRE_IsContentProcess()) {
+    PrintHitTestInfoStats(list);
+  }
+#endif
+
   TimeStamp paintStart = TimeStamp::Now();
   RefPtr<LayerManager> layerManager
     = list.PaintRoot(&builder, aRenderingContext, flags);
   Telemetry::AccumulateTimeDelta(Telemetry::PAINT_RASTERIZE_TIME,
                                  paintStart);
 
   builder.Check();