| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 renderer->setHasPendingResourceUpdate(false); | 76 renderer->setHasPendingResourceUpdate(false); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void ResourceLoadPriorityOptimizer::updateAllImageResourcePriorities() | 79 void ResourceLoadPriorityOptimizer::updateAllImageResourcePriorities() |
| 80 { | 80 { |
| 81 TRACE_EVENT0("blink", "ResourceLoadPriorityOptimizer::updateAllImageResource
Priorities"); | 81 TRACE_EVENT0("blink", "ResourceLoadPriorityOptimizer::updateAllImageResource
Priorities"); |
| 82 | 82 |
| 83 m_imageResources.clear(); | 83 m_imageResources.clear(); |
| 84 | 84 |
| 85 Vector<RenderObject*> objectsToRemove; | 85 Vector<RenderObject*> objectsToRemove; |
| 86 for (RenderObjectSet::iterator it = m_objects.begin(); it != m_objects.end()
; ++it) { | 86 for (const auto& renderObject : m_objects) { |
| 87 RenderObject* obj = *it; | 87 if (!renderObject->updateImageLoadingPriorities()) |
| 88 if (!obj->updateImageLoadingPriorities()) { | 88 objectsToRemove.append(renderObject); |
| 89 objectsToRemove.append(obj); | |
| 90 } | |
| 91 } | 89 } |
| 92 m_objects.removeAll(objectsToRemove); | 90 m_objects.removeAll(objectsToRemove); |
| 93 | 91 |
| 94 updateImageResourcesWithLoadPriority(); | 92 updateImageResourcesWithLoadPriority(); |
| 95 } | 93 } |
| 96 | 94 |
| 97 void ResourceLoadPriorityOptimizer::updateImageResourcesWithLoadPriority() | 95 void ResourceLoadPriorityOptimizer::updateImageResourcesWithLoadPriority() |
| 98 { | 96 { |
| 99 for (ImageResourceMap::iterator it = m_imageResources.begin(); it != m_image
Resources.end(); ++it) { | 97 for (const auto& resource : m_imageResources) { |
| 100 ResourceLoadPriority priority = it->value->status == Visible ? | 98 ResourceLoadPriority priority = resource.value->status == Visible ? |
| 101 ResourceLoadPriorityLow : ResourceLoadPriorityVeryLow; | 99 ResourceLoadPriorityLow : ResourceLoadPriorityVeryLow; |
| 102 | 100 |
| 103 if (priority != it->value->imageResource->resourceRequest().priority())
{ | 101 if (priority != resource.value->imageResource->resourceRequest().priorit
y()) { |
| 104 it->value->imageResource->mutableResourceRequest().setPriority(prior
ity, it->value->screenArea); | 102 resource.value->imageResource->mutableResourceRequest().setPriority(
priority, resource.value->screenArea); |
| 105 it->value->imageResource->didChangePriority(priority, it->value->scr
eenArea); | 103 resource.value->imageResource->didChangePriority(priority, resource.
value->screenArea); |
| 106 } | 104 } |
| 107 } | 105 } |
| 108 m_imageResources.clear(); | 106 m_imageResources.clear(); |
| 109 } | 107 } |
| 110 | 108 |
| 111 void ResourceLoadPriorityOptimizer::notifyImageResourceVisibility(ImageResource*
img, VisibilityStatus status, const LayoutRect& screenRect) | 109 void ResourceLoadPriorityOptimizer::notifyImageResourceVisibility(ImageResource*
img, VisibilityStatus status, const LayoutRect& screenRect) |
| 112 { | 110 { |
| 113 if (!img || img->isLoaded()) | 111 if (!img || img->isLoaded()) |
| 114 return; | 112 return; |
| 115 | 113 |
| 116 int screenArea = 0; | 114 int screenArea = 0; |
| 117 if (!screenRect.isEmpty() && status == Visible) | 115 if (!screenRect.isEmpty() && status == Visible) |
| 118 screenArea += static_cast<uint32_t>(screenRect.width() * screenRect.heig
ht()); | 116 screenArea += static_cast<uint32_t>(screenRect.width() * screenRect.heig
ht()); |
| 119 | 117 |
| 120 ImageResourceMap::AddResult result = m_imageResources.add(img->identifier(),
adoptPtr(new ResourceAndVisibility(img, status, screenArea))); | 118 ImageResourceMap::AddResult result = m_imageResources.add(img->identifier(),
adoptPtr(new ResourceAndVisibility(img, status, screenArea))); |
| 121 if (!result.isNewEntry && status == Visible) { | 119 if (!result.isNewEntry && status == Visible) { |
| 122 result.storedValue->value->status = Visible; | 120 result.storedValue->value->status = Visible; |
| 123 result.storedValue->value->screenArea += screenArea; | 121 result.storedValue->value->screenArea += screenArea; |
| 124 } | 122 } |
| 125 } | 123 } |
| 126 | 124 |
| 127 } | 125 } |
| OLD | NEW |