| 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 class RenderWidgetHost; | 7 #include "chrome/browser/renderer_host/render_widget_host.h" |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 | 10 |
| 11 typedef OwningMRUCache<RenderWidgetHost*, BackingStore*> BackingStoreCache; | 11 typedef OwningMRUCache<RenderWidgetHost*, BackingStore*> BackingStoreCache; |
| 12 static BackingStoreCache* cache = NULL; | 12 static BackingStoreCache* cache = NULL; |
| 13 | 13 |
| 14 // 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 | 15 // TODO(iyengar) Make this dynamic, i.e. based on the available resources |
| 16 // on the machine. | 16 // on the machine. |
| 17 static int GetBackingStoreCacheSize() { | 17 static int GetBackingStoreCacheSize() { |
| 18 const int kMaxSize = 5; | 18 const int kMaxSize = 5; |
| 19 return kMaxSize; | 19 return kMaxSize; |
| 20 } | 20 } |
| 21 | 21 |
| 22 // 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. |
| 23 // Removes the existing backing store if there is one. | 23 // Removes the existing backing store if there is one. |
| 24 BackingStore* CreateBackingStore(RenderWidgetHost* host, | 24 BackingStore* CreateBackingStore(RenderWidgetHost* host, |
| 25 const gfx::Rect& backing_store_rect) { | 25 const gfx::Size& backing_store_size) { |
| 26 BackingStoreManager::RemoveBackingStore(host); | 26 BackingStoreManager::RemoveBackingStore(host); |
| 27 | 27 |
| 28 BackingStore* backing_store = new BackingStore(backing_store_rect.size()); | 28 BackingStore* backing_store = host->AllocBackingStore(backing_store_size); |
| 29 int backing_store_cache_size = GetBackingStoreCacheSize(); | 29 int backing_store_cache_size = GetBackingStoreCacheSize(); |
| 30 if (backing_store_cache_size > 0) { | 30 if (backing_store_cache_size > 0) { |
| 31 if (!cache) | 31 if (!cache) |
| 32 cache = new BackingStoreCache(backing_store_cache_size); | 32 cache = new BackingStoreCache(backing_store_cache_size); |
| 33 cache->Put(host, backing_store); | 33 cache->Put(host, backing_store); |
| 34 } | 34 } |
| 35 return backing_store; | 35 return backing_store; |
| 36 } | 36 } |
| 37 | 37 |
| 38 } // namespace | 38 } // namespace |
| (...skipping 12 matching lines...) Expand all Loading... |
| 51 return backing_store; | 51 return backing_store; |
| 52 backing_store = NULL; | 52 backing_store = NULL; |
| 53 } | 53 } |
| 54 | 54 |
| 55 return backing_store; | 55 return backing_store; |
| 56 } | 56 } |
| 57 | 57 |
| 58 // static | 58 // static |
| 59 BackingStore* BackingStoreManager::PrepareBackingStore( | 59 BackingStore* BackingStoreManager::PrepareBackingStore( |
| 60 RenderWidgetHost* host, | 60 RenderWidgetHost* host, |
| 61 const gfx::Rect& backing_store_rect, | 61 const gfx::Size& backing_store_size, |
| 62 base::ProcessHandle process_handle, | 62 base::ProcessHandle process_handle, |
| 63 TransportDIB* bitmap, | 63 TransportDIB* bitmap, |
| 64 const gfx::Rect& bitmap_rect, | 64 const gfx::Rect& bitmap_rect, |
| 65 bool* needs_full_paint) { | 65 bool* needs_full_paint) { |
| 66 BackingStore* backing_store = GetBackingStore(host, | 66 BackingStore* backing_store = GetBackingStore(host, backing_store_size); |
| 67 backing_store_rect.size()); | |
| 68 if (!backing_store) { | 67 if (!backing_store) { |
| 69 // We need to get Webkit to generate a new paint here, as we | 68 // We need to get Webkit to generate a new paint here, as we |
| 70 // don't have a previous snapshot. | 69 // don't have a previous snapshot. |
| 71 if (bitmap_rect != backing_store_rect) { | 70 if (bitmap_rect.size() != backing_store_size || |
| 71 bitmap_rect.x() != 0 || bitmap_rect.y() != 0) { |
| 72 DCHECK(needs_full_paint != NULL); | 72 DCHECK(needs_full_paint != NULL); |
| 73 *needs_full_paint = true; | 73 *needs_full_paint = true; |
| 74 } | 74 } |
| 75 backing_store = CreateBackingStore(host, backing_store_rect); | 75 backing_store = CreateBackingStore(host, backing_store_size); |
| 76 } | 76 } |
| 77 | 77 |
| 78 DCHECK(backing_store != NULL); | 78 DCHECK(backing_store != NULL); |
| 79 backing_store->PaintRect(process_handle, bitmap, bitmap_rect); | 79 backing_store->PaintRect(process_handle, bitmap, bitmap_rect); |
| 80 return backing_store; | 80 return backing_store; |
| 81 } | 81 } |
| 82 | 82 |
| 83 // static | 83 // static |
| 84 BackingStore* BackingStoreManager::Lookup(RenderWidgetHost* host) { | 84 BackingStore* BackingStoreManager::Lookup(RenderWidgetHost* host) { |
| 85 if (cache) { | 85 if (cache) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 99 if (it == cache->end()) | 99 if (it == cache->end()) |
| 100 return; | 100 return; |
| 101 | 101 |
| 102 cache->Erase(it); | 102 cache->Erase(it); |
| 103 | 103 |
| 104 if (cache->empty()) { | 104 if (cache->empty()) { |
| 105 delete cache; | 105 delete cache; |
| 106 cache = NULL; | 106 cache = NULL; |
| 107 } | 107 } |
| 108 } | 108 } |
| OLD | NEW |