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

Unified Diff: Source/core/fetch/ResourceLoadPriorityOptimizer.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/fetch/ResourceLoadPriorityOptimizer.h ('k') | Source/core/frame/FrameView.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/fetch/ResourceLoadPriorityOptimizer.cpp
diff --git a/Source/core/rendering/SubtreeLayoutScope.cpp b/Source/core/fetch/ResourceLoadPriorityOptimizer.cpp
similarity index 53%
copy from Source/core/rendering/SubtreeLayoutScope.cpp
copy to Source/core/fetch/ResourceLoadPriorityOptimizer.cpp
index d650513a1c89e451b77d327e77d8809077432bf9..29882526a7c3c9c29648936219152a8f0d5d5aef 100644
--- a/Source/core/rendering/SubtreeLayoutScope.cpp
+++ b/Source/core/fetch/ResourceLoadPriorityOptimizer.cpp
@@ -29,52 +29,51 @@
*/
#include "config.h"
-#include "core/rendering/SubtreeLayoutScope.h"
-
-#include "core/frame/FrameView.h"
-#include "core/rendering/RenderObject.h"
+#include "core/fetch/ResourceLoadPriorityOptimizer.h"
namespace WebCore {
-SubtreeLayoutScope::SubtreeLayoutScope(RenderObject* root)
- : m_root(root)
+ResourceLoadPriorityOptimizer::ResourceAndVisibility::ResourceAndVisibility(ImageResource* image, VisibilityStatus v)
+ : imageResource(image)
+ , status(v)
{
- RELEASE_ASSERT(m_root->document().view()->isInLayout());
}
-SubtreeLayoutScope::~SubtreeLayoutScope()
+ResourceLoadPriorityOptimizer::ResourceAndVisibility::~ResourceAndVisibility()
{
- // Partial layout early-exits layout and will leave the tree as needing layout.
- if (m_root->frameView()->partialLayout().isStopping()) {
- ASSERT(m_root->needsLayout());
- return;
- }
-
- RELEASE_ASSERT(!m_root->needsLayout());
+}
-#ifndef NDEBUG
- for (HashSet<RenderObject*>::iterator it = m_renderersToLayout.begin(); it != m_renderersToLayout.end(); ++it)
- (*it)->assertRendererLaidOut();
-#endif
+ResourceLoadPriorityOptimizer::ResourceLoadPriorityOptimizer()
+{
}
-void SubtreeLayoutScope::setNeedsLayout(RenderObject* descendant)
+ResourceLoadPriorityOptimizer::~ResourceLoadPriorityOptimizer()
{
- ASSERT(descendant->isDescendantOf(m_root));
- descendant->setNeedsLayout(MarkContainingBlockChain, this);
+ updateImageResourcesWithLoadPriority();
}
-void SubtreeLayoutScope::setChildNeedsLayout(RenderObject* descendant)
+void ResourceLoadPriorityOptimizer::updateImageResourcesWithLoadPriority()
{
- ASSERT(descendant->isDescendantOf(m_root));
- descendant->setChildNeedsLayout(MarkContainingBlockChain, this);
+ for (ImageResourceMap::iterator it = m_imageResources.begin(); it != m_imageResources.end(); ++it) {
+ ResourceLoadPriority priority = it->value->status == Visible ?
+ ResourceLoadPriorityLow : ResourceLoadPriorityVeryLow;
+
+ if (priority != it->value->imageResource->resourceRequest().priority()) {
+ it->value->imageResource->resourceRequest().setPriority(priority);
+ it->value->imageResource->didChangePriority(priority);
+ }
+ }
+ m_imageResources.clear();
}
-void SubtreeLayoutScope::addRendererToLayout(RenderObject* renderer)
+void ResourceLoadPriorityOptimizer::notifyImageResourceVisibility(ImageResource* img, VisibilityStatus status)
{
-#ifndef NDEBUG
- m_renderersToLayout.add(renderer);
-#endif
+ if (!img || img->isLoaded())
+ return;
+
+ ImageResourceMap::AddResult result = m_imageResources.add(img->identifier(), adoptPtr(new ResourceAndVisibility(img, status)));
+ if (!result.isNewEntry && status == Visible)
+ result.iterator->value->status = status;
}
}
« no previous file with comments | « Source/core/fetch/ResourceLoadPriorityOptimizer.h ('k') | Source/core/frame/FrameView.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698