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 "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 g_memory_override_in_bytes *= 1024 * 1024; | 61 g_memory_override_in_bytes *= 1024 * 1024; |
62 } | 62 } |
63 | 63 |
64 // There is no need to limit number of tiles, so use an effectively unlimited | 64 // There is no need to limit number of tiles, so use an effectively unlimited |
65 // value as the limit. | 65 // value as the limit. |
66 GlobalTileManager::GetInstance()->SetTileLimit(10 * 1000 * 1000); | 66 GlobalTileManager::GetInstance()->SetTileLimit(10 * 1000 * 1000); |
67 } | 67 } |
68 | 68 |
69 BrowserViewRenderer::BrowserViewRenderer( | 69 BrowserViewRenderer::BrowserViewRenderer( |
70 BrowserViewRendererClient* client, | 70 BrowserViewRendererClient* client, |
71 SharedRendererState* shared_renderer_state, | |
72 content::WebContents* web_contents, | 71 content::WebContents* web_contents, |
73 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) | 72 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) |
74 : client_(client), | 73 : client_(client), |
75 shared_renderer_state_(shared_renderer_state), | 74 shared_renderer_state_(ui_task_runner, this), |
76 web_contents_(web_contents), | 75 web_contents_(web_contents), |
77 ui_task_runner_(ui_task_runner), | 76 ui_task_runner_(ui_task_runner), |
78 compositor_(NULL), | 77 compositor_(NULL), |
79 is_paused_(false), | 78 is_paused_(false), |
80 view_visible_(false), | 79 view_visible_(false), |
81 window_visible_(false), | 80 window_visible_(false), |
82 attached_to_window_(false), | 81 attached_to_window_(false), |
83 hardware_enabled_(false), | 82 hardware_enabled_(false), |
84 dip_scale_(0.0), | 83 dip_scale_(0.0), |
85 page_scale_factor_(1.0), | 84 page_scale_factor_(1.0), |
(...skipping 11 matching lines...) Expand all Loading... |
97 // Currently the logic in this class relies on |compositor_| remaining | 96 // Currently the logic in this class relies on |compositor_| remaining |
98 // NULL until the DidInitializeCompositor() call, hence it is not set here. | 97 // NULL until the DidInitializeCompositor() call, hence it is not set here. |
99 } | 98 } |
100 | 99 |
101 BrowserViewRenderer::~BrowserViewRenderer() { | 100 BrowserViewRenderer::~BrowserViewRenderer() { |
102 content::SynchronousCompositor::SetClientForWebContents(web_contents_, NULL); | 101 content::SynchronousCompositor::SetClientForWebContents(web_contents_, NULL); |
103 // OnDetachedFromWindow should be called before the destructor, so the memory | 102 // OnDetachedFromWindow should be called before the destructor, so the memory |
104 // policy should have already been updated. | 103 // policy should have already been updated. |
105 } | 104 } |
106 | 105 |
| 106 SharedRendererState* BrowserViewRenderer::GetSharedRendererState() { |
| 107 return &shared_renderer_state_; |
| 108 } |
| 109 |
| 110 bool BrowserViewRenderer::RequestDrawGL(jobject canvas, |
| 111 bool wait_for_completion) { |
| 112 return client_->RequestDrawGL(canvas, wait_for_completion); |
| 113 } |
| 114 |
107 // This function updates the resource allocation in GlobalTileManager. | 115 // This function updates the resource allocation in GlobalTileManager. |
108 void BrowserViewRenderer::TrimMemory(const int level, const bool visible) { | 116 void BrowserViewRenderer::TrimMemory(const int level, const bool visible) { |
109 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 117 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
110 // Constants from Android ComponentCallbacks2. | 118 // Constants from Android ComponentCallbacks2. |
111 enum { | 119 enum { |
112 TRIM_MEMORY_RUNNING_LOW = 10, | 120 TRIM_MEMORY_RUNNING_LOW = 10, |
113 TRIM_MEMORY_UI_HIDDEN = 20, | 121 TRIM_MEMORY_UI_HIDDEN = 20, |
114 TRIM_MEMORY_BACKGROUND = 40, | 122 TRIM_MEMORY_BACKGROUND = 40, |
115 }; | 123 }; |
116 | 124 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 | 213 |
206 // Perform a software draw | 214 // Perform a software draw |
207 return OnDrawSoftware(java_canvas); | 215 return OnDrawSoftware(java_canvas); |
208 } | 216 } |
209 | 217 |
210 bool BrowserViewRenderer::OnDrawHardware(jobject java_canvas) { | 218 bool BrowserViewRenderer::OnDrawHardware(jobject java_canvas) { |
211 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDrawHardware"); | 219 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDrawHardware"); |
212 if (!compositor_) | 220 if (!compositor_) |
213 return false; | 221 return false; |
214 | 222 |
215 shared_renderer_state_->SetScrollOffset(last_on_draw_scroll_offset_); | 223 shared_renderer_state_.SetScrollOffsetOnUI(last_on_draw_scroll_offset_); |
216 | 224 |
217 if (!hardware_enabled_) { | 225 if (!hardware_enabled_) { |
218 hardware_enabled_ = compositor_->InitializeHwDraw(); | 226 hardware_enabled_ = compositor_->InitializeHwDraw(); |
219 if (hardware_enabled_) { | 227 if (hardware_enabled_) { |
220 tile_manager_key_ = GlobalTileManager::GetInstance()->PushBack(this); | 228 tile_manager_key_ = GlobalTileManager::GetInstance()->PushBack(this); |
221 } | 229 } |
222 } | 230 } |
223 if (!hardware_enabled_) | 231 if (!hardware_enabled_) |
224 return false; | 232 return false; |
225 | 233 |
226 if (last_on_draw_global_visible_rect_.IsEmpty() && | 234 if (last_on_draw_global_visible_rect_.IsEmpty() && |
227 parent_draw_constraints_.surface_rect.IsEmpty()) { | 235 parent_draw_constraints_.surface_rect.IsEmpty()) { |
228 TRACE_EVENT_INSTANT0("android_webview", | 236 TRACE_EVENT_INSTANT0("android_webview", |
229 "EarlyOut_EmptyVisibleRect", | 237 "EarlyOut_EmptyVisibleRect", |
230 TRACE_EVENT_SCOPE_THREAD); | 238 TRACE_EVENT_SCOPE_THREAD); |
231 shared_renderer_state_->SetForceInvalidateOnNextDrawGL(true); | 239 shared_renderer_state_.SetForceInvalidateOnNextDrawGLOnUI(true); |
232 return client_->RequestDrawGL(java_canvas, false); | 240 return client_->RequestDrawGL(java_canvas, false); |
233 } | 241 } |
234 | 242 |
235 ReturnResourceFromParent(); | 243 ReturnResourceFromParent(); |
236 if (shared_renderer_state_->HasCompositorFrame()) { | 244 if (shared_renderer_state_.HasCompositorFrameOnUI()) { |
237 TRACE_EVENT_INSTANT0("android_webview", | 245 TRACE_EVENT_INSTANT0("android_webview", |
238 "EarlyOut_PreviousFrameUnconsumed", | 246 "EarlyOut_PreviousFrameUnconsumed", |
239 TRACE_EVENT_SCOPE_THREAD); | 247 TRACE_EVENT_SCOPE_THREAD); |
240 DidSkipCompositeInDraw(); | 248 DidSkipCompositeInDraw(); |
241 return client_->RequestDrawGL(java_canvas, false); | 249 return client_->RequestDrawGL(java_canvas, false); |
242 } | 250 } |
243 | 251 |
244 scoped_ptr<cc::CompositorFrame> frame = CompositeHw(); | 252 scoped_ptr<cc::CompositorFrame> frame = CompositeHw(); |
245 if (!frame.get()) | 253 if (!frame.get()) |
246 return false; | 254 return false; |
247 | 255 |
248 shared_renderer_state_->SetCompositorFrame(frame.Pass(), false); | 256 shared_renderer_state_.SetCompositorFrameOnUI(frame.Pass(), false); |
249 GlobalTileManager::GetInstance()->DidUse(tile_manager_key_); | 257 GlobalTileManager::GetInstance()->DidUse(tile_manager_key_); |
250 return client_->RequestDrawGL(java_canvas, false); | 258 return client_->RequestDrawGL(java_canvas, false); |
251 } | 259 } |
252 | 260 |
253 scoped_ptr<cc::CompositorFrame> BrowserViewRenderer::CompositeHw() { | 261 scoped_ptr<cc::CompositorFrame> BrowserViewRenderer::CompositeHw() { |
254 SynchronousCompositorMemoryPolicy new_policy = CalculateDesiredMemoryPolicy(); | 262 SynchronousCompositorMemoryPolicy new_policy = CalculateDesiredMemoryPolicy(); |
255 RequestMemoryPolicy(new_policy); | 263 RequestMemoryPolicy(new_policy); |
256 compositor_->SetMemoryPolicy(memory_policy_); | 264 compositor_->SetMemoryPolicy(memory_policy_); |
257 | 265 |
258 parent_draw_constraints_ = shared_renderer_state_->ParentDrawConstraints(); | 266 parent_draw_constraints_ = |
| 267 shared_renderer_state_.GetParentDrawConstraintsOnUI(); |
259 gfx::Size surface_size(width_, height_); | 268 gfx::Size surface_size(width_, height_); |
260 gfx::Rect viewport(surface_size); | 269 gfx::Rect viewport(surface_size); |
261 gfx::Rect clip = viewport; | 270 gfx::Rect clip = viewport; |
262 gfx::Transform transform_for_tile_priority = | 271 gfx::Transform transform_for_tile_priority = |
263 parent_draw_constraints_.transform; | 272 parent_draw_constraints_.transform; |
264 | 273 |
265 // If the WebView is on a layer, WebView does not know what transform is | 274 // If the WebView is on a layer, WebView does not know what transform is |
266 // applied onto the layer so global visible rect does not make sense here. | 275 // applied onto the layer so global visible rect does not make sense here. |
267 // In this case, just use the surface rect for tiling. | 276 // In this case, just use the surface rect for tiling. |
268 gfx::Rect viewport_rect_for_tile_priority; | 277 gfx::Rect viewport_rect_for_tile_priority; |
(...skipping 13 matching lines...) Expand all Loading... |
282 transform_for_tile_priority); | 291 transform_for_tile_priority); |
283 if (frame.get()) | 292 if (frame.get()) |
284 DidComposite(); | 293 DidComposite(); |
285 return frame.Pass(); | 294 return frame.Pass(); |
286 } | 295 } |
287 | 296 |
288 void BrowserViewRenderer::UpdateParentDrawConstraints() { | 297 void BrowserViewRenderer::UpdateParentDrawConstraints() { |
289 // Post an invalidate if the parent draw constraints are stale and there is | 298 // Post an invalidate if the parent draw constraints are stale and there is |
290 // no pending invalidate. | 299 // no pending invalidate. |
291 bool needs_force_invalidate = | 300 bool needs_force_invalidate = |
292 shared_renderer_state_->NeedsForceInvalidateOnNextDrawGL(); | 301 shared_renderer_state_.NeedsForceInvalidateOnNextDrawGLOnUI(); |
293 if (needs_force_invalidate || | 302 if (needs_force_invalidate || |
294 !parent_draw_constraints_.Equals( | 303 !parent_draw_constraints_.Equals( |
295 shared_renderer_state_->ParentDrawConstraints())) { | 304 shared_renderer_state_.GetParentDrawConstraintsOnUI())) { |
296 shared_renderer_state_->SetForceInvalidateOnNextDrawGL(false); | 305 shared_renderer_state_.SetForceInvalidateOnNextDrawGLOnUI(false); |
297 EnsureContinuousInvalidation(true, needs_force_invalidate); | 306 EnsureContinuousInvalidation(true, needs_force_invalidate); |
298 } | 307 } |
299 } | 308 } |
300 | 309 |
301 void BrowserViewRenderer::ReturnUnusedResource( | 310 void BrowserViewRenderer::ReturnUnusedResource( |
302 scoped_ptr<cc::CompositorFrame> frame) { | 311 scoped_ptr<cc::CompositorFrame> frame) { |
303 if (!frame.get()) | 312 if (!frame.get()) |
304 return; | 313 return; |
305 | 314 |
306 cc::CompositorFrameAck frame_ack; | 315 cc::CompositorFrameAck frame_ack; |
307 cc::TransferableResource::ReturnResources( | 316 cc::TransferableResource::ReturnResources( |
308 frame->delegated_frame_data->resource_list, &frame_ack.resources); | 317 frame->delegated_frame_data->resource_list, &frame_ack.resources); |
309 if (compositor_ && !frame_ack.resources.empty()) | 318 if (compositor_ && !frame_ack.resources.empty()) |
310 compositor_->ReturnResources(frame_ack); | 319 compositor_->ReturnResources(frame_ack); |
311 } | 320 } |
312 | 321 |
313 void BrowserViewRenderer::ReturnResourceFromParent() { | 322 void BrowserViewRenderer::ReturnResourceFromParent() { |
314 cc::CompositorFrameAck frame_ack; | 323 cc::CompositorFrameAck frame_ack; |
315 shared_renderer_state_->SwapReturnedResources(&frame_ack.resources); | 324 shared_renderer_state_.SwapReturnedResourcesOnUI(&frame_ack.resources); |
316 if (compositor_ && !frame_ack.resources.empty()) { | 325 if (compositor_ && !frame_ack.resources.empty()) { |
317 compositor_->ReturnResources(frame_ack); | 326 compositor_->ReturnResources(frame_ack); |
318 } | 327 } |
319 } | 328 } |
320 | 329 |
321 void BrowserViewRenderer::DidSkipCommitFrame() { | 330 void BrowserViewRenderer::DidSkipCommitFrame() { |
322 // Treat it the same way as skipping onDraw. | 331 // Treat it the same way as skipping onDraw. |
323 DidSkipCompositeInDraw(); | 332 DidSkipCompositeInDraw(); |
324 } | 333 } |
325 | 334 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 } | 447 } |
439 | 448 |
440 void BrowserViewRenderer::OnDetachedFromWindow() { | 449 void BrowserViewRenderer::OnDetachedFromWindow() { |
441 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDetachedFromWindow"); | 450 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDetachedFromWindow"); |
442 attached_to_window_ = false; | 451 attached_to_window_ = false; |
443 DCHECK(!hardware_enabled_); | 452 DCHECK(!hardware_enabled_); |
444 } | 453 } |
445 | 454 |
446 void BrowserViewRenderer::ReleaseHardware() { | 455 void BrowserViewRenderer::ReleaseHardware() { |
447 DCHECK(hardware_enabled_); | 456 DCHECK(hardware_enabled_); |
448 ReturnUnusedResource(shared_renderer_state_->PassCompositorFrame()); | 457 // TODO(hush): do this in somewhere else. Either in hardware render or in |
| 458 // shared renderer state. |
| 459 ReturnUnusedResource(shared_renderer_state_.PassCompositorFrame()); |
449 ReturnResourceFromParent(); | 460 ReturnResourceFromParent(); |
450 DCHECK(shared_renderer_state_->ReturnedResourcesEmpty()); | 461 DCHECK(shared_renderer_state_.ReturnedResourcesEmpty()); |
451 | 462 |
452 if (compositor_) { | 463 if (compositor_) { |
453 compositor_->ReleaseHwDraw(); | 464 compositor_->ReleaseHwDraw(); |
454 SynchronousCompositorMemoryPolicy zero_policy; | 465 SynchronousCompositorMemoryPolicy zero_policy; |
455 RequestMemoryPolicy(zero_policy); | 466 RequestMemoryPolicy(zero_policy); |
456 } | 467 } |
457 | 468 |
458 hardware_enabled_ = false; | 469 hardware_enabled_ = false; |
459 GlobalTileManager::GetInstance()->Remove(tile_manager_key_); | 470 GlobalTileManager::GetInstance()->Remove(tile_manager_key_); |
460 } | 471 } |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 "compositor_needs_continuous_invalidate_", | 748 "compositor_needs_continuous_invalidate_", |
738 compositor_needs_continuous_invalidate_); | 749 compositor_needs_continuous_invalidate_); |
739 | 750 |
740 // This should only be called if OnDraw or DrawGL did not come in time, which | 751 // This should only be called if OnDraw or DrawGL did not come in time, which |
741 // means block_invalidates_ must still be true. | 752 // means block_invalidates_ must still be true. |
742 DCHECK(block_invalidates_); | 753 DCHECK(block_invalidates_); |
743 fallback_tick_pending_ = false; | 754 fallback_tick_pending_ = false; |
744 if (compositor_needs_continuous_invalidate_ && compositor_) { | 755 if (compositor_needs_continuous_invalidate_ && compositor_) { |
745 if (hardware_enabled_) { | 756 if (hardware_enabled_) { |
746 ReturnResourceFromParent(); | 757 ReturnResourceFromParent(); |
747 ReturnUnusedResource(shared_renderer_state_->PassCompositorFrame()); | 758 ReturnUnusedResource(shared_renderer_state_.PassCompositorFrame()); |
748 scoped_ptr<cc::CompositorFrame> frame = CompositeHw(); | 759 scoped_ptr<cc::CompositorFrame> frame = CompositeHw(); |
749 if (frame.get()) { | 760 if (frame.get()) { |
750 shared_renderer_state_->SetCompositorFrame(frame.Pass(), true); | 761 shared_renderer_state_.SetCompositorFrameOnUI(frame.Pass(), true); |
751 } | 762 } |
752 } else { | 763 } else { |
753 ForceFakeCompositeSW(); | 764 ForceFakeCompositeSW(); |
754 } | 765 } |
755 } else { | 766 } else { |
756 // Pretend we just composited to unblock further invalidates. | 767 // Pretend we just composited to unblock further invalidates. |
757 DidComposite(); | 768 DidComposite(); |
758 } | 769 } |
759 } | 770 } |
760 | 771 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 base::StringAppendF(&str, | 820 base::StringAppendF(&str, |
810 "overscroll_rounding_error_: %s ", | 821 "overscroll_rounding_error_: %s ", |
811 overscroll_rounding_error_.ToString().c_str()); | 822 overscroll_rounding_error_.ToString().c_str()); |
812 base::StringAppendF( | 823 base::StringAppendF( |
813 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); | 824 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); |
814 base::StringAppendF(&str, "clear_view: %d ", clear_view_); | 825 base::StringAppendF(&str, "clear_view: %d ", clear_view_); |
815 return str; | 826 return str; |
816 } | 827 } |
817 | 828 |
818 } // namespace android_webview | 829 } // namespace android_webview |
OLD | NEW |