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

Side by Side Diff: third_party/WebKit/Source/core/css/resolver/StyleResolver.cpp

Issue 1644543002: Moved element style recalc count and stats to StyleEngine. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 139 }
140 } 140 }
141 } 141 }
142 142
143 StyleResolver::StyleResolver(Document& document) 143 StyleResolver::StyleResolver(Document& document)
144 : m_document(document) 144 : m_document(document)
145 , m_viewportStyleResolver(ViewportStyleResolver::create(&document)) 145 , m_viewportStyleResolver(ViewportStyleResolver::create(&document))
146 , m_needCollectFeatures(false) 146 , m_needCollectFeatures(false)
147 , m_printMediaType(false) 147 , m_printMediaType(false)
148 , m_styleSharingDepth(0) 148 , m_styleSharingDepth(0)
149 , m_accessCount(0)
150 { 149 {
151 FrameView* view = document.view(); 150 FrameView* view = document.view();
152 if (view) { 151 if (view) {
153 m_medium = adoptPtrWillBeNoop(new MediaQueryEvaluator(&view->frame())); 152 m_medium = adoptPtrWillBeNoop(new MediaQueryEvaluator(&view->frame()));
154 m_printMediaType = equalIgnoringCase(view->mediaType(), MediaTypeNames:: print); 153 m_printMediaType = equalIgnoringCase(view->mediaType(), MediaTypeNames:: print);
155 } else { 154 } else {
156 m_medium = adoptPtrWillBeNoop(new MediaQueryEvaluator("all")); 155 m_medium = adoptPtrWillBeNoop(new MediaQueryEvaluator("all"));
157 } 156 }
158 157
159 initWatchedSelectorRules(); 158 initWatchedSelectorRules();
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 return m_features.hasSelectorForId(id); 321 return m_features.hasSelectorForId(id);
323 } 322 }
324 323
325 void StyleResolver::addToStyleSharingList(Element& element) 324 void StyleResolver::addToStyleSharingList(Element& element)
326 { 325 {
327 ASSERT(RuntimeEnabledFeatures::styleSharingEnabled()); 326 ASSERT(RuntimeEnabledFeatures::styleSharingEnabled());
328 // Never add elements to the style sharing list if we're not in a recalcStyl e, 327 // Never add elements to the style sharing list if we're not in a recalcStyl e,
329 // otherwise we could leave stale pointers in there. 328 // otherwise we could leave stale pointers in there.
330 if (!document().inStyleRecalc()) 329 if (!document().inStyleRecalc())
331 return; 330 return;
332 INCREMENT_STYLE_STATS_COUNTER(*this, sharedStyleCandidates, 1); 331 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), sharedStyleCandidate s, 1);
333 StyleSharingList& list = styleSharingList(); 332 StyleSharingList& list = styleSharingList();
334 if (list.size() >= styleSharingListSize) 333 if (list.size() >= styleSharingListSize)
335 list.removeLast(); 334 list.removeLast();
336 list.prepend(&element); 335 list.prepend(&element);
337 } 336 }
338 337
339 StyleSharingList& StyleResolver::styleSharingList() 338 StyleSharingList& StyleResolver::styleSharingList()
340 { 339 {
341 m_styleSharingLists.resize(styleSharingMaxDepth); 340 m_styleSharingLists.resize(styleSharingMaxDepth);
342 341
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 if (!s_styleNotYetAvailable) { 568 if (!s_styleNotYetAvailable) {
570 s_styleNotYetAvailable = ComputedStyle::create().leakRef(); 569 s_styleNotYetAvailable = ComputedStyle::create().leakRef();
571 s_styleNotYetAvailable->setDisplay(NONE); 570 s_styleNotYetAvailable->setDisplay(NONE);
572 s_styleNotYetAvailable->font().update(document().styleEngine().fontS elector()); 571 s_styleNotYetAvailable->font().update(document().styleEngine().fontS elector());
573 } 572 }
574 573
575 document().setHasNodesWithPlaceholderStyle(); 574 document().setHasNodesWithPlaceholderStyle();
576 return s_styleNotYetAvailable; 575 return s_styleNotYetAvailable;
577 } 576 }
578 577
579 didAccess(); 578 document().styleEngine().incStyleForElementCount();
580 INCREMENT_STYLE_STATS_COUNTER(*this, elementsStyled, 1); 579 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), elementsStyled, 1);
581 580
582 StyleResolverParentScope::ensureParentStackIsPushed(); 581 StyleResolverParentScope::ensureParentStackIsPushed();
583 582
584 ElementResolveContext elementContext(*element); 583 ElementResolveContext elementContext(*element);
585 584
586 if (RuntimeEnabledFeatures::styleSharingEnabled() && sharingBehavior == Allo wStyleSharing && (defaultParent || elementContext.parentStyle())) { 585 if (RuntimeEnabledFeatures::styleSharingEnabled() && sharingBehavior == Allo wStyleSharing && (defaultParent || elementContext.parentStyle())) {
587 SharedStyleFinder styleFinder(elementContext, m_features, m_siblingRuleS et.get(), m_uncommonAttributeRuleSet.get(), *this); 586 SharedStyleFinder styleFinder(elementContext, m_features, m_siblingRuleS et.get(), m_uncommonAttributeRuleSet.get(), *this);
588 if (RefPtr<ComputedStyle> sharedStyle = styleFinder.findSharedStyle()) 587 if (RefPtr<ComputedStyle> sharedStyle = styleFinder.findSharedStyle())
589 return sharedStyle.release(); 588 return sharedStyle.release();
590 } 589 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 applyCallbackSelectors(state); 653 applyCallbackSelectors(state);
655 654
656 // Cache our original display. 655 // Cache our original display.
657 state.style()->setOriginalDisplay(state.style()->display()); 656 state.style()->setOriginalDisplay(state.style()->display());
658 657
659 adjustComputedStyle(state, element); 658 adjustComputedStyle(state, element);
660 659
661 if (elementAnimations) 660 if (elementAnimations)
662 elementAnimations->updateBaseComputedStyle(state.style()); 661 elementAnimations->updateBaseComputedStyle(state.style());
663 } else { 662 } else {
664 INCREMENT_STYLE_STATS_COUNTER(*this, baseStylesUsed, 1); 663 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), baseStylesUsed, 1);
665 } 664 }
666 665
667 // FIXME: The CSSWG wants to specify that the effects of animations are appl ied before 666 // FIXME: The CSSWG wants to specify that the effects of animations are appl ied before
668 // important rules, but this currently happens here as we require adjustment to have happened 667 // important rules, but this currently happens here as we require adjustment to have happened
669 // before deciding which properties to transition. 668 // before deciding which properties to transition.
670 if (applyAnimatedProperties(state, element)) { 669 if (applyAnimatedProperties(state, element)) {
671 INCREMENT_STYLE_STATS_COUNTER(*this, stylesAnimated, 1); 670 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesAnimated, 1);
672 adjustComputedStyle(state, element); 671 adjustComputedStyle(state, element);
673 } 672 }
674 673
675 if (isHTMLBodyElement(*element)) 674 if (isHTMLBodyElement(*element))
676 document().textLinkColors().setTextColor(state.style()->color()); 675 document().textLinkColors().setTextColor(state.style()->color());
677 676
678 setAnimationUpdateIfNeeded(state, *element); 677 setAnimationUpdateIfNeeded(state, *element);
679 678
680 if (state.style()->hasViewportUnits()) 679 if (state.style()->hasViewportUnits())
681 document().setHasViewportUnits(); 680 document().setHasViewportUnits();
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 if (elementAnimations) 811 if (elementAnimations)
813 elementAnimations->updateBaseComputedStyle(state.style()); 812 elementAnimations->updateBaseComputedStyle(state.style());
814 } 813 }
815 814
816 // FIXME: The CSSWG wants to specify that the effects of animations are appl ied before 815 // FIXME: The CSSWG wants to specify that the effects of animations are appl ied before
817 // important rules, but this currently happens here as we require adjustment to have happened 816 // important rules, but this currently happens here as we require adjustment to have happened
818 // before deciding which properties to transition. 817 // before deciding which properties to transition.
819 if (applyAnimatedProperties(state, pseudoElement)) 818 if (applyAnimatedProperties(state, pseudoElement))
820 adjustComputedStyle(state, 0); 819 adjustComputedStyle(state, 0);
821 820
822 didAccess(); 821 document().styleEngine().incStyleForElementCount();
823 INCREMENT_STYLE_STATS_COUNTER(*this, pseudoElementsStyled, 1); 822 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), pseudoElementsStyled , 1);
824 823
825 if (state.style()->hasViewportUnits()) 824 if (state.style()->hasViewportUnits())
826 document().setHasViewportUnits(); 825 document().setHasViewportUnits();
827 826
828 return true; 827 return true;
829 } 828 }
830 829
831 PassRefPtr<ComputedStyle> StyleResolver::pseudoStyleForElement(Element* element, const PseudoStyleRequest& pseudoStyleRequest, const ComputedStyle* parentStyle) 830 PassRefPtr<ComputedStyle> StyleResolver::pseudoStyleForElement(Element* element, const PseudoStyleRequest& pseudoStyleRequest, const ComputedStyle* parentStyle)
832 { 831 {
833 ASSERT(parentStyle); 832 ASSERT(parentStyle);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 const MatchResult& result = collector.matchedResult(); 870 const MatchResult& result = collector.matchedResult();
872 applyMatchedProperties<HighPropertyPriority>(state, result.allRules(), false , inheritedOnly); 871 applyMatchedProperties<HighPropertyPriority>(state, result.allRules(), false , inheritedOnly);
873 872
874 // If our font got dirtied, go ahead and update it now. 873 // If our font got dirtied, go ahead and update it now.
875 updateFont(state); 874 updateFont(state);
876 875
877 applyMatchedProperties<LowPropertyPriority>(state, result.allRules(), false, inheritedOnly); 876 applyMatchedProperties<LowPropertyPriority>(state, result.allRules(), false, inheritedOnly);
878 877
879 loadPendingResources(state); 878 loadPendingResources(state);
880 879
881 didAccess();
882
883 // Now return the style. 880 // Now return the style.
884 return state.takeStyle(); 881 return state.takeStyle();
885 } 882 }
886 883
887 PassRefPtr<ComputedStyle> StyleResolver::initialStyleForElement() 884 PassRefPtr<ComputedStyle> StyleResolver::initialStyleForElement()
888 { 885 {
889 RefPtr<ComputedStyle> style = ComputedStyle::create(); 886 RefPtr<ComputedStyle> style = ComputedStyle::create();
890 FontBuilder fontBuilder(document()); 887 FontBuilder fontBuilder(document());
891 fontBuilder.setInitial(style->effectiveZoom()); 888 fontBuilder.setInitial(style->effectiveZoom());
892 fontBuilder.createFont(document().styleEngine().fontSelector(), *style); 889 fontBuilder.createFont(document().styleEngine().fontSelector(), *style);
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 { 1338 {
1342 m_viewportStyleResolver->collectViewportRules(); 1339 m_viewportStyleResolver->collectViewportRules();
1343 m_matchedPropertiesCache.clearViewportDependent(); 1340 m_matchedPropertiesCache.clearViewportDependent();
1344 } 1341 }
1345 1342
1346 void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc hResult& matchResult) 1343 void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc hResult& matchResult)
1347 { 1344 {
1348 const Element* element = state.element(); 1345 const Element* element = state.element();
1349 ASSERT(element); 1346 ASSERT(element);
1350 1347
1351 INCREMENT_STYLE_STATS_COUNTER(*this, matchedPropertyApply, 1); 1348 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), matchedPropertyApply , 1);
1352 1349
1353 unsigned cacheHash = RuntimeEnabledFeatures::styleMatchedPropertiesCacheEnab led() && matchResult.isCacheable() ? computeMatchedPropertiesHash(matchResult.ma tchedProperties().data(), matchResult.matchedProperties().size()) : 0; 1350 unsigned cacheHash = RuntimeEnabledFeatures::styleMatchedPropertiesCacheEnab led() && matchResult.isCacheable() ? computeMatchedPropertiesHash(matchResult.ma tchedProperties().data(), matchResult.matchedProperties().size()) : 0;
1354 bool applyInheritedOnly = false; 1351 bool applyInheritedOnly = false;
1355 const CachedMatchedProperties* cachedMatchedProperties = cacheHash ? m_match edPropertiesCache.find(cacheHash, state, matchResult.matchedProperties()) : null ptr; 1352 const CachedMatchedProperties* cachedMatchedProperties = cacheHash ? m_match edPropertiesCache.find(cacheHash, state, matchResult.matchedProperties()) : null ptr;
1356 1353
1357 if (cachedMatchedProperties && MatchedPropertiesCache::isCacheable(*state.st yle(), *state.parentStyle())) { 1354 if (cachedMatchedProperties && MatchedPropertiesCache::isCacheable(*state.st yle(), *state.parentStyle())) {
1358 INCREMENT_STYLE_STATS_COUNTER(*this, matchedPropertyCacheHit, 1); 1355 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), matchedPropertyC acheHit, 1);
1359 // We can build up the style by copying non-inherited properties from an earlier style object built using the same exact 1356 // We can build up the style by copying non-inherited properties from an earlier style object built using the same exact
1360 // style declarations. We then only need to apply the inherited properti es, if any, as their values can depend on the 1357 // style declarations. We then only need to apply the inherited properti es, if any, as their values can depend on the
1361 // element context. This is fast and saves memory by reusing the style d ata structures. 1358 // element context. This is fast and saves memory by reusing the style d ata structures.
1362 state.style()->copyNonInheritedFromCached(*cachedMatchedProperties->comp utedStyle); 1359 state.style()->copyNonInheritedFromCached(*cachedMatchedProperties->comp utedStyle);
1363 if (state.parentStyle()->inheritedDataShared(*cachedMatchedProperties->p arentComputedStyle) && !isAtShadowBoundary(element) 1360 if (state.parentStyle()->inheritedDataShared(*cachedMatchedProperties->p arentComputedStyle) && !isAtShadowBoundary(element)
1364 && (!state.distributedToInsertionPoint() || state.style()->userModif y() == READ_ONLY)) { 1361 && (!state.distributedToInsertionPoint() || state.style()->userModif y() == READ_ONLY)) {
1365 INCREMENT_STYLE_STATS_COUNTER(*this, matchedPropertyCacheInheritedHi t, 1); 1362 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), matchedPrope rtyCacheInheritedHit, 1);
1366 1363
1367 EInsideLink linkStatus = state.style()->insideLink(); 1364 EInsideLink linkStatus = state.style()->insideLink();
1368 // If the cache item parent style has identical inherited properties to the current parent style then the 1365 // If the cache item parent style has identical inherited properties to the current parent style then the
1369 // resulting style will be identical too. We copy the inherited prop erties over from the cache and are done. 1366 // resulting style will be identical too. We copy the inherited prop erties over from the cache and are done.
1370 state.style()->inheritFrom(*cachedMatchedProperties->computedStyle); 1367 state.style()->inheritFrom(*cachedMatchedProperties->computedStyle);
1371 1368
1372 // Unfortunately the link status is treated like an inherited proper ty. We need to explicitly restore it. 1369 // Unfortunately the link status is treated like an inherited proper ty. We need to explicitly restore it.
1373 state.style()->setInsideLink(linkStatus); 1370 state.style()->setInsideLink(linkStatus);
1374 1371
1375 updateFont(state); 1372 updateFont(state);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 // and the value stored in cacheUserAgentBorderAndBackground is incorrec t, so doing this check again 1434 // and the value stored in cacheUserAgentBorderAndBackground is incorrec t, so doing this check again
1438 // would give the wrong answer. 1435 // would give the wrong answer.
1439 state.style()->setHasAuthorBackground(hasAuthorBackground(state)); 1436 state.style()->setHasAuthorBackground(hasAuthorBackground(state));
1440 state.style()->setHasAuthorBorder(hasAuthorBorder(state)); 1437 state.style()->setHasAuthorBorder(hasAuthorBorder(state));
1441 } 1438 }
1442 1439
1443 loadPendingResources(state); 1440 loadPendingResources(state);
1444 1441
1445 if (!cachedMatchedProperties && cacheHash && MatchedPropertiesCache::isCache able(*state.style(), *state.parentStyle())) { 1442 if (!cachedMatchedProperties && cacheHash && MatchedPropertiesCache::isCache able(*state.style(), *state.parentStyle())) {
1446 ASSERT(RuntimeEnabledFeatures::styleMatchedPropertiesCacheEnabled()); 1443 ASSERT(RuntimeEnabledFeatures::styleMatchedPropertiesCacheEnabled());
1447 INCREMENT_STYLE_STATS_COUNTER(*this, matchedPropertyCacheAdded, 1); 1444 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), matchedPropertyC acheAdded, 1);
1448 m_matchedPropertiesCache.add(*state.style(), *state.parentStyle(), cache Hash, matchResult.matchedProperties()); 1445 m_matchedPropertiesCache.add(*state.style(), *state.parentStyle(), cache Hash, matchResult.matchedProperties());
1449 } 1446 }
1450 1447
1451 ASSERT(!state.fontBuilder().fontDirty()); 1448 ASSERT(!state.fontBuilder().fontDirty());
1452 } 1449 }
1453 1450
1454 bool StyleResolver::hasAuthorBackground(const StyleResolverState& state) 1451 bool StyleResolver::hasAuthorBackground(const StyleResolverState& state)
1455 { 1452 {
1456 const CachedUAStyle* cachedUAStyle = state.cachedUAStyle(); 1453 const CachedUAStyle* cachedUAStyle = state.cachedUAStyle();
1457 if (!cachedUAStyle) 1454 if (!cachedUAStyle)
(...skipping 29 matching lines...) Expand all
1487 collector.collectMatchingRules(matchRequest); 1484 collector.collectMatchingRules(matchRequest);
1488 collector.sortAndTransferMatchedRules(); 1485 collector.sortAndTransferMatchedRules();
1489 1486
1490 RefPtrWillBeRawPtr<StyleRuleList> rules = collector.matchedStyleRuleList(); 1487 RefPtrWillBeRawPtr<StyleRuleList> rules = collector.matchedStyleRuleList();
1491 if (!rules) 1488 if (!rules)
1492 return; 1489 return;
1493 for (size_t i = 0; i < rules->size(); i++) 1490 for (size_t i = 0; i < rules->size(); i++)
1494 state.style()->addCallbackSelector(rules->at(i)->selectorList().selector sText()); 1491 state.style()->addCallbackSelector(rules->at(i)->selectorList().selector sText());
1495 } 1492 }
1496 1493
1497 void StyleResolver::setStatsEnabled(bool enabled)
1498 {
1499 if (enabled) {
1500 if (!m_styleResolverStats) {
1501 m_styleResolverStats = StyleResolverStats::create();
1502 } else {
1503 m_styleResolverStats->reset();
1504 }
1505 } else {
1506 m_styleResolverStats = nullptr;
1507 }
1508 }
1509
1510 void StyleResolver::computeFont(ComputedStyle* style, const StylePropertySet& pr opertySet) 1494 void StyleResolver::computeFont(ComputedStyle* style, const StylePropertySet& pr opertySet)
1511 { 1495 {
1512 CSSPropertyID properties[] = { 1496 CSSPropertyID properties[] = {
1513 CSSPropertyFontSize, 1497 CSSPropertyFontSize,
1514 CSSPropertyFontFamily, 1498 CSSPropertyFontFamily,
1515 CSSPropertyFontStretch, 1499 CSSPropertyFontStretch,
1516 CSSPropertyFontStyle, 1500 CSSPropertyFontStyle,
1517 CSSPropertyFontVariant, 1501 CSSPropertyFontVariant,
1518 CSSPropertyFontWeight, 1502 CSSPropertyFontWeight,
1519 CSSPropertyLineHeight, 1503 CSSPropertyLineHeight,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1574 visitor->trace(m_uncommonAttributeRuleSet); 1558 visitor->trace(m_uncommonAttributeRuleSet);
1575 visitor->trace(m_watchedSelectorsRules); 1559 visitor->trace(m_watchedSelectorsRules);
1576 visitor->trace(m_treeBoundaryCrossingScopes); 1560 visitor->trace(m_treeBoundaryCrossingScopes);
1577 visitor->trace(m_styleSharingLists); 1561 visitor->trace(m_styleSharingLists);
1578 visitor->trace(m_pendingStyleSheets); 1562 visitor->trace(m_pendingStyleSheets);
1579 visitor->trace(m_document); 1563 visitor->trace(m_document);
1580 #endif 1564 #endif
1581 } 1565 }
1582 1566
1583 } // namespace blink 1567 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698