Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1185)

Unified Diff: cc/scheduler/scheduler.cc

Issue 1051273003: Revert of cc: Make scheduling be driven by vsync for android webview. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/scheduler/scheduler.h ('k') | cc/scheduler/scheduler_state_machine.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/scheduler/scheduler.cc
diff --git a/cc/scheduler/scheduler.cc b/cc/scheduler/scheduler.cc
index fc82b26af731984e0f4864131fe5931120c7555a..ad5a6380ba2e655cf5592cc835586dab7e57939c 100644
--- a/cc/scheduler/scheduler.cc
+++ b/cc/scheduler/scheduler.cc
@@ -94,8 +94,6 @@
client_(client),
layer_tree_host_id_(layer_tree_host_id),
task_runner_(task_runner),
- begin_impl_frame_deadline_mode_(
- SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE),
state_machine_(scheduler_settings),
inside_process_scheduled_actions_(false),
inside_action_(SchedulerStateMachine::ACTION_NONE),
@@ -111,6 +109,8 @@
base::Bind(&Scheduler::BeginRetroFrame, weak_factory_.GetWeakPtr());
begin_impl_frame_deadline_closure_ = base::Bind(
&Scheduler::OnBeginImplFrameDeadline, weak_factory_.GetWeakPtr());
+ poll_for_draw_triggers_closure_ = base::Bind(
+ &Scheduler::PollForAnticipatedDrawTriggers, weak_factory_.GetWeakPtr());
advance_commit_state_closure_ = base::Bind(
&Scheduler::PollToAdvanceCommitState, weak_factory_.GetWeakPtr());
@@ -337,15 +337,37 @@
// We may need to poll when we can't rely on BeginFrame to advance certain
// state or to avoid deadlock.
void Scheduler::SetupPollingMechanisms() {
- // At this point we'd prefer to advance through the commit flow by
- // drawing a frame, however it's possible that the frame rate controller
- // will not give us a BeginFrame until the commit completes. See
- // crbug.com/317430 for an example of a swap ack being held on commit. Thus
- // we set a repeating timer to poll on ProcessScheduledActions until we
- // successfully reach BeginFrame. Synchronous compositor does not use
- // frame rate controller or have the circular wait in the bug.
- if (IsBeginMainFrameSentOrStarted() &&
- !settings_.using_synchronous_renderer_compositor) {
+ bool needs_advance_commit_state_timer = false;
+ // Setup PollForAnticipatedDrawTriggers if we need to monitor state but
+ // aren't expecting any more BeginFrames. This should only be needed by
+ // the synchronous compositor when BeginFrameNeeded is false.
+ if (state_machine_.ShouldPollForAnticipatedDrawTriggers()) {
+ DCHECK(!state_machine_.SupportsProactiveBeginFrame());
+ if (poll_for_draw_triggers_task_.IsCancelled()) {
+ poll_for_draw_triggers_task_.Reset(poll_for_draw_triggers_closure_);
+ base::TimeDelta delay = begin_impl_frame_args_.IsValid()
+ ? begin_impl_frame_args_.interval
+ : BeginFrameArgs::DefaultInterval();
+ task_runner_->PostDelayedTask(
+ FROM_HERE, poll_for_draw_triggers_task_.callback(), delay);
+ }
+ } else {
+ poll_for_draw_triggers_task_.Cancel();
+
+ // At this point we'd prefer to advance through the commit flow by
+ // drawing a frame, however it's possible that the frame rate controller
+ // will not give us a BeginFrame until the commit completes. See
+ // crbug.com/317430 for an example of a swap ack being held on commit. Thus
+ // we set a repeating timer to poll on ProcessScheduledActions until we
+ // successfully reach BeginFrame. Synchronous compositor does not use
+ // frame rate controller or have the circular wait in the bug.
+ if (IsBeginMainFrameSentOrStarted() &&
+ !settings_.using_synchronous_renderer_compositor) {
+ needs_advance_commit_state_timer = true;
+ }
+ }
+
+ if (needs_advance_commit_state_timer) {
if (advance_commit_state_task_.IsCancelled() &&
begin_impl_frame_args_.IsValid()) {
// Since we'd rather get a BeginImplFrame by the normal mechanism, we
@@ -384,11 +406,6 @@
BeginFrameArgs adjusted_args(args);
adjusted_args.deadline -= EstimatedParentDrawTime();
- if (settings_.using_synchronous_renderer_compositor) {
- BeginImplFrameSynchronous(adjusted_args);
- return true;
- }
-
// We have just called SetNeedsBeginFrame(true) and the BeginFrameSource has
// sent us the last BeginFrame we have missed. As we might not be able to
// actually make rendering for this call, handle it like a "retro frame".
@@ -399,12 +416,17 @@
return true;
}
- bool should_defer_begin_frame =
- !begin_retro_frame_args_.empty() ||
- !begin_retro_frame_task_.IsCancelled() ||
- !frame_source_->NeedsBeginFrames() ||
- (state_machine_.begin_impl_frame_state() !=
- SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
+ bool should_defer_begin_frame;
+ if (settings_.using_synchronous_renderer_compositor) {
+ should_defer_begin_frame = false;
+ } else {
+ should_defer_begin_frame =
+ !begin_retro_frame_args_.empty() ||
+ !begin_retro_frame_task_.IsCancelled() ||
+ !frame_source_->NeedsBeginFrames() ||
+ (state_machine_.begin_impl_frame_state() !=
+ SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
+ }
if (should_defer_begin_frame) {
begin_retro_frame_args_.push_back(adjusted_args);
@@ -412,7 +434,7 @@
"cc", "Scheduler::BeginFrame deferred", TRACE_EVENT_SCOPE_THREAD);
// Queuing the frame counts as "using it", so we need to return true.
} else {
- BeginImplFrameWithDeadline(adjusted_args);
+ BeginImplFrame(adjusted_args);
}
return true;
}
@@ -426,19 +448,6 @@
authoritative_vsync_interval_ = interval;
if (vsync_observer_)
vsync_observer_->OnUpdateVSyncParameters(last_vsync_timebase_, interval);
-}
-
-void Scheduler::OnDrawForOutputSurface() {
- DCHECK(settings_.using_synchronous_renderer_compositor);
- DCHECK_EQ(state_machine_.begin_impl_frame_state(),
- SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
- DCHECK(!BeginImplFrameDeadlinePending());
-
- state_machine_.OnBeginImplFrameDeadline();
- ProcessScheduledActions();
-
- state_machine_.OnBeginImplFrameIdle();
- ProcessScheduledActions();
}
// BeginRetroFrame is called for BeginFrames that we've deferred because
@@ -482,7 +491,7 @@
} else {
BeginFrameArgs front = begin_retro_frame_args_.front();
begin_retro_frame_args_.pop_front();
- BeginImplFrameWithDeadline(front);
+ BeginImplFrame(front);
}
}
@@ -512,27 +521,6 @@
begin_retro_frame_task_.Reset(begin_retro_frame_closure_);
task_runner_->PostTask(FROM_HERE, begin_retro_frame_task_.callback());
-}
-
-void Scheduler::BeginImplFrameWithDeadline(const BeginFrameArgs& args) {
- BeginImplFrame(args);
-
- // The deadline will be scheduled in ProcessScheduledActions.
- state_machine_.OnBeginImplFrameDeadlinePending();
- ProcessScheduledActions();
-}
-
-void Scheduler::BeginImplFrameSynchronous(const BeginFrameArgs& args) {
- BeginImplFrame(args);
- FinishImplFrame();
-}
-
-void Scheduler::FinishImplFrame() {
- state_machine_.OnBeginImplFrameIdle();
- ProcessScheduledActions();
-
- client_->DidBeginImplFrameDeadline();
- frame_source_->DidFinishFrame(begin_retro_frame_args_.size());
}
// BeginImplFrame starts a compositor frame that will wait up until a deadline
@@ -552,7 +540,6 @@
main_thread_is_in_high_latency_mode);
DCHECK_EQ(state_machine_.begin_impl_frame_state(),
SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_IDLE);
- DCHECK(!BeginImplFrameDeadlinePending());
DCHECK(state_machine_.HasInitializedOutputSurface());
advance_commit_state_task_.Cancel();
@@ -571,6 +558,19 @@
client_->WillBeginImplFrame(begin_impl_frame_args_);
ProcessScheduledActions();
+
+ state_machine_.OnBeginImplFrameDeadlinePending();
+
+ if (settings_.using_synchronous_renderer_compositor) {
+ // The synchronous renderer compositor has to make its GL calls
+ // within this call.
+ // TODO(brianderson): Have the OutputSurface initiate the deadline tasks
+ // so the synchronous renderer compositor can take advantage of splitting
+ // up the BeginImplFrame and deadline as well.
+ OnBeginImplFrameDeadline();
+ } else {
+ ScheduleBeginImplFrameDeadline();
+ }
}
void Scheduler::ScheduleBeginImplFrameDeadline() {
@@ -585,9 +585,6 @@
base::TimeTicks deadline;
switch (begin_impl_frame_deadline_mode_) {
- case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_NONE:
- // No deadline.
- return;
case SchedulerStateMachine::BEGIN_IMPL_FRAME_DEADLINE_MODE_IMMEDIATE:
// We are ready to draw a new active tree immediately.
// We don't use Now() here because it's somewhat expensive to call.
@@ -613,17 +610,17 @@
return;
}
- TRACE_EVENT2("cc", "Scheduler::ScheduleBeginImplFrameDeadline", "mode",
- SchedulerStateMachine::BeginImplFrameDeadlineModeToString(
- begin_impl_frame_deadline_mode_),
- "deadline", deadline);
-
- base::TimeDelta delta = std::max(deadline - Now(), base::TimeDelta());
+ TRACE_EVENT1(
+ "cc", "Scheduler::ScheduleBeginImplFrameDeadline", "deadline", deadline);
+
+ base::TimeDelta delta = deadline - Now();
+ if (delta <= base::TimeDelta())
+ delta = base::TimeDelta();
task_runner_->PostDelayedTask(
FROM_HERE, begin_impl_frame_deadline_task_.callback(), delta);
}
-void Scheduler::ScheduleBeginImplFrameDeadlineIfNeeded() {
+void Scheduler::RescheduleBeginImplFrameDeadlineIfNeeded() {
if (settings_.using_synchronous_renderer_compositor)
return;
@@ -631,12 +628,9 @@
SchedulerStateMachine::BEGIN_IMPL_FRAME_STATE_INSIDE_BEGIN_FRAME)
return;
- if (begin_impl_frame_deadline_mode_ ==
- state_machine_.CurrentBeginImplFrameDeadlineMode() &&
- BeginImplFrameDeadlinePending())
- return;
-
- ScheduleBeginImplFrameDeadline();
+ if (begin_impl_frame_deadline_mode_ !=
+ state_machine_.CurrentBeginImplFrameDeadlineMode())
+ ScheduleBeginImplFrameDeadline();
}
void Scheduler::OnBeginImplFrameDeadline() {
@@ -656,9 +650,20 @@
"461509 Scheduler::OnBeginImplFrameDeadline1"));
state_machine_.OnBeginImplFrameDeadline();
ProcessScheduledActions();
- FinishImplFrame();
-}
-
+ state_machine_.OnBeginImplFrameIdle();
+ ProcessScheduledActions();
+
+ client_->DidBeginImplFrameDeadline();
+ frame_source_->DidFinishFrame(begin_retro_frame_args_.size());
+}
+
+void Scheduler::PollForAnticipatedDrawTriggers() {
+ TRACE_EVENT0("cc", "Scheduler::PollForAnticipatedDrawTriggers");
+ poll_for_draw_triggers_task_.Cancel();
+ state_machine_.DidEnterPollForAnticipatedDrawTriggers();
+ ProcessScheduledActions();
+ state_machine_.DidLeavePollForAnticipatedDrawTriggers();
+}
void Scheduler::PollToAdvanceCommitState() {
TRACE_EVENT0("cc", "Scheduler::PollToAdvanceCommitState");
@@ -743,10 +748,6 @@
case SchedulerStateMachine::ACTION_PREPARE_TILES:
client_->ScheduledActionPrepareTiles();
break;
- case SchedulerStateMachine::ACTION_INVALIDATE_OUTPUT_SURFACE: {
- client_->ScheduledActionInvalidateOutputSurface();
- break;
- }
}
} while (action != SchedulerStateMachine::ACTION_NONE);
@@ -754,7 +755,7 @@
client_->DidAnticipatedDrawTimeChange(AnticipatedDrawTime());
- ScheduleBeginImplFrameDeadlineIfNeeded();
+ RescheduleBeginImplFrameDeadlineIfNeeded();
SetupNextBeginFrameIfNeeded();
}
@@ -795,6 +796,8 @@
!begin_retro_frame_task_.IsCancelled());
state->SetBoolean("begin_impl_frame_deadline_task_",
!begin_impl_frame_deadline_task_.IsCancelled());
+ state->SetBoolean("poll_for_draw_triggers_task_",
+ !poll_for_draw_triggers_task_.IsCancelled());
state->SetBoolean("advance_commit_state_task_",
!advance_commit_state_task_.IsCancelled());
state->BeginDictionary("begin_impl_frame_args");
« no previous file with comments | « cc/scheduler/scheduler.h ('k') | cc/scheduler/scheduler_state_machine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698