| 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 // The list of image resources is populated by the layout objects in |
| 72 // updateAllImageResourcePriorities so it is safe to only check the |
| 73 // setting when the first layout object is added. It is impossible to |
| 74 // have images to update without having first populated at least one |
| 75 // layout object. |
| 76 m_increaseFetchPriorities = layoutObject->document().settings()->fetchIn
creasePriorities(); |
| 77 m_retrievedSettings = true; |
| 78 } |
| 67 m_objects.add(layoutObject); | 79 m_objects.add(layoutObject); |
| 68 layoutObject->setHasPendingResourceUpdate(true); | 80 layoutObject->setHasPendingResourceUpdate(true); |
| 69 } | 81 } |
| 70 | 82 |
| 71 void ResourceLoadPriorityOptimizer::removeLayoutObject(LayoutObject* layoutObjec
t) | 83 void ResourceLoadPriorityOptimizer::removeLayoutObject(LayoutObject* layoutObjec
t) |
| 72 { | 84 { |
| 73 if (!layoutObject->hasPendingResourceUpdate()) | 85 if (!layoutObject->hasPendingResourceUpdate()) |
| 74 return; | 86 return; |
| 75 m_objects.remove(layoutObject); | 87 m_objects.remove(layoutObject); |
| 76 layoutObject->setHasPendingResourceUpdate(false); | 88 layoutObject->setHasPendingResourceUpdate(false); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 91 | 103 |
| 92 updateImageResourcesWithLoadPriority(); | 104 updateImageResourcesWithLoadPriority(); |
| 93 } | 105 } |
| 94 | 106 |
| 95 void ResourceLoadPriorityOptimizer::updateImageResourcesWithLoadPriority() | 107 void ResourceLoadPriorityOptimizer::updateImageResourcesWithLoadPriority() |
| 96 { | 108 { |
| 97 for (const auto& resource : m_imageResources) { | 109 for (const auto& resource : m_imageResources) { |
| 98 ResourceLoadPriority priority = resource.value->status == Visible ? | 110 ResourceLoadPriority priority = resource.value->status == Visible ? |
| 99 ResourceLoadPriorityLow : ResourceLoadPriorityVeryLow; | 111 ResourceLoadPriorityLow : ResourceLoadPriorityVeryLow; |
| 100 | 112 |
| 113 if (m_increaseFetchPriorities) { |
| 114 priority = resource.value->status == Visible ? |
| 115 ResourceLoadPriorityHigh : ResourceLoadPriorityLow; |
| 116 } |
| 117 |
| 101 if (priority != resource.value->imageResource->resourceRequest().priorit
y()) { | 118 if (priority != resource.value->imageResource->resourceRequest().priorit
y()) { |
| 102 resource.value->imageResource->mutableResourceRequest().setPriority(
priority, resource.value->screenArea); | 119 resource.value->imageResource->mutableResourceRequest().setPriority(
priority, resource.value->screenArea); |
| 103 resource.value->imageResource->didChangePriority(priority, resource.
value->screenArea); | 120 resource.value->imageResource->didChangePriority(priority, resource.
value->screenArea); |
| 104 } | 121 } |
| 105 } | 122 } |
| 106 m_imageResources.clear(); | 123 m_imageResources.clear(); |
| 107 } | 124 } |
| 108 | 125 |
| 109 void ResourceLoadPriorityOptimizer::notifyImageResourceVisibility(ImageResource*
img, VisibilityStatus status, const LayoutRect& screenRect) | 126 void ResourceLoadPriorityOptimizer::notifyImageResourceVisibility(ImageResource*
img, VisibilityStatus status, const LayoutRect& screenRect) |
| 110 { | 127 { |
| 111 if (!img || img->isLoaded()) | 128 if (!img || img->isLoaded()) |
| 112 return; | 129 return; |
| 113 | 130 |
| 114 int screenArea = 0; | 131 int screenArea = 0; |
| 115 if (!screenRect.isEmpty() && status == Visible) | 132 if (!screenRect.isEmpty() && status == Visible) |
| 116 screenArea += static_cast<uint32_t>(screenRect.width() * screenRect.heig
ht()); | 133 screenArea += static_cast<uint32_t>(screenRect.width() * screenRect.heig
ht()); |
| 117 | 134 |
| 118 ImageResourceMap::AddResult result = m_imageResources.add(img->identifier(),
adoptPtr(new ResourceAndVisibility(img, status, screenArea))); | 135 ImageResourceMap::AddResult result = m_imageResources.add(img->identifier(),
adoptPtr(new ResourceAndVisibility(img, status, screenArea))); |
| 119 if (!result.isNewEntry && status == Visible) { | 136 if (!result.isNewEntry && status == Visible) { |
| 120 result.storedValue->value->status = Visible; | 137 result.storedValue->value->status = Visible; |
| 121 result.storedValue->value->screenArea += screenArea; | 138 result.storedValue->value->screenArea += screenArea; |
| 122 } | 139 } |
| 123 } | 140 } |
| 124 | 141 |
| 125 } | 142 } |
| OLD | NEW |