| 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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 if (!hardware_enabled_) { | 219 if (!hardware_enabled_) { |
| 220 hardware_enabled_ = compositor_->InitializeHwDraw(); | 220 hardware_enabled_ = compositor_->InitializeHwDraw(); |
| 221 if (hardware_enabled_) { | 221 if (hardware_enabled_) { |
| 222 tile_manager_key_ = GlobalTileManager::GetInstance()->PushBack(this); | 222 tile_manager_key_ = GlobalTileManager::GetInstance()->PushBack(this); |
| 223 } | 223 } |
| 224 } | 224 } |
| 225 if (!hardware_enabled_) | 225 if (!hardware_enabled_) |
| 226 return false; | 226 return false; |
| 227 | 227 |
| 228 ReturnResourceFromParent(); | 228 ReturnResourceFromParent(); |
| 229 SynchronousCompositorMemoryPolicy new_policy = CalculateDesiredMemoryPolicy(); | |
| 230 RequestMemoryPolicy(new_policy); | |
| 231 compositor_->SetMemoryPolicy(memory_policy_); | |
| 232 | |
| 233 if (shared_renderer_state_->HasCompositorFrame()) { | 229 if (shared_renderer_state_->HasCompositorFrame()) { |
| 234 TRACE_EVENT_INSTANT0("android_webview", | 230 TRACE_EVENT_INSTANT0("android_webview", |
| 235 "EarlyOut_PreviousFrameUnconsumed", | 231 "EarlyOut_PreviousFrameUnconsumed", |
| 236 TRACE_EVENT_SCOPE_THREAD); | 232 TRACE_EVENT_SCOPE_THREAD); |
| 237 SkippedCompositeInDraw(); | 233 SkippedCompositeInDraw(); |
| 238 return client_->RequestDrawGL(java_canvas, false); | 234 return client_->RequestDrawGL(java_canvas, false); |
| 239 } | 235 } |
| 240 | 236 |
| 237 scoped_ptr<cc::CompositorFrame> frame = CompositeHw(); |
| 238 if (!frame.get()) |
| 239 return false; |
| 240 |
| 241 shared_renderer_state_->SetCompositorFrame(frame.Pass(), false); |
| 242 GlobalTileManager::GetInstance()->DidUse(tile_manager_key_); |
| 243 return client_->RequestDrawGL(java_canvas, false); |
| 244 } |
| 245 |
| 246 scoped_ptr<cc::CompositorFrame> BrowserViewRenderer::CompositeHw() { |
| 247 SynchronousCompositorMemoryPolicy new_policy = CalculateDesiredMemoryPolicy(); |
| 248 RequestMemoryPolicy(new_policy); |
| 249 compositor_->SetMemoryPolicy(memory_policy_); |
| 250 |
| 241 parent_draw_constraints_ = shared_renderer_state_->ParentDrawConstraints(); | 251 parent_draw_constraints_ = shared_renderer_state_->ParentDrawConstraints(); |
| 242 gfx::Size surface_size(width_, height_); | 252 gfx::Size surface_size(width_, height_); |
| 243 gfx::Rect viewport(surface_size); | 253 gfx::Rect viewport(surface_size); |
| 244 gfx::Rect clip = viewport; | 254 gfx::Rect clip = viewport; |
| 245 gfx::Transform transform_for_tile_priority = | 255 gfx::Transform transform_for_tile_priority = |
| 246 parent_draw_constraints_.transform; | 256 parent_draw_constraints_.transform; |
| 247 | 257 |
| 248 // If the WebView is on a layer, WebView does not know what transform is | 258 // If the WebView is on a layer, WebView does not know what transform is |
| 249 // applied onto the layer so global visible rect does not make sense here. | 259 // applied onto the layer so global visible rect does not make sense here. |
| 250 // In this case, just use the surface rect for tiling. | 260 // In this case, just use the surface rect for tiling. |
| 251 gfx::Rect viewport_rect_for_tile_priority; | 261 gfx::Rect viewport_rect_for_tile_priority; |
| 252 if (parent_draw_constraints_.is_layer) | 262 if (parent_draw_constraints_.is_layer) |
| 253 viewport_rect_for_tile_priority = parent_draw_constraints_.surface_rect; | 263 viewport_rect_for_tile_priority = parent_draw_constraints_.surface_rect; |
| 254 else | 264 else |
| 255 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; | 265 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; |
| 256 | 266 |
| 257 scoped_ptr<cc::CompositorFrame> frame = | 267 scoped_ptr<cc::CompositorFrame> frame = |
| 258 compositor_->DemandDrawHw(surface_size, | 268 compositor_->DemandDrawHw(surface_size, |
| 259 gfx::Transform(), | 269 gfx::Transform(), |
| 260 viewport, | 270 viewport, |
| 261 clip, | 271 clip, |
| 262 viewport_rect_for_tile_priority, | 272 viewport_rect_for_tile_priority, |
| 263 transform_for_tile_priority); | 273 transform_for_tile_priority); |
| 264 if (!frame.get()) | 274 if (frame.get()) |
| 265 return false; | 275 DidComposite(); |
| 266 | 276 return frame.Pass(); |
| 267 GlobalTileManager::GetInstance()->DidUse(tile_manager_key_); | |
| 268 | |
| 269 shared_renderer_state_->SetCompositorFrame(frame.Pass()); | |
| 270 DidComposite(); | |
| 271 return client_->RequestDrawGL(java_canvas, false); | |
| 272 } | 277 } |
| 273 | 278 |
| 274 void BrowserViewRenderer::UpdateParentDrawConstraints() { | 279 void BrowserViewRenderer::UpdateParentDrawConstraints() { |
| 275 // Post an invalidate if the parent draw constraints are stale and there is | 280 // Post an invalidate if the parent draw constraints are stale and there is |
| 276 // no pending invalidate. | 281 // no pending invalidate. |
| 277 if (shared_renderer_state_->NeedsForceInvalidateOnNextDrawGL() || | 282 if (shared_renderer_state_->NeedsForceInvalidateOnNextDrawGL() || |
| 278 !parent_draw_constraints_.Equals( | 283 !parent_draw_constraints_.Equals( |
| 279 shared_renderer_state_->ParentDrawConstraints())) { | 284 shared_renderer_state_->ParentDrawConstraints())) { |
| 280 shared_renderer_state_->SetForceInvalidateOnNextDrawGL(false); | 285 shared_renderer_state_->SetForceInvalidateOnNextDrawGL(false); |
| 281 EnsureContinuousInvalidation(true, false); | 286 EnsureContinuousInvalidation(true, false); |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 TRACE_EVENT1("android_webview", | 708 TRACE_EVENT1("android_webview", |
| 704 "BrowserViewRenderer::FallbackTickFired", | 709 "BrowserViewRenderer::FallbackTickFired", |
| 705 "compositor_needs_continuous_invalidate_", | 710 "compositor_needs_continuous_invalidate_", |
| 706 compositor_needs_continuous_invalidate_); | 711 compositor_needs_continuous_invalidate_); |
| 707 | 712 |
| 708 // This should only be called if OnDraw or DrawGL did not come in time, which | 713 // This should only be called if OnDraw or DrawGL did not come in time, which |
| 709 // means block_invalidates_ must still be true. | 714 // means block_invalidates_ must still be true. |
| 710 DCHECK(block_invalidates_); | 715 DCHECK(block_invalidates_); |
| 711 fallback_tick_pending_ = false; | 716 fallback_tick_pending_ = false; |
| 712 if (compositor_needs_continuous_invalidate_ && compositor_) { | 717 if (compositor_needs_continuous_invalidate_ && compositor_) { |
| 713 ForceFakeCompositeSW(); | 718 if (hardware_enabled_) { |
| 719 ReturnResourceFromParent(); |
| 720 ReturnUnusedResource(shared_renderer_state_->PassCompositorFrame()); |
| 721 scoped_ptr<cc::CompositorFrame> frame = CompositeHw(); |
| 722 if (frame.get()) { |
| 723 shared_renderer_state_->SetCompositorFrame(frame.Pass(), true); |
| 724 } |
| 725 } else { |
| 726 ForceFakeCompositeSW(); |
| 727 } |
| 714 } else { | 728 } else { |
| 715 // Pretend we just composited to unblock further invalidates. | 729 // Pretend we just composited to unblock further invalidates. |
| 716 DidComposite(); | 730 DidComposite(); |
| 717 } | 731 } |
| 718 } | 732 } |
| 719 | 733 |
| 720 void BrowserViewRenderer::ForceFakeCompositeSW() { | 734 void BrowserViewRenderer::ForceFakeCompositeSW() { |
| 721 DCHECK(compositor_); | 735 DCHECK(compositor_); |
| 722 SkBitmap bitmap; | 736 SkBitmap bitmap; |
| 723 bitmap.allocN32Pixels(1, 1); | 737 bitmap.allocN32Pixels(1, 1); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 base::StringAppendF(&str, | 782 base::StringAppendF(&str, |
| 769 "overscroll_rounding_error_: %s ", | 783 "overscroll_rounding_error_: %s ", |
| 770 overscroll_rounding_error_.ToString().c_str()); | 784 overscroll_rounding_error_.ToString().c_str()); |
| 771 base::StringAppendF( | 785 base::StringAppendF( |
| 772 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); | 786 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); |
| 773 base::StringAppendF(&str, "clear_view: %d ", clear_view_); | 787 base::StringAppendF(&str, "clear_view: %d ", clear_view_); |
| 774 return str; | 788 return str; |
| 775 } | 789 } |
| 776 | 790 |
| 777 } // namespace android_webview | 791 } // namespace android_webview |
| OLD | NEW |