Changeset 205421 in webkit


Ignore:
Timestamp:
Sep 4, 2016 11:50:21 AM (8 years ago)
Author:
Antti Koivisto
Message:

Remove Style::PendingResources
https://bugs.webkit.org/show_bug.cgi?id=161574

Reviewed by Andreas Kling.

RenderStyle contains all the information needed to initialize resource loads. There is no need for this side structure.

  • css/CSSFilterImageValue.cpp:

(WebCore::CSSFilterImageValue::loadSubimages):

Load external SVG resources along with any image resources.

  • css/CSSToStyleMap.cpp:

(WebCore::CSSToStyleMap::styleImage):
(WebCore::CSSToStyleMap::mapFillImage):
(WebCore::CSSToStyleMap::mapNinePieceImage):

  • css/CSSToStyleMap.h:
  • css/StyleBuilderConverter.h:

(WebCore::StyleBuilderConverter::convertStyleImage):
(WebCore::StyleBuilderConverter::convertShapeValue):

  • css/StyleBuilderCustom.h:

(WebCore::StyleBuilderCustom::applyValueCursor):
(WebCore::StyleBuilderCustom::applyValueContent):

  • css/StyleResolver.cpp:

(WebCore::StyleResolver::State::clear):
(WebCore::StyleResolver::styleImage):
(WebCore::StyleResolver::createFilterOperations):
(WebCore::StyleResolver::loadPendingResources):
(WebCore::StyleResolver::State::ensurePendingResources): Deleted.
(WebCore::StyleResolver::styleCachedImageFromValue): Deleted.
(WebCore::StyleResolver::styleGeneratedImageFromValue): Deleted.

  • css/StyleResolver.h:

(WebCore::StyleResolver::State::takePendingResources): Deleted.

  • platform/graphics/filters/FilterOperation.cpp:

(WebCore::ReferenceFilterOperation::loadExternalDocumentIfNeeded):
(WebCore::ReferenceFilterOperation::getOrCreateCachedSVGDocumentReference): Deleted.

  • platform/graphics/filters/FilterOperation.h:

(WebCore::ReferenceFilterOperation::cachedSVGDocumentReference):

  • rendering/style/StyleCachedImage.cpp:

(WebCore::StyleCachedImage::StyleCachedImage):

  • style/StylePendingResources.cpp:

(WebCore::Style::loadPendingResources):

Trigger resource loads by checking pending resources in RenderStyle unconditionally. Keeping track of them
separately wasn't necessary or a meaningful optimization.

(WebCore::Style::loadPendingImages): Deleted.
(WebCore::Style::loadPendingSVGFilters): Deleted.

  • style/StylePendingResources.h:
Location:
trunk/Source/WebCore
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r205419 r205421  
     12016-09-04  Antti Koivisto  <antti@apple.com>
     2
     3        Remove Style::PendingResources
     4        https://bugs.webkit.org/show_bug.cgi?id=161574
     5
     6        Reviewed by Andreas Kling.
     7
     8        RenderStyle contains all the information needed to initialize resource loads. There is no need for this side structure.
     9
     10        * css/CSSFilterImageValue.cpp:
     11        (WebCore::CSSFilterImageValue::loadSubimages):
     12
     13            Load external SVG resources along with any image resources.
     14
     15        * css/CSSToStyleMap.cpp:
     16        (WebCore::CSSToStyleMap::styleImage):
     17        (WebCore::CSSToStyleMap::mapFillImage):
     18        (WebCore::CSSToStyleMap::mapNinePieceImage):
     19        * css/CSSToStyleMap.h:
     20        * css/StyleBuilderConverter.h:
     21        (WebCore::StyleBuilderConverter::convertStyleImage):
     22        (WebCore::StyleBuilderConverter::convertShapeValue):
     23        * css/StyleBuilderCustom.h:
     24        (WebCore::StyleBuilderCustom::applyValueCursor):
     25        (WebCore::StyleBuilderCustom::applyValueContent):
     26        * css/StyleResolver.cpp:
     27        (WebCore::StyleResolver::State::clear):
     28        (WebCore::StyleResolver::styleImage):
     29        (WebCore::StyleResolver::createFilterOperations):
     30        (WebCore::StyleResolver::loadPendingResources):
     31        (WebCore::StyleResolver::State::ensurePendingResources): Deleted.
     32        (WebCore::StyleResolver::styleCachedImageFromValue): Deleted.
     33        (WebCore::StyleResolver::styleGeneratedImageFromValue): Deleted.
     34        * css/StyleResolver.h:
     35        (WebCore::StyleResolver::State::takePendingResources): Deleted.
     36        * platform/graphics/filters/FilterOperation.cpp:
     37        (WebCore::ReferenceFilterOperation::loadExternalDocumentIfNeeded):
     38        (WebCore::ReferenceFilterOperation::getOrCreateCachedSVGDocumentReference): Deleted.
     39        * platform/graphics/filters/FilterOperation.h:
     40        (WebCore::ReferenceFilterOperation::cachedSVGDocumentReference):
     41        * rendering/style/StyleCachedImage.cpp:
     42        (WebCore::StyleCachedImage::StyleCachedImage):
     43        * style/StylePendingResources.cpp:
     44        (WebCore::Style::loadPendingResources):
     45
     46            Trigger resource loads by checking pending resources in RenderStyle unconditionally. Keeping track of them
     47            separately wasn't necessary or a meaningful optimization.
     48
     49        (WebCore::Style::loadPendingImages): Deleted.
     50        (WebCore::Style::loadPendingSVGFilters): Deleted.
     51        * style/StylePendingResources.h:
     52
    1532016-09-04  Antti Koivisto  <antti@apple.com>
    254
  • trunk/Source/WebCore/css/CSSFilterImageValue.cpp

    r205181 r205421  
    3131#include "CachedImage.h"
    3232#include "CachedResourceLoader.h"
     33#include "CachedSVGDocumentReference.h"
    3334#include "CrossfadeGeneratedImage.h"
    3435#include "FilterEffectRenderer.h"
     
    9596        if (m_cachedImage)
    9697            m_cachedImage->addClient(&m_filterSubimageObserver);
     98    }
     99
     100    for (auto& filterOperation : m_filterOperations.operations()) {
     101        if (!is<ReferenceFilterOperation>(filterOperation.get()))
     102            continue;
     103        auto& referenceFilterOperation = downcast<ReferenceFilterOperation>(*filterOperation);
     104        referenceFilterOperation.loadExternalDocumentIfNeeded(cachedResourceLoader, options);
    97105    }
    98106
  • trunk/Source/WebCore/css/CSSToStyleMap.cpp

    r204566 r205421  
    6767}
    6868
    69 RefPtr<StyleImage> CSSToStyleMap::styleImage(CSSPropertyID propertyId, CSSValue& value)
    70 {
    71     return m_resolver->styleImage(propertyId, value);
     69RefPtr<StyleImage> CSSToStyleMap::styleImage(CSSValue& value)
     70{
     71    return m_resolver->styleImage(value);
    7272}
    7373
     
    156156    }
    157157
    158     layer.setImage(styleImage(propertyID, value));
     158    layer.setImage(styleImage(value));
    159159}
    160160
     
    558558    CSSValueList& borderImage = downcast<CSSValueList>(*value);
    559559
    560     // Set the image (this kicks off the load).
    561     CSSPropertyID imageProperty;
    562     if (property == CSSPropertyWebkitBorderImage)
    563         imageProperty = CSSPropertyBorderImageSource;
    564     else if (property == CSSPropertyWebkitMaskBoxImage)
    565         imageProperty = CSSPropertyWebkitMaskBoxImageSource;
    566     else
    567         imageProperty = property;
    568 
    569560    for (auto& current : borderImage) {
    570561        if (is<CSSImageValue>(current.get()) || is<CSSImageGeneratorValue>(current.get()) || is<CSSImageSetValue>(current.get()))
    571             image.setImage(styleImage(imageProperty, current.get()));
     562            image.setImage(styleImage(current.get()));
    572563        else if (is<CSSBorderImageSliceValue>(current.get()))
    573564            mapNinePieceImageSlice(current, image);
  • trunk/Source/WebCore/css/CSSToStyleMap.h

    r200098 r205421  
    8888    // is held by the StyleResolver, and likely provided to this object
    8989    // during the resolve.
    90     RefPtr<StyleImage> styleImage(CSSPropertyID, CSSValue&);
     90    RefPtr<StyleImage> styleImage(CSSValue&);
    9191
    9292    StyleResolver* m_resolver;
  • trunk/Source/WebCore/css/StyleBuilderConverter.h

    r204566 r205421  
    409409inline PassRefPtr<StyleImage> StyleBuilderConverter::convertStyleImage(StyleResolver& styleResolver, CSSValue& value)
    410410{
    411     return styleResolver.styleImage(property, value);
     411    return styleResolver.styleImage(value);
    412412}
    413413
     
    742742
    743743    if (isImageShape(value))
    744         return ShapeValue::createImageValue(styleResolver.styleImage(CSSPropertyWebkitShapeOutside, value));
     744        return ShapeValue::createImageValue(styleResolver.styleImage(value));
    745745
    746746    RefPtr<BasicShape> shape;
  • trunk/Source/WebCore/css/StyleBuilderCustom.h

    r205419 r205421  
    11481148        if (is<CSSCursorImageValue>(item.get())) {
    11491149            auto& image = downcast<CSSCursorImageValue>(item.get());
    1150             styleResolver.style()->addCursor(styleResolver.styleImage(CSSPropertyCursor, image), image.hotSpot());
     1150            styleResolver.style()->addCursor(styleResolver.styleImage(image), image.hotSpot());
    11511151            continue;
    11521152        }
     
    13151315            didSet = true;
    13161316        } else if (is<CSSImageSetValue>(item.get())) {
    1317             styleResolver.style()->setContent(styleResolver.styleCachedImageFromValue(CSSPropertyContent, item), didSet);
     1317            styleResolver.style()->setContent(StyleCachedImage::create(item), didSet);
    13181318            didSet = true;
    13191319        }
    13201320
    13211321        if (is<CSSImageValue>(item.get())) {
    1322             styleResolver.style()->setContent(styleResolver.styleCachedImageFromValue(CSSPropertyContent, item), didSet);
     1322            styleResolver.style()->setContent(StyleCachedImage::create(item), didSet);
    13231323            didSet = true;
    13241324            continue;
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r205419 r205421  
    190190    m_ownedParentStyle = nullptr;
    191191    m_regionForStyling = nullptr;
    192     m_pendingResources = nullptr;
    193192    m_cssToLengthConversionData = CSSToLengthConversionData();
    194193}
     
    377376    m_ownedParentStyle = WTFMove(parentStyle);
    378377    m_parentStyle = m_ownedParentStyle.get();
    379 }
    380 
    381 Style::PendingResources& StyleResolver::State::ensurePendingResources()
    382 {
    383     if (!m_pendingResources)
    384         m_pendingResources = std::make_unique<Style::PendingResources>();
    385     return *m_pendingResources;
    386378}
    387379
     
    17011693}
    17021694
    1703 RefPtr<StyleImage> StyleResolver::styleImage(CSSPropertyID property, CSSValue& value)
     1695RefPtr<StyleImage> StyleResolver::styleImage(CSSValue& value)
    17041696{
    17051697    if (is<CSSImageGeneratorValue>(value)) {
    17061698        if (is<CSSGradientValue>(value))
    1707             return styleGeneratedImageFromValue(property, *downcast<CSSGradientValue>(value).gradientWithStylesResolved(this));
    1708         return styleGeneratedImageFromValue(property, downcast<CSSImageGeneratorValue>(value));
     1699            return StyleGeneratedImage::create(*downcast<CSSGradientValue>(value).gradientWithStylesResolved(this));
     1700
     1701        if (is<CSSFilterImageValue>(value)) {
     1702            // FilterImage needs to calculate FilterOperations.
     1703            downcast<CSSFilterImageValue>(value).createFilterOperations(this);
     1704        }
     1705        return StyleGeneratedImage::create(downcast<CSSImageGeneratorValue>(value));
    17091706    }
    17101707
    17111708    if (is<CSSImageValue>(value) || is<CSSImageSetValue>(value) || is<CSSCursorImageValue>(value))
    1712         return styleCachedImageFromValue(property, value);
     1709        return StyleCachedImage::create(value);
    17131710
    17141711    return nullptr;
    1715 }
    1716 
    1717 Ref<StyleCachedImage> StyleResolver::styleCachedImageFromValue(CSSPropertyID property, CSSValue& value)
    1718 {
    1719     auto image = StyleCachedImage::create(value);
    1720     if (image->isPending())
    1721         m_state.ensurePendingResources().pendingImages.set(property, &value);
    1722     return image;
    1723 }
    1724 
    1725 Ref<StyleGeneratedImage> StyleResolver::styleGeneratedImageFromValue(CSSPropertyID property, CSSImageGeneratorValue& value)
    1726 {
    1727     if (is<CSSFilterImageValue>(value)) {
    1728         // FilterImage needs to calculate FilterOperations.
    1729         downcast<CSSFilterImageValue>(value).createFilterOperations(this);
    1730     }
    1731     if (value.isPending())
    1732         m_state.ensurePendingResources().pendingImages.set(property, &value);
    1733 
    1734     return StyleGeneratedImage::create(value);
    17351712}
    17361713
     
    19691946
    19701947            RefPtr<ReferenceFilterOperation> operation = ReferenceFilterOperation::create(cssUrl, url.fragmentIdentifier());
    1971             if (SVGURIReference::isExternalURIReference(cssUrl, m_state.document()))
    1972                 state.ensurePendingResources().pendingSVGFilters.append(operation);
    1973 
    19741948            operations.operations().append(operation);
    19751949            continue;
     
    20792053    TemporaryChange<bool> changeInLoadPendingImages(m_inLoadPendingImages, true);
    20802054
    2081     if (auto pendingResources = state().takePendingResources())
    2082         Style::loadPendingResources(*pendingResources, document(), *style(), m_state.element());
     2055    Style::loadPendingResources(*style(), document(), m_state.element());
    20832056}
    20842057
  • trunk/Source/WebCore/css/StyleResolver.h

    r205419 r205421  
    7777class StyleImage;
    7878class StyleKeyframe;
    79 class StylePendingImage;
    8079class StyleProperties;
    8180class StyleRule;
     
    408407        bool useSVGZoomRules() const { return m_element && m_element->isSVGElement(); }
    409408
    410         Style::PendingResources& ensurePendingResources();
    411         std::unique_ptr<Style::PendingResources> takePendingResources() { return WTFMove(m_pendingResources); }
    412 
    413409        const CSSToLengthConversionData& cssToLengthConversionData() const { return m_cssToLengthConversionData; }
    414410
     
    447443        Color m_backgroundColor;
    448444
    449         std::unique_ptr<Style::PendingResources> m_pendingResources;
    450445        CSSToLengthConversionData m_cssToLengthConversionData;
    451446       
     
    460455    const State& state() const { return m_state; }
    461456
    462     RefPtr<StyleImage> styleImage(CSSPropertyID, CSSValue&);
    463     Ref<StyleCachedImage> styleCachedImageFromValue(CSSPropertyID, CSSValue&);
    464     Ref<StyleGeneratedImage> styleGeneratedImageFromValue(CSSPropertyID, CSSImageGeneratorValue&);
     457    RefPtr<StyleImage> styleImage(CSSValue&);
    465458
    466459    bool applyPropertyToRegularStyle() const { return m_state.applyPropertyToRegularStyle(); }
  • trunk/Source/WebCore/platform/graphics/filters/FilterOperation.cpp

    r200343 r205421  
    2828
    2929#include "AnimationUtilities.h"
     30#include "CachedResourceLoader.h"
    3031#include "CachedSVGDocumentReference.h"
    3132#include "FilterEffect.h"
     33#include "SVGURIReference.h"
    3234#include "TextStream.h"
    3335
     
    6062    return m_url == downcast<ReferenceFilterOperation>(operation).m_url;
    6163}
    62    
    63 CachedSVGDocumentReference* ReferenceFilterOperation::getOrCreateCachedSVGDocumentReference()
    64 {
    65     if (!m_cachedSVGDocumentReference)
    66         m_cachedSVGDocumentReference = std::make_unique<CachedSVGDocumentReference>(m_url);
    67     return m_cachedSVGDocumentReference.get();
     64
     65void ReferenceFilterOperation::loadExternalDocumentIfNeeded(CachedResourceLoader& cachedResourceLoader, const ResourceLoaderOptions& options)
     66{
     67    if (m_cachedSVGDocumentReference)
     68        return;
     69    if (!SVGURIReference::isExternalURIReference(m_url, *cachedResourceLoader.document()))
     70        return;
     71    m_cachedSVGDocumentReference = std::make_unique<CachedSVGDocumentReference>(m_url);
     72    m_cachedSVGDocumentReference->load(cachedResourceLoader, options);
    6873}
    6974
  • trunk/Source/WebCore/platform/graphics/filters/FilterOperation.h

    r197563 r205421  
    4343// CSS Filters
    4444
     45class CachedResourceLoader;
    4546class CachedSVGDocumentReference;
    4647class FilterEffect;
     48struct ResourceLoaderOptions;
    4749
    4850class FilterOperation : public RefCounted<FilterOperation> {
     
    185187    const String& fragment() const { return m_fragment; }
    186188
     189    void loadExternalDocumentIfNeeded(CachedResourceLoader&, const ResourceLoaderOptions&);
     190
    187191    CachedSVGDocumentReference* cachedSVGDocumentReference() const { return m_cachedSVGDocumentReference.get(); }
    188     CachedSVGDocumentReference* getOrCreateCachedSVGDocumentReference();
    189192
    190193    FilterEffect* filterEffect() const { return m_filterEffect.get(); }
  • trunk/Source/WebCore/rendering/style/StyleCachedImage.cpp

    r205419 r205421  
    3939
    4040    m_isCachedImage = true;
     41
     42    // CSSImageValue doesn't get invalidated so we can grab the CachedImage immediately if it exists.
     43    if (is<CSSImageValue>(m_cssValue))
     44        m_cachedImage = downcast<CSSImageValue>(m_cssValue.get()).cachedImage();
    4145}
    4246
  • trunk/Source/WebCore/style/StylePendingResources.cpp

    r205419 r205421  
    2929#include "CSSCursorImageValue.h"
    3030#include "CachedResourceLoader.h"
    31 #include "CachedSVGDocumentReference.h"
    3231#include "ContentData.h"
    3332#include "CursorData.h"
     
    6160}
    6261
    63 static void loadPendingImages(const PendingResources& pendingResources, Document& document, RenderStyle& style, const Element* element)
     62void loadPendingResources(RenderStyle& style, Document& document, const Element* element)
    6463{
    65     for (auto currentProperty : pendingResources.pendingImages.keys()) {
    66         switch (currentProperty) {
    67         case CSSPropertyBackgroundImage: {
    68             for (auto* backgroundLayer = &style.ensureBackgroundLayers(); backgroundLayer; backgroundLayer = backgroundLayer->next())
    69                 loadPendingImage(document, backgroundLayer->image(), element);
    70             break;
    71         }
    72         case CSSPropertyContent: {
    73             for (auto* contentData = const_cast<ContentData*>(style.contentData()); contentData; contentData = contentData->next()) {
    74                 if (is<ImageContentData>(*contentData)) {
    75                     auto& styleImage = downcast<ImageContentData>(*contentData).image();
    76                     loadPendingImage(document, &styleImage, element);
    77                 }
    78             }
    79             break;
    80         }
    81         case CSSPropertyCursor: {
    82             if (auto* cursorList = style.cursors()) {
    83                 for (size_t i = 0; i < cursorList->size(); ++i)
    84                     loadPendingImage(document, cursorList->at(i).image(), element);
    85             }
    86             break;
    87         }
    88         case CSSPropertyListStyleImage: {
    89             loadPendingImage(document, style.listStyleImage(), element);
    90             break;
    91         }
    92         case CSSPropertyBorderImageSource: {
    93             loadPendingImage(document, style.borderImageSource(), element);
    94             break;
    95         }
    96         case CSSPropertyWebkitBoxReflect: {
    97             if (auto* reflection = style.boxReflect())
    98                 loadPendingImage(document, reflection->mask().image(), element);
    99             break;
    100         }
    101         case CSSPropertyWebkitMaskBoxImageSource: {
    102             loadPendingImage(document, style.maskBoxImageSource(), element);
    103             break;
    104         }
    105         case CSSPropertyWebkitMaskImage: {
    106             for (auto* maskLayer = &style.ensureMaskLayers(); maskLayer; maskLayer = maskLayer->next())
    107                 loadPendingImage(document, maskLayer->image(), element);
    108             break;
    109         }
    110 #if ENABLE(CSS_SHAPES)
    111         case CSSPropertyWebkitShapeOutside: {
    112             if (style.shapeOutside())
    113                 loadPendingImage(document, style.shapeOutside()->image(), element, LoadPolicy::ShapeOutside);
    114             break;
    115         }
    116 #endif
    117         default:
    118             ASSERT_NOT_REACHED();
     64    for (auto* backgroundLayer = style.backgroundLayers(); backgroundLayer; backgroundLayer = backgroundLayer->next())
     65        loadPendingImage(document, backgroundLayer->image(), element);
     66
     67    for (auto* contentData = style.contentData(); contentData; contentData = contentData->next()) {
     68        if (is<ImageContentData>(*contentData)) {
     69            auto& styleImage = downcast<ImageContentData>(*contentData).image();
     70            loadPendingImage(document, &styleImage, element);
    11971        }
    12072    }
    121 }
    12273
    123 static void loadPendingSVGFilters(const PendingResources& pendingResources, Document& document, const Element* element)
    124 {
    125     if (pendingResources.pendingSVGFilters.isEmpty())
    126         return;
     74    if (auto* cursorList = style.cursors()) {
     75        for (size_t i = 0; i < cursorList->size(); ++i)
     76            loadPendingImage(document, cursorList->at(i).image(), element);
     77    }
    12778
    128     ResourceLoaderOptions options = CachedResourceLoader::defaultCachedResourceOptions();
    129     options.contentSecurityPolicyImposition = element && element->isInUserAgentShadowTree() ? ContentSecurityPolicyImposition::SkipPolicyCheck : ContentSecurityPolicyImposition::DoPolicyCheck;
     79    loadPendingImage(document, style.listStyleImage(), element);
     80    loadPendingImage(document, style.borderImageSource(), element);
     81    loadPendingImage(document, style.maskBoxImageSource(), element);
    13082
    131     for (auto& filterOperation : pendingResources.pendingSVGFilters)
    132         filterOperation->getOrCreateCachedSVGDocumentReference()->load(document.cachedResourceLoader(), options);
    133 }
     83    if (auto* reflection = style.boxReflect())
     84        loadPendingImage(document, reflection->mask().image(), element);
    13485
    135 void loadPendingResources(const PendingResources& pendingResources, Document& document, RenderStyle& style, const Element* element)
    136 {
    137     loadPendingImages(pendingResources, document, style, element);
    138     loadPendingSVGFilters(pendingResources, document, element);
     86    for (auto* maskLayer = style.maskLayers(); maskLayer; maskLayer = maskLayer->next())
     87        loadPendingImage(document, maskLayer->image(), element);
     88
     89#if ENABLE(CSS_SHAPES)
     90    if (style.shapeOutside())
     91        loadPendingImage(document, style.shapeOutside()->image(), element, LoadPolicy::ShapeOutside);
     92#endif
    13993}
    14094
  • trunk/Source/WebCore/style/StylePendingResources.h

    r202656 r205421  
    2626#pragma once
    2727
    28 #include "CSSPropertyNames.h"
    29 #include "FilterOperations.h"
    30 #include <wtf/HashMap.h>
    31 
    3228namespace WebCore {
    3329
    34 class CSSValue;
    3530class Document;
    3631class Element;
     
    3934namespace Style {
    4035
    41 struct PendingResources {
    42     WTF_MAKE_FAST_ALLOCATED;
    43 public:
    44     HashMap<CSSPropertyID, RefPtr<CSSValue>> pendingImages;
    45     Vector<RefPtr<ReferenceFilterOperation>> pendingSVGFilters;
    46 };
    47 
    48 void loadPendingResources(const PendingResources&, Document&, RenderStyle&, const Element*);
     36void loadPendingResources(RenderStyle&, Document&, const Element*);
    4937
    5038}
Note: See TracChangeset for help on using the changeset viewer.