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

Side by Side Diff: Source/core/fetch/ResourceLoadPriorityOptimizer.cpp

Issue 131233003: Refactor ResourceLoadPriorityOptimizer to avoid walking render tree (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Changes from review. 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) 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 12 matching lines...) Expand all
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/fetch/ResourceLoadPriorityOptimizer.h" 32 #include "core/fetch/ResourceLoadPriorityOptimizer.h"
33 #include "core/rendering/RenderObject.h"
34
35 #include "wtf/Vector.h"
33 36
34 namespace WebCore { 37 namespace WebCore {
35 38
39 ResourceLoadPriorityOptimizer* ResourceLoadPriorityOptimizer::resourceLoadPriori tyOptimizer()
40 {
41 DEFINE_STATIC_LOCAL(ResourceLoadPriorityOptimizer, s_renderLoadOptimizer, () );
42 return &s_renderLoadOptimizer;
43 }
44
36 ResourceLoadPriorityOptimizer::ResourceAndVisibility::ResourceAndVisibility(Imag eResource* image, VisibilityStatus v) 45 ResourceLoadPriorityOptimizer::ResourceAndVisibility::ResourceAndVisibility(Imag eResource* image, VisibilityStatus v)
37 : imageResource(image) 46 : imageResource(image)
38 , status(v) 47 , status(v)
39 { 48 {
40 } 49 }
41 50
42 ResourceLoadPriorityOptimizer::ResourceAndVisibility::~ResourceAndVisibility() 51 ResourceLoadPriorityOptimizer::ResourceAndVisibility::~ResourceAndVisibility()
43 { 52 {
44 } 53 }
45 54
46 ResourceLoadPriorityOptimizer::ResourceLoadPriorityOptimizer() 55 ResourceLoadPriorityOptimizer::ResourceLoadPriorityOptimizer()
47 { 56 {
48 } 57 }
49 58
50 ResourceLoadPriorityOptimizer::~ResourceLoadPriorityOptimizer() 59 ResourceLoadPriorityOptimizer::~ResourceLoadPriorityOptimizer()
51 { 60 {
61 }
62
63 void ResourceLoadPriorityOptimizer::addRenderObject(RenderObject* renderer)
64 {
65 m_objects.add(renderer);
66 renderer->setHasPendingResourceUpdate(true);
67 }
68
69 void ResourceLoadPriorityOptimizer::removeRenderObject(RenderObject* renderer)
70 {
71 if (!renderer->hasPendingResourceUpdate())
72 return;
73 m_objects.remove(renderer);
74 renderer->setHasPendingResourceUpdate(false);
75 }
76
77 void ResourceLoadPriorityOptimizer::updateAllImageResourcePriorities()
78 {
79 m_imageResources.clear();
80
81 Vector<RenderObject*> objectsToRemove;
82 for (RenderObjectSet::iterator it = m_objects.begin(); it != m_objects.end() ; ++it) {
83 RenderObject* obj = *it;
84 if (!obj->updateImageLoadingPriorities()) {
85 objectsToRemove.append(obj);
86 }
87 }
88
89 for (Vector<RenderObject*>::iterator it = objectsToRemove.begin(); it != obj ectsToRemove.end(); ++it)
90 m_objects.remove(*it);
91
52 updateImageResourcesWithLoadPriority(); 92 updateImageResourcesWithLoadPriority();
53 } 93 }
54 94
55 void ResourceLoadPriorityOptimizer::updateImageResourcesWithLoadPriority() 95 void ResourceLoadPriorityOptimizer::updateImageResourcesWithLoadPriority()
56 { 96 {
57 for (ImageResourceMap::iterator it = m_imageResources.begin(); it != m_image Resources.end(); ++it) { 97 for (ImageResourceMap::iterator it = m_imageResources.begin(); it != m_image Resources.end(); ++it) {
58 ResourceLoadPriority priority = it->value->status == Visible ? 98 ResourceLoadPriority priority = it->value->status == Visible ?
59 ResourceLoadPriorityLow : ResourceLoadPriorityVeryLow; 99 ResourceLoadPriorityLow : ResourceLoadPriorityVeryLow;
60 100
61 if (priority != it->value->imageResource->resourceRequest().priority()) { 101 if (priority != it->value->imageResource->resourceRequest().priority()) {
62 it->value->imageResource->resourceRequest().setPriority(priority); 102 it->value->imageResource->resourceRequest().setPriority(priority);
63 it->value->imageResource->didChangePriority(priority); 103 it->value->imageResource->didChangePriority(priority);
64 } 104 }
65 } 105 }
66 m_imageResources.clear(); 106 m_imageResources.clear();
67 } 107 }
68 108
69 void ResourceLoadPriorityOptimizer::notifyImageResourceVisibility(ImageResource* img, VisibilityStatus status) 109 void ResourceLoadPriorityOptimizer::notifyImageResourceVisibility(ImageResource* img, VisibilityStatus status)
70 { 110 {
71 if (!img || img->isLoaded()) 111 if (!img || img->isLoaded())
72 return; 112 return;
73 113
74 ImageResourceMap::AddResult result = m_imageResources.add(img->identifier(), adoptPtr(new ResourceAndVisibility(img, status))); 114 ImageResourceMap::AddResult result = m_imageResources.add(img->identifier(), adoptPtr(new ResourceAndVisibility(img, status)));
75 if (!result.isNewEntry && status == Visible) 115 if (!result.isNewEntry && status == Visible)
76 result.iterator->value->status = status; 116 result.iterator->value->status = status;
77 } 117 }
78 118
79 } 119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698