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

Side by Side Diff: third_party/WebKit/Source/core/css/invalidation/StyleSheetInvalidationAnalysis.cpp

Issue 2105743002: Optimize style recalc when adding @keyframes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test review issues Created 4 years, 5 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 (C) 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2012 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 14 matching lines...) Expand all
25 25
26 #include "core/css/invalidation/StyleSheetInvalidationAnalysis.h" 26 #include "core/css/invalidation/StyleSheetInvalidationAnalysis.h"
27 27
28 #include "core/css/CSSSelectorList.h" 28 #include "core/css/CSSSelectorList.h"
29 #include "core/css/StyleRuleImport.h" 29 #include "core/css/StyleRuleImport.h"
30 #include "core/css/StyleSheetContents.h" 30 #include "core/css/StyleSheetContents.h"
31 #include "core/dom/ContainerNode.h" 31 #include "core/dom/ContainerNode.h"
32 #include "core/dom/Document.h" 32 #include "core/dom/Document.h"
33 #include "core/dom/ElementTraversal.h" 33 #include "core/dom/ElementTraversal.h"
34 #include "core/dom/StyleChangeReason.h" 34 #include "core/dom/StyleChangeReason.h"
35 #include "core/dom/StyleEngine.h"
35 #include "core/dom/TreeScope.h" 36 #include "core/dom/TreeScope.h"
36 #include "core/dom/shadow/ShadowRoot.h" 37 #include "core/dom/shadow/ShadowRoot.h"
37 #include "core/html/HTMLStyleElement.h" 38 #include "core/html/HTMLStyleElement.h"
38 39
39 namespace blink { 40 namespace blink {
40 41
41 StyleSheetInvalidationAnalysis::StyleSheetInvalidationAnalysis(const TreeScope& treeScope, const HeapVector<Member<StyleSheetContents>>& sheets) 42 StyleSheetInvalidationAnalysis::StyleSheetInvalidationAnalysis(const TreeScope& treeScope, const HeapVector<Member<StyleSheetContents>>& sheets)
42 : m_treeScope(&treeScope) 43 : m_treeScope(&treeScope)
43 { 44 {
44 for (unsigned i = 0; i < sheets.size() && !m_dirtiesAllStyle; ++i) 45 for (unsigned i = 0; i < sheets.size() && !m_dirtiesAllStyle; ++i)
(...skipping 25 matching lines...) Expand all
70 if (scopeSelector->match() == CSSSelector::Id) 71 if (scopeSelector->match() == CSSSelector::Id)
71 idScopes.add(scopeSelector->value().impl()); 72 idScopes.add(scopeSelector->value().impl());
72 else 73 else
73 classScopes.add(scopeSelector->value().impl()); 74 classScopes.add(scopeSelector->value().impl());
74 } 75 }
75 return true; 76 return true;
76 } 77 }
77 78
78 static bool ruleAdditionMightRequireDocumentStyleRecalc(StyleRuleBase* rule) 79 static bool ruleAdditionMightRequireDocumentStyleRecalc(StyleRuleBase* rule)
79 { 80 {
80 // This funciton is conservative. We only return false when we know that 81 // This function is conservative. We only return false when we know that
81 // the added @rule can't require style recalcs. 82 // the added @rule can't require style recalcs.
82 switch (rule->type()) { 83 switch (rule->type()) {
83 case StyleRule::Import: // Whatever we import should do its own analysis, we don't need to invalidate the document here! 84 case StyleRule::Import: // Whatever we import should do its own analysis, we don't need to invalidate the document here!
84 case StyleRule::Page: // Page rules apply only during printing, we force a f ull-recalc before printing. 85 case StyleRule::Page: // Page rules apply only during printing, we force a f ull-recalc before printing.
85 return false; 86 return false;
86 87
87 case StyleRule::Media: // If the media rule doesn't apply, we could avoid re calc. 88 case StyleRule::Media: // If the media rule doesn't apply, we could avoid re calc.
88 case StyleRule::FontFace: // If the fonts aren't in use, we could avoid reca lc. 89 case StyleRule::FontFace: // If the fonts aren't in use, we could avoid reca lc.
89 case StyleRule::Supports: // If we evaluated the supports-clause we could av oid recalc. 90 case StyleRule::Supports: // If we evaluated the supports-clause we could av oid recalc.
90 case StyleRule::Viewport: // If the viewport doesn't match, we could avoid r ecalcing. 91 case StyleRule::Viewport: // If the viewport doesn't match, we could avoid r ecalcing.
91 case StyleRule::Keyframes: // If the animation doesn't match an element, we could avoid recalc.
92 return true; 92 return true;
93 93
94 // These should all be impossible to reach: 94 // These should all be impossible to reach:
95 case StyleRule::Charset: 95 case StyleRule::Charset:
96 case StyleRule::Keyframe: 96 case StyleRule::Keyframe:
97 case StyleRule::Namespace: 97 case StyleRule::Namespace:
98 case StyleRule::Style: 98 case StyleRule::Style:
99 case StyleRule::Keyframes:
99 break; 100 break;
100 } 101 }
101 ASSERT_NOT_REACHED(); 102 ASSERT_NOT_REACHED();
102 return true; 103 return true;
103 } 104 }
104 105
105 void StyleSheetInvalidationAnalysis::analyzeStyleSheet(StyleSheetContents* style SheetContents) 106 void StyleSheetInvalidationAnalysis::analyzeStyleSheet(StyleSheetContents* style SheetContents)
106 { 107 {
107 // Updating the style on the shadow DOM for image fallback content can bring us here when imports 108 // Updating the style on the shadow DOM for image fallback content can bring us here when imports
108 // are still getting loaded in the main document. Just need to exit early as we will return here 109 // are still getting loaded in the main document. Just need to exit early as we will return here
(...skipping 12 matching lines...) Expand all
121 return; 122 return;
122 } 123 }
123 124
124 if (m_treeScope->rootNode().isShadowRoot()) 125 if (m_treeScope->rootNode().isShadowRoot())
125 return; 126 return;
126 127
127 const HeapVector<Member<StyleRuleBase>>& rules = styleSheetContents->childRu les(); 128 const HeapVector<Member<StyleRuleBase>>& rules = styleSheetContents->childRu les();
128 for (unsigned i = 0; i < rules.size(); i++) { 129 for (unsigned i = 0; i < rules.size(); i++) {
129 StyleRuleBase* rule = rules[i].get(); 130 StyleRuleBase* rule = rules[i].get();
130 if (!rule->isStyleRule()) { 131 if (!rule->isStyleRule()) {
132 if (rule->type() == StyleRule::Keyframes) {
133 m_addsKeyframes = true;
134 continue;
135 }
131 if (ruleAdditionMightRequireDocumentStyleRecalc(rule)) { 136 if (ruleAdditionMightRequireDocumentStyleRecalc(rule)) {
132 m_dirtiesAllStyle = true; 137 m_dirtiesAllStyle = true;
133 return; 138 return;
134 } 139 }
135 continue; 140 continue;
136 } 141 }
137 StyleRule* styleRule = toStyleRule(rule); 142 StyleRule* styleRule = toStyleRule(rule);
138 if (!determineSelectorScopes(styleRule->selectorList(), m_idScopes, m_cl assScopes)) { 143 if (!determineSelectorScopes(styleRule->selectorList(), m_idScopes, m_cl assScopes)) {
139 m_dirtiesAllStyle = true; 144 m_dirtiesAllStyle = true;
140 return; 145 return;
(...skipping 12 matching lines...) Expand all
153 if (classScopes.contains(classNames[i].impl())) 158 if (classScopes.contains(classNames[i].impl()))
154 return true; 159 return true;
155 } 160 }
156 return false; 161 return false;
157 } 162 }
158 163
159 void StyleSheetInvalidationAnalysis::invalidateStyle() 164 void StyleSheetInvalidationAnalysis::invalidateStyle()
160 { 165 {
161 ASSERT(!m_dirtiesAllStyle); 166 ASSERT(!m_dirtiesAllStyle);
162 167
168 if (m_addsKeyframes)
169 m_treeScope->document().styleEngine().keyframesRulesAdded();
170
163 if (m_treeScope->rootNode().isShadowRoot()) { 171 if (m_treeScope->rootNode().isShadowRoot()) {
164 ContainerNode& shadowHost = toShadowRoot(m_treeScope->rootNode()).host() ; 172 ContainerNode& shadowHost = toShadowRoot(m_treeScope->rootNode()).host() ;
165 shadowHost.setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForT racing::create(StyleChangeReason::StyleSheetChange)); 173 shadowHost.setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForT racing::create(StyleChangeReason::StyleSheetChange));
166 return; 174 return;
167 } 175 }
168 176
169 if (m_idScopes.isEmpty() && m_classScopes.isEmpty()) 177 if (m_idScopes.isEmpty() && m_classScopes.isEmpty())
170 return; 178 return;
171 Element* element = ElementTraversal::firstWithin(m_treeScope->document()); 179 Element* element = ElementTraversal::firstWithin(m_treeScope->document());
172 while (element) { 180 while (element) {
173 if (elementMatchesSelectorScopes(element, m_idScopes, m_classScopes)) { 181 if (elementMatchesSelectorScopes(element, m_idScopes, m_classScopes)) {
174 element->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonFo rTracing::create(StyleChangeReason::StyleSheetChange)); 182 element->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonFo rTracing::create(StyleChangeReason::StyleSheetChange));
175 // The whole subtree is now invalidated, we can skip to the next sib ling. 183 // The whole subtree is now invalidated, we can skip to the next sib ling.
176 element = ElementTraversal::nextSkippingChildren(*element); 184 element = ElementTraversal::nextSkippingChildren(*element);
177 continue; 185 continue;
178 } 186 }
179 element = ElementTraversal::next(*element); 187 element = ElementTraversal::next(*element);
180 } 188 }
181 } 189 }
182 190
183 } // namespace blink 191 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698