| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/paint/PaintPropertyTreePrinter.h" | 5 #include "core/paint/PaintPropertyTreePrinter.h" |
| 6 | 6 |
| 7 #include "core/frame/FrameView.h" | 7 #include "core/frame/FrameView.h" |
| 8 #include "core/frame/LocalFrame.h" | 8 #include "core/frame/LocalFrame.h" |
| 9 #include "core/layout/LayoutPart.h" | 9 #include "core/layout/LayoutPart.h" |
| 10 #include "core/layout/LayoutView.h" | 10 #include "core/layout/LayoutView.h" |
| 11 #include "core/paint/ObjectPaintProperties.h" | 11 #include "core/paint/ObjectPaintProperties.h" |
| 12 | 12 |
| 13 #include <iomanip> | 13 #include <iomanip> |
| 14 #include <sstream> | 14 #include <sstream> |
| 15 | 15 |
| 16 #ifndef NDEBUG | 16 #ifndef NDEBUG |
| 17 | 17 |
| 18 namespace blink { | 18 namespace blink { |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 template <typename PropertyTreeNode> | 21 template <typename PropertyTreeNode> |
| 22 class PropertyTreePrinterTraits; | 22 class PropertyTreePrinterTraits; |
| 23 | 23 |
| 24 template <typename PropertyTreeNode> | 24 template <typename PropertyTreeNode> |
| 25 class PropertyTreePrinter { | 25 class PropertyTreePrinter { |
| 26 public: | 26 public: |
| 27 void showTree(const FrameView& frameView) | 27 String treeAsString(const FrameView& frameView) |
| 28 { | 28 { |
| 29 DCHECK(RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()); | 29 DCHECK(RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()); |
| 30 collectPropertyNodes(frameView); | 30 collectPropertyNodes(frameView); |
| 31 showAllPropertyNodes(nullptr); | |
| 32 } | |
| 33 | 31 |
| 34 void showPath(const PropertyTreeNode* node) | 32 const PropertyTreeNode* rootNode = lookupRootNode(); |
| 35 { | 33 if (!rootNode) |
| 36 for (const PropertyTreeNode* n = node; n; n = n->parent()) | 34 return ""; |
| 37 addPropertyNode(n, ""); | 35 |
| 38 showAllPropertyNodes(nullptr); | 36 if (!m_nodeToDebugString.contains(rootNode)) |
| 37 addPropertyNode(rootNode, "root"); |
| 38 |
| 39 StringBuilder stringBuilder; |
| 40 addAllPropertyNodes(stringBuilder, rootNode); |
| 41 return stringBuilder.toString(); |
| 39 } | 42 } |
| 40 | 43 |
| 41 void addPropertyNode(const PropertyTreeNode* node, String debugInfo) | 44 void addPropertyNode(const PropertyTreeNode* node, String debugInfo) |
| 42 { | 45 { |
| 43 // showAllPropertyNodes determines the root node itself so roots should | |
| 44 // not be added explicitly. | |
| 45 DCHECK(node && !node->isRoot()); | |
| 46 m_nodeToDebugString.set(node, debugInfo); | 46 m_nodeToDebugString.set(node, debugInfo); |
| 47 } | 47 } |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 using Traits = PropertyTreePrinterTraits<PropertyTreeNode>; | 50 using Traits = PropertyTreePrinterTraits<PropertyTreeNode>; |
| 51 | 51 |
| 52 void collectPropertyNodes(const FrameView& frameView) | 52 void collectPropertyNodes(const FrameView& frameView) |
| 53 { | 53 { |
| 54 Traits::addFrameViewProperties(frameView, *this); | 54 Traits::addFrameViewProperties(frameView, *this); |
| 55 if (LayoutView* layoutView = frameView.layoutView()) | 55 if (LayoutView* layoutView = frameView.layoutView()) |
| 56 collectPropertyNodes(*layoutView); | 56 collectPropertyNodes(*layoutView); |
| 57 for (Frame* child = frameView.frame().tree().firstChild(); child; child
= child->tree().nextSibling()) { | 57 for (Frame* child = frameView.frame().tree().firstChild(); child; child
= child->tree().nextSibling()) { |
| 58 if (!child->isLocalFrame()) | 58 if (!child->isLocalFrame()) |
| 59 continue; | 59 continue; |
| 60 if (FrameView* childView = toLocalFrame(child)->view()) | 60 if (FrameView* childView = toLocalFrame(child)->view()) |
| 61 collectPropertyNodes(*childView); | 61 collectPropertyNodes(*childView); |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 void collectPropertyNodes(const LayoutObject& object) | 65 void collectPropertyNodes(const LayoutObject& object) |
| 66 { | 66 { |
| 67 if (const ObjectPaintProperties* paintProperties = object.objectPaintPro
perties()) | 67 if (const ObjectPaintProperties* paintProperties = object.objectPaintPro
perties()) |
| 68 Traits::addObjectPaintProperties(object, *paintProperties, *this); | 68 Traits::addObjectPaintProperties(object, *paintProperties, *this); |
| 69 for (LayoutObject* child = object.slowFirstChild(); child; child = child
->nextSibling()) | 69 for (LayoutObject* child = object.slowFirstChild(); child; child = child
->nextSibling()) |
| 70 collectPropertyNodes(*child); | 70 collectPropertyNodes(*child); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void showAllPropertyNodes(const PropertyTreeNode* node, unsigned indent = 0) | 73 void addAllPropertyNodes(StringBuilder& stringBuilder, const PropertyTreeNod
e* node, unsigned indent = 0) |
| 74 { | 74 { |
| 75 // If no node is specified, show the root node. | 75 DCHECK(node); |
| 76 if (!node) { | |
| 77 for (const auto* childNode : m_nodeToDebugString.keys()) { | |
| 78 if (childNode->parent() && childNode->parent()->isRoot()) { | |
| 79 showAllPropertyNodes(childNode->parent()); | |
| 80 break; | |
| 81 } | |
| 82 } | |
| 83 return; | |
| 84 } | |
| 85 | |
| 86 StringBuilder stringBuilder; | |
| 87 for (unsigned i = 0; i < indent; i++) | 76 for (unsigned i = 0; i < indent; i++) |
| 88 stringBuilder.append(' '); | 77 stringBuilder.append(' '); |
| 89 if (node->isRoot()) | 78 if (m_nodeToDebugString.contains(node)) |
| 90 stringBuilder.append("root"); | |
| 91 else if (m_nodeToDebugString.contains(node)) | |
| 92 stringBuilder.append(m_nodeToDebugString.get(node)); | 79 stringBuilder.append(m_nodeToDebugString.get(node)); |
| 93 stringBuilder.append(String::format(" %p", node)); | 80 stringBuilder.append(String::format(" %p", node)); |
| 94 Traits::printNodeAsString(node, stringBuilder); | 81 Traits::printNodeAsString(node, stringBuilder); |
| 95 fprintf(stderr, "%s\n", stringBuilder.toString().ascii().data()); | 82 stringBuilder.append("\n"); |
| 96 | 83 |
| 97 for (const auto* childNode : m_nodeToDebugString.keys()) { | 84 for (const auto* childNode : m_nodeToDebugString.keys()) { |
| 98 if (childNode->parent() == node) | 85 if (childNode->parent() == node) |
| 99 showAllPropertyNodes(childNode, indent + 2); | 86 addAllPropertyNodes(stringBuilder, childNode, indent + 2); |
| 100 } | 87 } |
| 101 } | 88 } |
| 102 | 89 |
| 90 // Root nodes may not be directly accessible but they can be determined by |
| 91 // walking up to the parent of a previously collected node. |
| 92 const PropertyTreeNode* lookupRootNode() |
| 93 { |
| 94 for (const auto* node : m_nodeToDebugString.keys()) { |
| 95 if (node->isRoot()) |
| 96 return node; |
| 97 if (node->parent() && node->parent()->isRoot()) |
| 98 return node->parent(); |
| 99 } |
| 100 return nullptr; |
| 101 } |
| 102 |
| 103 HashMap<const PropertyTreeNode*, String> m_nodeToDebugString; | 103 HashMap<const PropertyTreeNode*, String> m_nodeToDebugString; |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 template <> | 106 template <> |
| 107 class PropertyTreePrinterTraits<TransformPaintPropertyNode> { | 107 class PropertyTreePrinterTraits<TransformPaintPropertyNode> { |
| 108 public: | 108 public: |
| 109 static void addFrameViewProperties(const FrameView& frameView, PropertyTreeP
rinter<TransformPaintPropertyNode>& printer) | 109 static void addFrameViewProperties(const FrameView& frameView, PropertyTreeP
rinter<TransformPaintPropertyNode>& printer) |
| 110 { | 110 { |
| 111 if (const TransformPaintPropertyNode* preTranslation = frameView.preTran
slation()) | 111 if (const TransformPaintPropertyNode* preTranslation = frameView.preTran
slation()) |
| 112 printer.addPropertyNode(preTranslation, "PreTranslation (FrameView)"
); | 112 printer.addPropertyNode(preTranslation, "PreTranslation (FrameView)"
); |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 CORE_EXPORT void showAllPropertyTrees(const blink::FrameView& rootFrame) | 503 CORE_EXPORT void showAllPropertyTrees(const blink::FrameView& rootFrame) |
| 504 { | 504 { |
| 505 showTransformPropertyTree(rootFrame); | 505 showTransformPropertyTree(rootFrame); |
| 506 showClipPropertyTree(rootFrame); | 506 showClipPropertyTree(rootFrame); |
| 507 showEffectPropertyTree(rootFrame); | 507 showEffectPropertyTree(rootFrame); |
| 508 showScrollPropertyTree(rootFrame); | 508 showScrollPropertyTree(rootFrame); |
| 509 } | 509 } |
| 510 | 510 |
| 511 void showTransformPropertyTree(const blink::FrameView& rootFrame) | 511 void showTransformPropertyTree(const blink::FrameView& rootFrame) |
| 512 { | 512 { |
| 513 blink::PropertyTreePrinter<blink::TransformPaintPropertyNode>().showTree(roo
tFrame); | 513 fprintf(stderr, "%s\n", transformPropertyTreeAsString(rootFrame).utf8().data
()); |
| 514 } | 514 } |
| 515 | 515 |
| 516 void showClipPropertyTree(const blink::FrameView& rootFrame) | 516 void showClipPropertyTree(const blink::FrameView& rootFrame) |
| 517 { | 517 { |
| 518 blink::PropertyTreePrinter<blink::ClipPaintPropertyNode>().showTree(rootFram
e); | 518 fprintf(stderr, "%s\n", clipPropertyTreeAsString(rootFrame).utf8().data()); |
| 519 } | 519 } |
| 520 | 520 |
| 521 void showEffectPropertyTree(const blink::FrameView& rootFrame) | 521 void showEffectPropertyTree(const blink::FrameView& rootFrame) |
| 522 { | 522 { |
| 523 blink::PropertyTreePrinter<blink::EffectPaintPropertyNode>().showTree(rootFr
ame); | 523 fprintf(stderr, "%s\n", effectPropertyTreeAsString(rootFrame).utf8().data())
; |
| 524 } | 524 } |
| 525 | 525 |
| 526 void showScrollPropertyTree(const blink::FrameView& rootFrame) | 526 void showScrollPropertyTree(const blink::FrameView& rootFrame) |
| 527 { | 527 { |
| 528 blink::PropertyTreePrinter<blink::ScrollPaintPropertyNode>().showTree(rootFr
ame); | 528 fprintf(stderr, "%s\n", scrollPropertyTreeAsString(rootFrame).utf8().data())
; |
| 529 } | 529 } |
| 530 | 530 |
| 531 void showPaintPropertyPath(const blink::TransformPaintPropertyNode* node) | 531 String transformPropertyTreeAsString(const blink::FrameView& rootFrame) |
| 532 { | 532 { |
| 533 blink::PropertyTreePrinter<blink::TransformPaintPropertyNode>().showPath(nod
e); | 533 return blink::PropertyTreePrinter<blink::TransformPaintPropertyNode>().treeA
sString(rootFrame); |
| 534 } | 534 } |
| 535 | 535 |
| 536 void showPaintPropertyPath(const blink::ClipPaintPropertyNode* node) | 536 String clipPropertyTreeAsString(const blink::FrameView& rootFrame) |
| 537 { | 537 { |
| 538 blink::PropertyTreePrinter<blink::ClipPaintPropertyNode>().showPath(node); | 538 return blink::PropertyTreePrinter<blink::ClipPaintPropertyNode>().treeAsStri
ng(rootFrame); |
| 539 } | 539 } |
| 540 | 540 |
| 541 void showPaintPropertyPath(const blink::EffectPaintPropertyNode* node) | 541 String effectPropertyTreeAsString(const blink::FrameView& rootFrame) |
| 542 { | 542 { |
| 543 blink::PropertyTreePrinter<blink::EffectPaintPropertyNode>().showPath(node); | 543 return blink::PropertyTreePrinter<blink::EffectPaintPropertyNode>().treeAsSt
ring(rootFrame); |
| 544 } | 544 } |
| 545 | 545 |
| 546 void showPaintPropertyPath(const blink::ScrollPaintPropertyNode* node) | 546 String scrollPropertyTreeAsString(const blink::FrameView& rootFrame) |
| 547 { | 547 { |
| 548 blink::PropertyTreePrinter<blink::ScrollPaintPropertyNode>().showPath(node); | 548 return blink::PropertyTreePrinter<blink::ScrollPaintPropertyNode>().treeAsSt
ring(rootFrame); |
| 549 } | 549 } |
| 550 | 550 |
| 551 String paintPropertyTreeGraph(const blink::FrameView& frameView) | 551 String paintPropertyTreeGraph(const blink::FrameView& frameView) |
| 552 { | 552 { |
| 553 blink::PaintPropertyTreeGraphBuilder builder; | 553 blink::PaintPropertyTreeGraphBuilder builder; |
| 554 StringBuilder stringBuilder; | 554 StringBuilder stringBuilder; |
| 555 builder.generateTreeGraph(frameView, stringBuilder); | 555 builder.generateTreeGraph(frameView, stringBuilder); |
| 556 return stringBuilder.toString(); | 556 return stringBuilder.toString(); |
| 557 } | 557 } |
| 558 | 558 |
| 559 #endif | 559 #endif |
| OLD | NEW |