CTTE: SVGResourcesCache should only allow RenderElements.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 5 Sep 2014 19:25:57 +0000 (19:25 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 5 Sep 2014 19:25:57 +0000 (19:25 +0000)
<https://webkit.org/b/136578>

Only RenderElement subclasses can use SVG resources.
Codify this by making SVGResourcesCache::m_cache keyed on RenderElement.

Reviewed by Antti Koivisto.

* rendering/svg/RenderSVGContainer.cpp:
(WebCore::RenderSVGContainer::selfWillPaint):
* rendering/svg/RenderSVGImage.cpp:
(WebCore::RenderSVGImage::imageChanged):
* rendering/svg/RenderSVGResource.cpp:
(WebCore::requestPaintingResource):
(WebCore::removeFromCacheAndInvalidateDependencies):
* rendering/svg/RenderSVGResourceClipper.cpp:
(WebCore::RenderSVGResourceClipper::applyClippingToContext):
* rendering/svg/RenderSVGRoot.cpp:
(WebCore::RenderSVGRoot::paintReplaced):
* rendering/svg/RenderSVGShape.cpp:
(WebCore::RenderSVGShape::shouldGenerateMarkerPositions):
(WebCore::RenderSVGShape::markerRect):
(WebCore::RenderSVGShape::drawMarkers):
* rendering/svg/SVGRenderSupport.cpp:
(WebCore::invalidateResourcesOfChildren):
(WebCore::SVGRenderSupport::intersectRepaintRectWithResources):
(WebCore::SVGRenderSupport::filtersForceContainerLayout):
(WebCore::SVGRenderSupport::pointInClippingArea):
* rendering/svg/SVGRenderingContext.cpp:
(WebCore::SVGRenderingContext::prepareToRenderSVGContent):
* rendering/svg/SVGResourcesCache.cpp:
(WebCore::resourcesCacheFromRenderer):
(WebCore::SVGResourcesCache::cachedResourcesForRenderer):
(WebCore::SVGResourcesCache::clientLayoutChanged):
(WebCore::SVGResourcesCache::clientDestroyed):
(WebCore::SVGResourcesCache::resourceDestroyed):
(WebCore::SVGResourcesCache::cachedResourcesForRenderObject): Deleted.
* rendering/svg/SVGResourcesCache.h:
* rendering/svg/SVGResourcesCycleSolver.cpp:
(WebCore::SVGResourcesCycleSolver::resourceContainsCycles):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@173325 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
Source/WebCore/ChangeLog
Source/WebCore/rendering/svg/RenderSVGContainer.cpp
Source/WebCore/rendering/svg/RenderSVGImage.cpp
Source/WebCore/rendering/svg/RenderSVGResource.cpp
Source/WebCore/rendering/svg/RenderSVGResourceClipper.cpp
Source/WebCore/rendering/svg/RenderSVGRoot.cpp
Source/WebCore/rendering/svg/RenderSVGShape.cpp
Source/WebCore/rendering/svg/SVGRenderSupport.cpp
Source/WebCore/rendering/svg/SVGRenderingContext.cpp
Source/WebCore/rendering/svg/SVGResourcesCache.cpp
Source/WebCore/rendering/svg/SVGResourcesCache.h
Source/WebCore/rendering/svg/SVGResourcesCycleSolver.cpp

index 286b41a..4a20b52 100644 (file)
@@ -1,3 +1,46 @@
+2014-09-05  Andreas Kling  <akling@apple.com>
+
+        CTTE: SVGResourcesCache should only allow RenderElements.
+        <https://webkit.org/b/136578>
+
+        Only RenderElement subclasses can use SVG resources.
+        Codify this by making SVGResourcesCache::m_cache keyed on RenderElement.
+
+        Reviewed by Antti Koivisto.
+
+        * rendering/svg/RenderSVGContainer.cpp:
+        (WebCore::RenderSVGContainer::selfWillPaint):
+        * rendering/svg/RenderSVGImage.cpp:
+        (WebCore::RenderSVGImage::imageChanged):
+        * rendering/svg/RenderSVGResource.cpp:
+        (WebCore::requestPaintingResource):
+        (WebCore::removeFromCacheAndInvalidateDependencies):
+        * rendering/svg/RenderSVGResourceClipper.cpp:
+        (WebCore::RenderSVGResourceClipper::applyClippingToContext):
+        * rendering/svg/RenderSVGRoot.cpp:
+        (WebCore::RenderSVGRoot::paintReplaced):
+        * rendering/svg/RenderSVGShape.cpp:
+        (WebCore::RenderSVGShape::shouldGenerateMarkerPositions):
+        (WebCore::RenderSVGShape::markerRect):
+        (WebCore::RenderSVGShape::drawMarkers):
+        * rendering/svg/SVGRenderSupport.cpp:
+        (WebCore::invalidateResourcesOfChildren):
+        (WebCore::SVGRenderSupport::intersectRepaintRectWithResources):
+        (WebCore::SVGRenderSupport::filtersForceContainerLayout):
+        (WebCore::SVGRenderSupport::pointInClippingArea):
+        * rendering/svg/SVGRenderingContext.cpp:
+        (WebCore::SVGRenderingContext::prepareToRenderSVGContent):
+        * rendering/svg/SVGResourcesCache.cpp:
+        (WebCore::resourcesCacheFromRenderer):
+        (WebCore::SVGResourcesCache::cachedResourcesForRenderer):
+        (WebCore::SVGResourcesCache::clientLayoutChanged):
+        (WebCore::SVGResourcesCache::clientDestroyed):
+        (WebCore::SVGResourcesCache::resourceDestroyed):
+        (WebCore::SVGResourcesCache::cachedResourcesForRenderObject): Deleted.
+        * rendering/svg/SVGResourcesCache.h:
+        * rendering/svg/SVGResourcesCycleSolver.cpp:
+        (WebCore::SVGResourcesCycleSolver::resourceContainsCycles):
+
 2014-09-05  Simon Fraser  <simon.fraser@apple.com>
 
         IDB version changed events should have a valid eventType()
index 4caa1ba..172a0f4 100644 (file)
@@ -102,7 +102,7 @@ RenderObject* RenderSVGContainer::removeChild(RenderObject& child)
 
 bool RenderSVGContainer::selfWillPaint()
 {
-    SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(*this);
+    auto* resources = SVGResourcesCache::cachedResourcesForRenderer(*this);
     return resources && resources->filter();
 }
 
index eb2d33e..1c16d0b 100644 (file)
@@ -204,7 +204,7 @@ void RenderSVGImage::imageChanged(WrappedImagePtr, const IntRect*)
 {
     // The image resource defaults to nullImage until the resource arrives.
     // This empty image may be cached by SVG resources which must be invalidated.
-    if (SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(*this))
+    if (auto* resources = SVGResourcesCache::cachedResourcesForRenderer(*this))
         resources->removeClientFromCache(*this);
 
     // Eventually notify parent resources, that we've changed.
index 9f599f0..bb73507 100644 (file)
@@ -111,7 +111,7 @@ static inline RenderSVGResource* requestPaintingResource(RenderSVGResourceMode m
     }
 
     // If no resources are associated with the given renderer, return the color resource.
-    SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(renderer);
+    auto* resources = SVGResourcesCache::cachedResourcesForRenderer(renderer);
     if (!resources) {
         if (paintType == SVGPaint::SVG_PAINTTYPE_URI_NONE || !inheritColorFromParentStyleIfNeeded(renderer, applyToFill, color))
             return nullptr;
@@ -156,7 +156,7 @@ RenderSVGResourceSolidColor* RenderSVGResource::sharedSolidPaintingResource()
 
 static inline void removeFromCacheAndInvalidateDependencies(RenderElement& renderer, bool needsLayout)
 {
-    if (SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(renderer)) {
+    if (auto* resources = SVGResourcesCache::cachedResourcesForRenderer(renderer)) {
 #if ENABLE(FILTERS)
         if (RenderSVGResourceFilter* filter = resources->filter())
             filter->removeClientFromCache(renderer);
index fb203ee..01d558d 100644 (file)
@@ -158,7 +158,7 @@ bool RenderSVGResourceClipper::applyClippingToContext(RenderElement& renderer, c
         maskContext->concatCTM(animatedLocalTransform);
 
         // clipPath can also be clipped by another clipPath.
-        SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(*this);
+        auto* resources = SVGResourcesCache::cachedResourcesForRenderer(*this);
         RenderSVGResourceClipper* clipper;
         bool succeeded;
         if (resources && (clipper = resources->clipper())) {
index fb229a4..616c4fa 100644 (file)
@@ -247,7 +247,7 @@ void RenderSVGRoot::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paint
 
     // Don't paint if we don't have kids, except if we have filters we should paint those.
     if (!firstChild()) {
-        SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(*this);
+        auto* resources = SVGResourcesCache::cachedResourcesForRenderer(*this);
         if (!resources || !resources->filter()) {
             if (page && paintInfo.phase == PaintPhaseForeground)
                 page->addRelevantUnpaintedObject(this, visualOverflowRect());
index 0e86b35..9a61fe3 100644 (file)
@@ -218,7 +218,7 @@ bool RenderSVGShape::shouldGenerateMarkerPositions() const
     if (!graphicsElement().supportsMarkers())
         return false;
 
-    SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(*this);
+    auto* resources = SVGResourcesCache::cachedResourcesForRenderer(*this);
     if (!resources)
         return false;
 
@@ -372,7 +372,7 @@ FloatRect RenderSVGShape::markerRect(float strokeWidth) const
 {
     ASSERT(!m_markerPositions.isEmpty());
 
-    SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(*this);
+    auto* resources = SVGResourcesCache::cachedResourcesForRenderer(*this);
     ASSERT(resources);
 
     RenderSVGResourceMarker* markerStart = resources->markerStart();
@@ -448,7 +448,7 @@ void RenderSVGShape::drawMarkers(PaintInfo& paintInfo)
 {
     ASSERT(!m_markerPositions.isEmpty());
 
-    SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(*this);
+    auto* resources = SVGResourcesCache::cachedResourcesForRenderer(*this);
     if (!resources)
         return;
 
index 0dc1077..e13483f 100644 (file)
@@ -190,7 +190,7 @@ const RenderSVGRoot& SVGRenderSupport::findTreeRootObject(const RenderElement& s
 static inline void invalidateResourcesOfChildren(RenderElement& renderer)
 {
     ASSERT(!renderer.needsLayout());
-    if (SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(renderer))
+    if (auto* resources = SVGResourcesCache::cachedResourcesForRenderer(renderer))
         resources->removeClientFromCache(renderer, false);
 
     for (auto& child : childrenOfType<RenderElement>(renderer))
@@ -359,7 +359,7 @@ void SVGRenderSupport::intersectRepaintRectWithShadows(const RenderElement& rend
 
 void SVGRenderSupport::intersectRepaintRectWithResources(const RenderElement& renderer, FloatRect& repaintRect)
 {
-    SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(renderer);
+    auto* resources = SVGResourcesCache::cachedResourcesForRenderer(renderer);
     if (!resources)
         return;
 
@@ -382,7 +382,7 @@ bool SVGRenderSupport::filtersForceContainerLayout(const RenderElement& renderer
     if (!renderer.normalChildNeedsLayout())
         return false;
 
-    SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(renderer);
+    auto* resources = SVGResourcesCache::cachedResourcesForRenderer(renderer);
     if (!resources || !resources->filter())
         return false;
 
@@ -393,7 +393,7 @@ bool SVGRenderSupport::pointInClippingArea(const RenderElement& renderer, const
 {
     // We just take clippers into account to determine if a point is on the node. The Specification may
     // change later and we also need to check maskers.
-    SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(renderer);
+    auto* resources = SVGResourcesCache::cachedResourcesForRenderer(renderer);
     if (!resources)
         return true;
 
index de8f15f..68ca06d 100644 (file)
@@ -156,7 +156,7 @@ void SVGRenderingContext::prepareToRenderSVGContent(RenderElement& renderer, Pai
         m_paintInfo->context->clipPath(clipPath.pathForReferenceRect(referenceBox), clipPath.windRule());
     }
 
-    SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(*m_renderer);
+    auto* resources = SVGResourcesCache::cachedResourcesForRenderer(*m_renderer);
     if (!resources) {
 #if ENABLE(FILTERS)
         if (svgStyle.hasFilter())
index 2f27f21..f926601 100644 (file)
@@ -75,21 +75,21 @@ void SVGResourcesCache::removeResourcesFromRenderer(RenderElement& renderer)
         resourceContainer->removeClient(renderer);
 }
 
-static inline SVGResourcesCache& resourcesCacheFromRenderer(const RenderObject& renderer)
+static inline SVGResourcesCache& resourcesCacheFromRenderer(const RenderElement& renderer)
 {
     SVGDocumentExtensions* extensions = renderer.document().accessSVGExtensions();
     ASSERT(extensions);
     return extensions->resourcesCache();
 }
 
-SVGResources* SVGResourcesCache::cachedResourcesForRenderObject(const RenderObject& renderer)
+SVGResources* SVGResourcesCache::cachedResourcesForRenderer(const RenderElement& renderer)
 {
     return resourcesCacheFromRenderer(renderer).m_cache.get(&renderer);
 }
 
 void SVGResourcesCache::clientLayoutChanged(RenderElement& renderer)
 {
-    SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(renderer);
+    auto* resources = SVGResourcesCache::cachedResourcesForRenderer(renderer);
     if (!resources)
         return;
 
@@ -156,8 +156,7 @@ void SVGResourcesCache::clientWillBeRemovedFromTree(RenderObject& renderer)
 
 void SVGResourcesCache::clientDestroyed(RenderElement& renderer)
 {
-    SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(renderer);
-    if (resources)
+    if (auto* resources = SVGResourcesCache::cachedResourcesForRenderer(renderer))
         resources->removeClientFromCache(renderer);
 
     resourcesCacheFromRenderer(renderer).removeResourcesFromRenderer(renderer);
@@ -175,7 +174,7 @@ void SVGResourcesCache::resourceDestroyed(RenderSVGResourceContainer& resource)
 
         // Mark users of destroyed resources as pending resolution based on the id of the old resource.
         Element& resourceElement = resource.element();
-        Element* clientElement = toElement(it.key->node());
+        Element* clientElement = it.key->element();
         SVGDocumentExtensions* extensions = clientElement->document().accessSVGExtensions();
 
         extensions->addPendingResource(resourceElement.getIdAttribute(), clientElement);
index 77d61dd..b6d297e 100644 (file)
@@ -39,7 +39,7 @@ public:
     SVGResourcesCache();
     ~SVGResourcesCache();
 
-    static SVGResources* cachedResourcesForRenderObject(const RenderObject&);
+    static SVGResources* cachedResourcesForRenderer(const RenderElement&);
 
     // Called from all SVG renderers addChild() methods.
     static void clientWasAddedToTree(RenderObject&);
@@ -63,7 +63,7 @@ private:
     void addResourcesFromRenderer(RenderElement&, const RenderStyle&);
     void removeResourcesFromRenderer(RenderElement&);
 
-    typedef HashMap<const RenderObject*, std::unique_ptr<SVGResources>> CacheMap;
+    typedef HashMap<const RenderElement*, std::unique_ptr<SVGResources>> CacheMap;
     CacheMap m_cache;
 };
 
index e35620e..7216660 100644 (file)
@@ -50,7 +50,7 @@ bool SVGResourcesCycleSolver::resourceContainsCycles(RenderElement& renderer) co
     // First operate on the resources of the given renderer.
     // <marker id="a"> <path marker-start="url(#b)"/> ...
     // <marker id="b" marker-start="url(#a)"/>
-    if (SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(renderer)) {
+    if (auto* resources = SVGResourcesCache::cachedResourcesForRenderer(renderer)) {
         HashSet<RenderSVGResourceContainer*> resourceSet;
         resources->buildSetOfResources(resourceSet);
 
@@ -65,7 +65,7 @@ bool SVGResourcesCycleSolver::resourceContainsCycles(RenderElement& renderer) co
     // <marker id="a"> <path marker-start="url(#b)"/> ...
     // <marker id="b"> <path marker-start="url(#a)"/> ...
     for (auto& child : childrenOfType<RenderElement>(renderer)) {
-        SVGResources* childResources = SVGResourcesCache::cachedResourcesForRenderObject(child);
+        auto* childResources = SVGResourcesCache::cachedResourcesForRenderer(child);
         if (!childResources)
             continue;