Index: cc/scheduler/scheduler_unittest.cc |
diff --git a/cc/scheduler/scheduler_unittest.cc b/cc/scheduler/scheduler_unittest.cc |
index 205be5140aa9349f83c4f839b925558032cd7e33..db53c3d83399dce5bee9666038a1d649125a1894 100644 |
--- a/cc/scheduler/scheduler_unittest.cc |
+++ b/cc/scheduler/scheduler_unittest.cc |
@@ -14,6 +14,7 @@ |
#include "base/run_loop.h" |
#include "base/time/time.h" |
#include "base/trace_event/trace_event.h" |
+#include "cc/debug/rendering_stats_instrumentation.h" |
#include "cc/test/begin_frame_args_test.h" |
#include "cc/test/ordered_simple_task_runner.h" |
#include "cc/test/scheduler_test_common.h" |
@@ -133,7 +134,10 @@ class FakeSchedulerClient : public SchedulerClient { |
PushAction("ScheduledActionDrawAndSwapForced"); |
return DRAW_SUCCESS; |
} |
- void ScheduledActionCommit() override { PushAction("ScheduledActionCommit"); } |
+ void ScheduledActionCommit() override { |
+ PushAction("ScheduledActionCommit"); |
+ scheduler_->DidCommit(); |
+ } |
void ScheduledActionActivateSyncTree() override { |
PushAction("ScheduledActionActivateSyncTree"); |
} |
@@ -142,6 +146,8 @@ class FakeSchedulerClient : public SchedulerClient { |
} |
void ScheduledActionPrepareTiles() override { |
PushAction("ScheduledActionPrepareTiles"); |
+ scheduler_->WillPrepareTiles(); |
+ scheduler_->DidPrepareTiles(); |
picksi
2015/06/19 13:04:28
You seem to be measuring nothing here?
brianderson
2015/06/19 17:24:27
Every WillPrepareTiles must be followed by a DidPr
|
} |
void ScheduledActionInvalidateOutputSurface() override { |
actions_.push_back("ScheduledActionInvalidateOutputSurface"); |
@@ -151,13 +157,6 @@ class FakeSchedulerClient : public SchedulerClient { |
if (log_anticipated_draw_time_change_) |
PushAction("DidAnticipatedDrawTimeChange"); |
} |
- base::TimeDelta DrawDurationEstimate() override { return base::TimeDelta(); } |
- base::TimeDelta BeginMainFrameToCommitDurationEstimate() override { |
- return base::TimeDelta(); |
- } |
- base::TimeDelta CommitToActivateDurationEstimate() override { |
- return base::TimeDelta(); |
- } |
void SendBeginFramesToChildren(const BeginFrameArgs& args) override { |
begin_frame_args_sent_to_children_ = args; |
@@ -204,31 +203,6 @@ class FakeSchedulerClient : public SchedulerClient { |
TestScheduler* scheduler_; |
}; |
-class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { |
- public: |
- SchedulerClientWithFixedEstimates( |
- base::TimeDelta draw_duration, |
- base::TimeDelta begin_main_frame_to_commit_duration, |
- base::TimeDelta commit_to_activate_duration) |
- : draw_duration_(draw_duration), |
- begin_main_frame_to_commit_duration_( |
- begin_main_frame_to_commit_duration), |
- commit_to_activate_duration_(commit_to_activate_duration) {} |
- |
- base::TimeDelta DrawDurationEstimate() override { return draw_duration_; } |
- base::TimeDelta BeginMainFrameToCommitDurationEstimate() override { |
- return begin_main_frame_to_commit_duration_; |
- } |
- base::TimeDelta CommitToActivateDurationEstimate() override { |
- return commit_to_activate_duration_; |
- } |
- |
- private: |
- base::TimeDelta draw_duration_; |
- base::TimeDelta begin_main_frame_to_commit_duration_; |
- base::TimeDelta commit_to_activate_duration_; |
-}; |
- |
class FakeExternalBeginFrameSource : public BeginFrameSourceBase { |
public: |
explicit FakeExternalBeginFrameSource(FakeSchedulerClient* client) |
@@ -276,9 +250,11 @@ class SchedulerTest : public testing::Test { |
fake_external_begin_frame_source_ = |
fake_external_begin_frame_source.get(); |
} |
+ rendering_stats_instrumentation_ = RenderingStatsInstrumentation::Create(); |
scheduler_ = TestScheduler::Create(now_src_.get(), client_.get(), |
scheduler_settings_, 0, task_runner_, |
- fake_external_begin_frame_source.Pass()); |
+ fake_external_begin_frame_source.Pass(), |
+ rendering_stats_instrumentation_.get()); |
DCHECK(scheduler_); |
client_->set_scheduler(scheduler_.get()); |
return scheduler_.get(); |
@@ -339,7 +315,8 @@ class SchedulerTest : public testing::Test { |
AdvanceFrame(); |
scheduler_->NotifyBeginMainFrameStarted(); |
- scheduler_->NotifyReadyToCommitThenActivateIfNeeded(); |
+ scheduler_->NotifyReadyToCommit(); |
+ scheduler_->NotifyReadyToActivate(); |
EXPECT_FALSE(scheduler_->CommitPending()); |
@@ -435,6 +412,7 @@ class SchedulerTest : public testing::Test { |
SchedulerSettings scheduler_settings_; |
scoped_ptr<FakeSchedulerClient> client_; |
scoped_ptr<TestScheduler> scheduler_; |
+ scoped_ptr<RenderingStatsInstrumentation> rendering_stats_instrumentation_; |
}; |
TEST_F(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { |
@@ -486,13 +464,13 @@ TEST_F(SchedulerTest, SendBeginFramesToChildrenWithoutCommit) { |
TEST_F(SchedulerTest, SendBeginFramesToChildrenDeadlineNotAdjusted) { |
// Set up client with specified estimates. |
- SchedulerClientWithFixedEstimates* client = |
- new SchedulerClientWithFixedEstimates( |
- base::TimeDelta::FromMilliseconds(1), |
- base::TimeDelta::FromMilliseconds(2), |
- base::TimeDelta::FromMilliseconds(4)); |
scheduler_settings_.use_external_begin_frame_source = true; |
- SetUpScheduler(make_scoped_ptr(client).Pass(), true); |
+ SetUpScheduler(true); |
+ scheduler_->SetDrawDurationEstimate(base::TimeDelta::FromMilliseconds(1)); |
+ scheduler_->SetBeginMainFrameToCommitDurationEstimate( |
+ base::TimeDelta::FromMilliseconds(2)); |
+ scheduler_->SetPrepareTilesToReadyToActivateDurationEstimate( |
+ base::TimeDelta::FromMilliseconds(4)); |
EXPECT_FALSE(client_->needs_begin_frames()); |
scheduler_->SetChildrenNeedBeginFrames(true); |
@@ -747,8 +725,6 @@ class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { |
SchedulerClientThatsetNeedsDrawInsideDraw() |
: FakeSchedulerClient(), request_redraws_(false) {} |
- void ScheduledActionSendBeginMainFrame() override {} |
- |
void SetRequestRedrawsInsideDraw(bool enable) { request_redraws_ = enable; } |
DrawResult ScheduledActionDrawAndSwapIfPossible() override { |
@@ -764,9 +740,6 @@ class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { |
return DRAW_SUCCESS; |
} |
- void ScheduledActionCommit() override {} |
- void DidAnticipatedDrawTimeChange(base::TimeTicks) override {} |
- |
private: |
bool request_redraws_; |
}; |
@@ -861,7 +834,6 @@ class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { |
SchedulerClientThatSetNeedsCommitInsideDraw() |
: set_needs_commit_on_next_draw_(false) {} |
- void ScheduledActionSendBeginMainFrame() override {} |
DrawResult ScheduledActionDrawAndSwapIfPossible() override { |
// Only SetNeedsCommit the first time this is called |
if (set_needs_commit_on_next_draw_) { |
@@ -876,9 +848,6 @@ class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { |
return DRAW_SUCCESS; |
} |
- void ScheduledActionCommit() override {} |
- void DidAnticipatedDrawTimeChange(base::TimeTicks) override {} |
- |
void SetNeedsCommitOnNextDraw() { set_needs_commit_on_next_draw_ = true; } |
private: |
@@ -1130,6 +1099,7 @@ TEST_F(SchedulerTest, PrepareTilesOncePerFrame) { |
EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
+ scheduler_->WillPrepareTiles(); |
scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. |
EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
@@ -1161,10 +1131,10 @@ TEST_F(SchedulerTest, PrepareTilesOncePerFrame) { |
EXPECT_FALSE(scheduler_->RedrawPending()); |
EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
- scheduler_->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles |
// If we get another DidPrepareTiles within the same frame, we should |
// not PrepareTiles on the next frame. |
+ scheduler_->WillPrepareTiles(); |
scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. |
scheduler_->SetNeedsPrepareTiles(); |
scheduler_->SetNeedsRedraw(); |
@@ -1188,6 +1158,7 @@ TEST_F(SchedulerTest, PrepareTilesOncePerFrame) { |
// frame. This verifies we don't alternate calling PrepareTiles once and |
// twice. |
EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
+ scheduler_->WillPrepareTiles(); |
scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. |
EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
scheduler_->SetNeedsPrepareTiles(); |
@@ -1227,7 +1198,6 @@ TEST_F(SchedulerTest, PrepareTilesOncePerFrame) { |
EXPECT_FALSE(scheduler_->RedrawPending()); |
EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
- scheduler_->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles |
} |
TEST_F(SchedulerTest, TriggerBeginFrameDeadlineEarly) { |
@@ -1333,16 +1303,15 @@ void SchedulerTest::MainFrameInHighLatencyMode( |
int64 commit_to_activate_estimate_in_ms, |
bool impl_latency_takes_priority, |
bool should_send_begin_main_frame) { |
- // Set up client with specified estimates (draw duration is set to 1). |
- SchedulerClientWithFixedEstimates* client = |
- new SchedulerClientWithFixedEstimates( |
- base::TimeDelta::FromMilliseconds(1), |
- base::TimeDelta::FromMilliseconds( |
- begin_main_frame_to_commit_estimate_in_ms), |
- base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms)); |
- |
scheduler_settings_.use_external_begin_frame_source = true; |
- SetUpScheduler(make_scoped_ptr(client).Pass(), true); |
+ SetUpScheduler(true); |
picksi
2015/06/19 13:04:28
I see it is a common pattern, but SetUpScheduler(t
brianderson
2015/06/19 17:24:27
Good idea. I can clean that up in a separate patch
|
+ |
+ scheduler_->SetDrawDurationEstimate(base::TimeDelta::FromMilliseconds(1)); |
+ scheduler_->SetBeginMainFrameToCommitDurationEstimate( |
+ base::TimeDelta::FromMilliseconds( |
+ begin_main_frame_to_commit_estimate_in_ms)); |
+ scheduler_->SetPrepareTilesToReadyToActivateDurationEstimate( |
+ base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms)); |
scheduler_->SetImplLatencyTakesPriority(impl_latency_takes_priority); |
@@ -1357,9 +1326,9 @@ void SchedulerTest::MainFrameInHighLatencyMode( |
scheduler_->NotifyReadyToCommit(); |
scheduler_->NotifyReadyToActivate(); |
EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); |
- EXPECT_TRUE(client->HasAction("ScheduledActionSendBeginMainFrame")); |
+ EXPECT_TRUE(client_->HasAction("ScheduledActionSendBeginMainFrame")); |
- client->Reset(); |
+ client_->Reset(); |
scheduler_->SetNeedsCommit(); |
EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); |
EXPECT_SCOPED(AdvanceFrame()); |
@@ -1367,7 +1336,7 @@ void SchedulerTest::MainFrameInHighLatencyMode( |
task_runner().RunPendingTasks(); // Run posted deadline. |
EXPECT_EQ(scheduler_->MainThreadIsInHighLatencyMode(), |
should_send_begin_main_frame); |
- EXPECT_EQ(client->HasAction("ScheduledActionSendBeginMainFrame"), |
+ EXPECT_EQ(client_->HasAction("ScheduledActionSendBeginMainFrame"), |
should_send_begin_main_frame); |
} |
@@ -1407,15 +1376,16 @@ TEST_F(SchedulerTest, |
// Since we are simulating a long commit, set up a client with draw duration |
// estimates that prevent skipping main frames to get to low latency mode. |
- SchedulerClientWithFixedEstimates* client = |
- new SchedulerClientWithFixedEstimates( |
- base::TimeDelta::FromMilliseconds(1), |
- base::TimeDelta::FromMilliseconds(32), |
- base::TimeDelta::FromMilliseconds(32)); |
scheduler_settings_.use_external_begin_frame_source = true; |
- SetUpScheduler(make_scoped_ptr(client).Pass(), true); |
+ SetUpScheduler(true); |
- client->set_log_anticipated_draw_time_change(true); |
+ scheduler_->SetDrawDurationEstimate(base::TimeDelta::FromMilliseconds(1)); |
+ scheduler_->SetBeginMainFrameToCommitDurationEstimate( |
+ base::TimeDelta::FromMilliseconds(32)); |
+ scheduler_->SetPrepareTilesToReadyToActivateDurationEstimate( |
+ base::TimeDelta::FromMilliseconds(32)); |
+ |
+ client_->set_log_anticipated_draw_time_change(true); |
BeginFrameArgs frame_args = |
CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); |
@@ -1437,7 +1407,7 @@ TEST_F(SchedulerTest, |
// Spin the event loop a few times and make sure we get more |
// DidAnticipateDrawTimeChange calls every time. |
- int actions_so_far = client->num_actions_(); |
+ int actions_so_far = client_->num_actions_(); |
// Does three iterations to make sure that the timer is properly repeating. |
for (int i = 0; i < 3; ++i) { |
@@ -1445,10 +1415,10 @@ TEST_F(SchedulerTest, |
task_runner().DelayToNextTaskTime().InMicroseconds()) |
<< scheduler_->AsValue()->ToString(); |
task_runner().RunPendingTasks(); |
- EXPECT_GT(client->num_actions_(), actions_so_far); |
- EXPECT_STREQ(client->Action(client->num_actions_() - 1), |
+ EXPECT_GT(client_->num_actions_(), actions_so_far); |
+ EXPECT_STREQ(client_->Action(client_->num_actions_() - 1), |
"DidAnticipatedDrawTimeChange"); |
- actions_so_far = client->num_actions_(); |
+ actions_so_far = client_->num_actions_(); |
} |
// Do the same thing after BeginMainFrame starts but still before activation. |
@@ -1458,10 +1428,10 @@ TEST_F(SchedulerTest, |
task_runner().DelayToNextTaskTime().InMicroseconds()) |
<< scheduler_->AsValue()->ToString(); |
task_runner().RunPendingTasks(); |
- EXPECT_GT(client->num_actions_(), actions_so_far); |
- EXPECT_STREQ(client->Action(client->num_actions_() - 1), |
+ EXPECT_GT(client_->num_actions_(), actions_so_far); |
+ EXPECT_STREQ(client_->Action(client_->num_actions_() - 1), |
"DidAnticipatedDrawTimeChange"); |
- actions_so_far = client->num_actions_(); |
+ actions_so_far = client_->num_actions_(); |
} |
} |
@@ -1473,14 +1443,15 @@ TEST_F( |
// Since we are simulating a long commit, set up a client with draw duration |
// estimates that prevent skipping main frames to get to low latency mode. |
- SchedulerClientWithFixedEstimates* client = |
- new SchedulerClientWithFixedEstimates( |
- base::TimeDelta::FromMilliseconds(1), |
- base::TimeDelta::FromMilliseconds(32), |
- base::TimeDelta::FromMilliseconds(32)); |
scheduler_settings_.use_external_begin_frame_source = true; |
scheduler_settings_.main_frame_while_swap_throttled_enabled = true; |
- SetUpScheduler(make_scoped_ptr(client).Pass(), true); |
+ SetUpScheduler(true); |
+ |
+ scheduler_->SetDrawDurationEstimate(base::TimeDelta::FromMilliseconds(1)); |
+ scheduler_->SetBeginMainFrameToCommitDurationEstimate( |
+ base::TimeDelta::FromMilliseconds(32)); |
+ scheduler_->SetPrepareTilesToReadyToActivateDurationEstimate( |
+ base::TimeDelta::FromMilliseconds(32)); |
// Disables automatic swap acks so this test can force swap ack throttling |
// to simulate a blocked Browser ui thread. |
@@ -1550,15 +1521,16 @@ TEST_F(SchedulerTest, |
// Since we are simulating a long commit, set up a client with draw duration |
// estimates that prevent skipping main frames to get to low latency mode. |
- SchedulerClientWithFixedEstimates* client = |
- new SchedulerClientWithFixedEstimates( |
- base::TimeDelta::FromMilliseconds(1), |
- base::TimeDelta::FromMilliseconds(32), |
- base::TimeDelta::FromMilliseconds(32)); |
scheduler_settings_.use_external_begin_frame_source = true; |
scheduler_settings_.main_frame_while_swap_throttled_enabled = true; |
scheduler_settings_.main_frame_before_activation_enabled = true; |
- SetUpScheduler(make_scoped_ptr(client).Pass(), true); |
+ SetUpScheduler(true); |
+ |
+ scheduler_->SetDrawDurationEstimate(base::TimeDelta::FromMilliseconds(1)); |
+ scheduler_->SetBeginMainFrameToCommitDurationEstimate( |
+ base::TimeDelta::FromMilliseconds(32)); |
+ scheduler_->SetPrepareTilesToReadyToActivateDurationEstimate( |
+ base::TimeDelta::FromMilliseconds(32)); |
// Disables automatic swap acks so this test can force swap ack throttling |
// to simulate a blocked Browser ui thread. |
@@ -1636,15 +1608,16 @@ TEST_F( |
// Since we are simulating a long commit, set up a client with draw duration |
// estimates that prevent skipping main frames to get to low latency mode. |
- SchedulerClientWithFixedEstimates* client = |
- new SchedulerClientWithFixedEstimates( |
- base::TimeDelta::FromMilliseconds(1), |
- base::TimeDelta::FromMilliseconds(32), |
- base::TimeDelta::FromMilliseconds(32)); |
scheduler_settings_.use_external_begin_frame_source = true; |
scheduler_settings_.main_frame_while_swap_throttled_enabled = true; |
scheduler_settings_.main_frame_before_activation_enabled = true; |
- SetUpScheduler(make_scoped_ptr(client).Pass(), true); |
+ SetUpScheduler(true); |
+ |
+ scheduler_->SetDrawDurationEstimate(base::TimeDelta::FromMilliseconds(1)); |
+ scheduler_->SetBeginMainFrameToCommitDurationEstimate( |
+ base::TimeDelta::FromMilliseconds(32)); |
+ scheduler_->SetPrepareTilesToReadyToActivateDurationEstimate( |
+ base::TimeDelta::FromMilliseconds(32)); |
// Disables automatic swap acks so this test can force swap ack throttling |
// to simulate a blocked Browser ui thread. |
@@ -2953,11 +2926,6 @@ class SchedulerClientSetNeedsPrepareTilesOnDraw : public FakeSchedulerClient { |
scheduler_->SetNeedsPrepareTiles(); |
return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
} |
- |
- void ScheduledActionPrepareTiles() override { |
- FakeSchedulerClient::ScheduledActionPrepareTiles(); |
- scheduler_->DidPrepareTiles(); |
- } |
}; |
TEST_F(SchedulerTest, SynchronousCompositorPrepareTilesOnDraw) { |