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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « Source/core/fetch/ResourceLoadPriorityOptimizer.h ('k') | Source/core/frame/FrameView.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 11 matching lines...) Expand all
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "core/rendering/SubtreeLayoutScope.h" 32 #include "core/fetch/ResourceLoadPriorityOptimizer.h"
33
34 #include "core/frame/FrameView.h"
35 #include "core/rendering/RenderObject.h"
36 33
37 namespace WebCore { 34 namespace WebCore {
38 35
39 SubtreeLayoutScope::SubtreeLayoutScope(RenderObject* root) 36 ResourceLoadPriorityOptimizer::ResourceAndVisibility::ResourceAndVisibility(Imag eResource* image, VisibilityStatus v)
40 : m_root(root) 37 : imageResource(image)
38 , status(v)
41 { 39 {
42 RELEASE_ASSERT(m_root->document().view()->isInLayout());
43 } 40 }
44 41
45 SubtreeLayoutScope::~SubtreeLayoutScope() 42 ResourceLoadPriorityOptimizer::ResourceAndVisibility::~ResourceAndVisibility()
46 { 43 {
47 // Partial layout early-exits layout and will leave the tree as needing layo ut.
48 if (m_root->frameView()->partialLayout().isStopping()) {
49 ASSERT(m_root->needsLayout());
50 return;
51 }
52
53 RELEASE_ASSERT(!m_root->needsLayout());
54
55 #ifndef NDEBUG
56 for (HashSet<RenderObject*>::iterator it = m_renderersToLayout.begin(); it ! = m_renderersToLayout.end(); ++it)
57 (*it)->assertRendererLaidOut();
58 #endif
59 } 44 }
60 45
61 void SubtreeLayoutScope::setNeedsLayout(RenderObject* descendant) 46 ResourceLoadPriorityOptimizer::ResourceLoadPriorityOptimizer()
62 { 47 {
63 ASSERT(descendant->isDescendantOf(m_root));
64 descendant->setNeedsLayout(MarkContainingBlockChain, this);
65 } 48 }
66 49
67 void SubtreeLayoutScope::setChildNeedsLayout(RenderObject* descendant) 50 ResourceLoadPriorityOptimizer::~ResourceLoadPriorityOptimizer()
68 { 51 {
69 ASSERT(descendant->isDescendantOf(m_root)); 52 updateImageResourcesWithLoadPriority();
70 descendant->setChildNeedsLayout(MarkContainingBlockChain, this);
71 } 53 }
72 54
73 void SubtreeLayoutScope::addRendererToLayout(RenderObject* renderer) 55 void ResourceLoadPriorityOptimizer::updateImageResourcesWithLoadPriority()
74 { 56 {
75 #ifndef NDEBUG 57 for (ImageResourceMap::iterator it = m_imageResources.begin(); it != m_image Resources.end(); ++it) {
76 m_renderersToLayout.add(renderer); 58 ResourceLoadPriority priority = it->value->status == Visible ?
77 #endif 59 ResourceLoadPriorityLow : ResourceLoadPriorityVeryLow;
60
61 if (priority != it->value->imageResource->resourceRequest().priority()) {
62 it->value->imageResource->resourceRequest().setPriority(priority);
63 it->value->imageResource->didChangePriority(priority);
64 }
65 }
66 m_imageResources.clear();
67 }
68
69 void ResourceLoadPriorityOptimizer::notifyImageResourceVisibility(ImageResource* img, VisibilityStatus status)
70 {
71 if (!img || img->isLoaded())
72 return;
73
74 ImageResourceMap::AddResult result = m_imageResources.add(img->identifier(), adoptPtr(new ResourceAndVisibility(img, status)));
75 if (!result.isNewEntry && status == Visible)
76 result.iterator->value->status = status;
78 } 77 }
79 78
80 } 79 }
OLDNEW
« 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