1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "core/layout/LayoutAnalyzer.h"
8 #include "core/frame/FrameView.h"
9 #include "core/layout/LayoutBlock.h"
10 #include "core/layout/LayoutObject.h"
11 #include "core/layout/LayoutText.h"
12 #include "platform/TracedValue.h"
16 LayoutAnalyzer::Scope::Scope(const LayoutObject
& o
)
18 , m_analyzer(o
.frameView()->layoutAnalyzer())
24 LayoutAnalyzer::Scope::~Scope()
27 m_analyzer
->pop(m_layoutObject
);
30 LayoutAnalyzer::BlockScope::BlockScope(const LayoutBlock
& block
)
32 , m_width(block
.frameRect().width())
33 , m_height(block
.frameRect().height())
37 LayoutAnalyzer::BlockScope::~BlockScope()
39 LayoutAnalyzer
* analyzer
= m_block
.frameView()->layoutAnalyzer();
43 if (m_width
!= m_block
.frameRect().width()) {
44 analyzer
->increment(LayoutBlockWidthChanged
);
47 if (m_height
!= m_block
.frameRect().height()) {
48 analyzer
->increment(LayoutBlockHeightChanged
);
51 analyzer
->increment(changed
? LayoutBlockSizeChanged
: LayoutBlockSizeDidNotChange
);
54 void LayoutAnalyzer::reset()
56 m_startMs
= currentTimeMS();
58 for (size_t i
= 0; i
< NumCounters
; ++i
) {
63 void LayoutAnalyzer::push(const LayoutObject
& o
)
65 increment(TotalLayoutObjectsThatWereLaidOut
);
66 if (!o
.everHadLayout())
67 increment(LayoutObjectsThatHadNeverHadLayout
);
68 if (o
.selfNeedsLayout())
69 increment(LayoutObjectsThatNeedLayoutForThemselves
);
70 if (o
.needsPositionedMovementLayout())
71 increment(LayoutObjectsThatNeedPositionedMovementLayout
);
72 if (o
.isOutOfFlowPositioned())
73 increment(LayoutObjectsThatAreOutOfFlowPositioned
);
75 increment(LayoutObjectsThatAreTableCells
);
77 increment(LayoutObjectsThatAreFloating
);
78 if (o
.style()->specifiesColumns())
79 increment(LayoutObjectsThatSpecifyColumns
);
81 increment(LayoutObjectsThatHaveALayer
);
82 if (o
.isLayoutInline() && o
.alwaysCreateLineBoxesForLayoutInline())
83 increment(LayoutInlineObjectsThatAlwaysCreateLineBoxes
);
85 const LayoutText
& t
= *toLayoutText(&o
);
86 if (t
.canUseSimpleFontCodePath()) {
87 increment(LayoutObjectsThatAreTextAndCanUseTheSimpleFontCodePath
);
88 increment(CharactersInLayoutObjectsThatAreTextAndCanUseTheSimpleFontCodePath
, t
.textLength());
90 increment(LayoutObjectsThatAreTextAndCanNotUseTheSimpleFontCodePath
);
91 increment(CharactersInLayoutObjectsThatAreTextAndCanNotUseTheSimpleFontCodePath
, t
.textLength());
97 // This refers to LayoutAnalyzer depth, which is generally closer to C++
98 // stack recursion depth, not layout tree depth or DOM tree depth.
99 m_counters
[LayoutAnalyzerStackMaximumDepth
] = max(m_counters
[LayoutAnalyzerStackMaximumDepth
], m_depth
);
102 void LayoutAnalyzer::pop(const LayoutObject
& o
)
108 PassRefPtr
<TracedValue
> LayoutAnalyzer::toTracedValue()
110 RefPtr
<TracedValue
> tracedValue(TracedValue::create());
111 for (size_t i
= 0; i
< NumCounters
; ++i
) {
112 if (m_counters
[i
] > 0)
113 tracedValue
->setInteger(nameForCounter(static_cast<Counter
>(i
)), m_counters
[i
]);
115 return tracedValue
.release();
118 const char* LayoutAnalyzer::nameForCounter(Counter counter
) const
121 case LayoutBlockWidthChanged
: return "LayoutBlockWidthChanged";
122 case LayoutBlockHeightChanged
: return "LayoutBlockHeightChanged";
123 case LayoutBlockSizeChanged
: return "LayoutBlockSizeChanged";
124 case LayoutBlockSizeDidNotChange
: return "LayoutBlockSizeDidNotChange";
125 case LayoutObjectsThatSpecifyColumns
: return "LayoutObjectsThatSpecifyColumns";
126 case LayoutAnalyzerStackMaximumDepth
: return "LayoutAnalyzerStackMaximumDepth";
127 case LayoutObjectsThatAreFloating
: return "LayoutObjectsThatAreFloating";
128 case LayoutObjectsThatHaveALayer
: return "LayoutObjectsThatHaveALayer";
129 case LayoutInlineObjectsThatAlwaysCreateLineBoxes
: return "LayoutInlineObjectsThatAlwaysCreateLineBoxes";
130 case LayoutObjectsThatHadNeverHadLayout
: return "LayoutObjectsThatHadNeverHadLayout";
131 case LayoutObjectsThatAreOutOfFlowPositioned
: return "LayoutObjectsThatAreOutOfFlowPositioned";
132 case LayoutObjectsThatNeedPositionedMovementLayout
: return "LayoutObjectsThatNeedPositionedMovementLayout";
133 case PerformLayoutRootLayoutObjects
: return "PerformLayoutRootLayoutObjects";
134 case LayoutObjectsThatNeedLayoutForThemselves
: return "LayoutObjectsThatNeedLayoutForThemselves";
135 case LayoutObjectsThatNeedSimplifiedLayout
: return "LayoutObjectsThatNeedSimplifiedLayout";
136 case LayoutObjectsThatAreTableCells
: return "LayoutObjectsThatAreTableCells";
137 case LayoutObjectsThatAreTextAndCanNotUseTheSimpleFontCodePath
: return "LayoutObjectsThatAreTextAndCanNotUseTheSimpleFontCodePath";
138 case CharactersInLayoutObjectsThatAreTextAndCanNotUseTheSimpleFontCodePath
: return "CharactersInLayoutObjectsThatAreTextAndCanNotUseTheSimpleFontCodePath";
139 case LayoutObjectsThatAreTextAndCanUseTheSimpleFontCodePath
: return "LayoutObjectsThatAreTextAndCanUseTheSimpleFontCodePath";
140 case CharactersInLayoutObjectsThatAreTextAndCanUseTheSimpleFontCodePath
: return "CharactersInLayoutObjectsThatAreTextAndCanUseTheSimpleFontCodePath";
141 case TotalLayoutObjectsThatWereLaidOut
: return "TotalLayoutObjectsThatWereLaidOut";
143 ASSERT_NOT_REACHED();