Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: third_party/WebKit/Source/core/layout/svg/SVGResourcesCache.cpp

Issue 2824823003: DOM-based SVG resource tracking (Closed)
Patch Set: Update baselines Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 void SVGResourcesCache::RemoveResourcesFromLayoutObject(LayoutObject* object) { 63 void SVGResourcesCache::RemoveResourcesFromLayoutObject(LayoutObject* object) {
64 std::unique_ptr<SVGResources> resources = cache_.Take(object); 64 std::unique_ptr<SVGResources> resources = cache_.Take(object);
65 if (!resources) 65 if (!resources)
66 return; 66 return;
67 67
68 // Walk resources and unregister the layout object as a client of each 68 // Walk resources and unregister the layout object as a client of each
69 // resource. 69 // resource.
70 HashSet<LayoutSVGResourceContainer*> resource_set; 70 HashSet<LayoutSVGResourceContainer*> resource_set;
71 resources->BuildSetOfResources(resource_set); 71 resources->BuildSetOfResources(resource_set);
72 72
73 bool did_empty_client_set = false;
73 for (auto* resource_container : resource_set) 74 for (auto* resource_container : resource_set)
74 resource_container->RemoveClient(object); 75 did_empty_client_set |= resource_container->RemoveClient(object);
76
77 // Remove any registrations that became empty after the above.
78 if (did_empty_client_set)
79 SVGResources::RemoveUnreferencedResources(*object);
75 } 80 }
76 81
77 static inline SVGResourcesCache& ResourcesCache(Document& document) { 82 static inline SVGResourcesCache& ResourcesCache(Document& document) {
78 return document.AccessSVGExtensions().ResourcesCache(); 83 return document.AccessSVGExtensions().ResourcesCache();
79 } 84 }
80 85
81 SVGResources* SVGResourcesCache::CachedResourcesForLayoutObject( 86 SVGResources* SVGResourcesCache::CachedResourcesForLayoutObject(
82 const LayoutObject* layout_object) { 87 const LayoutObject* layout_object) {
83 DCHECK(layout_object); 88 DCHECK(layout_object);
84 return ResourcesCache(layout_object->GetDocument()).cache_.at(layout_object); 89 return ResourcesCache(layout_object->GetDocument()).cache_.at(layout_object);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // If this layoutObject is the child of ResourceContainer and it require 148 // If this layoutObject is the child of ResourceContainer and it require
144 // repainting that changes of CSS properties such as 'visibility', 149 // repainting that changes of CSS properties such as 'visibility',
145 // request repainting. 150 // request repainting.
146 bool needs_layout = diff.NeedsFullPaintInvalidation() && 151 bool needs_layout = diff.NeedsFullPaintInvalidation() &&
147 IsLayoutObjectOfResourceContainer(layout_object); 152 IsLayoutObjectOfResourceContainer(layout_object);
148 153
149 LayoutSVGResourceContainer::MarkForLayoutAndParentResourceInvalidation( 154 LayoutSVGResourceContainer::MarkForLayoutAndParentResourceInvalidation(
150 layout_object, needs_layout); 155 layout_object, needs_layout);
151 } 156 }
152 157
158 void SVGResourcesCache::ResourceReferenceChanged(LayoutObject& layout_object) {
159 DCHECK(layout_object.IsSVG());
160 DCHECK(layout_object.GetNode());
161 DCHECK(layout_object.GetNode()->IsSVGElement());
162
163 if (!layout_object.Parent())
164 return;
165
166 // Only LayoutObjects that can actually have resources should be pending and
167 // hence be able to call this method.
168 DCHECK(LayoutObjectCanHaveResources(&layout_object));
169
170 SVGResourcesCache& cache = ResourcesCache(layout_object.GetDocument());
171 cache.RemoveResourcesFromLayoutObject(&layout_object);
172 cache.AddResourcesFromLayoutObject(&layout_object, layout_object.StyleRef());
173
174 LayoutSVGResourceContainer::MarkForLayoutAndParentResourceInvalidation(
175 &layout_object, true);
176 }
177
153 void SVGResourcesCache::ClientWasAddedToTree(LayoutObject* layout_object, 178 void SVGResourcesCache::ClientWasAddedToTree(LayoutObject* layout_object,
154 const ComputedStyle& new_style) { 179 const ComputedStyle& new_style) {
155 if (!layout_object->GetNode()) 180 if (!layout_object->GetNode())
156 return; 181 return;
157 LayoutSVGResourceContainer::MarkForLayoutAndParentResourceInvalidation( 182 LayoutSVGResourceContainer::MarkForLayoutAndParentResourceInvalidation(
158 layout_object, false); 183 layout_object, false);
159 184
160 if (!LayoutObjectCanHaveResources(layout_object)) 185 if (!LayoutObjectCanHaveResources(layout_object))
161 return; 186 return;
162 SVGResourcesCache& cache = ResourcesCache(layout_object->GetDocument()); 187 SVGResourcesCache& cache = ResourcesCache(layout_object->GetDocument());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 const ComputedStyle& style) { 225 const ComputedStyle& style) {
201 DCHECK(LayoutObjectCanHaveResources(&layout_object_)); 226 DCHECK(LayoutObjectCanHaveResources(&layout_object_));
202 if (styles_are_equal_) 227 if (styles_are_equal_)
203 return; 228 return;
204 SVGResourcesCache& cache = ResourcesCache(layout_object_.GetDocument()); 229 SVGResourcesCache& cache = ResourcesCache(layout_object_.GetDocument());
205 cache.RemoveResourcesFromLayoutObject(&layout_object_); 230 cache.RemoveResourcesFromLayoutObject(&layout_object_);
206 cache.AddResourcesFromLayoutObject(&layout_object_, style); 231 cache.AddResourcesFromLayoutObject(&layout_object_, style);
207 } 232 }
208 233
209 } // namespace blink 234 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/svg/SVGResourcesCache.h ('k') | third_party/WebKit/Source/core/svg/SVGClipPathElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698