Skip to content

Commit

Permalink
cc: Pass task runner to scheduler
Browse files Browse the repository at this point in the history
Use explicit task runner to post BeginImplFrameDeadline and
PollForAnticipatedDrawTriggers calls. Removed PostBeginImplFrameDeadline
on the client since it's no longer needed. And fixed up tests.

BUG=348796

Review URL: https://codereview.chromium.org/203233002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@258326 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
boliu@chromium.org committed Mar 20, 2014
1 parent 5dcd57c commit 48abf81
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 75 deletions.
23 changes: 15 additions & 8 deletions cc/scheduler/scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@

namespace cc {

Scheduler::Scheduler(SchedulerClient* client,
const SchedulerSettings& scheduler_settings,
int layer_tree_host_id)
Scheduler::Scheduler(
SchedulerClient* client,
const SchedulerSettings& scheduler_settings,
int layer_tree_host_id,
const scoped_refptr<base::SequencedTaskRunner>& impl_task_runner)
: settings_(scheduler_settings),
client_(client),
layer_tree_host_id_(layer_tree_host_id),
impl_task_runner_(impl_task_runner),
last_set_needs_begin_impl_frame_(false),
state_machine_(scheduler_settings),
inside_process_scheduled_actions_(false),
Expand Down Expand Up @@ -178,7 +181,7 @@ void Scheduler::SetupNextBeginImplFrameIfNeeded() {
poll_for_draw_triggers_closure_.Reset(
base::Bind(&Scheduler::PollForAnticipatedDrawTriggers,
weak_factory_.GetWeakPtr()));
base::MessageLoop::current()->PostDelayedTask(
impl_task_runner_->PostDelayedTask(
FROM_HERE,
poll_for_draw_triggers_closure_.callback(),
last_begin_impl_frame_args_.interval);
Expand All @@ -202,8 +205,8 @@ void Scheduler::SetupNextBeginImplFrameIfNeeded() {
advance_commit_state_timer_.IsRunning()) {
if (needs_advance_commit_state_timer &&
last_begin_impl_frame_args_.IsValid()) {
// Since we'd rather get a BeginImplFrame by the normally mechanism, we set
// the interval to twice the interval from the previous frame.
// Since we'd rather get a BeginImplFrame by the normal mechanism, we
// set the interval to twice the interval from the previous frame.
advance_commit_state_timer_.Start(
FROM_HERE,
last_begin_impl_frame_args_.interval * 2,
Expand Down Expand Up @@ -281,8 +284,12 @@ void Scheduler::ScheduleBeginImplFrameDeadline(base::TimeTicks deadline) {
begin_impl_frame_deadline_closure_.Reset(
base::Bind(&Scheduler::OnBeginImplFrameDeadline,
weak_factory_.GetWeakPtr()));
client_->PostBeginImplFrameDeadline(
begin_impl_frame_deadline_closure_.callback(), deadline);

base::TimeDelta delta = deadline - gfx::FrameTime::Now();
if (delta <= base::TimeDelta())
delta = base::TimeDelta();
impl_task_runner_->PostDelayedTask(
FROM_HERE, begin_impl_frame_deadline_closure_.callback(), delta);
}

void Scheduler::OnBeginImplFrameDeadline() {
Expand Down
16 changes: 10 additions & 6 deletions cc/scheduler/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class SchedulerClient {
virtual base::TimeDelta DrawDurationEstimate() = 0;
virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() = 0;
virtual base::TimeDelta CommitToActivateDurationEstimate() = 0;
virtual void PostBeginImplFrameDeadline(const base::Closure& closure,
base::TimeTicks deadline) = 0;
virtual void DidBeginImplFrameDeadline() = 0;

protected:
Expand All @@ -52,9 +50,10 @@ class CC_EXPORT Scheduler {
static scoped_ptr<Scheduler> Create(
SchedulerClient* client,
const SchedulerSettings& scheduler_settings,
int layer_tree_host_id) {
return make_scoped_ptr(
new Scheduler(client, scheduler_settings, layer_tree_host_id));
int layer_tree_host_id,
const scoped_refptr<base::SequencedTaskRunner>& impl_task_runner) {
return make_scoped_ptr(new Scheduler(
client, scheduler_settings, layer_tree_host_id, impl_task_runner));
}

virtual ~Scheduler();
Expand Down Expand Up @@ -99,6 +98,9 @@ class CC_EXPORT Scheduler {
bool MainThreadIsInHighLatencyMode() const {
return state_machine_.MainThreadIsInHighLatencyMode();
}
bool BeginImplFrameDeadlinePending() const {
return !begin_impl_frame_deadline_closure_.IsCancelled();
}

bool WillDrawIfNeeded() const;

Expand All @@ -123,7 +125,8 @@ class CC_EXPORT Scheduler {
private:
Scheduler(SchedulerClient* client,
const SchedulerSettings& scheduler_settings,
int layer_tree_host_id);
int layer_tree_host_id,
const scoped_refptr<base::SequencedTaskRunner>& impl_task_runner);

base::TimeTicks AdjustedBeginImplFrameDeadline() const;
void ScheduleBeginImplFrameDeadline(base::TimeTicks deadline);
Expand All @@ -142,6 +145,7 @@ class CC_EXPORT Scheduler {
const SchedulerSettings settings_;
SchedulerClient* client_;
int layer_tree_host_id_;
scoped_refptr<base::SequencedTaskRunner> impl_task_runner_;

bool last_set_needs_begin_impl_frame_;
BeginFrameArgs last_begin_impl_frame_args_;
Expand Down
Loading

0 comments on commit 48abf81

Please sign in to comment.