OLD | NEW |
---|---|
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 Loading... | |
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/frame/Settings.h" | |
33 #include "core/layout/LayoutObject.h" | 34 #include "core/layout/LayoutObject.h" |
34 #include "platform/TraceEvent.h" | 35 #include "platform/TraceEvent.h" |
35 | 36 |
36 #include "wtf/Vector.h" | 37 #include "wtf/Vector.h" |
37 | 38 |
38 namespace blink { | 39 namespace blink { |
39 | 40 |
40 ResourceLoadPriorityOptimizer* ResourceLoadPriorityOptimizer::resourceLoadPriori tyOptimizer() | 41 ResourceLoadPriorityOptimizer* ResourceLoadPriorityOptimizer::resourceLoadPriori tyOptimizer() |
41 { | 42 { |
42 DEFINE_STATIC_LOCAL(ResourceLoadPriorityOptimizer, s_renderLoadOptimizer, () ); | 43 DEFINE_STATIC_LOCAL(ResourceLoadPriorityOptimizer, s_renderLoadOptimizer, () ); |
43 return &s_renderLoadOptimizer; | 44 return &s_renderLoadOptimizer; |
44 } | 45 } |
45 | 46 |
46 ResourceLoadPriorityOptimizer::ResourceAndVisibility::ResourceAndVisibility(Imag eResource* image, VisibilityStatus visibilityStatus, uint32_t screenArea) | 47 ResourceLoadPriorityOptimizer::ResourceAndVisibility::ResourceAndVisibility(Imag eResource* image, VisibilityStatus visibilityStatus, uint32_t screenArea) |
47 : imageResource(image) | 48 : imageResource(image) |
48 , status(visibilityStatus) | 49 , status(visibilityStatus) |
49 , screenArea(screenArea) | 50 , screenArea(screenArea) |
50 { | 51 { |
51 } | 52 } |
52 | 53 |
53 ResourceLoadPriorityOptimizer::ResourceAndVisibility::~ResourceAndVisibility() | 54 ResourceLoadPriorityOptimizer::ResourceAndVisibility::~ResourceAndVisibility() |
54 { | 55 { |
55 } | 56 } |
56 | 57 |
57 ResourceLoadPriorityOptimizer::ResourceLoadPriorityOptimizer() | 58 ResourceLoadPriorityOptimizer::ResourceLoadPriorityOptimizer() |
59 : m_retrievedSettings(false) | |
60 , m_increaseFetchPriorities(false) | |
58 { | 61 { |
59 } | 62 } |
60 | 63 |
61 ResourceLoadPriorityOptimizer::~ResourceLoadPriorityOptimizer() | 64 ResourceLoadPriorityOptimizer::~ResourceLoadPriorityOptimizer() |
62 { | 65 { |
63 } | 66 } |
64 | 67 |
65 void ResourceLoadPriorityOptimizer::addLayoutObject(LayoutObject* layoutObject) | 68 void ResourceLoadPriorityOptimizer::addLayoutObject(LayoutObject* layoutObject) |
66 { | 69 { |
70 if (!m_retrievedSettings) { | |
71 m_increaseFetchPriorities = layoutObject->document().settings()->fetchIn creasePriorities(); | |
72 m_retrievedSettings = true; | |
73 } | |
67 m_objects.add(layoutObject); | 74 m_objects.add(layoutObject); |
68 layoutObject->setHasPendingResourceUpdate(true); | 75 layoutObject->setHasPendingResourceUpdate(true); |
69 } | 76 } |
70 | 77 |
71 void ResourceLoadPriorityOptimizer::removeLayoutObject(LayoutObject* layoutObjec t) | 78 void ResourceLoadPriorityOptimizer::removeLayoutObject(LayoutObject* layoutObjec t) |
72 { | 79 { |
73 if (!layoutObject->hasPendingResourceUpdate()) | 80 if (!layoutObject->hasPendingResourceUpdate()) |
74 return; | 81 return; |
75 m_objects.remove(layoutObject); | 82 m_objects.remove(layoutObject); |
76 layoutObject->setHasPendingResourceUpdate(false); | 83 layoutObject->setHasPendingResourceUpdate(false); |
(...skipping 14 matching lines...) Expand all Loading... | |
91 | 98 |
92 updateImageResourcesWithLoadPriority(); | 99 updateImageResourcesWithLoadPriority(); |
93 } | 100 } |
94 | 101 |
95 void ResourceLoadPriorityOptimizer::updateImageResourcesWithLoadPriority() | 102 void ResourceLoadPriorityOptimizer::updateImageResourcesWithLoadPriority() |
96 { | 103 { |
97 for (const auto& resource : m_imageResources) { | 104 for (const auto& resource : m_imageResources) { |
98 ResourceLoadPriority priority = resource.value->status == Visible ? | 105 ResourceLoadPriority priority = resource.value->status == Visible ? |
99 ResourceLoadPriorityLow : ResourceLoadPriorityVeryLow; | 106 ResourceLoadPriorityLow : ResourceLoadPriorityVeryLow; |
100 | 107 |
108 ASSERT(m_retrievedSettings); | |
Bryan McQuade
2015/08/11 13:05:12
I think this assert is important given that we dep
Pat Meenan
2015/08/11 14:18:40
I'm not sure the ASSERT is even needed. updateIma
| |
109 if (m_increaseFetchPriorities) { | |
110 priority = resource.value->status == Visible ? | |
111 ResourceLoadPriorityHigh : ResourceLoadPriorityLow; | |
112 } | |
113 | |
101 if (priority != resource.value->imageResource->resourceRequest().priorit y()) { | 114 if (priority != resource.value->imageResource->resourceRequest().priorit y()) { |
102 resource.value->imageResource->mutableResourceRequest().setPriority( priority, resource.value->screenArea); | 115 resource.value->imageResource->mutableResourceRequest().setPriority( priority, resource.value->screenArea); |
103 resource.value->imageResource->didChangePriority(priority, resource. value->screenArea); | 116 resource.value->imageResource->didChangePriority(priority, resource. value->screenArea); |
104 } | 117 } |
105 } | 118 } |
106 m_imageResources.clear(); | 119 m_imageResources.clear(); |
107 } | 120 } |
108 | 121 |
109 void ResourceLoadPriorityOptimizer::notifyImageResourceVisibility(ImageResource* img, VisibilityStatus status, const LayoutRect& screenRect) | 122 void ResourceLoadPriorityOptimizer::notifyImageResourceVisibility(ImageResource* img, VisibilityStatus status, const LayoutRect& screenRect) |
110 { | 123 { |
111 if (!img || img->isLoaded()) | 124 if (!img || img->isLoaded()) |
112 return; | 125 return; |
113 | 126 |
114 int screenArea = 0; | 127 int screenArea = 0; |
115 if (!screenRect.isEmpty() && status == Visible) | 128 if (!screenRect.isEmpty() && status == Visible) |
116 screenArea += static_cast<uint32_t>(screenRect.width() * screenRect.heig ht()); | 129 screenArea += static_cast<uint32_t>(screenRect.width() * screenRect.heig ht()); |
117 | 130 |
118 ImageResourceMap::AddResult result = m_imageResources.add(img->identifier(), adoptPtr(new ResourceAndVisibility(img, status, screenArea))); | 131 ImageResourceMap::AddResult result = m_imageResources.add(img->identifier(), adoptPtr(new ResourceAndVisibility(img, status, screenArea))); |
119 if (!result.isNewEntry && status == Visible) { | 132 if (!result.isNewEntry && status == Visible) { |
120 result.storedValue->value->status = Visible; | 133 result.storedValue->value->status = Visible; |
121 result.storedValue->value->screenArea += screenArea; | 134 result.storedValue->value->screenArea += screenArea; |
122 } | 135 } |
123 } | 136 } |
124 | 137 |
125 } | 138 } |
OLD | NEW |