Index: cc/scheduler/scheduler_unittest.cc |
diff --git a/cc/scheduler/scheduler_unittest.cc b/cc/scheduler/scheduler_unittest.cc |
index 84d9fa38f5f3ade85759cb3cb9de4ab1f7e34fd9..d50c37fe99cdf2c90e1c060dcf64ee8045cb03a7 100644 |
--- a/cc/scheduler/scheduler_unittest.cc |
+++ b/cc/scheduler/scheduler_unittest.cc |
@@ -47,13 +47,11 @@ void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, |
class FakeSchedulerClient : public SchedulerClient { |
public: |
- struct FakeBeginFrameSourceForFakeSchedulerClient |
- : public FakeBeginFrameSource { |
- FakeSchedulerClient* client_; |
- |
- explicit FakeBeginFrameSourceForFakeSchedulerClient( |
- FakeSchedulerClient* client) |
+ class FakeExternalBeginFrameSource : public BeginFrameSourceMixIn { |
+ public: |
+ explicit FakeExternalBeginFrameSource(FakeSchedulerClient* client) |
: client_(client) {} |
+ virtual ~FakeExternalBeginFrameSource() {} |
virtual void OnNeedsBeginFramesChange(bool needs_begin_frames) override { |
if (needs_begin_frames) { |
@@ -63,6 +61,13 @@ class FakeSchedulerClient : public SchedulerClient { |
} |
client_->states_.push_back(client_->scheduler_->AsValue()); |
} |
+ |
+ void TestOnBeginFrame(const BeginFrameArgs& args) { |
+ return CallOnBeginFrame(args); |
+ } |
+ |
+ private: |
+ FakeSchedulerClient* client_; |
}; |
class FakePowerMonitorSource : public base::PowerMonitorSource { |
@@ -88,7 +93,7 @@ class FakeSchedulerClient : public SchedulerClient { |
redraw_will_happen_if_update_visible_tiles_happens_(false), |
now_src_(TestNowSource::Create()), |
task_runner_(new OrderedSimpleTaskRunner(now_src_, true)), |
- fake_frame_source_(this), |
+ fake_external_begin_frame_source_(nullptr), |
fake_power_monitor_source_(new FakePowerMonitorSource), |
power_monitor_(make_scoped_ptr<base::PowerMonitorSource>( |
fake_power_monitor_source_)), |
@@ -110,8 +115,21 @@ class FakeSchedulerClient : public SchedulerClient { |
} |
TestScheduler* CreateScheduler(const SchedulerSettings& settings) { |
- scheduler_ = TestScheduler::Create( |
- now_src_, this, settings, 0, task_runner_, &power_monitor_); |
+ scoped_ptr<FakeExternalBeginFrameSource> fake_external_begin_frame_source; |
+ if (settings.begin_frame_scheduling_enabled && |
+ settings.throttle_frame_production) { |
+ fake_external_begin_frame_source.reset( |
+ new FakeExternalBeginFrameSource(this)); |
+ fake_external_begin_frame_source_ = |
+ fake_external_begin_frame_source.get(); |
+ } |
+ scheduler_ = TestScheduler::Create(now_src_, |
+ this, |
+ settings, |
+ 0, |
+ task_runner_, |
+ &power_monitor_, |
+ fake_external_begin_frame_source.Pass()); |
DCHECK(scheduler_); |
return scheduler_.get(); |
} |
@@ -121,7 +139,7 @@ class FakeSchedulerClient : public SchedulerClient { |
void set_log_anticipated_draw_time_change(bool log) { |
log_anticipated_draw_time_change_ = log; |
} |
- bool needs_begin_frames() { return fake_frame_source_.NeedsBeginFrames(); } |
+ bool needs_begin_frames() { return scheduler_->NeedsBeginFrames(); } |
int num_draws() const { return num_draws_; } |
int num_actions_() const { return static_cast<int>(actions_.size()); } |
const char* Action(int i) const { return actions_[i]; } |
@@ -134,8 +152,10 @@ class FakeSchedulerClient : public SchedulerClient { |
return scheduler_->settings().begin_frame_scheduling_enabled && |
scheduler_->settings().throttle_frame_production; |
} |
- virtual FakeBeginFrameSource* ExternalBeginFrameSource() override { |
- return &fake_frame_source_; |
+ |
+ FakeExternalBeginFrameSource* ExternalBeginFrameSource() { |
+ DCHECK(ExternalBeginFrame()); |
+ return fake_external_begin_frame_source_; |
} |
base::PowerMonitor* PowerMonitor() { return &power_monitor_; } |
@@ -147,12 +167,11 @@ class FakeSchedulerClient : public SchedulerClient { |
void AdvanceFrame() { |
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), |
"FakeSchedulerClient::AdvanceFrame"); |
- // EXPECT_TRUE(needs_begin_frames()); |
if (ExternalBeginFrame()) { |
// Creep the time forward so that any BeginFrameArgs is not equal to the |
// last one otherwise we violate the BeginFrameSource contract. |
now_src_->AdvanceNowMicroseconds(1); |
- fake_frame_source_.TestOnBeginFrame( |
+ fake_external_begin_frame_source_->TestOnBeginFrame( |
CreateBeginFrameArgsForTesting(now_src_)); |
EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
} |
@@ -292,7 +311,7 @@ class FakeSchedulerClient : public SchedulerClient { |
std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat>> states_; |
scoped_refptr<TestNowSource> now_src_; |
scoped_refptr<OrderedSimpleTaskRunner> task_runner_; |
- FakeBeginFrameSourceForFakeSchedulerClient fake_frame_source_; |
+ FakeExternalBeginFrameSource* fake_external_begin_frame_source_; |
FakePowerMonitorSource* fake_power_monitor_source_; |
base::PowerMonitor power_monitor_; |
scoped_ptr<TestScheduler> scheduler_; |
@@ -331,8 +350,6 @@ void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, |
EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
client->task_runner().RunTasksWhile(client->ImplFrameDeadlinePending(true)); |
EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
- |
- // EXPECT_FALSE(client->needs_begin_frames()); |
} |
TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { |
@@ -1421,7 +1438,7 @@ void BeginFramesNotFromClient(bool begin_frame_scheduling_enabled, |
// without calling SetNeedsBeginFrame. |
client.Reset(); |
scheduler->SetNeedsCommit(); |
- EXPECT_FALSE(client.needs_begin_frames()); |
+ EXPECT_TRUE(client.needs_begin_frames()); |
brianderson
2014/10/18 00:08:45
BeginFramesNotFromClient tests are meant to test c
simonhong
2014/10/23 01:03:08
All client.needs_begin_frames() in NotFromClient a
|
EXPECT_NO_ACTION(client); |
client.Reset(); |
@@ -1431,21 +1448,21 @@ void BeginFramesNotFromClient(bool begin_frame_scheduling_enabled, |
EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
- EXPECT_FALSE(client.needs_begin_frames()); |
+ EXPECT_TRUE(client.needs_begin_frames()); |
client.Reset(); |
// If we don't swap on the deadline, we wait for the next BeginFrame. |
client.task_runner().RunPendingTasks(); // Run posted deadline. |
EXPECT_NO_ACTION(client); |
EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
- EXPECT_FALSE(client.needs_begin_frames()); |
+ EXPECT_TRUE(client.needs_begin_frames()); |
client.Reset(); |
// NotifyReadyToCommit should trigger the commit. |
scheduler->NotifyBeginMainFrameStarted(); |
scheduler->NotifyReadyToCommit(); |
EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
- EXPECT_FALSE(client.needs_begin_frames()); |
+ EXPECT_TRUE(client.needs_begin_frames()); |
client.Reset(); |
// BeginImplFrame should prepare the draw. |
@@ -1453,14 +1470,14 @@ void BeginFramesNotFromClient(bool begin_frame_scheduling_enabled, |
EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
- EXPECT_FALSE(client.needs_begin_frames()); |
+ EXPECT_TRUE(client.needs_begin_frames()); |
client.Reset(); |
// BeginImplFrame deadline should draw. |
client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); |
EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); |
EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
- EXPECT_FALSE(client.needs_begin_frames()); |
+ EXPECT_TRUE(client.needs_begin_frames()); |
client.Reset(); |
// The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
@@ -1519,7 +1536,7 @@ void BeginFramesNotFromClient_SwapThrottled(bool begin_frame_scheduling_enabled, |
// SetNeedsCommit should begin the frame on the next BeginImplFrame. |
client.Reset(); |
scheduler->SetNeedsCommit(); |
- EXPECT_FALSE(client.needs_begin_frames()); |
+ EXPECT_TRUE(client.needs_begin_frames()); |
brianderson
2014/10/18 00:08:44
Ditto for this class of tests.
|
EXPECT_NO_ACTION(client); |
client.Reset(); |
@@ -1528,14 +1545,14 @@ void BeginFramesNotFromClient_SwapThrottled(bool begin_frame_scheduling_enabled, |
EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
- EXPECT_FALSE(client.needs_begin_frames()); |
+ EXPECT_TRUE(client.needs_begin_frames()); |
client.Reset(); |
// NotifyReadyToCommit should trigger the pending commit and draw. |
scheduler->NotifyBeginMainFrameStarted(); |
scheduler->NotifyReadyToCommit(); |
EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
- EXPECT_FALSE(client.needs_begin_frames()); |
+ EXPECT_TRUE(client.needs_begin_frames()); |
client.Reset(); |
// Swapping will put us into a swap throttled state. |
@@ -1543,7 +1560,7 @@ void BeginFramesNotFromClient_SwapThrottled(bool begin_frame_scheduling_enabled, |
EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
- EXPECT_FALSE(client.needs_begin_frames()); |
+ EXPECT_TRUE(client.needs_begin_frames()); |
client.Reset(); |
// While swap throttled, BeginFrames should trigger BeginImplFrames, |
@@ -1552,14 +1569,14 @@ void BeginFramesNotFromClient_SwapThrottled(bool begin_frame_scheduling_enabled, |
client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); |
EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
- EXPECT_FALSE(client.needs_begin_frames()); |
+ EXPECT_TRUE(client.needs_begin_frames()); |
client.Reset(); |
// Take us out of a swap throttled state. |
scheduler->DidSwapBuffersComplete(); |
EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); |
EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
- EXPECT_FALSE(client.needs_begin_frames()); |
+ EXPECT_TRUE(client.needs_begin_frames()); |
client.Reset(); |
// BeginImplFrame deadline should draw. |
@@ -1568,7 +1585,7 @@ void BeginFramesNotFromClient_SwapThrottled(bool begin_frame_scheduling_enabled, |
EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
- EXPECT_FALSE(client.needs_begin_frames()); |
+ EXPECT_TRUE(client.needs_begin_frames()); |
client.Reset(); |
} |