Index: cc/trees/single_thread_proxy.cc |
diff --git a/cc/trees/single_thread_proxy.cc b/cc/trees/single_thread_proxy.cc |
index 157ecbeeb5ec4695591b26c69766a539a8227394..a629e3185c9d61219093288aba167faa384891ba 100644 |
--- a/cc/trees/single_thread_proxy.cc |
+++ b/cc/trees/single_thread_proxy.cc |
@@ -33,7 +33,10 @@ SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layer_tree_host, |
layer_tree_host_(layer_tree_host), |
client_(client), |
next_frame_is_newly_committed_frame_(false), |
- inside_draw_(false) { |
+ inside_draw_(false), |
+ defer_commits_(false), |
+ finish_commit_deferred_(false), |
+ weak_factory_(this) { |
TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy"); |
DCHECK(Proxy::IsMainThread()); |
DCHECK(layer_tree_host); |
@@ -46,6 +49,10 @@ SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layer_tree_host, |
void SingleThreadProxy::Start() { |
DebugScopedSetImplThread impl(this); |
layer_tree_host_impl_ = layer_tree_host_->CreateLayerTreeHostImpl(this); |
+ SchedulerSettings scheduler_settings(layer_tree_host_->settings()); |
+ scheduler_on_impl_thread_ = Scheduler::Create( |
+ this, scheduler_settings, layer_tree_host_->id(), MainThreadTaskRunner()); |
+ scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); |
} |
SingleThreadProxy::~SingleThreadProxy() { |
@@ -73,12 +80,16 @@ void SingleThreadProxy::SetLayerTreeHostClientReady() { |
TRACE_EVENT0("cc", "SingleThreadProxy::SetLayerTreeHostClientReady"); |
// Scheduling is controlled by the embedder in the single thread case, so |
// nothing to do. |
+ DCHECK(Proxy::IsMainThread()); |
+ DebugScopedSetImplThread impl(this); |
+ scheduler_on_impl_thread_->SetCanStart(); |
} |
void SingleThreadProxy::SetVisible(bool visible) { |
TRACE_EVENT0("cc", "SingleThreadProxy::SetVisible"); |
DebugScopedSetImplThread impl(this); |
layer_tree_host_impl_->SetVisible(visible); |
+ scheduler_on_impl_thread_->SetVisible(layer_tree_host_impl_->visible()); |
// Changing visibility could change ShouldComposite(). |
UpdateBackgroundAnimateTicking(); |
@@ -106,9 +117,13 @@ void SingleThreadProxy::CreateAndInitializeOutputSurface() { |
layer_tree_host_->OnCreateAndInitializeOutputSurfaceAttempted(success); |
- if (!success) { |
- // Force another recreation attempt to happen by requesting another commit. |
- SetNeedsCommit(); |
+ if (success) { |
+ scheduler_on_impl_thread_->DidCreateAndInitializeOutputSurface(); |
+ } else { |
+ Proxy::MainThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&SingleThreadProxy::CreateAndInitializeOutputSurface, |
+ weak_factory_.GetWeakPtr())); |
} |
} |
@@ -121,18 +136,38 @@ const RendererCapabilities& SingleThreadProxy::GetRendererCapabilities() const { |
void SingleThreadProxy::SetNeedsAnimate() { |
TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsAnimate"); |
DCHECK(Proxy::IsMainThread()); |
- client_->ScheduleAnimation(); |
+ SetNeedsCommit(); |
} |
void SingleThreadProxy::SetNeedsUpdateLayers() { |
TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsUpdateLayers"); |
DCHECK(Proxy::IsMainThread()); |
- client_->ScheduleComposite(); |
+ SetNeedsCommit(); |
} |
-void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) { |
+void SingleThreadProxy::DoCommit(base::TimeTicks frame_begin_time) { |
TRACE_EVENT0("cc", "SingleThreadProxy::DoCommit"); |
DCHECK(Proxy::IsMainThread()); |
+ layer_tree_host_->WillBeginMainFrame(); |
+ layer_tree_host_->Layout(); |
+ layer_tree_host_->AnimateLayers(frame_begin_time); |
+ |
+ if (PrioritizedResourceManager* contents_texture_manager = |
+ layer_tree_host_->contents_texture_manager()) { |
+ contents_texture_manager->UnlinkAndClearEvictedBackings(); |
+ contents_texture_manager->SetMaxMemoryLimitBytes( |
+ layer_tree_host_impl_->memory_allocation_limit_bytes()); |
+ contents_texture_manager->SetExternalPriorityCutoff( |
+ layer_tree_host_impl_->memory_allocation_priority_cutoff()); |
+ } |
+ |
+ scoped_ptr<ResourceUpdateQueue> queue = |
+ make_scoped_ptr(new ResourceUpdateQueue); |
+ |
+ layer_tree_host_->UpdateLayers(queue.get()); |
+ |
+ layer_tree_host_->WillCommit(); |
+ |
// Commit immediately. |
{ |
DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
@@ -164,6 +199,8 @@ void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) { |
layer_tree_host_->FinishCommitOnImplThread(layer_tree_host_impl_.get()); |
+ UpdateBackgroundAnimateTicking(); |
+ |
layer_tree_host_impl_->CommitComplete(); |
#if DCHECK_IS_ON |
@@ -182,32 +219,50 @@ void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) { |
stats_instrumentation->AccumulateAndClearMainThreadStats(); |
} |
layer_tree_host_->CommitComplete(); |
+ layer_tree_host_->DidBeginMainFrame(); |
+ timing_history_.DidCommit(); |
+ |
next_frame_is_newly_committed_frame_ = true; |
} |
void SingleThreadProxy::SetNeedsCommit() { |
- DCHECK(Proxy::IsMainThread()); |
- client_->ScheduleComposite(); |
+ scheduler_on_impl_thread_->SetNeedsCommit(); |
} |
void SingleThreadProxy::SetNeedsRedraw(const gfx::Rect& damage_rect) { |
TRACE_EVENT0("cc", "SingleThreadProxy::SetNeedsRedraw"); |
+ DCHECK(Proxy::IsMainThread()); |
+ DebugScopedSetImplThread impl(this); |
SetNeedsRedrawRectOnImplThread(damage_rect); |
- client_->ScheduleComposite(); |
} |
void SingleThreadProxy::SetNextCommitWaitsForActivation() { |
// There is no activation here other than commit. So do nothing. |
+ DCHECK(Proxy::IsMainThread()); |
} |
void SingleThreadProxy::SetDeferCommits(bool defer_commits) { |
- // Thread-only feature. |
- NOTREACHED(); |
+ DCHECK(Proxy::IsMainThread()); |
+ if (defer_commits_ == defer_commits) |
+ return; |
+ |
+ defer_commits_ = defer_commits; |
+ if (!defer_commits_ && finish_commit_deferred_) { |
+ scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(); |
+ scheduler_on_impl_thread_->NotifyReadyToCommit(); |
+ finish_commit_deferred_ = false; |
+ } |
} |
-bool SingleThreadProxy::CommitRequested() const { return false; } |
+bool SingleThreadProxy::CommitRequested() const { |
+ DCHECK(Proxy::IsMainThread()); |
+ return finish_commit_deferred_; |
+} |
-bool SingleThreadProxy::BeginMainFrameRequested() const { return false; } |
+bool SingleThreadProxy::BeginMainFrameRequested() const { |
+ DCHECK(Proxy::IsMainThread()); |
+ return finish_commit_deferred_; |
+} |
size_t SingleThreadProxy::MaxPartialTextureUpdates() const { |
return std::numeric_limits<size_t>::max(); |
@@ -223,6 +278,7 @@ void SingleThreadProxy::Stop() { |
BlockingTaskRunner::CapturePostTasks blocked; |
layer_tree_host_->DeleteContentsTexturesOnImplThread( |
layer_tree_host_impl_->resource_provider()); |
+ scheduler_on_impl_thread_.reset(); |
layer_tree_host_impl_.reset(); |
} |
layer_tree_host_ = NULL; |
@@ -233,15 +289,16 @@ void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) { |
"cc", "SingleThreadProxy::OnCanDrawStateChanged", "can_draw", can_draw); |
DCHECK(Proxy::IsImplThread()); |
UpdateBackgroundAnimateTicking(); |
+ scheduler_on_impl_thread_->SetCanDraw(can_draw); |
} |
void SingleThreadProxy::NotifyReadyToActivate() { |
- // Thread-only feature. |
+ // Impl-side painting only. |
NOTREACHED(); |
} |
void SingleThreadProxy::SetNeedsRedrawOnImplThread() { |
- client_->ScheduleComposite(); |
+ scheduler_on_impl_thread_->SetNeedsRedraw(); |
} |
void SingleThreadProxy::SetNeedsAnimateOnImplThread() { |
@@ -249,17 +306,14 @@ void SingleThreadProxy::SetNeedsAnimateOnImplThread() { |
} |
void SingleThreadProxy::SetNeedsManageTilesOnImplThread() { |
- // Thread-only/Impl-side-painting-only feature. |
+ // Impl-side painting only. |
NOTREACHED(); |
} |
void SingleThreadProxy::SetNeedsRedrawRectOnImplThread( |
const gfx::Rect& damage_rect) { |
- // TODO(brianderson): Once we move render_widget scheduling into this class, |
- // we can treat redraw requests more efficiently than CommitAndRedraw |
- // requests. |
layer_tree_host_impl_->SetViewportDamage(damage_rect); |
- SetNeedsCommit(); |
+ SetNeedsRedrawOnImplThread(); |
} |
void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() { |
@@ -268,7 +322,7 @@ void SingleThreadProxy::DidInitializeVisibleTileOnImplThread() { |
} |
void SingleThreadProxy::SetNeedsCommitOnImplThread() { |
- client_->ScheduleComposite(); |
+ scheduler_on_impl_thread_->SetNeedsCommit(); |
} |
void SingleThreadProxy::PostAnimationEventsToMainThreadOnImplThread( |
@@ -320,66 +374,55 @@ void SingleThreadProxy::UpdateRendererCapabilitiesOnImplThread() { |
layer_tree_host_impl_->GetRendererCapabilities().MainThreadCapabilities(); |
} |
+void SingleThreadProxy::DidActivatePendingTree() { |
+ // Impl-side painting only. |
+ NOTREACHED(); |
+} |
+ |
+void SingleThreadProxy::DidManageTiles() { |
+ // Impl-side painting only. |
+ NOTREACHED(); |
+} |
+ |
void SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() { |
TRACE_EVENT0("cc", "SingleThreadProxy::DidLoseOutputSurfaceOnImplThread"); |
- // Cause a commit so we can notice the lost context. |
- SetNeedsCommitOnImplThread(); |
+ { |
+ DebugScopedSetMainThread main(this); |
+ // This must happen before we notify the scheduler as it may try to recreate |
+ // the output surface if already in BEGIN_IMPL_FRAME_STATE_IDLE. |
+ layer_tree_host_->DidLoseOutputSurface(); |
+ } |
client_->DidAbortSwapBuffers(); |
+ scheduler_on_impl_thread_->DidLoseOutputSurface(); |
} |
void SingleThreadProxy::DidSwapBuffersOnImplThread() { |
+ TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersOnImplThread"); |
+ scheduler_on_impl_thread_->DidSwapBuffers(); |
client_->DidPostSwapBuffers(); |
} |
void SingleThreadProxy::DidSwapBuffersCompleteOnImplThread() { |
TRACE_EVENT0("cc", "SingleThreadProxy::DidSwapBuffersCompleteOnImplThread"); |
+ scheduler_on_impl_thread_->DidSwapBuffersComplete(); |
+ layer_tree_host_->DidCompleteSwapBuffers(); |
client_->DidCompleteSwapBuffers(); |
} |
-// Called by the legacy scheduling path (e.g. where render_widget does the |
-// scheduling) |
+void SingleThreadProxy::BeginFrame(const BeginFrameArgs& args) { |
+ TRACE_EVENT0("cc", "ThreadProxy::BeginFrame"); |
+ scheduler_on_impl_thread_->BeginImplFrame(args); |
+} |
+ |
void SingleThreadProxy::CompositeImmediately(base::TimeTicks frame_begin_time) { |
TRACE_EVENT0("cc", "SingleThreadProxy::CompositeImmediately"); |
DCHECK(Proxy::IsMainThread()); |
DCHECK(!layer_tree_host_->output_surface_lost()); |
- layer_tree_host_->AnimateLayers(frame_begin_time); |
- |
- if (PrioritizedResourceManager* contents_texture_manager = |
- layer_tree_host_->contents_texture_manager()) { |
- contents_texture_manager->UnlinkAndClearEvictedBackings(); |
- contents_texture_manager->SetMaxMemoryLimitBytes( |
- layer_tree_host_impl_->memory_allocation_limit_bytes()); |
- contents_texture_manager->SetExternalPriorityCutoff( |
- layer_tree_host_impl_->memory_allocation_priority_cutoff()); |
- } |
- |
- scoped_ptr<ResourceUpdateQueue> queue = |
- make_scoped_ptr(new ResourceUpdateQueue); |
- layer_tree_host_->UpdateLayers(queue.get()); |
- layer_tree_host_->WillCommit(); |
- DoCommit(queue.Pass()); |
- layer_tree_host_->DidBeginMainFrame(); |
+ DoCommit(frame_begin_time); |
LayerTreeHostImpl::FrameData frame; |
- if (DoComposite(frame_begin_time, &frame)) { |
- { |
- DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
- DebugScopedSetImplThread impl(this); |
- |
- // This CapturePostTasks should be destroyed before |
- // DidCommitAndDrawFrame() is called since that goes out to the embedder, |
- // and we want the embedder to receive its callbacks before that. |
- // NOTE: This maintains consistent ordering with the ThreadProxy since |
- // the DidCommitAndDrawFrame() must be post-tasked from the impl thread |
- // there as the main thread is not blocked, so any posted tasks inside |
- // the swap buffers will execute first. |
- BlockingTaskRunner::CapturePostTasks blocked; |
- |
- layer_tree_host_impl_->SwapBuffers(frame); |
- } |
- DidSwapFrame(); |
- } |
+ DoComposite(frame_begin_time, &frame); |
} |
scoped_ptr<base::Value> SingleThreadProxy::AsValue() const { |
@@ -418,13 +461,11 @@ void SingleThreadProxy::UpdateBackgroundAnimateTicking() { |
!ShouldComposite() && layer_tree_host_impl_->active_tree()->root_layer()); |
} |
-bool SingleThreadProxy::DoComposite( |
- base::TimeTicks frame_begin_time, |
- LayerTreeHostImpl::FrameData* frame) { |
+DrawResult SingleThreadProxy::DoComposite(base::TimeTicks frame_begin_time, |
+ LayerTreeHostImpl::FrameData* frame) { |
TRACE_EVENT0("cc", "SingleThreadProxy::DoComposite"); |
DCHECK(!layer_tree_host_->output_surface_lost()); |
- bool lost_output_surface = false; |
{ |
DebugScopedSetImplThread impl(this); |
base::AutoReset<bool> mark_inside(&inside_draw_, true); |
@@ -435,9 +476,11 @@ bool SingleThreadProxy::DoComposite( |
// CanDraw() as well. |
if (!ShouldComposite()) { |
UpdateBackgroundAnimateTicking(); |
- return false; |
+ return DrawResult::DRAW_ABORTED_CANT_DRAW; |
} |
+ timing_history_.DidStartDrawing(); |
+ |
layer_tree_host_impl_->Animate( |
layer_tree_host_impl_->CurrentFrameTimeTicks()); |
UpdateBackgroundAnimateTicking(); |
@@ -447,24 +490,42 @@ bool SingleThreadProxy::DoComposite( |
layer_tree_host_impl_->DrawLayers(frame, frame_begin_time); |
layer_tree_host_impl_->DidDrawAllLayers(*frame); |
} |
- lost_output_surface = layer_tree_host_impl_->IsContextLost(); |
bool start_ready_animations = true; |
layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); |
layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); |
+ |
+ timing_history_.DidFinishDrawing(); |
} |
- if (lost_output_surface) { |
- layer_tree_host_->DidLoseOutputSurface(); |
- return false; |
+ { |
+ DebugScopedSetImplThread impl(this); |
+ |
+ if (layer_tree_host_impl_->IsContextLost()) { |
+ DidLoseOutputSurfaceOnImplThread(); |
+ } else { |
+ // This CapturePostTasks should be destroyed before |
+ // DidCommitAndDrawFrame() is called since that goes out to the embedder, |
+ // and we want the embedder to receive its callbacks before that. |
+ // NOTE: This maintains consistent ordering with the ThreadProxy since |
+ // the DidCommitAndDrawFrame() must be post-tasked from the impl thread |
+ // there as the main thread is not blocked, so any posted tasks inside |
+ // the swap buffers will execute first. |
+ DebugScopedSetMainThreadBlocked main_thread_blocked(this); |
+ |
+ BlockingTaskRunner::CapturePostTasks blocked; |
+ layer_tree_host_impl_->SwapBuffers(*frame); |
+ } |
} |
+ DidCommitAndDrawFrame(); |
- return true; |
+ return DrawResult::DRAW_SUCCESS; |
} |
-void SingleThreadProxy::DidSwapFrame() { |
+void SingleThreadProxy::DidCommitAndDrawFrame() { |
if (next_frame_is_newly_committed_frame_) { |
+ DebugScopedSetMainThread main(this); |
next_frame_is_newly_committed_frame_ = false; |
layer_tree_host_->DidCommitAndDrawFrame(); |
} |
@@ -472,4 +533,97 @@ void SingleThreadProxy::DidSwapFrame() { |
bool SingleThreadProxy::CommitPendingForTesting() { return false; } |
+scoped_ptr<base::Value> SingleThreadProxy::SchedulerAsValueForTesting() { |
+ DebugScopedSetImplThread impl(this); |
+ return scheduler_on_impl_thread_->AsValue().Pass(); |
+} |
+ |
+void SingleThreadProxy::SetNeedsBeginFrame(bool enable) { |
+ if (OutputSurface* surface = layer_tree_host_impl_->output_surface()) |
+ surface->SetNeedsBeginFrame(enable); |
+} |
+ |
+void SingleThreadProxy::WillBeginImplFrame(const BeginFrameArgs& args) { |
+ layer_tree_host_impl_->WillBeginImplFrame(args); |
+} |
+ |
+void SingleThreadProxy::ScheduledActionSendBeginMainFrame() { |
+ TRACE_EVENT0("cc", "SingleThreadProxy::ScheduledActionSendBeginMainFrame"); |
+ if (defer_commits_) { |
+ DCHECK(!finish_commit_deferred_); |
+ finish_commit_deferred_ = true; |
+ layer_tree_host_->DidDeferCommit(); |
+ return; |
+ } |
+ timing_history_.DidBeginMainFrame(); |
+ |
+ scheduler_on_impl_thread_->NotifyBeginMainFrameStarted(); |
+ scheduler_on_impl_thread_->NotifyReadyToCommit(); |
+} |
+ |
+DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapIfPossible() { |
+ DebugScopedSetImplThread impl(this); |
+ if (layer_tree_host_impl_->IsContextLost()) { |
+ DidCommitAndDrawFrame(); |
+ return DrawResult::DRAW_SUCCESS; |
+ } |
+ |
+ LayerTreeHostImpl::FrameData frame; |
+ return DoComposite(gfx::FrameTime::Now(), &frame); |
+} |
+ |
+DrawResult SingleThreadProxy::ScheduledActionDrawAndSwapForced() { |
+ return ScheduledActionDrawAndSwapIfPossible(); |
+} |
+ |
+void SingleThreadProxy::ScheduledActionCommit() { |
+ DebugScopedSetMainThread main(this); |
+ DoCommit(gfx::FrameTime::Now()); |
+} |
+ |
+void SingleThreadProxy::ScheduledActionAnimate() { |
+ TRACE_EVENT0("cc", "ScheduledActionAnimate"); |
+ layer_tree_host_impl_->Animate( |
+ layer_tree_host_impl_->CurrentFrameTimeTicks()); |
+} |
+ |
+void SingleThreadProxy::ScheduledActionUpdateVisibleTiles() { |
+ // Impl-side painting only. |
+ NOTREACHED(); |
+} |
+ |
+void SingleThreadProxy::ScheduledActionActivatePendingTree() { |
+ // Impl-side painting only. |
+ NOTREACHED(); |
+} |
+ |
+void SingleThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { |
+ DebugScopedSetMainThread main(this); |
+ CreateAndInitializeOutputSurface(); |
+} |
+ |
+void SingleThreadProxy::ScheduledActionManageTiles() { |
+ // Impl-side painting only. |
+ NOTREACHED(); |
+} |
+ |
+void SingleThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { |
+} |
+ |
+base::TimeDelta SingleThreadProxy::DrawDurationEstimate() { |
+ return timing_history_.DrawDurationEstimate(); |
+} |
+ |
+base::TimeDelta SingleThreadProxy::BeginMainFrameToCommitDurationEstimate() { |
+ return timing_history_.BeginMainFrameToCommitDurationEstimate(); |
+} |
+ |
+base::TimeDelta SingleThreadProxy::CommitToActivateDurationEstimate() { |
+ return timing_history_.CommitToActivateDurationEstimate(); |
+} |
+ |
+void SingleThreadProxy::DidBeginImplFrameDeadline() { |
+ layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); |
+} |
+ |
} // namespace cc |