From 283dddc9fb5997a21cfa24f70d74a4851bafcd8a Mon Sep 17 00:00:00 2001 From: "boliu@chromium.org" Date: Tue, 13 May 2014 15:17:29 +0000 Subject: [PATCH] aw: Fix lost invalidate while playing video BrowserViewRenderer::block_invalidates_ needs to be unset immediately after draw. Posting the unset to UI thread could imply that it comes after the fallback tick, which can cause an invalidate to be dropped. This is especially bad for VideoLayer since the fallback tick does not advance video frames, which means the video could be stuck forever. Fix by unsetting block_invalidates_ and cancelling fallback tick immediately, but only post back to get the invalidate. Internal bug b/14643271 BUG= Review URL: https://codereview.chromium.org/271163002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270101 0039d316-1c4b-4281-b951-d872f2087c98 --- android_webview/browser/browser_view_renderer.cc | 20 ++++++++++++++++++-- android_webview/native/aw_contents.cc | 13 ++----------- android_webview/native/aw_contents.h | 4 ---- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/android_webview/browser/browser_view_renderer.cc b/android_webview/browser/browser_view_renderer.cc index 2fc80229d695..cad7c5b96b7b 100644 --- a/android_webview/browser/browser_view_renderer.cc +++ b/android_webview/browser/browser_view_renderer.cc @@ -664,7 +664,10 @@ void BrowserViewRenderer::EnsureContinuousInvalidation(bool force_invalidate) { if (throttle_fallback_tick) return; - block_invalidates_ = compositor_needs_continuous_invalidate_; + { + base::AutoLock lock(render_thread_lock_); + block_invalidates_ = compositor_needs_continuous_invalidate_; + } // Unretained here is safe because the callback is cancelled when // |fallback_tick_| is destroyed. @@ -713,8 +716,21 @@ bool BrowserViewRenderer::CompositeSW(SkCanvas* canvas) { } void BrowserViewRenderer::DidComposite(bool force_invalidate) { + { + base::AutoLock lock(render_thread_lock_); + block_invalidates_ = false; + } + + if (!ui_task_runner_->BelongsToCurrentThread()) { + ui_task_runner_->PostTask( + FROM_HERE, + base::Bind(&BrowserViewRenderer::EnsureContinuousInvalidation, + ui_thread_weak_ptr_, + force_invalidate)); + return; + } + fallback_tick_.Cancel(); - block_invalidates_ = false; EnsureContinuousInvalidation(force_invalidate); } diff --git a/android_webview/native/aw_contents.cc b/android_webview/native/aw_contents.cc index 78d6a5a07448..b9db7c11f071 100644 --- a/android_webview/native/aw_contents.cc +++ b/android_webview/native/aw_contents.cc @@ -151,9 +151,7 @@ AwContents* AwContents::FromID(int render_process_id, int render_view_id) { } AwContents::AwContents(scoped_ptr web_contents) - : weak_factory_on_ui_thread_(this), - ui_thread_weak_ptr_(weak_factory_on_ui_thread_.GetWeakPtr()), - web_contents_(web_contents.Pass()), + : web_contents_(web_contents.Pass()), shared_renderer_state_( BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), this), @@ -349,17 +347,10 @@ void AwContents::DrawGL(AwDrawGLInfo* draw_info) { state_restore.framebuffer_binding_ext(), draw_info, &result)) { - content::BrowserThread::PostTask( - content::BrowserThread::UI, - FROM_HERE, - base::Bind(&AwContents::DidDrawGL, ui_thread_weak_ptr_, result)); + browser_view_renderer_.DidDrawGL(result); } } -void AwContents::DidDrawGL(const DrawGLResult& result) { - browser_view_renderer_.DidDrawGL(result); -} - namespace { void DocumentHasImagesCallback(const ScopedJavaGlobalRef& message, bool has_images) { diff --git a/android_webview/native/aw_contents.h b/android_webview/native/aw_contents.h index 3479b457863f..73c10362f46c 100644 --- a/android_webview/native/aw_contents.h +++ b/android_webview/native/aw_contents.h @@ -216,15 +216,11 @@ class AwContents : public FindHelper::Listener, private: void InitDataReductionProxyIfNecessary(); void InitAutofillIfNecessary(bool enabled); - void DidDrawGL(const DrawGLResult& result); void InitializeHardwareDrawIfNeeded(); void InitializeHardwareDrawOnRenderThread(); void ReleaseHardwareDrawOnRenderThread(); - base::WeakPtrFactory weak_factory_on_ui_thread_; - base::WeakPtr ui_thread_weak_ptr_; - JavaObjectWeakGlobalRef java_ref_; scoped_ptr web_contents_; scoped_ptr web_contents_delegate_; -- 2.11.4.GIT