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

Side by Side Diff: Source/core/layout/svg/LayoutSVGResourceContainer.cpp

Issue 908243002: Move rendering/svg/RenderSVGResource* to layout/svg. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 10 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 | Annotate | Revision Log
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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public License 14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to 15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA. 17 * Boston, MA 02110-1301, USA.
18 */ 18 */
19 19
20 #include "config.h" 20 #include "config.h"
21 #include "core/rendering/svg/RenderSVGResourceContainer.h" 21 #include "core/layout/svg/LayoutSVGResourceContainer.h"
22 22
23 #include "core/layout/Layer.h" 23 #include "core/layout/Layer.h"
24 #include "core/layout/svg/LayoutSVGResourceClipper.h"
25 #include "core/layout/svg/LayoutSVGResourceFilter.h"
26 #include "core/layout/svg/LayoutSVGResourceMasker.h"
24 #include "core/layout/svg/SVGResources.h" 27 #include "core/layout/svg/SVGResources.h"
25 #include "core/layout/svg/SVGResourcesCache.h" 28 #include "core/layout/svg/SVGResourcesCache.h"
26 #include "core/rendering/svg/RenderSVGResourceClipper.h"
27 #include "core/rendering/svg/RenderSVGResourceFilter.h"
28 #include "core/rendering/svg/RenderSVGResourceMasker.h"
29 29
30 #include "wtf/TemporaryChange.h" 30 #include "wtf/TemporaryChange.h"
31 31
32 namespace blink { 32 namespace blink {
33 33
34 static inline SVGDocumentExtensions& svgExtensionsFromElement(SVGElement* elemen t) 34 static inline SVGDocumentExtensions& svgExtensionsFromElement(SVGElement* elemen t)
35 { 35 {
36 ASSERT(element); 36 ASSERT(element);
37 return element->document().accessSVGExtensions(); 37 return element->document().accessSVGExtensions();
38 } 38 }
39 39
40 RenderSVGResourceContainer::RenderSVGResourceContainer(SVGElement* node) 40 LayoutSVGResourceContainer::LayoutSVGResourceContainer(SVGElement* node)
41 : RenderSVGHiddenContainer(node) 41 : RenderSVGHiddenContainer(node)
42 , m_isInLayout(false) 42 , m_isInLayout(false)
43 , m_id(node->getIdAttribute()) 43 , m_id(node->getIdAttribute())
44 , m_invalidationMask(0) 44 , m_invalidationMask(0)
45 , m_registered(false) 45 , m_registered(false)
46 , m_isInvalidating(false) 46 , m_isInvalidating(false)
47 { 47 {
48 } 48 }
49 49
50 RenderSVGResourceContainer::~RenderSVGResourceContainer() 50 LayoutSVGResourceContainer::~LayoutSVGResourceContainer()
51 { 51 {
52 } 52 }
53 53
54 void RenderSVGResourceContainer::layout() 54 void LayoutSVGResourceContainer::layout()
55 { 55 {
56 // FIXME: Investigate a way to detect and break resource layout dependency c ycles early. 56 // FIXME: Investigate a way to detect and break resource layout dependency c ycles early.
57 // Then we can remove this method altogether, and fall back onto RenderSVGHi ddenContainer::layout(). 57 // Then we can remove this method altogether, and fall back onto RenderSVGHi ddenContainer::layout().
58 ASSERT(needsLayout()); 58 ASSERT(needsLayout());
59 if (m_isInLayout) 59 if (m_isInLayout)
60 return; 60 return;
61 61
62 TemporaryChange<bool> inLayoutChange(m_isInLayout, true); 62 TemporaryChange<bool> inLayoutChange(m_isInLayout, true);
63 63
64 RenderSVGHiddenContainer::layout(); 64 RenderSVGHiddenContainer::layout();
65 65
66 clearInvalidationMask(); 66 clearInvalidationMask();
67 } 67 }
68 68
69 void RenderSVGResourceContainer::willBeDestroyed() 69 void LayoutSVGResourceContainer::willBeDestroyed()
70 { 70 {
71 SVGResourcesCache::resourceDestroyed(this); 71 SVGResourcesCache::resourceDestroyed(this);
72 RenderSVGHiddenContainer::willBeDestroyed(); 72 RenderSVGHiddenContainer::willBeDestroyed();
73 if (m_registered) 73 if (m_registered)
74 svgExtensionsFromElement(element()).removeResource(m_id); 74 svgExtensionsFromElement(element()).removeResource(m_id);
75 } 75 }
76 76
77 void RenderSVGResourceContainer::styleDidChange(StyleDifference diff, const Layo utStyle* oldStyle) 77 void LayoutSVGResourceContainer::styleDidChange(StyleDifference diff, const Layo utStyle* oldStyle)
78 { 78 {
79 RenderSVGHiddenContainer::styleDidChange(diff, oldStyle); 79 RenderSVGHiddenContainer::styleDidChange(diff, oldStyle);
80 80
81 if (!m_registered) { 81 if (!m_registered) {
82 m_registered = true; 82 m_registered = true;
83 registerResource(); 83 registerResource();
84 } 84 }
85 } 85 }
86 86
87 void RenderSVGResourceContainer::idChanged() 87 void LayoutSVGResourceContainer::idChanged()
88 { 88 {
89 // Invalidate all our current clients. 89 // Invalidate all our current clients.
90 removeAllClientsFromCache(); 90 removeAllClientsFromCache();
91 91
92 // Remove old id, that is guaranteed to be present in cache. 92 // Remove old id, that is guaranteed to be present in cache.
93 SVGDocumentExtensions& extensions = svgExtensionsFromElement(element()); 93 SVGDocumentExtensions& extensions = svgExtensionsFromElement(element());
94 extensions.removeResource(m_id); 94 extensions.removeResource(m_id);
95 m_id = element()->getIdAttribute(); 95 m_id = element()->getIdAttribute();
96 96
97 registerResource(); 97 registerResource();
98 } 98 }
99 99
100 void RenderSVGResourceContainer::markAllClientsForInvalidation(InvalidationMode mode) 100 void LayoutSVGResourceContainer::markAllClientsForInvalidation(InvalidationMode mode)
101 { 101 {
102 if ((m_clients.isEmpty() && m_clientLayers.isEmpty()) || m_isInvalidating) 102 if ((m_clients.isEmpty() && m_clientLayers.isEmpty()) || m_isInvalidating)
103 return; 103 return;
104 104
105 if (m_invalidationMask & mode) 105 if (m_invalidationMask & mode)
106 return; 106 return;
107 107
108 m_invalidationMask |= mode; 108 m_invalidationMask |= mode;
109 m_isInvalidating = true; 109 m_isInvalidating = true;
110 bool needsLayout = mode == LayoutAndBoundariesInvalidation; 110 bool needsLayout = mode == LayoutAndBoundariesInvalidation;
111 bool markForInvalidation = mode != ParentOnlyInvalidation; 111 bool markForInvalidation = mode != ParentOnlyInvalidation;
112 112
113 HashSet<LayoutObject*>::iterator end = m_clients.end(); 113 HashSet<LayoutObject*>::iterator end = m_clients.end();
114 for (HashSet<LayoutObject*>::iterator it = m_clients.begin(); it != end; ++i t) { 114 for (HashSet<LayoutObject*>::iterator it = m_clients.begin(); it != end; ++i t) {
115 LayoutObject* client = *it; 115 LayoutObject* client = *it;
116 if (client->isSVGResourceContainer()) { 116 if (client->isSVGResourceContainer()) {
117 toRenderSVGResourceContainer(client)->removeAllClientsFromCache(mark ForInvalidation); 117 toLayoutSVGResourceContainer(client)->removeAllClientsFromCache(mark ForInvalidation);
118 continue; 118 continue;
119 } 119 }
120 120
121 if (markForInvalidation) 121 if (markForInvalidation)
122 markClientForInvalidation(client, mode); 122 markClientForInvalidation(client, mode);
123 123
124 RenderSVGResourceContainer::markForLayoutAndParentResourceInvalidation(c lient, needsLayout); 124 LayoutSVGResourceContainer::markForLayoutAndParentResourceInvalidation(c lient, needsLayout);
125 } 125 }
126 126
127 markAllClientLayersForInvalidation(); 127 markAllClientLayersForInvalidation();
128 128
129 m_isInvalidating = false; 129 m_isInvalidating = false;
130 } 130 }
131 131
132 void RenderSVGResourceContainer::markAllClientLayersForInvalidation() 132 void LayoutSVGResourceContainer::markAllClientLayersForInvalidation()
133 { 133 {
134 HashSet<Layer*>::iterator layerEnd = m_clientLayers.end(); 134 HashSet<Layer*>::iterator layerEnd = m_clientLayers.end();
135 for (HashSet<Layer*>::iterator it = m_clientLayers.begin(); it != layerEnd; ++it) 135 for (HashSet<Layer*>::iterator it = m_clientLayers.begin(); it != layerEnd; ++it)
136 (*it)->filterNeedsPaintInvalidation(); 136 (*it)->filterNeedsPaintInvalidation();
137 } 137 }
138 138
139 void RenderSVGResourceContainer::markClientForInvalidation(LayoutObject* client, InvalidationMode mode) 139 void LayoutSVGResourceContainer::markClientForInvalidation(LayoutObject* client, InvalidationMode mode)
140 { 140 {
141 ASSERT(client); 141 ASSERT(client);
142 ASSERT(!m_clients.isEmpty()); 142 ASSERT(!m_clients.isEmpty());
143 143
144 switch (mode) { 144 switch (mode) {
145 case LayoutAndBoundariesInvalidation: 145 case LayoutAndBoundariesInvalidation:
146 case BoundariesInvalidation: 146 case BoundariesInvalidation:
147 client->setNeedsBoundariesUpdate(); 147 client->setNeedsBoundariesUpdate();
148 break; 148 break;
149 case PaintInvalidation: 149 case PaintInvalidation:
150 client->setShouldDoFullPaintInvalidation(); 150 client->setShouldDoFullPaintInvalidation();
151 break; 151 break;
152 case ParentOnlyInvalidation: 152 case ParentOnlyInvalidation:
153 break; 153 break;
154 } 154 }
155 } 155 }
156 156
157 void RenderSVGResourceContainer::addClient(LayoutObject* client) 157 void LayoutSVGResourceContainer::addClient(LayoutObject* client)
158 { 158 {
159 ASSERT(client); 159 ASSERT(client);
160 m_clients.add(client); 160 m_clients.add(client);
161 clearInvalidationMask(); 161 clearInvalidationMask();
162 } 162 }
163 163
164 void RenderSVGResourceContainer::removeClient(LayoutObject* client) 164 void LayoutSVGResourceContainer::removeClient(LayoutObject* client)
165 { 165 {
166 ASSERT(client); 166 ASSERT(client);
167 removeClientFromCache(client, false); 167 removeClientFromCache(client, false);
168 m_clients.remove(client); 168 m_clients.remove(client);
169 } 169 }
170 170
171 void RenderSVGResourceContainer::addClientLayer(Node* node) 171 void LayoutSVGResourceContainer::addClientLayer(Node* node)
172 { 172 {
173 ASSERT(node); 173 ASSERT(node);
174 if (!node->renderer() || !node->renderer()->hasLayer()) 174 if (!node->renderer() || !node->renderer()->hasLayer())
175 return; 175 return;
176 m_clientLayers.add(toLayoutLayerModelObject(node->renderer())->layer()); 176 m_clientLayers.add(toLayoutLayerModelObject(node->renderer())->layer());
177 clearInvalidationMask(); 177 clearInvalidationMask();
178 } 178 }
179 179
180 void RenderSVGResourceContainer::addClientLayer(Layer* client) 180 void LayoutSVGResourceContainer::addClientLayer(Layer* client)
181 { 181 {
182 ASSERT(client); 182 ASSERT(client);
183 m_clientLayers.add(client); 183 m_clientLayers.add(client);
184 clearInvalidationMask(); 184 clearInvalidationMask();
185 } 185 }
186 186
187 void RenderSVGResourceContainer::removeClientLayer(Layer* client) 187 void LayoutSVGResourceContainer::removeClientLayer(Layer* client)
188 { 188 {
189 ASSERT(client); 189 ASSERT(client);
190 m_clientLayers.remove(client); 190 m_clientLayers.remove(client);
191 } 191 }
192 192
193 void RenderSVGResourceContainer::invalidateCacheAndMarkForLayout(SubtreeLayoutSc ope* layoutScope) 193 void LayoutSVGResourceContainer::invalidateCacheAndMarkForLayout(SubtreeLayoutSc ope* layoutScope)
194 { 194 {
195 if (selfNeedsLayout()) 195 if (selfNeedsLayout())
196 return; 196 return;
197 197
198 setNeedsLayoutAndFullPaintInvalidation(MarkContainingBlockChain, layoutScope ); 198 setNeedsLayoutAndFullPaintInvalidation(MarkContainingBlockChain, layoutScope );
199 199
200 if (everHadLayout()) 200 if (everHadLayout())
201 removeAllClientsFromCache(); 201 removeAllClientsFromCache();
202 } 202 }
203 203
204 void RenderSVGResourceContainer::registerResource() 204 void LayoutSVGResourceContainer::registerResource()
205 { 205 {
206 SVGDocumentExtensions& extensions = svgExtensionsFromElement(element()); 206 SVGDocumentExtensions& extensions = svgExtensionsFromElement(element());
207 if (!extensions.hasPendingResource(m_id)) { 207 if (!extensions.hasPendingResource(m_id)) {
208 extensions.addResource(m_id, this); 208 extensions.addResource(m_id, this);
209 return; 209 return;
210 } 210 }
211 211
212 OwnPtrWillBeRawPtr<SVGDocumentExtensions::SVGPendingElements> clients(extens ions.removePendingResource(m_id)); 212 OwnPtrWillBeRawPtr<SVGDocumentExtensions::SVGPendingElements> clients(extens ions.removePendingResource(m_id));
213 213
214 // Cache us with the new id. 214 // Cache us with the new id.
(...skipping 12 matching lines...) Expand all
227 diff.setNeedsFullLayout(); 227 diff.setNeedsFullLayout();
228 SVGResourcesCache::clientStyleChanged(renderer, diff, renderer->styleRef ()); 228 SVGResourcesCache::clientStyleChanged(renderer, diff, renderer->styleRef ());
229 renderer->setNeedsLayoutAndFullPaintInvalidation(); 229 renderer->setNeedsLayoutAndFullPaintInvalidation();
230 } 230 }
231 } 231 }
232 232
233 static inline void removeFromCacheAndInvalidateDependencies(LayoutObject* object , bool needsLayout) 233 static inline void removeFromCacheAndInvalidateDependencies(LayoutObject* object , bool needsLayout)
234 { 234 {
235 ASSERT(object); 235 ASSERT(object);
236 if (SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObj ect(object)) { 236 if (SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObj ect(object)) {
237 if (RenderSVGResourceFilter* filter = resources->filter()) 237 if (LayoutSVGResourceFilter* filter = resources->filter())
238 filter->removeClientFromCache(object); 238 filter->removeClientFromCache(object);
239 239
240 if (RenderSVGResourceMasker* masker = resources->masker()) 240 if (LayoutSVGResourceMasker* masker = resources->masker())
241 masker->removeClientFromCache(object); 241 masker->removeClientFromCache(object);
242 242
243 if (RenderSVGResourceClipper* clipper = resources->clipper()) 243 if (LayoutSVGResourceClipper* clipper = resources->clipper())
244 clipper->removeClientFromCache(object); 244 clipper->removeClientFromCache(object);
245 } 245 }
246 246
247 if (!object->node() || !object->node()->isSVGElement()) 247 if (!object->node() || !object->node()->isSVGElement())
248 return; 248 return;
249 SVGElementSet* dependencies = toSVGElement(object->node())->setOfIncomingRef erences(); 249 SVGElementSet* dependencies = toSVGElement(object->node())->setOfIncomingRef erences();
250 if (!dependencies) 250 if (!dependencies)
251 return; 251 return;
252 252
253 // We allow cycles in SVGDocumentExtensions reference sets in order to avoid expensive 253 // We allow cycles in SVGDocumentExtensions reference sets in order to avoid expensive
254 // reference graph adjustments on changes, so we need to break possible cycl es here. 254 // reference graph adjustments on changes, so we need to break possible cycl es here.
255 // This strong reference is safe, as it is guaranteed that this set will be emptied 255 // This strong reference is safe, as it is guaranteed that this set will be emptied
256 // at the end of recursion. 256 // at the end of recursion.
257 typedef WillBeHeapHashSet<RawPtrWillBeMember<SVGElement> > SVGElementSet; 257 typedef WillBeHeapHashSet<RawPtrWillBeMember<SVGElement>> SVGElementSet;
258 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<SVGElementSet>, invalidatingDepen dencies, (adoptPtrWillBeNoop(new SVGElementSet))); 258 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<SVGElementSet>, invalidatingDepen dencies, (adoptPtrWillBeNoop(new SVGElementSet)));
259 259
260 SVGElementSet::iterator end = dependencies->end(); 260 SVGElementSet::iterator end = dependencies->end();
261 for (SVGElementSet::iterator it = dependencies->begin(); it != end; ++it) { 261 for (SVGElementSet::iterator it = dependencies->begin(); it != end; ++it) {
262 if (LayoutObject* renderer = (*it)->renderer()) { 262 if (LayoutObject* renderer = (*it)->renderer()) {
263 if (UNLIKELY(!invalidatingDependencies->add(*it).isNewEntry)) { 263 if (UNLIKELY(!invalidatingDependencies->add(*it).isNewEntry)) {
264 // Reference cycle: we are in process of invalidating this depen dant. 264 // Reference cycle: we are in process of invalidating this depen dant.
265 continue; 265 continue;
266 } 266 }
267 267
268 RenderSVGResourceContainer::markForLayoutAndParentResourceInvalidati on(renderer, needsLayout); 268 LayoutSVGResourceContainer::markForLayoutAndParentResourceInvalidati on(renderer, needsLayout);
269 invalidatingDependencies->remove(*it); 269 invalidatingDependencies->remove(*it);
270 } 270 }
271 } 271 }
272 } 272 }
273 273
274 void RenderSVGResourceContainer::markForLayoutAndParentResourceInvalidation(Layo utObject* object, bool needsLayout) 274 void LayoutSVGResourceContainer::markForLayoutAndParentResourceInvalidation(Layo utObject* object, bool needsLayout)
275 { 275 {
276 ASSERT(object); 276 ASSERT(object);
277 ASSERT(object->node()); 277 ASSERT(object->node());
278 278
279 if (needsLayout && !object->documentBeingDestroyed()) 279 if (needsLayout && !object->documentBeingDestroyed())
280 object->setNeedsLayoutAndFullPaintInvalidation(); 280 object->setNeedsLayoutAndFullPaintInvalidation();
281 281
282 removeFromCacheAndInvalidateDependencies(object, needsLayout); 282 removeFromCacheAndInvalidateDependencies(object, needsLayout);
283 283
284 // Invalidate resources in ancestor chain, if needed. 284 // Invalidate resources in ancestor chain, if needed.
285 LayoutObject* current = object->parent(); 285 LayoutObject* current = object->parent();
286 while (current) { 286 while (current) {
287 removeFromCacheAndInvalidateDependencies(current, needsLayout); 287 removeFromCacheAndInvalidateDependencies(current, needsLayout);
288 288
289 if (current->isSVGResourceContainer()) { 289 if (current->isSVGResourceContainer()) {
290 // This will process the rest of the ancestors. 290 // This will process the rest of the ancestors.
291 toRenderSVGResourceContainer(current)->removeAllClientsFromCache(); 291 toLayoutSVGResourceContainer(current)->removeAllClientsFromCache();
292 break; 292 break;
293 } 293 }
294 294
295 current = current->parent(); 295 current = current->parent();
296 } 296 }
297 } 297 }
298 298
299 } 299 }
OLDNEW
« no previous file with comments | « Source/core/layout/svg/LayoutSVGResourceContainer.h ('k') | Source/core/layout/svg/LayoutSVGResourceFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698