| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/renderer_host/backing_store_manager.h" | 5 #include "content/browser/renderer_host/backing_store_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/mru_cache.h" | 9 #include "base/memory/mru_cache.h" |
| 10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
| 11 #include "content/browser/renderer_host/backing_store.h" | 11 #include "content/browser/renderer_host/backing_store.h" |
| 12 #include "content/browser/renderer_host/render_widget_host_impl.h" | 12 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 13 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
| 14 | 14 |
| 15 using content::RenderWidgetHost; | 15 namespace content { |
| 16 | |
| 17 namespace { | 16 namespace { |
| 18 | 17 |
| 19 // There are two separate caches, |large_cache| and |small_cache|. large_cache | 18 // There are two separate caches, |large_cache| and |small_cache|. large_cache |
| 20 // is meant for large items (tabs, popup windows), while small_cache is meant | 19 // is meant for large items (tabs, popup windows), while small_cache is meant |
| 21 // for small items (extension popups, HTML5 notifications). The idea is that | 20 // for small items (extension popups, HTML5 notifications). The idea is that |
| 22 // we'll almost always try to evict from large_cache first since small_cache | 21 // we'll almost always try to evict from large_cache first since small_cache |
| 23 // items will tend to be visible more of the time. | 22 // items will tend to be visible more of the time. |
| 24 typedef base::OwningMRUCache<RenderWidgetHost*, BackingStore*> | 23 typedef base::OwningMRUCache<RenderWidgetHost*, BackingStore*> |
| 25 BackingStoreCache; | 24 BackingStoreCache; |
| 26 static BackingStoreCache* large_cache = NULL; | 25 BackingStoreCache* large_cache = NULL; |
| 27 static BackingStoreCache* small_cache = NULL; | 26 BackingStoreCache* small_cache = NULL; |
| 28 | 27 |
| 29 // Threshold is based on a single large-monitor-width toolstrip. | 28 // Threshold is based on a single large-monitor-width toolstrip. |
| 30 // (32bpp, 32 pixels high, 1920 pixels wide) | 29 // (32bpp, 32 pixels high, 1920 pixels wide) |
| 31 // TODO(aa): The extension system no longer supports toolstrips, but we think | 30 // TODO(aa): The extension system no longer supports toolstrips, but we think |
| 32 // this might be helping for other examples of small HTML views in Chrome. | 31 // this might be helping for other examples of small HTML views in Chrome. |
| 33 // Maybe this cache should be redesigned to simply prefer smaller objects to | 32 // Maybe this cache should be redesigned to simply prefer smaller objects to |
| 34 // larger ones, rather than having a fixed threshold. | 33 // larger ones, rather than having a fixed threshold. |
| 35 // For more background, see: crbug.com/100506. | 34 // For more background, see: crbug.com/100506. |
| 36 const size_t kSmallThreshold = 4 * 32 * 1920; | 35 const size_t kSmallThreshold = 4 * 32 * 1920; |
| 37 | 36 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 // Limit the number of large backing stores (tabs) to the memory tier number | 139 // Limit the number of large backing stores (tabs) to the memory tier number |
| 141 // (between 2-5). While we allow a larger amount of memory for people who | 140 // (between 2-5). While we allow a larger amount of memory for people who |
| 142 // have large windows, this means that those who use small browser windows | 141 // have large windows, this means that those who use small browser windows |
| 143 // won't ever cache more than 5 tabs, so they pay a smaller memory cost. | 142 // won't ever cache more than 5 tabs, so they pay a smaller memory cost. |
| 144 if (large_cache->size() >= MaxNumberOfBackingStores()) | 143 if (large_cache->size() >= MaxNumberOfBackingStores()) |
| 145 ExpireLastBackingStore(large_cache); | 144 ExpireLastBackingStore(large_cache); |
| 146 cache = large_cache; | 145 cache = large_cache; |
| 147 } else { | 146 } else { |
| 148 cache = small_cache; | 147 cache = small_cache; |
| 149 } | 148 } |
| 150 BackingStore* backing_store = content::RenderWidgetHostImpl::From( | 149 BackingStore* backing_store = RenderWidgetHostImpl::From( |
| 151 host)->AllocBackingStore(backing_store_size); | 150 host)->AllocBackingStore(backing_store_size); |
| 152 if (backing_store) | 151 if (backing_store) |
| 153 cache->Put(host, backing_store); | 152 cache->Put(host, backing_store); |
| 154 return backing_store; | 153 return backing_store; |
| 155 } | 154 } |
| 156 | 155 |
| 157 int ComputeTotalArea(const std::vector<gfx::Rect>& rects) { | 156 int ComputeTotalArea(const std::vector<gfx::Rect>& rects) { |
| 158 // We assume that the given rects are non-overlapping, which is a property of | 157 // We assume that the given rects are non-overlapping, which is a property of |
| 159 // the paint rects generated by the PaintAggregator. | 158 // the paint rects generated by the PaintAggregator. |
| 160 #ifndef NDEBUG | 159 #ifndef NDEBUG |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 size_t mem = 0; | 271 size_t mem = 0; |
| 273 BackingStoreCache::iterator it; | 272 BackingStoreCache::iterator it; |
| 274 for (it = large_cache->begin(); it != large_cache->end(); ++it) | 273 for (it = large_cache->begin(); it != large_cache->end(); ++it) |
| 275 mem += it->second->MemorySize(); | 274 mem += it->second->MemorySize(); |
| 276 | 275 |
| 277 for (it = small_cache->begin(); it != small_cache->end(); ++it) | 276 for (it = small_cache->begin(); it != small_cache->end(); ++it) |
| 278 mem += it->second->MemorySize(); | 277 mem += it->second->MemorySize(); |
| 279 | 278 |
| 280 return mem; | 279 return mem; |
| 281 } | 280 } |
| 281 |
| 282 } // namespace content |
| OLD | NEW |