Chromium Code Reviews| Index: android_webview/browser/browser_view_renderer.cc |
| diff --git a/android_webview/browser/browser_view_renderer.cc b/android_webview/browser/browser_view_renderer.cc |
| index 6b4ee929ec07988429f16de61e0a5c6adfcb112d..3644d89b308f236a6487fb90b8f2e94e91c0bc2e 100644 |
| --- a/android_webview/browser/browser_view_renderer.cc |
| +++ b/android_webview/browser/browser_view_renderer.cc |
| @@ -98,8 +98,6 @@ BrowserViewRenderer::BrowserViewRenderer( |
| on_new_picture_enable_(false), |
| clear_view_(false), |
| offscreen_pre_raster_(false), |
| - compositor_needs_continuous_invalidate_(false), |
| - block_invalidates_(false), |
| fallback_tick_pending_(false) { |
| } |
| @@ -198,6 +196,11 @@ bool BrowserViewRenderer::CanOnDraw() { |
| bool BrowserViewRenderer::OnDrawHardware() { |
| TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDrawHardware"); |
| + |
| + post_fallback_tick_.Cancel(); |
| + fallback_tick_fired_.Cancel(); |
| + fallback_tick_pending_ = false; |
|
boliu
2015/03/20 18:59:06
Factor this out into a CancelFallbackTick function
sunnyps
2015/03/20 22:48:39
Done.
|
| + |
| shared_renderer_state_.InitializeHardwareDrawIfNeededOnUI(); |
| if (!CanOnDraw()) { |
| @@ -263,7 +266,6 @@ bool BrowserViewRenderer::CompositeHw() { |
| transform_for_tile_priority, offscreen_pre_raster_, |
| parent_draw_constraints.is_layer)); |
| - DidComposite(); |
| // Uncommitted frame can happen with consecutive fallback ticks. |
| ReturnUnusedResource(shared_renderer_state_.PassUncommittedFrameOnUI()); |
| shared_renderer_state_.SetCompositorFrameOnUI(child_frame.Pass()); |
| @@ -271,10 +273,10 @@ bool BrowserViewRenderer::CompositeHw() { |
| } |
| void BrowserViewRenderer::UpdateParentDrawConstraints() { |
| - EnsureContinuousInvalidation(true); |
| ParentCompositorDrawConstraints parent_draw_constraints = |
| shared_renderer_state_.GetParentDrawConstraintsOnUI(); |
| client_->ParentDrawConstraintsUpdated(parent_draw_constraints); |
| + PostInvalidateWithFallback(); |
|
boliu
2015/03/20 18:59:06
Put this before the client update, where EnsureCon
sunnyps
2015/03/20 22:48:39
Done.
|
| } |
| void BrowserViewRenderer::ReturnUnusedResource( |
| @@ -303,6 +305,10 @@ void BrowserViewRenderer::DetachFunctorFromView() { |
| } |
| bool BrowserViewRenderer::OnDrawSoftware(SkCanvas* canvas) { |
| + post_fallback_tick_.Cancel(); |
| + fallback_tick_fired_.Cancel(); |
| + fallback_tick_pending_ = false; |
| + |
| return CanOnDraw() && CompositeSW(canvas); |
| } |
| @@ -342,7 +348,7 @@ void BrowserViewRenderer::ClearView() { |
| clear_view_ = true; |
| // Always invalidate ignoring the compositor to actually clear the webview. |
| - EnsureContinuousInvalidation(true); |
| + PostInvalidateWithFallback(); |
| } |
| void BrowserViewRenderer::SetOffscreenPreRaster(bool enable) { |
| @@ -357,7 +363,7 @@ void BrowserViewRenderer::SetIsPaused(bool paused) { |
| "paused", |
| paused); |
| is_paused_ = paused; |
| - EnsureContinuousInvalidation(false); |
| + UpdateCompositorIsActive(); |
| } |
| void BrowserViewRenderer::SetViewVisibility(bool view_visible) { |
| @@ -376,7 +382,7 @@ void BrowserViewRenderer::SetWindowVisibility(bool window_visible) { |
| "window_visible", |
| window_visible); |
| window_visible_ = window_visible; |
| - EnsureContinuousInvalidation(false); |
| + UpdateCompositorIsActive(); |
| } |
| void BrowserViewRenderer::OnSizeChanged(int width, int height) { |
| @@ -399,6 +405,7 @@ void BrowserViewRenderer::OnAttachedToWindow(int width, int height) { |
| height); |
| attached_to_window_ = true; |
| size_.SetSize(width, height); |
| + UpdateCompositorIsActive(); |
| } |
| void BrowserViewRenderer::OnDetachedFromWindow() { |
| @@ -406,6 +413,7 @@ void BrowserViewRenderer::OnDetachedFromWindow() { |
| shared_renderer_state_.ReleaseHardwareDrawIfNeededOnUI(); |
| attached_to_window_ = false; |
| DCHECK(!hardware_enabled_); |
| + UpdateCompositorIsActive(); |
| } |
| void BrowserViewRenderer::ReleaseHardware() { |
| @@ -437,6 +445,7 @@ void BrowserViewRenderer::DidInitializeCompositor( |
| DCHECK(compositor); |
| DCHECK(!compositor_); |
| compositor_ = compositor; |
| + UpdateCompositorIsActive(); |
| } |
| void BrowserViewRenderer::DidDestroyCompositor( |
| @@ -446,20 +455,6 @@ void BrowserViewRenderer::DidDestroyCompositor( |
| compositor_ = NULL; |
| } |
| -void BrowserViewRenderer::SetContinuousInvalidate(bool invalidate) { |
| - if (compositor_needs_continuous_invalidate_ == invalidate) |
| - return; |
| - |
| - TRACE_EVENT_INSTANT1("android_webview", |
| - "BrowserViewRenderer::SetContinuousInvalidate", |
| - TRACE_EVENT_SCOPE_THREAD, |
| - "invalidate", |
| - invalidate); |
| - compositor_needs_continuous_invalidate_ = invalidate; |
| - |
| - EnsureContinuousInvalidation(false); |
| -} |
| - |
| void BrowserViewRenderer::SetDipScale(float dip_scale) { |
| dip_scale_ = dip_scale; |
| CHECK_GT(dip_scale_, 0.f); |
| @@ -627,17 +622,13 @@ void BrowserViewRenderer::DidOverscroll(gfx::Vector2dF accumulated_overscroll, |
| client_->DidOverscroll(rounded_overscroll_delta); |
| } |
| -void BrowserViewRenderer::EnsureContinuousInvalidation(bool force_invalidate) { |
| - // This method should be called again when any of these conditions change. |
| - bool need_invalidate = |
| - compositor_needs_continuous_invalidate_ || force_invalidate; |
| - if (!need_invalidate || block_invalidates_) |
| - return; |
| - |
| - // Always call view invalidate. We rely the Android framework to ignore the |
| - // invalidate when it's not needed such as when view is not visible. |
| - client_->PostInvalidate(); |
| +void BrowserViewRenderer::PostInvalidate() { |
| + TRACE_EVENT_INSTANT0("android_webview", "BrowserViewRenderer::PostInvalidate", |
| + TRACE_EVENT_SCOPE_THREAD); |
| + PostInvalidateWithFallback(); |
| +} |
| +void BrowserViewRenderer::PostInvalidateWithFallback() { |
| // Stop fallback ticks when one of these is true. |
| // 1) Webview is paused. Also need to check we are not in clear view since |
| // paused, offscreen still expect clear view to recover. |
| @@ -646,63 +637,47 @@ void BrowserViewRenderer::EnsureContinuousInvalidation(bool force_invalidate) { |
| // "on-screen" but that updates are not needed when in the background. |
| bool throttle_fallback_tick = |
| (is_paused_ && !clear_view_) || (attached_to_window_ && !window_visible_); |
| - if (throttle_fallback_tick) |
| - return; |
| - block_invalidates_ = compositor_needs_continuous_invalidate_; |
| - if (fallback_tick_pending_) |
| + if (throttle_fallback_tick || fallback_tick_pending_) |
| return; |
| - // Unretained here is safe because the callbacks are cancelled when |
| - // they are destroyed. |
| + // Always call view invalidate. We rely the Android framework to ignore the |
| + // invalidate when it's not needed such as when view is not visible. |
| + client_->PostInvalidate(); |
|
boliu
2015/03/20 18:59:06
This should be above the throttle/fallback pending
sunnyps
2015/03/20 22:48:39
Done.
|
| + |
| + DCHECK(post_fallback_tick_.IsCancelled()); |
| + DCHECK(fallback_tick_fired_.IsCancelled()); |
| + |
| post_fallback_tick_.Reset(base::Bind(&BrowserViewRenderer::PostFallbackTick, |
| base::Unretained(this))); |
| - fallback_tick_fired_.Cancel(); |
| - fallback_tick_pending_ = false; |
| - |
| - // No need to reschedule fallback tick if compositor does not need to be |
| - // ticked. This can happen if this is reached because force_invalidate is |
| - // true. |
| - if (compositor_needs_continuous_invalidate_) { |
| - fallback_tick_pending_ = true; |
| - ui_task_runner_->PostTask(FROM_HERE, post_fallback_tick_.callback()); |
| - } |
| + ui_task_runner_->PostTask(FROM_HERE, post_fallback_tick_.callback()); |
| + fallback_tick_pending_ = true; |
| } |
| void BrowserViewRenderer::PostFallbackTick() { |
| DCHECK(fallback_tick_fired_.IsCancelled()); |
| + TRACE_EVENT0("android_webview", "BrowserViewRenderer::PostFallbackTick"); |
| + post_fallback_tick_.Cancel(); |
| fallback_tick_fired_.Reset(base::Bind(&BrowserViewRenderer::FallbackTickFired, |
| base::Unretained(this))); |
| - if (compositor_needs_continuous_invalidate_) { |
| - ui_task_runner_->PostDelayedTask( |
| - FROM_HERE, |
| - fallback_tick_fired_.callback(), |
| - base::TimeDelta::FromMilliseconds(kFallbackTickTimeoutInMilliseconds)); |
| - } else { |
| - // Pretend we just composited to unblock further invalidates. |
| - DidComposite(); |
| - } |
| + ui_task_runner_->PostDelayedTask( |
| + FROM_HERE, fallback_tick_fired_.callback(), |
| + base::TimeDelta::FromMilliseconds(kFallbackTickTimeoutInMilliseconds)); |
| } |
| void BrowserViewRenderer::FallbackTickFired() { |
| - TRACE_EVENT1("android_webview", |
| - "BrowserViewRenderer::FallbackTickFired", |
| - "compositor_needs_continuous_invalidate_", |
| - compositor_needs_continuous_invalidate_); |
| - |
| + TRACE_EVENT0("android_webview", "BrowserViewRenderer::FallbackTickFired"); |
| // This should only be called if OnDraw or DrawGL did not come in time, which |
| - // means block_invalidates_ must still be true. |
| - DCHECK(block_invalidates_); |
| + // means fallback_tick_pending_ must still be true. |
| + DCHECK(fallback_tick_pending_); |
| + fallback_tick_fired_.Cancel(); |
| fallback_tick_pending_ = false; |
| - if (compositor_needs_continuous_invalidate_ && compositor_) { |
| + if (compositor_) { |
| if (hardware_enabled_) { |
| CompositeHw(); |
| } else { |
| ForceFakeCompositeSW(); |
| } |
| - } else { |
| - // Pretend we just composited to unblock further invalidates. |
| - DidComposite(); |
| } |
| } |
| @@ -718,17 +693,13 @@ void BrowserViewRenderer::ForceFakeCompositeSW() { |
| bool BrowserViewRenderer::CompositeSW(SkCanvas* canvas) { |
| DCHECK(compositor_); |
| ReturnResourceFromParent(); |
| - bool result = compositor_->DemandDrawSw(canvas); |
| - DidComposite(); |
| - return result; |
| + return compositor_->DemandDrawSw(canvas); |
| } |
| -void BrowserViewRenderer::DidComposite() { |
| - block_invalidates_ = false; |
| - post_fallback_tick_.Cancel(); |
| - fallback_tick_fired_.Cancel(); |
| - fallback_tick_pending_ = false; |
| - EnsureContinuousInvalidation(false); |
| +void BrowserViewRenderer::UpdateCompositorIsActive() { |
| + if (compositor_) |
| + compositor_->SetIsActive(!is_paused_ && |
| + (!attached_to_window_ || window_visible_)); |
| } |
| std::string BrowserViewRenderer::ToString() const { |
| @@ -738,10 +709,8 @@ std::string BrowserViewRenderer::ToString() const { |
| base::StringAppendF(&str, "window_visible: %d ", window_visible_); |
| base::StringAppendF(&str, "dip_scale: %f ", dip_scale_); |
| base::StringAppendF(&str, "page_scale_factor: %f ", page_scale_factor_); |
| - base::StringAppendF(&str, |
| - "compositor_needs_continuous_invalidate: %d ", |
| - compositor_needs_continuous_invalidate_); |
| - base::StringAppendF(&str, "block_invalidates: %d ", block_invalidates_); |
| + base::StringAppendF(&str, "fallback_tick_pending: %d ", |
| + fallback_tick_pending_); |
| base::StringAppendF(&str, "view size: %s ", size_.ToString().c_str()); |
| base::StringAppendF(&str, "attached_to_window: %d ", attached_to_window_); |
| base::StringAppendF(&str, |