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

Side by Side Diff: Source/core/rendering/RenderBlock.cpp

Issue 131233003: Refactor ResourceLoadPriorityOptimizer to avoid walking render tree (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Use esprehn's suggestion. Created 6 years, 11 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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2007 David Smith (catfish.man@gmail.com) 4 * (C) 2007 David Smith (catfish.man@gmail.com)
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 ASSERT(containerSet->contains(block)); 175 ASSERT(containerSet->contains(block));
176 containerSet->remove(block); 176 containerSet->remove(block);
177 if (containerSet->isEmpty()) 177 if (containerSet->isEmpty())
178 containerMap->remove(it); 178 containerMap->remove(it);
179 } 179 }
180 } 180 }
181 } 181 }
182 182
183 static void appendImageIfNotNull(Vector<ImageResource*>& imageResources, const S tyleImage* styleImage) 183 static void appendImageIfNotNull(Vector<ImageResource*>& imageResources, const S tyleImage* styleImage)
184 { 184 {
185 if (styleImage && styleImage->cachedImage()) 185 if (styleImage && styleImage->cachedImage()) {
186 imageResources.append(styleImage->cachedImage()); 186 ImageResource* imageResource = styleImage->cachedImage();
187 if (imageResource && !imageResource->isLoaded())
188 imageResources.append(styleImage->cachedImage());
189 }
187 } 190 }
188 191
189 static void appendLayers(Vector<ImageResource*>& images, const FillLayer* styleL ayer) 192 static void appendLayers(Vector<ImageResource*>& images, const FillLayer* styleL ayer)
190 { 193 {
191 for (const FillLayer* layer = styleLayer; layer; layer = layer->next()) { 194 for (const FillLayer* layer = styleLayer; layer; layer = layer->next()) {
192 appendImageIfNotNull(images, layer->image()); 195 appendImageIfNotNull(images, layer->image());
193 } 196 }
194 } 197 }
195 198
199 static void appendImagesFromStyle(Vector<ImageResource*>& images, RenderStyle* b lockStyle)
esprehn 2014/01/15 01:27:45 RenerStyle& blockStyle
shatch 2014/01/15 19:28:52 Done.
200 {
201 appendLayers(images, blockStyle->backgroundLayers());
202 appendLayers(images, blockStyle->maskLayers());
203
204 const ContentData* contentData = blockStyle->contentData();
205 if (contentData && contentData->isImage()) {
206 const ImageContentData* imageContentData = static_cast<const ImageConten tData*>(contentData);
207 appendImageIfNotNull(images, imageContentData->image());
208 }
209 if (blockStyle->boxReflect())
210 appendImageIfNotNull(images, blockStyle->boxReflect()->mask().image());
211 appendImageIfNotNull(images, blockStyle->listStyleImage());
212 appendImageIfNotNull(images, blockStyle->borderImageSource());
213 appendImageIfNotNull(images, blockStyle->maskBoxImageSource());
214 }
215
196 RenderBlock::~RenderBlock() 216 RenderBlock::~RenderBlock()
197 { 217 {
218 resourceLoadPriorityOptimizer()->removeRenderObject(this);
198 if (hasColumns()) 219 if (hasColumns())
199 gColumnInfoMap->take(this); 220 gColumnInfoMap->take(this);
200 if (gPercentHeightDescendantsMap) 221 if (gPercentHeightDescendantsMap)
201 removeBlockFromDescendantAndContainerMaps(this, gPercentHeightDescendant sMap, gPercentHeightContainerMap); 222 removeBlockFromDescendantAndContainerMaps(this, gPercentHeightDescendant sMap, gPercentHeightContainerMap);
202 if (gPositionedDescendantsMap) 223 if (gPositionedDescendantsMap)
203 removeBlockFromDescendantAndContainerMaps(this, gPositionedDescendantsMa p, gPositionedContainerMap); 224 removeBlockFromDescendantAndContainerMaps(this, gPositionedDescendantsMa p, gPositionedContainerMap);
204 } 225 }
205 226
206 void RenderBlock::willBeDestroyed() 227 void RenderBlock::willBeDestroyed()
207 { 228 {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 340
320 if (FastTextAutosizer* textAutosizer = document().fastTextAutosizer()) 341 if (FastTextAutosizer* textAutosizer = document().fastTextAutosizer())
321 textAutosizer->record(this); 342 textAutosizer->record(this);
322 343
323 propagateStyleToAnonymousChildren(true); 344 propagateStyleToAnonymousChildren(true);
324 m_lineHeight = -1; 345 m_lineHeight = -1;
325 346
326 // It's possible for our border/padding to change, but for the overall logic al width of the block to 347 // It's possible for our border/padding to change, but for the overall logic al width of the block to
327 // end up being the same. We keep track of this change so in layoutBlock, we can know to set relayoutChildren=true. 348 // end up being the same. We keep track of this change so in layoutBlock, we can know to set relayoutChildren=true.
328 m_hasBorderOrPaddingLogicalWidthChanged = oldStyle && diff == StyleDifferenc eLayout && needsLayout() && borderOrPaddingLogicalWidthChanged(oldStyle, newStyl e); 349 m_hasBorderOrPaddingLogicalWidthChanged = oldStyle && diff == StyleDifferenc eLayout && needsLayout() && borderOrPaddingLogicalWidthChanged(oldStyle, newStyl e);
350
351 // If the style has unloaded images, want to notify the ResourceLoadPriority Optimizer so that
352 // network priorities can be set.
353 Vector<ImageResource*> images;
354 appendImagesFromStyle(images, newStyle);
355 if (images.isEmpty())
356 resourceLoadPriorityOptimizer()->removeRenderObject(this);
esprehn 2014/01/15 01:27:45 This isn't good, you're going to hit the hash tabl
shatch 2014/01/15 19:28:52 Done.
357 else
358 resourceLoadPriorityOptimizer()->addRenderObject(this);
329 } 359 }
330 360
331 RenderBlock* RenderBlock::continuationBefore(RenderObject* beforeChild) 361 RenderBlock* RenderBlock::continuationBefore(RenderObject* beforeChild)
332 { 362 {
333 if (beforeChild && beforeChild->parent() == this) 363 if (beforeChild && beforeChild->parent() == this)
334 return this; 364 return this;
335 365
336 RenderBlock* curr = toRenderBlock(continuation()); 366 RenderBlock* curr = toRenderBlock(continuation());
337 RenderBlock* nextToLast = this; 367 RenderBlock* nextToLast = this;
338 RenderBlock* last = this; 368 RenderBlock* last = this;
(...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 return; 1289 return;
1260 1290
1261 // It's safe to check for control clip here, since controls can never be tab le cells. 1291 // It's safe to check for control clip here, since controls can never be tab le cells.
1262 // If we have a lightweight clip, there can never be any overflow from child ren. 1292 // If we have a lightweight clip, there can never be any overflow from child ren.
1263 if (hasControlClip() && m_overflow) 1293 if (hasControlClip() && m_overflow)
1264 clearLayoutOverflow(); 1294 clearLayoutOverflow();
1265 1295
1266 invalidateBackgroundObscurationStatus(); 1296 invalidateBackgroundObscurationStatus();
1267 } 1297 }
1268 1298
1269 void RenderBlock::didLayout(ResourceLoadPriorityOptimizer& optimizer) 1299 bool RenderBlock::updateImageLoadingPriorities()
1270 { 1300 {
1271 RenderBox::didLayout(optimizer);
1272 updateStyleImageLoadingPriorities(optimizer);
1273 }
1274
1275 void RenderBlock::didScroll(ResourceLoadPriorityOptimizer& optimizer)
1276 {
1277 RenderBox::didScroll(optimizer);
1278 updateStyleImageLoadingPriorities(optimizer);
1279 }
1280
1281 void RenderBlock::updateStyleImageLoadingPriorities(ResourceLoadPriorityOptimize r& optimizer)
1282 {
1283 RenderStyle* blockStyle = style();
1284 if (!blockStyle)
1285 return;
1286
1287 Vector<ImageResource*> images; 1301 Vector<ImageResource*> images;
1288 1302 appendImagesFromStyle(images, style());
1289 appendLayers(images, blockStyle->backgroundLayers());
1290 appendLayers(images, blockStyle->maskLayers());
1291
1292 const ContentData* contentData = blockStyle->contentData();
1293 if (contentData && contentData->isImage()) {
1294 const ImageContentData* imageContentData = static_cast<const ImageConten tData*>(contentData);
1295 appendImageIfNotNull(images, imageContentData->image());
1296 }
1297 if (blockStyle->boxReflect())
1298 appendImageIfNotNull(images, blockStyle->boxReflect()->mask().image());
1299 appendImageIfNotNull(images, blockStyle->listStyleImage());
1300 appendImageIfNotNull(images, blockStyle->borderImageSource());
1301 appendImageIfNotNull(images, blockStyle->maskBoxImageSource());
1302 1303
1303 if (images.isEmpty()) 1304 if (images.isEmpty())
1304 return; 1305 return false;
1305 1306
1306 LayoutRect viewBounds = viewRect(); 1307 LayoutRect viewBounds = viewRect();
1307 LayoutRect objectBounds = absoluteContentBox(); 1308 LayoutRect objectBounds = absoluteContentBox();
1308 // The object bounds might be empty right now, so intersects will fail since it doesn't deal 1309 // The object bounds might be empty right now, so intersects will fail since it doesn't deal
1309 // with empty rects. Use LayoutRect::contains in that case. 1310 // with empty rects. Use LayoutRect::contains in that case.
1310 bool isVisible; 1311 bool isVisible;
1311 if (!objectBounds.isEmpty()) 1312 if (!objectBounds.isEmpty())
1312 isVisible = viewBounds.intersects(objectBounds); 1313 isVisible = viewBounds.intersects(objectBounds);
1313 else 1314 else
1314 isVisible = viewBounds.contains(objectBounds); 1315 isVisible = viewBounds.contains(objectBounds);
1315 1316
1316 ResourceLoadPriorityOptimizer::VisibilityStatus status = isVisible ? 1317 ResourceLoadPriorityOptimizer::VisibilityStatus status = isVisible ?
1317 ResourceLoadPriorityOptimizer::Visible : ResourceLoadPriorityOptimizer:: NotVisible; 1318 ResourceLoadPriorityOptimizer::Visible : ResourceLoadPriorityOptimizer:: NotVisible;
1318 1319
1319 for (Vector<ImageResource*>::iterator it = images.begin(), end = images.end( ); it != end; ++it) 1320 for (Vector<ImageResource*>::iterator it = images.begin(), end = images.end( ); it != end; ++it)
1320 optimizer.notifyImageResourceVisibility(*it, status); 1321 resourceLoadPriorityOptimizer()->notifyImageResourceVisibility(*it, stat us);
1322
1323 return true;
1321 } 1324 }
1322 1325
1323 void RenderBlock::relayoutShapeDescendantIfMoved(RenderBlock* child, LayoutSize offset) 1326 void RenderBlock::relayoutShapeDescendantIfMoved(RenderBlock* child, LayoutSize offset)
1324 { 1327 {
1325 LayoutUnit left = isHorizontalWritingMode() ? offset.width() : offset.height (); 1328 LayoutUnit left = isHorizontalWritingMode() ? offset.width() : offset.height ();
1326 if (!left || !child || child->shapeInsideInfo() || !layoutShapeInsideInfo()) 1329 if (!left || !child || child->shapeInsideInfo() || !layoutShapeInsideInfo())
1327 return; 1330 return;
1328 // Propagate layout markers only up to the child, as we are still in the mid dle 1331 // Propagate layout markers only up to the child, as we are still in the mid dle
1329 // of a layout pass 1332 // of a layout pass
1330 child->setNormalChildNeedsLayout(true); 1333 child->setNormalChildNeedsLayout(true);
(...skipping 4339 matching lines...) Expand 10 before | Expand all | Expand 10 after
5670 void RenderBlock::showLineTreeAndMark(const InlineBox* markedBox1, const char* m arkedLabel1, const InlineBox* markedBox2, const char* markedLabel2, const Render Object* obj) const 5673 void RenderBlock::showLineTreeAndMark(const InlineBox* markedBox1, const char* m arkedLabel1, const InlineBox* markedBox2, const char* markedLabel2, const Render Object* obj) const
5671 { 5674 {
5672 showRenderObject(); 5675 showRenderObject();
5673 for (const RootInlineBox* root = firstRootBox(); root; root = root->nextRoot Box()) 5676 for (const RootInlineBox* root = firstRootBox(); root; root = root->nextRoot Box())
5674 root->showLineTreeAndMark(markedBox1, markedLabel1, markedBox2, markedLa bel2, obj, 1); 5677 root->showLineTreeAndMark(markedBox1, markedLabel1, markedBox2, markedLa bel2, obj, 1);
5675 } 5678 }
5676 5679
5677 #endif 5680 #endif
5678 5681
5679 } // namespace WebCore 5682 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698