OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "android_webview/browser/browser_view_renderer.h" | 5 #include "android_webview/browser/browser_view_renderer.h" |
6 | 6 |
7 #include "android_webview/browser/browser_view_renderer_client.h" | 7 #include "android_webview/browser/browser_view_renderer_client.h" |
8 #include "android_webview/browser/shared_renderer_state.h" | 8 #include "android_webview/browser/shared_renderer_state.h" |
9 #include "android_webview/common/aw_switches.h" | 9 #include "android_webview/common/aw_switches.h" |
10 #include "android_webview/public/browser/draw_gl.h" | 10 #include "android_webview/public/browser/draw_gl.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 // Currently the logic in this class relies on |compositor_| remaining | 144 // Currently the logic in this class relies on |compositor_| remaining |
145 // NULL until the DidInitializeCompositor() call, hence it is not set here. | 145 // NULL until the DidInitializeCompositor() call, hence it is not set here. |
146 } | 146 } |
147 | 147 |
148 BrowserViewRenderer::~BrowserViewRenderer() { | 148 BrowserViewRenderer::~BrowserViewRenderer() { |
149 content::SynchronousCompositor::SetClientForWebContents(web_contents_, NULL); | 149 content::SynchronousCompositor::SetClientForWebContents(web_contents_, NULL); |
150 // OnDetachedFromWindow should be called before the destructor, so the memory | 150 // OnDetachedFromWindow should be called before the destructor, so the memory |
151 // policy should have already been updated. | 151 // policy should have already been updated. |
152 } | 152 } |
153 | 153 |
154 // This function updates the cached memory policy in shared renderer state, as | 154 // This function updates the resource allocation in GlobalTileManager. |
155 // well as the tile resource allocation in GlobalTileManager. | |
156 void BrowserViewRenderer::TrimMemory(const int level, const bool visible) { | 155 void BrowserViewRenderer::TrimMemory(const int level, const bool visible) { |
157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
158 // Constants from Android ComponentCallbacks2. | 157 // Constants from Android ComponentCallbacks2. |
159 enum { | 158 enum { |
160 TRIM_MEMORY_RUNNING_LOW = 10, | 159 TRIM_MEMORY_RUNNING_LOW = 10, |
161 TRIM_MEMORY_UI_HIDDEN = 20, | 160 TRIM_MEMORY_UI_HIDDEN = 20, |
162 TRIM_MEMORY_BACKGROUND = 40, | 161 TRIM_MEMORY_BACKGROUND = 40, |
163 }; | 162 }; |
164 | 163 |
165 // Not urgent enough. TRIM_MEMORY_UI_HIDDEN is treated specially because | 164 // Not urgent enough. TRIM_MEMORY_UI_HIDDEN is treated specially because |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 num_bytes_ = new_policy.bytes_limit; | 212 num_bytes_ = new_policy.bytes_limit; |
214 | 213 |
215 GlobalTileManager* manager = GlobalTileManager::GetInstance(); | 214 GlobalTileManager* manager = GlobalTileManager::GetInstance(); |
216 | 215 |
217 // The following line will call BrowserViewRenderer::SetTilesNum(). | 216 // The following line will call BrowserViewRenderer::SetTilesNum(). |
218 manager->RequestTiles(new_policy.num_resources_limit, tile_manager_key_); | 217 manager->RequestTiles(new_policy.num_resources_limit, tile_manager_key_); |
219 } | 218 } |
220 | 219 |
221 void BrowserViewRenderer::SetNumTiles(size_t num_tiles, | 220 void BrowserViewRenderer::SetNumTiles(size_t num_tiles, |
222 bool effective_immediately) { | 221 bool effective_immediately) { |
223 if (num_tiles == num_tiles_) | |
224 return; | |
225 num_tiles_ = num_tiles; | 222 num_tiles_ = num_tiles; |
226 | 223 |
227 memory_policy_.num_resources_limit = num_tiles_; | 224 memory_policy_.num_resources_limit = num_tiles_; |
228 memory_policy_.bytes_limit = num_bytes_; | 225 memory_policy_.bytes_limit = num_bytes_; |
229 | 226 |
230 if (effective_immediately) | 227 if (effective_immediately) |
231 EnforceMemoryPolicyImmediately(memory_policy_); | 228 EnforceMemoryPolicyImmediately(memory_policy_); |
232 } | 229 } |
233 | 230 |
234 void BrowserViewRenderer::EnforceMemoryPolicyImmediately( | 231 void BrowserViewRenderer::EnforceMemoryPolicyImmediately( |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 base::StringAppendF(&str, | 812 base::StringAppendF(&str, |
816 "surface width height: [%d %d] ", | 813 "surface width height: [%d %d] ", |
817 draw_info->width, | 814 draw_info->width, |
818 draw_info->height); | 815 draw_info->height); |
819 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); | 816 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); |
820 } | 817 } |
821 return str; | 818 return str; |
822 } | 819 } |
823 | 820 |
824 } // namespace android_webview | 821 } // namespace android_webview |
OLD | NEW |