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