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(
}
void SVGElementResourceClient::ResourceElementChanged() {
if (LayoutObject* layout_object = element_->GetLayoutObject()) {
ClearFilterData();
SVGResourcesCache::ResourceReferenceChanged(*layout_object);
// 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();
LayoutObject* layout_object = element_->GetLayoutObject();
if (!layout_object)
return;
ClearFilterData();
if (layout_object->Parent()) {
SVGResourcesCache::UpdateResources(*layout_object);
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(
......
......@@ -109,19 +109,11 @@ void SVGResourcesCache::ClientStyleChanged(LayoutObject& layout_object,
// LayoutObjects for SVGFE*Element should not be calling this function.
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
// recompute the associated resources for a LayoutObject.
// 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.
SVGResourcesCache& cache = ResourcesCache(layout_object.GetDocument());
if (cache.UpdateResourcesFromLayoutObject(layout_object,
layout_object.StyleRef())) {
if (UpdateResources(layout_object))
layout_object.SetNeedsPaintPropertyUpdate();
}
// If this layoutObject is the child of ResourceContainer and it require
// repainting that changes of CSS properties such as 'visibility',
......@@ -133,28 +125,6 @@ void SVGResourcesCache::ClientStyleChanged(LayoutObject& layout_object,
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) {
DCHECK(LayoutObjectCanHaveResources(layout_object));
LayoutSVGResourceContainer::MarkForLayoutAndParentResourceInvalidation(
......@@ -177,6 +147,13 @@ void SVGResourcesCache::ClientWillBeRemovedFromTree(
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) {
SVGResourcesCache& cache = ResourcesCache(layout_object.GetDocument());
cache.RemoveResourcesFromLayoutObject(layout_object);
......
......@@ -56,8 +56,9 @@ class SVGResourcesCache {
static void ClientStyleChanged(LayoutObject&, StyleDifference);
// Called when the target element of a resource referenced by the
// LayoutObject may have changed.
static void ResourceReferenceChanged(LayoutObject&);
// LayoutObject may have changed and we need to recreate the
// associated SVGResources object.
static bool UpdateResources(LayoutObject&);
class TemporaryStyleScope {
STACK_ALLOCATED();
......
......@@ -115,8 +115,12 @@ void SVGPatternElement::BuildPendingResource() {
resource_->AddClient(EnsureSVGResourceClient());
InvalidatePattern(layout_invalidation_reason::kSvgResourceInvalidated);
if (auto* layout_object = GetLayoutObject())
SVGResourcesCache::ResourceReferenceChanged(*layout_object);
if (auto* layout_object = GetLayoutObject()) {
if (!layout_object->Parent())
return;
SVGResourcesCache::UpdateResources(*layout_object);
InvalidateDependentPatterns();
}
}
void SVGPatternElement::ClearResourceReferences() {
......@@ -200,6 +204,15 @@ void SVGPatternElement::InvalidatePattern(
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&,
LegacyLayout) {
return new LayoutSVGResourcePattern(this);
......
......@@ -76,6 +76,7 @@ class SVGPatternElement final : public SVGElement,
}
void InvalidatePattern(LayoutInvalidationReasonForTracing);
void InvalidateDependentPatterns();
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