summaryrefslogtreecommitdiff
path: root/Source/WebCore/rendering/svg/RenderSVGResource.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/rendering/svg/RenderSVGResource.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/rendering/svg/RenderSVGResource.cpp')
-rw-r--r--Source/WebCore/rendering/svg/RenderSVGResource.cpp74
1 files changed, 39 insertions, 35 deletions
diff --git a/Source/WebCore/rendering/svg/RenderSVGResource.cpp b/Source/WebCore/rendering/svg/RenderSVGResource.cpp
index d9e1d835e..e6c5c2401 100644
--- a/Source/WebCore/rendering/svg/RenderSVGResource.cpp
+++ b/Source/WebCore/rendering/svg/RenderSVGResource.cpp
@@ -21,8 +21,6 @@
*/
#include "config.h"
-
-#if ENABLE(SVG)
#include "RenderSVGResource.h"
#include "Frame.h"
@@ -72,18 +70,16 @@ static inline RenderSVGResource* requestPaintingResource(RenderSVGResourceMode m
}
bool applyToFill = mode == ApplyToFillMode;
- SVGPaint::SVGPaintType paintType = applyToFill ? svgStyle.fillPaintType() : svgStyle.strokePaintType();
- if (paintType == SVGPaint::SVG_PAINTTYPE_NONE)
+ SVGPaintType paintType = applyToFill ? svgStyle.fillPaintType() : svgStyle.strokePaintType();
+ if (paintType == SVG_PAINTTYPE_NONE)
return nullptr;
Color color;
switch (paintType) {
- case SVGPaint::SVG_PAINTTYPE_CURRENTCOLOR:
- case SVGPaint::SVG_PAINTTYPE_RGBCOLOR:
- case SVGPaint::SVG_PAINTTYPE_RGBCOLOR_ICCCOLOR:
- case SVGPaint::SVG_PAINTTYPE_URI_CURRENTCOLOR:
- case SVGPaint::SVG_PAINTTYPE_URI_RGBCOLOR:
- case SVGPaint::SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
+ case SVG_PAINTTYPE_CURRENTCOLOR:
+ case SVG_PAINTTYPE_RGBCOLOR:
+ case SVG_PAINTTYPE_URI_CURRENTCOLOR:
+ case SVG_PAINTTYPE_URI_RGBCOLOR:
color = applyToFill ? svgStyle.fillPaintColor() : svgStyle.strokePaintColor();
break;
default:
@@ -92,19 +88,19 @@ static inline RenderSVGResource* requestPaintingResource(RenderSVGResourceMode m
if (style.insideLink() == InsideVisitedLink) {
// FIXME: This code doesn't support the uri component of the visited link paint, https://bugs.webkit.org/show_bug.cgi?id=70006
- SVGPaint::SVGPaintType visitedPaintType = applyToFill ? svgStyle.visitedLinkFillPaintType() : svgStyle.visitedLinkStrokePaintType();
+ SVGPaintType visitedPaintType = applyToFill ? svgStyle.visitedLinkFillPaintType() : svgStyle.visitedLinkStrokePaintType();
// For SVG_PAINTTYPE_CURRENTCOLOR, 'color' already contains the 'visitedColor'.
- if (visitedPaintType < SVGPaint::SVG_PAINTTYPE_URI_NONE && visitedPaintType != SVGPaint::SVG_PAINTTYPE_CURRENTCOLOR) {
+ if (visitedPaintType < SVG_PAINTTYPE_URI_NONE && visitedPaintType != SVG_PAINTTYPE_CURRENTCOLOR) {
const Color& visitedColor = applyToFill ? svgStyle.visitedLinkFillPaintColor() : svgStyle.visitedLinkStrokePaintColor();
if (visitedColor.isValid())
- color = Color(visitedColor.red(), visitedColor.green(), visitedColor.blue(), color.alpha());
+ color = visitedColor.colorWithAlpha(color.alphaAsFloat());
}
}
// If the primary resource is just a color, return immediately.
RenderSVGResourceSolidColor* colorResource = RenderSVGResource::sharedSolidPaintingResource();
- if (paintType < SVGPaint::SVG_PAINTTYPE_URI_NONE) {
+ if (paintType < SVG_PAINTTYPE_URI_NONE) {
if (!inheritColorFromParentStyleIfNeeded(renderer, applyToFill, color))
return nullptr;
@@ -113,9 +109,9 @@ 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))
+ if (paintType == SVG_PAINTTYPE_URI_NONE || !inheritColorFromParentStyleIfNeeded(renderer, applyToFill, color))
return nullptr;
colorResource->setColor(color);
@@ -156,28 +152,38 @@ RenderSVGResourceSolidColor* RenderSVGResource::sharedSolidPaintingResource()
return s_sharedSolidPaintingResource;
}
-static inline void removeFromCacheAndInvalidateDependencies(RenderObject& object, bool needsLayout)
+static inline void removeFromCacheAndInvalidateDependencies(RenderElement& renderer, bool needsLayout)
{
- if (SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(object)) {
-#if ENABLE(FILTERS)
+ if (auto* resources = SVGResourcesCache::cachedResourcesForRenderer(renderer)) {
if (RenderSVGResourceFilter* filter = resources->filter())
- filter->removeClientFromCache(object);
-#endif
+ filter->removeClientFromCache(renderer);
+
if (RenderSVGResourceMasker* masker = resources->masker())
- masker->removeClientFromCache(object);
+ masker->removeClientFromCache(renderer);
if (RenderSVGResourceClipper* clipper = resources->clipper())
- clipper->removeClientFromCache(object);
+ clipper->removeClientFromCache(renderer);
}
- if (!object.node() || !object.node()->isSVGElement())
+ if (!renderer.element() || !renderer.element()->isSVGElement())
return;
- HashSet<SVGElement*>* dependencies = object.document().accessSVGExtensions()->setOfElementsReferencingTarget(toSVGElement(object.node()));
+ HashSet<SVGElement*>* dependencies = renderer.document().accessSVGExtensions().setOfElementsReferencingTarget(downcast<SVGElement>(renderer.element()));
if (!dependencies)
return;
- for (auto element : *dependencies) {
- if (auto renderer = element->renderer())
+
+ // We allow cycles in SVGDocumentExtensions reference sets in order to avoid expensive
+ // reference graph adjustments on changes, so we need to break possible cycles here.
+ static NeverDestroyed<HashSet<SVGElement*>> invalidatingDependencies;
+
+ for (auto* element : *dependencies) {
+ if (auto* renderer = element->renderer()) {
+ if (UNLIKELY(!invalidatingDependencies.get().add(element).isNewEntry)) {
+ // Reference cycle: we are in process of invalidating this dependant.
+ continue;
+ }
RenderSVGResource::markForLayoutAndParentResourceInvalidation(*renderer, needsLayout);
+ invalidatingDependencies.get().remove(element);
+ }
}
}
@@ -185,19 +191,20 @@ void RenderSVGResource::markForLayoutAndParentResourceInvalidation(RenderObject&
{
ASSERT(object.node());
- if (needsLayout && !object.documentBeingDestroyed())
+ if (needsLayout && !object.renderTreeBeingDestroyed())
object.setNeedsLayout();
- removeFromCacheAndInvalidateDependencies(object, needsLayout);
+ if (is<RenderElement>(object))
+ removeFromCacheAndInvalidateDependencies(downcast<RenderElement>(object), needsLayout);
// Invalidate resources in ancestor chain, if needed.
- RenderObject* current = object.parent();
+ auto current = object.parent();
while (current) {
removeFromCacheAndInvalidateDependencies(*current, needsLayout);
- if (current->isSVGResourceContainer()) {
+ if (is<RenderSVGResourceContainer>(*current)) {
// This will process the rest of the ancestors.
- current->toRenderSVGResourceContainer()->removeAllClientsFromCache();
+ downcast<RenderSVGResourceContainer>(*current).removeAllClientsFromCache();
break;
}
@@ -206,6 +213,3 @@ void RenderSVGResource::markForLayoutAndParentResourceInvalidation(RenderObject&
}
}
-
-#endif
-