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

Simplify SVGResourcesCache::ClientStyleChanged

This is largely a revert of the code-change from
a77da2a9, since that workaround should
no longer be required now that the visual rect no longer has bounds of
clip-path, mask and filter baked in.
Also replace the check of LayoutObjectCanHaveResources() with a DCHECK
since this is guaranteed by the callers.

Bug: 1028061, 1028063
Change-Id: I3cd7eef130468ca1bb2e6473535fac815a7bda1f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2450151Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#814132}
parent 55bc6909
...@@ -268,18 +268,6 @@ void SVGResources::LayoutIfNeeded() { ...@@ -268,18 +268,6 @@ void SVGResources::LayoutIfNeeded() {
linked_resource_->LayoutIfNeeded(); linked_resource_->LayoutIfNeeded();
} }
bool SVGResources::DifferenceNeedsLayout(const SVGResources* a,
const SVGResources* b) {
bool a_has_bounds_affecting_resource = a && a->clipper_filter_masker_data_;
bool b_has_bounds_affecting_resource = b && b->clipper_filter_masker_data_;
if (a_has_bounds_affecting_resource != b_has_bounds_affecting_resource)
return true;
if (!a_has_bounds_affecting_resource)
return false;
return a->Clipper() != b->Clipper() || a->Filter() != b->Filter() ||
a->Masker() != b->Masker();
}
void SVGResources::ResourceDestroyed(LayoutSVGResourceContainer* resource) { void SVGResources::ResourceDestroyed(LayoutSVGResourceContainer* resource) {
DCHECK(resource); DCHECK(resource);
if (!HasResourceData()) if (!HasResourceData())
......
...@@ -120,8 +120,6 @@ class SVGResources { ...@@ -120,8 +120,6 @@ class SVGResources {
void ResourceDestroyed(LayoutSVGResourceContainer*); void ResourceDestroyed(LayoutSVGResourceContainer*);
void ClearReferencesTo(LayoutSVGResourceContainer*); void ClearReferencesTo(LayoutSVGResourceContainer*);
static bool DifferenceNeedsLayout(const SVGResources*, const SVGResources*);
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
void Dump(const LayoutObject*); void Dump(const LayoutObject*);
#endif #endif
......
...@@ -33,7 +33,7 @@ SVGResourcesCache::SVGResourcesCache() = default; ...@@ -33,7 +33,7 @@ SVGResourcesCache::SVGResourcesCache() = default;
SVGResourcesCache::~SVGResourcesCache() = default; SVGResourcesCache::~SVGResourcesCache() = default;
SVGResources* SVGResourcesCache::AddResourcesFromLayoutObject( bool SVGResourcesCache::AddResourcesFromLayoutObject(
LayoutObject& object, LayoutObject& object,
const ComputedStyle& style) { const ComputedStyle& style) {
DCHECK(!cache_.Contains(&object)); DCHECK(!cache_.Contains(&object));
...@@ -42,7 +42,7 @@ SVGResources* SVGResourcesCache::AddResourcesFromLayoutObject( ...@@ -42,7 +42,7 @@ SVGResources* SVGResourcesCache::AddResourcesFromLayoutObject(
std::unique_ptr<SVGResources> new_resources = std::unique_ptr<SVGResources> new_resources =
SVGResources::BuildResources(object, style); SVGResources::BuildResources(object, style);
if (!new_resources) if (!new_resources)
return nullptr; return false;
// Put object in cache. // Put object in cache.
SVGResources* resources = SVGResources* resources =
...@@ -57,7 +57,7 @@ SVGResources* SVGResourcesCache::AddResourcesFromLayoutObject( ...@@ -57,7 +57,7 @@ SVGResources* SVGResourcesCache::AddResourcesFromLayoutObject(
if (resource_container->FindCycle(solver)) if (resource_container->FindCycle(solver))
resources->ClearReferencesTo(resource_container); resources->ClearReferencesTo(resource_container);
} }
return resources; return true;
} }
bool SVGResourcesCache::RemoveResourcesFromLayoutObject(LayoutObject& object) { bool SVGResourcesCache::RemoveResourcesFromLayoutObject(LayoutObject& object) {
...@@ -65,15 +65,12 @@ bool SVGResourcesCache::RemoveResourcesFromLayoutObject(LayoutObject& object) { ...@@ -65,15 +65,12 @@ bool SVGResourcesCache::RemoveResourcesFromLayoutObject(LayoutObject& object) {
return !!resources; return !!resources;
} }
SVGResourcesCache::ResourceUpdateInfo bool SVGResourcesCache::UpdateResourcesFromLayoutObject(
SVGResourcesCache::UpdateResourcesFromLayoutObject(
LayoutObject& object, LayoutObject& object,
const ComputedStyle& new_style) { const ComputedStyle& new_style) {
std::unique_ptr<SVGResources> old_resources = cache_.Take(&object); bool did_update = RemoveResourcesFromLayoutObject(object);
SVGResources* new_resources = AddResourcesFromLayoutObject(object, new_style); did_update |= AddResourcesFromLayoutObject(object, new_style);
return { return did_update;
old_resources || new_resources,
SVGResources::DifferenceNeedsLayout(old_resources.get(), new_resources)};
} }
static inline SVGResourcesCache& ResourcesCache(Document& document) { static inline SVGResourcesCache& ResourcesCache(Document& document) {
...@@ -147,32 +144,23 @@ void SVGResourcesCache::ClientStyleChanged(LayoutObject& layout_object, ...@@ -147,32 +144,23 @@ 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 // TODO(fs): Avoid passing in a useless StyleDifference, but instead compare
// oldStyle/newStyle to see which resources changed to be able to selectively // oldStyle/newStyle to see which resources changed to be able to selectively
// rebuild individual resources, instead of all of them. // rebuild individual resources, instead of all of them.
bool needs_layout = false; SVGResourcesCache& cache = ResourcesCache(layout_object.GetDocument());
if (LayoutObjectCanHaveResources(layout_object)) { if (cache.UpdateResourcesFromLayoutObject(layout_object, new_style))
SVGResourcesCache& cache = ResourcesCache(layout_object.GetDocument()); layout_object.SetNeedsPaintPropertyUpdate();
auto update_info =
cache.UpdateResourcesFromLayoutObject(layout_object, new_style);
if (update_info) {
layout_object.SetNeedsPaintPropertyUpdate();
// Since the visual rect has the bounds of the clip-path, mask and filter
// baked in, and the visual rect is updated during layout, we need to
// trigger layout if the style change could somehow have affected the
// bounds that form the visual rect.
needs_layout = update_info.needs_layout;
}
}
// 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',
// request repainting. // request repainting.
needs_layout |= diff.NeedsPaintInvalidation() && bool needs_layout = diff.NeedsPaintInvalidation() &&
IsLayoutObjectOfResourceContainer(layout_object); IsLayoutObjectOfResourceContainer(layout_object);
LayoutSVGResourceContainer::MarkForLayoutAndParentResourceInvalidation( LayoutSVGResourceContainer::MarkForLayoutAndParentResourceInvalidation(
layout_object, needs_layout); layout_object, needs_layout);
......
...@@ -85,17 +85,9 @@ class SVGResourcesCache { ...@@ -85,17 +85,9 @@ class SVGResourcesCache {
}; };
private: private:
struct ResourceUpdateInfo { bool AddResourcesFromLayoutObject(LayoutObject&, const ComputedStyle&);
bool changed;
bool needs_layout;
explicit operator bool() const { return changed; }
};
SVGResources* AddResourcesFromLayoutObject(LayoutObject&,
const ComputedStyle&);
bool RemoveResourcesFromLayoutObject(LayoutObject&); bool RemoveResourcesFromLayoutObject(LayoutObject&);
ResourceUpdateInfo UpdateResourcesFromLayoutObject(LayoutObject&, bool UpdateResourcesFromLayoutObject(LayoutObject&, const ComputedStyle&);
const ComputedStyle&);
typedef HashMap<const LayoutObject*, std::unique_ptr<SVGResources>> CacheMap; typedef HashMap<const LayoutObject*, std::unique_ptr<SVGResources>> CacheMap;
CacheMap cache_; CacheMap cache_;
......
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