Commit 1bcbbc27 authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

[CI] Refactor PaintPropertyTreePrinter

- Move PropertyTreeStatePrinter from PropertyTreeState.h into
  PaintPropertyNode.h and rename it to PropertyTreePrinter.

- Remove duplicated code originally in
  platform/.../PropertyTreeState.h and core/.../PaintPropertyTreePrinter.cpp
  and let PaintPropertyTreePrinter use the new PropertyTreePrinter in
  platform/.../PaintPropertyNode.h

- Add PaintPropertyNode::DebugName (DCHECK only) to store annotations
  for the node, so that we can also see them in the result of ToString()
  and ToTreeString(). This will help debugging property tree states
  in platform/ code.

- Remove paintPropertyTreeGraph which is out-dated and unlikely to be
  maintained.

- Other code cleanup and simplification

Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2
Change-Id: I02cdf3f054110a63190997db9f7543b6c254eb22
Reviewed-on: https://chromium-review.googlesource.com/897825
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: default avatarvmpstr <vmpstr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533939}
parent 86cd6434
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "core/paint/FindPropertiesNeedingUpdate.h" #include "core/paint/FindPropertiesNeedingUpdate.h"
#include "core/paint/ObjectPaintProperties.h" #include "core/paint/ObjectPaintProperties.h"
#include "core/paint/PaintLayer.h" #include "core/paint/PaintLayer.h"
#include "core/paint/PaintPropertyTreePrinter.h"
#include "core/paint/SVGRootPainter.h" #include "core/paint/SVGRootPainter.h"
#include "core/paint/compositing/CompositedLayerMapping.h" #include "core/paint/compositing/CompositedLayerMapping.h"
#include "core/paint/compositing/CompositingReasonFinder.h" #include "core/paint/compositing/CompositingReasonFinder.h"
...@@ -278,6 +279,10 @@ void FrameViewPaintPropertyTreeBuilder::Update( ...@@ -278,6 +279,10 @@ void FrameViewPaintPropertyTreeBuilder::Update(
std::unique_ptr<PropertyTreeState> contents_state(new PropertyTreeState( std::unique_ptr<PropertyTreeState> contents_state(new PropertyTreeState(
context.current.transform, context.current.clip, context.current_effect)); context.current.transform, context.current.clip, context.current_effect));
frame_view.SetTotalPropertyTreeStateForContents(std::move(contents_state)); frame_view.SetTotalPropertyTreeStateForContents(std::move(contents_state));
#if DCHECK_IS_ON()
PaintPropertyTreePrinter::UpdateDebugNames(frame_view);
#endif
} }
namespace { namespace {
...@@ -299,6 +304,10 @@ class FragmentPaintPropertyTreeBuilder { ...@@ -299,6 +304,10 @@ class FragmentPaintPropertyTreeBuilder {
~FragmentPaintPropertyTreeBuilder() { ~FragmentPaintPropertyTreeBuilder() {
full_context_.force_subtree_update |= property_added_or_removed_; full_context_.force_subtree_update |= property_added_or_removed_;
#if DCHECK_IS_ON()
if (properties_)
PaintPropertyTreePrinter::UpdateDebugNames(object_, *properties_);
#endif
} }
ALWAYS_INLINE void UpdateForSelf(); ALWAYS_INLINE void UpdateForSelf();
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "core/layout/LayoutEmbeddedContent.h" #include "core/layout/LayoutEmbeddedContent.h"
#include "core/layout/LayoutView.h" #include "core/layout/LayoutView.h"
#include "core/paint/ObjectPaintProperties.h" #include "core/paint/ObjectPaintProperties.h"
#include "platform/graphics/paint/PropertyTreeState.h"
#include <iomanip> #include <iomanip>
#include <sstream> #include <sstream>
...@@ -23,104 +22,42 @@ template <typename PropertyTreeNode> ...@@ -23,104 +22,42 @@ template <typename PropertyTreeNode>
class PropertyTreePrinterTraits; class PropertyTreePrinterTraits;
template <typename PropertyTreeNode> template <typename PropertyTreeNode>
class PropertyTreePrinter { class FrameViewPropertyTreePrinter
: public PropertyTreePrinter<PropertyTreeNode> {
public: public:
String TreeAsString(const LocalFrameView& frame_view) { String TreeAsString(const LocalFrameView& frame_view) {
CollectPropertyNodes(frame_view); CollectNodes(frame_view);
return PropertyTreePrinter<PropertyTreeNode>::NodesAsTreeString();
const PropertyTreeNode* root_node = LookupRootNode();
if (!root_node)
return "";
if (!node_to_debug_string_.Contains(root_node))
AddPropertyNode(root_node, "root");
StringBuilder string_builder;
AddAllPropertyNodes(string_builder, root_node);
return string_builder.ToString();
}
String PathAsString(const PropertyTreeNode* last_node) {
const PropertyTreeNode* node = last_node;
while (!node->IsRoot()) {
AddPropertyNode(node, "");
node = node->Parent();
}
AddPropertyNode(node, "root");
StringBuilder string_builder;
AddAllPropertyNodes(string_builder, node);
return string_builder.ToString();
}
void AddPropertyNode(const PropertyTreeNode* node, const String& debug_info) {
node_to_debug_string_.Set(node, debug_info);
}
void AddPropertyNode(const PropertyTreeNode* node,
const String& name,
const LayoutObject& object) {
node_to_debug_string_.Set(node, name + " (" + object.DebugName() + ")");
} }
private: private:
using Traits = PropertyTreePrinterTraits<PropertyTreeNode>; using Traits = PropertyTreePrinterTraits<PropertyTreeNode>;
void CollectPropertyNodes(const LocalFrameView& frame_view) { void CollectNodes(const LocalFrameView& frame_view) {
Traits::AddFrameViewProperties(frame_view, *this); Traits::AddFrameViewProperties(frame_view, *this);
if (LayoutView* layout_view = frame_view.GetLayoutView()) if (LayoutView* layout_view = frame_view.GetLayoutView())
CollectPropertyNodes(*layout_view); CollectNodes(*layout_view);
for (Frame* child = frame_view.GetFrame().Tree().FirstChild(); child; for (Frame* child = frame_view.GetFrame().Tree().FirstChild(); child;
child = child->Tree().NextSibling()) { child = child->Tree().NextSibling()) {
if (!child->IsLocalFrame()) if (!child->IsLocalFrame())
continue; continue;
if (LocalFrameView* child_view = ToLocalFrame(child)->View()) if (LocalFrameView* child_view = ToLocalFrame(child)->View())
CollectPropertyNodes(*child_view); CollectNodes(*child_view);
} }
} }
void CollectPropertyNodes(const LayoutObject& object) { void CollectNodes(const LayoutObject& object) {
for (const auto* fragment = &object.FirstFragment(); fragment; for (const auto* fragment = &object.FirstFragment(); fragment;
fragment = fragment->NextFragment()) { fragment = fragment->NextFragment()) {
if (const auto* properties = fragment->PaintProperties()) if (const auto* properties = fragment->PaintProperties())
Traits::AddObjectPaintProperties(object, *properties, *this); Traits::AddObjectPaintProperties(object, *properties, *this);
} }
for (const auto* child = object.SlowFirstChild(); child; for (const auto* child = object.SlowFirstChild(); child;
child = child->NextSibling()) child = child->NextSibling()) {
CollectPropertyNodes(*child); CollectNodes(*child);
}
void AddAllPropertyNodes(StringBuilder& string_builder,
const PropertyTreeNode* node,
unsigned indent = 0) {
DCHECK(node);
for (unsigned i = 0; i < indent; i++)
string_builder.Append(' ');
if (node_to_debug_string_.Contains(node))
string_builder.Append(node_to_debug_string_.at(node));
string_builder.Append(String::Format(" %p ", node));
string_builder.Append(node->ToString());
string_builder.Append("\n");
for (const auto* child_node : node_to_debug_string_.Keys()) {
if (child_node->Parent() == node)
AddAllPropertyNodes(string_builder, child_node, indent + 2);
} }
} }
// Root nodes may not be directly accessible but they can be determined by
// walking up to the parent of a previously collected node.
const PropertyTreeNode* LookupRootNode() {
for (const auto* node : node_to_debug_string_.Keys()) {
if (node->IsRoot())
return node;
if (node->Parent() && node->Parent()->IsRoot())
return node->Parent();
}
return nullptr;
}
HashMap<const PropertyTreeNode*, String> node_to_debug_string_;
}; };
template <> template <>
...@@ -129,29 +66,19 @@ class PropertyTreePrinterTraits<TransformPaintPropertyNode> { ...@@ -129,29 +66,19 @@ class PropertyTreePrinterTraits<TransformPaintPropertyNode> {
static void AddFrameViewProperties( static void AddFrameViewProperties(
const LocalFrameView& frame_view, const LocalFrameView& frame_view,
PropertyTreePrinter<TransformPaintPropertyNode>& printer) { PropertyTreePrinter<TransformPaintPropertyNode>& printer) {
if (const TransformPaintPropertyNode* pre_translation = printer.AddNode(frame_view.PreTranslation());
frame_view.PreTranslation()) printer.AddNode(frame_view.ScrollTranslation());
printer.AddPropertyNode(pre_translation, "PreTranslation (FrameView)");
if (const TransformPaintPropertyNode* scroll_translation =
frame_view.ScrollTranslation())
printer.AddPropertyNode(scroll_translation,
"ScrollTranslation (FrameView)");
} }
static void AddObjectPaintProperties( static void AddObjectPaintProperties(
const LayoutObject& object, const LayoutObject& object,
const ObjectPaintProperties& properties, const ObjectPaintProperties& properties,
PropertyTreePrinter<TransformPaintPropertyNode>& printer) { PropertyTreePrinter<TransformPaintPropertyNode>& printer) {
if (const auto* t = properties.PaintOffsetTranslation()) printer.AddNode(properties.PaintOffsetTranslation());
printer.AddPropertyNode(t, "PaintOffsetTranslation", object); printer.AddNode(properties.Transform());
if (const auto* t = properties.Transform()) printer.AddNode(properties.Perspective());
printer.AddPropertyNode(t, "Transform", object); printer.AddNode(properties.SvgLocalToBorderBoxTransform());
if (const auto* t = properties.Perspective()) printer.AddNode(properties.ScrollTranslation());
printer.AddPropertyNode(t, "Perspective", object);
if (const auto* t = properties.SvgLocalToBorderBoxTransform())
printer.AddPropertyNode(t, "SvgLocalToBorderBoxTransform", object);
if (const auto* t = properties.ScrollTranslation())
printer.AddPropertyNode(t, "ScrollTranslation", object);
} }
}; };
...@@ -161,28 +88,20 @@ class PropertyTreePrinterTraits<ClipPaintPropertyNode> { ...@@ -161,28 +88,20 @@ class PropertyTreePrinterTraits<ClipPaintPropertyNode> {
static void AddFrameViewProperties( static void AddFrameViewProperties(
const LocalFrameView& frame_view, const LocalFrameView& frame_view,
PropertyTreePrinter<ClipPaintPropertyNode>& printer) { PropertyTreePrinter<ClipPaintPropertyNode>& printer) {
if (const ClipPaintPropertyNode* content_clip = frame_view.ContentClip()) printer.AddNode(frame_view.ContentClip());
printer.AddPropertyNode(content_clip, "ContentClip (FrameView)");
} }
static void AddObjectPaintProperties( static void AddObjectPaintProperties(
const LayoutObject& object, const LayoutObject& object,
const ObjectPaintProperties& properties, const ObjectPaintProperties& properties,
PropertyTreePrinter<ClipPaintPropertyNode>& printer) { PropertyTreePrinter<ClipPaintPropertyNode>& printer) {
if (const auto* c = properties.FragmentClip()) printer.AddNode(properties.FragmentClip());
printer.AddPropertyNode(c, "FragmentClip", object); printer.AddNode(properties.MaskClip());
if (const auto* c = properties.MaskClip()) printer.AddNode(properties.CssClip());
printer.AddPropertyNode(c, "MaskClip", object); printer.AddNode(properties.CssClipFixedPosition());
if (const auto* c = properties.CssClip()) printer.AddNode(properties.OverflowControlsClip());
printer.AddPropertyNode(c, "CssClip", object); printer.AddNode(properties.InnerBorderRadiusClip());
if (const auto* c = properties.CssClipFixedPosition()) printer.AddNode(properties.OverflowClip());
printer.AddPropertyNode(c, "CssClipFixedPosition", object);
if (const auto* c = properties.OverflowControlsClip())
printer.AddPropertyNode(c, "OverflowControlsClip", object);
if (const auto* c = properties.InnerBorderRadiusClip())
printer.AddPropertyNode(c, "InnerBorderRadiusClip", object);
if (const auto* c = properties.OverflowClip())
printer.AddPropertyNode(c, "OverflowClip", object);
} }
}; };
...@@ -197,12 +116,9 @@ class PropertyTreePrinterTraits<EffectPaintPropertyNode> { ...@@ -197,12 +116,9 @@ class PropertyTreePrinterTraits<EffectPaintPropertyNode> {
const LayoutObject& object, const LayoutObject& object,
const ObjectPaintProperties& properties, const ObjectPaintProperties& properties,
PropertyTreePrinter<EffectPaintPropertyNode>& printer) { PropertyTreePrinter<EffectPaintPropertyNode>& printer) {
if (const auto* e = properties.Effect()) printer.AddNode(properties.Effect());
printer.AddPropertyNode(e, "Effect", object); printer.AddNode(properties.Filter());
if (const auto* e = properties.Filter()) printer.AddNode(properties.Mask());
printer.AddPropertyNode(e, "Filter", object);
if (const auto* e = properties.Mask())
printer.AddPropertyNode(e, "Mask", object);
} }
}; };
...@@ -212,312 +128,69 @@ class PropertyTreePrinterTraits<ScrollPaintPropertyNode> { ...@@ -212,312 +128,69 @@ class PropertyTreePrinterTraits<ScrollPaintPropertyNode> {
static void AddFrameViewProperties( static void AddFrameViewProperties(
const LocalFrameView& frame_view, const LocalFrameView& frame_view,
PropertyTreePrinter<ScrollPaintPropertyNode>& printer) { PropertyTreePrinter<ScrollPaintPropertyNode>& printer) {
if (const auto* s = frame_view.ScrollNode()) printer.AddNode(frame_view.ScrollNode());
printer.AddPropertyNode(s, "Scroll (FrameView)");
} }
static void AddObjectPaintProperties( static void AddObjectPaintProperties(
const LayoutObject& object, const LayoutObject& object,
const ObjectPaintProperties& properties, const ObjectPaintProperties& properties,
PropertyTreePrinter<ScrollPaintPropertyNode>& printer) { PropertyTreePrinter<ScrollPaintPropertyNode>& printer) {
if (const auto* s = properties.Scroll()) printer.AddNode(properties.Scroll());
printer.AddPropertyNode(s, "Scroll", object);
} }
}; };
class PaintPropertyTreeGraphBuilder { template <typename PropertyTreeNode>
public: void SetDebugName(const PropertyTreeNode* node, const String& debug_name) {
PaintPropertyTreeGraphBuilder() = default; if (node)
const_cast<PropertyTreeNode*>(node)->SetDebugName(debug_name);
void GenerateTreeGraph(const LocalFrameView& frame_view, }
StringBuilder& string_builder) {
layout_.str("");
properties_.str("");
owner_edges_.str("");
properties_ << std::setprecision(2)
<< std::setiosflags(std::ios_base::fixed);
WriteFrameViewNode(frame_view, nullptr);
string_builder.Append("digraph {\n");
string_builder.Append("graph [rankdir=BT];\n");
string_builder.Append("subgraph cluster_layout {\n");
std::string layout_str = layout_.str();
string_builder.Append(layout_str.c_str(), layout_str.length());
string_builder.Append("}\n");
string_builder.Append("subgraph cluster_properties {\n");
std::string properties_str = properties_.str();
string_builder.Append(properties_str.c_str(), properties_str.length());
string_builder.Append("}\n");
std::string owners_str = owner_edges_.str();
string_builder.Append(owners_str.c_str(), owners_str.length());
string_builder.Append("}\n");
}
private:
static String GetTagName(Node* n) {
if (n->IsDocumentNode())
return "";
if (n->getNodeType() == Node::kCommentNode)
return "COMMENT";
return n->nodeName();
}
static void WriteParentEdge(const void* node,
const void* parent,
const char* color,
std::ostream& os) {
os << "n" << node << " -> "
<< "n" << parent;
if (color)
os << " [color=" << color << "]";
os << ";" << std::endl;
}
void WriteOwnerEdge(const void* node, const void* owner) {
std::ostream& os = owner_edges_;
os << "n" << owner << " -> "
<< "n" << node << " [color=" << layout_node_color_
<< ", arrowhead=dot, constraint=false];" << std::endl;
}
void WriteTransformEdge(const void* node, const void* transform) {
std::ostream& os = properties_;
os << "n" << node << " -> "
<< "n" << transform << " [color=" << transform_node_color_ << "];"
<< std::endl;
}
void WritePaintPropertyNode(const TransformPaintPropertyNode& node,
const void* owner,
const char* label) {
std::ostream& os = properties_;
os << "n" << &node << " [color=" << transform_node_color_
<< ", fontcolor=" << transform_node_color_ << ", shape=box, label=\""
<< label << "\\n";
const FloatPoint3D& origin = node.Origin();
os << "origin=(";
os << origin.X() << "," << origin.Y() << "," << origin.Z() << ")\\n";
os << "flattensInheritedTransform="
<< (node.FlattensInheritedTransform() ? "true" : "false") << "\\n";
os << "renderingContextId=" << node.RenderingContextId() << "\\n";
const TransformationMatrix& matrix = node.Matrix();
os << "[" << std::setw(8) << matrix.M11() << "," << std::setw(8)
<< matrix.M12() << "," << std::setw(8) << matrix.M13() << ","
<< std::setw(8) << matrix.M14() << "\\n";
os << std::setw(9) << matrix.M21() << "," << std::setw(8) << matrix.M22()
<< "," << std::setw(8) << matrix.M23() << "," << std::setw(8)
<< matrix.M24() << "\\n";
os << std::setw(9) << matrix.M31() << "," << std::setw(8) << matrix.M32()
<< "," << std::setw(8) << matrix.M33() << "," << std::setw(8)
<< matrix.M34() << "\\n";
os << std::setw(9) << matrix.M41() << "," << std::setw(8) << matrix.M42()
<< "," << std::setw(8) << matrix.M43() << "," << std::setw(8)
<< matrix.M44() << "]";
TransformationMatrix::DecomposedType decomposition;
if (!node.Matrix().Decompose(decomposition))
os << "\\n(degenerate)";
os << "\"];" << std::endl;
if (owner)
WriteOwnerEdge(&node, owner);
if (node.Parent())
WriteParentEdge(&node, node.Parent(), transform_node_color_, os);
}
void WritePaintPropertyNode(const ClipPaintPropertyNode& node,
const void* owner,
const char* label) {
std::ostream& os = properties_;
os << "n" << &node << " [color=" << clip_node_color_
<< ", fontcolor=" << clip_node_color_ << ", shape=box, label=\"" << label
<< "\\n";
LayoutRect rect(node.ClipRect().Rect());
if (IntRect(rect) == LayoutRect::InfiniteIntRect())
os << "(infinite)";
else
os << "(" << rect.X() << ", " << rect.Y() << ", " << rect.Width() << ", "
<< rect.Height() << ")";
os << "\"];" << std::endl;
if (owner)
WriteOwnerEdge(&node, owner);
if (node.Parent())
WriteParentEdge(&node, node.Parent(), clip_node_color_, os);
if (node.LocalTransformSpace())
WriteTransformEdge(&node, node.LocalTransformSpace());
}
void WritePaintPropertyNode(const EffectPaintPropertyNode& node,
const void* owner,
const char* label) {
std::ostream& os = properties_;
os << "n" << &node << " [shape=diamond, label=\"" << label << "\\n";
os << "opacity=" << node.Opacity() << "\"];" << std::endl;
if (owner)
WriteOwnerEdge(&node, owner);
if (node.Parent())
WriteParentEdge(&node, node.Parent(), effect_node_color_, os);
}
void WritePaintPropertyNode(const ScrollPaintPropertyNode&,
const void*,
const char*) {
// TODO(pdr): fill this out.
}
void WriteObjectPaintPropertyNodes(const LayoutObject& object) {
const ObjectPaintProperties* properties =
object.FirstFragment().PaintProperties();
if (!properties)
return;
const TransformPaintPropertyNode* paint_offset =
properties->PaintOffsetTranslation();
if (paint_offset)
WritePaintPropertyNode(*paint_offset, &object, "paintOffset");
const TransformPaintPropertyNode* transform = properties->Transform();
if (transform)
WritePaintPropertyNode(*transform, &object, "transform");
const TransformPaintPropertyNode* perspective = properties->Perspective();
if (perspective)
WritePaintPropertyNode(*perspective, &object, "perspective");
const TransformPaintPropertyNode* svg_local_to_border_box =
properties->SvgLocalToBorderBoxTransform();
if (svg_local_to_border_box)
WritePaintPropertyNode(*svg_local_to_border_box, &object,
"svgLocalToBorderBox");
const TransformPaintPropertyNode* scroll_translation =
properties->ScrollTranslation();
if (scroll_translation)
WritePaintPropertyNode(*scroll_translation, &object, "scrollTranslation");
const EffectPaintPropertyNode* effect = properties->Effect();
if (effect)
WritePaintPropertyNode(*effect, &object, "effect");
const ClipPaintPropertyNode* css_clip = properties->CssClip();
if (css_clip)
WritePaintPropertyNode(*css_clip, &object, "cssClip");
const ClipPaintPropertyNode* css_clip_fixed_position =
properties->CssClipFixedPosition();
if (css_clip_fixed_position)
WritePaintPropertyNode(*css_clip_fixed_position, &object,
"cssClipFixedPosition");
const ClipPaintPropertyNode* overflow_clip = properties->OverflowClip();
if (overflow_clip) {
if (const ClipPaintPropertyNode* inner_border_radius_clip =
properties->InnerBorderRadiusClip())
WritePaintPropertyNode(*inner_border_radius_clip, &object,
"innerBorderRadiusClip");
WritePaintPropertyNode(*overflow_clip, &object, "overflowClip");
if (object.IsLayoutView() && overflow_clip->Parent())
WritePaintPropertyNode(*overflow_clip->Parent(), nullptr, "rootClip");
}
const auto* scroll =
scroll_translation ? scroll_translation->ScrollNode() : nullptr;
if (scroll)
WritePaintPropertyNode(*scroll, &object, "scroll");
}
template <typename PropertyTreeNode> template <typename PropertyTreeNode>
static const PropertyTreeNode* GetRoot(const PropertyTreeNode* node) { void SetDebugName(const PropertyTreeNode* node,
while (node && !node->IsRoot()) const String& name,
node = node->Parent(); const LayoutObject& object) {
return node; if (node)
} SetDebugName(node, name + " (" + object.DebugName() + ")");
}
void WriteFrameViewPaintPropertyNodes(const LocalFrameView& frame_view) { } // namespace
if (const auto* contents_state =
frame_view.TotalPropertyTreeStateForContents()) {
if (const auto* root = GetRoot(contents_state->Transform()))
WritePaintPropertyNode(*root, &frame_view, "rootTransform");
if (const auto* root = GetRoot(contents_state->Clip()))
WritePaintPropertyNode(*root, &frame_view, "rootClip");
if (const auto* root = GetRoot(contents_state->Effect()))
WritePaintPropertyNode(*root, &frame_view, "rootEffect");
}
TransformPaintPropertyNode* pre_translation = frame_view.PreTranslation();
if (pre_translation)
WritePaintPropertyNode(*pre_translation, &frame_view, "preTranslation");
TransformPaintPropertyNode* scroll_translation =
frame_view.ScrollTranslation();
if (scroll_translation)
WritePaintPropertyNode(*scroll_translation, &frame_view,
"scrollTranslation");
ClipPaintPropertyNode* content_clip = frame_view.ContentClip();
if (content_clip)
WritePaintPropertyNode(*content_clip, &frame_view, "contentClip");
const auto* scroll =
scroll_translation ? scroll_translation->ScrollNode() : nullptr;
if (scroll)
WritePaintPropertyNode(*scroll, &frame_view, "scroll");
}
void WriteLayoutObjectNode(const LayoutObject& object) { namespace PaintPropertyTreePrinter {
std::ostream& os = layout_;
os << "n" << &object << " [color=" << layout_node_color_
<< ", fontcolor=" << layout_node_color_ << ", label=\""
<< object.GetName();
Node* node = object.GetNode();
if (node) {
os << "\\n" << GetTagName(node).Utf8().data();
if (node->IsElementNode() && ToElement(node)->HasID())
os << "\\nid=" << ToElement(node)->GetIdAttribute().Utf8().data();
}
os << "\"];" << std::endl;
const void* parent = object.IsLayoutView()
? (const void*)ToLayoutView(object).GetFrameView()
: (const void*)object.Parent();
WriteParentEdge(&object, parent, layout_node_color_, os);
WriteObjectPaintPropertyNodes(object);
for (const LayoutObject* child = object.SlowFirstChild(); child;
child = child->NextSibling())
WriteLayoutObjectNode(*child);
if (object.IsLayoutEmbeddedContent()) {
FrameView* frame_view = ToLayoutEmbeddedContent(object).ChildFrameView();
if (frame_view && frame_view->IsLocalFrameView())
WriteFrameViewNode(*ToLocalFrameView(frame_view), &object);
}
}
void WriteFrameViewNode(const LocalFrameView& frame_view, void UpdateDebugNames(const LocalFrameView& frame_view) {
const void* parent) { SetDebugName(frame_view.PreTranslation(), "PreTranslation (FrameView)");
std::ostream& os = layout_; SetDebugName(frame_view.ScrollTranslation(), "ScrollTranslation (FrameView)");
os << "n" << &frame_view << " [color=" << layout_node_color_ SetDebugName(frame_view.ContentClip(), "ContentClip (FrameView)");
<< ", fontcolor=" << layout_node_color_ << ", shape=doublecircle" SetDebugName(frame_view.ScrollNode(), "Scroll (FrameView)");
<< ", label=FrameView];" << std::endl; }
WriteFrameViewPaintPropertyNodes(frame_view);
if (parent)
WriteParentEdge(&frame_view, parent, layout_node_color_, os);
LayoutView* layout_view = frame_view.GetLayoutView();
if (layout_view)
WriteLayoutObjectNode(*layout_view);
}
private: void UpdateDebugNames(const LayoutObject& object,
static const char* layout_node_color_; ObjectPaintProperties& properties) {
static const char* transform_node_color_; SetDebugName(properties.PaintOffsetTranslation(), "PaintOffsetTranslation",
static const char* clip_node_color_; object);
static const char* effect_node_color_; SetDebugName(properties.Transform(), "Transform", object);
SetDebugName(properties.Perspective(), "Perspective", object);
std::ostringstream layout_; SetDebugName(properties.SvgLocalToBorderBoxTransform(),
std::ostringstream properties_; "SvgLocalToBorderBoxTransform", object);
std::ostringstream owner_edges_; SetDebugName(properties.ScrollTranslation(), "ScrollTranslation", object);
}; SetDebugName(properties.FragmentClip(), "FragmentClip", object);
SetDebugName(properties.MaskClip(), "MaskClip", object);
SetDebugName(properties.CssClip(), "CssClip", object);
SetDebugName(properties.CssClipFixedPosition(), "CssClipFixedPosition",
object);
SetDebugName(properties.OverflowControlsClip(), "OverflowControlsClip",
object);
SetDebugName(properties.InnerBorderRadiusClip(), "InnerBorderRadiusClip",
object);
SetDebugName(properties.OverflowClip(), "OverflowClip", object);
SetDebugName(properties.Effect(), "Effect", object);
SetDebugName(properties.Filter(), "Filter", object);
SetDebugName(properties.Mask(), "Mask", object);
SetDebugName(properties.Scroll(), "Scroll", object);
}
const char* PaintPropertyTreeGraphBuilder::layout_node_color_ = "black"; } // namespace PaintPropertyTreePrinter
const char* PaintPropertyTreeGraphBuilder::transform_node_color_ = "green";
const char* PaintPropertyTreeGraphBuilder::clip_node_color_ = "blue";
const char* PaintPropertyTreeGraphBuilder::effect_node_color_ = "black";
} // namespace {
} // namespace blink } // namespace blink
CORE_EXPORT void showAllPropertyTrees(const blink::LocalFrameView& rootFrame) { CORE_EXPORT void showAllPropertyTrees(const blink::LocalFrameView& rootFrame) {
...@@ -548,30 +221,24 @@ void showScrollPropertyTree(const blink::LocalFrameView& rootFrame) { ...@@ -548,30 +221,24 @@ void showScrollPropertyTree(const blink::LocalFrameView& rootFrame) {
} }
String transformPropertyTreeAsString(const blink::LocalFrameView& rootFrame) { String transformPropertyTreeAsString(const blink::LocalFrameView& rootFrame) {
return blink::PropertyTreePrinter<blink::TransformPaintPropertyNode>() return blink::FrameViewPropertyTreePrinter<
blink::TransformPaintPropertyNode>()
.TreeAsString(rootFrame); .TreeAsString(rootFrame);
} }
String clipPropertyTreeAsString(const blink::LocalFrameView& rootFrame) { String clipPropertyTreeAsString(const blink::LocalFrameView& rootFrame) {
return blink::PropertyTreePrinter<blink::ClipPaintPropertyNode>() return blink::FrameViewPropertyTreePrinter<blink::ClipPaintPropertyNode>()
.TreeAsString(rootFrame); .TreeAsString(rootFrame);
} }
String effectPropertyTreeAsString(const blink::LocalFrameView& rootFrame) { String effectPropertyTreeAsString(const blink::LocalFrameView& rootFrame) {
return blink::PropertyTreePrinter<blink::EffectPaintPropertyNode>() return blink::FrameViewPropertyTreePrinter<blink::EffectPaintPropertyNode>()
.TreeAsString(rootFrame); .TreeAsString(rootFrame);
} }
String scrollPropertyTreeAsString(const blink::LocalFrameView& rootFrame) { String scrollPropertyTreeAsString(const blink::LocalFrameView& rootFrame) {
return blink::PropertyTreePrinter<blink::ScrollPaintPropertyNode>() return blink::FrameViewPropertyTreePrinter<blink::ScrollPaintPropertyNode>()
.TreeAsString(rootFrame); .TreeAsString(rootFrame);
} }
String paintPropertyTreeGraph(const blink::LocalFrameView& frameView) {
blink::PaintPropertyTreeGraphBuilder builder;
StringBuilder stringBuilder;
builder.GenerateTreeGraph(frameView, stringBuilder);
return stringBuilder.ToString();
}
#endif // DCHECK_IS_ON() #endif // DCHECK_IS_ON()
...@@ -13,6 +13,15 @@ ...@@ -13,6 +13,15 @@
namespace blink { namespace blink {
class LocalFrameView; class LocalFrameView;
class LayoutObject;
class ObjectPaintProperties;
namespace PaintPropertyTreePrinter {
void UpdateDebugNames(const LocalFrameView&);
void UpdateDebugNames(const LayoutObject&, ObjectPaintProperties&);
} // namespace PaintPropertyTreePrinter
} // namespace blink } // namespace blink
...@@ -32,8 +41,6 @@ effectPropertyTreeAsString(const blink::LocalFrameView& rootFrame); ...@@ -32,8 +41,6 @@ effectPropertyTreeAsString(const blink::LocalFrameView& rootFrame);
CORE_EXPORT String CORE_EXPORT String
scrollPropertyTreeAsString(const blink::LocalFrameView& rootFrame); scrollPropertyTreeAsString(const blink::LocalFrameView& rootFrame);
CORE_EXPORT String paintPropertyTreeGraph(const blink::LocalFrameView&);
#endif // if DCHECK_IS_ON() #endif // if DCHECK_IS_ON()
#endif // PaintPropertyTreePrinter_h #endif // PaintPropertyTreePrinter_h
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "platform/graphics/paint/ClipPaintPropertyNode.h" #include "platform/graphics/paint/ClipPaintPropertyNode.h"
#include "platform/geometry/LayoutRect.h" #include "platform/geometry/LayoutRect.h"
#include "platform/graphics/paint/PropertyTreeState.h"
namespace blink { namespace blink {
...@@ -38,13 +37,4 @@ std::unique_ptr<JSONObject> ClipPaintPropertyNode::ToJSON() const { ...@@ -38,13 +37,4 @@ std::unique_ptr<JSONObject> ClipPaintPropertyNode::ToJSON() const {
return json; return json;
} }
#if DCHECK_IS_ON()
String ClipPaintPropertyNode::ToTreeString() const {
return blink::PropertyTreeStatePrinter<blink::ClipPaintPropertyNode>()
.PathAsString(this);
}
#endif
} // namespace blink } // namespace blink
...@@ -102,8 +102,6 @@ class PLATFORM_EXPORT ClipPaintPropertyNode ...@@ -102,8 +102,6 @@ class PLATFORM_EXPORT ClipPaintPropertyNode
clip_rect_ == o.clip_rect_ && clip_path_ == o.clip_path_ && clip_rect_ == o.clip_rect_ && clip_path_ == o.clip_path_ &&
direct_compositing_reasons_ == o.direct_compositing_reasons_; direct_compositing_reasons_ == o.direct_compositing_reasons_;
} }
String ToTreeString() const;
#endif #endif
std::unique_ptr<JSONObject> ToJSON() const; std::unique_ptr<JSONObject> ToJSON() const;
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
#include "platform/graphics/paint/EffectPaintPropertyNode.h" #include "platform/graphics/paint/EffectPaintPropertyNode.h"
#include "platform/graphics/paint/PropertyTreeState.h"
namespace blink { namespace blink {
EffectPaintPropertyNode* EffectPaintPropertyNode::Root() { EffectPaintPropertyNode* EffectPaintPropertyNode::Root() {
...@@ -54,13 +52,4 @@ std::unique_ptr<JSONObject> EffectPaintPropertyNode::ToJSON() const { ...@@ -54,13 +52,4 @@ std::unique_ptr<JSONObject> EffectPaintPropertyNode::ToJSON() const {
return json; return json;
} }
#if DCHECK_IS_ON()
String EffectPaintPropertyNode::ToTreeString() const {
return blink::PropertyTreeStatePrinter<blink::EffectPaintPropertyNode>()
.PathAsString(this);
}
#endif
} // namespace blink } // namespace blink
...@@ -125,8 +125,6 @@ class PLATFORM_EXPORT EffectPaintPropertyNode ...@@ -125,8 +125,6 @@ class PLATFORM_EXPORT EffectPaintPropertyNode
compositor_element_id_ == o.compositor_element_id_ && compositor_element_id_ == o.compositor_element_id_ &&
paint_offset_ == o.paint_offset_; paint_offset_ == o.paint_offset_;
} }
String ToTreeString() const;
#endif #endif
std::unique_ptr<JSONObject> ToJSON() const; std::unique_ptr<JSONObject> ToJSON() const;
......
...@@ -11,6 +11,11 @@ ...@@ -11,6 +11,11 @@
#include "platform/wtf/RefCounted.h" #include "platform/wtf/RefCounted.h"
#include "platform/wtf/text/WTFString.h" #include "platform/wtf/text/WTFString.h"
#if DCHECK_IS_ON()
#include "platform/wtf/ListHashSet.h"
#include "platform/wtf/text/StringBuilder.h"
#endif
namespace blink { namespace blink {
class ClipPaintPropertyNode; class ClipPaintPropertyNode;
...@@ -77,9 +82,21 @@ class PaintPropertyNode : public RefCounted<NodeType> { ...@@ -77,9 +82,21 @@ class PaintPropertyNode : public RefCounted<NodeType> {
} }
String ToString() const { String ToString() const {
return static_cast<const NodeType*>(this)->ToJSON()->ToJSONString(); auto s = static_cast<const NodeType*>(this)->ToJSON()->ToJSONString();
#if DCHECK_IS_ON()
return debug_name_ + String::Format(" %p ", this) + s;
#else
return s;
#endif
} }
#if DCHECK_IS_ON()
String ToTreeString() const;
String DebugName() const { return debug_name_; }
void SetDebugName(const String& name) { debug_name_ = name; }
#endif
protected: protected:
PaintPropertyNode(scoped_refptr<const NodeType> parent) PaintPropertyNode(scoped_refptr<const NodeType> parent)
: parent_(std::move(parent)), changed_(false) {} : parent_(std::move(parent)), changed_(false) {}
...@@ -100,8 +117,73 @@ class PaintPropertyNode : public RefCounted<NodeType> { ...@@ -100,8 +117,73 @@ class PaintPropertyNode : public RefCounted<NodeType> {
private: private:
scoped_refptr<const NodeType> parent_; scoped_refptr<const NodeType> parent_;
mutable bool changed_; mutable bool changed_;
#if DCHECK_IS_ON()
String debug_name_;
#endif
};
#if DCHECK_IS_ON()
template <typename NodeType>
class PropertyTreePrinter {
public:
void AddNode(const NodeType* node) {
if (node)
nodes_.insert(node);
}
String NodesAsTreeString() {
if (nodes_.IsEmpty())
return "";
StringBuilder string_builder;
BuildTreeString(string_builder, RootNode(), 0);
return string_builder.ToString();
}
String PathAsString(const NodeType* last_node) {
for (const auto* n = last_node; !n->IsRoot(); n = n->Parent())
AddNode(n);
return NodesAsTreeString();
}
private:
void BuildTreeString(StringBuilder& string_builder,
const NodeType* node,
unsigned indent) {
DCHECK(node);
for (unsigned i = 0; i < indent; i++)
string_builder.Append(' ');
string_builder.Append(node->ToString());
string_builder.Append("\n");
for (const auto* child_node : nodes_) {
if (child_node->Parent() == node)
BuildTreeString(string_builder, child_node, indent + 2);
}
}
const NodeType* RootNode() {
const auto* node = nodes_.back();
while (!node->IsRoot())
node = node->Parent();
if (node->DebugName().IsEmpty())
const_cast<NodeType*>(node)->SetDebugName("root");
nodes_.insert(node);
return node;
}
ListHashSet<const NodeType*> nodes_;
}; };
template <typename NodeType>
String PaintPropertyNode<NodeType>::ToTreeString() const {
return PropertyTreePrinter<NodeType>().PathAsString(
static_cast<const NodeType*>(this));
}
#endif // DCHECK_IS_ON()
} // namespace blink } // namespace blink
#endif // PaintPropertyNode_h #endif // PaintPropertyNode_h
...@@ -68,51 +68,6 @@ inline bool operator==(const PropertyTreeState& a, const PropertyTreeState& b) { ...@@ -68,51 +68,6 @@ inline bool operator==(const PropertyTreeState& a, const PropertyTreeState& b) {
a.Effect() == b.Effect(); a.Effect() == b.Effect();
} }
#if DCHECK_IS_ON()
template <typename PropertyTreeNode>
class PropertyTreeStatePrinter {
public:
String PathAsString(const PropertyTreeNode* last_node) {
const PropertyTreeNode* node = last_node;
while (!node->IsRoot()) {
AddPropertyNode(node, "");
node = node->Parent();
}
AddPropertyNode(node, "root");
StringBuilder string_builder;
AddAllPropertyNodes(string_builder, node);
return string_builder.ToString();
}
void AddPropertyNode(const PropertyTreeNode* node, String debug_info) {
node_to_debug_string_.Set(node, debug_info);
}
void AddAllPropertyNodes(StringBuilder& string_builder,
const PropertyTreeNode* node,
unsigned indent = 0) {
DCHECK(node);
for (unsigned i = 0; i < indent; i++)
string_builder.Append(' ');
if (node_to_debug_string_.Contains(node))
string_builder.Append(node_to_debug_string_.at(node));
string_builder.Append(String::Format(" %p ", node));
string_builder.Append(node->ToString());
string_builder.Append("\n");
for (const auto* child_node : node_to_debug_string_.Keys()) {
if (child_node->Parent() == node)
AddAllPropertyNodes(string_builder, child_node, indent + 2);
}
}
HashMap<const PropertyTreeNode*, String> node_to_debug_string_;
};
#endif
} // namespace blink } // namespace blink
#endif // PropertyTreeState_h #endif // PropertyTreeState_h
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
#include "platform/graphics/paint/ScrollPaintPropertyNode.h" #include "platform/graphics/paint/ScrollPaintPropertyNode.h"
#include "platform/graphics/paint/PropertyTreeState.h"
namespace blink { namespace blink {
ScrollPaintPropertyNode* ScrollPaintPropertyNode::Root() { ScrollPaintPropertyNode* ScrollPaintPropertyNode::Root() {
...@@ -44,13 +42,4 @@ std::unique_ptr<JSONObject> ScrollPaintPropertyNode::ToJSON() const { ...@@ -44,13 +42,4 @@ std::unique_ptr<JSONObject> ScrollPaintPropertyNode::ToJSON() const {
return json; return json;
} }
#if DCHECK_IS_ON()
String ScrollPaintPropertyNode::ToTreeString() const {
return blink::PropertyTreeStatePrinter<blink::ScrollPaintPropertyNode>()
.PathAsString(this);
}
#endif
} // namespace blink } // namespace blink
...@@ -135,8 +135,6 @@ class PLATFORM_EXPORT ScrollPaintPropertyNode ...@@ -135,8 +135,6 @@ class PLATFORM_EXPORT ScrollPaintPropertyNode
main_thread_scrolling_reasons_ == o.main_thread_scrolling_reasons_ && main_thread_scrolling_reasons_ == o.main_thread_scrolling_reasons_ &&
compositor_element_id_ == o.compositor_element_id_; compositor_element_id_ == o.compositor_element_id_;
} }
String ToTreeString() const;
#endif #endif
std::unique_ptr<JSONObject> ToJSON() const; std::unique_ptr<JSONObject> ToJSON() const;
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
#include "platform/graphics/paint/TransformPaintPropertyNode.h" #include "platform/graphics/paint/TransformPaintPropertyNode.h"
#include "platform/graphics/paint/PropertyTreeState.h"
namespace blink { namespace blink {
// The root of the transform tree. The root transform node references the root // The root of the transform tree. The root transform node references the root
...@@ -58,13 +56,4 @@ std::unique_ptr<JSONObject> TransformPaintPropertyNode::ToJSON() const { ...@@ -58,13 +56,4 @@ std::unique_ptr<JSONObject> TransformPaintPropertyNode::ToJSON() const {
return json; return json;
} }
#if DCHECK_IS_ON()
String TransformPaintPropertyNode::ToTreeString() const {
return blink::PropertyTreeStatePrinter<blink::TransformPaintPropertyNode>()
.PathAsString(this);
}
#endif
} // namespace blink } // namespace blink
...@@ -150,8 +150,6 @@ class PLATFORM_EXPORT TransformPaintPropertyNode ...@@ -150,8 +150,6 @@ class PLATFORM_EXPORT TransformPaintPropertyNode
compositor_element_id_ == o.compositor_element_id_ && compositor_element_id_ == o.compositor_element_id_ &&
scroll_ == o.scroll_; scroll_ == o.scroll_;
} }
String ToTreeString() const;
#endif #endif
std::unique_ptr<JSONObject> ToJSON() const; std::unique_ptr<JSONObject> ToJSON() const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment