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

Unified Diff: cc/scheduler/scheduler_unittest.cc

Issue 811523002: Added ability to dynamically toggle frame throttling in the scheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added tests for SetThrottleFrameProduction Created 6 years 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
Index: cc/scheduler/scheduler_unittest.cc
diff --git a/cc/scheduler/scheduler_unittest.cc b/cc/scheduler/scheduler_unittest.cc
index 80d54d2306d093771f092d799be69feeb543c953..ec2c3e0eb6d583e84dbf148f499409c3be8a97f7 100644
--- a/cc/scheduler/scheduler_unittest.cc
+++ b/cc/scheduler/scheduler_unittest.cc
@@ -122,8 +122,7 @@ class FakeSchedulerClient : public SchedulerClient {
TestScheduler* CreateScheduler(const SchedulerSettings& settings) {
scoped_ptr<FakeExternalBeginFrameSource> fake_external_begin_frame_source;
- if (settings.use_external_begin_frame_source &&
- settings.throttle_frame_production) {
+ if (settings.use_external_begin_frame_source) {
fake_external_begin_frame_source.reset(
new FakeExternalBeginFrameSource(this));
fake_external_begin_frame_source_ =
@@ -156,11 +155,6 @@ class FakeSchedulerClient : public SchedulerClient {
return posted_begin_impl_frame_deadline_;
}
- bool ExternalBeginFrame() {
- return scheduler_->settings().use_external_begin_frame_source &&
- scheduler_->settings().throttle_frame_production;
- }
-
FakeExternalBeginFrameSource* fake_external_begin_frame_source() const {
return fake_external_begin_frame_source_;
}
@@ -245,7 +239,8 @@ class FakeSchedulerClient : public SchedulerClient {
// Send the next BeginFrame message if using an external source, otherwise
// it will be already in the task queue.
- if (ExternalBeginFrame()) {
+ if (scheduler_->settings().use_external_begin_frame_source &&
+ scheduler_->FrameProductionThrottled()) {
mithro-old 2014/12/19 04:11:19 I think we are actually better doing something lik
SendNextBeginFrame();
EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending());
}
@@ -256,7 +251,7 @@ class FakeSchedulerClient : public SchedulerClient {
}
void SendNextBeginFrame() {
- DCHECK(ExternalBeginFrame());
+ DCHECK(scheduler_->settings().use_external_begin_frame_source);
// Creep the time forward so that any BeginFrameArgs is not equal to the
// last one otherwise we violate the BeginFrameSource contract.
now_src_->AdvanceNow(BeginFrameArgs::DefaultInterval());
@@ -1510,8 +1505,6 @@ void BeginFramesNotFromClient(bool use_external_begin_frame_source,
CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings);
- DCHECK(!client.fake_external_begin_frame_source());
-
// SetNeedsCommit should begin the frame on the next BeginImplFrame
// without calling SetNeedsBeginFrame.
scheduler->SetNeedsCommit();
@@ -1598,8 +1591,6 @@ void BeginFramesNotFromClient_SwapThrottled(
CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings);
scheduler->SetEstimatedParentDrawTime(base::TimeDelta::FromMicroseconds(1));
- DCHECK(!client.fake_external_begin_frame_source());
-
// To test swap ack throttling, this test disables automatic swap acks.
scheduler->SetMaxSwapsPending(1);
client.SetAutomaticSwapAck(false);
@@ -2200,5 +2191,137 @@ TEST(SchedulerTest,
EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
}
+// Tests to ensure frame sources can be successfully changed while drawing.
+TEST(SchedulerTest, SwitchFrameSourceToUnthrottled) {
+ FakeSchedulerClient client;
+ SchedulerSettings scheduler_settings;
+ scheduler_settings.use_external_begin_frame_source = true;
mithro-old 2014/12/19 04:11:18 I think you want to actually check the BeginFrameA
+
+ CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings);
+
+ // SetNeedsRedraw should begin the frame on the next BeginImplFrame.
+ scheduler->SetNeedsRedraw();
+ EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client);
+ client.Reset();
+
+ EXPECT_SCOPED(client.AdvanceFrame());
+ EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
+ EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
+ EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
+ EXPECT_TRUE(client.needs_begin_frames());
+ client.Reset();
+ client.task_runner().RunPendingTasks(); // Run posted deadline.
+ EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1);
+ scheduler->SetNeedsRedraw();
+
+ // Switch to an unthrottled frame source.
+ scheduler->SetThrottleFrameProduction(false);
+ client.Reset();
+
+ // Unthrottled frame source will immediately begin a new frame.
+ client.task_runner().RunPendingTasks(); // Run posted BeginFrame.
+ EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
+ EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
+ EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
+ client.Reset();
+
+ // If we don't swap on the deadline, we wait for the next BeginFrame.
+ client.task_runner().RunPendingTasks(); // Run posted deadline.
+ EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1);
+ EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
+ client.Reset();
+}
+
+// Tests to ensure frame sources can be successfully changed while a frame
+// deadline is pending.
+TEST(SchedulerTest, SwitchFrameSourceToUnthrottledBeforeDeadline) {
+ FakeSchedulerClient client;
+ SchedulerSettings scheduler_settings;
+ scheduler_settings.use_external_begin_frame_source = true;
+
+ CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings);
+
+ // SetNeedsRedraw should begin the frame on the next BeginImplFrame.
+ scheduler->SetNeedsRedraw();
+ EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client);
+ client.Reset();
+
+ EXPECT_SCOPED(client.AdvanceFrame());
+ EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
+ EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
+
+ // Switch to an unthrottled frame source before the frame deadline is hit.
+ scheduler->SetThrottleFrameProduction(false);
+ client.Reset();
+
+ EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
+ EXPECT_TRUE(client.needs_begin_frames());
+ client.Reset();
+
+ client.task_runner().RunPendingTasks(); // Run posted deadline.
brianderson 2014/12/19 23:04:59 Comment should read "Run posted deadline and Begin
+ EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
+ // Unthrottled frame source will immediately begin a new frame.
+ EXPECT_ACTION("WillBeginImplFrame", client, 1, 2);
+ scheduler->SetNeedsRedraw();
+ client.Reset();
+
+ client.task_runner().RunPendingTasks(); // Run posted BeginFrame.
brianderson 2014/12/19 23:04:59 Comment should read "Run posted deadline."
+ EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2);
+ EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2);
+ EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
+ client.Reset();
+
+ // If we don't swap on the deadline, we wait for the next BeginFrame.
brianderson 2014/12/19 23:04:59 Probably just delete this block. We went through o
+ client.task_runner().RunPendingTasks(); // Run posted deadline.
+ EXPECT_ACTION("WillBeginImplFrame", client, 0, 1);
+ EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
+ client.Reset();
+}
+
+// Tests to ensure that the active frame source can successfully be changed from
+// unthrottled to throttled.
+TEST(SchedulerTest, SwitchFrameSourceToThrottled) {
+ FakeSchedulerClient client;
+ SchedulerSettings scheduler_settings;
+ scheduler_settings.throttle_frame_production = false;
+ scheduler_settings.use_external_begin_frame_source = true;
+
+ CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings);
+
+ scheduler->SetNeedsRedraw();
+ EXPECT_NO_ACTION(client);
+ client.Reset();
+
+ client.task_runner().RunPendingTasks(); // Run posted BeginFrame.
+ EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
+ EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
+ EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
+ client.Reset();
+
+ client.task_runner().RunPendingTasks(); // Run posted deadline.
+ EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1);
+ EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
+ client.Reset();
+
+ // Switch to a throttled frame source.
+ scheduler->SetThrottleFrameProduction(true);
+ client.Reset();
+
+ // SetNeedsRedraw should begin the frame on the next BeginImplFrame.
+ scheduler->SetNeedsRedraw();
brianderson 2014/12/19 23:04:59 What happens if you RunPendingTasks after here?
+ EXPECT_NO_ACTION(client);
+ client.Reset();
+
+ EXPECT_SCOPED(client.AdvanceFrame());
+ EXPECT_ACTION("WillBeginImplFrame", client, 0, 2);
+ EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2);
+ EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
+ EXPECT_TRUE(client.needs_begin_frames());
+ client.Reset();
+ client.task_runner().RunPendingTasks(); // Run posted deadline.
+ EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1);
+ scheduler->SetNeedsRedraw();
brianderson 2014/12/19 23:04:59 Don't need to SetNeedsRedraw here.
+}
+
mithro-old 2014/12/19 04:11:19 You probably want a simple test for going to/from
} // namespace
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698