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 @@
#include "core/paint/FindPropertiesNeedingUpdate.h"
#include "core/paint/ObjectPaintProperties.h"
#include "core/paint/PaintLayer.h"
#include "core/paint/PaintPropertyTreePrinter.h"
#include "core/paint/SVGRootPainter.h"
#include "core/paint/compositing/CompositedLayerMapping.h"
#include "core/paint/compositing/CompositingReasonFinder.h"
......@@ -278,6 +279,10 @@ void FrameViewPaintPropertyTreeBuilder::Update(
std::unique_ptr<PropertyTreeState> contents_state(new PropertyTreeState(
context.current.transform, context.current.clip, context.current_effect));
frame_view.SetTotalPropertyTreeStateForContents(std::move(contents_state));
#if DCHECK_IS_ON()
PaintPropertyTreePrinter::UpdateDebugNames(frame_view);
#endif
}
namespace {
......@@ -299,6 +304,10 @@ class FragmentPaintPropertyTreeBuilder {
~FragmentPaintPropertyTreeBuilder() {
full_context_.force_subtree_update |= property_added_or_removed_;
#if DCHECK_IS_ON()
if (properties_)
PaintPropertyTreePrinter::UpdateDebugNames(object_, *properties_);
#endif
}
ALWAYS_INLINE void UpdateForSelf();
......
......@@ -13,6 +13,15 @@
namespace blink {
class LocalFrameView;
class LayoutObject;
class ObjectPaintProperties;
namespace PaintPropertyTreePrinter {
void UpdateDebugNames(const LocalFrameView&);
void UpdateDebugNames(const LayoutObject&, ObjectPaintProperties&);
} // namespace PaintPropertyTreePrinter
} // namespace blink
......@@ -32,8 +41,6 @@ effectPropertyTreeAsString(const blink::LocalFrameView& rootFrame);
CORE_EXPORT String
scrollPropertyTreeAsString(const blink::LocalFrameView& rootFrame);
CORE_EXPORT String paintPropertyTreeGraph(const blink::LocalFrameView&);
#endif // if DCHECK_IS_ON()
#endif // PaintPropertyTreePrinter_h
......@@ -80,7 +80,7 @@ TEST_P(PaintPropertyTreePrinterTest, SimpleTransformTreePath) {
::testing::MatchesRegex("root .*\"scroll\".*"
" .*\"parent\".*"
" .*\"matrix\".*"
" .*\"matrix\".*"));
" .*\"matrix\".*"));
}
TEST_P(PaintPropertyTreePrinterTest, SimpleClipTreePath) {
......
......@@ -5,7 +5,6 @@
#include "platform/graphics/paint/ClipPaintPropertyNode.h"
#include "platform/geometry/LayoutRect.h"
#include "platform/graphics/paint/PropertyTreeState.h"
namespace blink {
......@@ -38,13 +37,4 @@ std::unique_ptr<JSONObject> ClipPaintPropertyNode::ToJSON() const {
return json;
}
#if DCHECK_IS_ON()
String ClipPaintPropertyNode::ToTreeString() const {
return blink::PropertyTreeStatePrinter<blink::ClipPaintPropertyNode>()
.PathAsString(this);
}
#endif
} // namespace blink
......@@ -102,8 +102,6 @@ class PLATFORM_EXPORT ClipPaintPropertyNode
clip_rect_ == o.clip_rect_ && clip_path_ == o.clip_path_ &&
direct_compositing_reasons_ == o.direct_compositing_reasons_;
}
String ToTreeString() const;
#endif
std::unique_ptr<JSONObject> ToJSON() const;
......
......@@ -4,8 +4,6 @@
#include "platform/graphics/paint/EffectPaintPropertyNode.h"
#include "platform/graphics/paint/PropertyTreeState.h"
namespace blink {
EffectPaintPropertyNode* EffectPaintPropertyNode::Root() {
......@@ -54,13 +52,4 @@ std::unique_ptr<JSONObject> EffectPaintPropertyNode::ToJSON() const {
return json;
}
#if DCHECK_IS_ON()
String EffectPaintPropertyNode::ToTreeString() const {
return blink::PropertyTreeStatePrinter<blink::EffectPaintPropertyNode>()
.PathAsString(this);
}
#endif
} // namespace blink
......@@ -125,8 +125,6 @@ class PLATFORM_EXPORT EffectPaintPropertyNode
compositor_element_id_ == o.compositor_element_id_ &&
paint_offset_ == o.paint_offset_;
}
String ToTreeString() const;
#endif
std::unique_ptr<JSONObject> ToJSON() const;
......
......@@ -11,6 +11,11 @@
#include "platform/wtf/RefCounted.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 {
class ClipPaintPropertyNode;
......@@ -77,9 +82,21 @@ class PaintPropertyNode : public RefCounted<NodeType> {
}
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:
PaintPropertyNode(scoped_refptr<const NodeType> parent)
: parent_(std::move(parent)), changed_(false) {}
......@@ -100,8 +117,73 @@ class PaintPropertyNode : public RefCounted<NodeType> {
private:
scoped_refptr<const NodeType> parent_;
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
#endif // PaintPropertyNode_h
......@@ -68,51 +68,6 @@ inline bool operator==(const PropertyTreeState& a, const PropertyTreeState& b) {
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
#endif // PropertyTreeState_h
......@@ -4,8 +4,6 @@
#include "platform/graphics/paint/ScrollPaintPropertyNode.h"
#include "platform/graphics/paint/PropertyTreeState.h"
namespace blink {
ScrollPaintPropertyNode* ScrollPaintPropertyNode::Root() {
......@@ -44,13 +42,4 @@ std::unique_ptr<JSONObject> ScrollPaintPropertyNode::ToJSON() const {
return json;
}
#if DCHECK_IS_ON()
String ScrollPaintPropertyNode::ToTreeString() const {
return blink::PropertyTreeStatePrinter<blink::ScrollPaintPropertyNode>()
.PathAsString(this);
}
#endif
} // namespace blink
......@@ -135,8 +135,6 @@ class PLATFORM_EXPORT ScrollPaintPropertyNode
main_thread_scrolling_reasons_ == o.main_thread_scrolling_reasons_ &&
compositor_element_id_ == o.compositor_element_id_;
}
String ToTreeString() const;
#endif
std::unique_ptr<JSONObject> ToJSON() const;
......
......@@ -4,8 +4,6 @@
#include "platform/graphics/paint/TransformPaintPropertyNode.h"
#include "platform/graphics/paint/PropertyTreeState.h"
namespace blink {
// The root of the transform tree. The root transform node references the root
......@@ -58,13 +56,4 @@ std::unique_ptr<JSONObject> TransformPaintPropertyNode::ToJSON() const {
return json;
}
#if DCHECK_IS_ON()
String TransformPaintPropertyNode::ToTreeString() const {
return blink::PropertyTreeStatePrinter<blink::TransformPaintPropertyNode>()
.PathAsString(this);
}
#endif
} // namespace blink
......@@ -150,8 +150,6 @@ class PLATFORM_EXPORT TransformPaintPropertyNode
compositor_element_id_ == o.compositor_element_id_ &&
scroll_ == o.scroll_;
}
String ToTreeString() const;
#endif
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