OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/css/invalidation/StyleInvalidator.h" | 5 #include "core/css/invalidation/StyleInvalidator.h" |
6 | 6 |
7 #include "core/css/invalidation/InvalidationSet.h" | 7 #include "core/css/invalidation/InvalidationSet.h" |
8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
9 #include "core/dom/Element.h" | 9 #include "core/dom/Element.h" |
10 #include "core/dom/ElementTraversal.h" | 10 #include "core/dom/ElementTraversal.h" |
11 #include "core/dom/StyleChangeReason.h" | 11 #include "core/dom/StyleChangeReason.h" |
12 #include "core/dom/shadow/ElementShadow.h" | 12 #include "core/dom/shadow/ElementShadow.h" |
13 #include "core/dom/shadow/ShadowRoot.h" | 13 #include "core/dom/shadow/ShadowRoot.h" |
14 #include "core/html/HTMLSlotElement.h" | 14 #include "core/html/HTMLSlotElement.h" |
15 #include "core/inspector/InspectorTraceEvents.h" | 15 #include "core/inspector/InspectorTraceEvents.h" |
16 #include "core/layout/LayoutObject.h" | 16 #include "core/layout/LayoutObject.h" |
17 #include "wtf/PtrUtil.h" | 17 #include "wtf/PtrUtil.h" |
18 | 18 |
19 namespace blink { | 19 namespace blink { |
20 | 20 |
21 // StyleInvalidator methods are super sensitive to performance benchmarks. | 21 // StyleInvalidator methods are super sensitive to performance benchmarks. |
22 // We easily get 1% regression per additional if statement on recursive | 22 // We easily get 1% regression per additional if statement on recursive |
23 // invalidate methods. | 23 // invalidate methods. |
24 // To minimize performance impact, we wrap trace events with a lookup of | 24 // To minimize performance impact, we wrap trace events with a lookup of |
25 // cached flag. The cached flag is made "static const" and is not shared | 25 // cached flag. The cached flag is made "static const" and is not shared |
26 // with InvalidationSet to avoid additional GOT lookup cost. | 26 // with InvalidationSet to avoid additional GOT lookup cost. |
27 static const unsigned char* s_tracingEnabled = nullptr; | 27 static const unsigned char* s_styleInvalidatorTracingEnabled = nullptr; |
28 | 28 |
29 #define TRACE_STYLE_INVALIDATOR_INVALIDATION_IF_ENABLED(element, reason) \ | 29 #define TRACE_STYLE_INVALIDATOR_INVALIDATION_IF_ENABLED(element, reason) \ |
30 if (UNLIKELY(*s_tracingEnabled)) \ | 30 if (UNLIKELY(*s_styleInvalidatorTracingEnabled)) \ |
31 TRACE_STYLE_INVALIDATOR_INVALIDATION(element, reason); | 31 TRACE_STYLE_INVALIDATOR_INVALIDATION(element, reason); |
32 | 32 |
33 void StyleInvalidator::invalidate(Document& document) { | 33 void StyleInvalidator::invalidate(Document& document) { |
34 RecursionData recursionData; | 34 RecursionData recursionData; |
35 SiblingData siblingData; | 35 SiblingData siblingData; |
36 if (UNLIKELY(document.needsStyleInvalidation())) | 36 if (UNLIKELY(document.needsStyleInvalidation())) |
37 pushInvalidationSetsForContainerNode(document, recursionData, siblingData); | 37 pushInvalidationSetsForContainerNode(document, recursionData, siblingData); |
38 if (Element* documentElement = document.documentElement()) | 38 if (Element* documentElement = document.documentElement()) |
39 invalidate(*documentElement, recursionData, siblingData); | 39 invalidate(*documentElement, recursionData, siblingData); |
40 document.clearChildNeedsStyleInvalidation(); | 40 document.clearChildNeedsStyleInvalidation(); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 PendingInvalidations& StyleInvalidator::ensurePendingInvalidations( | 163 PendingInvalidations& StyleInvalidator::ensurePendingInvalidations( |
164 ContainerNode& node) { | 164 ContainerNode& node) { |
165 PendingInvalidationMap::AddResult addResult = | 165 PendingInvalidationMap::AddResult addResult = |
166 m_pendingInvalidationMap.insert(&node, nullptr); | 166 m_pendingInvalidationMap.insert(&node, nullptr); |
167 if (addResult.isNewEntry) | 167 if (addResult.isNewEntry) |
168 addResult.storedValue->value = WTF::makeUnique<PendingInvalidations>(); | 168 addResult.storedValue->value = WTF::makeUnique<PendingInvalidations>(); |
169 return *addResult.storedValue->value; | 169 return *addResult.storedValue->value; |
170 } | 170 } |
171 | 171 |
172 StyleInvalidator::StyleInvalidator() { | 172 StyleInvalidator::StyleInvalidator() { |
173 s_tracingEnabled = TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( | 173 s_styleInvalidatorTracingEnabled = TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( |
174 TRACE_DISABLED_BY_DEFAULT("devtools.timeline.invalidationTracking")); | 174 TRACE_DISABLED_BY_DEFAULT("devtools.timeline.invalidationTracking")); |
175 InvalidationSet::cacheTracingFlag(); | 175 InvalidationSet::cacheTracingFlag(); |
176 } | 176 } |
177 | 177 |
178 StyleInvalidator::~StyleInvalidator() {} | 178 StyleInvalidator::~StyleInvalidator() {} |
179 | 179 |
180 void StyleInvalidator::RecursionData::pushInvalidationSet( | 180 void StyleInvalidator::RecursionData::pushInvalidationSet( |
181 const InvalidationSet& invalidationSet) { | 181 const InvalidationSet& invalidationSet) { |
182 DCHECK(!m_wholeSubtreeInvalid); | 182 DCHECK(!m_wholeSubtreeInvalid); |
183 DCHECK(!invalidationSet.wholeSubtreeInvalid()); | 183 DCHECK(!invalidationSet.wholeSubtreeInvalid()); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 } | 292 } |
293 | 293 |
294 if (node.getStyleChangeType() >= SubtreeStyleChange) | 294 if (node.getStyleChangeType() >= SubtreeStyleChange) |
295 return; | 295 return; |
296 | 296 |
297 if (!pendingInvalidations->descendants().isEmpty()) { | 297 if (!pendingInvalidations->descendants().isEmpty()) { |
298 for (const auto& invalidationSet : pendingInvalidations->descendants()) { | 298 for (const auto& invalidationSet : pendingInvalidations->descendants()) { |
299 CHECK(invalidationSet->isAlive()); | 299 CHECK(invalidationSet->isAlive()); |
300 recursionData.pushInvalidationSet(*invalidationSet); | 300 recursionData.pushInvalidationSet(*invalidationSet); |
301 } | 301 } |
302 if (UNLIKELY(*s_tracingEnabled)) { | 302 if (UNLIKELY(*s_styleInvalidatorTracingEnabled)) { |
303 TRACE_EVENT_INSTANT1( | 303 TRACE_EVENT_INSTANT1( |
304 TRACE_DISABLED_BY_DEFAULT("devtools.timeline.invalidationTracking"), | 304 TRACE_DISABLED_BY_DEFAULT("devtools.timeline.invalidationTracking"), |
305 "StyleInvalidatorInvalidationTracking", TRACE_EVENT_SCOPE_THREAD, | 305 "StyleInvalidatorInvalidationTracking", TRACE_EVENT_SCOPE_THREAD, |
306 "data", InspectorStyleInvalidatorInvalidateEvent::invalidationList( | 306 "data", InspectorStyleInvalidatorInvalidateEvent::invalidationList( |
307 node, pendingInvalidations->descendants())); | 307 node, pendingInvalidations->descendants())); |
308 } | 308 } |
309 } | 309 } |
310 } | 310 } |
311 | 311 |
312 ALWAYS_INLINE bool StyleInvalidator::checkInvalidationSetsAgainstElement( | 312 ALWAYS_INLINE bool StyleInvalidator::checkInvalidationSetsAgainstElement( |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 continue; | 434 continue; |
435 if (recursionData.matchesCurrentInvalidationSetsAsSlotted( | 435 if (recursionData.matchesCurrentInvalidationSetsAsSlotted( |
436 toElement(*distributedNode))) | 436 toElement(*distributedNode))) |
437 distributedNode->setNeedsStyleRecalc( | 437 distributedNode->setNeedsStyleRecalc( |
438 LocalStyleChange, StyleChangeReasonForTracing::create( | 438 LocalStyleChange, StyleChangeReasonForTracing::create( |
439 StyleChangeReason::StyleInvalidator)); | 439 StyleChangeReason::StyleInvalidator)); |
440 } | 440 } |
441 } | 441 } |
442 | 442 |
443 } // namespace blink | 443 } // namespace blink |
OLD | NEW |