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 if (offscreen_pre_raster_) |
| 151 shared_renderer_state_.DeleteHardwareRendererOnUI(); |
| 152 else |
| 153 shared_renderer_state_.ReleaseHardwareDrawIfNeededOnUI(); |
151 return; | 154 return; |
152 } | 155 } |
153 | 156 |
154 // Just set the memory limit to 0 and drop all tiles. This will be reset to | 157 // Just set the memory limit to 0 and drop all tiles. This will be reset to |
155 // normal levels in the next DrawGL call. | 158 // normal levels in the next DrawGL call. |
156 compositor_->SetMemoryPolicy(0u); | 159 if (!offscreen_pre_raster_) |
157 ForceFakeCompositeSW(); | 160 compositor_->SetMemoryPolicy(0u); |
158 } | 161 } |
159 | 162 |
160 size_t BrowserViewRenderer::CalculateDesiredMemoryPolicy() { | 163 void BrowserViewRenderer::UpdateMemoryPolicy() { |
161 if (g_memory_override_in_bytes) | 164 if (!hardware_enabled_) { |
162 return static_cast<size_t>(g_memory_override_in_bytes); | 165 compositor_->SetMemoryPolicy(0u); |
| 166 return; |
| 167 } |
163 | 168 |
164 gfx::Rect interest_rect = offscreen_pre_raster_ | 169 size_t bytes_limit = 0u; |
165 ? gfx::Rect(size_) | 170 if (g_memory_override_in_bytes) { |
166 : last_on_draw_global_visible_rect_; | 171 bytes_limit = static_cast<size_t>(g_memory_override_in_bytes); |
167 size_t width = interest_rect.width(); | 172 } else { |
168 size_t height = interest_rect.height(); | 173 gfx::Rect interest_rect = offscreen_pre_raster_ |
169 size_t bytes_limit = kMemoryMultiplier * kBytesPerPixel * width * height; | 174 ? gfx::Rect(size_) |
170 // Round up to a multiple of kMemoryAllocationStep. | 175 : last_on_draw_global_visible_rect_; |
171 bytes_limit = | 176 size_t width = interest_rect.width(); |
172 (bytes_limit / kMemoryAllocationStep + 1) * kMemoryAllocationStep; | 177 size_t height = interest_rect.height(); |
173 return bytes_limit; | 178 bytes_limit = kMemoryMultiplier * kBytesPerPixel * width * height; |
| 179 // Round up to a multiple of kMemoryAllocationStep. |
| 180 bytes_limit = |
| 181 (bytes_limit / kMemoryAllocationStep + 1) * kMemoryAllocationStep; |
| 182 } |
| 183 |
| 184 compositor_->SetMemoryPolicy(bytes_limit); |
174 } | 185 } |
175 | 186 |
176 void BrowserViewRenderer::PrepareToDraw(const gfx::Vector2d& scroll, | 187 void BrowserViewRenderer::PrepareToDraw(const gfx::Vector2d& scroll, |
177 const gfx::Rect& global_visible_rect) { | 188 const gfx::Rect& global_visible_rect) { |
178 last_on_draw_scroll_offset_ = scroll; | 189 last_on_draw_scroll_offset_ = scroll; |
179 last_on_draw_global_visible_rect_ = global_visible_rect; | 190 last_on_draw_global_visible_rect_ = global_visible_rect; |
180 } | 191 } |
181 | 192 |
182 bool BrowserViewRenderer::CanOnDraw() { | 193 bool BrowserViewRenderer::CanOnDraw() { |
183 if (!compositor_) { | 194 if (!compositor_) { |
(...skipping 22 matching lines...) Expand all Loading... |
206 shared_renderer_state_.SetScrollOffsetOnUI(last_on_draw_scroll_offset_); | 217 shared_renderer_state_.SetScrollOffsetOnUI(last_on_draw_scroll_offset_); |
207 hardware_enabled_ = true; | 218 hardware_enabled_ = true; |
208 | 219 |
209 return CompositeHw(); | 220 return CompositeHw(); |
210 } | 221 } |
211 | 222 |
212 bool BrowserViewRenderer::CompositeHw() { | 223 bool BrowserViewRenderer::CompositeHw() { |
213 CancelFallbackTick(); | 224 CancelFallbackTick(); |
214 | 225 |
215 ReturnResourceFromParent(); | 226 ReturnResourceFromParent(); |
216 compositor_->SetMemoryPolicy(CalculateDesiredMemoryPolicy()); | 227 UpdateMemoryPolicy(); |
217 | 228 |
218 ParentCompositorDrawConstraints parent_draw_constraints = | 229 ParentCompositorDrawConstraints parent_draw_constraints = |
219 shared_renderer_state_.GetParentDrawConstraintsOnUI(); | 230 shared_renderer_state_.GetParentDrawConstraintsOnUI(); |
220 gfx::Size surface_size(size_); | 231 gfx::Size surface_size(size_); |
221 gfx::Rect viewport(surface_size); | 232 gfx::Rect viewport(surface_size); |
222 gfx::Rect clip = viewport; | 233 gfx::Rect clip = viewport; |
223 gfx::Transform transform_for_tile_priority = | 234 gfx::Transform transform_for_tile_priority = |
224 parent_draw_constraints.transform; | 235 parent_draw_constraints.transform; |
225 | 236 |
226 // If the WebView is on a layer, WebView does not know what transform is | 237 // If the WebView is on a layer, WebView does not know what transform is |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 TRACE_EVENT_SCOPE_THREAD); | 341 TRACE_EVENT_SCOPE_THREAD); |
331 if (clear_view_) | 342 if (clear_view_) |
332 return; | 343 return; |
333 | 344 |
334 clear_view_ = true; | 345 clear_view_ = true; |
335 // Always invalidate ignoring the compositor to actually clear the webview. | 346 // Always invalidate ignoring the compositor to actually clear the webview. |
336 PostInvalidateWithFallback(); | 347 PostInvalidateWithFallback(); |
337 } | 348 } |
338 | 349 |
339 void BrowserViewRenderer::SetOffscreenPreRaster(bool enable) { | 350 void BrowserViewRenderer::SetOffscreenPreRaster(bool enable) { |
340 // TODO(hush): anything to do when the setting is toggled? | 351 if (offscreen_pre_raster_ != enable && compositor_) |
| 352 UpdateMemoryPolicy(); |
| 353 |
341 offscreen_pre_raster_ = enable; | 354 offscreen_pre_raster_ = enable; |
342 } | 355 } |
343 | 356 |
344 void BrowserViewRenderer::SetIsPaused(bool paused) { | 357 void BrowserViewRenderer::SetIsPaused(bool paused) { |
345 TRACE_EVENT_INSTANT1("android_webview", | 358 TRACE_EVENT_INSTANT1("android_webview", |
346 "BrowserViewRenderer::SetIsPaused", | 359 "BrowserViewRenderer::SetIsPaused", |
347 TRACE_EVENT_SCOPE_THREAD, | 360 TRACE_EVENT_SCOPE_THREAD, |
348 "paused", | 361 "paused", |
349 paused); | 362 paused); |
350 is_paused_ = paused; | 363 is_paused_ = paused; |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 base::StringAppendF(&str, | 726 base::StringAppendF(&str, |
714 "overscroll_rounding_error_: %s ", | 727 "overscroll_rounding_error_: %s ", |
715 overscroll_rounding_error_.ToString().c_str()); | 728 overscroll_rounding_error_.ToString().c_str()); |
716 base::StringAppendF( | 729 base::StringAppendF( |
717 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); | 730 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); |
718 base::StringAppendF(&str, "clear_view: %d ", clear_view_); | 731 base::StringAppendF(&str, "clear_view: %d ", clear_view_); |
719 return str; | 732 return str; |
720 } | 733 } |
721 | 734 |
722 } // namespace android_webview | 735 } // namespace android_webview |
OLD | NEW |