Chromium Code Reviews| 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()) { |
|
Mike West
2014/10/17 10:38:49
Nit: Drop the {} for one-liners.
riju_
2014/10/17 18:36:48
Done.
| |
| 88 if (!obj->updateImageLoadingPriorities()) { | 88 objectsToRemove.append(renderObject); |
| 89 objectsToRemove.append(obj); | |
| 90 } | 89 } |
| 91 } | 90 } |
| 92 m_objects.removeAll(objectsToRemove); | 91 m_objects.removeAll(objectsToRemove); |
| 93 | 92 |
| 94 updateImageResourcesWithLoadPriority(); | 93 updateImageResourcesWithLoadPriority(); |
| 95 } | 94 } |
| 96 | 95 |
| 97 void ResourceLoadPriorityOptimizer::updateImageResourcesWithLoadPriority() | 96 void ResourceLoadPriorityOptimizer::updateImageResourcesWithLoadPriority() |
| 98 { | 97 { |
| 99 for (ImageResourceMap::iterator it = m_imageResources.begin(); it != m_image Resources.end(); ++it) { | 98 for (const auto& resource : m_imageResources) { |
| 100 ResourceLoadPriority priority = it->value->status == Visible ? | 99 ResourceLoadPriority priority = resource.value->status == Visible ? |
| 101 ResourceLoadPriorityLow : ResourceLoadPriorityVeryLow; | 100 ResourceLoadPriorityLow : ResourceLoadPriorityVeryLow; |
| 102 | 101 |
| 103 if (priority != it->value->imageResource->resourceRequest().priority()) { | 102 if (priority != resource.value->imageResource->resourceRequest().priorit y()) { |
| 104 it->value->imageResource->mutableResourceRequest().setPriority(prior ity, it->value->screenArea); | 103 resource.value->imageResource->mutableResourceRequest().setPriority( priority, resource.value->screenArea); |
| 105 it->value->imageResource->didChangePriority(priority, it->value->scr eenArea); | 104 resource.value->imageResource->didChangePriority(priority, resource. value->screenArea); |
| 106 } | 105 } |
| 107 } | 106 } |
| 108 m_imageResources.clear(); | 107 m_imageResources.clear(); |
| 109 } | 108 } |
| 110 | 109 |
| 111 void ResourceLoadPriorityOptimizer::notifyImageResourceVisibility(ImageResource* img, VisibilityStatus status, const LayoutRect& screenRect) | 110 void ResourceLoadPriorityOptimizer::notifyImageResourceVisibility(ImageResource* img, VisibilityStatus status, const LayoutRect& screenRect) |
| 112 { | 111 { |
| 113 if (!img || img->isLoaded()) | 112 if (!img || img->isLoaded()) |
| 114 return; | 113 return; |
| 115 | 114 |
| 116 int screenArea = 0; | 115 int screenArea = 0; |
| 117 if (!screenRect.isEmpty() && status == Visible) | 116 if (!screenRect.isEmpty() && status == Visible) |
| 118 screenArea += static_cast<uint32_t>(screenRect.width() * screenRect.heig ht()); | 117 screenArea += static_cast<uint32_t>(screenRect.width() * screenRect.heig ht()); |
| 119 | 118 |
| 120 ImageResourceMap::AddResult result = m_imageResources.add(img->identifier(), adoptPtr(new ResourceAndVisibility(img, status, screenArea))); | 119 ImageResourceMap::AddResult result = m_imageResources.add(img->identifier(), adoptPtr(new ResourceAndVisibility(img, status, screenArea))); |
| 121 if (!result.isNewEntry && status == Visible) { | 120 if (!result.isNewEntry && status == Visible) { |
| 122 result.storedValue->value->status = Visible; | 121 result.storedValue->value->status = Visible; |
| 123 result.storedValue->value->screenArea += screenArea; | 122 result.storedValue->value->screenArea += screenArea; |
| 124 } | 123 } |
| 125 } | 124 } |
| 126 | 125 |
| 127 } | 126 } |
| OLD | NEW |