| 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 |
| 34 #include "core/fetch/ResourceLoader.h" |
| 33 #include "core/layout/LayoutObject.h" | 35 #include "core/layout/LayoutObject.h" |
| 34 #include "platform/TraceEvent.h" | 36 #include "platform/TraceEvent.h" |
| 35 | 37 |
| 36 #include "wtf/Vector.h" | 38 #include "wtf/Vector.h" |
| 37 | 39 |
| 38 namespace blink { | 40 namespace blink { |
| 39 | 41 |
| 40 ResourceLoadPriorityOptimizer* ResourceLoadPriorityOptimizer::resourceLoadPriori
tyOptimizer() | 42 ResourceLoadPriorityOptimizer* ResourceLoadPriorityOptimizer::resourceLoadPriori
tyOptimizer() |
| 41 { | 43 { |
| 42 DEFINE_STATIC_LOCAL(ResourceLoadPriorityOptimizer, s_renderLoadOptimizer, ()
); | 44 DEFINE_STATIC_LOCAL(ResourceLoadPriorityOptimizer, s_renderLoadOptimizer, ()
); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 93 |
| 92 updateImageResourcesWithLoadPriority(); | 94 updateImageResourcesWithLoadPriority(); |
| 93 } | 95 } |
| 94 | 96 |
| 95 void ResourceLoadPriorityOptimizer::updateImageResourcesWithLoadPriority() | 97 void ResourceLoadPriorityOptimizer::updateImageResourcesWithLoadPriority() |
| 96 { | 98 { |
| 97 for (const auto& resource : m_imageResources) { | 99 for (const auto& resource : m_imageResources) { |
| 98 ResourceLoadPriority priority = resource.value->status == Visible ? | 100 ResourceLoadPriority priority = resource.value->status == Visible ? |
| 99 ResourceLoadPriorityLow : ResourceLoadPriorityVeryLow; | 101 ResourceLoadPriorityLow : ResourceLoadPriorityVeryLow; |
| 100 | 102 |
| 103 if (resource.value->imageResource->loader() && resource.value->imageReso
urce->loader()->shouldUseIncreasedPriorities()) { |
| 104 priority = resource.value->status == Visible ? |
| 105 ResourceLoadPriorityHigh : ResourceLoadPriorityLow; |
| 106 } |
| 107 |
| 101 if (priority != resource.value->imageResource->resourceRequest().priorit
y()) { | 108 if (priority != resource.value->imageResource->resourceRequest().priorit
y()) { |
| 102 resource.value->imageResource->mutableResourceRequest().setPriority(
priority, resource.value->screenArea); | 109 resource.value->imageResource->mutableResourceRequest().setPriority(
priority, resource.value->screenArea); |
| 103 resource.value->imageResource->didChangePriority(priority, resource.
value->screenArea); | 110 resource.value->imageResource->didChangePriority(priority, resource.
value->screenArea); |
| 104 } | 111 } |
| 105 } | 112 } |
| 106 m_imageResources.clear(); | 113 m_imageResources.clear(); |
| 107 } | 114 } |
| 108 | 115 |
| 109 void ResourceLoadPriorityOptimizer::notifyImageResourceVisibility(ImageResource*
img, VisibilityStatus status, const LayoutRect& screenRect) | 116 void ResourceLoadPriorityOptimizer::notifyImageResourceVisibility(ImageResource*
img, VisibilityStatus status, const LayoutRect& screenRect) |
| 110 { | 117 { |
| 111 if (!img || img->isLoaded()) | 118 if (!img || img->isLoaded()) |
| 112 return; | 119 return; |
| 113 | 120 |
| 114 int screenArea = 0; | 121 int screenArea = 0; |
| 115 if (!screenRect.isEmpty() && status == Visible) | 122 if (!screenRect.isEmpty() && status == Visible) |
| 116 screenArea += static_cast<uint32_t>(screenRect.width() * screenRect.heig
ht()); | 123 screenArea += static_cast<uint32_t>(screenRect.width() * screenRect.heig
ht()); |
| 117 | 124 |
| 118 ImageResourceMap::AddResult result = m_imageResources.add(img->identifier(),
adoptPtr(new ResourceAndVisibility(img, status, screenArea))); | 125 ImageResourceMap::AddResult result = m_imageResources.add(img->identifier(),
adoptPtr(new ResourceAndVisibility(img, status, screenArea))); |
| 119 if (!result.isNewEntry && status == Visible) { | 126 if (!result.isNewEntry && status == Visible) { |
| 120 result.storedValue->value->status = Visible; | 127 result.storedValue->value->status = Visible; |
| 121 result.storedValue->value->screenArea += screenArea; | 128 result.storedValue->value->screenArea += screenArea; |
| 122 } | 129 } |
| 123 } | 130 } |
| 124 | 131 |
| 125 } | 132 } |
| OLD | NEW |