1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "core/layout/LayoutAnalyzer.h"
#include "core/frame/FrameView.h"
#include "core/layout/LayoutBlock.h"
#include "core/layout/LayoutObject.h"
#include "core/layout/LayoutText.h"
#include "platform/instrumentation/tracing/TracedValue.h"
#include <memory>
namespace blink {
LayoutAnalyzer::Scope::Scope(const LayoutObject& o)
: m_layoutObject(o), m_analyzer(o.frameView()->layoutAnalyzer()) {
if (m_analyzer)
m_analyzer->push(o);
}
LayoutAnalyzer::Scope::~Scope() {
if (m_analyzer)
m_analyzer->pop(m_layoutObject);
}
LayoutAnalyzer::BlockScope::BlockScope(const LayoutBlock& block)
: m_block(block),
m_width(block.frameRect().width()),
m_height(block.frameRect().height()) {}
LayoutAnalyzer::BlockScope::~BlockScope() {
LayoutAnalyzer* analyzer = m_block.frameView()->layoutAnalyzer();
if (!analyzer)
return;
bool changed = false;
if (m_width != m_block.frameRect().width()) {
analyzer->increment(LayoutBlockWidthChanged);
changed = true;
}
if (m_height != m_block.frameRect().height()) {
analyzer->increment(LayoutBlockHeightChanged);
changed = true;
}
analyzer->increment(changed ? LayoutBlockSizeChanged
: LayoutBlockSizeDidNotChange);
}
void LayoutAnalyzer::reset() {
m_startMs = currentTimeMS();
m_depth = 0;
for (size_t i = 0; i < NumCounters; ++i) {
m_counters[i] = 0;
}
}
void LayoutAnalyzer::push(const LayoutObject& o) {
increment(TotalLayoutObjectsThatWereLaidOut);
if (!o.everHadLayout())
increment(LayoutObjectsThatHadNeverHadLayout);
if (o.selfNeedsLayout())
increment(LayoutObjectsThatNeedLayoutForThemselves);
if (o.needsPositionedMovementLayout())
increment(LayoutObjectsThatNeedPositionedMovementLayout);
if (o.isOutOfFlowPositioned())
increment(LayoutObjectsThatAreOutOfFlowPositioned);
if (o.isTableCell())
increment(LayoutObjectsThatAreTableCells);
if (o.isFloating())
increment(LayoutObjectsThatAreFloating);
if (o.style()->specifiesColumns())
increment(LayoutObjectsThatSpecifyColumns);
if (o.hasLayer())
increment(LayoutObjectsThatHaveALayer);
if (o.isLayoutInline() && o.alwaysCreateLineBoxesForLayoutInline())
increment(LayoutInlineObjectsThatAlwaysCreateLineBoxes);
if (o.isText()) {
const LayoutText& t = *toLayoutText(&o);
increment(LayoutObjectsThatAreTextAndCanNotUseTheSimpleFontCodePath);
increment(
CharactersInLayoutObjectsThatAreTextAndCanNotUseTheSimpleFontCodePath,
t.textLength());
}
++m_depth;
// This refers to LayoutAnalyzer depth, which is generally closer to C++
// stack recursion depth, not layout tree depth or DOM tree depth.
m_counters[LayoutAnalyzerStackMaximumDepth] =
max(m_counters[LayoutAnalyzerStackMaximumDepth], m_depth);
}
void LayoutAnalyzer::pop(const LayoutObject& o) {
ASSERT(m_depth > 0);
--m_depth;
}
std::unique_ptr<TracedValue> LayoutAnalyzer::toTracedValue() {
std::unique_ptr<TracedValue> tracedValue(TracedValue::create());
for (size_t i = 0; i < NumCounters; ++i) {
if (m_counters[i] > 0)
tracedValue->setInteger(nameForCounter(static_cast<Counter>(i)),
m_counters[i]);
}
return tracedValue;
}
const char* LayoutAnalyzer::nameForCounter(Counter counter) const {
switch (counter) {
case LayoutBlockWidthChanged:
return "LayoutBlockWidthChanged";
case LayoutBlockHeightChanged:
return "LayoutBlockHeightChanged";
case LayoutBlockSizeChanged:
return "LayoutBlockSizeChanged";
case LayoutBlockSizeDidNotChange:
return "LayoutBlockSizeDidNotChange";
case LayoutObjectsThatSpecifyColumns:
return "LayoutObjectsThatSpecifyColumns";
case LayoutAnalyzerStackMaximumDepth:
return "LayoutAnalyzerStackMaximumDepth";
case LayoutObjectsThatAreFloating:
return "LayoutObjectsThatAreFloating";
case LayoutObjectsThatHaveALayer:
return "LayoutObjectsThatHaveALayer";
case LayoutInlineObjectsThatAlwaysCreateLineBoxes:
return "LayoutInlineObjectsThatAlwaysCreateLineBoxes";
case LayoutObjectsThatHadNeverHadLayout:
return "LayoutObjectsThatHadNeverHadLayout";
case LayoutObjectsThatAreOutOfFlowPositioned:
return "LayoutObjectsThatAreOutOfFlowPositioned";
case LayoutObjectsThatNeedPositionedMovementLayout:
return "LayoutObjectsThatNeedPositionedMovementLayout";
case PerformLayoutRootLayoutObjects:
return "PerformLayoutRootLayoutObjects";
case LayoutObjectsThatNeedLayoutForThemselves:
return "LayoutObjectsThatNeedLayoutForThemselves";
case LayoutObjectsThatNeedSimplifiedLayout:
return "LayoutObjectsThatNeedSimplifiedLayout";
case LayoutObjectsThatAreTableCells:
return "LayoutObjectsThatAreTableCells";
case LayoutObjectsThatAreTextAndCanNotUseTheSimpleFontCodePath:
return "LayoutObjectsThatAreTextAndCanNotUseTheSimpleFontCodePath";
case CharactersInLayoutObjectsThatAreTextAndCanNotUseTheSimpleFontCodePath:
return "CharactersInLayoutObjectsThatAreTextAndCanNotUseTheSimpleFontCode"
"Path";
case LayoutObjectsThatAreTextAndCanUseTheSimpleFontCodePath:
return "LayoutObjectsThatAreTextAndCanUseTheSimpleFontCodePath";
case CharactersInLayoutObjectsThatAreTextAndCanUseTheSimpleFontCodePath:
return "CharactersInLayoutObjectsThatAreTextAndCanUseTheSimpleFontCodePat"
"h";
case TotalLayoutObjectsThatWereLaidOut:
return "TotalLayoutObjectsThatWereLaidOut";
}
ASSERT_NOT_REACHED();
return "";
}
} // namespace blink
|