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

Unified Diff: Source/core/rendering/RenderBlock.cpp

Issue 109153003: Raise the loading priority of in-viewport images. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Changes from review. Created 7 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/rendering/RenderBlock.h ('k') | Source/core/rendering/RenderImage.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/rendering/RenderBlock.cpp
diff --git a/Source/core/rendering/RenderBlock.cpp b/Source/core/rendering/RenderBlock.cpp
index 5f0eb9c7f4b07ca76caf9e01d55a68562f1ef96b..17b01671130324d95200dc9288aba0cf605ab528 100644
--- a/Source/core/rendering/RenderBlock.cpp
+++ b/Source/core/rendering/RenderBlock.cpp
@@ -32,6 +32,7 @@
#include "core/dom/shadow/ShadowRoot.h"
#include "core/editing/Editor.h"
#include "core/editing/FrameSelection.h"
+#include "core/fetch/ResourceLoadPriorityOptimizer.h"
#include "core/frame/Frame.h"
#include "core/frame/FrameView.h"
#include "core/page/Page.h"
@@ -58,6 +59,8 @@
#include "core/rendering/RenderTheme.h"
#include "core/rendering/RenderView.h"
#include "core/rendering/shapes/ShapeOutsideInfo.h"
+#include "core/rendering/style/ContentData.h"
+#include "core/rendering/style/RenderStyle.h"
#include "platform/geometry/FloatQuad.h"
#include "platform/geometry/TransformState.h"
#include "platform/graphics/GraphicsContextStateSaver.h"
@@ -169,6 +172,19 @@ static void removeBlockFromDescendantAndContainerMaps(RenderBlock* block, Tracke
}
}
+static void appendImageIfNotNull(Vector<ImageResource*>& imageResources, const StyleImage* styleImage)
+{
+ if (styleImage && styleImage->cachedImage())
+ imageResources.append(styleImage->cachedImage());
+}
+
+static void appendLayers(Vector<ImageResource*>& images, const FillLayer* styleLayer)
+{
+ for (const FillLayer* layer = styleLayer; layer; layer = layer->next()) {
+ appendImageIfNotNull(images, layer->image());
+ }
+}
+
RenderBlock::~RenderBlock()
{
if (hasColumns())
@@ -1252,6 +1268,60 @@ void RenderBlock::layout()
invalidateBackgroundObscurationStatus();
}
+void RenderBlock::didLayout(ResourceLoadPriorityOptimizer& optimizer)
+{
+ RenderBox::didLayout(optimizer);
+ updateStyleImageLoadingPriorities(optimizer);
+}
+
+void RenderBlock::didScroll(ResourceLoadPriorityOptimizer& optimizer)
+{
+ RenderBox::didScroll(optimizer);
+ updateStyleImageLoadingPriorities(optimizer);
+}
+
+void RenderBlock::updateStyleImageLoadingPriorities(ResourceLoadPriorityOptimizer& optimizer)
+{
+ RenderStyle* blockStyle = style();
+ if (!blockStyle)
+ return;
+
+ Vector<ImageResource*> images;
+
+ appendLayers(images, blockStyle->backgroundLayers());
+ appendLayers(images, blockStyle->maskLayers());
+
+ const ContentData* contentData = blockStyle->contentData();
+ if (contentData && contentData->isImage()) {
+ const ImageContentData* imageContentData = static_cast<const ImageContentData*>(contentData);
+ appendImageIfNotNull(images, imageContentData->image());
+ }
+ if (blockStyle->boxReflect())
+ appendImageIfNotNull(images, blockStyle->boxReflect()->mask().image());
+ appendImageIfNotNull(images, blockStyle->listStyleImage());
+ appendImageIfNotNull(images, blockStyle->borderImageSource());
+ appendImageIfNotNull(images, blockStyle->maskBoxImageSource());
+
+ if (images.isEmpty())
+ return;
+
+ LayoutRect viewBounds = viewRect();
+ LayoutRect objectBounds = absoluteContentBox();
+ // The object bounds might be empty right now, so intersects will fail since it doesn't deal
+ // with empty rects. Use LayoutRect::contains in that case.
+ bool isVisible;
+ if (!objectBounds.isEmpty())
+ isVisible = viewBounds.intersects(objectBounds);
+ else
+ isVisible = viewBounds.contains(objectBounds);
+
+ ResourceLoadPriorityOptimizer::VisibilityStatus status = isVisible ?
+ ResourceLoadPriorityOptimizer::Visible : ResourceLoadPriorityOptimizer::NotVisible;
+
+ for (Vector<ImageResource*>::iterator it = images.begin(), end = images.end(); it != end; ++it)
+ optimizer.notifyImageResourceVisibility(*it, status);
+}
+
void RenderBlock::relayoutShapeDescendantIfMoved(RenderBlock* child, LayoutSize offset)
{
LayoutUnit left = isHorizontalWritingMode() ? offset.width() : offset.height();
« no previous file with comments | « Source/core/rendering/RenderBlock.h ('k') | Source/core/rendering/RenderImage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698