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

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: Fixup. 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..efd9f4de3810f43dacf8f36355d3b7e15b7d6d9a 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"
@@ -1252,6 +1255,82 @@ 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;
+
+ for (const FillLayer* layer = blockStyle->backgroundLayers(); layer; layer = layer->next()) {
eseidel 2013/12/09 23:57:39 These two loops look identical. Helper function?
shatch 2013/12/10 01:41:28 Done.
+ if (layer->image()) {
+ ImageResource* img = layer->image()->cachedImage();
+ if (img) {
+ images.append(img);
+ }
+ }
+ }
+ for (const FillLayer* layer = blockStyle->maskLayers(); layer; layer = layer->next()) {
+ if (layer->image()) {
+ ImageResource* imageResource = layer->image()->cachedImage();
+ if (imageResource) {
+ images.append(imageResource);
+ }
+ }
+ }
+ ContentData* contentData = const_cast<ContentData*>(blockStyle->contentData());
+ if (contentData && contentData->isImage()) {
+ ImageContentData* imageContentData = static_cast<ImageContentData*>(contentData);
+ if (imageContentData->image() && imageContentData->image()->cachedImage())
+ images.append(imageContentData->image()->cachedImage());
+ }
+ if (blockStyle->boxReflect()) {
+ if (blockStyle->boxReflect()->mask().image()) {
+ if (blockStyle->boxReflect()->mask().image()->cachedImage()) {
+ images.append(blockStyle->boxReflect()->mask().image()->cachedImage());
+ }
+ }
+ }
+ if (blockStyle->listStyleImage() && blockStyle->listStyleImage()->cachedImage())
+ images.append(blockStyle->listStyleImage()->cachedImage());
+ if (blockStyle->borderImageSource() && blockStyle->borderImageSource()->cachedImage())
+ images.append(blockStyle->borderImageSource()->cachedImage());
+ if (blockStyle->maskBoxImageSource() && blockStyle->maskBoxImageSource()->cachedImage())
eseidel 2013/12/09 23:57:39 I might have used a helper here too: appendIfNotN
shatch 2013/12/10 01:41:28 Done.
+ images.append(blockStyle->maskBoxImageSource()->cachedImage());
+
+ 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.
eseidel 2013/12/09 23:57:39 What does contains do with an empty rect? Are you
shatch 2013/12/10 01:41:28 Yeah, it's pretty much just checking if the point
+ 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