cc: Add frame data to LTHI tracing

This adds AddValue support to FrameData, RenderPass, *DrawQuad, FilterOperations, etc.
It also adds an optional 'frame' field to the LTHI state which is the frame
being produced at this point, with everything mentioned above.

BUG=None
[email protected], [email protected], [email protected]

Review URL: https://codereview.chromium.org/20667002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@216782 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc
index cc31001..d4a9498 100644
--- a/cc/trees/layer_tree_host_impl.cc
+++ b/cc/trees/layer_tree_host_impl.cc
@@ -7,6 +7,7 @@
 #include <algorithm>
 
 #include "base/basictypes.h"
+#include "base/containers/hash_tables.h"
 #include "base/json/json_writer.h"
 #include "base/metrics/histogram.h"
 #include "base/stl_util.h"
@@ -437,6 +438,25 @@
   }
 }
 
+scoped_ptr<base::Value> LayerTreeHostImpl::FrameData::AsValue() const {
+  scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
+  value->SetBoolean("contains_incomplete_tile", contains_incomplete_tile);
+  value->SetBoolean("has_no_damage", has_no_damage);
+
+  // Quad data can be quite large, so only dump render passes if we select
+  // cc.debug.quads.
+  bool quads_enabled;
+  TRACE_EVENT_CATEGORY_GROUP_ENABLED(
+      TRACE_DISABLED_BY_DEFAULT("cc.debug.quads"), &quads_enabled);
+  if (quads_enabled) {
+    scoped_ptr<base::ListValue> render_pass_list(new base::ListValue());
+    for (size_t i = 0; i < render_passes.size(); ++i)
+      render_pass_list->Append(render_passes[i]->AsValue().release());
+    value->Set("render_passes", render_pass_list.release());
+  }
+  return value.PassAs<base::Value>();
+}
+
 void LayerTreeHostImpl::FrameData::AppendRenderPass(
     scoped_ptr<RenderPass> render_pass) {
   render_passes_by_id[render_pass->id] = render_pass.get();
@@ -1257,8 +1277,9 @@
   }
 
   TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(
-      TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerTreeHostImpl", this,
-      TracedValue::FromValue(AsValue().release()));
+      TRACE_DISABLED_BY_DEFAULT("cc.debug") ","
+      TRACE_DISABLED_BY_DEFAULT("cc.debug.quads"), "cc::LayerTreeHostImpl",
+      this, TracedValue::FromValue(AsValueWithFrame(frame).release()));
 
   // Because the contents of the HUD depend on everything else in the frame, the
   // contents of its texture are updated as the last thing before the frame is
@@ -2431,7 +2452,8 @@
   return base::TimeTicks::Now();
 }
 
-scoped_ptr<base::Value> LayerTreeHostImpl::AsValue() const {
+scoped_ptr<base::Value> LayerTreeHostImpl::AsValueWithFrame(
+    FrameData* frame) const {
   scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
   if (this->pending_tree_)
       state->Set("activation_state", ActivationStateAsValue().release());
@@ -2442,6 +2464,8 @@
   state->Set("active_tree", active_tree_->AsValue().release());
   if (pending_tree_)
     state->Set("pending_tree", pending_tree_->AsValue().release());
+  if (frame)
+    state->Set("frame", frame->AsValue().release());
   return state.PassAs<base::Value>();
 }