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(); |
| 1132 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); |
| 1133 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 1134 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); |
| 1135 scheduler->OnBeginImplFrameDeadline(); |
| 1136 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
| 1137 scheduler->FinishCommit(); |
| 1138 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
| 1139 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); |
| 1140 |
| 1141 client.Reset(); |
| 1142 scheduler->SetNeedsCommit(); |
| 1143 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
| 1144 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 1145 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
| 1146 scheduler->OnBeginImplFrameDeadline(); |
| 1147 EXPECT_EQ(scheduler->MainThreadIsInHighLatencyMode(), |
| 1148 should_send_begin_main_frame); |
| 1149 EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"), |
| 1150 should_send_begin_main_frame); |
| 1151 } |
| 1152 |
| 1153 TEST(SchedulerTest, |
| 1154 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { |
| 1155 // Set up client so that estimates indicate that we can commit and activate |
| 1156 // before the deadline (~8ms by default). |
| 1157 MainFrameInHighLatencyMode(1, 1, false); |
| 1158 } |
| 1159 |
| 1160 TEST(SchedulerTest, NotSkipMainFrameIfHighLatencyAndCanCommitTooLong) { |
| 1161 // Set up client so that estimates indicate that the commit cannot finish |
| 1162 // before the deadline (~8ms by default). |
| 1163 MainFrameInHighLatencyMode(10, 1, true); |
| 1164 } |
| 1165 |
| 1166 TEST(SchedulerTest, NotSkipMainFrameIfHighLatencyAndCanActivateTooLong) { |
| 1167 // Set up client so that estimates indicate that the activate cannot finish |
| 1168 // before the deadline (~8ms by default). |
| 1169 MainFrameInHighLatencyMode(1, 10, true); |
| 1170 } |
| 1171 |
1083 } // namespace | 1172 } // namespace |
1084 } // namespace cc | 1173 } // namespace cc |
OLD | NEW |