Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 #include "cc/scheduler/scheduler.h" | 4 #include "cc/scheduler/scheduler.h" |
| 5 | 5 |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| 11 #include "base/time/time.h" | |
| 11 #include "cc/test/scheduler_test_common.h" | 12 #include "cc/test/scheduler_test_common.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 #define EXPECT_ACTION(action, client, action_index, expected_num_actions) \ | 16 #define EXPECT_ACTION(action, client, action_index, expected_num_actions) \ |
| 16 EXPECT_EQ(expected_num_actions, client.num_actions_()); \ | 17 EXPECT_EQ(expected_num_actions, client.num_actions_()); \ |
| 17 ASSERT_LT(action_index, client.num_actions_()); \ | 18 ASSERT_LT(action_index, client.num_actions_()); \ |
| 18 do { \ | 19 do { \ |
| 19 EXPECT_STREQ(action, client.Action(action_index)); \ | 20 EXPECT_STREQ(action, client.Action(action_index)); \ |
| 20 for (int i = expected_num_actions; i < client.num_actions_(); ++i) \ | 21 for (int i = expected_num_actions; i < client.num_actions_(); ++i) \ |
| (...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1073 client.Reset(); | 1074 client.Reset(); |
| 1074 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 1075 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 1075 EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); | 1076 EXPECT_SINGLE_ACTION("PostBeginImplFrameDeadlineTask", client); |
| 1076 client.Reset(); | 1077 client.Reset(); |
| 1077 scheduler->OnBeginImplFrameDeadline(); | 1078 scheduler->OnBeginImplFrameDeadline(); |
| 1078 EXPECT_EQ(0, client.num_draws()); | 1079 EXPECT_EQ(0, client.num_draws()); |
| 1079 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1080 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 1080 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 1081 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
| 1081 } | 1082 } |
| 1082 | 1083 |
| 1084 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { | |
| 1085 public: | |
| 1086 SchedulerClientWithFixedEstimates( | |
| 1087 base::TimeDelta draw_duration, | |
| 1088 base::TimeDelta begin_main_frame_to_commit_duration, | |
| 1089 base::TimeDelta commit_to_activate_duration) | |
| 1090 : draw_duration_(draw_duration), | |
| 1091 begin_main_frame_to_commit_duration_( | |
| 1092 begin_main_frame_to_commit_duration), | |
| 1093 commit_to_activate_duration_(commit_to_activate_duration) {} | |
| 1094 | |
| 1095 virtual base::TimeDelta DrawDurationEstimate() OVERRIDE { | |
| 1096 return draw_duration_; | |
| 1097 } | |
| 1098 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() OVERRIDE { | |
| 1099 return begin_main_frame_to_commit_duration_; | |
| 1100 } | |
| 1101 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE { | |
| 1102 return commit_to_activate_duration_; | |
| 1103 } | |
| 1104 | |
| 1105 private: | |
| 1106 base::TimeDelta draw_duration_; | |
| 1107 base::TimeDelta begin_main_frame_to_commit_duration_; | |
| 1108 base::TimeDelta commit_to_activate_duration_; | |
| 1109 }; | |
| 1110 | |
| 1111 void MainFrameInHighLatencyMode(int64 begin_main_frame_to_commit_estimate_in_ms, | |
| 1112 int64 commit_to_activate_estimate_in_ms, | |
| 1113 bool should_send_begin_main_frame) { | |
| 1114 // Set up client with specified estimates (draw duration is set to 1). | |
| 1115 SchedulerClientWithFixedEstimates client( | |
| 1116 base::TimeDelta::FromMilliseconds(1), | |
| 1117 base::TimeDelta::FromMilliseconds( | |
| 1118 begin_main_frame_to_commit_estimate_in_ms), | |
| 1119 base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms)); | |
| 1120 SchedulerSettings scheduler_settings; | |
| 1121 scheduler_settings.deadline_scheduling_enabled = true; | |
| 1122 scheduler_settings.switch_to_low_latency_if_possible = true; | |
| 1123 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); | |
| 1124 scheduler->SetCanStart(); | |
| 1125 scheduler->SetVisible(true); | |
| 1126 scheduler->SetCanDraw(true); | |
| 1127 InitializeOutputSurfaceAndFirstCommit(scheduler); | |
| 1128 | |
| 1129 // Impl thread hits deadline before commit finishes. | |
| 1130 client.Reset(); | |
| 1131 scheduler->SetNeedsCommit(); | |
|
brianderson
2013/11/06 02:38:07
Before you land this, can you check the expected v
| |
| 1132 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | |
| 1133 scheduler->OnBeginImplFrameDeadline(); | |
| 1134 scheduler->FinishCommit(); | |
| 1135 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); | |
| 1136 | |
| 1137 client.Reset(); | |
| 1138 scheduler->SetNeedsCommit(); | |
| 1139 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | |
| 1140 scheduler->OnBeginImplFrameDeadline(); | |
| 1141 EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"), | |
| 1142 should_send_begin_main_frame); | |
| 1143 } | |
| 1144 | |
| 1145 TEST(SchedulerTest, | |
| 1146 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { | |
| 1147 // Set up client so that estimates indicate that we can commit and activate | |
| 1148 // before the deadline (~8ms by default). | |
| 1149 MainFrameInHighLatencyMode(1, 1, false); | |
| 1150 } | |
| 1151 | |
| 1152 TEST(SchedulerTest, NotSkipMainFrameIfHighLatencyAndCanCommitTooLong) { | |
| 1153 // Set up client so that estimates indicate that the commit cannot finish | |
| 1154 // before the deadline (~8ms by default). | |
| 1155 MainFrameInHighLatencyMode(10, 1, true); | |
| 1156 } | |
| 1157 | |
| 1158 TEST(SchedulerTest, NotSkipMainFrameIfHighLatencyAndCanActivateTooLong) { | |
| 1159 // Set up client so that estimates indicate that the activate cannot finish | |
| 1160 // before the deadline (~8ms by default). | |
| 1161 MainFrameInHighLatencyMode(1, 10, true); | |
| 1162 } | |
| 1163 | |
| 1083 } // namespace | 1164 } // namespace |
| 1084 } // namespace cc | 1165 } // namespace cc |
| OLD | NEW |