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/rendering/RenderObject.h" |
| 34 |
| 35 #include "wtf/Vector.h" |
33 | 36 |
34 namespace WebCore { | 37 namespace WebCore { |
35 | 38 |
| 39 ResourceLoadPriorityOptimizer* ResourceLoadPriorityOptimizer::resourceLoadPriori
tyOptimizer() |
| 40 { |
| 41 DEFINE_STATIC_LOCAL(ResourceLoadPriorityOptimizer, s_renderLoadOptimizer, ()
); |
| 42 return &s_renderLoadOptimizer; |
| 43 } |
| 44 |
36 ResourceLoadPriorityOptimizer::ResourceAndVisibility::ResourceAndVisibility(Imag
eResource* image, VisibilityStatus v) | 45 ResourceLoadPriorityOptimizer::ResourceAndVisibility::ResourceAndVisibility(Imag
eResource* image, VisibilityStatus v) |
37 : imageResource(image) | 46 : imageResource(image) |
38 , status(v) | 47 , status(v) |
39 { | 48 { |
40 } | 49 } |
41 | 50 |
42 ResourceLoadPriorityOptimizer::ResourceAndVisibility::~ResourceAndVisibility() | 51 ResourceLoadPriorityOptimizer::ResourceAndVisibility::~ResourceAndVisibility() |
43 { | 52 { |
44 } | 53 } |
45 | 54 |
46 ResourceLoadPriorityOptimizer::ResourceLoadPriorityOptimizer() | 55 ResourceLoadPriorityOptimizer::ResourceLoadPriorityOptimizer() |
47 { | 56 { |
48 } | 57 } |
49 | 58 |
50 ResourceLoadPriorityOptimizer::~ResourceLoadPriorityOptimizer() | 59 ResourceLoadPriorityOptimizer::~ResourceLoadPriorityOptimizer() |
51 { | 60 { |
| 61 } |
| 62 |
| 63 void ResourceLoadPriorityOptimizer::addRenderObject(RenderObject* renderer) |
| 64 { |
| 65 m_objects.add(renderer); |
| 66 renderer->setHasPendingResourceUpdate(true); |
| 67 } |
| 68 |
| 69 void ResourceLoadPriorityOptimizer::removeRenderObject(RenderObject* renderer) |
| 70 { |
| 71 if (!renderer->hasPendingResourceUpdate()) |
| 72 return; |
| 73 m_objects.remove(renderer); |
| 74 renderer->setHasPendingResourceUpdate(false); |
| 75 } |
| 76 |
| 77 void ResourceLoadPriorityOptimizer::updateAllImageResourcePriorities() |
| 78 { |
| 79 m_imageResources.clear(); |
| 80 |
| 81 Vector<RenderObject*> objectsToRemove; |
| 82 for (RenderObjectSet::iterator it = m_objects.begin(); it != m_objects.end()
; ++it) { |
| 83 RenderObject* obj = *it; |
| 84 if (!obj->updateImageLoadingPriorities()) { |
| 85 objectsToRemove.append(obj); |
| 86 } |
| 87 } |
| 88 |
| 89 for (Vector<RenderObject*>::iterator it = objectsToRemove.begin(); it != obj
ectsToRemove.end(); ++it) |
| 90 m_objects.remove(*it); |
| 91 |
52 updateImageResourcesWithLoadPriority(); | 92 updateImageResourcesWithLoadPriority(); |
53 } | 93 } |
54 | 94 |
55 void ResourceLoadPriorityOptimizer::updateImageResourcesWithLoadPriority() | 95 void ResourceLoadPriorityOptimizer::updateImageResourcesWithLoadPriority() |
56 { | 96 { |
57 for (ImageResourceMap::iterator it = m_imageResources.begin(); it != m_image
Resources.end(); ++it) { | 97 for (ImageResourceMap::iterator it = m_imageResources.begin(); it != m_image
Resources.end(); ++it) { |
58 ResourceLoadPriority priority = it->value->status == Visible ? | 98 ResourceLoadPriority priority = it->value->status == Visible ? |
59 ResourceLoadPriorityLow : ResourceLoadPriorityVeryLow; | 99 ResourceLoadPriorityLow : ResourceLoadPriorityVeryLow; |
60 | 100 |
61 if (priority != it->value->imageResource->resourceRequest().priority())
{ | 101 if (priority != it->value->imageResource->resourceRequest().priority())
{ |
62 it->value->imageResource->resourceRequest().setPriority(priority); | 102 it->value->imageResource->resourceRequest().setPriority(priority); |
63 it->value->imageResource->didChangePriority(priority); | 103 it->value->imageResource->didChangePriority(priority); |
64 } | 104 } |
65 } | 105 } |
66 m_imageResources.clear(); | 106 m_imageResources.clear(); |
67 } | 107 } |
68 | 108 |
69 void ResourceLoadPriorityOptimizer::notifyImageResourceVisibility(ImageResource*
img, VisibilityStatus status) | 109 void ResourceLoadPriorityOptimizer::notifyImageResourceVisibility(ImageResource*
img, VisibilityStatus status) |
70 { | 110 { |
71 if (!img || img->isLoaded()) | 111 if (!img || img->isLoaded()) |
72 return; | 112 return; |
73 | 113 |
74 ImageResourceMap::AddResult result = m_imageResources.add(img->identifier(),
adoptPtr(new ResourceAndVisibility(img, status))); | 114 ImageResourceMap::AddResult result = m_imageResources.add(img->identifier(),
adoptPtr(new ResourceAndVisibility(img, status))); |
75 if (!result.isNewEntry && status == Visible) | 115 if (!result.isNewEntry && status == Visible) |
76 result.iterator->value->status = status; | 116 result.iterator->value->status = status; |
77 } | 117 } |
78 | 118 |
79 } | 119 } |
OLD | NEW |