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/child_frame.h" | 8 #include "android_webview/browser/child_frame.h" |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 } | 111 } |
112 | 112 |
113 SharedRendererState* BrowserViewRenderer::GetAwDrawGLViewContext() { | 113 SharedRendererState* BrowserViewRenderer::GetAwDrawGLViewContext() { |
114 return &shared_renderer_state_; | 114 return &shared_renderer_state_; |
115 } | 115 } |
116 | 116 |
117 bool BrowserViewRenderer::RequestDrawGL(bool wait_for_completion) { | 117 bool BrowserViewRenderer::RequestDrawGL(bool wait_for_completion) { |
118 return client_->RequestDrawGL(wait_for_completion); | 118 return client_->RequestDrawGL(wait_for_completion); |
119 } | 119 } |
120 | 120 |
121 // This function updates the resource allocation in GlobalTileManager. | |
122 void BrowserViewRenderer::TrimMemory(const int level, const bool visible) { | 121 void BrowserViewRenderer::TrimMemory(const int level, const bool visible) { |
123 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 122 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
124 // Constants from Android ComponentCallbacks2. | 123 // Constants from Android ComponentCallbacks2. |
125 enum { | 124 enum { |
126 TRIM_MEMORY_RUNNING_LOW = 10, | 125 TRIM_MEMORY_RUNNING_LOW = 10, |
127 TRIM_MEMORY_UI_HIDDEN = 20, | 126 TRIM_MEMORY_UI_HIDDEN = 20, |
128 TRIM_MEMORY_BACKGROUND = 40, | 127 TRIM_MEMORY_BACKGROUND = 40, |
129 TRIM_MEMORY_MODERATE = 60, | 128 TRIM_MEMORY_MODERATE = 60, |
130 }; | 129 }; |
131 | 130 |
132 // Not urgent enough. TRIM_MEMORY_UI_HIDDEN is treated specially because | 131 // Not urgent enough. TRIM_MEMORY_UI_HIDDEN is treated specially because |
133 // it does not indicate memory pressure, but merely that the app is | 132 // it does not indicate memory pressure, but merely that the app is |
134 // backgrounded. | 133 // backgrounded. |
135 if (level < TRIM_MEMORY_RUNNING_LOW || level == TRIM_MEMORY_UI_HIDDEN) | 134 if (level < TRIM_MEMORY_RUNNING_LOW || level == TRIM_MEMORY_UI_HIDDEN) |
136 return; | 135 return; |
137 | 136 |
138 // Do not release resources on view we expect to get DrawGL soon. | 137 // Do not release resources on view we expect to get DrawGL soon. |
139 if (level < TRIM_MEMORY_BACKGROUND && visible) | 138 if (level < TRIM_MEMORY_BACKGROUND && visible) |
140 return; | 139 return; |
141 | 140 |
142 // Nothing to drop. | 141 // Nothing to drop. |
143 if (!compositor_ || !hardware_enabled_) | 142 if (!compositor_ || !hardware_enabled_) |
144 return; | 143 return; |
145 | 144 |
146 TRACE_EVENT0("android_webview", "BrowserViewRenderer::TrimMemory"); | 145 TRACE_EVENT0("android_webview", "BrowserViewRenderer::TrimMemory"); |
147 | 146 |
148 // Drop everything in hardware. | 147 // If offscreen pre-raster is disabled, drop everything in hardware. Otherwise |
148 // keep the tiles and just delete the HardwareRenderer. | |
149 if (level >= TRIM_MEMORY_MODERATE) { | 149 if (level >= TRIM_MEMORY_MODERATE) { |
150 shared_renderer_state_.ReleaseHardwareDrawIfNeededOnUI(); | 150 shared_renderer_state_.ReleaseHardwareDrawIfNeededOnUI(); |
151 return; | 151 return; |
152 } | 152 } |
153 | 153 |
154 // Just set the memory limit to 0 and drop all tiles. This will be reset to | 154 // Just set the memory limit to 0 and drop all tiles. This will be reset to |
155 // normal levels in the next DrawGL call. | 155 // normal levels in the next DrawGL call. |
156 compositor_->SetMemoryPolicy(0u); | 156 if (!offscreen_pre_raster_) |
157 ForceFakeCompositeSW(); | 157 compositor_->SetMemoryPolicy(0u); |
158 } | 158 } |
159 | 159 |
160 size_t BrowserViewRenderer::CalculateDesiredMemoryPolicy() { | 160 size_t BrowserViewRenderer::CalculateDesiredMemoryPolicy() { |
161 if (g_memory_override_in_bytes) | 161 if (g_memory_override_in_bytes) |
162 return static_cast<size_t>(g_memory_override_in_bytes); | 162 return static_cast<size_t>(g_memory_override_in_bytes); |
163 | 163 |
164 gfx::Rect interest_rect = offscreen_pre_raster_ | 164 gfx::Rect interest_rect = offscreen_pre_raster_ |
165 ? gfx::Rect(size_) | 165 ? gfx::Rect(size_) |
166 : last_on_draw_global_visible_rect_; | 166 : last_on_draw_global_visible_rect_; |
167 size_t width = interest_rect.width(); | 167 size_t width = interest_rect.width(); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 TRACE_EVENT_SCOPE_THREAD); | 330 TRACE_EVENT_SCOPE_THREAD); |
331 if (clear_view_) | 331 if (clear_view_) |
332 return; | 332 return; |
333 | 333 |
334 clear_view_ = true; | 334 clear_view_ = true; |
335 // Always invalidate ignoring the compositor to actually clear the webview. | 335 // Always invalidate ignoring the compositor to actually clear the webview. |
336 PostInvalidateWithFallback(); | 336 PostInvalidateWithFallback(); |
337 } | 337 } |
338 | 338 |
339 void BrowserViewRenderer::SetOffscreenPreRaster(bool enable) { | 339 void BrowserViewRenderer::SetOffscreenPreRaster(bool enable) { |
340 // TODO(hush): anything to do when the setting is toggled? | 340 if (offscreen_pre_raster_ != enable && compositor_) |
341 compositor_->SetMemoryPolicy(CalculateDesiredMemoryPolicy()); | |
boliu
2015/04/15 00:31:01
This ignores hardware_enabled_
hush (inactive)
2015/04/15 21:35:48
What do you mean? Do I need to do anything here? D
boliu
2015/04/15 22:27:45
policy should be 0 if hardware_enabled_ is false,
boliu
2015/04/15 22:57:04
Maybe CalcuateDesiredMemoryPolicy should take into
hush (inactive)
2015/04/16 01:13:24
I agree doing so keeps the logic sane. But setting
| |
342 | |
341 offscreen_pre_raster_ = enable; | 343 offscreen_pre_raster_ = enable; |
342 } | 344 } |
343 | 345 |
344 void BrowserViewRenderer::SetIsPaused(bool paused) { | 346 void BrowserViewRenderer::SetIsPaused(bool paused) { |
345 TRACE_EVENT_INSTANT1("android_webview", | 347 TRACE_EVENT_INSTANT1("android_webview", |
346 "BrowserViewRenderer::SetIsPaused", | 348 "BrowserViewRenderer::SetIsPaused", |
347 TRACE_EVENT_SCOPE_THREAD, | 349 TRACE_EVENT_SCOPE_THREAD, |
348 "paused", | 350 "paused", |
349 paused); | 351 paused); |
350 is_paused_ = paused; | 352 is_paused_ = paused; |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
713 base::StringAppendF(&str, | 715 base::StringAppendF(&str, |
714 "overscroll_rounding_error_: %s ", | 716 "overscroll_rounding_error_: %s ", |
715 overscroll_rounding_error_.ToString().c_str()); | 717 overscroll_rounding_error_.ToString().c_str()); |
716 base::StringAppendF( | 718 base::StringAppendF( |
717 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); | 719 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); |
718 base::StringAppendF(&str, "clear_view: %d ", clear_view_); | 720 base::StringAppendF(&str, "clear_view: %d ", clear_view_); |
719 return str; | 721 return str; |
720 } | 722 } |
721 | 723 |
722 } // namespace android_webview | 724 } // namespace android_webview |
OLD | NEW |