| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/renderer_host/backing_store.h" | 5 #include "chrome/browser/renderer_host/backing_store.h" |
| 6 | 6 |
| 7 #include "base/sys_info.h" |
| 7 #include "chrome/browser/renderer_host/render_widget_host.h" | 8 #include "chrome/browser/renderer_host/render_widget_host.h" |
| 9 #include "chrome/common/chrome_constants.h" |
| 8 | 10 |
| 9 namespace { | 11 namespace { |
| 10 | 12 |
| 11 typedef OwningMRUCache<RenderWidgetHost*, BackingStore*> BackingStoreCache; | 13 typedef OwningMRUCache<RenderWidgetHost*, BackingStore*> BackingStoreCache; |
| 12 static BackingStoreCache* cache = NULL; | 14 static BackingStoreCache* cache = NULL; |
| 13 | 15 |
| 14 // Returns the size of the backing store cache. | 16 // Returns the size of the backing store cache. |
| 15 // TODO(iyengar) Make this dynamic, i.e. based on the available resources | |
| 16 // on the machine. | |
| 17 static int GetBackingStoreCacheSize() { | 17 static int GetBackingStoreCacheSize() { |
| 18 const int kMaxSize = 5; | 18 // This uses a similar approach to GetMaxRendererProcessCount. The goal |
| 19 return kMaxSize; | 19 // is to reduce memory pressure and swapping on low-resource machines. |
| 20 static const int kMaxDibCountByRamTier[] = { |
| 21 2, // less than 256MB |
| 22 3, // 256MB |
| 23 4, // 512MB |
| 24 5 // 768MB and above |
| 25 }; |
| 26 |
| 27 static int max_size = kMaxDibCountByRamTier[ |
| 28 std::min(base::SysInfo::AmountOfPhysicalMemoryMB() / 256, |
| 29 static_cast<int>(arraysize(kMaxDibCountByRamTier)) - 1)]; |
| 30 return max_size; |
| 20 } | 31 } |
| 21 | 32 |
| 22 // Creates the backing store for the host based on the dimensions passed in. | 33 // Creates the backing store for the host based on the dimensions passed in. |
| 23 // Removes the existing backing store if there is one. | 34 // Removes the existing backing store if there is one. |
| 24 BackingStore* CreateBackingStore(RenderWidgetHost* host, | 35 BackingStore* CreateBackingStore(RenderWidgetHost* host, |
| 25 const gfx::Size& backing_store_size) { | 36 const gfx::Size& backing_store_size) { |
| 26 BackingStoreManager::RemoveBackingStore(host); | 37 BackingStoreManager::RemoveBackingStore(host); |
| 27 | 38 |
| 28 BackingStore* backing_store = host->AllocBackingStore(backing_store_size); | 39 BackingStore* backing_store = host->AllocBackingStore(backing_store_size); |
| 29 int backing_store_cache_size = GetBackingStoreCacheSize(); | 40 int backing_store_cache_size = GetBackingStoreCacheSize(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 if (it == cache->end()) | 110 if (it == cache->end()) |
| 100 return; | 111 return; |
| 101 | 112 |
| 102 cache->Erase(it); | 113 cache->Erase(it); |
| 103 | 114 |
| 104 if (cache->empty()) { | 115 if (cache->empty()) { |
| 105 delete cache; | 116 delete cache; |
| 106 cache = NULL; | 117 cache = NULL; |
| 107 } | 118 } |
| 108 } | 119 } |
| OLD | NEW |