Index: cc/trees/thread_proxy.cc |
diff --git a/cc/trees/thread_proxy.cc b/cc/trees/thread_proxy.cc |
index a7c408613f069af52e3e3ec831b78c6c8343616a..22bba7aeed385a83dc3b26e666670921a66adc8d 100644 |
--- a/cc/trees/thread_proxy.cc |
+++ b/cc/trees/thread_proxy.cc |
@@ -10,7 +10,6 @@ |
#include "base/bind.h" |
#include "base/debug/trace_event.h" |
#include "base/metrics/histogram.h" |
-#include "cc/base/thread.h" |
#include "cc/input/input_handler.h" |
#include "cc/output/context_provider.h" |
#include "cc/output/output_surface.h" |
@@ -55,15 +54,17 @@ struct ThreadProxy::SchedulerStateRequest { |
std::string state; |
}; |
-scoped_ptr<Proxy> ThreadProxy::Create(LayerTreeHost* layer_tree_host, |
- scoped_ptr<Thread> impl_thread) { |
+scoped_ptr<Proxy> ThreadProxy::Create( |
+ LayerTreeHost* layer_tree_host, |
+ scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { |
return make_scoped_ptr( |
- new ThreadProxy(layer_tree_host, impl_thread.Pass())).PassAs<Proxy>(); |
+ new ThreadProxy(layer_tree_host, impl_task_runner)).PassAs<Proxy>(); |
} |
-ThreadProxy::ThreadProxy(LayerTreeHost* layer_tree_host, |
- scoped_ptr<Thread> impl_thread) |
- : Proxy(impl_thread.Pass()), |
+ThreadProxy::ThreadProxy( |
+ LayerTreeHost* layer_tree_host, |
+ scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) |
+ : Proxy(impl_task_runner), |
animate_requested_(false), |
commit_requested_(false), |
commit_request_sent_to_impl_thread_(false), |
@@ -117,7 +118,8 @@ bool ThreadProxy::CompositeAndReadback(void* pixels, gfx::Rect rect) { |
{ |
DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
CompletionEvent begin_frame_sent_to_main_thread_completion; |
- Proxy::ImplThread()->PostTask( |
+ Proxy::ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
base::Bind(&ThreadProxy::ForceCommitOnImplThread, |
impl_thread_weak_ptr_, |
&begin_frame_sent_to_main_thread_completion)); |
@@ -133,7 +135,8 @@ bool ThreadProxy::CompositeAndReadback(void* pixels, gfx::Rect rect) { |
request.pixels = pixels; |
{ |
DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
- Proxy::ImplThread()->PostTask( |
+ Proxy::ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
base::Bind(&ThreadProxy::RequestReadbackOnImplThread, |
impl_thread_weak_ptr_, |
&request)); |
@@ -177,7 +180,8 @@ void ThreadProxy::FinishAllRendering() { |
// Make sure all GL drawing is finished on the impl thread. |
DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
CompletionEvent completion; |
- Proxy::ImplThread()->PostTask( |
+ Proxy::ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
base::Bind(&ThreadProxy::FinishAllRenderingOnImplThread, |
impl_thread_weak_ptr_, |
&completion)); |
@@ -191,9 +195,10 @@ bool ThreadProxy::IsStarted() const { |
void ThreadProxy::SetLayerTreeHostClientReady() { |
TRACE_EVENT0("cc", "ThreadProxy::SetLayerTreeHostClientReady"); |
- Proxy::ImplThread()->PostTask(base::Bind( |
- &ThreadProxy::SetLayerTreeHostClientReadyOnImplThread, |
- impl_thread_weak_ptr_)); |
+ Proxy::ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&ThreadProxy::SetLayerTreeHostClientReadyOnImplThread, |
+ impl_thread_weak_ptr_)); |
} |
void ThreadProxy::SetLayerTreeHostClientReadyOnImplThread() { |
@@ -205,10 +210,12 @@ void ThreadProxy::SetVisible(bool visible) { |
TRACE_EVENT0("cc", "ThreadProxy::SetVisible"); |
DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
CompletionEvent completion; |
- Proxy::ImplThread()->PostTask(base::Bind(&ThreadProxy::SetVisibleOnImplThread, |
- impl_thread_weak_ptr_, |
- &completion, |
- visible)); |
+ Proxy::ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&ThreadProxy::SetVisibleOnImplThread, |
+ impl_thread_weak_ptr_, |
+ &completion, |
+ visible)); |
completion.Wait(); |
} |
@@ -254,7 +261,8 @@ void ThreadProxy::DoCreateAndInitializeOutputSurface() { |
CompletionEvent completion; |
DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
- Proxy::ImplThread()->PostTask( |
+ Proxy::ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
base::Bind(&ThreadProxy::InitializeOutputSurfaceOnImplThread, |
impl_thread_weak_ptr_, |
&completion, |
@@ -282,8 +290,8 @@ void ThreadProxy::OnOutputSurfaceInitializeAttempted( |
layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success); |
if (result == LayerTreeHost::CreateFailedButTryAgain) { |
if (!output_surface_creation_callback_.callback().is_null()) { |
- Proxy::MainThread()->PostTask( |
- output_surface_creation_callback_.callback()); |
+ Proxy::MainThreadTaskRunner()->PostTask( |
+ FROM_HERE, output_surface_creation_callback_.callback()); |
} |
} else { |
output_surface_creation_callback_.Cancel(); |
@@ -307,8 +315,10 @@ void ThreadProxy::SetNeedsAnimate() { |
if (commit_request_sent_to_impl_thread_) |
return; |
commit_request_sent_to_impl_thread_ = true; |
- Proxy::ImplThread()->PostTask(base::Bind( |
- &ThreadProxy::SetNeedsCommitOnImplThread, impl_thread_weak_ptr_)); |
+ Proxy::ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&ThreadProxy::SetNeedsCommitOnImplThread, |
+ impl_thread_weak_ptr_)); |
} |
void ThreadProxy::SetNeedsCommit() { |
@@ -321,14 +331,17 @@ void ThreadProxy::SetNeedsCommit() { |
if (commit_request_sent_to_impl_thread_) |
return; |
commit_request_sent_to_impl_thread_ = true; |
- Proxy::ImplThread()->PostTask(base::Bind( |
- &ThreadProxy::SetNeedsCommitOnImplThread, impl_thread_weak_ptr_)); |
+ Proxy::ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&ThreadProxy::SetNeedsCommitOnImplThread, |
+ impl_thread_weak_ptr_)); |
} |
void ThreadProxy::DidLoseOutputSurfaceOnImplThread() { |
DCHECK(IsImplThread()); |
TRACE_EVENT0("cc", "ThreadProxy::DidLoseOutputSurfaceOnImplThread"); |
- Proxy::ImplThread()->PostTask( |
+ Proxy::ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
base::Bind(&ThreadProxy::CheckOutputSurfaceStatusOnImplThread, |
impl_thread_weak_ptr_)); |
} |
@@ -351,7 +364,8 @@ void ThreadProxy::CheckOutputSurfaceStatusOnImplThread() { |
void ThreadProxy::OnSwapBuffersCompleteOnImplThread() { |
DCHECK(IsImplThread()); |
TRACE_EVENT0("cc", "ThreadProxy::OnSwapBuffersCompleteOnImplThread"); |
- Proxy::MainThread()->PostTask( |
+ Proxy::MainThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
base::Bind(&ThreadProxy::DidCompleteSwapBuffers, main_thread_weak_ptr_)); |
} |
@@ -396,10 +410,12 @@ void ThreadProxy::PostAnimationEventsToMainThreadOnImplThread( |
DCHECK(IsImplThread()); |
TRACE_EVENT0("cc", |
"ThreadProxy::PostAnimationEventsToMainThreadOnImplThread"); |
- Proxy::MainThread()->PostTask(base::Bind(&ThreadProxy::SetAnimationEvents, |
- main_thread_weak_ptr_, |
- base::Passed(&events), |
- wall_clock_time)); |
+ Proxy::MainThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&ThreadProxy::SetAnimationEvents, |
+ main_thread_weak_ptr_, |
+ base::Passed(&events), |
+ wall_clock_time)); |
} |
bool ThreadProxy::ReduceContentsTextureMemoryOnImplThread(size_t limit_bytes, |
@@ -464,9 +480,11 @@ bool ThreadProxy::IsInsideDraw() { return inside_draw_; } |
void ThreadProxy::SetNeedsRedraw(gfx::Rect damage_rect) { |
DCHECK(IsMainThread()); |
TRACE_EVENT0("cc", "ThreadProxy::SetNeedsRedraw"); |
- Proxy::ImplThread()->PostTask(base::Bind( |
- &ThreadProxy::SetNeedsRedrawRectOnImplThread, |
- impl_thread_weak_ptr_, damage_rect)); |
+ Proxy::ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&ThreadProxy::SetNeedsRedrawRectOnImplThread, |
+ impl_thread_weak_ptr_, |
+ damage_rect)); |
} |
void ThreadProxy::SetDeferCommits(bool defer_commits) { |
@@ -480,7 +498,8 @@ void ThreadProxy::SetDeferCommits(bool defer_commits) { |
TRACE_EVENT_ASYNC_END0("cc", "ThreadProxy::SetDeferCommits", this); |
if (!defer_commits_ && pending_deferred_commit_) |
- Proxy::MainThread()->PostTask( |
+ Proxy::MainThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
base::Bind(&ThreadProxy::BeginFrameOnMainThread, |
main_thread_weak_ptr_, |
base::Passed(&pending_deferred_commit_))); |
@@ -517,7 +536,8 @@ void ThreadProxy::DidInitializeVisibleTileOnImplThread() { |
void ThreadProxy::MainThreadHasStoppedFlinging() { |
DCHECK(IsMainThread()); |
- Proxy::ImplThread()->PostTask( |
+ Proxy::ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
base::Bind(&ThreadProxy::MainThreadHasStoppedFlingingOnImplThread, |
impl_thread_weak_ptr_)); |
} |
@@ -529,12 +549,13 @@ void ThreadProxy::MainThreadHasStoppedFlingingOnImplThread() { |
void ThreadProxy::Start(scoped_ptr<OutputSurface> first_output_surface) { |
DCHECK(IsMainThread()); |
- DCHECK(Proxy::ImplThread()); |
+ DCHECK(Proxy::HasImplThread()); |
DCHECK(first_output_surface); |
// Create LayerTreeHostImpl. |
DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
CompletionEvent completion; |
- Proxy::ImplThread()->PostTask( |
+ Proxy::ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
base::Bind(&ThreadProxy::InitializeImplOnImplThread, |
base::Unretained(this), |
&completion)); |
@@ -559,7 +580,8 @@ void ThreadProxy::Stop() { |
DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
CompletionEvent completion; |
- Proxy::ImplThread()->PostTask( |
+ Proxy::ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
base::Bind(&ThreadProxy::FinishGLOnImplThread, |
impl_thread_weak_ptr_, |
&completion)); |
@@ -569,7 +591,8 @@ void ThreadProxy::Stop() { |
DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
CompletionEvent completion; |
- Proxy::ImplThread()->PostTask( |
+ Proxy::ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
base::Bind(&ThreadProxy::LayerTreeHostClosedOnImplThread, |
impl_thread_weak_ptr_, |
&completion)); |
@@ -586,7 +609,8 @@ void ThreadProxy::Stop() { |
void ThreadProxy::ForceSerializeOnSwapBuffers() { |
DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
CompletionEvent completion; |
- Proxy::ImplThread()->PostTask( |
+ Proxy::ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
base::Bind(&ThreadProxy::ForceSerializeOnSwapBuffersOnImplThread, |
impl_thread_weak_ptr_, |
&completion)); |
@@ -618,7 +642,8 @@ void ThreadProxy::ScheduledActionSendBeginFrameToMainThread() { |
DCHECK_GT(layer_tree_host_impl_->memory_allocation_limit_bytes(), 0u); |
begin_frame_state->memory_allocation_limit_bytes = |
layer_tree_host_impl_->memory_allocation_limit_bytes(); |
- Proxy::MainThread()->PostTask( |
+ Proxy::MainThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
base::Bind(&ThreadProxy::BeginFrameOnMainThread, |
main_thread_weak_ptr_, |
base::Passed(&begin_frame_state))); |
@@ -664,9 +689,10 @@ void ThreadProxy::BeginFrameOnMainThread( |
commit_request_sent_to_impl_thread_ = false; |
TRACE_EVENT0("cc", "EarlyOut_NotVisible"); |
- Proxy::ImplThread()->PostTask(base::Bind( |
- &ThreadProxy::BeginFrameAbortedByMainThreadOnImplThread, |
- impl_thread_weak_ptr_)); |
+ Proxy::ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&ThreadProxy::BeginFrameAbortedByMainThreadOnImplThread, |
+ impl_thread_weak_ptr_)); |
return; |
} |
@@ -740,7 +766,8 @@ void ThreadProxy::BeginFrameOnMainThread( |
base::TimeTicks start_time = stats_instrumentation->StartRecording(); |
CompletionEvent completion; |
- Proxy::ImplThread()->PostTask( |
+ Proxy::ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
base::Bind(&ThreadProxy::StartCommitOnImplThread, |
impl_thread_weak_ptr_, |
&completion, |
@@ -801,7 +828,7 @@ void ThreadProxy::StartCommitOnImplThread( |
current_resource_update_controller_on_impl_thread_ = |
ResourceUpdateController::Create( |
this, |
- Proxy::ImplThread()->TaskRunner(), |
+ Proxy::ImplThreadTaskRunner(), |
queue.Pass(), |
layer_tree_host_impl_->resource_provider()); |
current_resource_update_controller_on_impl_thread_->PerformMoreUpdates( |
@@ -877,7 +904,8 @@ void ThreadProxy::ScheduledActionActivatePendingTreeIfNeeded() { |
void ThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { |
DCHECK(IsImplThread()); |
- Proxy::MainThread()->PostTask( |
+ Proxy::MainThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
base::Bind(&ThreadProxy::CreateAndInitializeOutputSurface, |
main_thread_weak_ptr_)); |
} |
@@ -980,7 +1008,8 @@ ThreadProxy::ScheduledActionDrawAndSwapInternal(bool forced_draw) { |
// Tell the main thread that the the newly-commited frame was drawn. |
if (next_frame_is_newly_committed_frame_on_impl_thread_) { |
next_frame_is_newly_committed_frame_on_impl_thread_ = false; |
- Proxy::MainThread()->PostTask( |
+ Proxy::MainThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
base::Bind(&ThreadProxy::DidCommitAndDrawFrame, main_thread_weak_ptr_)); |
} |
@@ -1035,7 +1064,8 @@ void ThreadProxy::AcquireLayerTextures() { |
TRACE_EVENT0("cc", "ThreadProxy::AcquireLayerTextures"); |
DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
CompletionEvent completion; |
- Proxy::ImplThread()->PostTask( |
+ Proxy::ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
base::Bind(&ThreadProxy::AcquireLayerTexturesForMainThreadOnImplThread, |
impl_thread_weak_ptr_, |
&completion)); |
@@ -1122,7 +1152,8 @@ void ThreadProxy::CreateAndInitializeOutputSurface() { |
bool has_initialized_output_surface_on_impl_thread = true; |
{ |
CompletionEvent completion; |
- Proxy::ImplThread()->PostTask( |
+ Proxy::ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
base::Bind(&ThreadProxy::HasInitializedOutputSurfaceOnImplThread, |
impl_thread_weak_ptr_, |
&completion, |
@@ -1248,10 +1279,12 @@ scoped_ptr<base::Value> ThreadProxy::AsValue() const { |
{ |
DebugScopedSetMainThreadBlocked main_thread_blocked( |
const_cast<ThreadProxy*>(this)); |
- Proxy::ImplThread()->PostTask(base::Bind(&ThreadProxy::AsValueOnImplThread, |
- impl_thread_weak_ptr_, |
- &completion, |
- state.get())); |
+ Proxy::ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&ThreadProxy::AsValueOnImplThread, |
+ impl_thread_weak_ptr_, |
+ &completion, |
+ state.get())); |
completion.Wait(); |
} |
return state.PassAs<base::Value>(); |
@@ -1269,7 +1302,8 @@ bool ThreadProxy::CommitPendingForTesting() { |
CommitPendingRequest commit_pending_request; |
{ |
DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
- Proxy::ImplThread()->PostTask( |
+ Proxy::ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
base::Bind(&ThreadProxy::CommitPendingOnImplThreadForTesting, |
impl_thread_weak_ptr_, |
&commit_pending_request)); |
@@ -1295,7 +1329,8 @@ std::string ThreadProxy::SchedulerStateAsStringForTesting() { |
SchedulerStateRequest scheduler_state_request; |
{ |
DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
- Proxy::ImplThread()->PostTask( |
+ Proxy::ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
base::Bind(&ThreadProxy::SchedulerStateAsStringOnImplThreadForTesting, |
impl_thread_weak_ptr_, |
&scheduler_state_request)); |
@@ -1317,7 +1352,8 @@ skia::RefPtr<SkPicture> ThreadProxy::CapturePicture() { |
skia::RefPtr<SkPicture> picture; |
{ |
DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
- Proxy::ImplThread()->PostTask( |
+ Proxy::ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
base::Bind(&ThreadProxy::CapturePictureOnImplThread, |
impl_thread_weak_ptr_, |
&completion, |
@@ -1381,7 +1417,8 @@ void ThreadProxy::RenewTreePriority() { |
if (renew_tree_priority_on_impl_thread_pending_) |
return; |
- Proxy::ImplThread()->PostDelayedTask( |
+ Proxy::ImplThreadTaskRunner()->PostDelayedTask( |
+ FROM_HERE, |
base::Bind(&ThreadProxy::RenewTreePriorityOnImplThread, |
weak_factory_on_impl_thread_.GetWeakPtr()), |
delay); |
@@ -1397,7 +1434,8 @@ void ThreadProxy::RenewTreePriorityOnImplThread() { |
} |
void ThreadProxy::RequestScrollbarAnimationOnImplThread(base::TimeDelta delay) { |
- Proxy::ImplThread()->PostDelayedTask( |
+ Proxy::ImplThreadTaskRunner()->PostDelayedTask( |
+ FROM_HERE, |
base::Bind(&ThreadProxy::StartScrollbarAnimationOnImplThread, |
impl_thread_weak_ptr_), |
delay); |