Commit 54d78bab authored by fs@opera.com's avatar fs@opera.com

Random clean up of SVGResourcesCache

 * Fix up some comments.

 * Rename resourcesCacheFromLayoutObject to resourcesCache; let it take
   a Document& instead (to reflect the wider "scope" it has), and make it
   return a SVGResourceCache& since the cache will always be present if
   SVGDocumentExtensions are.

 * Drop redundant qualification.

BUG=521334

Review URL: https://codereview.chromium.org/1288903003

git-svn-id: svn://svn.chromium.org/blink/trunk@200826 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent db70bb19
...@@ -43,7 +43,7 @@ void SVGResourcesCache::addResourcesFromLayoutObject(LayoutObject* object, const ...@@ -43,7 +43,7 @@ void SVGResourcesCache::addResourcesFromLayoutObject(LayoutObject* object, const
const SVGComputedStyle& svgStyle = style.svgStyle(); const SVGComputedStyle& svgStyle = style.svgStyle();
// Build a list of all resources associated with the passed LayoutObject // Build a list of all resources associated with the passed LayoutObject.
OwnPtr<SVGResources> newResources = SVGResources::buildResources(object, svgStyle); OwnPtr<SVGResources> newResources = SVGResources::buildResources(object, svgStyle);
if (!newResources) if (!newResources)
return; return;
...@@ -55,7 +55,7 @@ void SVGResourcesCache::addResourcesFromLayoutObject(LayoutObject* object, const ...@@ -55,7 +55,7 @@ void SVGResourcesCache::addResourcesFromLayoutObject(LayoutObject* object, const
SVGResourcesCycleSolver solver(object, resources); SVGResourcesCycleSolver solver(object, resources);
solver.resolveCycles(); solver.resolveCycles();
// Walk resources and register the layout object at each resources. // Walk resources and register the layout object as a client of each resource.
HashSet<LayoutSVGResourceContainer*> resourceSet; HashSet<LayoutSVGResourceContainer*> resourceSet;
resources->buildSetOfResources(resourceSet); resources->buildSetOfResources(resourceSet);
...@@ -69,7 +69,7 @@ void SVGResourcesCache::removeResourcesFromLayoutObject(LayoutObject* object) ...@@ -69,7 +69,7 @@ void SVGResourcesCache::removeResourcesFromLayoutObject(LayoutObject* object)
if (!resources) if (!resources)
return; return;
// Walk resources and register the layout object at each resources. // Walk resources and unregister the layout object as a client of each resource.
HashSet<LayoutSVGResourceContainer*> resourceSet; HashSet<LayoutSVGResourceContainer*> resourceSet;
resources->buildSetOfResources(resourceSet); resources->buildSetOfResources(resourceSet);
...@@ -77,26 +77,20 @@ void SVGResourcesCache::removeResourcesFromLayoutObject(LayoutObject* object) ...@@ -77,26 +77,20 @@ void SVGResourcesCache::removeResourcesFromLayoutObject(LayoutObject* object)
resourceContainer->removeClient(object); resourceContainer->removeClient(object);
} }
static inline SVGResourcesCache* resourcesCacheFromLayoutObject(const LayoutObject* layoutObject) static inline SVGResourcesCache& resourcesCache(Document& document)
{ {
Document& document = layoutObject->document(); return document.accessSVGExtensions().resourcesCache();
SVGDocumentExtensions& extensions = document.accessSVGExtensions();
SVGResourcesCache* cache = extensions.resourcesCache();
ASSERT(cache);
return cache;
} }
SVGResources* SVGResourcesCache::cachedResourcesForLayoutObject(const LayoutObject* layoutObject) SVGResources* SVGResourcesCache::cachedResourcesForLayoutObject(const LayoutObject* layoutObject)
{ {
ASSERT(layoutObject); ASSERT(layoutObject);
return resourcesCacheFromLayoutObject(layoutObject)->m_cache.get(layoutObject); return resourcesCache(layoutObject->document()).m_cache.get(layoutObject);
} }
void SVGResourcesCache::clientLayoutChanged(LayoutObject* object) void SVGResourcesCache::clientLayoutChanged(LayoutObject* object)
{ {
SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObject(object); SVGResources* resources = cachedResourcesForLayoutObject(object);
if (!resources) if (!resources)
return; return;
...@@ -121,17 +115,20 @@ void SVGResourcesCache::clientStyleChanged(LayoutObject* layoutObject, StyleDiff ...@@ -121,17 +115,20 @@ void SVGResourcesCache::clientStyleChanged(LayoutObject* layoutObject, StyleDiff
if (!diff.hasDifference() || !layoutObject->parent()) if (!diff.hasDifference() || !layoutObject->parent())
return; return;
// In this case the proper SVGFE*Element will decide whether the modified CSS properties require a relayout or paintInvalidation. // In this case the proper SVGFE*Element will decide whether the modified CSS properties require
// a relayout or paintInvalidation.
if (layoutObject->isSVGResourceFilterPrimitive() && !diff.needsLayout()) if (layoutObject->isSVGResourceFilterPrimitive() && !diff.needsLayout())
return; return;
// Dynamic changes of CSS properties like 'clip-path' may require us to recompute the associated resources for a layoutObject. // Dynamic changes of CSS properties like 'clip-path' may require us to recompute the associated
// FIXME: Avoid passing in a useless StyleDifference, but instead compare oldStyle/newStyle to see which resources changed // resources for a LayoutObject.
// to be able to selectively rebuild individual resources, instead of all of them. // TODO(fs): Avoid passing in a useless StyleDifference, but instead compare oldStyle/newStyle
// to see which resources changed to be able to selectively rebuild individual resources,
// instead of all of them.
if (layoutObjectCanHaveResources(layoutObject)) { if (layoutObjectCanHaveResources(layoutObject)) {
SVGResourcesCache* cache = resourcesCacheFromLayoutObject(layoutObject); SVGResourcesCache& cache = resourcesCache(layoutObject->document());
cache->removeResourcesFromLayoutObject(layoutObject); cache.removeResourcesFromLayoutObject(layoutObject);
cache->addResourcesFromLayoutObject(layoutObject, newStyle); cache.addResourcesFromLayoutObject(layoutObject, newStyle);
} }
LayoutSVGResourceContainer::markForLayoutAndParentResourceInvalidation(layoutObject, false); LayoutSVGResourceContainer::markForLayoutAndParentResourceInvalidation(layoutObject, false);
...@@ -145,8 +142,8 @@ void SVGResourcesCache::clientWasAddedToTree(LayoutObject* layoutObject, const C ...@@ -145,8 +142,8 @@ void SVGResourcesCache::clientWasAddedToTree(LayoutObject* layoutObject, const C
if (!layoutObjectCanHaveResources(layoutObject)) if (!layoutObjectCanHaveResources(layoutObject))
return; return;
SVGResourcesCache* cache = resourcesCacheFromLayoutObject(layoutObject); SVGResourcesCache& cache = resourcesCache(layoutObject->document());
cache->addResourcesFromLayoutObject(layoutObject, newStyle); cache.addResourcesFromLayoutObject(layoutObject, newStyle);
} }
void SVGResourcesCache::clientWillBeRemovedFromTree(LayoutObject* layoutObject) void SVGResourcesCache::clientWillBeRemovedFromTree(LayoutObject* layoutObject)
...@@ -157,31 +154,30 @@ void SVGResourcesCache::clientWillBeRemovedFromTree(LayoutObject* layoutObject) ...@@ -157,31 +154,30 @@ void SVGResourcesCache::clientWillBeRemovedFromTree(LayoutObject* layoutObject)
if (!layoutObjectCanHaveResources(layoutObject)) if (!layoutObjectCanHaveResources(layoutObject))
return; return;
SVGResourcesCache* cache = resourcesCacheFromLayoutObject(layoutObject); SVGResourcesCache& cache = resourcesCache(layoutObject->document());
cache->removeResourcesFromLayoutObject(layoutObject); cache.removeResourcesFromLayoutObject(layoutObject);
} }
void SVGResourcesCache::clientDestroyed(LayoutObject* layoutObject) void SVGResourcesCache::clientDestroyed(LayoutObject* layoutObject)
{ {
ASSERT(layoutObject); ASSERT(layoutObject);
SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObject(layoutObject); SVGResources* resources = cachedResourcesForLayoutObject(layoutObject);
if (resources) if (resources)
resources->removeClientFromCache(layoutObject); resources->removeClientFromCache(layoutObject);
SVGResourcesCache& cache = resourcesCache(layoutObject->document());
SVGResourcesCache* cache = resourcesCacheFromLayoutObject(layoutObject); cache.removeResourcesFromLayoutObject(layoutObject);
cache->removeResourcesFromLayoutObject(layoutObject);
} }
void SVGResourcesCache::resourceDestroyed(LayoutSVGResourceContainer* resource) void SVGResourcesCache::resourceDestroyed(LayoutSVGResourceContainer* resource)
{ {
ASSERT(resource); ASSERT(resource);
SVGResourcesCache* cache = resourcesCacheFromLayoutObject(resource); SVGResourcesCache& cache = resourcesCache(resource->document());
// The resource itself may have clients, that need to be notified. // The resource itself may have clients, that need to be notified.
cache->removeResourcesFromLayoutObject(resource); cache.removeResourcesFromLayoutObject(resource);
for (auto& objectResources : cache->m_cache) { for (auto& objectResources : cache.m_cache) {
objectResources.value->resourceDestroyed(resource); objectResources.value->resourceDestroyed(resource);
// Mark users of destroyed resources as pending resolution based on the id of the old resource. // Mark users of destroyed resources as pending resolution based on the id of the old resource.
......
...@@ -60,7 +60,7 @@ public: ...@@ -60,7 +60,7 @@ public:
void reportWarning(const String&); void reportWarning(const String&);
void reportError(const String&); void reportError(const String&);
SVGResourcesCache* resourcesCache() const { return m_resourcesCache.get(); } SVGResourcesCache& resourcesCache() const { return *m_resourcesCache; }
void addSVGRootWithRelativeLengthDescendents(SVGSVGElement*); void addSVGRootWithRelativeLengthDescendents(SVGSVGElement*);
void removeSVGRootWithRelativeLengthDescendents(SVGSVGElement*); void removeSVGRootWithRelativeLengthDescendents(SVGSVGElement*);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment