Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Side by Side Diff: Source/core/css/invalidation/StyleInvalidator.cpp

Issue 580373002: [Invalidation Tracking] Trace StyleInvalidator setNeedsStyleRecalc (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: attributes Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 1
2 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Copyright 2014 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be 3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file. 4 // found in the LICENSE file.
5 5
6 #include "config.h" 6 #include "config.h"
7 7
8 #include "core/css/invalidation/StyleInvalidator.h" 8 #include "core/css/invalidation/StyleInvalidator.h"
9 9
10 #include "core/css/invalidation/DescendantInvalidationSet.h" 10 #include "core/css/invalidation/DescendantInvalidationSet.h"
11 #include "core/dom/Document.h" 11 #include "core/dom/Document.h"
12 #include "core/dom/Element.h" 12 #include "core/dom/Element.h"
13 #include "core/dom/ElementTraversal.h" 13 #include "core/dom/ElementTraversal.h"
14 #include "core/dom/shadow/ElementShadow.h" 14 #include "core/dom/shadow/ElementShadow.h"
15 #include "core/dom/shadow/ShadowRoot.h" 15 #include "core/dom/shadow/ShadowRoot.h"
16 #include "core/inspector/InspectorTraceEvents.h"
16 #include "core/rendering/RenderObject.h" 17 #include "core/rendering/RenderObject.h"
17 18
18 namespace blink { 19 namespace blink {
19 20
21 static const unsigned char* s_tracingEnabled = nullptr;
22
23 #define TRACE_STYLE_INVALIDATOR_INVALIDATION_IF_ENABLED(element, reason) \
24 if (UNLIKELY(*s_tracingEnabled)) \
25 TRACE_STYLE_INVALIDATOR_INVALIDATION(element, reason);
26
20 void StyleInvalidator::invalidate(Document& document) 27 void StyleInvalidator::invalidate(Document& document)
21 { 28 {
22 RecursionData recursionData; 29 RecursionData recursionData;
23 if (Element* documentElement = document.documentElement()) 30 if (Element* documentElement = document.documentElement())
24 invalidate(*documentElement, recursionData); 31 invalidate(*documentElement, recursionData);
25 document.clearChildNeedsStyleInvalidation(); 32 document.clearChildNeedsStyleInvalidation();
26 document.clearNeedsStyleInvalidation(); 33 document.clearNeedsStyleInvalidation();
27 clearPendingInvalidations(); 34 clearPendingInvalidations();
28 } 35 }
29 36
(...skipping 26 matching lines...) Expand all
56 m_pendingInvalidationMap.remove(toElement(&node)); 63 m_pendingInvalidationMap.remove(toElement(&node));
57 } 64 }
58 65
59 void StyleInvalidator::clearPendingInvalidations() 66 void StyleInvalidator::clearPendingInvalidations()
60 { 67 {
61 m_pendingInvalidationMap.clear(); 68 m_pendingInvalidationMap.clear();
62 } 69 }
63 70
64 StyleInvalidator::StyleInvalidator() 71 StyleInvalidator::StyleInvalidator()
65 { 72 {
73 s_tracingEnabled = TRACE_EVENT_API_GET_CATEGORY_ENABLED(TRACE_DISABLED_BY_DE FAULT("devtools.timeline.invalidationTracking"));
74 DescendantInvalidationSet::cacheTracingFlag();
66 } 75 }
67 76
68 StyleInvalidator::~StyleInvalidator() 77 StyleInvalidator::~StyleInvalidator()
69 { 78 {
70 } 79 }
71 80
72 void StyleInvalidator::RecursionData::pushInvalidationSet(const DescendantInvali dationSet& invalidationSet) 81 void StyleInvalidator::RecursionData::pushInvalidationSet(const DescendantInvali dationSet& invalidationSet)
73 { 82 {
74 ASSERT(!m_wholeSubtreeInvalid); 83 ASSERT(!m_wholeSubtreeInvalid);
75 if (invalidationSet.treeBoundaryCrossing()) 84 if (invalidationSet.treeBoundaryCrossing())
76 m_treeBoundaryCrossing = true; 85 m_treeBoundaryCrossing = true;
77 if (invalidationSet.wholeSubtreeInvalid()) { 86 if (invalidationSet.wholeSubtreeInvalid()) {
78 m_wholeSubtreeInvalid = true; 87 m_wholeSubtreeInvalid = true;
79 return; 88 return;
80 } 89 }
81 m_invalidationSets.append(&invalidationSet); 90 m_invalidationSets.append(&invalidationSet);
82 m_invalidateCustomPseudo = invalidationSet.customPseudoInvalid(); 91 m_invalidateCustomPseudo = invalidationSet.customPseudoInvalid();
83 } 92 }
84 93
85 bool StyleInvalidator::RecursionData::matchesCurrentInvalidationSets(Element& el ement) 94 ALWAYS_INLINE bool StyleInvalidator::RecursionData::matchesCurrentInvalidationSe ts(Element& element)
86 { 95 {
87 ASSERT(!m_wholeSubtreeInvalid); 96 ASSERT(!m_wholeSubtreeInvalid);
88 97
89 if (m_invalidateCustomPseudo && element.shadowPseudoId() != nullAtom) 98 if (m_invalidateCustomPseudo && element.shadowPseudoId() != nullAtom) {
99 TRACE_STYLE_INVALIDATOR_INVALIDATION_IF_ENABLED(element, InvalidateCusto mPseudo);
90 return true; 100 return true;
101 }
91 102
92 for (const auto& invalidationSet : m_invalidationSets) { 103 for (const auto& invalidationSet : m_invalidationSets) {
93 if (invalidationSet->invalidatesElement(element)) 104 if (invalidationSet->invalidatesElement(element))
94 return true; 105 return true;
95 } 106 }
96 107
97 return false; 108 return false;
98 } 109 }
99 110
100 bool StyleInvalidator::checkInvalidationSetsAgainstElement(Element& element, Sty leInvalidator::RecursionData& recursionData) 111 ALWAYS_INLINE bool StyleInvalidator::checkInvalidationSetsAgainstElement(Element & element, StyleInvalidator::RecursionData& recursionData)
101 { 112 {
102 if (element.styleChangeType() >= SubtreeStyleChange || recursionData.wholeSu btreeInvalid()) { 113 if (element.styleChangeType() >= SubtreeStyleChange || recursionData.wholeSu btreeInvalid()) {
103 recursionData.setWholeSubtreeInvalid(); 114 recursionData.setWholeSubtreeInvalid();
104 return false; 115 return false;
105 } 116 }
106 if (element.needsStyleInvalidation()) { 117 if (element.needsStyleInvalidation()) {
107 if (InvalidationList* invalidationList = m_pendingInvalidationMap.get(&e lement)) { 118 if (InvalidationList* invalidationList = m_pendingInvalidationMap.get(&e lement)) {
108 for (const auto& invalidationSet : *invalidationList) 119 for (const auto& invalidationSet : *invalidationList)
109 recursionData.pushInvalidationSet(*invalidationSet); 120 recursionData.pushInvalidationSet(*invalidationSet);
110 // FIXME: It's really only necessary to clone the render style for t his element, not full style recalc. 121 // FIXME: It's really only necessary to clone the render style for t his element, not full style recalc.
122 if (UNLIKELY(*s_tracingEnabled)) {
123 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timelin e.invalidationTracking"),
124 "StyleInvalidatorInvalidationTracking",
125 "data", InspectorStyleInvalidatorInvalidateEvent::invalidati onList(element, *invalidationList));
126 }
111 return true; 127 return true;
112 } 128 }
113 } 129 }
130
114 return recursionData.matchesCurrentInvalidationSets(element); 131 return recursionData.matchesCurrentInvalidationSets(element);
115 } 132 }
116 133
117 bool StyleInvalidator::invalidateChildren(Element& element, StyleInvalidator::Re cursionData& recursionData) 134 bool StyleInvalidator::invalidateChildren(Element& element, StyleInvalidator::Re cursionData& recursionData)
118 { 135 {
119 bool someChildrenNeedStyleRecalc = false; 136 bool someChildrenNeedStyleRecalc = false;
120 for (ShadowRoot* root = element.youngestShadowRoot(); root; root = root->old erShadowRoot()) { 137 for (ShadowRoot* root = element.youngestShadowRoot(); root; root = root->old erShadowRoot()) {
121 if (!recursionData.treeBoundaryCrossing() && !root->childNeedsStyleInval idation() && !root->needsStyleInvalidation()) 138 if (!recursionData.treeBoundaryCrossing() && !root->childNeedsStyleInval idation() && !root->needsStyleInvalidation())
122 continue; 139 continue;
123 for (Element* child = ElementTraversal::firstChild(*root); child; child = ElementTraversal::nextSibling(*child)) { 140 for (Element* child = ElementTraversal::firstChild(*root); child; child = ElementTraversal::nextSibling(*child)) {
(...skipping 17 matching lines...) Expand all
141 bool thisElementNeedsStyleRecalc = checkInvalidationSetsAgainstElement(eleme nt, recursionData); 158 bool thisElementNeedsStyleRecalc = checkInvalidationSetsAgainstElement(eleme nt, recursionData);
142 159
143 bool someChildrenNeedStyleRecalc = false; 160 bool someChildrenNeedStyleRecalc = false;
144 if (recursionData.hasInvalidationSets() || element.childNeedsStyleInvalidati on()) 161 if (recursionData.hasInvalidationSets() || element.childNeedsStyleInvalidati on())
145 someChildrenNeedStyleRecalc = invalidateChildren(element, recursionData) ; 162 someChildrenNeedStyleRecalc = invalidateChildren(element, recursionData) ;
146 163
147 if (thisElementNeedsStyleRecalc) { 164 if (thisElementNeedsStyleRecalc) {
148 element.setNeedsStyleRecalc(recursionData.wholeSubtreeInvalid() ? Subtre eStyleChange : LocalStyleChange, StyleChangeReasonForTracing::create(StyleChange Reason::StyleInvalidator)); 165 element.setNeedsStyleRecalc(recursionData.wholeSubtreeInvalid() ? Subtre eStyleChange : LocalStyleChange, StyleChangeReasonForTracing::create(StyleChange Reason::StyleInvalidator));
149 } else if (recursionData.hasInvalidationSets() && someChildrenNeedStyleRecal c) { 166 } else if (recursionData.hasInvalidationSets() && someChildrenNeedStyleRecal c) {
150 // Clone the RenderStyle in order to preserve correct style sharing, if possible. Otherwise recalc style. 167 // Clone the RenderStyle in order to preserve correct style sharing, if possible. Otherwise recalc style.
151 if (RenderObject* renderer = element.renderer()) 168 if (RenderObject* renderer = element.renderer()) {
152 renderer->setStyleInternal(RenderStyle::clone(renderer->style())); 169 renderer->setStyleInternal(RenderStyle::clone(renderer->style()));
153 else 170 } else {
171 TRACE_STYLE_INVALIDATOR_INVALIDATION_IF_ENABLED(element, PreventStyl eSharingForParent);
154 element.setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTr acing::create(StyleChangeReason::StyleInvalidator)); 172 element.setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTr acing::create(StyleChangeReason::StyleInvalidator));
173 }
155 } 174 }
156 175
157 element.clearChildNeedsStyleInvalidation(); 176 element.clearChildNeedsStyleInvalidation();
158 element.clearNeedsStyleInvalidation(); 177 element.clearNeedsStyleInvalidation();
159 178
160 return thisElementNeedsStyleRecalc; 179 return thisElementNeedsStyleRecalc;
161 } 180 }
162 181
163 void StyleInvalidator::trace(Visitor* visitor) 182 void StyleInvalidator::trace(Visitor* visitor)
164 { 183 {
165 #if ENABLE(OILPAN) 184 #if ENABLE(OILPAN)
166 visitor->trace(m_pendingInvalidationMap); 185 visitor->trace(m_pendingInvalidationMap);
167 #endif 186 #endif
168 } 187 }
169 188
170 } // namespace blink 189 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/css/invalidation/DescendantInvalidationSet.cpp ('k') | Source/core/inspector/InspectorTraceEvents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698