diff options
author | boliu <boliu@chromium.org> | 2014-10-21 16:23:57 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-21 23:25:31 +0000 |
commit | 6b96a049428fceb4af34a5ea92b106ae208ea75b (patch) | |
tree | 4728e16cf9bf5f5b65cae147f920f61c6b2fe2ac | |
parent | 05bc9c84e44660e9ba56f5566092228d3674679a (diff) | |
download | chromium_src-6b96a049428fceb4af34a5ea92b106ae208ea75b.zip chromium_src-6b96a049428fceb4af34a5ea92b106ae208ea75b.tar.gz chromium_src-6b96a049428fceb4af34a5ea92b106ae208ea75b.tar.bz2 |
aw: Ensure invalidation when pipeline is stalled
* If CommitFrame is skipped to to stall, ensure we invalidate.
* Make sure force_invalidate does not get cancelled by a
pending fallback tick.
* Allow hardware initialization even when visible rect is
empty, so fallback tick is always in the right mode.
* Fix visible rect empty checks.
BUG=425372
Review URL: https://codereview.chromium.org/654403006
Cr-Commit-Position: refs/heads/master@{#300566}
-rw-r--r-- | android_webview/browser/browser_view_renderer.cc | 50 | ||||
-rw-r--r-- | android_webview/browser/browser_view_renderer.h | 5 | ||||
-rw-r--r-- | android_webview/browser/browser_view_renderer_client.h | 3 | ||||
-rw-r--r-- | android_webview/browser/hardware_renderer.cc | 1 | ||||
-rw-r--r-- | android_webview/browser/shared_renderer_state.cc | 12 | ||||
-rw-r--r-- | android_webview/browser/shared_renderer_state.h | 2 | ||||
-rw-r--r-- | android_webview/native/aw_contents.cc | 5 | ||||
-rw-r--r-- | android_webview/native/aw_contents.h | 1 |
8 files changed, 62 insertions, 17 deletions
diff --git a/android_webview/browser/browser_view_renderer.cc b/android_webview/browser/browser_view_renderer.cc index be3e162..cbe3185 100644 --- a/android_webview/browser/browser_view_renderer.cc +++ b/android_webview/browser/browser_view_renderer.cc @@ -85,6 +85,7 @@ BrowserViewRenderer::BrowserViewRenderer( on_new_picture_enable_(false), clear_view_(false), compositor_needs_continuous_invalidate_(false), + invalidate_after_composite_(false), block_invalidates_(false), fallback_tick_pending_(false), width_(0), @@ -211,13 +212,6 @@ bool BrowserViewRenderer::OnDrawHardware(jobject java_canvas) { return false; shared_renderer_state_->SetScrollOffset(last_on_draw_scroll_offset_); - if (last_on_draw_global_visible_rect_.IsEmpty()) { - TRACE_EVENT_INSTANT0("android_webview", - "EarlyOut_EmptyVisibleRect", - TRACE_EVENT_SCOPE_THREAD); - shared_renderer_state_->SetForceInvalidateOnNextDrawGL(true); - return client_->RequestDrawGL(java_canvas, false); - } if (!hardware_enabled_) { hardware_enabled_ = compositor_->InitializeHwDraw(); @@ -228,12 +222,21 @@ bool BrowserViewRenderer::OnDrawHardware(jobject java_canvas) { if (!hardware_enabled_) return false; + if (last_on_draw_global_visible_rect_.IsEmpty() && + parent_draw_constraints_.surface_rect.IsEmpty()) { + TRACE_EVENT_INSTANT0("android_webview", + "EarlyOut_EmptyVisibleRect", + TRACE_EVENT_SCOPE_THREAD); + shared_renderer_state_->SetForceInvalidateOnNextDrawGL(true); + return client_->RequestDrawGL(java_canvas, false); + } + ReturnResourceFromParent(); if (shared_renderer_state_->HasCompositorFrame()) { TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_PreviousFrameUnconsumed", TRACE_EVENT_SCOPE_THREAD); - SkippedCompositeInDraw(); + DidSkipCompositeInDraw(); return client_->RequestDrawGL(java_canvas, false); } @@ -262,10 +265,12 @@ scoped_ptr<cc::CompositorFrame> BrowserViewRenderer::CompositeHw() { // applied onto the layer so global visible rect does not make sense here. // In this case, just use the surface rect for tiling. gfx::Rect viewport_rect_for_tile_priority; - if (parent_draw_constraints_.is_layer) + if (parent_draw_constraints_.is_layer || + last_on_draw_global_visible_rect_.IsEmpty()) { viewport_rect_for_tile_priority = parent_draw_constraints_.surface_rect; - else + } else { viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; + } scoped_ptr<cc::CompositorFrame> frame = compositor_->DemandDrawHw(surface_size, @@ -282,11 +287,13 @@ scoped_ptr<cc::CompositorFrame> BrowserViewRenderer::CompositeHw() { void BrowserViewRenderer::UpdateParentDrawConstraints() { // Post an invalidate if the parent draw constraints are stale and there is // no pending invalidate. - if (shared_renderer_state_->NeedsForceInvalidateOnNextDrawGL() || + bool needs_force_invalidate = + shared_renderer_state_->NeedsForceInvalidateOnNextDrawGL(); + if (needs_force_invalidate || !parent_draw_constraints_.Equals( - shared_renderer_state_->ParentDrawConstraints())) { + shared_renderer_state_->ParentDrawConstraints())) { shared_renderer_state_->SetForceInvalidateOnNextDrawGL(false); - EnsureContinuousInvalidation(true, false); + EnsureContinuousInvalidation(true, needs_force_invalidate); } } @@ -310,6 +317,11 @@ void BrowserViewRenderer::ReturnResourceFromParent() { } } +void BrowserViewRenderer::DidSkipCommitFrame() { + // Treat it the same way as skipping onDraw. + DidSkipCompositeInDraw(); +} + bool BrowserViewRenderer::OnDrawSoftware(jobject java_canvas) { if (!compositor_) { TRACE_EVENT_INSTANT0( @@ -656,12 +668,18 @@ void BrowserViewRenderer::DidOverscroll(gfx::Vector2dF accumulated_overscroll, void BrowserViewRenderer::EnsureContinuousInvalidation( bool force_invalidate, bool skip_reschedule_tick) { + if (force_invalidate) + invalidate_after_composite_ = true; + // This method should be called again when any of these conditions change. bool need_invalidate = - compositor_needs_continuous_invalidate_ || force_invalidate; + compositor_needs_continuous_invalidate_ || invalidate_after_composite_; if (!need_invalidate || block_invalidates_) return; + if (!compositor_needs_continuous_invalidate_ && invalidate_after_composite_) + invalidate_after_composite_ = false; + // 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(); @@ -764,9 +782,9 @@ void BrowserViewRenderer::DidComposite() { EnsureContinuousInvalidation(false, false); } -void BrowserViewRenderer::SkippedCompositeInDraw() { +void BrowserViewRenderer::DidSkipCompositeInDraw() { block_invalidates_ = false; - EnsureContinuousInvalidation(false, true); + EnsureContinuousInvalidation(true, true); } std::string BrowserViewRenderer::ToString() const { diff --git a/android_webview/browser/browser_view_renderer.h b/android_webview/browser/browser_view_renderer.h index 61fadc1..1fc5650 100644 --- a/android_webview/browser/browser_view_renderer.h +++ b/android_webview/browser/browser_view_renderer.h @@ -141,6 +141,7 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient, bool effective_immediately) override; void UpdateParentDrawConstraints(); + void DidSkipCommitFrame(); private: void SetTotalRootLayerScrollOffset(gfx::Vector2dF new_value_dip); @@ -154,7 +155,7 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient, bool OnDrawSoftware(jobject java_canvas); bool CompositeSW(SkCanvas* canvas); void DidComposite(); - void SkippedCompositeInDraw(); + void DidSkipCompositeInDraw(); scoped_refptr<base::debug::ConvertableToTraceFormat> RootLayerStateAsValue( const gfx::Vector2dF& total_scroll_offset_dip, const gfx::SizeF& scrollable_size_dip); @@ -216,6 +217,8 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient, // states. bool compositor_needs_continuous_invalidate_; + bool invalidate_after_composite_; + // Used to block additional invalidates while one is already pending. bool block_invalidates_; diff --git a/android_webview/browser/browser_view_renderer_client.h b/android_webview/browser/browser_view_renderer_client.h index 2fba4d2..ebf5b7b 100644 --- a/android_webview/browser/browser_view_renderer_client.h +++ b/android_webview/browser/browser_view_renderer_client.h @@ -31,6 +31,9 @@ class BrowserViewRendererClient { // Called to update the parent draw constraints in browser view renderer. virtual void UpdateParentDrawConstraints() = 0; + // Called if commit is skipped due to pipeline stall. + virtual void DidSkipCommitFrame() = 0; + // Called to get view's absolute location on the screen. virtual gfx::Point GetLocationOnScreen() = 0; diff --git a/android_webview/browser/hardware_renderer.cc b/android_webview/browser/hardware_renderer.cc index 49679a9..3511bb8 100644 --- a/android_webview/browser/hardware_renderer.cc +++ b/android_webview/browser/hardware_renderer.cc @@ -144,6 +144,7 @@ void HardwareRenderer::CommitFrame() { TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_PreviousFrameUnconsumed", TRACE_EVENT_SCOPE_THREAD); + shared_renderer_state_->DidSkipCommitFrame(); return; } diff --git a/android_webview/browser/shared_renderer_state.cc b/android_webview/browser/shared_renderer_state.cc index 5450da6..0de8371 100644 --- a/android_webview/browser/shared_renderer_state.cc +++ b/android_webview/browser/shared_renderer_state.cc @@ -186,6 +186,18 @@ void SharedRendererState::PostExternalDrawConstraintsToChildCompositor( } } +void SharedRendererState::DidSkipCommitFrame() { + ui_loop_->PostTask( + FROM_HERE, + base::Bind(&SharedRendererState::DidSkipCommitFrameOnUIThread, + ui_thread_weak_ptr_)); +} + +void SharedRendererState::DidSkipCommitFrameOnUIThread() { + DCHECK(ui_loop_->BelongsToCurrentThread()); + client_on_ui_->DidSkipCommitFrame(); +} + const ParentCompositorDrawConstraints SharedRendererState::ParentDrawConstraints() const { base::AutoLock lock(lock_); diff --git a/android_webview/browser/shared_renderer_state.h b/android_webview/browser/shared_renderer_state.h index 9b60cf1..29d05c2 100644 --- a/android_webview/browser/shared_renderer_state.h +++ b/android_webview/browser/shared_renderer_state.h @@ -49,6 +49,7 @@ class SharedRendererState { const ParentCompositorDrawConstraints& parent_draw_constraints); void PostExternalDrawConstraintsToChildCompositor( const ParentCompositorDrawConstraints& parent_draw_constraints); + void DidSkipCommitFrame(); const ParentCompositorDrawConstraints ParentDrawConstraints() const; @@ -67,6 +68,7 @@ class SharedRendererState { void ResetRequestDrawGLCallback(); void ClientRequestDrawGLOnUIThread(); void UpdateParentDrawConstraintsOnUIThread(); + void DidSkipCommitFrameOnUIThread(); void SetInsideHardwareRelease(bool inside); scoped_refptr<base::MessageLoopProxy> ui_loop_; diff --git a/android_webview/native/aw_contents.cc b/android_webview/native/aw_contents.cc index c0da925..eac4600 100644 --- a/android_webview/native/aw_contents.cc +++ b/android_webview/native/aw_contents.cc @@ -774,6 +774,11 @@ void AwContents::UpdateParentDrawConstraints() { browser_view_renderer_.UpdateParentDrawConstraints(); } +void AwContents::DidSkipCommitFrame() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + browser_view_renderer_.DidSkipCommitFrame(); +} + void AwContents::OnNewPicture() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); JNIEnv* env = AttachCurrentThread(); diff --git a/android_webview/native/aw_contents.h b/android_webview/native/aw_contents.h index e49d842..f350b73 100644 --- a/android_webview/native/aw_contents.h +++ b/android_webview/native/aw_contents.h @@ -192,6 +192,7 @@ class AwContents : public FindHelper::Listener, virtual bool RequestDrawGL(jobject canvas, bool wait_for_completion) override; virtual void PostInvalidate() override; virtual void UpdateParentDrawConstraints() override; + virtual void DidSkipCommitFrame() override; virtual void OnNewPicture() override; virtual gfx::Point GetLocationOnScreen() override; virtual void ScrollContainerViewTo(gfx::Vector2d new_value) override; |