Chromium Code Reviews| 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 // This function updates the resource allocation in GlobalTileManager. | 138 // This function updates the resource allocation in GlobalTileManager. |
| 139 void BrowserViewRenderer::TrimMemory(const int level, const bool visible) { | 139 void BrowserViewRenderer::TrimMemory(const int level, const bool visible) { |
| 140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 141 // Constants from Android ComponentCallbacks2. | 141 // Constants from Android ComponentCallbacks2. |
| 142 enum { | 142 enum { |
| 143 TRIM_MEMORY_RUNNING_LOW = 10, | 143 TRIM_MEMORY_RUNNING_LOW = 10, |
| 144 TRIM_MEMORY_UI_HIDDEN = 20, | 144 TRIM_MEMORY_UI_HIDDEN = 20, |
| 145 TRIM_MEMORY_BACKGROUND = 40, | 145 TRIM_MEMORY_BACKGROUND = 40, |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 if (!compositor_ || !hardware_enabled_) | |
| 149 return; | |
| 150 | |
| 148 // Not urgent enough. TRIM_MEMORY_UI_HIDDEN is treated specially because | 151 // Not urgent enough. TRIM_MEMORY_UI_HIDDEN is treated specially because |
| 149 // it does not indicate memory pressure, but merely that the app is | 152 // it does not indicate memory pressure, but merely that the app is |
| 150 // backgrounded. | 153 // backgrounded. |
| 151 if (level < TRIM_MEMORY_RUNNING_LOW || level == TRIM_MEMORY_UI_HIDDEN) | 154 if (level < TRIM_MEMORY_RUNNING_LOW || level == TRIM_MEMORY_UI_HIDDEN) |
| 152 return; | 155 return; |
| 153 | 156 |
| 154 // Do not release resources on view we expect to get DrawGL soon. | 157 // Do not release resources on view we expect to get DrawGL soon. |
| 155 if (level < TRIM_MEMORY_BACKGROUND && visible) | 158 if (level < TRIM_MEMORY_BACKGROUND && visible) |
| 156 return; | 159 return; |
| 157 | 160 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 185 // is also kTileAllocationStep. | 188 // is also kTileAllocationStep. |
| 186 tiles = (tiles / kTileAllocationStep + 1) * kTileAllocationStep; | 189 tiles = (tiles / kTileAllocationStep + 1) * kTileAllocationStep; |
| 187 policy.num_resources_limit = tiles; | 190 policy.num_resources_limit = tiles; |
| 188 return policy; | 191 return policy; |
| 189 } | 192 } |
| 190 | 193 |
| 191 // This function updates the cached memory policy in shared renderer state, as | 194 // This function updates the cached memory policy in shared renderer state, as |
| 192 // well as the tile resource allocation in GlobalTileManager. | 195 // well as the tile resource allocation in GlobalTileManager. |
| 193 void BrowserViewRenderer::RequestMemoryPolicy( | 196 void BrowserViewRenderer::RequestMemoryPolicy( |
| 194 SynchronousCompositorMemoryPolicy& new_policy) { | 197 SynchronousCompositorMemoryPolicy& new_policy) { |
| 198 DCHECK(compositor_); | |
| 195 GlobalTileManager* manager = GlobalTileManager::GetInstance(); | 199 GlobalTileManager* manager = GlobalTileManager::GetInstance(); |
| 196 | 200 |
| 197 // The following line will call BrowserViewRenderer::SetMemoryPolicy(). | 201 // The following line will call BrowserViewRenderer::SetMemoryPolicy(). |
| 198 manager->RequestTiles(new_policy, tile_manager_key_); | 202 manager->RequestTiles(new_policy, tile_manager_key_); |
| 199 } | 203 } |
| 200 | 204 |
| 201 void BrowserViewRenderer::SetMemoryPolicy( | 205 void BrowserViewRenderer::SetMemoryPolicy( |
| 202 SynchronousCompositorMemoryPolicy new_policy, | 206 SynchronousCompositorMemoryPolicy new_policy, |
| 203 bool effective_immediately) { | 207 bool effective_immediately) { |
| 204 memory_policy_ = new_policy; | 208 memory_policy_ = new_policy; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 if (shared_renderer_state_->NeedsForceInvalidateOnNextDrawGL() || | 314 if (shared_renderer_state_->NeedsForceInvalidateOnNextDrawGL() || |
| 311 !parent_draw_constraints_.Equals( | 315 !parent_draw_constraints_.Equals( |
| 312 shared_renderer_state_->ParentDrawConstraints())) { | 316 shared_renderer_state_->ParentDrawConstraints())) { |
| 313 shared_renderer_state_->SetForceInvalidateOnNextDrawGL(false); | 317 shared_renderer_state_->SetForceInvalidateOnNextDrawGL(false); |
| 314 EnsureContinuousInvalidation(true, false); | 318 EnsureContinuousInvalidation(true, false); |
| 315 } | 319 } |
| 316 } | 320 } |
| 317 | 321 |
| 318 void BrowserViewRenderer::ReturnUnusedResource( | 322 void BrowserViewRenderer::ReturnUnusedResource( |
| 319 scoped_ptr<cc::CompositorFrame> frame) { | 323 scoped_ptr<cc::CompositorFrame> frame) { |
| 324 DCHECK(compositor_); | |
| 320 if (!frame.get()) | 325 if (!frame.get()) |
| 321 return; | 326 return; |
| 322 | 327 |
| 323 cc::CompositorFrameAck frame_ack; | 328 cc::CompositorFrameAck frame_ack; |
| 324 cc::TransferableResource::ReturnResources( | 329 cc::TransferableResource::ReturnResources( |
| 325 frame->delegated_frame_data->resource_list, &frame_ack.resources); | 330 frame->delegated_frame_data->resource_list, &frame_ack.resources); |
| 326 if (!frame_ack.resources.empty()) | 331 if (!frame_ack.resources.empty()) |
| 327 compositor_->ReturnResources(frame_ack); | 332 compositor_->ReturnResources(frame_ack); |
| 328 } | 333 } |
| 329 | 334 |
| 330 void BrowserViewRenderer::ReturnResourceFromParent() { | 335 void BrowserViewRenderer::ReturnResourceFromParent() { |
| 336 DCHECK(compositor_); | |
| 331 cc::CompositorFrameAck frame_ack; | 337 cc::CompositorFrameAck frame_ack; |
| 332 shared_renderer_state_->SwapReturnedResources(&frame_ack.resources); | 338 shared_renderer_state_->SwapReturnedResources(&frame_ack.resources); |
| 333 if (!frame_ack.resources.empty()) { | 339 if (!frame_ack.resources.empty()) { |
| 334 compositor_->ReturnResources(frame_ack); | 340 compositor_->ReturnResources(frame_ack); |
| 335 } | 341 } |
| 336 } | 342 } |
| 337 | 343 |
| 338 bool BrowserViewRenderer::OnDrawSoftware(jobject java_canvas) { | 344 bool BrowserViewRenderer::OnDrawSoftware(jobject java_canvas) { |
| 339 if (!compositor_) { | 345 if (!compositor_) { |
| 340 TRACE_EVENT_INSTANT0( | 346 TRACE_EVENT_INSTANT0( |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 height_ = height; | 455 height_ = height; |
| 450 } | 456 } |
| 451 | 457 |
| 452 void BrowserViewRenderer::OnDetachedFromWindow() { | 458 void BrowserViewRenderer::OnDetachedFromWindow() { |
| 453 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDetachedFromWindow"); | 459 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDetachedFromWindow"); |
| 454 attached_to_window_ = false; | 460 attached_to_window_ = false; |
| 455 DCHECK(!hardware_enabled_); | 461 DCHECK(!hardware_enabled_); |
| 456 } | 462 } |
| 457 | 463 |
| 458 void BrowserViewRenderer::ReleaseHardware() { | 464 void BrowserViewRenderer::ReleaseHardware() { |
| 465 DCHECK(compositor_); | |
| 459 DCHECK(hardware_enabled_); | 466 DCHECK(hardware_enabled_); |
| 460 ReturnUnusedResource(shared_renderer_state_->PassCompositorFrame()); | 467 ReturnUnusedResource(shared_renderer_state_->PassCompositorFrame()); |
| 461 ReturnResourceFromParent(); | 468 ReturnResourceFromParent(); |
| 462 DCHECK(shared_renderer_state_->ReturnedResourcesEmpty()); | 469 DCHECK(shared_renderer_state_->ReturnedResourcesEmpty()); |
| 463 | 470 |
| 464 compositor_->ReleaseHwDraw(); | 471 compositor_->ReleaseHwDraw(); |
| 465 hardware_enabled_ = false; | 472 hardware_enabled_ = false; |
| 466 | 473 |
| 467 SynchronousCompositorMemoryPolicy zero_policy; | 474 SynchronousCompositorMemoryPolicy zero_policy; |
| 468 RequestMemoryPolicy(zero_policy); | 475 RequestMemoryPolicy(zero_policy); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 484 "BrowserViewRenderer::DidInitializeCompositor"); | 491 "BrowserViewRenderer::DidInitializeCompositor"); |
| 485 DCHECK(compositor); | 492 DCHECK(compositor); |
| 486 DCHECK(!compositor_); | 493 DCHECK(!compositor_); |
| 487 compositor_ = compositor; | 494 compositor_ = compositor; |
| 488 } | 495 } |
| 489 | 496 |
| 490 void BrowserViewRenderer::DidDestroyCompositor( | 497 void BrowserViewRenderer::DidDestroyCompositor( |
| 491 content::SynchronousCompositor* compositor) { | 498 content::SynchronousCompositor* compositor) { |
| 492 TRACE_EVENT0("android_webview", "BrowserViewRenderer::DidDestroyCompositor"); | 499 TRACE_EVENT0("android_webview", "BrowserViewRenderer::DidDestroyCompositor"); |
| 493 DCHECK(compositor_); | 500 DCHECK(compositor_); |
| 501 SynchronousCompositorMemoryPolicy zero_policy; | |
| 502 RequestMemoryPolicy(zero_policy); | |
| 494 compositor_ = NULL; | 503 compositor_ = NULL; |
| 495 SynchronousCompositorMemoryPolicy zero_policy; | 504 hardware_enabled_ = false; |
|
boliu
2014/10/17 22:59:26
oh god that's so freaking wrong
hush (inactive)
2014/10/17 23:04:15
what do you mean? I thought what you did is replac
boliu
2014/10/17 23:06:01
CHECK was to see it actually happens, not the fix.
| |
| 496 DCHECK(memory_policy_ == zero_policy); | |
| 497 } | 505 } |
| 498 | 506 |
| 499 void BrowserViewRenderer::SetContinuousInvalidate(bool invalidate) { | 507 void BrowserViewRenderer::SetContinuousInvalidate(bool invalidate) { |
| 500 if (compositor_needs_continuous_invalidate_ == invalidate) | 508 if (compositor_needs_continuous_invalidate_ == invalidate) |
| 501 return; | 509 return; |
| 502 | 510 |
| 503 TRACE_EVENT_INSTANT1("android_webview", | 511 TRACE_EVENT_INSTANT1("android_webview", |
| 504 "BrowserViewRenderer::SetContinuousInvalidate", | 512 "BrowserViewRenderer::SetContinuousInvalidate", |
| 505 TRACE_EVENT_SCOPE_THREAD, | 513 TRACE_EVENT_SCOPE_THREAD, |
| 506 "invalidate", | 514 "invalidate", |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 814 base::StringAppendF(&str, | 822 base::StringAppendF(&str, |
| 815 "surface width height: [%d %d] ", | 823 "surface width height: [%d %d] ", |
| 816 draw_info->width, | 824 draw_info->width, |
| 817 draw_info->height); | 825 draw_info->height); |
| 818 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); | 826 base::StringAppendF(&str, "is_layer: %d ", draw_info->is_layer); |
| 819 } | 827 } |
| 820 return str; | 828 return str; |
| 821 } | 829 } |
| 822 | 830 |
| 823 } // namespace android_webview | 831 } // namespace android_webview |
| OLD | NEW |