Commit 504f2c47 authored by Fredrik Söderqvist's avatar Fredrik Söderqvist Committed by Commit Bot

Fold SVGResourcesCache::ResourceReferenceChanged

Fold SVGResourcesCache::ResourceReferenceChanged into its two users,
greatly tailoring the resulting code for one user (SVGPatternElement).
Expose a function for updating the SVGResources object.

Bug: 1028063
Change-Id: I439ca043c659bad7dbb3fa89d9a4d3d9578f7c17
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2489650Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#820179}
parent 9e47bed5
...@@ -725,14 +725,19 @@ void SVGElementResourceClient::ResourceContentChanged( ...@@ -725,14 +725,19 @@ void SVGElementResourceClient::ResourceContentChanged(
} }
void SVGElementResourceClient::ResourceElementChanged() { void SVGElementResourceClient::ResourceElementChanged() {
if (LayoutObject* layout_object = element_->GetLayoutObject()) { LayoutObject* layout_object = element_->GetLayoutObject();
ClearFilterData(); if (!layout_object)
SVGResourcesCache::ResourceReferenceChanged(*layout_object); return;
// TODO(fs): If the resource element (for a filter) doesn't actually change ClearFilterData();
// we don't need to perform the associated invalidations. if (layout_object->Parent()) {
layout_object->SetNeedsPaintPropertyUpdate(); SVGResourcesCache::UpdateResources(*layout_object);
MarkFilterDataDirty(); LayoutSVGResourceContainer::MarkForLayoutAndParentResourceInvalidation(
*layout_object, true);
} }
// TODO(fs): If the resource element (for a filter) doesn't actually change
// we don't need to perform the associated invalidations.
layout_object->SetNeedsPaintPropertyUpdate();
MarkFilterDataDirty();
} }
void SVGElementResourceClient::ResourceDestroyed( void SVGElementResourceClient::ResourceDestroyed(
......
...@@ -109,19 +109,11 @@ void SVGResourcesCache::ClientStyleChanged(LayoutObject& layout_object, ...@@ -109,19 +109,11 @@ void SVGResourcesCache::ClientStyleChanged(LayoutObject& layout_object,
// LayoutObjects for SVGFE*Element should not be calling this function. // LayoutObjects for SVGFE*Element should not be calling this function.
DCHECK(!layout_object.IsSVGFilterPrimitive()); DCHECK(!layout_object.IsSVGFilterPrimitive());
// We only call this function on LayoutObjects that fulfil this condition.
DCHECK(LayoutObjectCanHaveResources(layout_object));
// Dynamic changes of CSS properties like 'clip-path' may require us to // Dynamic changes of CSS properties like 'clip-path' may require us to
// recompute the associated resources for a LayoutObject. // recompute the associated resources for a LayoutObject.
// TODO(fs): Avoid passing in a useless StyleDifference, but instead compare if (UpdateResources(layout_object))
// oldStyle/newStyle to see which resources changed to be able to selectively
// rebuild individual resources, instead of all of them.
SVGResourcesCache& cache = ResourcesCache(layout_object.GetDocument());
if (cache.UpdateResourcesFromLayoutObject(layout_object,
layout_object.StyleRef())) {
layout_object.SetNeedsPaintPropertyUpdate(); layout_object.SetNeedsPaintPropertyUpdate();
}
// If this layoutObject is the child of ResourceContainer and it require // If this layoutObject is the child of ResourceContainer and it require
// repainting that changes of CSS properties such as 'visibility', // repainting that changes of CSS properties such as 'visibility',
...@@ -133,28 +125,6 @@ void SVGResourcesCache::ClientStyleChanged(LayoutObject& layout_object, ...@@ -133,28 +125,6 @@ void SVGResourcesCache::ClientStyleChanged(LayoutObject& layout_object,
layout_object, needs_layout); layout_object, needs_layout);
} }
void SVGResourcesCache::ResourceReferenceChanged(LayoutObject& layout_object) {
DCHECK(layout_object.IsSVG());
DCHECK(layout_object.GetNode());
DCHECK(layout_object.GetNode()->IsSVGElement());
if (!layout_object.Parent())
return;
// Only LayoutObjects that can actually have resources should be pending and
// hence be able to call this method.
DCHECK(LayoutObjectCanHaveResources(layout_object));
SVGResourcesCache& cache = ResourcesCache(layout_object.GetDocument());
if (cache.UpdateResourcesFromLayoutObject(layout_object,
layout_object.StyleRef())) {
layout_object.SetNeedsPaintPropertyUpdate();
}
LayoutSVGResourceContainer::MarkForLayoutAndParentResourceInvalidation(
layout_object, true);
}
void SVGResourcesCache::ClientWasAddedToTree(LayoutObject& layout_object) { void SVGResourcesCache::ClientWasAddedToTree(LayoutObject& layout_object) {
DCHECK(LayoutObjectCanHaveResources(layout_object)); DCHECK(LayoutObjectCanHaveResources(layout_object));
LayoutSVGResourceContainer::MarkForLayoutAndParentResourceInvalidation( LayoutSVGResourceContainer::MarkForLayoutAndParentResourceInvalidation(
...@@ -177,6 +147,13 @@ void SVGResourcesCache::ClientWillBeRemovedFromTree( ...@@ -177,6 +147,13 @@ void SVGResourcesCache::ClientWillBeRemovedFromTree(
layout_object.SetNeedsPaintPropertyUpdate(); layout_object.SetNeedsPaintPropertyUpdate();
} }
bool SVGResourcesCache::UpdateResources(LayoutObject& layout_object) {
DCHECK(LayoutObjectCanHaveResources(layout_object));
SVGResourcesCache& cache = ResourcesCache(layout_object.GetDocument());
return cache.UpdateResourcesFromLayoutObject(layout_object,
layout_object.StyleRef());
}
void SVGResourcesCache::ClientDestroyed(LayoutObject& layout_object) { void SVGResourcesCache::ClientDestroyed(LayoutObject& layout_object) {
SVGResourcesCache& cache = ResourcesCache(layout_object.GetDocument()); SVGResourcesCache& cache = ResourcesCache(layout_object.GetDocument());
cache.RemoveResourcesFromLayoutObject(layout_object); cache.RemoveResourcesFromLayoutObject(layout_object);
......
...@@ -56,8 +56,9 @@ class SVGResourcesCache { ...@@ -56,8 +56,9 @@ class SVGResourcesCache {
static void ClientStyleChanged(LayoutObject&, StyleDifference); static void ClientStyleChanged(LayoutObject&, StyleDifference);
// Called when the target element of a resource referenced by the // Called when the target element of a resource referenced by the
// LayoutObject may have changed. // LayoutObject may have changed and we need to recreate the
static void ResourceReferenceChanged(LayoutObject&); // associated SVGResources object.
static bool UpdateResources(LayoutObject&);
class TemporaryStyleScope { class TemporaryStyleScope {
STACK_ALLOCATED(); STACK_ALLOCATED();
......
...@@ -115,8 +115,12 @@ void SVGPatternElement::BuildPendingResource() { ...@@ -115,8 +115,12 @@ void SVGPatternElement::BuildPendingResource() {
resource_->AddClient(EnsureSVGResourceClient()); resource_->AddClient(EnsureSVGResourceClient());
InvalidatePattern(layout_invalidation_reason::kSvgResourceInvalidated); InvalidatePattern(layout_invalidation_reason::kSvgResourceInvalidated);
if (auto* layout_object = GetLayoutObject()) if (auto* layout_object = GetLayoutObject()) {
SVGResourcesCache::ResourceReferenceChanged(*layout_object); if (!layout_object->Parent())
return;
SVGResourcesCache::UpdateResources(*layout_object);
InvalidateDependentPatterns();
}
} }
void SVGPatternElement::ClearResourceReferences() { void SVGPatternElement::ClearResourceReferences() {
...@@ -200,6 +204,15 @@ void SVGPatternElement::InvalidatePattern( ...@@ -200,6 +204,15 @@ void SVGPatternElement::InvalidatePattern(
layout_object->InvalidateCacheAndMarkForLayout(reason); layout_object->InvalidateCacheAndMarkForLayout(reason);
} }
void SVGPatternElement::InvalidateDependentPatterns() {
NotifyIncomingReferences([](SVGElement& element) {
if (auto* pattern = DynamicTo<SVGPatternElement>(element)) {
pattern->InvalidatePattern(
layout_invalidation_reason::kSvgResourceInvalidated);
}
});
}
LayoutObject* SVGPatternElement::CreateLayoutObject(const ComputedStyle&, LayoutObject* SVGPatternElement::CreateLayoutObject(const ComputedStyle&,
LegacyLayout) { LegacyLayout) {
return new LayoutSVGResourcePattern(this); return new LayoutSVGResourcePattern(this);
......
...@@ -76,6 +76,7 @@ class SVGPatternElement final : public SVGElement, ...@@ -76,6 +76,7 @@ class SVGPatternElement final : public SVGElement,
} }
void InvalidatePattern(LayoutInvalidationReasonForTracing); void InvalidatePattern(LayoutInvalidationReasonForTracing);
void InvalidateDependentPatterns();
const SVGPatternElement* ReferencedElement() const; const SVGPatternElement* ReferencedElement() const;
......
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